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(job
, remoteUrl
, localFile
);
62 static HRESULT
test_create_manager(void)
65 IBackgroundCopyManager
*manager
= NULL
;
67 /* Creating BITS instance */
68 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
, CLSCTX_LOCAL_SERVER
,
69 &IID_IBackgroundCopyManager
, (void **) &manager
);
71 if(hres
== HRESULT_FROM_WIN32(ERROR_SERVICE_DISABLED
)) {
72 win_skip("Needed Service is disabled\n");
78 IBackgroundCopyJob
*job
;
81 hres
= IBackgroundCopyManager_CreateJob(manager
, test_displayName
, BG_JOB_TYPE_DOWNLOAD
, &jobId
, &job
);
84 hres
= addFileHelper(job
, test_localNameA
, test_remoteNameA
);
86 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
87 IBackgroundCopyJob_Release(job
);
89 IBackgroundCopyManager_Release(manager
);
95 /* Generic test setup */
96 static BOOL
setup(void)
101 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
102 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
103 (void **) &test_manager
);
107 hres
= IBackgroundCopyManager_CreateJob(test_manager
, test_displayName
,
108 BG_JOB_TYPE_DOWNLOAD
, &test_jobId
,
112 IBackgroundCopyManager_Release(test_manager
);
116 if (addFileHelper(test_job
, test_localNameA
, test_remoteNameA
) != S_OK
117 || addFileHelper(test_job
, test_localNameB
, test_remoteNameB
) != S_OK
118 || IBackgroundCopyJob_EnumFiles(test_job
, &test_enumFiles
) != S_OK
)
120 IBackgroundCopyJob_Release(test_job
);
121 IBackgroundCopyManager_Release(test_manager
);
128 /* Generic test cleanup */
129 static void teardown(void)
131 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
132 IBackgroundCopyJob_Release(test_job
);
133 IBackgroundCopyManager_Release(test_manager
);
137 static void test_GetCount(void)
142 hres
= IEnumBackgroundCopyFiles_GetCount(test_enumFiles
, &fileCount
);
143 ok(hres
== S_OK
, "GetCount failed: %08x\n", hres
);
144 ok(fileCount
== test_fileCount
, "Got incorrect count\n");
147 /* Test Next with a NULL pceltFetched*/
148 static void test_Next_walkListNull(void)
151 IBackgroundCopyFile
*file
;
154 /* Fetch the available files */
155 for (i
= 0; i
< test_fileCount
; i
++)
157 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, NULL
);
158 ok(hres
== S_OK
, "Next failed: %08x\n", hres
);
159 IBackgroundCopyFile_Release(file
);
162 /* Attempt to fetch one more than the number of available files */
163 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, NULL
);
164 ok(hres
== S_FALSE
, "Next off end of available files failed: %08x\n", hres
);
167 /* Test Next by requesting one file at a time */
168 static void test_Next_walkList_1(void)
171 IBackgroundCopyFile
*file
;
175 /* Fetch the available files */
176 for (i
= 0; i
< test_fileCount
; i
++)
180 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, &fetched
);
181 ok(hres
== S_OK
, "Next failed: %08x\n", hres
);
182 ok(fetched
== 1, "Next returned the incorrect number of files: %08x\n", hres
);
183 ok(file
!= NULL
, "Next returned NULL\n");
185 IBackgroundCopyFile_Release(file
);
188 /* Attempt to fetch one more than the number of available files */
190 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &file
, &fetched
);
191 ok(hres
== S_FALSE
, "Next off end of available files failed: %08x\n", hres
);
192 ok(fetched
== 0, "Next returned the incorrect number of files: %08x\n", hres
);
195 /* Test Next by requesting multiple files at a time */
196 static void test_Next_walkList_2(void)
199 IBackgroundCopyFile
*files
[NUM_FILES
];
203 for (i
= 0; i
< test_fileCount
; i
++)
207 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, test_fileCount
, files
, &fetched
);
208 ok(hres
== S_OK
, "Next failed: %08x\n", hres
);
209 ok(fetched
== test_fileCount
, "Next returned the incorrect number of files: %08x\n", hres
);
211 for (i
= 0; i
< test_fileCount
; i
++)
213 ok(files
[i
] != NULL
, "Next returned NULL\n");
215 IBackgroundCopyFile_Release(files
[i
]);
219 /* Test Next Error conditions */
220 static void test_Next_errors(void)
223 IBackgroundCopyFile
*files
[NUM_FILES
];
225 /* E_INVALIDARG: pceltFetched can ONLY be NULL if celt is 1 */
226 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 2, files
, NULL
);
227 ok(hres
== E_INVALIDARG
, "Invalid call to Next succeeded: %08x\n", hres
);
230 /* Test skipping through the files in a list */
231 static void test_Skip_walkList(void)
236 for (i
= 0; i
< test_fileCount
; i
++)
238 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, 1);
239 ok(hres
== S_OK
, "Skip failed: %08x\n", hres
);
242 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, 1);
243 ok(hres
== S_FALSE
, "Skip expected end of list: %08x\n", hres
);
246 /* Test skipping off the end of the list */
247 static void test_Skip_offEnd(void)
251 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, test_fileCount
+ 1);
252 ok(hres
== S_FALSE
, "Skip expected end of list: %08x\n", hres
);
255 /* Test resetting the file enumerator */
256 static void test_Reset(void)
260 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, test_fileCount
);
261 ok(hres
== S_OK
, "Skip failed: %08x\n", hres
);
262 hres
= IEnumBackgroundCopyFiles_Reset(test_enumFiles
);
263 ok(hres
== S_OK
, "Reset failed: %08x\n", hres
);
264 hres
= IEnumBackgroundCopyFiles_Skip(test_enumFiles
, test_fileCount
);
265 ok(hres
== S_OK
, "Reset failed: %08x\n", hres
);
268 typedef void (*test_t
)(void);
270 START_TEST(enum_files
)
272 static const test_t tests
[] = {
274 test_Next_walkListNull
,
275 test_Next_walkList_1
,
276 test_Next_walkList_2
,
288 if (FAILED(test_create_manager()))
291 win_skip("Failed to create Manager instance, skipping tests\n");
295 for (test
= tests
, i
= 0; *test
; ++test
, ++i
)
297 /* Keep state separate between tests. */
300 ok(0, "tests:%d: Unable to setup test\n", i
);