1 | /* $Id: tstUnattendedScript.cpp 102381 2023-11-29 14:51:33Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * tstUnattendedScript - testcases for UnattendedScript.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2022-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | #include "UnattendedScript.h"
|
---|
33 |
|
---|
34 | #include <VBox/com/VirtualBox.h>
|
---|
35 | #include <VBox/com/errorprint.h>
|
---|
36 |
|
---|
37 | #include <iprt/crypto/shacrypt.h>
|
---|
38 |
|
---|
39 | #include <iprt/file.h>
|
---|
40 | #include <iprt/path.h>
|
---|
41 | #include <iprt/test.h>
|
---|
42 | #include <iprt/stream.h>
|
---|
43 |
|
---|
44 | #include "VirtualBoxBase.h"
|
---|
45 | #include "UnattendedImpl.h"
|
---|
46 | #include "UnattendedScript.h"
|
---|
47 | #include "VirtualBoxImpl.h"
|
---|
48 | #include "MachineImpl.h"
|
---|
49 |
|
---|
50 | using namespace std;
|
---|
51 |
|
---|
52 |
|
---|
53 | /*********************************************************************************************************************************
|
---|
54 | * Unattended Stub Implementation *
|
---|
55 | *********************************************************************************************************************************/
|
---|
56 | Unattended::Unattended()
|
---|
57 | : mhThreadReconfigureVM(NIL_RTNATIVETHREAD), mfRtcUseUtc(false), mfGuestOs64Bit(false)
|
---|
58 | , mpInstaller(NULL), mpTimeZoneInfo(NULL), mfIsDefaultAuxiliaryBasePath(true), mfDoneDetectIsoOS(false)
|
---|
59 | {
|
---|
60 | mStrUser = "vboxuser";
|
---|
61 | mStrPassword = "changeme";
|
---|
62 | mStrFullUserName = "VBox & VBox;";
|
---|
63 | mStrProductKey = "911";
|
---|
64 | mStrIsoPath = "/iso/path/file.iso";
|
---|
65 | mStrAdditionsIsoPath = "/iso/path/addition.iso";
|
---|
66 | mfInstallGuestAdditions = true;
|
---|
67 | mfInstallTestExecService = true;
|
---|
68 | mStrValidationKitIsoPath = "/iso/path/valkit.iso";
|
---|
69 | mStrTimeZone = "cet";
|
---|
70 | mpTimeZoneInfo = NULL;
|
---|
71 | mStrLocale = "dk_DK";
|
---|
72 | mStrLanguage = "dk";
|
---|
73 | mStrCountry = "DK";
|
---|
74 | //mPackageSelectionAdjustments = "minimal";
|
---|
75 | mStrHostname = "my-extra-long-name.hostname.com";
|
---|
76 | mStrAuxiliaryBasePath = "/aux/path/pfx-";
|
---|
77 | mfIsDefaultAuxiliaryBasePath = false;
|
---|
78 | midxImage = 42;
|
---|
79 | mStrScriptTemplatePath = "/path/to/script-template.file";
|
---|
80 | mStrPostInstallScriptTemplatePath = "/path/to/post-install-template.file";
|
---|
81 | mStrPostInstallCommand = "/bin/post-install-command arg1 arg2 --amp=& --lt=< --gt=> --dq-word=\"word\" --sq-word='word'";
|
---|
82 | mStrExtraInstallKernelParameters = "extra=kernel parameters quiet amp=& lt=< gt=>";
|
---|
83 | mStrProxy = "http://proxy.intranet.com:443";
|
---|
84 |
|
---|
85 | mfDoneDetectIsoOS = true;
|
---|
86 | mStrDetectedOSTypeId = "MyOSTypeId";
|
---|
87 | mStrDetectedOSVersion = "3.4.2";
|
---|
88 | mStrDetectedOSFlavor = "server";
|
---|
89 | //mDetectedOSLanguages = "en_UK"
|
---|
90 | mStrDetectedOSHints = "nudge nudge wink wink";
|
---|
91 | mStrAdditionsInstallPackage = "Something-none-existing.run";
|
---|
92 | }
|
---|
93 |
|
---|
94 | Unattended::~Unattended()
|
---|
95 | {
|
---|
96 | }
|
---|
97 |
|
---|
98 | HRESULT Unattended::FinalConstruct()
|
---|
99 | {
|
---|
100 | return BaseFinalConstruct();
|
---|
101 | }
|
---|
102 |
|
---|
103 | void Unattended::FinalRelease()
|
---|
104 | {
|
---|
105 | uninit();
|
---|
106 | BaseFinalRelease();
|
---|
107 | }
|
---|
108 |
|
---|
109 | void Unattended::uninit()
|
---|
110 | {
|
---|
111 | }
|
---|
112 |
|
---|
113 | HRESULT Unattended::initUnattended(VirtualBox *aParent)
|
---|
114 | {
|
---|
115 | unconst(mParent) = aParent;
|
---|
116 | return S_OK;
|
---|
117 | }
|
---|
118 |
|
---|
119 | HRESULT Unattended::detectIsoOS()
|
---|
120 | {
|
---|
121 | return E_NOTIMPL;
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | HRESULT Unattended::prepare()
|
---|
126 | {
|
---|
127 | return E_NOTIMPL;
|
---|
128 | }
|
---|
129 |
|
---|
130 | HRESULT Unattended::constructMedia()
|
---|
131 | {
|
---|
132 | return E_NOTIMPL;
|
---|
133 | }
|
---|
134 |
|
---|
135 | HRESULT Unattended::reconfigureVM()
|
---|
136 | {
|
---|
137 | return E_NOTIMPL;
|
---|
138 | }
|
---|
139 |
|
---|
140 | HRESULT Unattended::done()
|
---|
141 | {
|
---|
142 | return E_NOTIMPL;
|
---|
143 | }
|
---|
144 |
|
---|
145 | HRESULT Unattended::getIsoPath(com::Utf8Str &isoPath)
|
---|
146 | {
|
---|
147 | RT_NOREF(isoPath);
|
---|
148 | return E_NOTIMPL;
|
---|
149 | }
|
---|
150 |
|
---|
151 | HRESULT Unattended::setIsoPath(const com::Utf8Str &isoPath)
|
---|
152 | {
|
---|
153 | RT_NOREF(isoPath);
|
---|
154 | return E_NOTIMPL;
|
---|
155 | }
|
---|
156 |
|
---|
157 | HRESULT Unattended::getUser(com::Utf8Str &user)
|
---|
158 | {
|
---|
159 | RT_NOREF(user);
|
---|
160 | return E_NOTIMPL;
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | HRESULT Unattended::setUser(const com::Utf8Str &user)
|
---|
165 | {
|
---|
166 | RT_NOREF(user);
|
---|
167 | return E_NOTIMPL;
|
---|
168 | }
|
---|
169 |
|
---|
170 | HRESULT Unattended::getPassword(com::Utf8Str &password)
|
---|
171 | {
|
---|
172 | RT_NOREF(password);
|
---|
173 | return E_NOTIMPL;
|
---|
174 | }
|
---|
175 |
|
---|
176 | HRESULT Unattended::setPassword(const com::Utf8Str &password)
|
---|
177 | {
|
---|
178 | RT_NOREF(password);
|
---|
179 | return E_NOTIMPL;
|
---|
180 | }
|
---|
181 |
|
---|
182 | HRESULT Unattended::getFullUserName(com::Utf8Str &fullUserName)
|
---|
183 | {
|
---|
184 | RT_NOREF(fullUserName);
|
---|
185 | return E_NOTIMPL;
|
---|
186 | }
|
---|
187 |
|
---|
188 | HRESULT Unattended::setFullUserName(const com::Utf8Str &fullUserName)
|
---|
189 | {
|
---|
190 | RT_NOREF(fullUserName);
|
---|
191 | return E_NOTIMPL;
|
---|
192 | }
|
---|
193 |
|
---|
194 | HRESULT Unattended::getProductKey(com::Utf8Str &productKey)
|
---|
195 | {
|
---|
196 | RT_NOREF(productKey);
|
---|
197 | return E_NOTIMPL;
|
---|
198 | }
|
---|
199 |
|
---|
200 | HRESULT Unattended::setProductKey(const com::Utf8Str &productKey)
|
---|
201 | {
|
---|
202 | RT_NOREF(productKey);
|
---|
203 | return E_NOTIMPL;
|
---|
204 | }
|
---|
205 |
|
---|
206 | HRESULT Unattended::getAdditionsIsoPath(com::Utf8Str &additionsIsoPath)
|
---|
207 | {
|
---|
208 | RT_NOREF(additionsIsoPath);
|
---|
209 | return E_NOTIMPL;
|
---|
210 | }
|
---|
211 |
|
---|
212 | HRESULT Unattended::setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath)
|
---|
213 | {
|
---|
214 | RT_NOREF(additionsIsoPath);
|
---|
215 | return E_NOTIMPL;
|
---|
216 | }
|
---|
217 |
|
---|
218 | HRESULT Unattended::getInstallGuestAdditions(BOOL *installGuestAdditions)
|
---|
219 | {
|
---|
220 | RT_NOREF(installGuestAdditions);
|
---|
221 | return E_NOTIMPL;
|
---|
222 | }
|
---|
223 |
|
---|
224 | HRESULT Unattended::setInstallGuestAdditions(BOOL installGuestAdditions)
|
---|
225 | {
|
---|
226 | RT_NOREF(installGuestAdditions);
|
---|
227 | return E_NOTIMPL;
|
---|
228 | }
|
---|
229 |
|
---|
230 | HRESULT Unattended::getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath)
|
---|
231 | {
|
---|
232 | RT_NOREF(aValidationKitIsoPath);
|
---|
233 | return E_NOTIMPL;
|
---|
234 | }
|
---|
235 |
|
---|
236 | HRESULT Unattended::setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath)
|
---|
237 | {
|
---|
238 | RT_NOREF(aValidationKitIsoPath);
|
---|
239 | return E_NOTIMPL;
|
---|
240 | }
|
---|
241 |
|
---|
242 | HRESULT Unattended::getInstallTestExecService(BOOL *aInstallTestExecService)
|
---|
243 | {
|
---|
244 | RT_NOREF(aInstallTestExecService);
|
---|
245 | return E_NOTIMPL;
|
---|
246 | }
|
---|
247 |
|
---|
248 | HRESULT Unattended::setInstallTestExecService(BOOL aInstallTestExecService)
|
---|
249 | {
|
---|
250 | RT_NOREF(aInstallTestExecService);
|
---|
251 | return E_NOTIMPL;
|
---|
252 | }
|
---|
253 |
|
---|
254 | HRESULT Unattended::getUserPayloadIsoPath(com::Utf8Str &userPayloadIsoPath)
|
---|
255 | {
|
---|
256 | RT_NOREF(userPayloadIsoPath);
|
---|
257 | return E_NOTIMPL;
|
---|
258 | }
|
---|
259 |
|
---|
260 | HRESULT Unattended::setUserPayloadIsoPath(const com::Utf8Str &userPayloadIsoPath)
|
---|
261 | {
|
---|
262 | RT_NOREF(userPayloadIsoPath);
|
---|
263 | return E_NOTIMPL;
|
---|
264 | }
|
---|
265 |
|
---|
266 | HRESULT Unattended::getInstallUserPayload(BOOL *installUserPayload)
|
---|
267 | {
|
---|
268 | RT_NOREF(installUserPayload);
|
---|
269 | return E_NOTIMPL;
|
---|
270 | }
|
---|
271 |
|
---|
272 | HRESULT Unattended::setInstallUserPayload(BOOL installUserPayload)
|
---|
273 | {
|
---|
274 | RT_NOREF(installUserPayload);
|
---|
275 | return E_NOTIMPL;
|
---|
276 | }
|
---|
277 |
|
---|
278 | HRESULT Unattended::getTimeZone(com::Utf8Str &aTimeZone)
|
---|
279 | {
|
---|
280 | RT_NOREF(aTimeZone);
|
---|
281 | return E_NOTIMPL;
|
---|
282 | }
|
---|
283 |
|
---|
284 | HRESULT Unattended::setTimeZone(const com::Utf8Str &aTimezone)
|
---|
285 | {
|
---|
286 | RT_NOREF(aTimezone);
|
---|
287 | return E_NOTIMPL;
|
---|
288 | }
|
---|
289 |
|
---|
290 | HRESULT Unattended::getKeyboardLayout(com::Utf8Str &aKeyboardLayout)
|
---|
291 | {
|
---|
292 | RT_NOREF(aKeyboardLayout);
|
---|
293 | return E_NOTIMPL;
|
---|
294 | }
|
---|
295 |
|
---|
296 | HRESULT Unattended::setKeyboardLayout(const com::Utf8Str &aKeyboardLayout)
|
---|
297 | {
|
---|
298 | RT_NOREF(aKeyboardLayout);
|
---|
299 | return E_NOTIMPL;
|
---|
300 | }
|
---|
301 |
|
---|
302 | HRESULT Unattended::getKeyboardVariant(com::Utf8Str &aKeyboardVariant)
|
---|
303 | {
|
---|
304 | RT_NOREF(aKeyboardVariant);
|
---|
305 | return E_NOTIMPL;
|
---|
306 | }
|
---|
307 |
|
---|
308 | HRESULT Unattended::setKeyboardVariant(const com::Utf8Str &aKeyboardVariant)
|
---|
309 | {
|
---|
310 | RT_NOREF(aKeyboardVariant);
|
---|
311 | return E_NOTIMPL;
|
---|
312 | }
|
---|
313 |
|
---|
314 | HRESULT Unattended::getLocale(com::Utf8Str &aLocale)
|
---|
315 | {
|
---|
316 | RT_NOREF(aLocale);
|
---|
317 | return E_NOTIMPL;
|
---|
318 | }
|
---|
319 |
|
---|
320 | HRESULT Unattended::setLocale(const com::Utf8Str &aLocale)
|
---|
321 | {
|
---|
322 | RT_NOREF(aLocale);
|
---|
323 | return E_NOTIMPL;
|
---|
324 | }
|
---|
325 |
|
---|
326 | HRESULT Unattended::getLanguage(com::Utf8Str &aLanguage)
|
---|
327 | {
|
---|
328 | RT_NOREF(aLanguage);
|
---|
329 | return E_NOTIMPL;
|
---|
330 | }
|
---|
331 |
|
---|
332 | HRESULT Unattended::setLanguage(const com::Utf8Str &aLanguage)
|
---|
333 | {
|
---|
334 | RT_NOREF(aLanguage);
|
---|
335 | return E_NOTIMPL;
|
---|
336 | }
|
---|
337 |
|
---|
338 | HRESULT Unattended::getCountry(com::Utf8Str &aCountry)
|
---|
339 | {
|
---|
340 | RT_NOREF(aCountry);
|
---|
341 | return E_NOTIMPL;
|
---|
342 | }
|
---|
343 |
|
---|
344 | HRESULT Unattended::setCountry(const com::Utf8Str &aCountry)
|
---|
345 | {
|
---|
346 | RT_NOREF(aCountry);
|
---|
347 | return E_NOTIMPL;
|
---|
348 | }
|
---|
349 |
|
---|
350 | HRESULT Unattended::getProxy(com::Utf8Str &aProxy)
|
---|
351 | {
|
---|
352 | RT_NOREF(aProxy);
|
---|
353 | return E_NOTIMPL;
|
---|
354 | }
|
---|
355 |
|
---|
356 | HRESULT Unattended::setProxy(const com::Utf8Str &aProxy)
|
---|
357 | {
|
---|
358 | RT_NOREF(aProxy);
|
---|
359 | return E_NOTIMPL;
|
---|
360 | }
|
---|
361 |
|
---|
362 | HRESULT Unattended::getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments)
|
---|
363 | {
|
---|
364 | RT_NOREF(aPackageSelectionAdjustments);
|
---|
365 | return E_NOTIMPL;
|
---|
366 | }
|
---|
367 |
|
---|
368 | HRESULT Unattended::setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments)
|
---|
369 | {
|
---|
370 | RT_NOREF(aPackageSelectionAdjustments);
|
---|
371 | return E_NOTIMPL;
|
---|
372 | }
|
---|
373 |
|
---|
374 | HRESULT Unattended::getHostname(com::Utf8Str &aHostname)
|
---|
375 | {
|
---|
376 | RT_NOREF(aHostname);
|
---|
377 | return E_NOTIMPL;
|
---|
378 | }
|
---|
379 |
|
---|
380 | HRESULT Unattended::setHostname(const com::Utf8Str &aHostname)
|
---|
381 | {
|
---|
382 | RT_NOREF(aHostname);
|
---|
383 | return E_NOTIMPL;
|
---|
384 | }
|
---|
385 |
|
---|
386 | HRESULT Unattended::getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath)
|
---|
387 | {
|
---|
388 | RT_NOREF(aAuxiliaryBasePath);
|
---|
389 | return E_NOTIMPL;
|
---|
390 | }
|
---|
391 |
|
---|
392 | HRESULT Unattended::setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath)
|
---|
393 | {
|
---|
394 | RT_NOREF(aAuxiliaryBasePath);
|
---|
395 | return E_NOTIMPL;
|
---|
396 | }
|
---|
397 |
|
---|
398 | HRESULT Unattended::getImageIndex(ULONG *index)
|
---|
399 | {
|
---|
400 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
401 | *index = midxImage;
|
---|
402 | return S_OK;
|
---|
403 | }
|
---|
404 |
|
---|
405 | HRESULT Unattended::setImageIndex(ULONG index)
|
---|
406 | {
|
---|
407 | RT_NOREF(index);
|
---|
408 | return E_NOTIMPL;
|
---|
409 | }
|
---|
410 |
|
---|
411 | HRESULT Unattended::getMachine(ComPtr<IMachine> &aMachine)
|
---|
412 | {
|
---|
413 | RT_NOREF(aMachine);
|
---|
414 | return E_NOTIMPL;
|
---|
415 | }
|
---|
416 |
|
---|
417 | HRESULT Unattended::setMachine(const ComPtr<IMachine> &aMachine)
|
---|
418 | {
|
---|
419 | RT_NOREF(aMachine);
|
---|
420 | return E_NOTIMPL;
|
---|
421 | }
|
---|
422 |
|
---|
423 | HRESULT Unattended::getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath)
|
---|
424 | {
|
---|
425 | RT_NOREF(aScriptTemplatePath);
|
---|
426 | return E_NOTIMPL;
|
---|
427 | }
|
---|
428 |
|
---|
429 | HRESULT Unattended::setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath)
|
---|
430 | {
|
---|
431 | RT_NOREF(aScriptTemplatePath);
|
---|
432 | return E_NOTIMPL;
|
---|
433 |
|
---|
434 | }
|
---|
435 |
|
---|
436 | HRESULT Unattended::getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath)
|
---|
437 | {
|
---|
438 | RT_NOREF(aPostInstallScriptTemplatePath);
|
---|
439 | return E_NOTIMPL;
|
---|
440 | }
|
---|
441 |
|
---|
442 | HRESULT Unattended::setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath)
|
---|
443 | {
|
---|
444 | RT_NOREF(aPostInstallScriptTemplatePath);
|
---|
445 | return E_NOTIMPL;
|
---|
446 | }
|
---|
447 |
|
---|
448 | HRESULT Unattended::getPostInstallCommand(com::Utf8Str &aPostInstallCommand)
|
---|
449 | {
|
---|
450 | RT_NOREF(aPostInstallCommand);
|
---|
451 | return E_NOTIMPL;
|
---|
452 | }
|
---|
453 |
|
---|
454 | HRESULT Unattended::setPostInstallCommand(const com::Utf8Str &aPostInstallCommand)
|
---|
455 | {
|
---|
456 | RT_NOREF(aPostInstallCommand);
|
---|
457 | return E_NOTIMPL;
|
---|
458 | }
|
---|
459 |
|
---|
460 | HRESULT Unattended::getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters)
|
---|
461 | {
|
---|
462 | RT_NOREF(aExtraInstallKernelParameters);
|
---|
463 | return E_NOTIMPL;
|
---|
464 | }
|
---|
465 |
|
---|
466 | HRESULT Unattended::setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters)
|
---|
467 | {
|
---|
468 | RT_NOREF(aExtraInstallKernelParameters);
|
---|
469 | return E_NOTIMPL;
|
---|
470 | }
|
---|
471 |
|
---|
472 | HRESULT Unattended::getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId)
|
---|
473 | {
|
---|
474 | RT_NOREF(aDetectedOSTypeId);
|
---|
475 | return E_NOTIMPL;
|
---|
476 | }
|
---|
477 |
|
---|
478 | HRESULT Unattended::getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion)
|
---|
479 | {
|
---|
480 | RT_NOREF(aDetectedOSVersion);
|
---|
481 | return E_NOTIMPL;
|
---|
482 | }
|
---|
483 |
|
---|
484 | HRESULT Unattended::getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor)
|
---|
485 | {
|
---|
486 | RT_NOREF(aDetectedOSFlavor);
|
---|
487 | return E_NOTIMPL;
|
---|
488 | }
|
---|
489 |
|
---|
490 | HRESULT Unattended::getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages)
|
---|
491 | {
|
---|
492 | RT_NOREF(aDetectedOSLanguages);
|
---|
493 | return E_NOTIMPL;
|
---|
494 | }
|
---|
495 |
|
---|
496 | HRESULT Unattended::getDetectedOSHints(com::Utf8Str &aDetectedOSHints)
|
---|
497 | {
|
---|
498 | RT_NOREF(aDetectedOSHints);
|
---|
499 | return E_NOTIMPL;
|
---|
500 | }
|
---|
501 |
|
---|
502 | HRESULT Unattended::getDetectedImageNames(std::vector<com::Utf8Str> &aDetectedImageNames)
|
---|
503 | {
|
---|
504 | RT_NOREF(aDetectedImageNames);
|
---|
505 | return E_NOTIMPL;
|
---|
506 | }
|
---|
507 |
|
---|
508 | HRESULT Unattended::getDetectedImageIndices(std::vector<ULONG> &aDetectedImageIndices)
|
---|
509 | {
|
---|
510 | RT_NOREF(aDetectedImageIndices);
|
---|
511 | return E_NOTIMPL;
|
---|
512 | }
|
---|
513 |
|
---|
514 | HRESULT Unattended::getIsUnattendedInstallSupported(BOOL *aIsUnattendedInstallSupported)
|
---|
515 | {
|
---|
516 | RT_NOREF(aIsUnattendedInstallSupported);
|
---|
517 | return E_NOTIMPL;
|
---|
518 | }
|
---|
519 |
|
---|
520 | HRESULT Unattended::getAvoidUpdatesOverNetwork(BOOL *aAvoidUpdatesOverNetwork)
|
---|
521 | {
|
---|
522 | RT_NOREF(aAvoidUpdatesOverNetwork);
|
---|
523 | return E_NOTIMPL;
|
---|
524 | }
|
---|
525 |
|
---|
526 | HRESULT Unattended::setAvoidUpdatesOverNetwork(BOOL aAvoidUpdatesOverNetwork)
|
---|
527 | {
|
---|
528 | RT_NOREF(aAvoidUpdatesOverNetwork);
|
---|
529 | return E_NOTIMPL;
|
---|
530 | }
|
---|
531 |
|
---|
532 |
|
---|
533 | /*
|
---|
534 | * Getters that the installer and script classes can use.
|
---|
535 | */
|
---|
536 | Utf8Str const &Unattended::i_getIsoPath() const
|
---|
537 | {
|
---|
538 | return mStrIsoPath;
|
---|
539 | }
|
---|
540 |
|
---|
541 | Utf8Str const &Unattended::i_getUser() const
|
---|
542 | {
|
---|
543 | return mStrUser;
|
---|
544 | }
|
---|
545 |
|
---|
546 | Utf8Str const &Unattended::i_getPassword() const
|
---|
547 | {
|
---|
548 | return mStrPassword;
|
---|
549 | }
|
---|
550 |
|
---|
551 | Utf8Str const &Unattended::i_getFullUserName() const
|
---|
552 | {
|
---|
553 | return mStrFullUserName.isNotEmpty() ? mStrFullUserName : mStrUser;
|
---|
554 | }
|
---|
555 |
|
---|
556 | Utf8Str const &Unattended::i_getProductKey() const
|
---|
557 | {
|
---|
558 | return mStrProductKey;
|
---|
559 | }
|
---|
560 |
|
---|
561 | Utf8Str const &Unattended::i_getProxy() const
|
---|
562 | {
|
---|
563 | return mStrProxy;
|
---|
564 | }
|
---|
565 |
|
---|
566 | Utf8Str const &Unattended::i_getAdditionsIsoPath() const
|
---|
567 | {
|
---|
568 | return mStrAdditionsIsoPath;
|
---|
569 | }
|
---|
570 |
|
---|
571 | bool Unattended::i_getInstallGuestAdditions() const
|
---|
572 | {
|
---|
573 | return mfInstallGuestAdditions;
|
---|
574 | }
|
---|
575 |
|
---|
576 | Utf8Str const &Unattended::i_getValidationKitIsoPath() const
|
---|
577 | {
|
---|
578 | return mStrValidationKitIsoPath;
|
---|
579 | }
|
---|
580 |
|
---|
581 | bool Unattended::i_getInstallTestExecService() const
|
---|
582 | {
|
---|
583 | return mfInstallTestExecService;
|
---|
584 | }
|
---|
585 |
|
---|
586 | Utf8Str const &Unattended::i_getTimeZone() const
|
---|
587 | {
|
---|
588 | return mStrTimeZone;
|
---|
589 | }
|
---|
590 |
|
---|
591 | PCRTTIMEZONEINFO Unattended::i_getTimeZoneInfo() const
|
---|
592 | {
|
---|
593 | return mpTimeZoneInfo;
|
---|
594 | }
|
---|
595 |
|
---|
596 | Utf8Str const &Unattended::i_getLocale() const
|
---|
597 | {
|
---|
598 | return mStrLocale;
|
---|
599 | }
|
---|
600 |
|
---|
601 | Utf8Str const &Unattended::i_getLanguage() const
|
---|
602 | {
|
---|
603 | return mStrLanguage;
|
---|
604 | }
|
---|
605 |
|
---|
606 | Utf8Str const &Unattended::i_getCountry() const
|
---|
607 | {
|
---|
608 | return mStrCountry;
|
---|
609 | }
|
---|
610 |
|
---|
611 | bool Unattended::i_isMinimalInstallation() const
|
---|
612 | {
|
---|
613 | size_t i = mPackageSelectionAdjustments.size();
|
---|
614 | while (i-- > 0)
|
---|
615 | if (mPackageSelectionAdjustments[i].equals("minimal"))
|
---|
616 | return true;
|
---|
617 | return false;
|
---|
618 | }
|
---|
619 |
|
---|
620 | Utf8Str const &Unattended::i_getHostname() const
|
---|
621 | {
|
---|
622 | return mStrHostname;
|
---|
623 | }
|
---|
624 |
|
---|
625 | Utf8Str const &Unattended::i_getAuxiliaryBasePath() const
|
---|
626 | {
|
---|
627 | return mStrAuxiliaryBasePath;
|
---|
628 | }
|
---|
629 |
|
---|
630 | ULONG Unattended::i_getImageIndex() const
|
---|
631 | {
|
---|
632 | return midxImage;
|
---|
633 | }
|
---|
634 |
|
---|
635 | Utf8Str const &Unattended::i_getScriptTemplatePath() const
|
---|
636 | {
|
---|
637 | return mStrScriptTemplatePath;
|
---|
638 | }
|
---|
639 |
|
---|
640 | Utf8Str const &Unattended::i_getPostInstallScriptTemplatePath() const
|
---|
641 | {
|
---|
642 | return mStrPostInstallScriptTemplatePath;
|
---|
643 | }
|
---|
644 |
|
---|
645 | Utf8Str const &Unattended::i_getPostInstallCommand() const
|
---|
646 | {
|
---|
647 | return mStrPostInstallCommand;
|
---|
648 | }
|
---|
649 |
|
---|
650 | Utf8Str const &Unattended::i_getAuxiliaryInstallDir() const
|
---|
651 | {
|
---|
652 | static Utf8Str s_strAuxInstallDir("/aux/install/dir");
|
---|
653 | return s_strAuxInstallDir;
|
---|
654 | }
|
---|
655 |
|
---|
656 | Utf8Str const &Unattended::i_getExtraInstallKernelParameters() const
|
---|
657 | {
|
---|
658 | return mStrExtraInstallKernelParameters;
|
---|
659 | }
|
---|
660 |
|
---|
661 | Utf8Str const &Unattended::i_getAdditionsInstallPackage() const
|
---|
662 | {
|
---|
663 | return mStrAdditionsInstallPackage;
|
---|
664 | }
|
---|
665 |
|
---|
666 | bool Unattended::i_isRtcUsingUtc() const
|
---|
667 | {
|
---|
668 | return mfRtcUseUtc;
|
---|
669 | }
|
---|
670 |
|
---|
671 | bool Unattended::i_isGuestOs64Bit() const
|
---|
672 | {
|
---|
673 | return mfGuestOs64Bit;
|
---|
674 | }
|
---|
675 |
|
---|
676 | bool Unattended::i_isFirmwareEFI() const
|
---|
677 | {
|
---|
678 | return menmFirmwareType != FirmwareType_BIOS;
|
---|
679 | }
|
---|
680 |
|
---|
681 | Utf8Str const &Unattended::i_getDetectedOSVersion()
|
---|
682 | {
|
---|
683 | return mStrDetectedOSVersion;
|
---|
684 | }
|
---|
685 |
|
---|
686 | bool Unattended::i_getAvoidUpdatesOverNetwork() const
|
---|
687 | {
|
---|
688 | return mfAvoidUpdatesOverNetwork;
|
---|
689 | }
|
---|
690 |
|
---|
691 |
|
---|
692 | /*********************************************************************************************************************************
|
---|
693 | * The Testcase *
|
---|
694 | *********************************************************************************************************************************/
|
---|
695 |
|
---|
696 | static bool loadFileAsString(const char *pszFilename, Utf8Str &rstrContent)
|
---|
697 | {
|
---|
698 | rstrContent.setNull();
|
---|
699 |
|
---|
700 | char szPath[RTPATH_MAX];
|
---|
701 | RTTESTI_CHECK_RC_RET(RTPathExecDir(szPath, sizeof(szPath)), VINF_SUCCESS, false);
|
---|
702 | RTTESTI_CHECK_RC_RET(RTPathAppend(szPath, sizeof(szPath), pszFilename), VINF_SUCCESS, false);
|
---|
703 |
|
---|
704 | RTFILE hFile;
|
---|
705 | RTTESTI_CHECK_RC_RET(RTFileOpen(&hFile, szPath, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE), VINF_SUCCESS, false);
|
---|
706 |
|
---|
707 | uint64_t cbFile = 0;
|
---|
708 | RTTESTI_CHECK_RC_RET(RTFileQuerySize(hFile, &cbFile), VINF_SUCCESS, false);
|
---|
709 |
|
---|
710 | rstrContent.reserve((size_t)cbFile + 1);
|
---|
711 | RTTESTI_CHECK_RC_RET(RTFileRead(hFile, rstrContent.mutableRaw(), (size_t)cbFile, NULL), VINF_SUCCESS, false);
|
---|
712 | rstrContent.mutableRaw()[cbFile] = '\0';
|
---|
713 | rstrContent.jolt();
|
---|
714 |
|
---|
715 | RTTESTI_CHECK_RC_RET(RTFileClose(hFile), VINF_SUCCESS, false);
|
---|
716 |
|
---|
717 | return true;
|
---|
718 | }
|
---|
719 |
|
---|
720 | static void doTest1()
|
---|
721 | {
|
---|
722 | RTTestISub("tstUnattendedScript-1.template");
|
---|
723 |
|
---|
724 | /* Create the parent class instance: */
|
---|
725 | ComObjPtr<Unattended> ptrParent;
|
---|
726 | HRESULT hrc = ptrParent.createObject();
|
---|
727 | RTTESTI_CHECK_MSG_RETV(SUCCEEDED(hrc), ("hrc=%Rhrc\n", hrc));
|
---|
728 |
|
---|
729 | /* Instantiate the script editor. */
|
---|
730 | UnattendedScriptTemplate Tmpl(ptrParent, "template.ext", "file.ext");
|
---|
731 | #define CHECK_HRESULT(a_Expr) do { \
|
---|
732 | HRESULT hrcThis = a_Expr; \
|
---|
733 | if (SUCCEEDED(hrcThis)) break; \
|
---|
734 | RTTestIFailed("line %d: %s -> %Rhrc", __LINE__, #a_Expr, hrcThis); \
|
---|
735 | GlueHandleComError(ptrParent, NULL, hrcThis, NULL, __LINE__); \
|
---|
736 | } while (0)
|
---|
737 |
|
---|
738 | /* Load the exercise script. */
|
---|
739 | char szPath[RTPATH_MAX];
|
---|
740 | RTTESTI_CHECK_RC_RETV(RTPathExecDir(szPath, sizeof(szPath)), VINF_SUCCESS);
|
---|
741 | RTTESTI_CHECK_RC_RETV(RTPathAppend(szPath, sizeof(szPath), "tstUnattendedScript-1.template"), VINF_SUCCESS);
|
---|
742 | CHECK_HRESULT(Tmpl.read(szPath));
|
---|
743 |
|
---|
744 | /* Save the template to string. */
|
---|
745 | Utf8Str strActual;
|
---|
746 | CHECK_HRESULT(Tmpl.saveToString(strActual));
|
---|
747 |
|
---|
748 | /* Load the expected result. */
|
---|
749 | Utf8Str strExpected;
|
---|
750 | RTTESTI_CHECK_RETV(loadFileAsString("tstUnattendedScript-1.expected", strExpected));
|
---|
751 |
|
---|
752 | /* Compare the two. */
|
---|
753 | if (strExpected != strActual)
|
---|
754 | {
|
---|
755 | RTTestIFailed("Output does not match tstUnattendedScript-1.expected!");
|
---|
756 | RTTestIFailureDetails("------ BEGIN OUTPUT ------\n");
|
---|
757 | RTStrmWrite(g_pStdErr, strActual.c_str(), strActual.length());
|
---|
758 | RTTestIFailureDetails("------- END OUTPUT -------\n");
|
---|
759 |
|
---|
760 | RTCList<RTCString, RTCString *> const lstActual = strActual.split("\n");
|
---|
761 | RTCList<RTCString, RTCString *> const lstExpected = strExpected.split("\n");
|
---|
762 | size_t const cLines = RT_MIN(lstActual.size(), lstExpected.size());
|
---|
763 | for (size_t i = 0; i < cLines; i++)
|
---|
764 | if (lstActual[i] != lstExpected[i])
|
---|
765 | {
|
---|
766 | RTTestIFailureDetails("First difference on line %u:\n%s\nexpected:\n%s\n",
|
---|
767 | i + 1, lstActual[i].c_str(), lstExpected[i].c_str());
|
---|
768 | break;
|
---|
769 | }
|
---|
770 | }
|
---|
771 | }
|
---|
772 |
|
---|
773 | int main()
|
---|
774 | {
|
---|
775 | RTTEST hTest;
|
---|
776 | RTEXITCODE rcExit = RTTestInitAndCreate("tstUnattendedScript", &hTest);
|
---|
777 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
778 | return rcExit;
|
---|
779 |
|
---|
780 | #ifdef RT_OS_WINDOWS
|
---|
781 | /*ATL::CComModule *g_pAtlComModule = */ new(ATL::CComModule);
|
---|
782 | #endif
|
---|
783 |
|
---|
784 | doTest1();
|
---|
785 |
|
---|
786 | return RTTestSummaryAndDestroy(hTest);
|
---|
787 | }
|
---|