VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/tstUnattendedScript.cpp@ 105006

Last change on this file since 105006 was 102534, checked in by vboxsync, 12 months ago

Main/Unattended: Renamed the attribute "IUnattended::password" to "IUnattended::userPassword". Added new getter/setter attribute "IUnattended::adminPassword", to set a dedicated admin / root password. If not specified explicitly, the password from "IUnattended::userPassword" will be used. Extended testcases. bugref:10554

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette