dxdiagn: Add date and time properties to the DxDiag_SystemInfo container.
[wine] / dlls / dxdiagn / tests / container.c
1 /*
2  * Unit tests for IDxDiagContainer
3  *
4  * Copyright 2010 Andrew Nguyen
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COBJMACROS
22
23 #include <stdio.h>
24 #include "dxdiag.h"
25 #include "oleauto.h"
26 #include "wine/test.h"
27
28 static IDxDiagProvider *pddp;
29 static IDxDiagContainer *pddc;
30
31 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
32
33 /* Based on debugstr_variant in dlls/jscript/jsutils.c. */
34 static const char *debugstr_variant(const VARIANT *var)
35 {
36     static char buf[400];
37
38     if (!var)
39         return "(null)";
40
41     switch (V_VT(var))
42     {
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;
57     }
58
59     return buf;
60 }
61
62 static BOOL create_root_IDxDiagContainer(void)
63 {
64     HRESULT hr;
65     DXDIAG_INIT_PARAMS params;
66
67     hr = CoCreateInstance(&CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER,
68                           &IID_IDxDiagProvider, (LPVOID*)&pddp);
69     if (SUCCEEDED(hr))
70     {
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))
77         {
78             hr = IDxDiagProvider_GetRootContainer(pddp, &pddc);
79             if (SUCCEEDED(hr))
80                 return TRUE;
81         }
82         IDxDiagProvider_Release(pddp);
83     }
84     return FALSE;
85 }
86
87 static void test_GetNumberOfChildContainers(void)
88 {
89     HRESULT hr;
90     DWORD count;
91
92     if (!create_root_IDxDiagContainer())
93     {
94         skip("Unable to create the root IDxDiagContainer\n");
95         return;
96     }
97
98     hr = IDxDiagContainer_GetNumberOfChildContainers(pddc, NULL);
99     ok(hr == E_INVALIDARG,
100        "Expected IDxDiagContainer::GetNumberOfChildContainers to return E_INVALIDARG, got 0x%08x\n", hr);
101
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");
107
108     IDxDiagContainer_Release(pddc);
109     IDxDiagProvider_Release(pddp);
110 }
111
112 static void test_GetNumberOfProps(void)
113 {
114     HRESULT hr;
115     DWORD count;
116
117     if (!create_root_IDxDiagContainer())
118     {
119         skip("Unable to create the root IDxDiagContainer\n");
120         return;
121     }
122
123     hr = IDxDiagContainer_GetNumberOfProps(pddc, NULL);
124     ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetNumberOfProps to return E_INVALIDARG, got 0x%08x\n", hr);
125
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");
130
131     IDxDiagContainer_Release(pddc);
132     IDxDiagProvider_Release(pddp);
133 }
134
135 static void test_EnumChildContainerNames(void)
136 {
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};
142
143     if (!create_root_IDxDiagContainer())
144     {
145         skip("Unable to create the root IDxDiagContainer\n");
146         return;
147     }
148
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);
153
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);
157
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));
165
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));
172
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));
179
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))
183     {
184         skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
185         goto cleanup;
186     }
187
188     trace("Starting child container enumeration of the root container:\n");
189
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++)
193     {
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)
200         {
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;
208         }
209         else if (hr == DXDIAG_E_INSUFFICIENT_BUFFER)
210         {
211             WCHAR temp[256];
212
213             ok(container[0] == '\0',
214                "Expected the container buffer string to be empty, got %s\n", wine_dbgstr_w(container));
215
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);
220
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++)
227             {
228                 memcpy(container, testW, sizeof(testW));
229                 hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, container, buffersize);
230                 if (hr != DXDIAG_E_INSUFFICIENT_BUFFER)
231                     break;
232
233                 ok(!memcmp(temp, container, sizeof(WCHAR)*(buffersize - 1)),
234                    "Expected truncated container name string, got %s\n", wine_dbgstr_w(container));
235             }
236
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);
242         }
243         else
244         {
245             ok(0, "IDxDiagContainer::EnumChildContainerNames unexpectedly returned 0x%08x\n", hr);
246             break;
247         }
248     }
249
250 cleanup:
251     IDxDiagContainer_Release(pddc);
252     IDxDiagProvider_Release(pddp);
253 }
254
255 static void test_GetChildContainer(void)
256 {
257     HRESULT hr;
258     WCHAR container[256] = {0};
259     IDxDiagContainer *child;
260
261     if (!create_root_IDxDiagContainer())
262     {
263         skip("Unable to create the root IDxDiagContainer\n");
264         return;
265     }
266
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);
271
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);
277
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);
281
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);
287
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))
293     {
294         skip("IDxDiagContainer::EnumChildContainerNames failed\n");
295         goto cleanup;
296     }
297
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);
303
304     if (SUCCEEDED(hr))
305     {
306         IDxDiagContainer *ptr;
307
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);
315
316         IDxDiagContainer_Release(ptr);
317         IDxDiagContainer_Release(child);
318     }
319
320 cleanup:
321     IDxDiagContainer_Release(pddc);
322     IDxDiagProvider_Release(pddp);
323 }
324
325 static void test_dot_parsing(void)
326 {
327     HRESULT hr;
328     WCHAR containerbufW[256] = {0}, childbufW[256] = {0};
329     DWORD count, index;
330     size_t i;
331     static const struct
332     {
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 },
342     };
343
344     if (!create_root_IDxDiagContainer())
345     {
346         skip("Unable to create the root IDxDiagContainer\n");
347         return;
348     }
349
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))
354     {
355         skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
356         goto cleanup;
357     }
358
359     for (index = 0; index < count; index++)
360     {
361         IDxDiagContainer *child;
362
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))
366         {
367             skip("IDxDiagContainer::EnumChildContainerNames failed\n");
368             goto cleanup;
369         }
370
371         hr = IDxDiagContainer_GetChildContainer(pddc, containerbufW, &child);
372         ok(hr == S_OK, "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
373
374         if (SUCCEEDED(hr))
375         {
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);
380
381             if (SUCCEEDED(hr))
382                 break;
383         }
384     }
385
386     if (!*containerbufW || !*childbufW)
387     {
388         skip("Unable to find a suitable container\n");
389         goto cleanup;
390     }
391
392     trace("Testing IDxDiagContainer::GetChildContainer dot parsing with container %s and child container %s.\n",
393           wine_dbgstr_w(containerbufW), wine_dbgstr_w(childbufW));
394
395     for (i = 0; i < sizeof(test_strings)/sizeof(test_strings[0]); i++)
396     {
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 */
402
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));
407
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);
415     }
416
417 cleanup:
418     IDxDiagContainer_Release(pddc);
419     IDxDiagProvider_Release(pddp);
420 }
421
422 static void test_EnumPropNames(void)
423 {
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};
429
430     if (!create_root_IDxDiagContainer())
431     {
432         skip("Unable to create the root IDxDiagContainer\n");
433         return;
434     }
435
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))
440     {
441         skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
442         goto cleanup;
443     }
444
445     for (index = 0; index < count; index++)
446     {
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))
450         {
451             skip("IDxDiagContainer::EnumChildContainerNames failed\n");
452             goto cleanup;
453         }
454
455         hr = IDxDiagContainer_GetChildContainer(pddc, container, &child);
456         ok(hr == S_OK, "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
457
458         if (SUCCEEDED(hr))
459         {
460             hr = IDxDiagContainer_GetNumberOfProps(child, &propcount);
461             ok(hr == S_OK, "Expected IDxDiagContainer::GetNumberOfProps to return S_OK, got 0x%08x\n", hr);
462
463             if (!propcount)
464             {
465                 IDxDiagContainer_Release(child);
466                 child = NULL;
467             }
468             else
469                 break;
470         }
471     }
472
473     if (!child)
474     {
475         skip("Unable to find a container with non-zero property count\n");
476         goto cleanup;
477     }
478
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);
481
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));
487
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));
493
494     trace("Starting property enumeration of the %s container:\n", wine_dbgstr_w(container));
495
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++)
499     {
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;
503
504         memcpy(property, testW, sizeof(testW));
505         hr = IDxDiagContainer_EnumPropNames(child, index, property, buffersize);
506         if (hr == E_INVALIDARG)
507         {
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;
515         }
516         else if (hr == DXDIAG_E_INSUFFICIENT_BUFFER)
517         {
518             WCHAR temp[256];
519
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);
525
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++)
532             {
533                 memcpy(property, testW, sizeof(testW));
534                 hr = IDxDiagContainer_EnumPropNames(child, index, property, buffersize);
535                 if (hr != DXDIAG_E_INSUFFICIENT_BUFFER)
536                     break;
537
538                 ok(!memcmp(temp, property, sizeof(WCHAR)*(buffersize - 1)),
539                    "Expected truncated property name string, got %s\n", wine_dbgstr_w(property));
540             }
541
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);
547         }
548         else
549         {
550             ok(0, "IDxDiagContainer::EnumPropNames unexpectedly returned 0x%08x\n", hr);
551             break;
552         }
553     }
554
555     IDxDiagContainer_Release(child);
556
557 cleanup:
558     IDxDiagContainer_Release(pddc);
559     IDxDiagProvider_Release(pddp);
560 }
561
562 static void test_GetProp(void)
563 {
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};
573
574     if (!create_root_IDxDiagContainer())
575     {
576         skip("Unable to create the root IDxDiagContainer\n");
577         return;
578     }
579
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))
584     {
585         skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
586         goto cleanup;
587     }
588
589     for (index = 0; index < count; index++)
590     {
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))
594         {
595             skip("IDxDiagContainer::EnumChildContainerNames failed\n");
596             goto cleanup;
597         }
598
599         hr = IDxDiagContainer_GetChildContainer(pddc, container, &child);
600         ok(hr == S_OK, "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
601
602         if (SUCCEEDED(hr))
603         {
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);
607
608             if (SUCCEEDED(hr))
609                 break;
610             else
611             {
612                 IDxDiagContainer_Release(child);
613                 child = NULL;
614             }
615         }
616     }
617
618     if (!child)
619     {
620         skip("Unable to find a suitable container\n");
621         goto cleanup;
622     }
623
624     hr = IDxDiagContainer_GetProp(child, NULL, NULL);
625     ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetProp to return E_INVALIDARG, got 0x%08x\n", hr);
626
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));
631
632     hr = IDxDiagContainer_GetProp(child, emptyW, NULL);
633     ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetProp to return E_INVALIDARG, got 0x%08x\n", hr);
634
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));
639
640     hr = IDxDiagContainer_GetProp(child, testW, NULL);
641     ok(hr == E_INVALIDARG, "Expected IDxDiagContainer::GetProp to return E_INVALIDARG, got 0x%08x\n", hr);
642
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));
647
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));
652
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. */
656
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));
662
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");
668
669     V_VT(&var) = (VT_ARRAY | VT_UI1);
670     V_ARRAY(&var) = sa;
671
672     hr = SafeArrayLock(sa);
673     ok(hr == S_OK, "Expected SafeArrayLock to return S_OK, got 0x%08x\n", hr);
674
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");
678
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);
684
685 cleanup:
686     IDxDiagContainer_Release(pddc);
687     IDxDiagProvider_Release(pddp);
688 }
689
690 static void test_root_children(void)
691 {
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};
701
702     HRESULT hr;
703     DWORD count, index;
704
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
710     };
711
712     if (!create_root_IDxDiagContainer())
713     {
714         skip("Unable to create the root IDxDiagContainer\n");
715         return;
716     }
717
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))
722     {
723         skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
724         goto cleanup;
725     }
726
727     ok(count == sizeof(root_children)/sizeof(root_children[0]),
728        "Got unexpected count %u for the number of child containers\n", count);
729
730     if (count != sizeof(root_children)/sizeof(root_children[0]))
731     {
732         skip("Received unexpected number of child containers\n");
733         goto cleanup;
734     }
735
736     for (index = 0; index <= count; index++)
737     {
738         WCHAR container[256];
739
740         hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, container, sizeof(container)/sizeof(WCHAR));
741         if (hr == E_INVALIDARG)
742         {
743             ok(index == count,
744                "Expected IDxDiagContainer::EnumChildContainerNames to return "
745                "E_INVALIDARG on the last index %u\n", count);
746             break;
747         }
748         else if (hr == S_OK)
749         {
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));
753         }
754         else
755         {
756             ok(0, "IDxDiagContainer::EnumChildContainerNames unexpectedly returned 0x%08x\n", hr);
757             break;
758         }
759     }
760
761 cleanup:
762     IDxDiagContainer_Release(pddc);
763     IDxDiagProvider_Release(pddp);
764 }
765
766 static void test_DxDiag_SystemInfo(void)
767 {
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
792     static const struct
793     {
794         const WCHAR *prop;
795         VARTYPE vt;
796     } property_tests[] =
797     {
798         {dwOSMajorVersion, VT_UI4},
799         {dwOSMinorVersion, VT_UI4},
800         {dwOSBuildNumber, VT_UI4},
801         {dwOSPlatformID, VT_UI4},
802         {dwDirectXVersionMajor, VT_UI4},
803         {dwDirectXVersionMinor, VT_UI4},
804         {szDirectXVersionLetter, VT_BSTR},
805         {bDebug, VT_BOOL},
806         {bNECPC98, VT_BOOL},
807         {ullPhysicalMemory, VT_BSTR},
808         {ullUsedPageFile, VT_BSTR},
809         {ullAvailPageFile, VT_BSTR},
810         {szWindowsDir, VT_BSTR},
811         {szCSDVersion, VT_BSTR},
812         {szDirectXVersionEnglish, VT_BSTR},
813         {szDirectXVersionLongEnglish, VT_BSTR},
814         {bNetMeetingRunning, VT_BOOL},
815         {szMachineNameLocalized, VT_BSTR},
816         {szMachineNameEnglish, VT_BSTR},
817         {szLanguagesLocalized, VT_BSTR},
818         {szLanguagesEnglish, VT_BSTR},
819         {szTimeLocalized, VT_BSTR},
820         {szTimeEnglish, VT_BSTR},
821     };
822
823     HRESULT hr;
824     IDxDiagContainer *child = NULL;
825     VARIANT var;
826
827     if (!create_root_IDxDiagContainer())
828     {
829         skip("Unable to create the root IDxDiagContainer\n");
830         return;
831     }
832
833     hr = IDxDiagContainer_GetChildContainer(pddc, DxDiag_SystemInfo, &child);
834     ok(hr == S_OK, "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
835
836     if (hr == S_OK)
837     {
838         int i;
839
840         /* Examine the variant types of obtained property values. */
841         for (i = 0; i < sizeof(property_tests)/sizeof(property_tests[0]); i++)
842         {
843             hr = IDxDiagContainer_GetProp(child, property_tests[i].prop, &var);
844             ok(hr == S_OK, "[%d] Expected IDxDiagContainer::GetProp to return S_OK, got 0x%08x\n", i, hr);
845
846             if (hr == S_OK)
847             {
848                 ok(V_VT(&var) == property_tests[i].vt,
849                    "[%d] Expected variant type %d, got %d\n", i, property_tests[i].vt, V_VT(&var));
850                 trace("%s = %s\n", wine_dbgstr_w(property_tests[i].prop), debugstr_variant(&var));
851                 VariantClear(&var);
852             }
853         }
854     }
855
856     IDxDiagContainer_Release(child);
857     IDxDiagContainer_Release(pddc);
858     IDxDiagProvider_Release(pddp);
859 }
860
861 START_TEST(container)
862 {
863     CoInitialize(NULL);
864     test_GetNumberOfChildContainers();
865     test_GetNumberOfProps();
866     test_EnumChildContainerNames();
867     test_GetChildContainer();
868     test_dot_parsing();
869     test_EnumPropNames();
870     test_GetProp();
871
872     test_root_children();
873     test_DxDiag_SystemInfo();
874     CoUninitialize();
875 }