VirtualBox

Changeset 95140 in vbox for trunk/src/VBox/Main/testcase


Ignore:
Timestamp:
May 31, 2022 9:11:39 AM (3 years ago)
Author:
vboxsync
Message:

Frontends + Main: Adjust to the new rules wrt. to rc -> hrc,vrc usage. This also fixes quite a few bugs wrt shadow variables, wrong return values and output error translations / exit codes. Also see @todos added. ​​bugref:10223

Location:
trunk/src/VBox/Main/testcase
Files:
2 edited

Legend:

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

    r93115 r95140  
    5757HRESULT readAndChangeMachineSettings(IMachine *machine, IMachine *readonlyMachine = 0)
    5858{
    59     HRESULT rc = S_OK;
     59    HRESULT hrc = S_OK;
    6060
    6161    Bstr name;
    6262    RTPrintf("Getting machine name...\n");
    63     CHECK_ERROR_RET(machine, COMGETTER(Name)(name.asOutParam()), rc);
     63    CHECK_ERROR_RET(machine, COMGETTER(Name)(name.asOutParam()), hrc);
    6464    RTPrintf("Name: {%ls}\n", name.raw());
    6565
     
    6767    Bstr guid;
    6868    CHECK_ERROR(machine, COMGETTER(Id)(guid.asOutParam()));
    69     if (SUCCEEDED(rc) && !guid.isEmpty()) {
     69    if (SUCCEEDED(hrc) && !guid.isEmpty()) {
    7070        RTPrintf("Guid::toString(): {%s}\n", Utf8Str(guid).c_str());
    7171    } else {
     
    7575    ULONG memorySize;
    7676    RTPrintf("Getting memory size...\n");
    77     CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySize), rc);
     77    CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySize), hrc);
    7878    RTPrintf("Memory size: %d\n", memorySize);
    7979
    8080    MachineState_T machineState;
    8181    RTPrintf("Getting machine state...\n");
    82     CHECK_ERROR_RET(machine, COMGETTER(State)(&machineState), rc);
     82    CHECK_ERROR_RET(machine, COMGETTER(State)(&machineState), hrc);
    8383    RTPrintf("Machine state: %d\n", machineState);
    8484
     
    8686    RTPrintf("Are any settings modified?...\n");
    8787    CHECK_ERROR(machine, COMGETTER(SettingsModified)(&modified));
    88     if (SUCCEEDED(rc))
     88    if (SUCCEEDED(hrc))
    8989        RTPrintf("%s\n", modified ? "yes" : "no");
    9090
     
    9393    CHECK_ERROR(machine, COMSETTER(MemorySize)(memorySizeBig));
    9494
    95     if (SUCCEEDED(rc))
     95    if (SUCCEEDED(hrc))
    9696    {
    9797        RTPrintf("Are any settings modified now?...\n");
    98         CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), rc);
     98        CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), hrc);
    9999        RTPrintf("%s\n", modified ? "yes" : "no");
    100100        ASSERT_RET(modified, 0);
     
    102102        ULONG memorySizeGot;
    103103        RTPrintf("Getting memory size again...\n");
    104         CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySizeGot), rc);
     104        CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySizeGot), hrc);
    105105        RTPrintf("Memory size: %d\n", memorySizeGot);
    106106        ASSERT_RET(memorySizeGot == memorySizeBig, 0);
     
    116116
    117117        RTPrintf("Discarding recent changes...\n");
    118         CHECK_ERROR_RET(machine, DiscardSettings(), rc);
     118        CHECK_ERROR_RET(machine, DiscardSettings(), hrc);
    119119        RTPrintf("Are any settings modified after discarding?...\n");
    120         CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), rc);
     120        CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), hrc);
    121121        RTPrintf("%s\n", modified ? "yes" : "no");
    122122        ASSERT_RET(!modified, 0);
    123123
    124124        RTPrintf("Getting memory size once more...\n");
    125         CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySizeGot), rc);
     125        CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySizeGot), hrc);
    126126        RTPrintf("Memory size: %d\n", memorySizeGot);
    127127        ASSERT_RET(memorySizeGot == memorySize, 0);
     
    129129        memorySize = memorySize > 128 ? memorySize / 2 : memorySize * 2;
    130130        RTPrintf("Changing memory size to %d...\n", memorySize);
    131         CHECK_ERROR_RET(machine, COMSETTER(MemorySize)(memorySize), rc);
     131        CHECK_ERROR_RET(machine, COMSETTER(MemorySize)(memorySize), hrc);
    132132    }
    133133
    134134    Bstr desc;
    135135    RTPrintf("Getting description...\n");
    136     CHECK_ERROR_RET(machine, COMGETTER(Description)(desc.asOutParam()), rc);
     136    CHECK_ERROR_RET(machine, COMGETTER(Description)(desc.asOutParam()), hrc);
    137137    RTPrintf("Description is: \"%ls\"\n", desc.raw());
    138138
    139139    desc = L"This is an exemplary description (changed).";
    140140    RTPrintf("Setting description to \"%ls\"...\n", desc.raw());
    141     CHECK_ERROR_RET(machine, COMSETTER(Description)(desc.raw()), rc);
     141    CHECK_ERROR_RET(machine, COMSETTER(Description)(desc.raw()), hrc);
    142142
    143143    RTPrintf("Saving machine settings...\n");
    144144    CHECK_ERROR(machine, SaveSettings());
    145     if (SUCCEEDED(rc))
     145    if (SUCCEEDED(hrc))
    146146    {
    147147        RTPrintf("Are any settings modified after saving?...\n");
    148         CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), rc);
     148        CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), hrc);
    149149        RTPrintf("%s\n", modified ? "yes" : "no");
    150150        ASSERT_RET(!modified, 0);
     
    162162    Bstr extraData;
    163163    RTPrintf("Getting extra data key {%ls}...\n", extraDataKey.raw());
    164     CHECK_ERROR_RET(machine, GetExtraData(extraDataKey.raw(), extraData.asOutParam()), rc);
     164    CHECK_ERROR_RET(machine, GetExtraData(extraDataKey.raw(), extraData.asOutParam()), hrc);
    165165    if (!extraData.isEmpty()) {
    166166        RTPrintf("Extra data value: {%ls}\n", extraData.raw());
     
    177177    CHECK_ERROR(machine, SetExtraData(extraDataKey.raw(), extraData.raw()));
    178178
    179     if (SUCCEEDED(rc)) {
     179    if (SUCCEEDED(hrc)) {
    180180        RTPrintf("Getting extra data key {%ls} again...\n", extraDataKey.raw());
    181         CHECK_ERROR_RET(machine, GetExtraData(extraDataKey.raw(), extraData.asOutParam()), rc);
     181        CHECK_ERROR_RET(machine, GetExtraData(extraDataKey.raw(), extraData.asOutParam()), hrc);
    182182        if (!extraData.isEmpty()) {
    183183            RTPrintf("Extra data value: {%ls}\n", extraData.raw());
     
    187187    }
    188188
    189     return rc;
     189    return hrc;
    190190}
    191191
     
    201201    RTR3InitExe(argc, &argv, 0);
    202202
    203     HRESULT rc;
     203    HRESULT hrc;
    204204
    205205    {
     
    211211    RTPrintf("Initializing COM...\n");
    212212
    213     rc = com::Initialize();
    214     if (FAILED(rc))
     213    hrc = com::Initialize();
     214    if (FAILED(hrc))
    215215    {
    216216        RTPrintf("ERROR: failed to initialize COM!\n");
    217         return rc;
     217        return hrc;
    218218    }
    219219
     
    243243
    244244    RTPrintf("Creating VirtualBox object...\n");
    245     rc = virtualBoxClient.createInprocObject(CLSID_VirtualBoxClient);
    246     if (SUCCEEDED(rc))
    247         rc = virtualBoxClient->COMGETTER(VirtualBox)(virtualBox.asOutParam());
    248     if (FAILED(rc))
     245    hrc = virtualBoxClient.createInprocObject(CLSID_VirtualBoxClient);
     246    if (SUCCEEDED(hrc))
     247        hrc = virtualBoxClient->COMGETTER(VirtualBox)(virtualBox.asOutParam());
     248    if (FAILED(hrc))
    249249        RTPrintf("ERROR: failed to create the VirtualBox object!\n");
    250250    else
    251251    {
    252         rc = session.createInprocObject(CLSID_Session);
    253         if (FAILED(rc))
     252        hrc = session.createInprocObject(CLSID_Session);
     253        if (FAILED(hrc))
    254254            RTPrintf("ERROR: failed to create a session object!\n");
    255255    }
    256256
    257     if (FAILED(rc))
     257    if (FAILED(hrc))
    258258    {
    259259        com::ErrorInfo info;
    260260        if (!info.isFullAvailable() && !info.isBasicAvailable())
    261261        {
    262             com::GluePrintRCMessage(rc);
     262            com::GluePrintRCMessage(hrc);
    263263            RTPrintf("Most likely, the VirtualBox COM server is not running or failed to start.\n");
    264264        }
     
    15921592    RTPrintf("tstAPI FINISHED.\n");
    15931593
    1594     return rc;
     1594    return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
    15951595}
    15961596
  • trunk/src/VBox/Main/testcase/tstVBoxAPI.cpp

    r94660 r95140  
    5757static BOOL tstApiIVirtualBox(IVirtualBox *pVBox)
    5858{
    59     HRESULT rc;
     59    HRESULT hrc;
    6060    Bstr bstrTmp;
    6161    ULONG ulTmp;
     
    6363    RTTestSub(g_hTest, "IVirtualBox::version");
    6464    CHECK_ERROR(pVBox, COMGETTER(Version)(bstrTmp.asOutParam()));
    65     if (SUCCEEDED(rc))
     65    if (SUCCEEDED(hrc))
    6666        RTTestPassed(g_hTest, "IVirtualBox::version");
    6767    else
     
    7070    RTTestSub(g_hTest, "IVirtualBox::versionNormalized");
    7171    CHECK_ERROR(pVBox, COMGETTER(VersionNormalized)(bstrTmp.asOutParam()));
    72     if (SUCCEEDED(rc))
     72    if (SUCCEEDED(hrc))
    7373        RTTestPassed(g_hTest, "IVirtualBox::versionNormalized");
    7474    else
     
    7777    RTTestSub(g_hTest, "IVirtualBox::revision");
    7878    CHECK_ERROR(pVBox, COMGETTER(Revision)(&ulTmp));
    79     if (SUCCEEDED(rc))
     79    if (SUCCEEDED(hrc))
    8080        RTTestPassed(g_hTest, "IVirtualBox::revision");
    8181    else
     
    8484    RTTestSub(g_hTest, "IVirtualBox::packageType");
    8585    CHECK_ERROR(pVBox, COMGETTER(PackageType)(bstrTmp.asOutParam()));
    86     if (SUCCEEDED(rc))
     86    if (SUCCEEDED(hrc))
    8787        RTTestPassed(g_hTest, "IVirtualBox::packageType");
    8888    else
     
    9191    RTTestSub(g_hTest, "IVirtualBox::APIVersion");
    9292    CHECK_ERROR(pVBox, COMGETTER(APIVersion)(bstrTmp.asOutParam()));
    93     if (SUCCEEDED(rc))
     93    if (SUCCEEDED(hrc))
    9494        RTTestPassed(g_hTest, "IVirtualBox::APIVersion");
    9595    else
     
    9898    RTTestSub(g_hTest, "IVirtualBox::homeFolder");
    9999    CHECK_ERROR(pVBox, COMGETTER(HomeFolder)(bstrTmp.asOutParam()));
    100     if (SUCCEEDED(rc))
     100    if (SUCCEEDED(hrc))
    101101        RTTestPassed(g_hTest, "IVirtualBox::homeFolder");
    102102    else
     
    105105    RTTestSub(g_hTest, "IVirtualBox::settingsFilePath");
    106106    CHECK_ERROR(pVBox, COMGETTER(SettingsFilePath)(bstrTmp.asOutParam()));
    107     if (SUCCEEDED(rc))
     107    if (SUCCEEDED(hrc))
    108108        RTTestPassed(g_hTest, "IVirtualBox::settingsFilePath");
    109109    else
     
    113113    RTTestSub(g_hTest, "IVirtualBox::guestOSTypes");
    114114    CHECK_ERROR(pVBox, COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(guestOSTypes)));
    115     if (SUCCEEDED(rc))
     115    if (SUCCEEDED(hrc))
    116116        RTTestPassed(g_hTest, "IVirtualBox::guestOSTypes");
    117117    else
     
    132132                                     NULL,                          /** Password */
    133133                                     ptrMachine.asOutParam()));     /** Machine */
    134     if (SUCCEEDED(rc))
     134    if (SUCCEEDED(hrc))
    135135        RTTestPassed(g_hTest, "IVirtualBox::CreateMachine");
    136136    else
     
    142142    RTTestSub(g_hTest, "IVirtualBox::RegisterMachine");
    143143    CHECK_ERROR(pVBox, RegisterMachine(ptrMachine));
    144     if (SUCCEEDED(rc))
     144    if (SUCCEEDED(hrc))
    145145        RTTestPassed(g_hTest, "IVirtualBox::RegisterMachine");
    146146    else
     
    153153    RTTestSub(g_hTest, "IVirtualBox::host");
    154154    CHECK_ERROR(pVBox, COMGETTER(Host)(host.asOutParam()));
    155     if (SUCCEEDED(rc))
     155    if (SUCCEEDED(hrc))
    156156    {
    157157        /** @todo Add IHost testing here. */
     
    164164    RTTestSub(g_hTest, "IVirtualBox::systemProperties");
    165165    CHECK_ERROR(pVBox, COMGETTER(SystemProperties)(sysprop.asOutParam()));
    166     if (SUCCEEDED(rc))
     166    if (SUCCEEDED(hrc))
    167167    {
    168168        /** @todo Add ISystemProperties testing here. */
     
    175175    RTTestSub(g_hTest, "IVirtualBox::machines");
    176176    CHECK_ERROR(pVBox, COMGETTER(Machines)(ComSafeArrayAsOutParam(machines)));
    177     if (SUCCEEDED(rc))
     177    if (SUCCEEDED(hrc))
    178178    {
    179179        bool bFound = FALSE;
     
    183183            {
    184184                Bstr tmpName;
    185                 rc = machines[i]->COMGETTER(Name)(tmpName.asOutParam());
    186                 if (SUCCEEDED(rc))
     185                hrc = machines[i]->COMGETTER(Name)(tmpName.asOutParam());
     186                if (SUCCEEDED(hrc))
    187187                {
    188188                    if (tmpName == tstMachineName)
     
    219219    RTTestSub(g_hTest, "IVirtualBox::hardDisks");
    220220    CHECK_ERROR(pVBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hardDisks)));
    221     if (SUCCEEDED(rc))
     221    if (SUCCEEDED(hrc))
    222222    {
    223223        /** @todo Add hardDisks testing here. */
     
    230230    RTTestSub(g_hTest, "IVirtualBox::DVDImages");
    231231    CHECK_ERROR(pVBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(DVDImages)));
    232     if (SUCCEEDED(rc))
     232    if (SUCCEEDED(hrc))
    233233    {
    234234        /** @todo Add DVDImages testing here. */
     
    241241    RTTestSub(g_hTest, "IVirtualBox::floppyImages");
    242242    CHECK_ERROR(pVBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppyImages)));
    243     if (SUCCEEDED(rc))
     243    if (SUCCEEDED(hrc))
    244244    {
    245245        /** @todo Add floppyImages testing here. */
     
    252252    RTTestSub(g_hTest, "IVirtualBox::progressOperations");
    253253    CHECK_ERROR(pVBox, COMGETTER(ProgressOperations)(ComSafeArrayAsOutParam(progressOperations)));
    254     if (SUCCEEDED(rc))
     254    if (SUCCEEDED(hrc))
    255255    {
    256256        /** @todo Add IProgress testing here. */
     
    263263    RTTestSub(g_hTest, "IVirtualBox::performanceCollector");
    264264    CHECK_ERROR(pVBox, COMGETTER(PerformanceCollector)(performanceCollector.asOutParam()));
    265     if (SUCCEEDED(rc))
     265    if (SUCCEEDED(hrc))
    266266    {
    267267        /** @todo Add IPerformanceCollector testing here. */
     
    274274    RTTestSub(g_hTest, "IVirtualBox::DHCPServers");
    275275    CHECK_ERROR(pVBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(DHCPServers)));
    276     if (SUCCEEDED(rc))
     276    if (SUCCEEDED(hrc))
    277277    {
    278278        /** @todo Add IDHCPServers testing here. */
     
    285285    RTTestSub(g_hTest, "IVirtualBox::NATNetworks");
    286286    CHECK_ERROR(pVBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(NATNetworks)));
    287     if (SUCCEEDED(rc))
     287    if (SUCCEEDED(hrc))
    288288    {
    289289        /** @todo Add INATNetworks testing here. */
     
    296296    RTTestSub(g_hTest, "IVirtualBox::eventSource");
    297297    CHECK_ERROR(pVBox, COMGETTER(EventSource)(eventSource.asOutParam()));
    298     if (SUCCEEDED(rc))
     298    if (SUCCEEDED(hrc))
    299299    {
    300300        /** @todo Add IEventSource testing here. */
     
    307307    RTTestSub(g_hTest, "IVirtualBox::extensionPackManager");
    308308    CHECK_ERROR(pVBox, COMGETTER(ExtensionPackManager)(extensionPackManager.asOutParam()));
    309     if (SUCCEEDED(rc))
     309    if (SUCCEEDED(hrc))
    310310    {
    311311        /** @todo Add IExtPackManager testing here. */
     
    318318    RTTestSub(g_hTest, "IVirtualBox::internalNetworks");
    319319    CHECK_ERROR(pVBox, COMGETTER(InternalNetworks)(ComSafeArrayAsOutParam(internalNetworks)));
    320     if (SUCCEEDED(rc))
     320    if (SUCCEEDED(hrc))
    321321    {
    322322        RTTestPassed(g_hTest, "IVirtualBox::internalNetworks");
     
    328328    RTTestSub(g_hTest, "IVirtualBox::genericNetworkDrivers");
    329329    CHECK_ERROR(pVBox, COMGETTER(GenericNetworkDrivers)(ComSafeArrayAsOutParam(genericNetworkDrivers)));
    330     if (SUCCEEDED(rc))
     330    if (SUCCEEDED(hrc))
    331331    {
    332332        RTTestPassed(g_hTest, "IVirtualBox::genericNetworkDrivers");
     
    341341static BOOL tstApiClean(IVirtualBox *pVBox)
    342342{
    343     HRESULT rc;
     343    HRESULT hrc;
    344344
    345345    /** Delete created VM and its files */
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