kerberos: Add support for SECPKG_CRED_BOTH.
[wine.git] / dlls / qmgr / tests / enum_files.c
blob1ca0fcd84481e38a64c73fa1a444d619a45976d7
1 /*
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
21 #include <shlwapi.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "wine/test.h"
27 #include "initguid.h"
28 #include "bits.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
39 the file. */
40 static HRESULT addFileHelper(IBackgroundCopyJob* job,
41 const WCHAR *localName, const WCHAR *remoteName)
43 DWORD urlSize;
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);
52 urlSize = MAX_PATH;
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)
60 HRESULT hres;
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");
69 return hres;
72 if (hres == S_OK)
74 IBackgroundCopyJob *job;
75 GUID jobId;
77 hres = IBackgroundCopyManager_CreateJob(manager, L"Test", BG_JOB_TYPE_DOWNLOAD, &jobId, &job);
78 if (hres == S_OK)
80 hres = addFileHelper(job, L"localA", L"remoteA");
81 if (hres != S_OK)
82 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
83 IBackgroundCopyJob_Release(job);
85 IBackgroundCopyManager_Release(manager);
88 return hres;
91 /* Generic test setup */
92 static BOOL setup(void)
94 HRESULT hres;
95 GUID test_jobId;
97 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
98 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
99 (void **) &test_manager);
100 if(hres != S_OK)
101 return FALSE;
103 hres = IBackgroundCopyManager_CreateJob(test_manager, L"Test", BG_JOB_TYPE_DOWNLOAD,
104 &test_jobId, &test_job);
105 if(hres != S_OK)
107 IBackgroundCopyManager_Release(test_manager);
108 return FALSE;
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);
117 return FALSE;
120 return TRUE;
123 /* Generic test cleanup */
124 static void teardown(void)
126 IEnumBackgroundCopyFiles_Release(test_enumFiles);
127 IBackgroundCopyJob_Release(test_job);
128 IBackgroundCopyManager_Release(test_manager);
131 /* Test GetCount */
132 static void test_GetCount(void)
134 HRESULT hres;
135 ULONG fileCount;
137 hres = IEnumBackgroundCopyFiles_GetCount(test_enumFiles, &fileCount);
138 ok(hres == S_OK, "GetCount failed: %08lx\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)
145 HRESULT hres;
146 IBackgroundCopyFile *file;
147 ULONG i;
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: %08lx\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: %08lx\n", hres);
162 /* Test Next by requesting one file at a time */
163 static void test_Next_walkList_1(void)
165 HRESULT hres;
166 IBackgroundCopyFile *file;
167 ULONG fetched;
168 ULONG i;
170 /* Fetch the available files */
171 for (i = 0; i < test_fileCount; i++)
173 file = NULL;
174 fetched = 0;
175 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, &fetched);
176 ok(hres == S_OK, "Next failed: %08lx\n", hres);
177 ok(fetched == 1, "Next returned the incorrect number of files: %08lx\n", hres);
178 ok(file != NULL, "Next returned NULL\n");
179 if (file)
180 IBackgroundCopyFile_Release(file);
183 /* Attempt to fetch one more than the number of available files */
184 fetched = 0;
185 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, &fetched);
186 ok(hres == S_FALSE, "Next off end of available files failed: %08lx\n", hres);
187 ok(fetched == 0, "Next returned the incorrect number of files: %08lx\n", hres);
190 /* Test Next by requesting multiple files at a time */
191 static void test_Next_walkList_2(void)
193 HRESULT hres;
194 IBackgroundCopyFile *files[NUM_FILES];
195 ULONG fetched;
196 ULONG i;
198 for (i = 0; i < test_fileCount; i++)
199 files[i] = NULL;
201 fetched = 0;
202 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, test_fileCount, files, &fetched);
203 ok(hres == S_OK, "Next failed: %08lx\n", hres);
204 ok(fetched == test_fileCount, "Next returned the incorrect number of files: %08lx\n", hres);
206 for (i = 0; i < test_fileCount; i++)
208 ok(files[i] != NULL, "Next returned NULL\n");
209 if (files[i])
210 IBackgroundCopyFile_Release(files[i]);
214 /* Test Next Error conditions */
215 static void test_Next_errors(void)
217 HRESULT hres;
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: %08lx\n", hres);
225 /* Test skipping through the files in a list */
226 static void test_Skip_walkList(void)
228 HRESULT hres;
229 ULONG i;
231 for (i = 0; i < test_fileCount; i++)
233 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, 1);
234 ok(hres == S_OK, "Skip failed: %08lx\n", hres);
237 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, 1);
238 ok(hres == S_FALSE, "Skip expected end of list: %08lx\n", hres);
241 /* Test skipping off the end of the list */
242 static void test_Skip_offEnd(void)
244 HRESULT hres;
246 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, test_fileCount + 1);
247 ok(hres == S_FALSE, "Skip expected end of list: %08lx\n", hres);
250 /* Test resetting the file enumerator */
251 static void test_Reset(void)
253 HRESULT hres;
255 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, test_fileCount);
256 ok(hres == S_OK, "Skip failed: %08lx\n", hres);
257 hres = IEnumBackgroundCopyFiles_Reset(test_enumFiles);
258 ok(hres == S_OK, "Reset failed: %08lx\n", hres);
259 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, test_fileCount);
260 ok(hres == S_OK, "Reset failed: %08lx\n", hres);
263 typedef void (*test_t)(void);
265 START_TEST(enum_files)
267 static const test_t tests[] = {
268 test_GetCount,
269 test_Next_walkListNull,
270 test_Next_walkList_1,
271 test_Next_walkList_2,
272 test_Next_errors,
273 test_Skip_walkList,
274 test_Skip_offEnd,
275 test_Reset,
278 const test_t *test;
279 int i;
281 CoInitialize(NULL);
283 if (FAILED(test_create_manager()))
285 CoUninitialize();
286 win_skip("Failed to create Manager instance, skipping tests\n");
287 return;
290 for (test = tests, i = 0; *test; ++test, ++i)
292 /* Keep state separate between tests. */
293 if (!setup())
295 ok(0, "tests:%d: Unable to setup test\n", i);
296 break;
298 (*test)();
299 teardown();
301 CoUninitialize();