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