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