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 ULONG test_fileCount
= NUM_FILES
;
33 static IBackgroundCopyJob
*test_job
;
34 static IBackgroundCopyManager
*test_manager
;
35 static IEnumBackgroundCopyFiles
*test_enumFiles
;
37 /* Helper function to add a file to a job. The helper function takes base
38 file name and creates properly formed path and URL strings for creation of
40 static HRESULT
addFileHelper(IBackgroundCopyJob
* job
,
41 const WCHAR
*localName
, const WCHAR
*remoteName
)
44 WCHAR localFile
[MAX_PATH
];
45 WCHAR remoteUrl
[MAX_PATH
];
46 WCHAR remoteFile
[MAX_PATH
];
48 GetCurrentDirectoryW(MAX_PATH
, localFile
);
49 PathAppendW(localFile
, localName
);
50 GetCurrentDirectoryW(MAX_PATH
, remoteFile
);
51 PathAppendW(remoteFile
, remoteName
);
53 UrlCreateFromPathW(remoteFile
, remoteUrl
, &urlSize
, 0);
54 UrlUnescapeW(remoteUrl
, NULL
, &urlSize
, URL_UNESCAPE_INPLACE
);
55 return IBackgroundCopyJob_AddFile(job
, remoteUrl
, localFile
);
58 static HRESULT
test_create_manager(void)
61 IBackgroundCopyManager
*manager
= NULL
;
63 /* Creating BITS instance */
64 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
, CLSCTX_LOCAL_SERVER
,
65 &IID_IBackgroundCopyManager
, (void **) &manager
);
67 if(hres
== HRESULT_FROM_WIN32(ERROR_SERVICE_DISABLED
)) {
68 win_skip("Needed Service is disabled\n");
74 IBackgroundCopyJob
*job
;
77 hres
= IBackgroundCopyManager_CreateJob(manager
, L
"Test", BG_JOB_TYPE_DOWNLOAD
, &jobId
, &job
);
80 hres
= addFileHelper(job
, L
"localA", L
"remoteA");
82 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
83 IBackgroundCopyJob_Release(job
);
85 IBackgroundCopyManager_Release(manager
);
91 /* Generic test setup */
92 static BOOL
setup(void)
97 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
98 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
99 (void **) &test_manager
);
103 hres
= IBackgroundCopyManager_CreateJob(test_manager
, L
"Test", BG_JOB_TYPE_DOWNLOAD
,
104 &test_jobId
, &test_job
);
107 IBackgroundCopyManager_Release(test_manager
);
111 if (addFileHelper(test_job
, L
"localA", L
"remoteA") != S_OK
112 || addFileHelper(test_job
, L
"localB", L
"remoteB") != S_OK
113 || IBackgroundCopyJob_EnumFiles(test_job
, &test_enumFiles
) != S_OK
)
115 IBackgroundCopyJob_Release(test_job
);
116 IBackgroundCopyManager_Release(test_manager
);
123 /* Generic test cleanup */
124 static void teardown(void)
126 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
127 IBackgroundCopyJob_Release(test_job
);
128 IBackgroundCopyManager_Release(test_manager
);
132 static void test_GetCount(void)
137 hres
= IEnumBackgroundCopyFiles_GetCount(test_enumFiles
, &fileCount
);
138 ok(hres
== S_OK
, "GetCount failed: %08x\n", hres
);
139 ok(fileCount
== test_fileCount
, "Got incorrect count\n");
142 /* Test Next with a NULL pceltFetched*/
143 static void test_Next_walkListNull(void)
146 IBackgroundCopyFile
*file
;
149 /* Fetch the available files */
150 for (i
= 0; i
< test_fileCount
; i
++)
152 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, NULL
);
153 ok(hres
== S_OK
, "Next failed: %08x\n", hres
);
154 IBackgroundCopyFile_Release(file
);
157 /* Attempt to fetch one more than the number of available files */
158 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, NULL
);
159 ok(hres
== S_FALSE
, "Next off end of available files failed: %08x\n", hres
);
162 /* Test Next by requesting one file at a time */
163 static void test_Next_walkList_1(void)
166 IBackgroundCopyFile
*file
;
170 /* Fetch the available files */
171 for (i
= 0; i
< test_fileCount
; i
++)
175 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, &fetched
);
176 ok(hres
== S_OK
, "Next failed: %08x\n", hres
);
177 ok(fetched
== 1, "Next returned the incorrect number of files: %08x\n", hres
);
178 ok(file
!= NULL
, "Next returned NULL\n");
180 IBackgroundCopyFile_Release(file
);
183 /* Attempt to fetch one more than the number of available files */
185 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, &fetched
);
186 ok(hres
== S_FALSE
, "Next off end of available files failed: %08x\n", hres
);
187 ok(fetched
== 0, "Next returned the incorrect number of files: %08x\n", hres
);
190 /* Test Next by requesting multiple files at a time */
191 static void test_Next_walkList_2(void)
194 IBackgroundCopyFile
*files
[NUM_FILES
];
198 for (i
= 0; i
< test_fileCount
; i
++)
202 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, test_fileCount
, files
, &fetched
);
203 ok(hres
== S_OK
, "Next failed: %08x\n", hres
);
204 ok(fetched
== test_fileCount
, "Next returned the incorrect number of files: %08x\n", hres
);
206 for (i
= 0; i
< test_fileCount
; i
++)
208 ok(files
[i
] != NULL
, "Next returned NULL\n");
210 IBackgroundCopyFile_Release(files
[i
]);
214 /* Test Next Error conditions */
215 static void test_Next_errors(void)
218 IBackgroundCopyFile
*files
[NUM_FILES
];
220 /* E_INVALIDARG: pceltFetched can ONLY be NULL if celt is 1 */
221 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 2, files
, NULL
);
222 ok(hres
== E_INVALIDARG
, "Invalid call to Next succeeded: %08x\n", hres
);
225 /* Test skipping through the files in a list */
226 static void test_Skip_walkList(void)
231 for (i
= 0; i
< test_fileCount
; i
++)
233 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, 1);
234 ok(hres
== S_OK
, "Skip failed: %08x\n", hres
);
237 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, 1);
238 ok(hres
== S_FALSE
, "Skip expected end of list: %08x\n", hres
);
241 /* Test skipping off the end of the list */
242 static void test_Skip_offEnd(void)
246 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, test_fileCount
+ 1);
247 ok(hres
== S_FALSE
, "Skip expected end of list: %08x\n", hres
);
250 /* Test resetting the file enumerator */
251 static void test_Reset(void)
255 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, test_fileCount
);
256 ok(hres
== S_OK
, "Skip failed: %08x\n", hres
);
257 hres
= IEnumBackgroundCopyFiles_Reset(test_enumFiles
);
258 ok(hres
== S_OK
, "Reset failed: %08x\n", hres
);
259 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, test_fileCount
);
260 ok(hres
== S_OK
, "Reset failed: %08x\n", hres
);
263 typedef void (*test_t
)(void);
265 START_TEST(enum_files
)
267 static const test_t tests
[] = {
269 test_Next_walkListNull
,
270 test_Next_walkList_1
,
271 test_Next_walkList_2
,
283 if (FAILED(test_create_manager()))
286 win_skip("Failed to create Manager instance, skipping tests\n");
290 for (test
= tests
, i
= 0; *test
; ++test
, ++i
)
292 /* Keep state separate between tests. */
295 ok(0, "tests:%d: Unable to setup test\n", i
);