ReactOS 0.4.16-dev-297-gc569aee
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. */
32static const WCHAR test_remoteNameA[] = {'r','e','m','o','t','e','A', 0};
33static const WCHAR test_localNameA[] = {'l','o','c','a','l','A', 0};
34static const WCHAR test_remoteNameB[] = {'r','e','m','o','t','e','B', 0};
35static const WCHAR test_localNameB[] = {'l','o','c','a','l','B', 0};
36static const WCHAR test_displayName[] = {'T', 'e', 's', 't', 0};
41
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
44 the file. */
46 const WCHAR *localName, const WCHAR *remoteName)
47{
48 DWORD urlSize;
49 WCHAR localFile[MAX_PATH];
50 WCHAR remoteUrl[MAX_PATH];
51 WCHAR remoteFile[MAX_PATH];
52
54 PathAppendW(localFile, localName);
55 GetCurrentDirectoryW(MAX_PATH, remoteFile);
56 PathAppendW(remoteFile, remoteName);
57 urlSize = MAX_PATH;
58 UrlCreateFromPathW(remoteFile, remoteUrl, &urlSize, 0);
59 UrlUnescapeW(remoteUrl, NULL, &urlSize, URL_UNESCAPE_INPLACE);
60 return IBackgroundCopyJob_AddFile(job, remoteUrl, localFile);
61}
62
64{
67
68 /* Creating BITS instance */
69 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, CLSCTX_LOCAL_SERVER,
70 &IID_IBackgroundCopyManager, (void **) &manager);
71
73 win_skip("Needed Service is disabled\n");
74 return hres;
75 }
76
77 if (hres == S_OK)
78 {
80 GUID jobId;
81
82 hres = IBackgroundCopyManager_CreateJob(manager, test_displayName, BG_JOB_TYPE_DOWNLOAD, &jobId, &job);
83 if (hres == S_OK)
84 {
86 if (hres != S_OK)
87 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
88 IBackgroundCopyJob_Release(job);
89 }
90 IBackgroundCopyManager_Release(manager);
91 }
92
93 return hres;
94}
95
96/* Generic test setup */
97static BOOL setup(void)
98{
101
102 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
103 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
104 (void **) &test_manager);
105 if(hres != S_OK)
106 return FALSE;
107
108 hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayName,
109 BG_JOB_TYPE_DOWNLOAD, &test_jobId,
110 &test_job);
111 if(hres != S_OK)
112 {
113 IBackgroundCopyManager_Release(test_manager);
114 return FALSE;
115 }
116
119 || IBackgroundCopyJob_EnumFiles(test_job, &test_enumFiles) != S_OK)
120 {
121 IBackgroundCopyJob_Release(test_job);
122 IBackgroundCopyManager_Release(test_manager);
123 return FALSE;
124 }
125
126 return TRUE;
127}
128
129/* Generic test cleanup */
130static void teardown(void)
131{
132 IEnumBackgroundCopyFiles_Release(test_enumFiles);
133 IBackgroundCopyJob_Release(test_job);
134 IBackgroundCopyManager_Release(test_manager);
135}
136
137/* Test GetCount */
138static void test_GetCount(void)
139{
141 ULONG fileCount;
142
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");
146}
147
148/* Test Next with a NULL pceltFetched*/
149static void test_Next_walkListNull(void)
150{
153 ULONG i;
154
155 /* Fetch the available files */
156 for (i = 0; i < test_fileCount; i++)
157 {
158 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, NULL);
159 ok(hres == S_OK, "Next failed: %08x\n", hres);
160 IBackgroundCopyFile_Release(file);
161 }
162
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);
166}
167
168/* Test Next by requesting one file at a time */
169static void test_Next_walkList_1(void)
170{
173 ULONG fetched;
174 ULONG i;
175
176 /* Fetch the available files */
177 for (i = 0; i < test_fileCount; i++)
178 {
179 file = NULL;
180 fetched = 0;
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");
185 if (file)
186 IBackgroundCopyFile_Release(file);
187 }
188
189 /* Attempt to fetch one more than the number of available files */
190 fetched = 0;
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);
194}
195
196/* Test Next by requesting multiple files at a time */
197static void test_Next_walkList_2(void)
198{
201 ULONG fetched;
202 ULONG i;
203
204 for (i = 0; i < test_fileCount; i++)
205 files[i] = NULL;
206
207 fetched = 0;
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);
211
212 for (i = 0; i < test_fileCount; i++)
213 {
214 ok(files[i] != NULL, "Next returned NULL\n");
215 if (files[i])
216 IBackgroundCopyFile_Release(files[i]);
217 }
218}
219
220/* Test Next Error conditions */
221static void test_Next_errors(void)
222{
225
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);
229}
230
231/* Test skipping through the files in a list */
232static void test_Skip_walkList(void)
233{
235 ULONG i;
236
237 for (i = 0; i < test_fileCount; i++)
238 {
239 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, 1);
240 ok(hres == S_OK, "Skip failed: %08x\n", hres);
241 }
242
243 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, 1);
244 ok(hres == S_FALSE, "Skip expected end of list: %08x\n", hres);
245}
246
247/* Test skipping off the end of the list */
248static void test_Skip_offEnd(void)
249{
251
252 hres = IEnumBackgroundCopyFiles_Skip(test_enumFiles, test_fileCount + 1);
253 ok(hres == S_FALSE, "Skip expected end of list: %08x\n", hres);
254}
255
256/* Test resetting the file enumerator */
257static void test_Reset(void)
258{
260
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);
267}
268
269typedef void (*test_t)(void);
270
271START_TEST(enum_files)
272{
273 static const test_t tests[] = {
282 0
283 };
284 const test_t *test;
285 int i;
286
288
290 {
292 win_skip("Failed to create Manager instance, skipping tests\n");
293 return;
294 }
295
296 for (test = tests, i = 0; *test; ++test, ++i)
297 {
298 /* Keep state separate between tests. */
299 if (!setup())
300 {
301 ok(0, "tests:%d: Unable to setup test\n", i);
302 break;
303 }
304 (*test)();
305 teardown();
306 }
308}
#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
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
HRESULT WINAPI UrlUnescapeW(LPWSTR pszUrl, LPWSTR pszUnescaped, LPDWORD pcchUnescaped, DWORD dwFlags)
Definition: url.c:1367
HRESULT WINAPI UrlCreateFromPathW(LPCWSTR pszPath, LPWSTR pszUrl, LPDWORD pcchUrl, DWORD dwReserved)
Definition: url.c:2497
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
static struct test_info tests[]
HRESULT hres
Definition: protocol.c:465
static HANDLE job
Definition: process.c:77
static void test_Reset(void)
Definition: enum_files.c:257
static void test_Next_errors(void)
Definition: enum_files.c:221
static IEnumBackgroundCopyFiles * test_enumFiles
Definition: enum_files.c:40
static const WCHAR test_remoteNameB[]
Definition: enum_files.c:34
static void test_Next_walkList_2(void)
Definition: enum_files.c:197
static void teardown(void)
Definition: enum_files.c:130
static const WCHAR test_localNameB[]
Definition: enum_files.c:35
static void test_Next_walkListNull(void)
Definition: enum_files.c:149
static void test_Next_walkList_1(void)
Definition: enum_files.c:169
static const WCHAR test_remoteNameA[]
Definition: enum_files.c:32
#define NUM_FILES
Definition: enum_files.c:31
static void test_GetCount(void)
Definition: enum_files.c:138
static void test_Skip_offEnd(void)
Definition: enum_files.c:248
static BOOL setup(void)
Definition: enum_files.c:97
static HRESULT addFileHelper(IBackgroundCopyJob *job, const WCHAR *localName, const WCHAR *remoteName)
Definition: enum_files.c:45
static void test_Skip_walkList(void)
Definition: enum_files.c:232
static IBackgroundCopyJob * test_job
Definition: enum_files.c:38
static const WCHAR test_localNameA[]
Definition: enum_files.c:33
static IBackgroundCopyManager * test_manager
Definition: enum_files.c:39
static const WCHAR test_displayName[]
Definition: enum_files.c:36
static HRESULT test_create_manager(void)
Definition: enum_files.c:63
void(* test_t)(void)
Definition: enum_files.c:269
static const ULONG test_fileCount
Definition: enum_files.c:37
static GUID test_jobId
Definition: job.c:39
#define PathAppendW
Definition: pathcch.h:309
#define test
Definition: rosglue.h:37
#define win_skip
Definition: test.h:163
#define URL_UNESCAPE_INPLACE
Definition: shlwapi.h:1250
Definition: fci.c:127
uint32_t ULONG
Definition: typedefs.h:59
#define S_FALSE
Definition: winerror.h:2357
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define ERROR_SERVICE_DISABLED
Definition: winerror.h:609
__wchar_t WCHAR
Definition: xmlstorage.h:180