winecoreaudio: Use mmdevapi's AudioClient's GetService.
[wine.git] / dlls / msdmo / tests / msdmo.c
blobd84617fc65712410c3b629c9e35a4640ace3c00d
1 /*
2 * MSDMO tests
4 * Copyright 2014 Nikolay Sivov for CodeWeavers
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 #include <stdio.h>
22 #define COBJMACROS
23 #include "dmo.h"
24 #include "wine/test.h"
26 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
27 static const GUID GUID_unknowndmo = {0x14d99047,0x441f,0x4cd3,{0xbc,0xa8,0x3e,0x67,0x99,0xaf,0x34,0x75}};
28 static const GUID GUID_unknowncategory = {0x14d99048,0x441f,0x4cd3,{0xbc,0xa8,0x3e,0x67,0x99,0xaf,0x34,0x75}};
29 static const GUID GUID_wmp1 = {0x13a7995e,0x7d8f,0x45b4,{0x9c,0x77,0x81,0x92,0x65,0x22,0x57,0x63}};
31 static const char *guid_to_string(const GUID *guid)
33 static char buffer[50];
34 sprintf(buffer, "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
35 guid->Data1, guid->Data2, guid->Data3,
36 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
37 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
38 return buffer;
41 static void test_DMOUnregister(void)
43 static char buffer[200];
44 HRESULT hr;
46 hr = DMOUnregister(&GUID_unknowndmo, &GUID_unknowncategory);
47 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
49 hr = DMOUnregister(&GUID_unknowndmo, &GUID_NULL);
50 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
52 /* can't register for all categories */
53 hr = DMORegister(L"testdmo", &GUID_unknowndmo, &GUID_NULL, 0, 0, NULL, 0, NULL);
54 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
56 hr = DMORegister(L"testdmo", &GUID_unknowndmo, &GUID_unknowncategory, 0, 0, NULL, 0, NULL);
57 if (hr != S_OK) {
58 win_skip("Failed to register DMO. Probably user doesn't have persmissions to do so.\n");
59 return;
62 hr = DMOUnregister(&GUID_unknowndmo, &GUID_NULL);
63 ok(hr == S_OK, "got 0x%08lx\n", hr);
65 hr = DMOUnregister(&GUID_unknowndmo, &GUID_NULL);
66 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
68 /* clean up category since Windows doesn't */
69 sprintf(buffer, "DirectShow\\MediaObjects\\Categories\\%s", guid_to_string(&GUID_unknowncategory));
70 RegDeleteKeyA(HKEY_CLASSES_ROOT, buffer);
73 static void test_DMOGetName(void)
75 WCHAR name[80];
76 HRESULT hr;
78 hr = DMOGetName(&GUID_unknowndmo, NULL);
79 ok(hr == E_FAIL, "got 0x%08lx\n", hr);
81 /* no such DMO */
82 name[0] = 'a';
83 hr = DMOGetName(&GUID_wmp1, name);
84 ok(hr == E_FAIL, "got 0x%08lx\n", hr);
85 ok(name[0] == 'a', "got %x\n", name[0]);
88 static void test_DMOEnum(void)
90 static const DMO_PARTIAL_MEDIATYPE input_type = {{0x1111}, {0x2222}};
91 static const DMO_PARTIAL_MEDIATYPE wrong_type = {{0x3333}, {0x4444}};
93 IEnumDMO *enum_dmo;
94 HRESULT hr;
95 CLSID clsid;
96 WCHAR *name;
97 DWORD count;
99 hr = DMOEnum(&GUID_unknowncategory, 0, 0, NULL, 0, NULL, &enum_dmo);
100 ok(hr == S_OK, "DMOEnum() failed with %#lx\n", hr);
102 hr = IEnumDMO_Next(enum_dmo, 1, &clsid, &name, NULL);
103 ok(hr == S_FALSE, "expected S_FALSE, got %#lx\n", hr);
105 hr = IEnumDMO_Next(enum_dmo, 2, &clsid, &name, NULL);
106 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#lx\n", hr);
108 hr = IEnumDMO_Next(enum_dmo, 2, &clsid, &name, &count);
109 ok(hr == S_FALSE, "expected S_FALSE, got %#lx\n", hr);
110 ok(count == 0, "expected 0, got %ld\n", count);
112 hr = IEnumDMO_Next(enum_dmo, 2, NULL, &name, &count);
113 ok(hr == E_POINTER, "expected S_FALSE, got %#lx\n", hr);
115 hr = IEnumDMO_Next(enum_dmo, 2, &clsid, NULL, &count);
116 ok(hr == S_FALSE, "expected S_FALSE, got %#lx\n", hr);
117 ok(count == 0, "expected 0, got %ld\n", count);
119 IEnumDMO_Release(enum_dmo);
121 hr = DMORegister(L"testdmo", &GUID_unknowndmo, &GUID_unknowncategory, 0, 1, &input_type, 0, NULL);
122 if (hr != S_OK)
123 return;
125 hr = DMOEnum(&GUID_unknowncategory, 0, 0, NULL, 0, NULL, &enum_dmo);
126 ok(hr == S_OK, "Got hr %#lx.\n", hr);
128 hr = IEnumDMO_Next(enum_dmo, 1, &clsid, &name, NULL);
129 ok(hr == S_OK, "Got hr %#lx.\n", hr);
130 ok(IsEqualGUID(&clsid, &GUID_unknowndmo), "Got clsid %s.\n", debugstr_guid(&clsid));
131 ok(!wcscmp(name, L"testdmo"), "Got name %s.\n", debugstr_w(name));
133 hr = IEnumDMO_Next(enum_dmo, 1, &clsid, &name, NULL);
134 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
136 IEnumDMO_Release(enum_dmo);
138 hr = DMOEnum(&GUID_unknowncategory, 0, 1, &input_type, 0, NULL, &enum_dmo);
139 ok(hr == S_OK, "Got hr %#lx.\n", hr);
141 hr = IEnumDMO_Next(enum_dmo, 1, &clsid, &name, NULL);
142 ok(hr == S_OK, "Got hr %#lx.\n", hr);
143 ok(IsEqualGUID(&clsid, &GUID_unknowndmo), "Got clsid %s.\n", debugstr_guid(&clsid));
144 ok(!wcscmp(name, L"testdmo"), "Got name %s.\n", debugstr_w(name));
146 hr = IEnumDMO_Next(enum_dmo, 1, &clsid, &name, NULL);
147 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
149 IEnumDMO_Release(enum_dmo);
151 hr = DMOEnum(&GUID_unknowncategory, 0, 1, &wrong_type, 0, NULL, &enum_dmo);
152 ok(hr == S_OK, "Got hr %#lx.\n", hr);
154 hr = IEnumDMO_Next(enum_dmo, 1, &clsid, &name, NULL);
155 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
157 IEnumDMO_Release(enum_dmo);
159 hr = DMOUnregister(&GUID_unknowndmo, &GUID_unknowncategory);
160 ok(hr == S_OK, "Got hr %#lx.\n", hr);
163 static void test_DMOGetTypes(void)
165 static const DMO_PARTIAL_MEDIATYPE input_types[] =
167 {{0x1111}, {0x2222}},
168 {{0x1111}, {0x3333}},
170 ULONG input_count, output_count;
171 DMO_PARTIAL_MEDIATYPE types[3];
172 HRESULT hr;
174 hr = DMOGetTypes(&GUID_unknowndmo, 0, &input_count, types, 0, &output_count, NULL);
175 ok(hr == E_FAIL, "Got hr %#lx.\n", hr);
177 hr = DMORegister(L"testdmo", &GUID_unknowndmo, &GUID_unknowncategory, 0,
178 ARRAY_SIZE(input_types), input_types, 0, NULL);
179 if (hr != S_OK)
180 return;
182 hr = DMOGetTypes(&GUID_unknowndmo, 0, &input_count, types, 0, &output_count, NULL);
183 ok(hr == S_OK, "Got hr %#lx.\n", hr);
184 ok(!input_count, "Got input count %lu.\n", input_count);
185 ok(!output_count, "Got output count %lu.\n", output_count);
187 memset(types, 0, sizeof(types));
188 hr = DMOGetTypes(&GUID_unknowndmo, 1, &input_count, types, 0, &output_count, NULL);
189 ok(hr == S_OK, "Got hr %#lx.\n", hr);
190 ok(input_count == 1, "Got input count %lu.\n", input_count);
191 ok(!output_count, "Got output count %lu.\n", output_count);
192 todo_wine ok(!memcmp(types, input_types, sizeof(DMO_PARTIAL_MEDIATYPE)), "Types didn't match.\n");
194 memset(types, 0, sizeof(types));
195 hr = DMOGetTypes(&GUID_unknowndmo, 2, &input_count, types, 0, &output_count, NULL);
196 ok(hr == S_OK, "Got hr %#lx.\n", hr);
197 ok(input_count == 2, "Got input count %lu.\n", input_count);
198 ok(!output_count, "Got output count %lu.\n", output_count);
199 ok(!memcmp(types, input_types, 2 * sizeof(DMO_PARTIAL_MEDIATYPE)), "Types didn't match.\n");
201 memset(types, 0, sizeof(types));
202 hr = DMOGetTypes(&GUID_unknowndmo, 2, &input_count, types, 0, &output_count, NULL);
203 ok(hr == S_OK, "Got hr %#lx.\n", hr);
204 ok(input_count == 2, "Got input count %lu.\n", input_count);
205 ok(!output_count, "Got output count %lu.\n", output_count);
206 ok(!memcmp(types, input_types, 2 * sizeof(DMO_PARTIAL_MEDIATYPE)), "Types didn't match.\n");
208 hr = DMOUnregister(&GUID_unknowndmo, &GUID_unknowncategory);
209 ok(hr == S_OK, "Got hr %#lx.\n", hr);
212 START_TEST(msdmo)
214 test_DMOUnregister();
215 test_DMOGetName();
216 test_DMOEnum();
217 test_DMOGetTypes();