VirtualBox

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

最後變更 在這個檔案是 108362,由 vboxsync 提交於 3 週 前

Unattended: bugref:10864. build fix.

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

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