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 "wine/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 || 36 broken(hr == REGDB_E_CLASSNOTREG), /* Clean W2K3 */ 37 "Creating a IDxDiagProvider instance failed with %x\n", hr); 38 if (FAILED(hr)) 39 { 40 skip("Failed to create a IDxDiagProvider instance\n"); 41 return; 42 } 43 44 /* Test passing a NULL DXDIAG_INIT_PARAMS pointer. */ 45 hr = IDxDiagProvider_Initialize(pddp, NULL); 46 ok(hr == E_POINTER, 47 "Expected IDxDiagProvider::Initialize to return E_POINTER, got %x\n", hr); 48 49 /* Test passing invalid dwSize values. */ 50 params.dwSize = 0; 51 hr = IDxDiagProvider_Initialize(pddp, ¶ms); 52 ok(hr == E_INVALIDARG, 53 "Expected IDxDiagProvider::Initialize to return E_INVALIDARG, got %x\n", hr); 54 55 params.dwSize = sizeof(params) + 1; 56 hr = IDxDiagProvider_Initialize(pddp, ¶ms); 57 ok(hr == E_INVALIDARG, 58 "Expected IDxDiagProvider::Initialize to return E_INVALIDARG, got %x\n", hr); 59 60 /* Test passing an unexpected dwDxDiagHeaderVersion value. */ 61 params.dwSize = sizeof(params); 62 params.dwDxDiagHeaderVersion = 0; 63 params.bAllowWHQLChecks = FALSE; 64 params.pReserved = NULL; 65 hr = IDxDiagProvider_Initialize(pddp, ¶ms); 66 ok(hr == E_INVALIDARG, 67 "Expected IDxDiagProvider::Initialize to return E_INVALIDARG, got %x\n", hr); 68 69 /* Setting pReserved to a non-NULL value causes a crash on Windows. */ 70 if (0) 71 { 72 params.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION; 73 params.bAllowWHQLChecks = FALSE; 74 params.pReserved = (VOID*)0xdeadbeef; 75 hr = IDxDiagProvider_Initialize(pddp, ¶ms); 76 trace("IDxDiagProvider::Initialize returned %x\n", hr); 77 } 78 79 /* Test passing an appropriately initialized DXDIAG_INIT_PARAMS. */ 80 params.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION; 81 params.bAllowWHQLChecks = FALSE; 82 params.pReserved = NULL; 83 hr = IDxDiagProvider_Initialize(pddp, ¶ms); 84 ok(hr == S_OK, "Expected IDxDiagProvider::Initialize to return S_OK, got %x\n", hr); 85 86 /* Test initializing multiple times. */ 87 hr = IDxDiagProvider_Initialize(pddp, ¶ms); 88 ok(hr == S_OK, "Expected IDxDiagProvider::Initialize to return S_OK, got %x\n", hr); 89 90 IDxDiagProvider_Release(pddp); 91 } 92 93 static void test_GetRootContainer(void) 94 { 95 HRESULT hr; 96 IDxDiagProvider *pddp; 97 IDxDiagContainer *pddc, *pddc2; 98 DXDIAG_INIT_PARAMS params; 99 100 hr = CoCreateInstance(&CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER, 101 &IID_IDxDiagProvider, (LPVOID*)&pddp); 102 ok(hr == S_OK || 103 broken(hr == REGDB_E_CLASSNOTREG), /* Clean W2K3 */ 104 "Creating a IDxDiagProvider instance failed with %x\n", hr); 105 if (FAILED(hr)) 106 { 107 skip("Failed to create a IDxDiagProvider instance\n"); 108 return; 109 } 110 111 /* Test calling IDxDiagProvider::GetRootContainer before initialization. */ 112 hr = IDxDiagProvider_GetRootContainer(pddp, NULL); 113 ok(hr == CO_E_NOTINITIALIZED, 114 "Expected IDxDiagProvider::GetRootContainer to return CO_E_NOTINITIALIZED, got %x\n", hr); 115 116 hr = IDxDiagProvider_GetRootContainer(pddp, &pddc); 117 ok(hr == CO_E_NOTINITIALIZED, 118 "Expected IDxDiagProvider::GetRootContainer to return CO_E_NOTINITIALIZED, got %x\n", hr); 119 120 params.dwSize = sizeof(params); 121 params.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION; 122 params.bAllowWHQLChecks = FALSE; 123 params.pReserved = NULL; 124 hr = IDxDiagProvider_Initialize(pddp, ¶ms); 125 ok(hr == S_OK, "Expected IDxDiagProvider::Initialize to return S_OK, got %x\n", hr); 126 if (FAILED(hr)) 127 { 128 skip("IDxDiagProvider::Initialize failed\n"); 129 IDxDiagProvider_Release(pddp); 130 return; 131 } 132 133 /* Passing NULL causes a crash on Windows. */ 134 if (0) 135 { 136 hr = IDxDiagProvider_GetRootContainer(pddp, NULL); 137 trace("IDxDiagProvider::GetRootContainer returned %x\n", hr); 138 } 139 140 hr = IDxDiagProvider_GetRootContainer(pddp, &pddc); 141 ok(hr == S_OK, "Expected IDxDiagProvider::GetRootContainer to return S_OK, got %x\n", hr); 142 143 /* IDxDiagProvider::GetRootContainer creates new instances of the root 144 * container rather than maintain a static root container. */ 145 hr = IDxDiagProvider_GetRootContainer(pddp, &pddc2); 146 ok(hr == S_OK, "Expected IDxDiagProvider::GetRootContainer to return S_OK, got %x\n", hr); 147 ok(pddc != pddc2, "Expected the two pointers (%p vs. %p) to be unequal\n", pddc, pddc2); 148 149 IDxDiagContainer_Release(pddc2); 150 IDxDiagContainer_Release(pddc); 151 IDxDiagProvider_Release(pddp); 152 } 153 154 START_TEST(provider) 155 { 156 CoInitialize(NULL); 157 test_Initialize(); 158 test_GetRootContainer(); 159 CoUninitialize(); 160 } 161