Changeset 47813 in vbox for trunk/src/VBox/Main/testcase/tstVBoxAPILinux.cpp
- Timestamp:
- Aug 16, 2013 1:39:49 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 88074
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstVBoxAPILinux.cpp
r44528 r47813 89 89 #include <VBox/com/VirtualBox.h> 90 90 91 #include <iprt/stream.h> 92 91 93 92 94 /* … … 113 115 nsresult rc; 114 116 115 printf("----------------------------------------------------\n");116 printf("VM List:\n\n");117 RTPrintf("----------------------------------------------------\n"); 118 RTPrintf("VM List:\n\n"); 117 119 118 120 /* … … 141 143 machine->GetName(getter_Copies(machineName)); 142 144 char *machineNameAscii = ToNewCString(machineName); 143 printf("\tName: %s\n", machineNameAscii);145 RTPrintf("\tName: %s\n", machineNameAscii); 144 146 free(machineNameAscii); 145 147 } 146 148 else 147 149 { 148 printf("\tName: <inaccessible>\n");150 RTPrintf("\tName: <inaccessible>\n"); 149 151 } 150 152 … … 152 154 machine->GetId(getter_Copies(iid)); 153 155 const char *uuidString = ToNewCString(iid); 154 printf("\tUUID: %s\n", uuidString);156 RTPrintf("\tUUID: %s\n", uuidString); 155 157 free((void*)uuidString); 156 158 … … 160 162 machine->GetSettingsFilePath(getter_Copies(configFile)); 161 163 char *configFileAscii = ToNewCString(configFile); 162 printf("\tConfig file: %s\n", configFileAscii);164 RTPrintf("\tConfig file: %s\n", configFileAscii); 163 165 free(configFileAscii); 164 166 165 167 PRUint32 memorySize; 166 168 machine->GetMemorySize(&memorySize); 167 printf("\tMemory size: %uMB\n", memorySize);169 RTPrintf("\tMemory size: %uMB\n", memorySize); 168 170 169 171 nsXPIDLString typeId; … … 174 176 osType->GetDescription(getter_Copies(osName)); 175 177 char *osNameAscii = ToNewCString(osName); 176 printf("\tGuest OS: %s\n\n", osNameAscii);178 RTPrintf("\tGuest OS: %s\n\n", osNameAscii); 177 179 free(osNameAscii); 178 180 osType->Release(); … … 184 186 } 185 187 } 186 printf("----------------------------------------------------\n\n");188 RTPrintf("----------------------------------------------------\n\n"); 187 189 } 188 190 … … 208 210 if (NS_FAILED(rc)) 209 211 { 210 printf("Error: could not create machine! rc=%08X\n", rc);212 RTPrintf("Error: could not create machine! rc=%Rhrc\n", rc); 211 213 return; 212 214 } … … 230 232 */ 231 233 nsCOMPtr<IGuestOSType> osType; 232 rc = virtualBox->GetGuestOSType(NS_LITERAL_STRING(" win2k").get(),234 rc = virtualBox->GetGuestOSType(NS_LITERAL_STRING("Windows2000").get(), 233 235 getter_AddRefs(osType)); 234 236 if (NS_FAILED(rc)) 235 237 { 236 printf("Error: could not find guest OS type! rc=%08X\n", rc);238 RTPrintf("Error: could not find guest OS type! rc=%Rhrc\n", rc); 237 239 } 238 240 else 239 241 { 240 machine->SetOSTypeId (NS_LITERAL_STRING(" win2k").get());242 machine->SetOSTypeId (NS_LITERAL_STRING("Windows2000").get()); 241 243 } 242 244 … … 252 254 if (NS_FAILED(rc)) 253 255 { 254 printf("Error: could not register machine! rc=%08X\n", rc);256 RTPrintf("Error: could not register machine! rc=%Rhrc\n", rc); 255 257 printErrorInfo(); 256 258 return; 257 259 } 258 260 261 nsCOMPtr<IMachine> origMachine = machine; 262 259 263 /* 260 264 * In order to manipulate the registered machine, we must open a session … … 262 266 */ 263 267 nsCOMPtr<ISession> session; 268 nsCOMPtr<IMachine> sessionMachine; 264 269 { 265 270 nsCOMPtr<nsIComponentManager> manager; … … 267 272 if (NS_FAILED(rc)) 268 273 { 269 printf("Error: could not get component manager! rc=%08X\n", rc);274 RTPrintf("Error: could not get component manager! rc=%Rhrc\n", rc); 270 275 return; 271 276 } … … 276 281 if (NS_FAILED(rc)) 277 282 { 278 printf("Error, could not instantiate session object! rc=0x%x\n", rc);283 RTPrintf("Error, could not instantiate session object! rc=0x%x\n", rc); 279 284 return; 280 285 } … … 283 288 if (NS_FAILED(rc)) 284 289 { 285 printf("Error, could not lock the machine for the session! rc=0x%x\n", rc);290 RTPrintf("Error, could not lock the machine for the session! rc=0x%x\n", rc); 286 291 return; 287 292 } … … 292 297 * it from the opened session object. 293 298 */ 294 rc = session->GetMachine(getter_AddRefs( machine));295 if (NS_FAILED(rc)) 296 { 297 printf("Error, could not get machine session! rc=0x%x\n", rc);299 rc = session->GetMachine(getter_AddRefs(sessionMachine)); 300 if (NS_FAILED(rc)) 301 { 302 RTPrintf("Error, could not get machine session! rc=0x%x\n", rc); 298 303 return; 299 304 } … … 309 314 if (NS_FAILED(rc)) 310 315 { 311 printf("Failed creating a hard disk object! rc=%08X\n", rc);316 RTPrintf("Failed creating a hard disk object! rc=%Rhrc\n", rc); 312 317 } 313 318 else … … 326 331 if (NS_FAILED(rc)) 327 332 { 328 printf("Failed creating hard disk image! rc=%08X\n", rc);333 RTPrintf("Failed creating hard disk image! rc=%Rhrc\n", rc); 329 334 } 330 335 else … … 340 345 if (NS_FAILED(rc) || NS_FAILED(resultCode)) 341 346 { 342 printf("Error: could not create hard disk! rc=%08X\n",347 RTPrintf("Error: could not create hard disk! rc=%Rhrc\n", 343 348 NS_FAILED(rc) ? rc : resultCode); 344 349 } … … 348 353 * Now that it's created, we can assign it to the VM. 349 354 */ 350 rc = machine->AttachDevice(NS_LITERAL_STRING("IDE Controller").get(), // controller identifier 355 rc = sessionMachine->AttachDevice( 356 NS_LITERAL_STRING("IDE Controller").get(), // controller identifier 351 357 0, // channel number on the controller 352 358 0, // device number on the controller … … 355 361 if (NS_FAILED(rc)) 356 362 { 357 printf("Error: could not attach hard disk! rc=%08X\n", rc);363 RTPrintf("Error: could not attach hard disk! rc=%Rhrc\n", rc); 358 364 } 359 365 } … … 374 380 getter_AddRefs(dvdImage)); 375 381 if (NS_FAILED(rc)) 376 printf("Error: could not open CD image! rc=%08X\n", rc);382 RTPrintf("Error: could not open CD image! rc=%Rhrc\n", rc); 377 383 else 378 384 { … … 380 386 * Now assign it to our VM 381 387 */ 382 rc = machine->MountMedium(NS_LITERAL_STRING("IDE Controller").get(), // controller identifier 388 rc = sessionMachine->MountMedium( 389 NS_LITERAL_STRING("IDE Controller").get(), // controller identifier 383 390 2, // channel number on the controller 384 391 0, // device number on the controller … … 387 394 if (NS_FAILED(rc)) 388 395 { 389 printf("Error: could not mount ISO image! rc=%08X\n", rc);396 RTPrintf("Error: could not mount ISO image! rc=%Rhrc\n", rc); 390 397 } 391 398 else … … 394 401 * Last step: tell the VM to boot from the CD. 395 402 */ 396 rc = machine->SetBootOrder (1, DeviceType::DVD);403 rc = sessionMachine->SetBootOrder (1, DeviceType::DVD); 397 404 if (NS_FAILED(rc)) 398 405 { 399 printf("Could not set boot device! rc=%08X\n", rc);406 RTPrintf("Could not set boot device! rc=%Rhrc\n", rc); 400 407 } 401 408 } … … 405 412 * Save all changes we've just made. 406 413 */ 407 rc = machine->SaveSettings();414 rc = sessionMachine->SaveSettings(); 408 415 if (NS_FAILED(rc)) 409 { 410 printf("Could not save machine settings! rc=%08X\n", rc); 411 } 416 RTPrintf("Could not save machine settings! rc=%Rhrc\n", rc); 412 417 413 418 /* … … 416 421 */ 417 422 session->UnlockMachine(); 423 424 com::SafeIfaceArray<IMedium> aMedia; 425 rc = machine->Unregister((CleanupMode_T)CleanupMode_DetachAllReturnHardDisksOnly, 426 ComSafeArrayAsOutParam(aMedia)); 427 if (NS_FAILED(rc)) 428 RTPrintf("Unregistering the machine failed! rc=%Rhrc\n", rc); 429 else 430 { 431 ComPtr<IProgress> pProgress; 432 rc = machine->DeleteConfig(ComSafeArrayAsInParam(aMedia), pProgress.asOutParam()); 433 if (NS_FAILED(rc)) 434 RTPrintf("Deleting of machine failed! rc=%Rhrc\n", rc); 435 else 436 { 437 rc = pProgress->WaitForCompletion(-1); 438 PRInt32 resultCode; 439 pProgress->GetResultCode(&resultCode); 440 if (NS_FAILED(rc) || NS_FAILED(resultCode)) 441 RTPrintf("Failed to delete the machine! rc=%Rhrc\n", 442 NS_FAILED(rc) ? rc : resultCode); 443 } 444 } 418 445 } 419 446 … … 432 459 if (sizeof(PRUnichar) != sizeof(wchar_t)) 433 460 { 434 printf("Error: sizeof(PRUnichar) {%lu} != sizeof(wchar_t) {%lu}!\n"461 RTPrintf("Error: sizeof(PRUnichar) {%lu} != sizeof(wchar_t) {%lu}!\n" 435 462 "Probably, you forgot the -fshort-wchar compiler option.\n", 436 463 (unsigned long) sizeof(PRUnichar), … … 460 487 if (NS_FAILED(rc)) 461 488 { 462 printf("Error: XPCOM could not be initialized! rc=0x%x\n", rc);489 RTPrintf("Error: XPCOM could not be initialized! rc=0x%x\n", rc); 463 490 return -1; 464 491 } … … 473 500 if (!registrar) 474 501 { 475 printf("Error: could not query nsIComponentRegistrar interface!\n");502 RTPrintf("Error: could not query nsIComponentRegistrar interface!\n"); 476 503 return -1; 477 504 } … … 491 518 if (NS_FAILED(rc)) 492 519 { 493 printf("Error: could not get main event queue! rc=%08X\n", rc);520 RTPrintf("Error: could not get main event queue! rc=%Rhrc\n", rc); 494 521 return -1; 495 522 } … … 507 534 if (NS_FAILED(rc)) 508 535 { 509 printf("Error: could not get component manager! rc=%08X\n", rc);536 RTPrintf("Error: could not get component manager! rc=%Rhrc\n", rc); 510 537 return -1; 511 538 } … … 518 545 if (NS_FAILED(rc)) 519 546 { 520 printf("Error, could not instantiate VirtualBox object! rc=0x%x\n", rc);547 RTPrintf("Error, could not instantiate VirtualBox object! rc=0x%x\n", rc); 521 548 return -1; 522 549 } 523 printf("VirtualBox object created\n");550 RTPrintf("VirtualBox object created\n"); 524 551 525 552 //////////////////////////////////////////////////////////////////////////////// … … 554 581 XPCOMGlueShutdown(); 555 582 #endif 556 printf("Done!\n");583 RTPrintf("Done!\n"); 557 584 return 0; 558 585 } … … 575 602 if (res != NULL) 576 603 { 577 snprintf(res, 39, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",604 RTStrPrintf(res, 39, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", 578 605 guid->m0, (PRUint32)guid->m1, (PRUint32)guid->m2, 579 606 (PRUint32)guid->m3[0], (PRUint32)guid->m3[1], (PRUint32)guid->m3[2], … … 610 637 { 611 638 /* got extended error info */ 612 printf ("Extended error info (IVirtualBoxErrorInfo):\n");639 RTPrintf ("Extended error info (IVirtualBoxErrorInfo):\n"); 613 640 PRInt32 resultCode = NS_OK; 614 641 info->GetResultCode (&resultCode); 615 printf (" resultCode=%08X\n", resultCode);642 RTPrintf (" resultCode=%08X\n", resultCode); 616 643 nsXPIDLString component; 617 644 info->GetComponent (getter_Copies (component)); 618 printf (" component=%s\n", NS_ConvertUTF16toUTF8(component).get());645 RTPrintf (" component=%s\n", NS_ConvertUTF16toUTF8(component).get()); 619 646 nsXPIDLString text; 620 647 info->GetText (getter_Copies (text)); 621 printf (" text=%s\n", NS_ConvertUTF16toUTF8(text).get());648 RTPrintf (" text=%s\n", NS_ConvertUTF16toUTF8(text).get()); 622 649 } 623 650 else 624 651 { 625 652 /* got basic error info */ 626 printf ("Basic error info (nsIException):\n");653 RTPrintf ("Basic error info (nsIException):\n"); 627 654 nsresult resultCode = NS_OK; 628 655 ex->GetResult (&resultCode); 629 printf (" resultCode=%08X\n", resultCode);656 RTPrintf (" resultCode=%08X\n", resultCode); 630 657 nsXPIDLCString message; 631 658 ex->GetMessage (getter_Copies (message)); 632 printf (" message=%s\n", message.get());659 RTPrintf (" message=%s\n", message.get()); 633 660 } 634 661
Note:
See TracChangeset
for help on using the changeset viewer.