VirtualBox

Changeset 50339 in vbox


Ignore:
Timestamp:
Feb 6, 2014 10:30:07 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
92072
Message:

Main/testcase: beat some sense into the XPCOM sample code, it was meant to be standalone, and actually was anything but separately compilable due to using IPRT. Fixed the template which is used for building the code, so that this will not slip through again, letting it be so unusable for a long time.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/testcase/Makefile.kmk

    r49951 r50339  
    55
    66#
    7 # Copyright (C) 2004-2013 Oracle Corporation
     7# Copyright (C) 2004-2014 Oracle Corporation
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    102102# It comes with a custom makefile which should be tested as well!
    103103#
    104 tstVBoxAPIXPCOM_TEMPLATE = VBOXMAINCLIENTTSTEXE
     104# Use very generic template to make the build environment similar
     105# to the standalone case, to detect if IPRT or glue use sneaks in.
     106#
     107tstVBoxAPIXPCOM_TEMPLATE = VBoxBldProg
     108tstVBoxAPIXPCOM_INST = $(INST_TESTCASE)
    105109tstVBoxAPIXPCOM_SOURCES  = tstVBoxAPIXPCOM.cpp
     110tstVBoxAPIXPCOM_INCS = \
     111        $(VBOX_PATH_SDK)/bindings/xpcom/include \
     112        $(VBOX_PATH_SDK)/bindings/xpcom/include/nsprpub \
     113        $(VBOX_PATH_SDK)/bindings/xpcom/include/string \
     114        $(VBOX_PATH_SDK)/bindings/xpcom/include/xpcom \
     115        $(VBOX_PATH_SDK)/bindings/xpcom/include/ipcd
     116tstVBoxAPIXPCOM_LIBS = \
     117        $(LIB_XPCOM)
     118tstVBoxAPIXPCOM_CXXFLAGS = -fshort-wchar
     119ifdef VBOX_WITH_RUNPATH
     120 tstVBoxAPIXPCOM_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' $(TEMPLATE_VBoxBldProg_LDFLAGS)
     121else ifdef VBOX_WITH_RELATIVE_RUNPATH
     122 tstVBoxAPIXPCOM_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/..' $(TEMPLATE_VBoxBldProg_LDFLAGS)
     123endif
     124tstVBoxAPIXPCOM_INTERMEDIATES = \
     125        $(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h
     126ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
     127 tstVBoxAPIXPCOM_DEFS += VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
     128endif
    106129
    107130
     
    109132# tstVBoxAPIWin
    110133#
    111 tstVBoxAPIWin_TEMPLATE = VBOXMAINCLIENTTSTEXE
     134# Use very generic template to make the build environment similar
     135# to the standalone case, to detect if IPRT or glue use sneaks in.
     136#
     137tstVBoxAPIWin_TEMPLATE = VBoxBldProg
     138tstVBoxAPIWin_INST = $(INST_TESTCASE)
    112139tstVBoxAPIWin_SOURCES  = \
    113140        tstVBoxAPIWin.cpp \
    114141        $(VBOX_PATH_SDK)/bindings/mscom/lib/VirtualBox_i.c
     142tstVBoxAPIWin_INCS = \
     143        $(VBOX_PATH_SDK)/bindings/mscom/include
     144tstVBoxAPIWin_INTERMEDIATES = \
     145        $(VBOX_PATH_SDK)/bindings/mscom/include/VirtualBox.h
    115146
    116147
  • trunk/src/VBox/Main/testcase/makefile.tstVBoxAPIXPCOM

    r48164 r50339  
    33#
    44#
    5 # Copyright (C) 2006-2013 Oracle Corporation
     5# Copyright (C) 2006-2014 Oracle Corporation
    66#
    77# This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232endif
    3333
     34# Adjust this to match your platform, pick from RT_OS_LINUX, RT_OS_WINDOWS,
     35# RT_OS_DARWIN, RT_OS_SOLARIS...
     36DEFS_XPCOM += RT_OS_LINUX
     37
    3438
    3539#
  • trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp

    r44528 r50339  
    1313
    1414/*
    15  * Copyright (C) 2006-2010 Oracle Corporation
     15 * Copyright (C) 2006-2014 Oracle Corporation
    1616 *
    1717 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    7474    {
    7575        IMachine **machines;
    76         rc = SafeArrayAccessData (machinesArray, (void **) &machines);
     76        rc = SafeArrayAccessData(machinesArray, (void **) &machines);
    7777        if (SUCCEEDED(rc))
    7878        {
     
    8989            }
    9090
    91             SafeArrayUnaccessData (machinesArray);
    92         }
    93 
    94         SafeArrayDestroy (machinesArray);
     91            SafeArrayUnaccessData(machinesArray);
     92        }
     93
     94        SafeArrayDestroy(machinesArray);
    9595    }
    9696
     
    218218
    219219            /* Wait until VM is running. */
    220             printf ("Starting VM, please wait ...\n");
    221             rc = progress->WaitForCompletion (-1);
     220            printf("Starting VM, please wait ...\n");
     221            rc = progress->WaitForCompletion(-1);
    222222
    223223            /* Get console object. */
     
    227227            machine->ShowConsoleWindow(0);
    228228
    229             printf ("Press enter to power off VM and close the session...\n");
     229            printf("Press enter to power off VM and close the session...\n");
    230230            getchar();
    231231
     
    234234
    235235            /* Wait until VM is powered down. */
    236             printf ("Powering off VM, please wait ...\n");
    237             rc = progress->WaitForCompletion (-1);
     236            printf("Powering off VM, please wait ...\n");
     237            rc = progress->WaitForCompletion(-1);
    238238
    239239            /* Close the session. */
  • trunk/src/VBox/Main/testcase/tstVBoxAPIXPCOM.cpp

    r50117 r50339  
    11/** @file
    22 *
    3  * tstVBoxAPILinux - sample program to illustrate the VirtualBox
    4  *                   XPCOM API for machine management on Linux.
     3 * tstVBoxAPIXPCOM - sample program to illustrate the VirtualBox
     4 *                   XPCOM API for machine management.
    55 *                   It only uses standard C/C++ and XPCOM semantics,
    66 *                   no additional VBox classes/macros/helpers.
     
    5353 * use the following (or similar) command to execute it:
    5454 *
    55  *   $ env VBOX_XPCOM_HOME=../../.. LD_LIBRARY_PATH=../../.. ./tstVBoxAPILinux
     55 *   $ env VBOX_XPCOM_HOME=../../.. LD_LIBRARY_PATH=../../.. ./tstVBoxAPIXPCOM
    5656 *
    5757 * The above command assumes that VBoxRT.so, VBoxXPCOM.so and others reside in
     
    7474#include <nsIExceptionService.h>
    7575
    76 #include <VBox/com/com.h>
    77 #include <VBox/com/string.h>
    78 #include <VBox/com/array.h>
    79 #include <VBox/com/Guid.h>
    80 #include <VBox/com/ErrorInfo.h>
    81 #include <VBox/com/errorprint.h>
    82 
    83 #include <VBox/com/VirtualBox.h>
    84 
    85 #include <iprt/stream.h>
    86 
    87 
    8876/*
    8977 * VirtualBox XPCOM interface. This header is generated
     
    10997    nsresult rc;
    11098
    111     RTPrintf("----------------------------------------------------\n");
    112     RTPrintf("VM List:\n\n");
     99    printf("----------------------------------------------------\n");
     100    printf("VM List:\n\n");
    113101
    114102    /*
     
    137125                    machine->GetName(getter_Copies(machineName));
    138126                    char *machineNameAscii = ToNewCString(machineName);
    139                     RTPrintf("\tName:        %s\n", machineNameAscii);
     127                    printf("\tName:        %s\n", machineNameAscii);
    140128                    free(machineNameAscii);
    141129                }
    142130                else
    143131                {
    144                     RTPrintf("\tName:        <inaccessible>\n");
     132                    printf("\tName:        <inaccessible>\n");
    145133                }
    146134
     
    148136                machine->GetId(getter_Copies(iid));
    149137                const char *uuidString = ToNewCString(iid);
    150                 RTPrintf("\tUUID:        %s\n", uuidString);
     138                printf("\tUUID:        %s\n", uuidString);
    151139                free((void*)uuidString);
    152140
     
    156144                    machine->GetSettingsFilePath(getter_Copies(configFile));
    157145                    char *configFileAscii = ToNewCString(configFile);
    158                     RTPrintf("\tConfig file: %s\n", configFileAscii);
     146                    printf("\tConfig file: %s\n", configFileAscii);
    159147                    free(configFileAscii);
    160148
    161149                    PRUint32 memorySize;
    162150                    machine->GetMemorySize(&memorySize);
    163                     RTPrintf("\tMemory size: %uMB\n", memorySize);
     151                    printf("\tMemory size: %uMB\n", memorySize);
    164152
    165153                    nsXPIDLString typeId;
     
    170158                    osType->GetDescription(getter_Copies(osName));
    171159                    char *osNameAscii = ToNewCString(osName);
    172                     RTPrintf("\tGuest OS:    %s\n\n", osNameAscii);
     160                    printf("\tGuest OS:    %s\n\n", osNameAscii);
    173161                    free(osNameAscii);
    174162                    osType->Release();
     
    180168        }
    181169    }
    182     RTPrintf("----------------------------------------------------\n\n");
     170    printf("----------------------------------------------------\n\n");
    183171}
    184172
     
    204192    if (NS_FAILED(rc))
    205193    {
    206         RTPrintf("Error: could not create machine! rc=%Rhrc\n", rc);
     194        printf("Error: could not create machine! rc=%#x\n", rc);
    207195        return;
    208196    }
     
    230218    if (NS_FAILED(rc))
    231219    {
    232         RTPrintf("Error: could not find guest OS type! rc=%Rhrc\n", rc);
     220        printf("Error: could not find guest OS type! rc=%#x\n", rc);
    233221    }
    234222    else
     
    248236    if (NS_FAILED(rc))
    249237    {
    250         RTPrintf("Error: could not register machine! rc=%Rhrc\n", rc);
     238        printf("Error: could not register machine! rc=%#x\n", rc);
    251239        printErrorInfo();
    252240        return;
     
    266254        if (NS_FAILED(rc))
    267255        {
    268             RTPrintf("Error: could not get component manager! rc=%Rhrc\n", rc);
     256            printf("Error: could not get component manager! rc=%#x\n", rc);
    269257            return;
    270258        }
     
    275263        if (NS_FAILED(rc))
    276264        {
    277             RTPrintf("Error, could not instantiate session object! rc=%Rhrc\n", rc);
     265            printf("Error, could not instantiate session object! rc=%#x\n", rc);
    278266            return;
    279267        }
     
    282270        if (NS_FAILED(rc))
    283271        {
    284             RTPrintf("Error, could not lock the machine for the session! rc=%Rhrc\n", rc);
     272            printf("Error, could not lock the machine for the session! rc=%#x\n", rc);
    285273            return;
    286274        }
     
    294282        if (NS_FAILED(rc))
    295283        {
    296             RTPrintf("Error, could not get machine session! rc=%Rhrc\n", rc);
     284            printf("Error, could not get machine session! rc=%#x\n", rc);
    297285            return;
    298286        }
     
    304292    nsCOMPtr<IMedium> hardDisk = 0;
    305293    rc = virtualBox->CreateHardDisk(NS_LITERAL_STRING("VDI").get(),
    306                                     NS_LITERAL_STRING("TestHardDisk.vdi").get(),
     294                                    NS_LITERAL_STRING("/tmp/TestHardDisk.vdi").get(),
    307295                                    getter_AddRefs(hardDisk));
    308296    if (NS_FAILED(rc))
    309297    {
    310         RTPrintf("Failed creating a hard disk object! rc=%Rhrc\n", rc);
     298        printf("Failed creating a hard disk object! rc=%#x\n", rc);
    311299    }
    312300    else
     
    318306         */
    319307        nsCOMPtr<IProgress> progress;
    320         com::SafeArray<MediumVariant_T> mediumVariant;
    321         mediumVariant.push_back(MediumVariant_Standard);
    322         rc = hardDisk->CreateBaseStorage(100,                                // size in megabytes
    323                                          ComSafeArrayAsInParam(mediumVariant),
     308        MediumVariant_T mediumVariants[] =
     309            { MediumVariant_Standard };
     310        rc = hardDisk->CreateBaseStorage(100 * 1024 * 1024,                  // size in bytes
     311                                         sizeof(mediumVariants) / sizeof(mediumVariants[0]), mediumVariants,
    324312                                         getter_AddRefs(progress));          // optional progress object
    325313        if (NS_FAILED(rc))
    326314        {
    327             RTPrintf("Failed creating hard disk image! rc=%Rhrc\n", rc);
     315            printf("Failed creating hard disk image! rc=%#x\n", rc);
    328316        }
    329317        else
     
    339327            if (NS_FAILED(rc) || NS_FAILED(resultCode))
    340328            {
    341                 RTPrintf("Error: could not create hard disk! rc=%Rhrc\n",
     329                printf("Error: could not create hard disk! rc=%#x\n",
    342330                       NS_FAILED(rc) ? rc : resultCode);
    343331            }
     
    355343                if (NS_FAILED(rc))
    356344                {
    357                     RTPrintf("Error: could not attach hard disk! rc=%Rhrc\n", rc);
     345                    printf("Error: could not attach hard disk! rc=%#x\n", rc);
    358346                }
    359347            }
     
    374362                                getter_AddRefs(dvdImage));
    375363    if (NS_FAILED(rc))
    376         RTPrintf("Error: could not open CD image! rc=%Rhrc\n", rc);
     364        printf("Error: could not open CD image! rc=%#x\n", rc);
    377365    else
    378366    {
     
    388376        if (NS_FAILED(rc))
    389377        {
    390             RTPrintf("Error: could not mount ISO image! rc=%Rhrc\n", rc);
     378            printf("Error: could not mount ISO image! rc=%#x\n", rc);
    391379        }
    392380        else
     
    398386            if (NS_FAILED(rc))
    399387            {
    400                 RTPrintf("Could not set boot device! rc=%Rhrc\n", rc);
     388                printf("Could not set boot device! rc=%#x\n", rc);
    401389            }
    402390        }
     
    408396    rc = sessionMachine->SaveSettings();
    409397    if (NS_FAILED(rc))
    410         RTPrintf("Could not save machine settings! rc=%Rhrc\n", rc);
     398        printf("Could not save machine settings! rc=%#x\n", rc);
    411399
    412400    /*
     
    416404    session->UnlockMachine();
    417405
    418     com::SafeIfaceArray<IMedium> aMedia;
     406    IMedium **aMedia;
     407    PRUint32 cMedia;
    419408    rc = machine->Unregister((CleanupMode_T)CleanupMode_DetachAllReturnHardDisksOnly,
    420                              ComSafeArrayAsOutParam(aMedia));
     409                             &cMedia, &aMedia);
    421410    if (NS_FAILED(rc))
    422         RTPrintf("Unregistering the machine failed! rc=%Rhrc\n", rc);
     411        printf("Unregistering the machine failed! rc=%#x\n", rc);
    423412    else
    424413    {
    425         ComPtr<IProgress> pProgress;
    426         rc = machine->DeleteConfig(ComSafeArrayAsInParam(aMedia), pProgress.asOutParam());
    427         if (NS_FAILED(rc))
    428             RTPrintf("Deleting of machine failed! rc=%Rhrc\n", rc);
     414        nsCOMPtr<IProgress> pProgress;
     415        rc = machine->DeleteConfig(cMedia, aMedia, getter_AddRefs(pProgress));
     416        if (NS_FAILED(rc))
     417            printf("Deleting of machine failed! rc=%#x\n", rc);
    429418        else
    430419        {
     
    433422            pProgress->GetResultCode(&resultCode);
    434423            if (NS_FAILED(rc) || NS_FAILED(resultCode))
    435                 RTPrintf("Failed to delete the machine! rc=%Rhrc\n",
    436                          NS_FAILED(rc) ? rc : resultCode);
     424                printf("Failed to delete the machine! rc=%#x\n",
     425                       NS_FAILED(rc) ? rc : resultCode);
    437426        }
    438427    }
     
    453442    if (sizeof(PRUnichar) != sizeof(wchar_t))
    454443    {
    455         RTPrintf("Error: sizeof(PRUnichar) {%lu} != sizeof(wchar_t) {%lu}!\n"
     444        printf("Error: sizeof(PRUnichar) {%lu} != sizeof(wchar_t) {%lu}!\n"
    456445               "Probably, you forgot the -fshort-wchar compiler option.\n",
    457446               (unsigned long) sizeof(PRUnichar),
     
    476465        if (NS_FAILED(rc))
    477466        {
    478             RTPrintf("Error: XPCOM could not be initialized! rc=%Rhrc\n", rc);
     467            printf("Error: XPCOM could not be initialized! rc=%#x\n", rc);
    479468            return -1;
    480469        }
     
    489478        if (!registrar)
    490479        {
    491             RTPrintf("Error: could not query nsIComponentRegistrar interface!\n");
     480            printf("Error: could not query nsIComponentRegistrar interface!\n");
    492481            return -1;
    493482        }
     
    507496        if (NS_FAILED(rc))
    508497        {
    509             RTPrintf("Error: could not get main event queue! rc=%Rhrc\n", rc);
     498            printf("Error: could not get main event queue! rc=%#x\n", rc);
    510499            return -1;
    511500        }
     
    523512        if (NS_FAILED(rc))
    524513        {
    525             RTPrintf("Error: could not get component manager! rc=%Rhrc\n", rc);
     514            printf("Error: could not get component manager! rc=%#x\n", rc);
    526515            return -1;
    527516        }
     
    534523        if (NS_FAILED(rc))
    535524        {
    536             RTPrintf("Error, could not instantiate VirtualBox object! rc=%Rhrc\n", rc);
     525            printf("Error, could not instantiate VirtualBox object! rc=%#x\n", rc);
    537526            return -1;
    538527        }
    539         RTPrintf("VirtualBox object created\n");
     528        printf("VirtualBox object created\n");
    540529
    541530        ////////////////////////////////////////////////////////////////////////////////
     
    567556     */
    568557    NS_ShutdownXPCOM(nsnull);
    569     RTPrintf("Done!\n");
     558    printf("Done!\n");
    570559    return 0;
    571560}
     
    588577    if (res != NULL)
    589578    {
    590         RTStrPrintf(res, 39, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
     579        snprintf(res, 39, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
    591580                 guid->m0, (PRUint32)guid->m1, (PRUint32)guid->m2,
    592581                 (PRUint32)guid->m3[0], (PRUint32)guid->m3[1], (PRUint32)guid->m3[2],
     
    623612                {
    624613                    /* got extended error info */
    625                     RTPrintf("Extended error info (IVirtualBoxErrorInfo):\n");
     614                    printf("Extended error info (IVirtualBoxErrorInfo):\n");
    626615                    PRInt32 resultCode = NS_OK;
    627616                    info->GetResultCode(&resultCode);
    628                     RTPrintf("  resultCode=%08X\n", resultCode);
     617                    printf("  resultCode=%08X\n", resultCode);
    629618                    nsXPIDLString component;
    630619                    info->GetComponent(getter_Copies(component));
    631                     RTPrintf("  component=%s\n", NS_ConvertUTF16toUTF8(component).get());
     620                    printf("  component=%s\n", NS_ConvertUTF16toUTF8(component).get());
    632621                    nsXPIDLString text;
    633622                    info->GetText(getter_Copies(text));
    634                     RTPrintf("  text=%s\n", NS_ConvertUTF16toUTF8(text).get());
     623                    printf("  text=%s\n", NS_ConvertUTF16toUTF8(text).get());
    635624                }
    636625                else
    637626                {
    638627                    /* got basic error info */
    639                     RTPrintf("Basic error info (nsIException):\n");
     628                    printf("Basic error info (nsIException):\n");
    640629                    nsresult resultCode = NS_OK;
    641630                    ex->GetResult(&resultCode);
    642                     RTPrintf("  resultCode=%08X\n", resultCode);
     631                    printf("  resultCode=%08X\n", resultCode);
    643632                    nsXPIDLCString message;
    644633                    ex->GetMessage(getter_Copies(message));
    645                     RTPrintf("  message=%s\n", message.get());
     634                    printf("  message=%s\n", message.get());
    646635                }
    647636
Note: See TracChangeset for help on using the changeset viewer.

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