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"
30 /* Globals used by many tests */
31 #define NUM_FILES 2 /* At least two. */
32 static const WCHAR test_remoteNameA
[] = {'r','e','m','o','t','e','A', 0};
33 static const WCHAR test_localNameA
[] = {'l','o','c','a','l','A', 0};
34 static const WCHAR test_remoteNameB
[] = {'r','e','m','o','t','e','B', 0};
35 static const WCHAR test_localNameB
[] = {'l','o','c','a','l','B', 0};
36 static const WCHAR test_displayName
[] = {'T', 'e', 's', 't', 0};
37 static const ULONG test_fileCount
= NUM_FILES
;
38 static IBackgroundCopyJob
*test_job
;
39 static IBackgroundCopyManager
*test_manager
;
40 static IEnumBackgroundCopyFiles
*test_enumFiles
;
42 /* Helper function to add a file to a job. The helper function takes base
43 file name and creates properly formed path and URL strings for creation of
45 static HRESULT
addFileHelper(IBackgroundCopyJob
* job
,
46 const WCHAR
*localName
, const WCHAR
*remoteName
)
49 WCHAR localFile
[MAX_PATH
];
50 WCHAR remoteUrl
[MAX_PATH
];
51 WCHAR remoteFile
[MAX_PATH
];
53 GetCurrentDirectoryW(MAX_PATH
, localFile
);
54 PathAppendW(localFile
, localName
);
55 GetCurrentDirectoryW(MAX_PATH
, remoteFile
);
56 PathAppendW(remoteFile
, remoteName
);
58 UrlCreateFromPathW(remoteFile
, remoteUrl
, &urlSize
, 0);
59 UrlUnescapeW(remoteUrl
, NULL
, &urlSize
, URL_UNESCAPE_INPLACE
);
60 return IBackgroundCopyJob_AddFile(job
, remoteUrl
, localFile
);
63 static HRESULT
test_create_manager(void)
66 IBackgroundCopyManager
*manager
= NULL
;
68 /* Creating BITS instance */
69 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
, CLSCTX_LOCAL_SERVER
,
70 &IID_IBackgroundCopyManager
, (void **) &manager
);
72 if(hres
== HRESULT_FROM_WIN32(ERROR_SERVICE_DISABLED
)) {
73 win_skip("Needed Service is disabled\n");
79 IBackgroundCopyJob
*job
;
82 hres
= IBackgroundCopyManager_CreateJob(manager
, test_displayName
, BG_JOB_TYPE_DOWNLOAD
, &jobId
, &job
);
85 hres
= addFileHelper(job
, test_localNameA
, test_remoteNameA
);
87 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
88 IBackgroundCopyJob_Release(job
);
90 IBackgroundCopyManager_Release(manager
);
96 /* Generic test setup */
97 static BOOL
setup(void)
102 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
103 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
104 (void **) &test_manager
);
108 hres
= IBackgroundCopyManager_CreateJob(test_manager
, test_displayName
,
109 BG_JOB_TYPE_DOWNLOAD
, &test_jobId
,
113 IBackgroundCopyManager_Release(test_manager
);
117 if (addFileHelper(test_job
, test_localNameA
, test_remoteNameA
) != S_OK
118 || addFileHelper(test_job
, test_localNameB
, test_remoteNameB
) != S_OK
119 || IBackgroundCopyJob_EnumFiles(test_job
, &test_enumFiles
) != S_OK
)
121 IBackgroundCopyJob_Release(test_job
);
122 IBackgroundCopyManager_Release(test_manager
);
129 /* Generic test cleanup */
130 static void teardown(void)
132 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
133 IBackgroundCopyJob_Release(test_job
);
134 IBackgroundCopyManager_Release(test_manager
);
138 static void test_GetCount(void)
143 hres
= IEnumBackgroundCopyFiles_GetCount(test_enumFiles
, &fileCount
);
144 ok(hres
== S_OK
, "GetCount failed: %08x\n", hres
);
145 ok(fileCount
== test_fileCount
, "Got incorrect count\n");
148 /* Test Next with a NULL pceltFetched*/
149 static void test_Next_walkListNull(void)
152 IBackgroundCopyFile
*file
;
155 /* Fetch the available files */
156 for (i
= 0; i
< test_fileCount
; i
++)
158 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, NULL
);
159 ok(hres
== S_OK
, "Next failed: %08x\n", hres
);
160 IBackgroundCopyFile_Release(file
);
163 /* Attempt to fetch one more than the number of available files */
164 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, NULL
);
165 ok(hres
== S_FALSE
, "Next off end of available files failed: %08x\n", hres
);
168 /* Test Next by requesting one file at a time */
169 static void test_Next_walkList_1(void)
172 IBackgroundCopyFile
*file
;
176 /* Fetch the available files */
177 for (i
= 0; i
< test_fileCount
; i
++)
181 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, &fetched
);
182 ok(hres
== S_OK
, "Next failed: %08x\n", hres
);
183 ok(fetched
== 1, "Next returned the incorrect number of files: %08x\n", hres
);
184 ok(file
!= NULL
, "Next returned NULL\n");
186 IBackgroundCopyFile_Release(file
);
189 /* Attempt to fetch one more than the number of available files */
191 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, &fetched
);
192 ok(hres
== S_FALSE
, "Next off end of available files failed: %08x\n", hres
);
193 ok(fetched
== 0, "Next returned the incorrect number of files: %08x\n", hres
);
196 /* Test Next by requesting multiple files at a time */
197 static void test_Next_walkList_2(void)
200 IBackgroundCopyFile
*files
[NUM_FILES
];
204 for (i
= 0; i
< test_fileCount
; i
++)
208 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, test_fileCount
, files
, &fetched
);
209 ok(hres
== S_OK
, "Next failed: %08x\n", hres
);
210 ok(fetched
== test_fileCount
, "Next returned the incorrect number of files: %08x\n", hres
);
212 for (i
= 0; i
< test_fileCount
; i
++)
214 ok(files
[i
] != NULL
, "Next returned NULL\n");
216 IBackgroundCopyFile_Release(files
[i
]);
220 /* Test Next Error conditions */
221 static void test_Next_errors(void)
224 IBackgroundCopyFile
*files
[NUM_FILES
];
226 /* E_INVALIDARG: pceltFetched can ONLY be NULL if celt is 1 */
227 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 2, files
, NULL
);
228 ok(hres
== E_INVALIDARG
, "Invalid call to Next succeeded: %08x\n", hres
);
231 /* Test skipping through the files in a list */
232 static void test_Skip_walkList(void)
237 for (i
= 0; i
< test_fileCount
; i
++)
239 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, 1);
240 ok(hres
== S_OK
, "Skip failed: %08x\n", hres
);
243 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, 1);
244 ok(hres
== S_FALSE
, "Skip expected end of list: %08x\n", hres
);
247 /* Test skipping off the end of the list */
248 static void test_Skip_offEnd(void)
252 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, test_fileCount
+ 1);
253 ok(hres
== S_FALSE
, "Skip expected end of list: %08x\n", hres
);
256 /* Test resetting the file enumerator */
257 static void test_Reset(void)
261 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, test_fileCount
);
262 ok(hres
== S_OK
, "Skip failed: %08x\n", hres
);
263 hres
= IEnumBackgroundCopyFiles_Reset(test_enumFiles
);
264 ok(hres
== S_OK
, "Reset failed: %08x\n", hres
);
265 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, test_fileCount
);
266 ok(hres
== S_OK
, "Reset failed: %08x\n", hres
);
269 typedef void (*test_t
)(void);
271 START_TEST(enum_files
)
273 static const test_t tests
[] = {
275 test_Next_walkListNull
,
276 test_Next_walkList_1
,
277 test_Next_walkList_2
,
289 if (FAILED(test_create_manager()))
292 win_skip("Failed to create Manager instance, skipping tests\n");
296 for (test
= tests
, i
= 0; *test
; ++test
, ++i
)
298 /* Keep state separate between tests. */
301 ok(0, "tests:%d: Unable to setup test\n", i
);