VirtualBox

Changeset 50397 in vbox


Ignore:
Timestamp:
Feb 10, 2014 4:04:15 PM (11 years ago)
Author:
vboxsync
Message:

Show full error info and remove test VM files before exit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/testcase/tstVBoxAPI.cpp

    r50390 r50397  
    2525#include <VBox/com/Guid.h>
    2626#include <VBox/com/ErrorInfo.h>
     27#include <VBox/com/errorprint.h>
    2728#include <VBox/com/VirtualBox.h>
    2829#include <VBox/sup.h>
     
    5455
    5556
    56 static void tstApiIVirtualBox(IVirtualBox *pVBox)
     57static BOOL tstApiIVirtualBox(IVirtualBox *pVBox)
    5758{
    58     HRESULT hrc;
     59    HRESULT rc;
    5960    Bstr bstrTmp;
    6061    ULONG ulTmp;
    6162
    6263    RTTestSub(g_hTest, "IVirtualBox::version");
    63     hrc = pVBox->COMGETTER(Version)(bstrTmp.asOutParam());
    64     if (SUCCEEDED(hrc))
     64    CHECK_ERROR(pVBox, COMGETTER(Version)(bstrTmp.asOutParam()));
     65    if (SUCCEEDED(rc))
    6566        RTTestPassed(g_hTest, "IVirtualBox::version");
    6667    else
    67         RTTestFailed(g_hTest, "%d: IVirtualBox::version failed with return value %Rhrc.", __LINE__, hrc);
     68        RTTestFailed(g_hTest, "%d: IVirtualBox::version failed", __LINE__);
    6869
    6970    RTTestSub(g_hTest, "IVirtualBox::versionNormalized");
    70     hrc = pVBox->COMGETTER(VersionNormalized)(bstrTmp.asOutParam());
    71     if (SUCCEEDED(hrc))
     71    CHECK_ERROR(pVBox, COMGETTER(VersionNormalized)(bstrTmp.asOutParam()));
     72    if (SUCCEEDED(rc))
    7273        RTTestPassed(g_hTest, "IVirtualBox::versionNormalized");
    7374    else
    74         RTTestFailed(g_hTest, "%d: IVirtualBox::versionNormalized failed with return value %Rhrc.", __LINE__, hrc);
     75        RTTestFailed(g_hTest, "%d: IVirtualBox::versionNormalized failed", __LINE__);
    7576
    7677    RTTestSub(g_hTest, "IVirtualBox::revision");
    77     hrc = pVBox->COMGETTER(Revision)(&ulTmp);
    78     if (SUCCEEDED(hrc))
     78    CHECK_ERROR(pVBox, COMGETTER(Revision)(&ulTmp));
     79    if (SUCCEEDED(rc))
    7980        RTTestPassed(g_hTest, "IVirtualBox::revision");
    8081    else
    81         RTTestFailed(g_hTest, "%d: IVirtualBox::revision failed with return value %Rhrc.", __LINE__, hrc);
     82        RTTestFailed(g_hTest, "%d: IVirtualBox::revision failed", __LINE__);
    8283
    8384    RTTestSub(g_hTest, "IVirtualBox::packageType");
    84     hrc = pVBox->COMGETTER(PackageType)(bstrTmp.asOutParam());
    85     if (SUCCEEDED(hrc))
     85    CHECK_ERROR(pVBox, COMGETTER(PackageType)(bstrTmp.asOutParam()));
     86    if (SUCCEEDED(rc))
    8687        RTTestPassed(g_hTest, "IVirtualBox::packageType");
    8788    else
    88         RTTestFailed(g_hTest, "%d: IVirtualBox::packageType failed with return value %Rhrc.", __LINE__, hrc);
     89        RTTestFailed(g_hTest, "%d: IVirtualBox::packageType failed", __LINE__);
    8990
    9091    RTTestSub(g_hTest, "IVirtualBox::APIVersion");
    91     hrc = pVBox->COMGETTER(APIVersion)(bstrTmp.asOutParam());
    92     if (SUCCEEDED(hrc))
     92    CHECK_ERROR(pVBox, COMGETTER(APIVersion)(bstrTmp.asOutParam()));
     93    if (SUCCEEDED(rc))
    9394        RTTestPassed(g_hTest, "IVirtualBox::APIVersion");
    9495    else
    95         RTTestFailed(g_hTest, "%d: IVirtualBox::APIVersion failed with return value %Rhrc.", __LINE__, hrc);
     96        RTTestFailed(g_hTest, "%d: IVirtualBox::APIVersion failed", __LINE__);
    9697
    9798    RTTestSub(g_hTest, "IVirtualBox::homeFolder");
    98     hrc = pVBox->COMGETTER(HomeFolder)(bstrTmp.asOutParam());
    99     if (SUCCEEDED(hrc))
     99    CHECK_ERROR(pVBox, COMGETTER(HomeFolder)(bstrTmp.asOutParam()));
     100    if (SUCCEEDED(rc))
    100101        RTTestPassed(g_hTest, "IVirtualBox::homeFolder");
    101102    else
    102         RTTestFailed(g_hTest, "%d: IVirtualBox::homeFolder failed with return value %Rhrc.", __LINE__, hrc);
     103        RTTestFailed(g_hTest, "%d: IVirtualBox::homeFolder failed", __LINE__);
    103104
    104105    RTTestSub(g_hTest, "IVirtualBox::settingsFilePath");
    105     hrc = pVBox->COMGETTER(SettingsFilePath)(bstrTmp.asOutParam());
    106     if (SUCCEEDED(hrc))
     106    CHECK_ERROR(pVBox, COMGETTER(SettingsFilePath)(bstrTmp.asOutParam()));
     107    if (SUCCEEDED(rc))
    107108        RTTestPassed(g_hTest, "IVirtualBox::settingsFilePath");
    108109    else
    109         RTTestFailed(g_hTest, "%d: IVirtualBox::settingsFilePath failed with return value %Rhrc.", __LINE__, hrc);
     110        RTTestFailed(g_hTest, "%d: IVirtualBox::settingsFilePath failed", __LINE__);
    110111
    111112    com::SafeIfaceArray<IGuestOSType> guestOSTypes;
    112113    RTTestSub(g_hTest, "IVirtualBox::guestOSTypes");
    113     hrc = pVBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(guestOSTypes));
    114     if (SUCCEEDED(hrc))
     114    CHECK_ERROR(pVBox, COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(guestOSTypes)));
     115    if (SUCCEEDED(rc))
    115116        RTTestPassed(g_hTest, "IVirtualBox::guestOSTypes");
    116117    else
    117         RTTestFailed(g_hTest, "%d: IVirtualBox::guestOSTypes failed with return value %Rhrc.", __LINE__, hrc);
     118        RTTestFailed(g_hTest, "%d: IVirtualBox::guestOSTypes failed", __LINE__);
    118119
    119120    /** Create VM */
    120121    RTTestSub(g_hTest, "IVirtualBox::CreateMachine");
    121122    ComPtr<IMachine> ptrMachine;
    122     Bstr tstMachineName = "TestMachine";
     123    Bstr tstMachineName = "tstVBoxAPI test VM";
    123124    com::SafeArray<BSTR> groups;
    124125    /** Default VM settings */
    125     hrc = pVBox->CreateMachine(NULL,                          /** Settings */
    126                                tstMachineName.raw(),          /** Name */
    127                                ComSafeArrayAsInParam(groups), /** Groups */
    128                                NULL,                          /** OS Type */
    129                                NULL,                          /** Create flags */
    130                                ptrMachine.asOutParam());      /** Machine */
    131     if (SUCCEEDED(hrc))
     126    CHECK_ERROR(pVBox, CreateMachine(NULL,                          /** Settings */
     127                                     tstMachineName.raw(),          /** Name */
     128                                     ComSafeArrayAsInParam(groups), /** Groups */
     129                                     NULL,                          /** OS Type */
     130                                     NULL,                          /** Create flags */
     131                                     ptrMachine.asOutParam()));     /** Machine */
     132    if (SUCCEEDED(rc))
    132133        RTTestPassed(g_hTest, "IVirtualBox::CreateMachine");
    133134    else
    134135    {
    135         RTTestFailed(g_hTest, "%d: IVirtualBox::CreateMachine failed with return value %Rhrc.", __LINE__, hrc);
    136         return;
     136        RTTestFailed(g_hTest, "%d: IVirtualBox::CreateMachine failed", __LINE__);
     137        return FALSE;
    137138    }
    138139
    139140    RTTestSub(g_hTest, "IVirtualBox::RegisterMachine");
    140     hrc = pVBox->RegisterMachine(ptrMachine);
    141     if (SUCCEEDED(hrc))
     141    CHECK_ERROR(pVBox, RegisterMachine(ptrMachine));
     142    if (SUCCEEDED(rc))
    142143        RTTestPassed(g_hTest, "IVirtualBox::RegisterMachine");
    143144    else
    144145    {
    145         RTTestFailed(g_hTest, "%d: IVirtualBox::RegisterMachine failed with return value %Rhrc.", __LINE__, hrc);
    146         return;
     146        RTTestFailed(g_hTest, "%d: IVirtualBox::RegisterMachine failed", __LINE__);
     147        return FALSE;
    147148    }
    148149
    149150    ComPtr<IHost> host;
    150151    RTTestSub(g_hTest, "IVirtualBox::host");
    151     hrc = pVBox->COMGETTER(Host)(host.asOutParam());
    152     if (SUCCEEDED(hrc))
     152    CHECK_ERROR(pVBox, COMGETTER(Host)(host.asOutParam()));
     153    if (SUCCEEDED(rc))
    153154    {
    154155        /** @todo Add IHost testing here. */
     
    156157    }
    157158    else
    158         RTTestFailed(g_hTest, "%d: IVirtualBox::host failed with return value %Rhrc.", __LINE__, hrc);
     159        RTTestFailed(g_hTest, "%d: IVirtualBox::host failed", __LINE__);
    159160
    160161    ComPtr<ISystemProperties> sysprop;
    161162    RTTestSub(g_hTest, "IVirtualBox::systemProperties");
    162     hrc = pVBox->COMGETTER(SystemProperties)(sysprop.asOutParam());
    163     if (SUCCEEDED(hrc))
     163    CHECK_ERROR(pVBox, COMGETTER(SystemProperties)(sysprop.asOutParam()));
     164    if (SUCCEEDED(rc))
    164165    {
    165166        /** @todo Add ISystemProperties testing here. */
     
    167168    }
    168169    else
    169         RTTestFailed(g_hTest, "%d: IVirtualBox::systemProperties failed with return value %Rhrc.", __LINE__, hrc);
     170        RTTestFailed(g_hTest, "%d: IVirtualBox::systemProperties failed", __LINE__);
    170171
    171172    com::SafeIfaceArray<IMachine> machines;
    172173    RTTestSub(g_hTest, "IVirtualBox::machines");
    173     hrc = pVBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
    174     if (SUCCEEDED(hrc))
     174    CHECK_ERROR(pVBox, COMGETTER(Machines)(ComSafeArrayAsOutParam(machines)));
     175    if (SUCCEEDED(rc))
    175176    {
    176177        bool bFound = FALSE;
     
    180181            {
    181182                Bstr tmpName;
    182                 hrc = machines[i]->COMGETTER(Name)(tmpName.asOutParam());
    183                 if (SUCCEEDED(hrc))
     183                CHECK_ERROR(machines[i], COMGETTER(Name)(tmpName.asOutParam()));
     184                if (SUCCEEDED(rc))
    184185                {
    185186                    if (tmpName == tstMachineName)
     
    198199    }
    199200    else
    200         RTTestFailed(g_hTest, "%d: IVirtualBox::machines failed with return value %Rhrc.", __LINE__, hrc);
     201        RTTestFailed(g_hTest, "%d: IVirtualBox::machines failed", __LINE__);
    201202
    202203#if 0 /** Not yet implemented */
    203204    com::SafeIfaceArray<ISharedFolder> sharedFolders;
    204205    RTTestSub(g_hTest, "IVirtualBox::sharedFolders");
    205     hrc = pVBox->COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sharedFolders));
    206     if (SUCCEEDED(hrc))
     206    CHECK_ERROR(pVBox, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sharedFolders)));
     207    if (SUCCEEDED(rc))
    207208    {
    208209        /** @todo Add ISharedFolders testing here. */
     
    210211    }
    211212    else
    212         RTTestFailed(g_hTest, "%d: IVirtualBox::sharedFolders failed with return value %Rhrc.", __LINE__, hrc);
     213        RTTestFailed(g_hTest, "%d: IVirtualBox::sharedFolders failed", __LINE__);
    213214#endif
    214215
    215216    com::SafeIfaceArray<IMedium> hardDisks;
    216217    RTTestSub(g_hTest, "IVirtualBox::hardDisks");
    217     hrc = pVBox->COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hardDisks));
    218     if (SUCCEEDED(hrc))
     218    CHECK_ERROR(pVBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hardDisks)));
     219    if (SUCCEEDED(rc))
    219220    {
    220221        /** @todo Add hardDisks testing here. */
     
    222223    }
    223224    else
    224         RTTestFailed(g_hTest, "%d: IVirtualBox::hardDisks failed with return value %Rhrc.", __LINE__, hrc);
     225        RTTestFailed(g_hTest, "%d: IVirtualBox::hardDisks failed", __LINE__);
    225226
    226227    com::SafeIfaceArray<IMedium> DVDImages;
    227228    RTTestSub(g_hTest, "IVirtualBox::DVDImages");
    228     hrc = pVBox->COMGETTER(DVDImages)(ComSafeArrayAsOutParam(DVDImages));
    229     if (SUCCEEDED(hrc))
     229    CHECK_ERROR(pVBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(DVDImages)));
     230    if (SUCCEEDED(rc))
    230231    {
    231232        /** @todo Add DVDImages testing here. */
     
    233234    }
    234235    else
    235         RTTestFailed(g_hTest, "%d: IVirtualBox::DVDImages failed with return value %Rhrc.", __LINE__, hrc);
     236        RTTestFailed(g_hTest, "%d: IVirtualBox::DVDImages failed", __LINE__);
    236237
    237238    com::SafeIfaceArray<IMedium> floppyImages;
    238239    RTTestSub(g_hTest, "IVirtualBox::floppyImages");
    239     hrc = pVBox->COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppyImages));
    240     if (SUCCEEDED(hrc))
     240    CHECK_ERROR(pVBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppyImages)));
     241    if (SUCCEEDED(rc))
    241242    {
    242243        /** @todo Add floppyImages testing here. */
     
    244245    }
    245246    else
    246         RTTestFailed(g_hTest, "%d: IVirtualBox::floppyImages failed with return value %Rhrc.", __LINE__, hrc);
     247        RTTestFailed(g_hTest, "%d: IVirtualBox::floppyImages failed", __LINE__);
    247248
    248249    com::SafeIfaceArray<IProgress> progressOperations;
    249250    RTTestSub(g_hTest, "IVirtualBox::progressOperations");
    250     hrc = pVBox->COMGETTER(ProgressOperations)(ComSafeArrayAsOutParam(progressOperations));
    251     if (SUCCEEDED(hrc))
     251    CHECK_ERROR(pVBox, COMGETTER(ProgressOperations)(ComSafeArrayAsOutParam(progressOperations)));
     252    if (SUCCEEDED(rc))
    252253    {
    253254        /** @todo Add IProgress testing here. */
     
    255256    }
    256257    else
    257         RTTestFailed(g_hTest, "%d: IVirtualBox::progressOperations failed with return value %Rhrc.", __LINE__, hrc);
     258        RTTestFailed(g_hTest, "%d: IVirtualBox::progressOperations failed", __LINE__);
    258259
    259260    ComPtr<IPerformanceCollector> performanceCollector;
    260261    RTTestSub(g_hTest, "IVirtualBox::performanceCollector");
    261     hrc = pVBox->COMGETTER(PerformanceCollector)(performanceCollector.asOutParam());
    262     if (SUCCEEDED(hrc))
     262    CHECK_ERROR(pVBox, COMGETTER(PerformanceCollector)(performanceCollector.asOutParam()));
     263    if (SUCCEEDED(rc))
    263264    {
    264265        /** @todo Add IPerformanceCollector testing here. */
     
    266267    }
    267268    else
    268         RTTestFailed(g_hTest, "%d: IVirtualBox::performanceCollector failed with return value %Rhrc.", __LINE__, hrc);
     269        RTTestFailed(g_hTest, "%d: IVirtualBox::performanceCollector failed", __LINE__);
    269270
    270271    com::SafeIfaceArray<IDHCPServer> DHCPServers;
    271272    RTTestSub(g_hTest, "IVirtualBox::DHCPServers");
    272     hrc = pVBox->COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(DHCPServers));
    273     if (SUCCEEDED(hrc))
     273    CHECK_ERROR(pVBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(DHCPServers)));
     274    if (SUCCEEDED(rc))
    274275    {
    275276        /** @todo Add IDHCPServers testing here. */
     
    277278    }
    278279    else
    279         RTTestFailed(g_hTest, "%d: IVirtualBox::DHCPServers failed with return value %Rhrc.", __LINE__, hrc);
     280        RTTestFailed(g_hTest, "%d: IVirtualBox::DHCPServers failed", __LINE__);
    280281
    281282    com::SafeIfaceArray<INATNetwork> NATNetworks;
    282283    RTTestSub(g_hTest, "IVirtualBox::NATNetworks");
    283     hrc = pVBox->COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(NATNetworks));
    284     if (SUCCEEDED(hrc))
     284    CHECK_ERROR(pVBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(NATNetworks)));
     285    if (SUCCEEDED(rc))
    285286    {
    286287        /** @todo Add INATNetworks testing here. */
     
    288289    }
    289290    else
    290         RTTestFailed(g_hTest, "%d: IVirtualBox::NATNetworks failed with return value %Rhrc.", __LINE__, hrc);
     291        RTTestFailed(g_hTest, "%d: IVirtualBox::NATNetworks failed", __LINE__);
    291292
    292293    ComPtr<IEventSource> eventSource;
    293294    RTTestSub(g_hTest, "IVirtualBox::eventSource");
    294     hrc = pVBox->COMGETTER(EventSource)(eventSource.asOutParam());
    295     if (SUCCEEDED(hrc))
     295    CHECK_ERROR(pVBox, COMGETTER(EventSource)(eventSource.asOutParam()));
     296    if (SUCCEEDED(rc))
    296297    {
    297298        /** @todo Add IEventSource testing here. */
     
    299300    }
    300301    else
    301         RTTestFailed(g_hTest, "%d: IVirtualBox::eventSource failed with return value %Rhrc.", __LINE__, hrc);
     302        RTTestFailed(g_hTest, "%d: IVirtualBox::eventSource failed", __LINE__);
    302303
    303304    ComPtr<IExtPackManager> extensionPackManager;
    304305    RTTestSub(g_hTest, "IVirtualBox::extensionPackManager");
    305     hrc = pVBox->COMGETTER(ExtensionPackManager)(extensionPackManager.asOutParam());
    306     if (SUCCEEDED(hrc))
     306    CHECK_ERROR(pVBox, COMGETTER(ExtensionPackManager)(extensionPackManager.asOutParam()));
     307    if (SUCCEEDED(rc))
    307308    {
    308309        /** @todo Add IExtPackManager testing here. */
     
    310311    }
    311312    else
    312         RTTestFailed(g_hTest, "%d: IVirtualBox::extensionPackManager failed with return value %Rhrc.", __LINE__, hrc);
     313        RTTestFailed(g_hTest, "%d: IVirtualBox::extensionPackManager failed", __LINE__);
    313314
    314315    com::SafeArray<BSTR> internalNetworks;
    315316    RTTestSub(g_hTest, "IVirtualBox::internalNetworks");
    316     hrc = pVBox->COMGETTER(InternalNetworks)(ComSafeArrayAsOutParam(internalNetworks));
    317     if (SUCCEEDED(hrc))
     317    CHECK_ERROR(pVBox, COMGETTER(InternalNetworks)(ComSafeArrayAsOutParam(internalNetworks)));
     318    if (SUCCEEDED(rc))
    318319    {
    319320        RTTestPassed(g_hTest, "IVirtualBox::internalNetworks");
    320321    }
    321322    else
    322         RTTestFailed(g_hTest, "%d: IVirtualBox::internalNetworks failed with return value %Rhrc.", __LINE__, hrc);
     323        RTTestFailed(g_hTest, "%d: IVirtualBox::internalNetworks failed", __LINE__);
    323324
    324325    com::SafeArray<BSTR> genericNetworkDrivers;
    325326    RTTestSub(g_hTest, "IVirtualBox::genericNetworkDrivers");
    326     hrc = pVBox->COMGETTER(GenericNetworkDrivers)(ComSafeArrayAsOutParam(genericNetworkDrivers));
    327     if (SUCCEEDED(hrc))
     327    CHECK_ERROR(pVBox, COMGETTER(GenericNetworkDrivers)(ComSafeArrayAsOutParam(genericNetworkDrivers)));
     328    if (SUCCEEDED(rc))
    328329    {
    329330        RTTestPassed(g_hTest, "IVirtualBox::genericNetworkDrivers");
    330331    }
    331332    else
    332         RTTestFailed(g_hTest, "%d: IVirtualBox::genericNetworkDrivers failed with return value %Rhrc.", __LINE__, hrc);
     333        RTTestFailed(g_hTest, "%d: IVirtualBox::genericNetworkDrivers failed", __LINE__);
     334
     335    /** Delete created VM and its files */
     336    ComPtr<IMachine> machine;
     337    CHECK_ERROR_RET(pVBox, FindMachine(Bstr(tstMachineName).raw(), machine.asOutParam()), FALSE);
     338    SafeIfaceArray<IMedium> media;
     339    CHECK_ERROR_RET(machine, Unregister(CleanupMode_DetachAllReturnHardDisksOnly,
     340                                    ComSafeArrayAsOutParam(media)), FALSE);
     341    ComPtr<IProgress> progress;
     342    CHECK_ERROR_RET(machine, DeleteConfig(ComSafeArrayAsInParam(media), progress.asOutParam()), FALSE);
     343    CHECK_ERROR_RET(progress, WaitForCompletion(-1), FALSE);
     344
     345    return TRUE;
    333346}
    334347
Note: See TracChangeset for help on using the changeset viewer.

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