Changeset 50117 in vbox for trunk/src/VBox/Frontends/VBoxHeadless/testcase
- Timestamp:
- Jan 20, 2014 2:05:02 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 91661
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxHeadless/testcase/tstHeadless.cpp
r48244 r50117 6 6 7 7 /* 8 * Copyright (C) 2006-201 1Oracle Corporation8 * Copyright (C) 2006-2014 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 22 22 #include <VBox/com/ErrorInfo.h> 23 23 #include <VBox/com/errorprint.h> 24 #include <VBox/com/EventQueue.h>25 24 26 25 #include <VBox/com/VirtualBox.h> … … 38 37 * Entry point. 39 38 */ 40 int main 39 int main(int argc, char **argv) 41 40 { 42 41 // initialize VBox Runtime … … 56 55 if (!name || !operation) 57 56 { 58 RTPrintf 59 60 57 RTPrintf("\nUsage:\n\n" 58 "%s <machine_name> [on|off|pause|resume]\n\n", 59 argv [0]); 61 60 return 0; 62 61 } 63 62 64 RTPrintf 65 RTPrintf 66 67 RTPrintf 68 69 63 RTPrintf("\n"); 64 RTPrintf("tstHeadless STARTED.\n"); 65 66 RTPrintf("VM name : {%s}\n" 67 "Operation : %s\n\n", 68 name, operation); 70 69 71 70 HRESULT rc; … … 83 82 ComPtr <ISession> session; 84 83 85 RTPrintf 86 rc = virtualBox.createLocalObject 84 RTPrintf("Creating VirtualBox object...\n"); 85 rc = virtualBox.createLocalObject(CLSID_VirtualBox); 87 86 if (FAILED(rc)) 88 87 RTPrintf("ERROR: failed to create the VirtualBox object!\n"); … … 94 93 } 95 94 96 if (FAILED 95 if (FAILED(rc)) 97 96 { 98 97 com::ErrorInfo info; … … 106 105 break; 107 106 } 108 109 // create the event queue110 // (here it is necessary only to process remaining XPCOM/IPC events111 // after the session is closed)112 EventQueue eventQ;113 107 114 108 ComPtr <IMachine> m; … … 121 115 { 122 116 ComPtr <IProgress> progress; 123 RTPrintf 124 CHECK_ERROR_BREAK 125 126 127 128 RTPrintf 129 CHECK_ERROR_BREAK (progress, WaitForCompletion(-1));117 RTPrintf("Opening a new (remote) session...\n"); 118 CHECK_ERROR_BREAK(m, 119 LaunchVMProcess(session, Bstr("vrdp").raw(), 120 NULL, progress.asOutParam())); 121 122 RTPrintf("Waiting for the remote session to open...\n"); 123 CHECK_ERROR_BREAK(progress, WaitForCompletion(-1)); 130 124 131 125 BOOL completed; 132 CHECK_ERROR_BREAK (progress, COMGETTER(Completed)(&completed));133 ASSERT 126 CHECK_ERROR_BREAK(progress, COMGETTER(Completed)(&completed)); 127 ASSERT(completed); 134 128 135 129 LONG resultCode; 136 CHECK_ERROR_BREAK (progress, COMGETTER(ResultCode)(&resultCode));137 if (FAILED 130 CHECK_ERROR_BREAK(progress, COMGETTER(ResultCode)(&resultCode)); 131 if (FAILED(resultCode)) 138 132 { 139 133 ProgressErrorInfo info(progress); … … 142 136 else 143 137 { 144 RTPrintf 138 RTPrintf("Remote session has been successfully opened.\n"); 145 139 } 146 140 } 147 141 else 148 142 { 149 RTPrintf 143 RTPrintf("Opening an existing session...\n"); 150 144 CHECK_ERROR_BREAK(m, LockMachine(session, LockType_Shared)); 151 145 … … 153 147 CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam())); 154 148 155 if (!strcmp 149 if (!strcmp(operation, "off")) 156 150 { 157 151 ComPtr <IProgress> progress; 158 RTPrintf 159 CHECK_ERROR_BREAK 160 161 RTPrintf 162 CHECK_ERROR_BREAK (progress, WaitForCompletion(-1));152 RTPrintf("Powering the VM off...\n"); 153 CHECK_ERROR_BREAK(console, PowerDown(progress.asOutParam())); 154 155 RTPrintf("Waiting for the VM to power down...\n"); 156 CHECK_ERROR_BREAK(progress, WaitForCompletion(-1)); 163 157 164 158 BOOL completed; 165 CHECK_ERROR_BREAK (progress, COMGETTER(Completed)(&completed));166 ASSERT 159 CHECK_ERROR_BREAK(progress, COMGETTER(Completed)(&completed)); 160 ASSERT(completed); 167 161 168 162 LONG resultCode; 169 CHECK_ERROR_BREAK (progress, COMGETTER(ResultCode)(&resultCode));170 if (FAILED 163 CHECK_ERROR_BREAK(progress, COMGETTER(ResultCode)(&resultCode)); 164 if (FAILED(resultCode)) 171 165 { 172 166 ProgressErrorInfo info(progress); … … 175 169 else 176 170 { 177 RTPrintf 171 RTPrintf("VM is powered down.\n"); 178 172 } 179 173 } 180 174 else 181 if (!strcmp 182 { 183 RTPrintf 184 CHECK_ERROR_BREAK 185 } 186 else 187 if (!strcmp 188 { 189 RTPrintf 190 CHECK_ERROR_BREAK 191 } 192 else 193 { 194 RTPrintf 175 if (!strcmp(operation, "pause")) 176 { 177 RTPrintf("Pausing the VM...\n"); 178 CHECK_ERROR_BREAK(console, Pause()); 179 } 180 else 181 if (!strcmp(operation, "resume")) 182 { 183 RTPrintf("Resuming the VM...\n"); 184 CHECK_ERROR_BREAK(console, Resume()); 185 } 186 else 187 { 188 RTPrintf("Invalid operation!\n"); 195 189 } 196 190 } … … 200 194 } 201 195 while (0); 202 RTPrintf 196 RTPrintf("\n"); 203 197 204 198 com::Shutdown(); 205 199 206 RTPrintf 200 RTPrintf("tstHeadless FINISHED.\n"); 207 201 208 202 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.