ReactOS 0.4.15-dev-7788-g1ad9096
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 */
31static const WCHAR test_remoteName[] = {'r','e','m','o','t','e', 0};
32static const WCHAR test_localName[] = {'l','o','c','a','l', 0};
35static const WCHAR test_displayName[] = {'T','e','s','t', 0};
40
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
43 the file. */
45 const WCHAR *localName, const WCHAR *remoteName)
46{
47 DWORD urlSize;
48
50 PathAppendW(test_localFile, localName);
52 PathAppendW(test_remoteUrl, remoteName);
53 urlSize = MAX_PATH;
56
57 return IBackgroundCopyJob_AddFile(job, test_remoteUrl, test_localFile);
58}
59
61{
64
65 /* Creating BITS instance */
66 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, CLSCTX_LOCAL_SERVER,
67 &IID_IBackgroundCopyManager, (void **) &manager);
68
70 win_skip("Needed Service is disabled\n");
71 return hres;
72 }
73
74 if (hres == S_OK)
75 {
77 GUID jobId;
78
79 hres = IBackgroundCopyManager_CreateJob(manager, test_displayName, BG_JOB_TYPE_DOWNLOAD, &jobId, &job);
80 if (hres == S_OK)
81 {
83 if (hres != S_OK)
84 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
85 IBackgroundCopyJob_Release(job);
86 }
87 IBackgroundCopyManager_Release(manager);
88 }
89
90 return hres;
91}
92
93/* Generic test setup */
94static BOOL setup(void)
95{
98
100 test_job = NULL;
101 memset(&test_jobId, 0, sizeof test_jobId);
102
103 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
104 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
105 (void **) &test_manager);
106 if(hres != S_OK)
107 return FALSE;
108
109 hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayName,
110 BG_JOB_TYPE_DOWNLOAD, &test_jobId, &test_job);
111 if(hres != S_OK)
112 {
113 IBackgroundCopyManager_Release(test_manager);
114 return FALSE;
115 }
116
118 || IBackgroundCopyJob_EnumFiles(test_job, &test_enumFiles) != S_OK)
119 {
120 IBackgroundCopyJob_Release(test_job);
121 IBackgroundCopyManager_Release(test_manager);
122 return FALSE;
123 }
124
125 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &test_file, NULL);
126 if(hres != S_OK)
127 {
128 IEnumBackgroundCopyFiles_Release(test_enumFiles);
129 IBackgroundCopyJob_Release(test_job);
130 IBackgroundCopyManager_Release(test_manager);
131 return FALSE;
132 }
133
134 return TRUE;
135}
136
137/* Generic test cleanup */
138static void teardown(void)
139{
140 IBackgroundCopyFile_Release(test_file);
141 IEnumBackgroundCopyFiles_Release(test_enumFiles);
142 IBackgroundCopyJob_Release(test_job);
143 IBackgroundCopyManager_Release(test_manager);
144}
145
146/* Test that the remote name is properly set */
147static void test_GetRemoteName(void)
148{
150 LPWSTR name;
151
152 hres = IBackgroundCopyFile_GetRemoteName(test_file, &name);
153 ok(hres == S_OK, "GetRemoteName failed: %08x\n", hres);
154 ok(lstrcmpW(name, test_remoteUrl) == 0, "Got incorrect remote name\n");
156}
157
158/* Test that the local name is properly set */
159static void test_GetLocalName(void)
160{
162 LPWSTR name;
163
164 hres = IBackgroundCopyFile_GetLocalName(test_file, &name);
165 ok(hres == S_OK, "GetLocalName failed: %08x\n", hres);
166 ok(lstrcmpW(name, test_localFile) == 0, "Got incorrect local name\n");
168}
169
170/* Test getting the progress of a file*/
172{
174 BG_FILE_PROGRESS progress;
175
176 hres = IBackgroundCopyFile_GetProgress(test_file, &progress);
177 ok(hres == S_OK, "GetProgress failed: %08x\n", hres);
178 ok(progress.BytesTotal == BG_SIZE_UNKNOWN, "Got incorrect total size: %s\n",
179 wine_dbgstr_longlong(progress.BytesTotal));
180 ok(progress.BytesTransferred == 0, "Got incorrect number of transferred bytes: %s\n",
181 wine_dbgstr_longlong(progress.BytesTransferred));
182 ok(progress.Completed == FALSE, "Got incorrect completion status\n");
183}
184
185typedef void (*test_t)(void);
186
188{
189 static const test_t tests[] = {
193 0
194 };
195 const test_t *test;
196 int i;
197
199
201 {
203 win_skip("Failed to create Manager instance, skipping tests\n");
204 return;
205 }
206
207 for (test = tests, i = 0; *test; ++test, ++i)
208 {
209 /* Keep state separate between tests. */
210 if (!setup())
211 {
212 ok(0, "tests:%d: Unable to setup test\n", i);
213 break;
214 }
215 (*test)();
216 teardown();
217 }
219}
#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
#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
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
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
static struct test_info tests[]
HRESULT hres
Definition: protocol.c:465
static HANDLE job
Definition: process.c:77
static IEnumBackgroundCopyFiles * test_enumFiles
Definition: file.c:38
static void teardown(void)
Definition: file.c:138
static void test_GetProgress_PreTransfer(void)
Definition: file.c:171
static const WCHAR test_localName[]
Definition: file.c:32
static WCHAR test_remoteUrl[MAX_PATH]
Definition: file.c:34
static BOOL setup(void)
Definition: file.c:94
static const WCHAR test_remoteName[]
Definition: file.c:31
static HRESULT addFileHelper(IBackgroundCopyJob *job, const WCHAR *localName, const WCHAR *remoteName)
Definition: file.c:44
static void test_GetLocalName(void)
Definition: file.c:159
static IBackgroundCopyJob * test_job
Definition: file.c:36
static IBackgroundCopyFile * test_file
Definition: file.c:39
static IBackgroundCopyManager * test_manager
Definition: file.c:37
static WCHAR test_localFile[MAX_PATH]
Definition: file.c:33
static void test_GetRemoteName(void)
Definition: file.c:147
static const WCHAR test_displayName[]
Definition: file.c:35
static HRESULT test_create_manager(void)
Definition: file.c:60
void(* test_t)(void)
Definition: file.c:185
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:160
#define memset(x, y, z)
Definition: compat.h:39
#define URL_UNESCAPE_INPLACE
Definition: shlwapi.h:1224
Definition: fci.c:127
Definition: name.c:39
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define ERROR_SERVICE_DISABLED
Definition: winerror.h:609
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184