push 2f3ca95c4974ba229fa47d638b3044f50788f3bd
[wine/hacks.git] / dlls / ddrawex / tests / ddrawex.c
blob608a19c00d28513ae50b4fb27a619d38c8a884ee
1 /*
2 * Unit tests for ddrawex specific things
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 #define COBJMACROS
20 #include <assert.h>
21 #include "wine/test.h"
22 #include "windef.h"
23 #include "winbase.h"
24 #include "ddraw.h"
25 #include "ddrawex.h"
26 #include "unknwn.h"
28 static IDirectDrawFactory *factory;
29 static HRESULT (WINAPI *pDllGetClassObject)(REFCLSID rclsid, REFIID riid, LPVOID *ppv);
31 static IDirectDraw *createDD(void)
33 HRESULT hr;
34 IDirectDraw *dd;
36 hr = IDirectDrawFactory_CreateDirectDraw(factory, NULL, NULL, DDSCL_NORMAL, 0,
37 0, &dd);
38 ok(hr == DD_OK, "Failed to create an IDirectDraw interface, hr = 0x%08x\n", hr);
39 return SUCCEEDED(hr) ? dd : NULL;
42 static ULONG get_ref(IUnknown *o)
44 IUnknown_AddRef(o);
45 return IUnknown_Release(o);
48 static void RefCountTest(void)
50 IDirectDraw *dd1 = createDD();
51 IDirectDraw2 *dd2;
52 IDirectDraw3 *dd3;
53 IDirectDraw4 *dd4;
54 ULONG ref;
56 ref = get_ref((IUnknown *) dd1);
57 ok(ref == 1, "A new ddraw object's refcount is %u, expected 1\n", ref);
59 IDirectDraw_AddRef(dd1);
60 ref = get_ref((IUnknown *) dd1);
61 ok(ref == 2, "After AddRef the refcount is %u, expected 2\n", ref);
62 IDirectDraw_Release(dd1);
63 ref = get_ref((IUnknown *) dd1);
64 ok(ref == 1, "After Release the refcount is %u, expected 1\n", ref);
66 IDirectDraw_QueryInterface(dd1, &IID_IDirectDraw2, (void **) &dd2);
67 ref = get_ref((IUnknown *) dd2);
68 ok(ref == 2, "IDirectDraw2 refcount is %u, expected 2\n", ref);
70 IDirectDraw_QueryInterface(dd1, &IID_IDirectDraw3, (void **) &dd3);
71 ref = get_ref((IUnknown *) dd3);
72 ok(ref == 3, "IDirectDraw3 refcount is %u, expected 3\n", ref);
74 IDirectDraw_QueryInterface(dd1, &IID_IDirectDraw4, (void **) &dd4);
75 ref = get_ref((IUnknown *) dd4);
76 ok(ref == 4, "IDirectDraw4 refcount is %u, expected 4\n", ref);
78 IDirectDraw_Release(dd1);
79 IDirectDraw2_Release(dd2);
80 IDirectDraw3_Release(dd3);
82 ref = get_ref((IUnknown *) dd4);
83 ok(ref == 1, "IDirectDraw4 refcount is %u, expected 1\n", ref);
85 IDirectDraw4_Release(dd4);
88 START_TEST(ddrawex)
90 IClassFactory *classfactory = NULL;
91 ULONG ref;
92 HRESULT hr;
93 HMODULE hmod = LoadLibrary("ddrawex.dll");
94 if(hmod == NULL) {
95 skip("Failed to load ddrawex.dll\n");
96 return;
98 pDllGetClassObject = (void*)GetProcAddress(hmod, "DllGetClassObject");
99 if(pDllGetClassObject == NULL) {
100 skip("Failed to get DllGetClassObject\n");
101 return;
104 hr = pDllGetClassObject(&CLSID_DirectDrawFactory, &IID_IClassFactory, (void **) &classfactory);
105 ok(hr == S_OK, "Failed to create a IClassFactory\n");
106 hr = IClassFactory_CreateInstance(classfactory, NULL, &IID_IDirectDrawFactory, (void **) &factory);
107 ok(hr == S_OK, "Failed to create a IDirectDrawFactory\n");
109 RefCountTest();
111 if(factory) {
112 ref = IDirectDrawFactory_Release(factory);
113 ok(ref == 0, "IDirectDrawFactory not cleanly released\n");
115 if(classfactory) {
116 ref = IClassFactory_Release(classfactory);
117 todo_wine ok(ref == 1, "IClassFactory refcount wrong, ref = %u\n", ref);