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
25 #include "wine/test.h"
28 /* Globals used by many tests */
29 static const WCHAR test_displayNameA[] = {'T','e','s','t','A', 0};
30 static const WCHAR test_displayNameB[] = {'T','e','s','t','B', 0};
31 static IBackgroundCopyManager *test_manager;
32 static IBackgroundCopyJob *test_jobA;
33 static IBackgroundCopyJob *test_jobB;
34 static ULONG test_jobCountB;
35 static IEnumBackgroundCopyJobs *test_enumJobsA;
36 static IEnumBackgroundCopyJobs *test_enumJobsB;
37 static GUID test_jobIdA;
38 static GUID test_jobIdB;
40 /* Generic test setup */
41 static BOOL setup(void)
48 memset(&test_jobIdA, 0, sizeof test_jobIdA);
49 memset(&test_jobIdB, 0, sizeof test_jobIdB);
51 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
52 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
53 (void **) &test_manager);
57 hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayNameA,
58 BG_JOB_TYPE_DOWNLOAD, &test_jobIdA,
63 hres = IBackgroundCopyManager_EnumJobs(test_manager, 0, &test_enumJobsA);
67 hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayNameB,
68 BG_JOB_TYPE_DOWNLOAD, &test_jobIdB,
73 hres = IBackgroundCopyManager_EnumJobs(test_manager, 0, &test_enumJobsB);
77 hres = IEnumBackgroundCopyJobs_GetCount(test_enumJobsB, &test_jobCountB);
84 /* Generic test cleanup */
85 static void teardown(void)
88 IEnumBackgroundCopyJobs_Release(test_enumJobsB);
89 test_enumJobsB = NULL;
91 IBackgroundCopyJob_Release(test_jobB);
94 IEnumBackgroundCopyJobs_Release(test_enumJobsA);
95 test_enumJobsA = NULL;
97 IBackgroundCopyJob_Release(test_jobA);
100 IBackgroundCopyManager_Release(test_manager);
104 /* We can't assume the job count will start at any fixed number since esp
105 when testing on Windows there may be other jobs created by other
106 processes. Even this approach of creating two jobs and checking the
107 difference in counts could fail if a job was created in between, but
108 it's probably not worth worrying about in sane test environments. */
109 static void test_GetCount(void)
112 ULONG jobCountA, jobCountB;
114 hres = IEnumBackgroundCopyJobs_GetCount(test_enumJobsA, &jobCountA);
115 ok(hres == S_OK, "GetCount failed: %08x\n", hres);
118 skip("Couldn't get job count\n");
122 hres = IEnumBackgroundCopyJobs_GetCount(test_enumJobsB, &jobCountB);
123 ok(hres == S_OK, "GetCount failed: %08x\n", hres);
126 skip("Couldn't get job count\n");
130 ok(jobCountB == jobCountA + 1, "Got incorrect count\n");
133 /* Test Next with a NULL pceltFetched*/
134 static void test_Next_walkListNull(void)
137 IBackgroundCopyJob *job;
140 /* Fetch the available jobs */
141 for (i = 0; i < test_jobCountB; i++)
143 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, NULL);
144 ok(hres == S_OK, "Next failed: %08x\n", hres);
147 skip("Unable to get job from Next\n");
150 IBackgroundCopyJob_Release(job);
153 /* Attempt to fetch one more than the number of available jobs */
154 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, NULL);
155 ok(hres == S_FALSE, "Next off end of available jobs failed: %08x\n", hres);
159 static void test_Next_walkList_1(void)
162 IBackgroundCopyJob *job;
166 /* Fetch the available jobs */
167 for (i = 0; i < test_jobCountB; i++)
170 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, &fetched);
171 ok(hres == S_OK, "Next failed: %08x\n", hres);
174 skip("Unable to get job from Next\n");
177 ok(fetched == 1, "Next returned the incorrect number of jobs: %08x\n", hres);
178 IBackgroundCopyJob_Release(job);
181 /* Attempt to fetch one more than the number of available jobs */
183 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, &fetched);
184 ok(hres == S_FALSE, "Next off end of available jobs failed: %08x\n", hres);
185 ok(fetched == 0, "Next returned the incorrect number of jobs: %08x\n", hres);
188 /* Test Next by requesting multiple files at a time */
189 static void test_Next_walkList_2(void)
192 IBackgroundCopyJob **jobs;
196 jobs = HeapAlloc(GetProcessHeap(), 0, test_jobCountB * sizeof *jobs);
199 skip("Couldn't allocate memory\n");
203 for (i = 0; i < test_jobCountB; i++)
207 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, test_jobCountB, jobs, &fetched);
208 ok(hres == S_OK, "Next failed: %08x\n", hres);
211 skip("Unable to get file from test_enumJobs\n");
214 ok(fetched == test_jobCountB, "Next returned the incorrect number of jobs: %08x\n", hres);
216 for (i = 0; i < test_jobCountB; i++)
218 ok(jobs[i] != NULL, "Next returned NULL\n");
220 IBackgroundCopyFile_Release(jobs[i]);
224 /* Test Next Error conditions */
225 static void test_Next_errors(void)
228 IBackgroundCopyJob *jobs[2];
230 /* E_INVALIDARG: pceltFetched can ONLY be NULL if celt is 1 */
231 hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 2, jobs, NULL);
232 ok(hres != S_OK, "Invalid call to Next succeeded: %08x\n", hres);
235 typedef void (*test_t)(void);
237 START_TEST(enum_jobs)
239 static const test_t tests[] = {
241 test_Next_walkListNull,
242 test_Next_walkList_1,
243 test_Next_walkList_2,
250 for (test = tests; *test; ++test)
252 /* Keep state seperate between tests. */
256 skip("Unable to setup test\n");