2 * Unit test suite for Enum Background Copy Files Interface
4 * Copyright 2007, 2008 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
26 #include "wine/test.h"
29 /* Globals used by many tests */
30 #define NUM_FILES 2 /* At least two. */
31 static const WCHAR test_remoteNameA[] = {'r','e','m','o','t','e','A', 0};
32 static const WCHAR test_localNameA[] = {'l','o','c','a','l','A', 0};
33 static const WCHAR test_remoteNameB[] = {'r','e','m','o','t','e','B', 0};
34 static const WCHAR test_localNameB[] = {'l','o','c','a','l','B', 0};
35 static const WCHAR test_displayName[] = {'T', 'e', 's', 't', 0};
36 static const ULONG test_fileCount = NUM_FILES;
37 static IBackgroundCopyJob *test_job;
38 static IBackgroundCopyManager *test_manager;
39 static IEnumBackgroundCopyFiles *test_enumFiles;
41 /* Helper function to add a file to a job. The helper function takes base
42 file name and creates properly formed path and URL strings for creation of
44 static HRESULT addFileHelper(IBackgroundCopyJob* job,
45 const WCHAR *localName, const WCHAR *remoteName)
48 WCHAR localFile[MAX_PATH];
49 WCHAR remoteUrl[MAX_PATH];
50 WCHAR remoteFile[MAX_PATH];
52 GetCurrentDirectoryW(MAX_PATH, localFile);
53 PathAppendW(localFile, localName);
54 GetCurrentDirectoryW(MAX_PATH, remoteFile);
55 PathAppendW(remoteFile, remoteName);
57 UrlCreateFromPathW(remoteFile, remoteUrl, &urlSize, 0);
58 UrlUnescapeW(remoteUrl, NULL, &urlSize, URL_UNESCAPE_INPLACE);
59 return IBackgroundCopyJob_AddFile(test_job, remoteUrl, localFile);
62 /* Generic test setup */
63 static BOOL setup(void)
68 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
69 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
70 (void **) &test_manager);
74 hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayName,
75 BG_JOB_TYPE_DOWNLOAD, &test_jobId,
79 IBackgroundCopyManager_Release(test_manager);
83 if (addFileHelper(test_job, test_localNameA, test_remoteNameA) != S_OK
84 || addFileHelper(test_job, test_localNameB, test_remoteNameB) != S_OK
85 || IBackgroundCopyJob_EnumFiles(test_job, &test_enumFiles) != S_OK)
87 IBackgroundCopyJob_Release(test_job);
88 IBackgroundCopyManager_Release(test_manager);
95 /* Generic test cleanup */
96 static void teardown(void)
98 IEnumBackgroundCopyFiles_Release(test_enumFiles);
99 IBackgroundCopyJob_Release(test_job);
100 IBackgroundCopyManager_Release(test_manager);
104 static void test_GetCount(void)
109 hres = IEnumBackgroundCopyFiles_GetCount(test_enumFiles, &fileCount);
110 ok(hres == S_OK, "GetCount failed: %08x\n", hres);
113 skip("Unable to get count from test_enumFiles.\n");
116 ok(fileCount == test_fileCount, "Got incorrect count\n");
119 /* Test Next with a NULL pceltFetched*/
120 static void test_Next_walkListNull(void)
123 IBackgroundCopyFile *file;
126 /* Fetch the available files */
127 for (i = 0; i < test_fileCount; i++)
129 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, NULL);
130 ok(hres == S_OK, "Next failed: %08x\n", hres);
133 skip("Unable to get file from test_enumFiles\n");
136 IBackgroundCopyFile_Release(file);
139 /* Attempt to fetch one more than the number of available files */
140 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, NULL);
141 ok(hres == S_FALSE, "Next off end of available files failed: %08x\n", hres);
144 /* Test Next by requesting one file at a time */
145 static void test_Next_walkList_1(void)
148 IBackgroundCopyFile *file;
152 /* Fetch the available files */
153 for (i = 0; i < test_fileCount; i++)
157 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, &fetched);
158 ok(hres == S_OK, "Next failed: %08x\n", hres);
161 skip("Unable to get file from test_enumFiles\n");
164 ok(fetched == 1, "Next returned the incorrect number of files: %08x\n", hres);
165 ok(file != NULL, "Next returned NULL\n");
167 IBackgroundCopyFile_Release(file);
170 /* Attempt to fetch one more than the number of available files */
172 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, &fetched);
173 ok(hres == S_FALSE, "Next off end of available files failed: %08x\n", hres);
174 ok(fetched == 0, "Next returned the incorrect number of files: %08x\n", hres);
177 /* Test Next by requesting multiple files at a time */
178 static void test_Next_walkList_2(void)
181 IBackgroundCopyFile *files[NUM_FILES];
185 for (i = 0; i < test_fileCount; i++)
189 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, test_fileCount, files, &fetched);
190 ok(hres == S_OK, "Next failed: %08x\n", hres);
193 skip("Unable to get file from test_enumFiles\n");
196 ok(fetched == test_fileCount, "Next returned the incorrect number of files: %08x\n", hres);
198 for (i = 0; i < test_fileCount; i++)
200 ok(files[i] != NULL, "Next returned NULL\n");
202 IBackgroundCopyFile_Release(files[i]);
206 /* Test Next Error conditions */
207 static void test_Next_errors(void)
210 IBackgroundCopyFile *files[NUM_FILES];
212 /* E_INVALIDARG: pceltFetched can ONLY be NULL if celt is 1 */
213 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 2, files, NULL);
214 ok(hres == E_INVALIDARG, "Invalid call to Next succeeded: %08x\n", hres);
217 /* Test skipping through the files in a list */
218 static void test_Skip_walkList(void)
223 for (i = 0; i < test_fileCount; i++)
225 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, 1);
226 ok(hres == S_OK, "Skip failed: %08x\n", hres);
229 skip("Unable to properly Skip files\n");
234 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, 1);
235 ok(hres == S_FALSE, "Skip expected end of list: %08x\n", hres);
238 /* Test skipping off the end of the list */
239 static void test_Skip_offEnd(void)
243 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, test_fileCount + 1);
244 ok(hres == S_FALSE, "Skip expected end of list: %08x\n", hres);
247 /* Test resetting the file enumerator */
248 static void test_Reset(void)
252 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, test_fileCount);
253 ok(hres == S_OK, "Skip failed: %08x\n", hres);
254 hres = IEnumBackgroundCopyFiles_Reset(test_enumFiles);
255 ok(hres == S_OK, "Reset failed: %08x\n", hres);
258 skip("Unable to Reset enumerator\n");
261 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, test_fileCount);
262 ok(hres == S_OK, "Reset failed: %08x\n", hres);
265 typedef void (*test_t)(void);
267 START_TEST(enum_files)
269 static const test_t tests[] = {
271 test_Next_walkListNull,
272 test_Next_walkList_1,
273 test_Next_walkList_2,
283 for (test = tests; *test; ++test)
285 /* Keep state separate between tests. */
288 skip("Unable to setup test\n");