hidclass.sys: Support parsing of explicit usage page.
[wine.git] / dlls / qmgr / tests / enum_jobs.c
blob81df72e2e696a4141820d6c58d7f20908f9422b6
1 /*
2 * Unit test suite for Enum Background Copy Jobs Interface
4 * Copyright 2007 Google (Roy Shea, Dan Hipschman)
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>
23 #define COBJMACROS
25 #include "wine/test.h"
26 #include "bits.h"
28 /* Globals used by many tests */
29 static IBackgroundCopyManager *test_manager;
30 static IBackgroundCopyJob *test_jobA;
31 static IBackgroundCopyJob *test_jobB;
32 static ULONG test_jobCountB;
33 static IEnumBackgroundCopyJobs *test_enumJobsA;
34 static IEnumBackgroundCopyJobs *test_enumJobsB;
35 static GUID test_jobIdA;
36 static GUID test_jobIdB;
38 /* Generic test setup */
39 static BOOL setup(void)
41 HRESULT hres;
43 test_manager = NULL;
44 test_jobA = NULL;
45 test_jobB = NULL;
46 memset(&test_jobIdA, 0, sizeof test_jobIdA);
47 memset(&test_jobIdB, 0, sizeof test_jobIdB);
49 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
50 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
51 (void **) &test_manager);
52 if(hres != S_OK)
53 return FALSE;
55 hres = IBackgroundCopyManager_CreateJob(test_manager, L"TestA", BG_JOB_TYPE_DOWNLOAD,
56 &test_jobIdA, &test_jobA);
57 if(hres != S_OK)
58 return FALSE;
60 hres = IBackgroundCopyManager_EnumJobs(test_manager, 0, &test_enumJobsA);
61 if(hres != S_OK)
62 return FALSE;
64 hres = IBackgroundCopyManager_CreateJob(test_manager, L"TestB", BG_JOB_TYPE_DOWNLOAD,
65 &test_jobIdB, &test_jobB);
66 if(hres != S_OK)
67 return FALSE;
69 hres = IBackgroundCopyManager_EnumJobs(test_manager, 0, &test_enumJobsB);
70 if(hres != S_OK)
71 return FALSE;
73 hres = IEnumBackgroundCopyJobs_GetCount(test_enumJobsB, &test_jobCountB);
74 if (hres != S_OK)
75 return FALSE;
77 return TRUE;
80 /* Generic test cleanup */
81 static void teardown(void)
83 if (test_enumJobsB)
84 IEnumBackgroundCopyJobs_Release(test_enumJobsB);
85 test_enumJobsB = NULL;
86 if (test_jobB)
87 IBackgroundCopyJob_Release(test_jobB);
88 test_jobB = NULL;
89 if (test_enumJobsA)
90 IEnumBackgroundCopyJobs_Release(test_enumJobsA);
91 test_enumJobsA = NULL;
92 if (test_jobA)
93 IBackgroundCopyJob_Release(test_jobA);
94 test_jobA = NULL;
95 if (test_manager)
96 IBackgroundCopyManager_Release(test_manager);
97 test_manager = NULL;
100 /* We can't assume the job count will start at any fixed number since esp
101 when testing on Windows there may be other jobs created by other
102 processes. Even this approach of creating two jobs and checking the
103 difference in counts could fail if a job was created in between, but
104 it's probably not worth worrying about in sane test environments. */
105 static void test_GetCount(void)
107 HRESULT hres;
108 ULONG jobCountA, jobCountB;
110 hres = IEnumBackgroundCopyJobs_GetCount(test_enumJobsA, &jobCountA);
111 ok(hres == S_OK, "GetCount failed: %08x\n", hres);
113 hres = IEnumBackgroundCopyJobs_GetCount(test_enumJobsB, &jobCountB);
114 ok(hres == S_OK, "GetCount failed: %08x\n", hres);
116 ok(jobCountB == jobCountA + 1, "Got incorrect count\n");
119 /* Test Next with a NULL pceltFetched*/
120 static void test_Next_walkListNull(void)
122 HRESULT hres;
123 IBackgroundCopyJob *job;
124 ULONG i;
126 /* Fetch the available jobs */
127 for (i = 0; i < test_jobCountB; i++)
129 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, NULL);
130 ok(hres == S_OK, "Next failed: %08x\n", hres);
131 IBackgroundCopyJob_Release(job);
134 /* Attempt to fetch one more than the number of available jobs */
135 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, NULL);
136 ok(hres == S_FALSE, "Next off end of available jobs failed: %08x\n", hres);
139 /* Test Next */
140 static void test_Next_walkList_1(void)
142 HRESULT hres;
143 IBackgroundCopyJob *job;
144 ULONG fetched;
145 ULONG i;
147 /* Fetch the available jobs */
148 for (i = 0; i < test_jobCountB; i++)
150 fetched = 0;
151 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, &fetched);
152 ok(hres == S_OK, "Next failed: %08x\n", hres);
153 ok(fetched == 1, "Next returned the incorrect number of jobs: %08x\n", hres);
154 IBackgroundCopyJob_Release(job);
157 /* Attempt to fetch one more than the number of available jobs */
158 fetched = 0;
159 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, &fetched);
160 ok(hres == S_FALSE, "Next off end of available jobs failed: %08x\n", hres);
161 ok(fetched == 0, "Next returned the incorrect number of jobs: %08x\n", hres);
164 /* Test Next by requesting multiple files at a time */
165 static void test_Next_walkList_2(void)
167 HRESULT hres;
168 IBackgroundCopyJob **jobs;
169 ULONG fetched;
170 ULONG i;
172 jobs = HeapAlloc(GetProcessHeap(), 0, test_jobCountB * sizeof *jobs);
173 for (i = 0; i < test_jobCountB; i++)
174 jobs[i] = NULL;
176 fetched = 0;
177 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, test_jobCountB, jobs, &fetched);
178 ok(hres == S_OK, "Next failed: %08x\n", hres);
179 ok(fetched == test_jobCountB, "Next returned the incorrect number of jobs: %08x\n", hres);
181 for (i = 0; i < test_jobCountB; i++)
183 ok(jobs[i] != NULL, "Next returned NULL\n");
184 if (jobs[i])
185 IBackgroundCopyJob_Release(jobs[i]);
188 HeapFree(GetProcessHeap(), 0, jobs);
191 /* Test Next Error conditions */
192 static void test_Next_errors(void)
194 HRESULT hres;
195 IBackgroundCopyJob *jobs[2];
197 /* E_INVALIDARG: pceltFetched can ONLY be NULL if celt is 1 */
198 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 2, jobs, NULL);
199 ok(hres != S_OK, "Invalid call to Next succeeded: %08x\n", hres);
202 /* Test skipping through the jobs in a list */
203 static void test_Skip_walkList(void)
205 HRESULT hres;
206 ULONG i;
208 for (i = 0; i < test_jobCountB; i++)
210 hres = IEnumBackgroundCopyJobs_Skip(test_enumJobsB, 1);
211 ok(hres == S_OK, "Skip failed: %08x\n", hres);
214 hres = IEnumBackgroundCopyJobs_Skip(test_enumJobsB, 1);
215 ok(hres == S_FALSE, "Skip expected end of list: %08x\n", hres);
218 /* Test skipping off the end of the list */
219 static void test_Skip_offEnd(void)
221 HRESULT hres;
223 hres = IEnumBackgroundCopyJobs_Skip(test_enumJobsB, test_jobCountB + 1);
224 ok(hres == S_FALSE, "Skip expected end of list: %08x\n", hres);
227 /* Test reset */
228 static void test_Reset(void)
230 HRESULT hres;
232 hres = IEnumBackgroundCopyJobs_Skip(test_enumJobsB, test_jobCountB);
233 ok(hres == S_OK, "Skip failed: %08x\n", hres);
235 hres = IEnumBackgroundCopyJobs_Reset(test_enumJobsB);
236 ok(hres == S_OK, "Reset failed: %08x\n", hres);
238 hres = IEnumBackgroundCopyJobs_Skip(test_enumJobsB, test_jobCountB);
239 ok(hres == S_OK, "Reset failed: %08x\n", hres);
242 typedef void (*test_t)(void);
244 START_TEST(enum_jobs)
246 static const test_t tests[] = {
247 test_GetCount,
248 test_Next_walkListNull,
249 test_Next_walkList_1,
250 test_Next_walkList_2,
251 test_Next_errors,
252 test_Skip_walkList,
253 test_Skip_offEnd,
254 test_Reset,
257 const test_t *test;
258 int i;
260 CoInitialize(NULL);
261 for (test = tests, i = 0; *test; ++test, ++i)
263 /* Keep state separate between tests */
264 if (!setup())
266 teardown();
267 ok(0, "tests:%d: Unable to setup test\n", i);
268 break;
270 (*test)();
271 teardown();
273 CoUninitialize();