wined3d: Handle stateblock capture for default lights created while recording.
[wine] / dlls / dxdiagn / tests / provider.c
1 /*
2  * Unit tests for IDxDiagProvider
3  *
4  * Copyright (C) 2009 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 "initguid.h"
24 #include "dxdiag.h"
25 #include "wine/test.h"
26
27 static void test_Initialize(void)
28 {
29     HRESULT hr;
30     IDxDiagProvider *pddp;
31     DXDIAG_INIT_PARAMS params;
32
33     hr = CoCreateInstance(&CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER,
34                           &IID_IDxDiagProvider, (LPVOID*)&pddp);
35     ok(hr == S_OK, "Creating a IDxDiagProvider instance failed with %x\n", hr);
36     if (FAILED(hr))
37     {
38         skip("Failed to create a IDxDiagProvider instance\n");
39         return;
40     }
41
42     /* Test passing a NULL DXDIAG_INIT_PARAMS pointer. */
43     hr = IDxDiagProvider_Initialize(pddp, NULL);
44     ok(hr == E_POINTER,
45        "Expected IDxDiagProvider::Initialize to return E_POINTER, got %x\n", hr);
46
47     /* Test passing invalid dwSize values. */
48     params.dwSize = 0;
49     hr = IDxDiagProvider_Initialize(pddp, &params);
50     ok(hr == E_INVALIDARG,
51        "Expected IDxDiagProvider::Initialize to return E_INVALIDARG, got %x\n", hr);
52
53     params.dwSize = sizeof(params) + 1;
54     hr = IDxDiagProvider_Initialize(pddp, &params);
55     ok(hr == E_INVALIDARG,
56        "Expected IDxDiagProvider::Initialize to return E_INVALIDARG, got %x\n", hr);
57
58     /* Test passing an unexpected dwDxDiagHeaderVersion value. */
59     params.dwSize = sizeof(params);
60     params.dwDxDiagHeaderVersion = 0;
61     params.bAllowWHQLChecks = FALSE;
62     params.pReserved = NULL;
63     hr = IDxDiagProvider_Initialize(pddp, &params);
64     ok(hr == E_INVALIDARG,
65        "Expected IDxDiagProvider::Initialize to return E_INVALIDARG, got %x\n", hr);
66
67     /* Setting pReserved to a non-NULL value causes a crash on Windows. */
68     if (0)
69     {
70         params.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION;
71         params.bAllowWHQLChecks = FALSE;
72         params.pReserved = (VOID*)0xdeadbeef;
73         hr = IDxDiagProvider_Initialize(pddp, &params);
74         trace("IDxDiagProvider::Initialize returned %x\n", hr);
75     }
76
77     /* Test passing an appropriately initialized DXDIAG_INIT_PARAMS. */
78     params.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION;
79     params.bAllowWHQLChecks = FALSE;
80     params.pReserved = NULL;
81     hr = IDxDiagProvider_Initialize(pddp, &params);
82     ok(hr == S_OK, "Expected IDxDiagProvider::Initialize to return S_OK, got %x\n", hr);
83
84     /* Test initializing multiple times. */
85     hr = IDxDiagProvider_Initialize(pddp, &params);
86     ok(hr == S_OK, "Expected IDxDiagProvider::Initialize to return S_OK, got %x\n", hr);
87
88     IDxDiagProvider_Release(pddp);
89 }
90
91 static void test_GetRootContainer(void)
92 {
93     HRESULT hr;
94     IDxDiagProvider *pddp;
95     IDxDiagContainer *pddc;
96     DXDIAG_INIT_PARAMS params;
97
98     hr = CoCreateInstance(&CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER,
99                           &IID_IDxDiagProvider, (LPVOID*)&pddp);
100     ok(hr == S_OK, "Creating a IDxDiagProvider instance failed with %x\n", hr);
101     if (FAILED(hr))
102     {
103         skip("Failed to create a IDxDiagProvider instance\n");
104         return;
105     }
106
107     /* Test calling IDxDiagProvider::GetRootContainer before initialization. */
108     hr = IDxDiagProvider_GetRootContainer(pddp, NULL);
109     ok(hr == CO_E_NOTINITIALIZED,
110        "Expected IDxDiagProvider::GetRootContainer to return CO_E_NOTINITIALIZED, got %x\n", hr);
111
112     hr = IDxDiagProvider_GetRootContainer(pddp, &pddc);
113     ok(hr == CO_E_NOTINITIALIZED,
114        "Expected IDxDiagProvider::GetRootContainer to return CO_E_NOTINITIALIZED, got %x\n", hr);
115
116     params.dwSize = sizeof(params);
117     params.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION;
118     params.bAllowWHQLChecks = FALSE;
119     params.pReserved = NULL;
120     hr = IDxDiagProvider_Initialize(pddp, &params);
121     ok(hr == S_OK, "Expected IDxDiagProvider::Initialize to return S_OK, got %x\n", hr);
122     if (FAILED(hr))
123     {
124         skip("IDxDiagProvider::Initialize failed\n");
125         IDxDiagProvider_Release(pddp);
126         return;
127     }
128
129     /* Passing NULL causes a crash on Windows. */
130     if (0)
131     {
132         hr = IDxDiagProvider_GetRootContainer(pddp, NULL);
133         trace("IDxDiagProvider::GetRootContainer returned %x\n", hr);
134     }
135
136     hr = IDxDiagProvider_GetRootContainer(pddp, &pddc);
137     ok(hr == S_OK, "Expected IDxDiagProvider::GetRootContainer to return S_OK, got %x\n", hr);
138
139     IDxDiagContainer_Release(pddc);
140     IDxDiagProvider_Release(pddp);
141 }
142
143 START_TEST(provider)
144 {
145     CoInitialize(NULL);
146     test_Initialize();
147     test_GetRootContainer();
148     CoUninitialize();
149 }