ReactOS 0.4.17-dev-966-gf06eace
file.c
Go to the documentation of this file.
1/*
2 * Unit test suite for Background Copy File Interface
3 *
4 * Copyright 2007 Google (Roy Shea)
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 <stdio.h>
22
23#include <shlwapi.h>
24
25#define COBJMACROS
26
27#include "wine/test.h"
28#include "bits.h"
29
30/* Globals used by many tests */
37
38/* Helper function to add a file to a job. The helper function takes base
39 file name and creates properly formed path and URL strings for creation of
40 the file. */
42 const WCHAR *localName, const WCHAR *remoteName)
43{
44 DWORD urlSize;
45
47 PathAppendW(test_localFile, localName);
49 PathAppendW(test_remoteUrl, remoteName);
50 urlSize = MAX_PATH;
53
54 return IBackgroundCopyJob_AddFile(job, test_remoteUrl, test_localFile);
55}
56
58{
61
62 /* Creating BITS instance */
63 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, CLSCTX_LOCAL_SERVER,
64 &IID_IBackgroundCopyManager, (void **) &manager);
65
67 win_skip("Needed Service is disabled\n");
68 return hres;
69 }
70
71 if (hres == S_OK)
72 {
74 GUID jobId;
75
76 hres = IBackgroundCopyManager_CreateJob(manager, L"Test", BG_JOB_TYPE_DOWNLOAD, &jobId, &job);
77 if (hres == S_OK)
78 {
79 hres = addFileHelper(job, L"local", L"remote");
80 if (hres != S_OK)
81 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
82 IBackgroundCopyJob_Release(job);
83 }
84 IBackgroundCopyManager_Release(manager);
85 }
86
87 return hres;
88}
89
90/* Generic test setup */
91static BOOL setup(void)
92{
95
97 test_job = NULL;
98 memset(&test_jobId, 0, sizeof test_jobId);
99
100 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
101 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
102 (void **) &test_manager);
103 if(hres != S_OK)
104 return FALSE;
105
106 hres = IBackgroundCopyManager_CreateJob(test_manager, L"Test",
107 BG_JOB_TYPE_DOWNLOAD, &test_jobId, &test_job);
108 if(hres != S_OK)
109 {
110 IBackgroundCopyManager_Release(test_manager);
111 return FALSE;
112 }
113
114 if (addFileHelper(test_job, L"local", L"remote") != S_OK
115 || IBackgroundCopyJob_EnumFiles(test_job, &test_enumFiles) != S_OK)
116 {
117 IBackgroundCopyJob_Release(test_job);
118 IBackgroundCopyManager_Release(test_manager);
119 return FALSE;
120 }
121
122 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &test_file, NULL);
123 if(hres != S_OK)
124 {
125 IEnumBackgroundCopyFiles_Release(test_enumFiles);
126 IBackgroundCopyJob_Release(test_job);
127 IBackgroundCopyManager_Release(test_manager);
128 return FALSE;
129 }
130
131 return TRUE;
132}
133
134/* Generic test cleanup */
135static void teardown(void)
136{
137 IBackgroundCopyFile_Release(test_file);
138 IEnumBackgroundCopyFiles_Release(test_enumFiles);
139 IBackgroundCopyJob_Release(test_job);
140 IBackgroundCopyManager_Release(test_manager);
141}
142
143/* Test that the remote name is properly set */
144static void test_GetRemoteName(void)
145{
147 LPWSTR name;
148
149 hres = IBackgroundCopyFile_GetRemoteName(test_file, &name);
150 ok(hres == S_OK, "GetRemoteName failed: %08lx\n", hres);
151 ok(lstrcmpW(name, test_remoteUrl) == 0, "Got incorrect remote name\n");
153}
154
155/* Test that the local name is properly set */
156static void test_GetLocalName(void)
157{
159 LPWSTR name;
160
161 hres = IBackgroundCopyFile_GetLocalName(test_file, &name);
162 ok(hres == S_OK, "GetLocalName failed: %08lx\n", hres);
163 ok(lstrcmpW(name, test_localFile) == 0, "Got incorrect local name\n");
165}
166
167/* Test getting the progress of a file*/
169{
171 BG_FILE_PROGRESS progress;
172
173 hres = IBackgroundCopyFile_GetProgress(test_file, &progress);
174 ok(hres == S_OK, "GetProgress failed: %08lx\n", hres);
175 ok(progress.BytesTotal == BG_SIZE_UNKNOWN, "Got incorrect total size: %s\n",
176 wine_dbgstr_longlong(progress.BytesTotal));
177 ok(progress.BytesTransferred == 0, "Got incorrect number of transferred bytes: %s\n",
178 wine_dbgstr_longlong(progress.BytesTransferred));
179 ok(progress.Completed == FALSE, "Got incorrect completion status\n");
180}
181
182typedef void (*test_t)(void);
183
185{
186 static const test_t tests[] = {
190 0
191 };
192 const test_t *test;
193 int i;
194
196
198 {
200 win_skip("Failed to create Manager instance, skipping tests\n");
201 return;
202 }
203
204 for (test = tests, i = 0; *test; ++test, ++i)
205 {
206 /* Keep state separate between tests. */
207 if (!setup())
208 {
209 ok(0, "tests:%d: Unable to setup test\n", i);
210 break;
211 }
212 (*test)();
213 teardown();
214 }
216}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
cd_progress_ptr progress
Definition: cdjpeg.h:152
#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
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
#define MAX_PATH
Definition: compat.h:34
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
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 IEnumBackgroundCopyFiles * test_enumFiles
Definition: file.c:35
static void teardown(void)
Definition: file.c:135
static void test_GetProgress_PreTransfer(void)
Definition: file.c:168
static WCHAR test_remoteUrl[MAX_PATH]
Definition: file.c:32
static BOOL setup(void)
Definition: file.c:91
static HRESULT addFileHelper(IBackgroundCopyJob *job, const WCHAR *localName, const WCHAR *remoteName)
Definition: file.c:41
static void test_GetLocalName(void)
Definition: file.c:156
static IBackgroundCopyJob * test_job
Definition: file.c:33
static IBackgroundCopyFile * test_file
Definition: file.c:36
static IBackgroundCopyManager * test_manager
Definition: file.c:34
static WCHAR test_localFile[MAX_PATH]
Definition: file.c:31
static void test_GetRemoteName(void)
Definition: file.c:144
static HRESULT test_create_manager(void)
Definition: file.c:57
void(* test_t)(void)
Definition: file.c:182
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
#define memset(x, y, z)
Definition: compat.h:39
Definition: fci.c:123
Definition: name.c:39
uint16_t * LPWSTR
Definition: typedefs.h:56
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_SERVICE_DISABLED
Definition: winerror.h:933