Changeset 50339 in vbox
- Timestamp:
- Feb 6, 2014 10:30:07 AM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 92072
- Location:
- trunk/src/VBox/Main/testcase
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/Makefile.kmk
r49951 r50339 5 5 6 6 # 7 # Copyright (C) 2004-201 3Oracle Corporation7 # Copyright (C) 2004-2014 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 102 102 # It comes with a custom makefile which should be tested as well! 103 103 # 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 # 107 tstVBoxAPIXPCOM_TEMPLATE = VBoxBldProg 108 tstVBoxAPIXPCOM_INST = $(INST_TESTCASE) 105 109 tstVBoxAPIXPCOM_SOURCES = tstVBoxAPIXPCOM.cpp 110 tstVBoxAPIXPCOM_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 116 tstVBoxAPIXPCOM_LIBS = \ 117 $(LIB_XPCOM) 118 tstVBoxAPIXPCOM_CXXFLAGS = -fshort-wchar 119 ifdef VBOX_WITH_RUNPATH 120 tstVBoxAPIXPCOM_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' $(TEMPLATE_VBoxBldProg_LDFLAGS) 121 else ifdef VBOX_WITH_RELATIVE_RUNPATH 122 tstVBoxAPIXPCOM_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/..' $(TEMPLATE_VBoxBldProg_LDFLAGS) 123 endif 124 tstVBoxAPIXPCOM_INTERMEDIATES = \ 125 $(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h 126 ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 127 tstVBoxAPIXPCOM_DEFS += VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 128 endif 106 129 107 130 … … 109 132 # tstVBoxAPIWin 110 133 # 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 # 137 tstVBoxAPIWin_TEMPLATE = VBoxBldProg 138 tstVBoxAPIWin_INST = $(INST_TESTCASE) 112 139 tstVBoxAPIWin_SOURCES = \ 113 140 tstVBoxAPIWin.cpp \ 114 141 $(VBOX_PATH_SDK)/bindings/mscom/lib/VirtualBox_i.c 142 tstVBoxAPIWin_INCS = \ 143 $(VBOX_PATH_SDK)/bindings/mscom/include 144 tstVBoxAPIWin_INTERMEDIATES = \ 145 $(VBOX_PATH_SDK)/bindings/mscom/include/VirtualBox.h 115 146 116 147 -
trunk/src/VBox/Main/testcase/makefile.tstVBoxAPIXPCOM
r48164 r50339 3 3 # 4 4 # 5 # Copyright (C) 2006-201 3Oracle Corporation5 # Copyright (C) 2006-2014 Oracle Corporation 6 6 # 7 7 # This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 endif 33 33 34 # Adjust this to match your platform, pick from RT_OS_LINUX, RT_OS_WINDOWS, 35 # RT_OS_DARWIN, RT_OS_SOLARIS... 36 DEFS_XPCOM += RT_OS_LINUX 37 34 38 35 39 # -
trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp
r44528 r50339 13 13 14 14 /* 15 * Copyright (C) 2006-201 0Oracle Corporation15 * Copyright (C) 2006-2014 Oracle Corporation 16 16 * 17 17 * This file is part of VirtualBox Open Source Edition (OSE), as … … 74 74 { 75 75 IMachine **machines; 76 rc = SafeArrayAccessData 76 rc = SafeArrayAccessData(machinesArray, (void **) &machines); 77 77 if (SUCCEEDED(rc)) 78 78 { … … 89 89 } 90 90 91 SafeArrayUnaccessData 92 } 93 94 SafeArrayDestroy 91 SafeArrayUnaccessData(machinesArray); 92 } 93 94 SafeArrayDestroy(machinesArray); 95 95 } 96 96 … … 218 218 219 219 /* Wait until VM is running. */ 220 printf 221 rc = progress->WaitForCompletion 220 printf("Starting VM, please wait ...\n"); 221 rc = progress->WaitForCompletion(-1); 222 222 223 223 /* Get console object. */ … … 227 227 machine->ShowConsoleWindow(0); 228 228 229 printf 229 printf("Press enter to power off VM and close the session...\n"); 230 230 getchar(); 231 231 … … 234 234 235 235 /* Wait until VM is powered down. */ 236 printf 237 rc = progress->WaitForCompletion 236 printf("Powering off VM, please wait ...\n"); 237 rc = progress->WaitForCompletion(-1); 238 238 239 239 /* Close the session. */ -
trunk/src/VBox/Main/testcase/tstVBoxAPIXPCOM.cpp
r50117 r50339 1 1 /** @file 2 2 * 3 * tstVBoxAPI Linux- sample program to illustrate the VirtualBox4 * XPCOM API for machine management on Linux.3 * tstVBoxAPIXPCOM - sample program to illustrate the VirtualBox 4 * XPCOM API for machine management. 5 5 * It only uses standard C/C++ and XPCOM semantics, 6 6 * no additional VBox classes/macros/helpers. … … 53 53 * use the following (or similar) command to execute it: 54 54 * 55 * $ env VBOX_XPCOM_HOME=../../.. LD_LIBRARY_PATH=../../.. ./tstVBoxAPI Linux55 * $ env VBOX_XPCOM_HOME=../../.. LD_LIBRARY_PATH=../../.. ./tstVBoxAPIXPCOM 56 56 * 57 57 * The above command assumes that VBoxRT.so, VBoxXPCOM.so and others reside in … … 74 74 #include <nsIExceptionService.h> 75 75 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 88 76 /* 89 77 * VirtualBox XPCOM interface. This header is generated … … 109 97 nsresult rc; 110 98 111 RTPrintf("----------------------------------------------------\n");112 RTPrintf("VM List:\n\n");99 printf("----------------------------------------------------\n"); 100 printf("VM List:\n\n"); 113 101 114 102 /* … … 137 125 machine->GetName(getter_Copies(machineName)); 138 126 char *machineNameAscii = ToNewCString(machineName); 139 RTPrintf("\tName: %s\n", machineNameAscii);127 printf("\tName: %s\n", machineNameAscii); 140 128 free(machineNameAscii); 141 129 } 142 130 else 143 131 { 144 RTPrintf("\tName: <inaccessible>\n");132 printf("\tName: <inaccessible>\n"); 145 133 } 146 134 … … 148 136 machine->GetId(getter_Copies(iid)); 149 137 const char *uuidString = ToNewCString(iid); 150 RTPrintf("\tUUID: %s\n", uuidString);138 printf("\tUUID: %s\n", uuidString); 151 139 free((void*)uuidString); 152 140 … … 156 144 machine->GetSettingsFilePath(getter_Copies(configFile)); 157 145 char *configFileAscii = ToNewCString(configFile); 158 RTPrintf("\tConfig file: %s\n", configFileAscii);146 printf("\tConfig file: %s\n", configFileAscii); 159 147 free(configFileAscii); 160 148 161 149 PRUint32 memorySize; 162 150 machine->GetMemorySize(&memorySize); 163 RTPrintf("\tMemory size: %uMB\n", memorySize);151 printf("\tMemory size: %uMB\n", memorySize); 164 152 165 153 nsXPIDLString typeId; … … 170 158 osType->GetDescription(getter_Copies(osName)); 171 159 char *osNameAscii = ToNewCString(osName); 172 RTPrintf("\tGuest OS: %s\n\n", osNameAscii);160 printf("\tGuest OS: %s\n\n", osNameAscii); 173 161 free(osNameAscii); 174 162 osType->Release(); … … 180 168 } 181 169 } 182 RTPrintf("----------------------------------------------------\n\n");170 printf("----------------------------------------------------\n\n"); 183 171 } 184 172 … … 204 192 if (NS_FAILED(rc)) 205 193 { 206 RTPrintf("Error: could not create machine! rc=%Rhrc\n", rc);194 printf("Error: could not create machine! rc=%#x\n", rc); 207 195 return; 208 196 } … … 230 218 if (NS_FAILED(rc)) 231 219 { 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); 233 221 } 234 222 else … … 248 236 if (NS_FAILED(rc)) 249 237 { 250 RTPrintf("Error: could not register machine! rc=%Rhrc\n", rc);238 printf("Error: could not register machine! rc=%#x\n", rc); 251 239 printErrorInfo(); 252 240 return; … … 266 254 if (NS_FAILED(rc)) 267 255 { 268 RTPrintf("Error: could not get component manager! rc=%Rhrc\n", rc);256 printf("Error: could not get component manager! rc=%#x\n", rc); 269 257 return; 270 258 } … … 275 263 if (NS_FAILED(rc)) 276 264 { 277 RTPrintf("Error, could not instantiate session object! rc=%Rhrc\n", rc);265 printf("Error, could not instantiate session object! rc=%#x\n", rc); 278 266 return; 279 267 } … … 282 270 if (NS_FAILED(rc)) 283 271 { 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); 285 273 return; 286 274 } … … 294 282 if (NS_FAILED(rc)) 295 283 { 296 RTPrintf("Error, could not get machine session! rc=%Rhrc\n", rc);284 printf("Error, could not get machine session! rc=%#x\n", rc); 297 285 return; 298 286 } … … 304 292 nsCOMPtr<IMedium> hardDisk = 0; 305 293 rc = virtualBox->CreateHardDisk(NS_LITERAL_STRING("VDI").get(), 306 NS_LITERAL_STRING(" TestHardDisk.vdi").get(),294 NS_LITERAL_STRING("/tmp/TestHardDisk.vdi").get(), 307 295 getter_AddRefs(hardDisk)); 308 296 if (NS_FAILED(rc)) 309 297 { 310 RTPrintf("Failed creating a hard disk object! rc=%Rhrc\n", rc);298 printf("Failed creating a hard disk object! rc=%#x\n", rc); 311 299 } 312 300 else … … 318 306 */ 319 307 nsCOMPtr<IProgress> progress; 320 com::SafeArray<MediumVariant_T> mediumVariant;321 mediumVariant.push_back(MediumVariant_Standard);322 rc = hardDisk->CreateBaseStorage(100 , // size in megabytes323 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, 324 312 getter_AddRefs(progress)); // optional progress object 325 313 if (NS_FAILED(rc)) 326 314 { 327 RTPrintf("Failed creating hard disk image! rc=%Rhrc\n", rc);315 printf("Failed creating hard disk image! rc=%#x\n", rc); 328 316 } 329 317 else … … 339 327 if (NS_FAILED(rc) || NS_FAILED(resultCode)) 340 328 { 341 RTPrintf("Error: could not create hard disk! rc=%Rhrc\n",329 printf("Error: could not create hard disk! rc=%#x\n", 342 330 NS_FAILED(rc) ? rc : resultCode); 343 331 } … … 355 343 if (NS_FAILED(rc)) 356 344 { 357 RTPrintf("Error: could not attach hard disk! rc=%Rhrc\n", rc);345 printf("Error: could not attach hard disk! rc=%#x\n", rc); 358 346 } 359 347 } … … 374 362 getter_AddRefs(dvdImage)); 375 363 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); 377 365 else 378 366 { … … 388 376 if (NS_FAILED(rc)) 389 377 { 390 RTPrintf("Error: could not mount ISO image! rc=%Rhrc\n", rc);378 printf("Error: could not mount ISO image! rc=%#x\n", rc); 391 379 } 392 380 else … … 398 386 if (NS_FAILED(rc)) 399 387 { 400 RTPrintf("Could not set boot device! rc=%Rhrc\n", rc);388 printf("Could not set boot device! rc=%#x\n", rc); 401 389 } 402 390 } … … 408 396 rc = sessionMachine->SaveSettings(); 409 397 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); 411 399 412 400 /* … … 416 404 session->UnlockMachine(); 417 405 418 com::SafeIfaceArray<IMedium> aMedia; 406 IMedium **aMedia; 407 PRUint32 cMedia; 419 408 rc = machine->Unregister((CleanupMode_T)CleanupMode_DetachAllReturnHardDisksOnly, 420 ComSafeArrayAsOutParam(aMedia));409 &cMedia, &aMedia); 421 410 if (NS_FAILED(rc)) 422 RTPrintf("Unregistering the machine failed! rc=%Rhrc\n", rc);411 printf("Unregistering the machine failed! rc=%#x\n", rc); 423 412 else 424 413 { 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); 429 418 else 430 419 { … … 433 422 pProgress->GetResultCode(&resultCode); 434 423 if (NS_FAILED(rc) || NS_FAILED(resultCode)) 435 RTPrintf("Failed to delete the machine! rc=%Rhrc\n",436 424 printf("Failed to delete the machine! rc=%#x\n", 425 NS_FAILED(rc) ? rc : resultCode); 437 426 } 438 427 } … … 453 442 if (sizeof(PRUnichar) != sizeof(wchar_t)) 454 443 { 455 RTPrintf("Error: sizeof(PRUnichar) {%lu} != sizeof(wchar_t) {%lu}!\n"444 printf("Error: sizeof(PRUnichar) {%lu} != sizeof(wchar_t) {%lu}!\n" 456 445 "Probably, you forgot the -fshort-wchar compiler option.\n", 457 446 (unsigned long) sizeof(PRUnichar), … … 476 465 if (NS_FAILED(rc)) 477 466 { 478 RTPrintf("Error: XPCOM could not be initialized! rc=%Rhrc\n", rc);467 printf("Error: XPCOM could not be initialized! rc=%#x\n", rc); 479 468 return -1; 480 469 } … … 489 478 if (!registrar) 490 479 { 491 RTPrintf("Error: could not query nsIComponentRegistrar interface!\n");480 printf("Error: could not query nsIComponentRegistrar interface!\n"); 492 481 return -1; 493 482 } … … 507 496 if (NS_FAILED(rc)) 508 497 { 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); 510 499 return -1; 511 500 } … … 523 512 if (NS_FAILED(rc)) 524 513 { 525 RTPrintf("Error: could not get component manager! rc=%Rhrc\n", rc);514 printf("Error: could not get component manager! rc=%#x\n", rc); 526 515 return -1; 527 516 } … … 534 523 if (NS_FAILED(rc)) 535 524 { 536 RTPrintf("Error, could not instantiate VirtualBox object! rc=%Rhrc\n", rc);525 printf("Error, could not instantiate VirtualBox object! rc=%#x\n", rc); 537 526 return -1; 538 527 } 539 RTPrintf("VirtualBox object created\n");528 printf("VirtualBox object created\n"); 540 529 541 530 //////////////////////////////////////////////////////////////////////////////// … … 567 556 */ 568 557 NS_ShutdownXPCOM(nsnull); 569 RTPrintf("Done!\n");558 printf("Done!\n"); 570 559 return 0; 571 560 } … … 588 577 if (res != NULL) 589 578 { 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}", 591 580 guid->m0, (PRUint32)guid->m1, (PRUint32)guid->m2, 592 581 (PRUint32)guid->m3[0], (PRUint32)guid->m3[1], (PRUint32)guid->m3[2], … … 623 612 { 624 613 /* got extended error info */ 625 RTPrintf("Extended error info (IVirtualBoxErrorInfo):\n");614 printf("Extended error info (IVirtualBoxErrorInfo):\n"); 626 615 PRInt32 resultCode = NS_OK; 627 616 info->GetResultCode(&resultCode); 628 RTPrintf(" resultCode=%08X\n", resultCode);617 printf(" resultCode=%08X\n", resultCode); 629 618 nsXPIDLString component; 630 619 info->GetComponent(getter_Copies(component)); 631 RTPrintf(" component=%s\n", NS_ConvertUTF16toUTF8(component).get());620 printf(" component=%s\n", NS_ConvertUTF16toUTF8(component).get()); 632 621 nsXPIDLString text; 633 622 info->GetText(getter_Copies(text)); 634 RTPrintf(" text=%s\n", NS_ConvertUTF16toUTF8(text).get());623 printf(" text=%s\n", NS_ConvertUTF16toUTF8(text).get()); 635 624 } 636 625 else 637 626 { 638 627 /* got basic error info */ 639 RTPrintf("Basic error info (nsIException):\n");628 printf("Basic error info (nsIException):\n"); 640 629 nsresult resultCode = NS_OK; 641 630 ex->GetResult(&resultCode); 642 RTPrintf(" resultCode=%08X\n", resultCode);631 printf(" resultCode=%08X\n", resultCode); 643 632 nsXPIDLCString message; 644 633 ex->GetMessage(getter_Copies(message)); 645 RTPrintf(" message=%s\n", message.get());634 printf(" message=%s\n", message.get()); 646 635 } 647 636
Note:
See TracChangeset
for help on using the changeset viewer.