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