dxdiagn: Add operating system string properties to the DxDiag_SystemInfo container.
[wine.git] / dlls / dxdiagn / tests / container.c
blob6de80e7f3907eb23ede334b7b6c9309bed01f6f8
1 /*
2 * Unit tests for IDxDiagContainer
4 * Copyright 2010 Andrew Nguyen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdio.h>
24 #include "dxdiag.h"
25 #include "oleauto.h"
26 #include "wine/test.h"
28 static IDxDiagProvider *pddp;
29 static IDxDiagContainer *pddc;
31 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
33 /* Based on debugstr_variant in dlls/jscript/jsutils.c. */
34 static const char *debugstr_variant(const VARIANT *var)
36 static char buf[400];
38 if (!var)
39 return "(null)";
41 switch (V_VT(var))
43 case VT_EMPTY:
44 return "{VT_EMPTY}";
45 case VT_BSTR:
46 sprintf(buf, "{VT_BSTR: %s}", wine_dbgstr_w(V_BSTR(var)));
47 break;
48 case VT_BOOL:
49 sprintf(buf, "{VT_BOOL: %x}", V_BOOL(var));
50 break;
51 case VT_UI4:
52 sprintf(buf, "{VT_UI4: %u}", V_UI4(var));
53 break;
54 default:
55 sprintf(buf, "{vt %d}", V_VT(var));
56 break;
59 return buf;
62 static BOOL create_root_IDxDiagContainer(void)
64 HRESULT hr;
65 DXDIAG_INIT_PARAMS params;
67 hr = CoCreateInstance(&CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER,
68 &IID_IDxDiagProvider, (LPVOID*)&pddp);
69 if (SUCCEEDED(hr))
71 params.dwSize = sizeof(params);
72 params.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION;
73 params.bAllowWHQLChecks = FALSE;
74 params.pReserved = NULL;
75 hr = IDxDiagProvider_Initialize(pddp, &params);
76 if (SUCCEEDED(hr))
78 hr = IDxDiagProvider_GetRootContainer(pddp, &pddc);
79 if (SUCCEEDED(hr))
80 return TRUE;
82 IDxDiagProvider_Release(pddp);
84 return FALSE;
87 static void test_GetNumberOfChildContainers(void)
89 HRESULT hr;
90 DWORD count;
92 if (!create_root_IDxDiagContainer())
94 skip("Unable to create the root IDxDiagContainer\n");
95 return;
98 hr = IDxDiagContainer_GetNumberOfChildContainers(pddc, NULL);
99 ok(hr == E_INVALIDARG,
100 "Expected IDxDiagContainer::GetNumberOfChildContainers to return E_INVALIDARG, got 0x%08x\n", hr);
102 hr = IDxDiagContainer_GetNumberOfChildContainers(pddc, &count);
103 ok(hr == S_OK,
104 "Expected IDxDiagContainer::GetNumberOfChildContainers to return S_OK, got 0x%08x\n", hr);
105 if (hr == S_OK)
106 ok(count != 0, "Expected the number of child containers for the root container to be non-zero\n");
108 IDxDiagContainer_Release(pddc);
109 IDxDiagProvider_Release(pddp);
112 static void test_GetNumberOfProps(void)
114 HRESULT hr;
115 DWORD count;
117 if (!create_root_IDxDiagContainer())
119 skip("Unable to create the root IDxDiagContainer\n");
120 return;
123 hr = IDxDiagContainer_GetNumberOfProps(pddc, NULL);
124 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetNumberOfProps to return E_INVALIDARG, got 0x%08x\n", hr);
126 hr = IDxDiagContainer_GetNumberOfProps(pddc, &count);
127 ok(hr == S_OK, "Expected IDxDiagContainer::GetNumberOfProps to return S_OK, got 0x%08x\n", hr);
128 if (hr == S_OK)
129 ok(count == 0, "Expected the number of properties for the root container to be zero\n");
131 IDxDiagContainer_Release(pddc);
132 IDxDiagProvider_Release(pddp);
135 static void test_EnumChildContainerNames(void)
137 HRESULT hr;
138 WCHAR container[256];
139 DWORD maxcount, index;
140 static const WCHAR testW[] = {'t','e','s','t',0};
141 static const WCHAR zerotestW[] = {0,'e','s','t',0};
143 if (!create_root_IDxDiagContainer())
145 skip("Unable to create the root IDxDiagContainer\n");
146 return;
149 /* Test various combinations of invalid parameters. */
150 hr = IDxDiagContainer_EnumChildContainerNames(pddc, 0, NULL, 0);
151 ok(hr == E_INVALIDARG,
152 "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
154 hr = IDxDiagContainer_EnumChildContainerNames(pddc, 0, NULL, sizeof(container)/sizeof(WCHAR));
155 ok(hr == E_INVALIDARG,
156 "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
158 /* Test the conditions in which the output buffer can be modified. */
159 memcpy(container, testW, sizeof(testW));
160 hr = IDxDiagContainer_EnumChildContainerNames(pddc, 0, container, 0);
161 ok(hr == E_INVALIDARG,
162 "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
163 ok(!memcmp(container, testW, sizeof(testW)),
164 "Expected the container buffer to be untouched, got %s\n", wine_dbgstr_w(container));
166 memcpy(container, testW, sizeof(testW));
167 hr = IDxDiagContainer_EnumChildContainerNames(pddc, ~0, container, 0);
168 ok(hr == E_INVALIDARG,
169 "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
170 ok(!memcmp(container, testW, sizeof(testW)),
171 "Expected the container buffer to be untouched, got %s\n", wine_dbgstr_w(container));
173 memcpy(container, testW, sizeof(testW));
174 hr = IDxDiagContainer_EnumChildContainerNames(pddc, ~0, container, sizeof(container)/sizeof(WCHAR));
175 ok(hr == E_INVALIDARG,
176 "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
177 ok(!memcmp(container, zerotestW, sizeof(zerotestW)),
178 "Expected the container buffer string to be empty, got %s\n", wine_dbgstr_w(container));
180 hr = IDxDiagContainer_GetNumberOfChildContainers(pddc, &maxcount);
181 ok(hr == S_OK, "Expected IDxDiagContainer::GetNumberOfChildContainers to return S_OK, got 0x%08x\n", hr);
182 if (FAILED(hr))
184 skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
185 goto cleanup;
188 trace("Starting child container enumeration of the root container:\n");
190 /* We should be able to enumerate as many child containers as the value
191 * that IDxDiagContainer::GetNumberOfChildContainers returns. */
192 for (index = 0; index <= maxcount; index++)
194 /* A buffer size of 1 is unlikely to be valid, as only a null terminator
195 * could be stored, and it is unlikely that a container name could be empty. */
196 DWORD buffersize = 1;
197 memcpy(container, testW, sizeof(testW));
198 hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, container, buffersize);
199 if (hr == E_INVALIDARG)
201 /* We should get here when index is one more than the maximum index value. */
202 ok(maxcount == index,
203 "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG "
204 "on the last index %d, got 0x%08x\n", index, hr);
205 ok(container[0] == '\0',
206 "Expected the container buffer string to be empty, got %s\n", wine_dbgstr_w(container));
207 break;
209 else if (hr == DXDIAG_E_INSUFFICIENT_BUFFER)
211 WCHAR temp[256];
213 ok(container[0] == '\0',
214 "Expected the container buffer string to be empty, got %s\n", wine_dbgstr_w(container));
216 /* Get the container name to compare against. */
217 hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, temp, sizeof(temp)/sizeof(WCHAR));
218 ok(hr == S_OK,
219 "Expected IDxDiagContainer::EnumChildContainerNames to return S_OK, got 0x%08x\n", hr);
221 /* Show that the DirectX SDK's stipulation that the buffer be at
222 * least 256 characters long is a mere suggestion, and smaller sizes
223 * can be acceptable also. IDxDiagContainer::EnumChildContainerNames
224 * doesn't provide a way of getting the exact size required, so the
225 * buffersize value will be iterated to at most 256 characters. */
226 for (buffersize = 2; buffersize <= 256; buffersize++)
228 memcpy(container, testW, sizeof(testW));
229 hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, container, buffersize);
230 if (hr != DXDIAG_E_INSUFFICIENT_BUFFER)
231 break;
233 ok(!memcmp(temp, container, sizeof(WCHAR)*(buffersize - 1)),
234 "Expected truncated container name string, got %s\n", wine_dbgstr_w(container));
237 ok(hr == S_OK,
238 "Expected IDxDiagContainer::EnumChildContainerNames to return S_OK, "
239 "got hr = 0x%08x, buffersize = %d\n", hr, buffersize);
240 if (hr == S_OK)
241 trace("pddc[%d] = %s, length = %d\n", index, wine_dbgstr_w(container), buffersize);
243 else
245 ok(0, "IDxDiagContainer::EnumChildContainerNames unexpectedly returned 0x%08x\n", hr);
246 break;
250 cleanup:
251 IDxDiagContainer_Release(pddc);
252 IDxDiagProvider_Release(pddp);
255 static void test_GetChildContainer(void)
257 HRESULT hr;
258 WCHAR container[256] = {0};
259 IDxDiagContainer *child;
261 if (!create_root_IDxDiagContainer())
263 skip("Unable to create the root IDxDiagContainer\n");
264 return;
267 /* Test various combinations of invalid parameters. */
268 hr = IDxDiagContainer_GetChildContainer(pddc, NULL, NULL);
269 ok(hr == E_INVALIDARG,
270 "Expected IDxDiagContainer::GetChildContainer to return E_INVALIDARG, got 0x%08x\n", hr);
272 child = (void*)0xdeadbeef;
273 hr = IDxDiagContainer_GetChildContainer(pddc, NULL, &child);
274 ok(hr == E_INVALIDARG,
275 "Expected IDxDiagContainer::GetChildContainer to return E_INVALIDARG, got 0x%08x\n", hr);
276 ok(child == (void*)0xdeadbeef, "Expected output pointer to be unchanged, got %p\n", child);
278 hr = IDxDiagContainer_GetChildContainer(pddc, container, NULL);
279 ok(hr == E_INVALIDARG,
280 "Expected IDxDiagContainer::GetChildContainer to return E_INVALIDARG, got 0x%08x\n", hr);
282 child = (void*)0xdeadbeef;
283 hr = IDxDiagContainer_GetChildContainer(pddc, container, &child);
284 ok(hr == E_INVALIDARG,
285 "Expected IDxDiagContainer::GetChildContainer to return E_INVALIDARG, got 0x%08x\n", hr);
286 ok(child == NULL, "Expected output pointer to be NULL, got %p\n", child);
288 /* Get the name of a suitable child container. */
289 hr = IDxDiagContainer_EnumChildContainerNames(pddc, 0, container, sizeof(container)/sizeof(WCHAR));
290 ok(hr == S_OK,
291 "Expected IDxDiagContainer::EnumChildContainerNames to return S_OK, got 0x%08x\n", hr);
292 if (FAILED(hr))
294 skip("IDxDiagContainer::EnumChildContainerNames failed\n");
295 goto cleanup;
298 child = (void*)0xdeadbeef;
299 hr = IDxDiagContainer_GetChildContainer(pddc, container, &child);
300 ok(hr == S_OK,
301 "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
302 ok(child != NULL && child != (void*)0xdeadbeef, "Expected a valid output pointer, got %p\n", child);
304 if (SUCCEEDED(hr))
306 IDxDiagContainer *ptr;
308 /* Show that IDxDiagContainer::GetChildContainer returns a different pointer
309 * for multiple calls for the same container name. */
310 hr = IDxDiagContainer_GetChildContainer(pddc, container, &ptr);
311 ok(hr == S_OK,
312 "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
313 if (SUCCEEDED(hr))
314 ok(ptr != child, "Expected the two pointers (%p vs. %p) to be unequal\n", child, ptr);
316 IDxDiagContainer_Release(ptr);
317 IDxDiagContainer_Release(child);
320 cleanup:
321 IDxDiagContainer_Release(pddc);
322 IDxDiagProvider_Release(pddp);
325 static void test_dot_parsing(void)
327 HRESULT hr;
328 WCHAR containerbufW[256] = {0}, childbufW[256] = {0};
329 DWORD count, index;
330 size_t i;
331 static const struct
333 const char *format;
334 const HRESULT expect;
335 } test_strings[] = {
336 { "%s.%s", S_OK },
337 { "%s.%s.", S_OK },
338 { ".%s.%s", E_INVALIDARG },
339 { "%s.%s..", E_INVALIDARG },
340 { ".%s.%s.", E_INVALIDARG },
341 { "..%s.%s", E_INVALIDARG },
344 if (!create_root_IDxDiagContainer())
346 skip("Unable to create the root IDxDiagContainer\n");
347 return;
350 /* Find a container with a child container of its own. */
351 hr = IDxDiagContainer_GetNumberOfChildContainers(pddc, &count);
352 ok(hr == S_OK, "Expected IDxDiagContainer::GetNumberOfChildContainers to return S_OK, got 0x%08x\n", hr);
353 if (FAILED(hr))
355 skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
356 goto cleanup;
359 for (index = 0; index < count; index++)
361 IDxDiagContainer *child;
363 hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, containerbufW, sizeof(containerbufW)/sizeof(WCHAR));
364 ok(hr == S_OK, "Expected IDxDiagContainer_EnumChildContainerNames to return S_OK, got 0x%08x\n", hr);
365 if (FAILED(hr))
367 skip("IDxDiagContainer::EnumChildContainerNames failed\n");
368 goto cleanup;
371 hr = IDxDiagContainer_GetChildContainer(pddc, containerbufW, &child);
372 ok(hr == S_OK, "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
374 if (SUCCEEDED(hr))
376 hr = IDxDiagContainer_EnumChildContainerNames(child, 0, childbufW, sizeof(childbufW)/sizeof(WCHAR));
377 ok(hr == S_OK || hr == E_INVALIDARG,
378 "Expected IDxDiagContainer::EnumChildContainerNames to return S_OK or E_INVALIDARG, got 0x%08x\n", hr);
379 IDxDiagContainer_Release(child);
381 if (SUCCEEDED(hr))
382 break;
386 if (!*containerbufW || !*childbufW)
388 skip("Unable to find a suitable container\n");
389 goto cleanup;
392 trace("Testing IDxDiagContainer::GetChildContainer dot parsing with container %s and child container %s.\n",
393 wine_dbgstr_w(containerbufW), wine_dbgstr_w(childbufW));
395 for (i = 0; i < sizeof(test_strings)/sizeof(test_strings[0]); i++)
397 IDxDiagContainer *child;
398 char containerbufA[256];
399 char childbufA[256];
400 char dotbufferA[255 + 255 + 3 + 1];
401 WCHAR dotbufferW[255 + 255 + 3 + 1]; /* containerbuf + childbuf + dots + null terminator */
403 WideCharToMultiByte(CP_ACP, 0, containerbufW, -1, containerbufA, sizeof(containerbufA), NULL, NULL);
404 WideCharToMultiByte(CP_ACP, 0, childbufW, -1, childbufA, sizeof(childbufA), NULL, NULL);
405 sprintf(dotbufferA, test_strings[i].format, containerbufA, childbufA);
406 MultiByteToWideChar(CP_ACP, 0, dotbufferA, -1, dotbufferW, sizeof(dotbufferW)/sizeof(WCHAR));
408 trace("Trying container name %s\n", wine_dbgstr_w(dotbufferW));
409 hr = IDxDiagContainer_GetChildContainer(pddc, dotbufferW, &child);
410 ok(hr == test_strings[i].expect,
411 "Expected IDxDiagContainer::GetChildContainer to return 0x%08x for %s, got 0x%08x\n",
412 test_strings[i].expect, wine_dbgstr_w(dotbufferW), hr);
413 if (SUCCEEDED(hr))
414 IDxDiagContainer_Release(child);
417 cleanup:
418 IDxDiagContainer_Release(pddc);
419 IDxDiagProvider_Release(pddp);
422 static void test_EnumPropNames(void)
424 HRESULT hr;
425 WCHAR container[256], property[256];
426 IDxDiagContainer *child = NULL;
427 DWORD count, index, propcount;
428 static const WCHAR testW[] = {'t','e','s','t',0};
430 if (!create_root_IDxDiagContainer())
432 skip("Unable to create the root IDxDiagContainer\n");
433 return;
436 /* Find a container with a non-zero number of properties. */
437 hr = IDxDiagContainer_GetNumberOfChildContainers(pddc, &count);
438 ok(hr == S_OK, "Expected IDxDiagContainer::GetNumberOfChildContainers to return S_OK, got 0x%08x\n", hr);
439 if (FAILED(hr))
441 skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
442 goto cleanup;
445 for (index = 0; index < count; index++)
447 hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, container, sizeof(container)/sizeof(WCHAR));
448 ok(hr == S_OK, "Expected IDxDiagContainer_EnumChildContainerNames to return S_OK, got 0x%08x\n", hr);
449 if (FAILED(hr))
451 skip("IDxDiagContainer::EnumChildContainerNames failed\n");
452 goto cleanup;
455 hr = IDxDiagContainer_GetChildContainer(pddc, container, &child);
456 ok(hr == S_OK, "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
458 if (SUCCEEDED(hr))
460 hr = IDxDiagContainer_GetNumberOfProps(child, &propcount);
461 ok(hr == S_OK, "Expected IDxDiagContainer::GetNumberOfProps to return S_OK, got 0x%08x\n", hr);
463 if (!propcount)
465 IDxDiagContainer_Release(child);
466 child = NULL;
468 else
469 break;
473 if (!child)
475 skip("Unable to find a container with non-zero property count\n");
476 goto cleanup;
479 hr = IDxDiagContainer_EnumPropNames(child, ~0, NULL, 0);
480 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::EnumPropNames to return E_INVALIDARG, got 0x%08x\n", hr);
482 memcpy(property, testW, sizeof(testW));
483 hr = IDxDiagContainer_EnumPropNames(child, ~0, property, 0);
484 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::EnumPropNames to return E_INVALIDARG, got 0x%08x\n", hr);
485 ok(!memcmp(property, testW, sizeof(testW)),
486 "Expected the property buffer to be unchanged, got %s\n", wine_dbgstr_w(property));
488 memcpy(property, testW, sizeof(testW));
489 hr = IDxDiagContainer_EnumPropNames(child, ~0, property, sizeof(property)/sizeof(WCHAR));
490 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::EnumPropNames to return E_INVALIDARG, got 0x%08x\n", hr);
491 ok(!memcmp(property, testW, sizeof(testW)),
492 "Expected the property buffer to be unchanged, got %s\n", wine_dbgstr_w(property));
494 trace("Starting property enumeration of the %s container:\n", wine_dbgstr_w(container));
496 /* We should be able to enumerate as many properties as the value that
497 * IDxDiagContainer::GetNumberOfProps returns. */
498 for (index = 0; index <= propcount; index++)
500 /* A buffer size of 1 is unlikely to be valid, as only a null terminator
501 * could be stored, and it is unlikely that a property name could be empty. */
502 DWORD buffersize = 1;
504 memcpy(property, testW, sizeof(testW));
505 hr = IDxDiagContainer_EnumPropNames(child, index, property, buffersize);
506 if (hr == E_INVALIDARG)
508 /* We should get here when index is one more than the maximum index value. */
509 ok(propcount == index,
510 "Expected IDxDiagContainer::EnumPropNames to return E_INVALIDARG "
511 "on the last index %d, got 0x%08x\n", index, hr);
512 ok(!memcmp(property, testW, sizeof(testW)),
513 "Expected the property buffer to be unchanged, got %s\n", wine_dbgstr_w(property));
514 break;
516 else if (hr == DXDIAG_E_INSUFFICIENT_BUFFER)
518 WCHAR temp[256];
520 ok(property[0] == '\0',
521 "Expected the property buffer string to be empty, got %s\n", wine_dbgstr_w(property));
522 hr = IDxDiagContainer_EnumPropNames(child, index, temp, sizeof(temp)/sizeof(WCHAR));
523 ok(hr == S_OK,
524 "Expected IDxDiagContainer::EnumPropNames to return S_OK, got 0x%08x\n", hr);
526 /* Show that the DirectX SDK's stipulation that the buffer be at
527 * least 256 characters long is a mere suggestion, and smaller sizes
528 * can be acceptable also. IDxDiagContainer::EnumPropNames doesn't
529 * provide a way of getting the exact size required, so the buffersize
530 * value will be iterated to at most 256 characters. */
531 for (buffersize = 2; buffersize <= 256; buffersize++)
533 memcpy(property, testW, sizeof(testW));
534 hr = IDxDiagContainer_EnumPropNames(child, index, property, buffersize);
535 if (hr != DXDIAG_E_INSUFFICIENT_BUFFER)
536 break;
538 ok(!memcmp(temp, property, sizeof(WCHAR)*(buffersize - 1)),
539 "Expected truncated property name string, got %s\n", wine_dbgstr_w(property));
542 ok(hr == S_OK,
543 "Expected IDxDiagContainer::EnumPropNames to return S_OK, "
544 "got hr = 0x%08x, buffersize = %d\n", hr, buffersize);
545 if (hr == S_OK)
546 trace("child[%d] = %s, length = %d\n", index, wine_dbgstr_w(property), buffersize);
548 else
550 ok(0, "IDxDiagContainer::EnumPropNames unexpectedly returned 0x%08x\n", hr);
551 break;
555 IDxDiagContainer_Release(child);
557 cleanup:
558 IDxDiagContainer_Release(pddc);
559 IDxDiagProvider_Release(pddp);
562 static void test_GetProp(void)
564 HRESULT hr;
565 WCHAR container[256], property[256];
566 IDxDiagContainer *child = NULL;
567 DWORD count, index;
568 VARIANT var;
569 SAFEARRAY *sa;
570 SAFEARRAYBOUND bound;
571 static const WCHAR emptyW[] = {0};
572 static const WCHAR testW[] = {'t','e','s','t',0};
574 if (!create_root_IDxDiagContainer())
576 skip("Unable to create the root IDxDiagContainer\n");
577 return;
580 /* Find a container with a property. */
581 hr = IDxDiagContainer_GetNumberOfChildContainers(pddc, &count);
582 ok(hr == S_OK, "Expected IDxDiagContainer::GetNumberOfChildContainers to return S_OK, got 0x%08x\n", hr);
583 if (FAILED(hr))
585 skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
586 goto cleanup;
589 for (index = 0; index < count; index++)
591 hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, container, sizeof(container)/sizeof(WCHAR));
592 ok(hr == S_OK, "Expected IDxDiagContainer_EnumChildContainerNames to return S_OK, got 0x%08x\n", hr);
593 if (FAILED(hr))
595 skip("IDxDiagContainer::EnumChildContainerNames failed\n");
596 goto cleanup;
599 hr = IDxDiagContainer_GetChildContainer(pddc, container, &child);
600 ok(hr == S_OK, "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
602 if (SUCCEEDED(hr))
604 hr = IDxDiagContainer_EnumPropNames(child, 0, property, sizeof(property)/sizeof(WCHAR));
605 ok(hr == S_OK || hr == E_INVALIDARG,
606 "Expected IDxDiagContainer::EnumPropNames to return S_OK or E_INVALIDARG, got 0x%08x\n", hr);
608 if (SUCCEEDED(hr))
609 break;
610 else
612 IDxDiagContainer_Release(child);
613 child = NULL;
618 if (!child)
620 skip("Unable to find a suitable container\n");
621 goto cleanup;
624 hr = IDxDiagContainer_GetProp(child, NULL, NULL);
625 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetProp to return E_INVALIDARG, got 0x%08x\n", hr);
627 V_VT(&var) = 0xdead;
628 hr = IDxDiagContainer_GetProp(child, NULL, &var);
629 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetProp to return E_INVALIDARG, got 0x%08x\n", hr);
630 ok(V_VT(&var) == 0xdead, "Expected the variant to be untouched, got %u\n", V_VT(&var));
632 hr = IDxDiagContainer_GetProp(child, emptyW, NULL);
633 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetProp to return E_INVALIDARG, got 0x%08x\n", hr);
635 V_VT(&var) = 0xdead;
636 hr = IDxDiagContainer_GetProp(child, emptyW, &var);
637 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetProp to return E_INVALIDARG, got 0x%08x\n", hr);
638 ok(V_VT(&var) == 0xdead, "Expected the variant to be untouched, got %u\n", V_VT(&var));
640 hr = IDxDiagContainer_GetProp(child, testW, NULL);
641 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetProp to return E_INVALIDARG, got 0x%08x\n", hr);
643 V_VT(&var) = 0xdead;
644 hr = IDxDiagContainer_GetProp(child, testW, &var);
645 ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetProp to return E_INVALIDARG, got 0x%08x\n", hr);
646 ok(V_VT(&var) == 0xdead, "Expected the variant to be untouched, got %u\n", V_VT(&var));
648 VariantInit(&var);
649 hr = IDxDiagContainer_GetProp(child, property, &var);
650 ok(hr == S_OK, "Expected IDxDiagContainer::GetProp to return S_OK, got 0x%08x\n", hr);
651 ok(V_VT(&var) != VT_EMPTY, "Expected the variant to be modified, got %d\n", V_VT(&var));
653 /* Since the documentation for IDxDiagContainer::GetProp claims that the
654 * function reports return values from VariantCopy, try to exercise failure
655 * paths in handling the destination variant. */
657 /* Try an invalid variant type. */
658 V_VT(&var) = 0xdead;
659 hr = IDxDiagContainer_GetProp(child, property, &var);
660 ok(hr == S_OK, "Expected IDxDiagContainer::GetProp to return S_OK, got 0x%08x\n", hr);
661 ok(V_VT(&var) != 0xdead, "Expected the variant to be modified, got %d\n", V_VT(&var));
663 /* Try passing a variant with a locked SAFEARRAY. */
664 bound.cElements = 1;
665 bound.lLbound = 0;
666 sa = SafeArrayCreate(VT_UI1, 1, &bound);
667 ok(sa != NULL, "Expected SafeArrayCreate to return a valid pointer\n");
669 V_VT(&var) = (VT_ARRAY | VT_UI1);
670 V_ARRAY(&var) = sa;
672 hr = SafeArrayLock(sa);
673 ok(hr == S_OK, "Expected SafeArrayLock to return S_OK, got 0x%08x\n", hr);
675 hr = IDxDiagContainer_GetProp(child, property, &var);
676 ok(hr == S_OK, "Expected IDxDiagContainer::GetProp to return S_OK, got 0x%08x\n", hr);
677 ok(V_VT(&var) != (VT_ARRAY | VT_UI1), "Expected the variant to be modified\n");
679 hr = SafeArrayUnlock(sa);
680 ok(hr == S_OK, "Expected SafeArrayUnlock to return S_OK, got 0x%08x\n", hr);
681 hr = SafeArrayDestroy(sa);
682 ok(hr == S_OK, "Expected SafeArrayDestroy to return S_OK, got 0x%08x\n", hr);
683 IDxDiagContainer_Release(child);
685 cleanup:
686 IDxDiagContainer_Release(pddc);
687 IDxDiagProvider_Release(pddp);
690 static void test_root_children(void)
692 static const WCHAR DxDiag_DisplayDevices[] = {'D','x','D','i','a','g','_','D','i','s','p','l','a','y','D','e','v','i','c','e','s',0};
693 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
694 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
695 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
696 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
697 static const WCHAR DxDiag_SystemDevices[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','D','e','v','i','c','e','s',0};
698 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
699 static const WCHAR DxDiag_DirectShowFilters[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','h','o','w','F','i','l','t','e','r','s',0};
700 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
702 HRESULT hr;
703 DWORD count, index;
705 static const WCHAR *root_children[] = {
706 DxDiag_SystemInfo, DxDiag_DisplayDevices, DxDiag_DirectSound,
707 DxDiag_DirectMusic, DxDiag_DirectInput, DxDiag_DirectPlay,
708 DxDiag_SystemDevices, DxDiag_DirectXFiles, DxDiag_DirectShowFilters,
709 DxDiag_LogicalDisks
712 if (!create_root_IDxDiagContainer())
714 skip("Unable to create the root IDxDiagContainer\n");
715 return;
718 /* Verify the identity and ordering of the root container's children. */
719 hr = IDxDiagContainer_GetNumberOfChildContainers(pddc, &count);
720 ok(hr == S_OK, "Expected IDxDiagContainer::GetNumberOfChildContainers to return S_OK, got 0x%08x\n", hr);
721 if (FAILED(hr))
723 skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
724 goto cleanup;
727 ok(count == sizeof(root_children)/sizeof(root_children[0]),
728 "Got unexpected count %u for the number of child containers\n", count);
730 if (count != sizeof(root_children)/sizeof(root_children[0]))
732 skip("Received unexpected number of child containers\n");
733 goto cleanup;
736 for (index = 0; index <= count; index++)
738 WCHAR container[256];
740 hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, container, sizeof(container)/sizeof(WCHAR));
741 if (hr == E_INVALIDARG)
743 ok(index == count,
744 "Expected IDxDiagContainer::EnumChildContainerNames to return "
745 "E_INVALIDARG on the last index %u\n", count);
746 break;
748 else if (hr == S_OK)
750 ok(!lstrcmpW(container, root_children[index]),
751 "Expected container %s for index %u, got %s\n",
752 wine_dbgstr_w(root_children[index]), index, wine_dbgstr_w(container));
754 else
756 ok(0, "IDxDiagContainer::EnumChildContainerNames unexpectedly returned 0x%08x\n", hr);
757 break;
761 cleanup:
762 IDxDiagContainer_Release(pddc);
763 IDxDiagProvider_Release(pddp);
766 static void test_DxDiag_SystemInfo(void)
768 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
769 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
770 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
771 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
772 static const WCHAR dwDirectXVersionMajor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','a','j','o','r',0};
773 static const WCHAR dwDirectXVersionMinor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','i','n','o','r',0};
774 static const WCHAR szDirectXVersionLetter[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','e','t','t','e','r',0};
775 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
776 static const WCHAR bNECPC98[] = {'b','N','E','C','P','C','9','8',0};
777 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
778 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
779 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
780 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
781 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
782 static const WCHAR szDirectXVersionEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','E','n','g','l','i','s','h',0};
783 static const WCHAR szDirectXVersionLongEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','o','n','g','E','n','g','l','i','s','h',0};
784 static const WCHAR bNetMeetingRunning[] = {'b','N','e','t','M','e','e','t','i','n','g','R','u','n','n','i','n','g',0};
785 static const WCHAR szMachineNameLocalized[] = {'s','z','M','a','c','h','i','n','e','N','a','m','e','L','o','c','a','l','i','z','e','d',0};
786 static const WCHAR szMachineNameEnglish[] = {'s','z','M','a','c','h','i','n','e','N','a','m','e','E','n','g','l','i','s','h',0};
787 static const WCHAR szLanguagesLocalized[] = {'s','z','L','a','n','g','u','a','g','e','s','L','o','c','a','l','i','z','e','d',0};
788 static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
789 static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
790 static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
791 static const WCHAR szPhysicalMemoryEnglish[] = {'s','z','P','h','y','s','i','c','a','l','M','e','m','o','r','y','E','n','g','l','i','s','h',0};
792 static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
793 static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
794 static const WCHAR szOSLocalized[] = {'s','z','O','S','L','o','c','a','l','i','z','e','d',0};
795 static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
796 static const WCHAR szOSExLongLocalized[] = {'s','z','O','S','E','x','L','o','n','g','L','o','c','a','l','i','z','e','d',0};
797 static const WCHAR szOSEnglish[] = {'s','z','O','S','E','n','g','l','i','s','h',0};
798 static const WCHAR szOSExEnglish[] = {'s','z','O','S','E','x','E','n','g','l','i','s','h',0};
799 static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
801 static const struct
803 const WCHAR *prop;
804 VARTYPE vt;
805 } property_tests[] =
807 {dwOSMajorVersion, VT_UI4},
808 {dwOSMinorVersion, VT_UI4},
809 {dwOSBuildNumber, VT_UI4},
810 {dwOSPlatformID, VT_UI4},
811 {dwDirectXVersionMajor, VT_UI4},
812 {dwDirectXVersionMinor, VT_UI4},
813 {szDirectXVersionLetter, VT_BSTR},
814 {bDebug, VT_BOOL},
815 {bNECPC98, VT_BOOL},
816 {ullPhysicalMemory, VT_BSTR},
817 {ullUsedPageFile, VT_BSTR},
818 {ullAvailPageFile, VT_BSTR},
819 {szWindowsDir, VT_BSTR},
820 {szCSDVersion, VT_BSTR},
821 {szDirectXVersionEnglish, VT_BSTR},
822 {szDirectXVersionLongEnglish, VT_BSTR},
823 {bNetMeetingRunning, VT_BOOL},
824 {szMachineNameLocalized, VT_BSTR},
825 {szMachineNameEnglish, VT_BSTR},
826 {szLanguagesLocalized, VT_BSTR},
827 {szLanguagesEnglish, VT_BSTR},
828 {szTimeLocalized, VT_BSTR},
829 {szTimeEnglish, VT_BSTR},
830 {szPhysicalMemoryEnglish, VT_BSTR},
831 {szPageFileLocalized, VT_BSTR},
832 {szPageFileEnglish, VT_BSTR},
833 {szOSLocalized, VT_BSTR},
834 {szOSExLocalized, VT_BSTR},
835 {szOSExLongLocalized, VT_BSTR},
836 {szOSEnglish, VT_BSTR},
837 {szOSExEnglish, VT_BSTR},
838 {szOSExLongEnglish, VT_BSTR},
841 HRESULT hr;
842 IDxDiagContainer *child = NULL;
843 VARIANT var;
845 if (!create_root_IDxDiagContainer())
847 skip("Unable to create the root IDxDiagContainer\n");
848 return;
851 hr = IDxDiagContainer_GetChildContainer(pddc, DxDiag_SystemInfo, &child);
852 ok(hr == S_OK, "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
854 if (hr == S_OK)
856 int i;
858 /* Examine the variant types of obtained property values. */
859 for (i = 0; i < sizeof(property_tests)/sizeof(property_tests[0]); i++)
861 hr = IDxDiagContainer_GetProp(child, property_tests[i].prop, &var);
862 ok(hr == S_OK, "[%d] Expected IDxDiagContainer::GetProp to return S_OK, got 0x%08x\n", i, hr);
864 if (hr == S_OK)
866 ok(V_VT(&var) == property_tests[i].vt,
867 "[%d] Expected variant type %d, got %d\n", i, property_tests[i].vt, V_VT(&var));
868 trace("%s = %s\n", wine_dbgstr_w(property_tests[i].prop), debugstr_variant(&var));
869 VariantClear(&var);
874 IDxDiagContainer_Release(child);
875 IDxDiagContainer_Release(pddc);
876 IDxDiagProvider_Release(pddp);
879 START_TEST(container)
881 CoInitialize(NULL);
882 test_GetNumberOfChildContainers();
883 test_GetNumberOfProps();
884 test_EnumChildContainerNames();
885 test_GetChildContainer();
886 test_dot_parsing();
887 test_EnumPropNames();
888 test_GetProp();
890 test_root_children();
891 test_DxDiag_SystemInfo();
892 CoUninitialize();