ReactOS 0.4.17-dev-966-gf06eace
enum_files.c
Go to the documentation of this file.
1/*
2 * Unit test suite for Enum Background Copy Files Interface
3 *
4 * Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman)
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <shlwapi.h>
22#include <stdio.h>
23
24#define COBJMACROS
25
26#include "wine/test.h"
27#include "initguid.h"
28#include "bits.h"
29
30/* Globals used by many tests */
31#define NUM_FILES 2 /* At least two. */
36
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. */
41 const WCHAR *localName, const WCHAR *remoteName)
42{
43 DWORD urlSize;
44 WCHAR localFile[MAX_PATH];
45 WCHAR remoteUrl[MAX_PATH];
46 WCHAR remoteFile[MAX_PATH];
47
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);
56}
57
59{
62
63 /* Creating BITS instance */
64 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, CLSCTX_LOCAL_SERVER,
65 &IID_IBackgroundCopyManager, (void **) &manager);
66
68 win_skip("Needed Service is disabled\n");
69 return hres;
70 }
71
72 if (hres == S_OK)
73 {
75 GUID jobId;
76
77 hres = IBackgroundCopyManager_CreateJob(manager, L"Test", BG_JOB_TYPE_DOWNLOAD, &jobId, &job);
78 if (hres == S_OK)
79 {
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);
84 }
85 IBackgroundCopyManager_Release(manager);
86 }
87
88 return hres;
89}
90
91/* Generic test setup */
92static BOOL setup(void)
93{
96
97 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
98 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
99 (void **) &test_manager);
100 if(hres != S_OK)
101 return FALSE;
102
103 hres = IBackgroundCopyManager_CreateJob(test_manager, L"Test", BG_JOB_TYPE_DOWNLOAD,
105 if(hres != S_OK)
106 {
107 IBackgroundCopyManager_Release(test_manager);
108 return FALSE;
109 }
110
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)
114 {
115 IBackgroundCopyJob_Release(test_job);
116 IBackgroundCopyManager_Release(test_manager);
117 return FALSE;
118 }
119
120 return TRUE;
121}
122
123/* Generic test cleanup */
124static void teardown(void)
125{
126 IEnumBackgroundCopyFiles_Release(test_enumFiles);
127 IBackgroundCopyJob_Release(test_job);
128 IBackgroundCopyManager_Release(test_manager);
129}
130
131/* Test GetCount */
132static void test_GetCount(void)
133{
135 ULONG fileCount;
136
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");
140}
141
142/* Test Next with a NULL pceltFetched*/
143static void test_Next_walkListNull(void)
144{
147 ULONG i;
148
149 /* Fetch the available files */
150 for (i = 0; i < test_fileCount; i++)
151 {
152 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, NULL);
153 ok(hres == S_OK, "Next failed: %08lx\n", hres);
154 IBackgroundCopyFile_Release(file);
155 }
156
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);
160}
161
162/* Test Next by requesting one file at a time */
163static void test_Next_walkList_1(void)
164{
167 ULONG fetched;
168 ULONG i;
169
170 /* Fetch the available files */
171 for (i = 0; i < test_fileCount; i++)
172 {
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);
181 }
182
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);
188}
189
190/* Test Next by requesting multiple files at a time */
191static void test_Next_walkList_2(void)
192{
195 ULONG fetched;
196 ULONG i;
197
198 for (i = 0; i < test_fileCount; i++)
199 files[i] = NULL;
200
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);
205
206 for (i = 0; i < test_fileCount; i++)
207 {
208 ok(files[i] != NULL, "Next returned NULL\n");
209 if (files[i])
210 IBackgroundCopyFile_Release(files[i]);
211 }
212}
213
214/* Test Next Error conditions */
215static void test_Next_errors(void)
216{
219
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);
223}
224
225/* Test skipping through the files in a list */
226static void test_Skip_walkList(void)
227{
229 ULONG i;
230
231 for (i = 0; i < test_fileCount; i++)
232 {
233 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, 1);
234 ok(hres == S_OK, "Skip failed: %08lx\n", hres);
235 }
236
237 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, 1);
238 ok(hres == S_FALSE, "Skip expected end of list: %08lx\n", hres);
239}
240
241/* Test skipping off the end of the list */
242static void test_Skip_offEnd(void)
243{
245
246 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, test_fileCount + 1);
247 ok(hres == S_FALSE, "Skip expected end of list: %08lx\n", hres);
248}
249
250/* Test resetting the file enumerator */
251static void test_Reset(void)
252{
254
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);
261}
262
263typedef void (*test_t)(void);
264
265START_TEST(enum_files)
266{
267 static const test_t tests[] = {
276 0
277 };
278 const test_t *test;
279 int i;
280
282
284 {
286 win_skip("Failed to create Manager instance, skipping tests\n");
287 return;
288 }
289
290 for (test = tests, i = 0; *test; ++test, ++i)
291 {
292 /* Keep state separate between tests. */
293 if (!setup())
294 {
295 ok(0, "tests:%d: Unable to setup test\n", i);
296 break;
297 }
298 (*test)();
299 teardown();
300 }
302}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define E_INVALIDARG
Definition: ddrawi.h:101
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI UrlCreateFromPathW(const WCHAR *path, WCHAR *url, DWORD *url_len, DWORD reserved)
Definition: path.c:4892
HRESULT WINAPI UrlUnescapeW(WCHAR *url, WCHAR *unescaped, DWORD *unescaped_len, DWORD flags)
Definition: path.c:2912
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define win_skip
Definition: minitest.h:67
static struct test_info tests[]
HRESULT hres
Definition: protocol.c:432
static HANDLE job
Definition: process.c:79
static void test_Reset(void)
Definition: enum_files.c:251
static void test_Next_errors(void)
Definition: enum_files.c:215
static IEnumBackgroundCopyFiles * test_enumFiles
Definition: enum_files.c:35
static void test_Next_walkList_2(void)
Definition: enum_files.c:191
static void teardown(void)
Definition: enum_files.c:124
static void test_Next_walkListNull(void)
Definition: enum_files.c:143
static void test_Next_walkList_1(void)
Definition: enum_files.c:163
#define NUM_FILES
Definition: enum_files.c:31
static void test_GetCount(void)
Definition: enum_files.c:132
static void test_Skip_offEnd(void)
Definition: enum_files.c:242
static BOOL setup(void)
Definition: enum_files.c:92
static HRESULT addFileHelper(IBackgroundCopyJob *job, const WCHAR *localName, const WCHAR *remoteName)
Definition: enum_files.c:40
static void test_Skip_walkList(void)
Definition: enum_files.c:226
static IBackgroundCopyJob * test_job
Definition: enum_files.c:33
static IBackgroundCopyManager * test_manager
Definition: enum_files.c:34
static HRESULT test_create_manager(void)
Definition: enum_files.c:58
void(* test_t)(void)
Definition: enum_files.c:263
static const ULONG test_fileCount
Definition: enum_files.c:32
static GUID test_jobId
Definition: job.c:39
#define PathAppendW
Definition: pathcch.h:310
short WCHAR
Definition: pedump.c:58
#define URL_UNESCAPE_INPLACE
Definition: shlwapi.h:525
#define test
Definition: rosglue.h:37
Definition: fci.c:123
uint32_t ULONG
Definition: typedefs.h:59
#define S_FALSE
Definition: winerror.h:3451
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_SERVICE_DISABLED
Definition: winerror.h:933