VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/tstVBoxAPI.cpp@ 50390

Last change on this file since 50390 was 50390, checked in by vboxsync, 11 years ago

svn properties

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.9 KB
Line 
1/* $Id: tstVBoxAPI.cpp 50390 2014-02-10 14:14:53Z vboxsync $ */
2/** @file
3 * tstVBoxAPI - Checks VirtualBox API.
4 */
5
6/*
7 * Copyright (C) 2006-2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <VBox/com/com.h>
23#include <VBox/com/string.h>
24#include <VBox/com/array.h>
25#include <VBox/com/Guid.h>
26#include <VBox/com/ErrorInfo.h>
27#include <VBox/com/VirtualBox.h>
28#include <VBox/sup.h>
29
30#include <iprt/test.h>
31#include <iprt/time.h>
32
33using namespace com;
34
35
36/*******************************************************************************
37* Global Variables *
38*******************************************************************************/
39static RTTEST g_hTest;
40
41
42/** Worker for TST_COM_EXPR(). */
43static HRESULT tstComExpr(HRESULT hrc, const char *pszOperation, int iLine)
44{
45 if (FAILED(hrc))
46 RTTestFailed(g_hTest, "%s failed on line %u with hrc=%Rhrc", pszOperation, iLine, hrc);
47 return hrc;
48}
49
50/** Macro that executes the given expression and report any failure.
51 * The expression must return a HRESULT. */
52#define TST_COM_EXPR(expr) tstComExpr(expr, #expr, __LINE__)
53
54
55
56static void tstApiIVirtualBox(IVirtualBox *pVBox)
57{
58 HRESULT hrc;
59 Bstr bstrTmp;
60 ULONG ulTmp;
61
62 RTTestSub(g_hTest, "IVirtualBox::version");
63 hrc = pVBox->COMGETTER(Version)(bstrTmp.asOutParam());
64 if (SUCCEEDED(hrc))
65 RTTestPassed(g_hTest, "IVirtualBox::version");
66 else
67 RTTestFailed(g_hTest, "%d: IVirtualBox::version failed with return value %Rhrc.", __LINE__, hrc);
68
69 RTTestSub(g_hTest, "IVirtualBox::versionNormalized");
70 hrc = pVBox->COMGETTER(VersionNormalized)(bstrTmp.asOutParam());
71 if (SUCCEEDED(hrc))
72 RTTestPassed(g_hTest, "IVirtualBox::versionNormalized");
73 else
74 RTTestFailed(g_hTest, "%d: IVirtualBox::versionNormalized failed with return value %Rhrc.", __LINE__, hrc);
75
76 RTTestSub(g_hTest, "IVirtualBox::revision");
77 hrc = pVBox->COMGETTER(Revision)(&ulTmp);
78 if (SUCCEEDED(hrc))
79 RTTestPassed(g_hTest, "IVirtualBox::revision");
80 else
81 RTTestFailed(g_hTest, "%d: IVirtualBox::revision failed with return value %Rhrc.", __LINE__, hrc);
82
83 RTTestSub(g_hTest, "IVirtualBox::packageType");
84 hrc = pVBox->COMGETTER(PackageType)(bstrTmp.asOutParam());
85 if (SUCCEEDED(hrc))
86 RTTestPassed(g_hTest, "IVirtualBox::packageType");
87 else
88 RTTestFailed(g_hTest, "%d: IVirtualBox::packageType failed with return value %Rhrc.", __LINE__, hrc);
89
90 RTTestSub(g_hTest, "IVirtualBox::APIVersion");
91 hrc = pVBox->COMGETTER(APIVersion)(bstrTmp.asOutParam());
92 if (SUCCEEDED(hrc))
93 RTTestPassed(g_hTest, "IVirtualBox::APIVersion");
94 else
95 RTTestFailed(g_hTest, "%d: IVirtualBox::APIVersion failed with return value %Rhrc.", __LINE__, hrc);
96
97 RTTestSub(g_hTest, "IVirtualBox::homeFolder");
98 hrc = pVBox->COMGETTER(HomeFolder)(bstrTmp.asOutParam());
99 if (SUCCEEDED(hrc))
100 RTTestPassed(g_hTest, "IVirtualBox::homeFolder");
101 else
102 RTTestFailed(g_hTest, "%d: IVirtualBox::homeFolder failed with return value %Rhrc.", __LINE__, hrc);
103
104 RTTestSub(g_hTest, "IVirtualBox::settingsFilePath");
105 hrc = pVBox->COMGETTER(SettingsFilePath)(bstrTmp.asOutParam());
106 if (SUCCEEDED(hrc))
107 RTTestPassed(g_hTest, "IVirtualBox::settingsFilePath");
108 else
109 RTTestFailed(g_hTest, "%d: IVirtualBox::settingsFilePath failed with return value %Rhrc.", __LINE__, hrc);
110
111 com::SafeIfaceArray<IGuestOSType> guestOSTypes;
112 RTTestSub(g_hTest, "IVirtualBox::guestOSTypes");
113 hrc = pVBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(guestOSTypes));
114 if (SUCCEEDED(hrc))
115 RTTestPassed(g_hTest, "IVirtualBox::guestOSTypes");
116 else
117 RTTestFailed(g_hTest, "%d: IVirtualBox::guestOSTypes failed with return value %Rhrc.", __LINE__, hrc);
118
119 /** Create VM */
120 RTTestSub(g_hTest, "IVirtualBox::CreateMachine");
121 ComPtr<IMachine> ptrMachine;
122 Bstr tstMachineName = "TestMachine";
123 com::SafeArray<BSTR> groups;
124 /** Default VM settings */
125 hrc = pVBox->CreateMachine(NULL, /** Settings */
126 tstMachineName.raw(), /** Name */
127 ComSafeArrayAsInParam(groups), /** Groups */
128 NULL, /** OS Type */
129 NULL, /** Create flags */
130 ptrMachine.asOutParam()); /** Machine */
131 if (SUCCEEDED(hrc))
132 RTTestPassed(g_hTest, "IVirtualBox::CreateMachine");
133 else
134 {
135 RTTestFailed(g_hTest, "%d: IVirtualBox::CreateMachine failed with return value %Rhrc.", __LINE__, hrc);
136 return;
137 }
138
139 RTTestSub(g_hTest, "IVirtualBox::RegisterMachine");
140 hrc = pVBox->RegisterMachine(ptrMachine);
141 if (SUCCEEDED(hrc))
142 RTTestPassed(g_hTest, "IVirtualBox::RegisterMachine");
143 else
144 {
145 RTTestFailed(g_hTest, "%d: IVirtualBox::RegisterMachine failed with return value %Rhrc.", __LINE__, hrc);
146 return;
147 }
148
149 ComPtr<IHost> host;
150 RTTestSub(g_hTest, "IVirtualBox::host");
151 hrc = pVBox->COMGETTER(Host)(host.asOutParam());
152 if (SUCCEEDED(hrc))
153 {
154 /** @todo Add IHost testing here. */
155 RTTestPassed(g_hTest, "IVirtualBox::host");
156 }
157 else
158 RTTestFailed(g_hTest, "%d: IVirtualBox::host failed with return value %Rhrc.", __LINE__, hrc);
159
160 ComPtr<ISystemProperties> sysprop;
161 RTTestSub(g_hTest, "IVirtualBox::systemProperties");
162 hrc = pVBox->COMGETTER(SystemProperties)(sysprop.asOutParam());
163 if (SUCCEEDED(hrc))
164 {
165 /** @todo Add ISystemProperties testing here. */
166 RTTestPassed(g_hTest, "IVirtualBox::systemProperties");
167 }
168 else
169 RTTestFailed(g_hTest, "%d: IVirtualBox::systemProperties failed with return value %Rhrc.", __LINE__, hrc);
170
171 com::SafeIfaceArray<IMachine> machines;
172 RTTestSub(g_hTest, "IVirtualBox::machines");
173 hrc = pVBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
174 if (SUCCEEDED(hrc))
175 {
176 bool bFound = FALSE;
177 for (size_t i = 0; i < machines.size(); ++i)
178 {
179 if (machines[i])
180 {
181 Bstr tmpName;
182 hrc = machines[i]->COMGETTER(Name)(tmpName.asOutParam());
183 if (SUCCEEDED(hrc))
184 {
185 if (tmpName == tstMachineName)
186 {
187 bFound = TRUE;
188 break;
189 }
190 }
191 }
192 }
193
194 if (bFound)
195 RTTestPassed(g_hTest, "IVirtualBox::machines");
196 else
197 RTTestFailed(g_hTest, "%d: IVirtualBox::machines failed. No created machine found", __LINE__);
198 }
199 else
200 RTTestFailed(g_hTest, "%d: IVirtualBox::machines failed with return value %Rhrc.", __LINE__, hrc);
201
202#if 0 /** Not yet implemented */
203 com::SafeIfaceArray<ISharedFolder> sharedFolders;
204 RTTestSub(g_hTest, "IVirtualBox::sharedFolders");
205 hrc = pVBox->COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sharedFolders));
206 if (SUCCEEDED(hrc))
207 {
208 /** @todo Add ISharedFolders testing here. */
209 RTTestPassed(g_hTest, "IVirtualBox::sharedFolders");
210 }
211 else
212 RTTestFailed(g_hTest, "%d: IVirtualBox::sharedFolders failed with return value %Rhrc.", __LINE__, hrc);
213#endif
214
215 com::SafeIfaceArray<IMedium> hardDisks;
216 RTTestSub(g_hTest, "IVirtualBox::hardDisks");
217 hrc = pVBox->COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hardDisks));
218 if (SUCCEEDED(hrc))
219 {
220 /** @todo Add hardDisks testing here. */
221 RTTestPassed(g_hTest, "IVirtualBox::hardDisks");
222 }
223 else
224 RTTestFailed(g_hTest, "%d: IVirtualBox::hardDisks failed with return value %Rhrc.", __LINE__, hrc);
225
226 com::SafeIfaceArray<IMedium> DVDImages;
227 RTTestSub(g_hTest, "IVirtualBox::DVDImages");
228 hrc = pVBox->COMGETTER(DVDImages)(ComSafeArrayAsOutParam(DVDImages));
229 if (SUCCEEDED(hrc))
230 {
231 /** @todo Add DVDImages testing here. */
232 RTTestPassed(g_hTest, "IVirtualBox::DVDImages");
233 }
234 else
235 RTTestFailed(g_hTest, "%d: IVirtualBox::DVDImages failed with return value %Rhrc.", __LINE__, hrc);
236
237 com::SafeIfaceArray<IMedium> floppyImages;
238 RTTestSub(g_hTest, "IVirtualBox::floppyImages");
239 hrc = pVBox->COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppyImages));
240 if (SUCCEEDED(hrc))
241 {
242 /** @todo Add floppyImages testing here. */
243 RTTestPassed(g_hTest, "IVirtualBox::floppyImages");
244 }
245 else
246 RTTestFailed(g_hTest, "%d: IVirtualBox::floppyImages failed with return value %Rhrc.", __LINE__, hrc);
247
248 com::SafeIfaceArray<IProgress> progressOperations;
249 RTTestSub(g_hTest, "IVirtualBox::progressOperations");
250 hrc = pVBox->COMGETTER(ProgressOperations)(ComSafeArrayAsOutParam(progressOperations));
251 if (SUCCEEDED(hrc))
252 {
253 /** @todo Add IProgress testing here. */
254 RTTestPassed(g_hTest, "IVirtualBox::progressOperations");
255 }
256 else
257 RTTestFailed(g_hTest, "%d: IVirtualBox::progressOperations failed with return value %Rhrc.", __LINE__, hrc);
258
259 ComPtr<IPerformanceCollector> performanceCollector;
260 RTTestSub(g_hTest, "IVirtualBox::performanceCollector");
261 hrc = pVBox->COMGETTER(PerformanceCollector)(performanceCollector.asOutParam());
262 if (SUCCEEDED(hrc))
263 {
264 /** @todo Add IPerformanceCollector testing here. */
265 RTTestPassed(g_hTest, "IVirtualBox::performanceCollector");
266 }
267 else
268 RTTestFailed(g_hTest, "%d: IVirtualBox::performanceCollector failed with return value %Rhrc.", __LINE__, hrc);
269
270 com::SafeIfaceArray<IDHCPServer> DHCPServers;
271 RTTestSub(g_hTest, "IVirtualBox::DHCPServers");
272 hrc = pVBox->COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(DHCPServers));
273 if (SUCCEEDED(hrc))
274 {
275 /** @todo Add IDHCPServers testing here. */
276 RTTestPassed(g_hTest, "IVirtualBox::DHCPServers");
277 }
278 else
279 RTTestFailed(g_hTest, "%d: IVirtualBox::DHCPServers failed with return value %Rhrc.", __LINE__, hrc);
280
281 com::SafeIfaceArray<INATNetwork> NATNetworks;
282 RTTestSub(g_hTest, "IVirtualBox::NATNetworks");
283 hrc = pVBox->COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(NATNetworks));
284 if (SUCCEEDED(hrc))
285 {
286 /** @todo Add INATNetworks testing here. */
287 RTTestPassed(g_hTest, "IVirtualBox::NATNetworks");
288 }
289 else
290 RTTestFailed(g_hTest, "%d: IVirtualBox::NATNetworks failed with return value %Rhrc.", __LINE__, hrc);
291
292 ComPtr<IEventSource> eventSource;
293 RTTestSub(g_hTest, "IVirtualBox::eventSource");
294 hrc = pVBox->COMGETTER(EventSource)(eventSource.asOutParam());
295 if (SUCCEEDED(hrc))
296 {
297 /** @todo Add IEventSource testing here. */
298 RTTestPassed(g_hTest, "IVirtualBox::eventSource");
299 }
300 else
301 RTTestFailed(g_hTest, "%d: IVirtualBox::eventSource failed with return value %Rhrc.", __LINE__, hrc);
302
303 ComPtr<IExtPackManager> extensionPackManager;
304 RTTestSub(g_hTest, "IVirtualBox::extensionPackManager");
305 hrc = pVBox->COMGETTER(ExtensionPackManager)(extensionPackManager.asOutParam());
306 if (SUCCEEDED(hrc))
307 {
308 /** @todo Add IExtPackManager testing here. */
309 RTTestPassed(g_hTest, "IVirtualBox::extensionPackManager");
310 }
311 else
312 RTTestFailed(g_hTest, "%d: IVirtualBox::extensionPackManager failed with return value %Rhrc.", __LINE__, hrc);
313
314 com::SafeArray<BSTR> internalNetworks;
315 RTTestSub(g_hTest, "IVirtualBox::internalNetworks");
316 hrc = pVBox->COMGETTER(InternalNetworks)(ComSafeArrayAsOutParam(internalNetworks));
317 if (SUCCEEDED(hrc))
318 {
319 RTTestPassed(g_hTest, "IVirtualBox::internalNetworks");
320 }
321 else
322 RTTestFailed(g_hTest, "%d: IVirtualBox::internalNetworks failed with return value %Rhrc.", __LINE__, hrc);
323
324 com::SafeArray<BSTR> genericNetworkDrivers;
325 RTTestSub(g_hTest, "IVirtualBox::genericNetworkDrivers");
326 hrc = pVBox->COMGETTER(GenericNetworkDrivers)(ComSafeArrayAsOutParam(genericNetworkDrivers));
327 if (SUCCEEDED(hrc))
328 {
329 RTTestPassed(g_hTest, "IVirtualBox::genericNetworkDrivers");
330 }
331 else
332 RTTestFailed(g_hTest, "%d: IVirtualBox::genericNetworkDrivers failed with return value %Rhrc.", __LINE__, hrc);
333}
334
335
336
337int main(int argc, char **argv)
338{
339 /*
340 * Initialization.
341 */
342 RTEXITCODE rcExit = RTTestInitAndCreate("tstVBoxAPI", &g_hTest);
343 if (rcExit != RTEXITCODE_SUCCESS)
344 return rcExit;
345 SUPR3Init(NULL); /* Better time support. */
346 RTTestBanner(g_hTest);
347
348 RTTestSub(g_hTest, "Initializing COM and singletons");
349 HRESULT hrc = com::Initialize();
350 if (SUCCEEDED(hrc))
351 {
352 ComPtr<IVirtualBox> ptrVBox;
353 hrc = TST_COM_EXPR(ptrVBox.createLocalObject(CLSID_VirtualBox));
354 if (SUCCEEDED(hrc))
355 {
356 ComPtr<ISession> ptrSession;
357 hrc = TST_COM_EXPR(ptrSession.createInprocObject(CLSID_Session));
358 if (SUCCEEDED(hrc))
359 {
360 RTTestSubDone(g_hTest);
361
362 /*
363 * Call test functions.
364 */
365
366 /** Test IVirtualBox interface */
367 tstApiIVirtualBox(ptrVBox);
368 }
369 }
370
371 ptrVBox.setNull();
372 com::Shutdown();
373 }
374 else
375 RTTestIFailed("com::Initialize failed with hrc=%Rhrc", hrc);
376 return RTTestSummaryAndDestroy(g_hTest);
377}
Note: See TracBrowser for help on using the repository browser.

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