2 * Unit test suite for Background Copy File Interface
4 * Copyright 2007 Google (Roy Shea)
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
27 #include "wine/test.h"
30 /* Globals used by many tests */
32 static const WCHAR test_remoteName
[] = {'r','e','m','o','t','e', 0};
33 static const WCHAR test_localName
[] = {'l','o','c','a','l', 0};
34 static WCHAR test_localFile
[MAX_PATH
];
35 static WCHAR test_remoteUrl
[MAX_PATH
];
36 static const ULONG test_fileCount
= NUM_FILES
;
37 static const WCHAR test_displayName
[] = {'T','e','s','t', 0};
38 static IBackgroundCopyJob
*test_job
;
39 static IBackgroundCopyManager
*test_manager
;
40 static IEnumBackgroundCopyFiles
*test_enumFiles
;
41 static IBackgroundCopyFile
*test_file
;
43 /* Helper function to add a file to a job. The helper function takes base
44 file name and creates properly formed path and URL strings for creation of
46 static HRESULT
addFileHelper(IBackgroundCopyJob
* job
,
47 const WCHAR
*localName
, const WCHAR
*remoteName
)
51 GetCurrentDirectoryW(MAX_PATH
, test_localFile
);
52 PathAppendW(test_localFile
, localName
);
53 GetCurrentDirectoryW(MAX_PATH
, test_remoteUrl
);
54 PathAppendW(test_remoteUrl
, remoteName
);
56 UrlCreateFromPathW(test_remoteUrl
, test_remoteUrl
, &urlSize
, 0);
57 UrlUnescapeW(test_remoteUrl
, NULL
, &urlSize
, URL_UNESCAPE_INPLACE
);
59 return IBackgroundCopyJob_AddFile(job
, test_remoteUrl
, test_localFile
);
62 static HRESULT
test_create_manager(void)
65 IBackgroundCopyManager
*manager
= NULL
;
67 /* Creating BITS instance */
68 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
, CLSCTX_LOCAL_SERVER
,
69 &IID_IBackgroundCopyManager
, (void **) &manager
);
71 if(hres
== HRESULT_FROM_WIN32(ERROR_SERVICE_DISABLED
)) {
72 win_skip("Needed Service is disabled\n");
78 IBackgroundCopyJob
*job
;
81 hres
= IBackgroundCopyManager_CreateJob(manager
, test_displayName
, BG_JOB_TYPE_DOWNLOAD
, &jobId
, &job
);
84 hres
= addFileHelper(job
, test_localName
, test_remoteName
);
86 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
87 IBackgroundCopyJob_Release(job
);
89 IBackgroundCopyManager_Release(manager
);
95 /* Generic test setup */
96 static BOOL
setup(void)
103 memset(&test_jobId
, 0, sizeof test_jobId
);
105 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
106 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
107 (void **) &test_manager
);
111 hres
= IBackgroundCopyManager_CreateJob(test_manager
, test_displayName
,
112 BG_JOB_TYPE_DOWNLOAD
, &test_jobId
, &test_job
);
115 IBackgroundCopyManager_Release(test_manager
);
119 if (addFileHelper(test_job
, test_localName
, test_remoteName
) != S_OK
120 || IBackgroundCopyJob_EnumFiles(test_job
, &test_enumFiles
) != S_OK
)
122 IBackgroundCopyJob_Release(test_job
);
123 IBackgroundCopyManager_Release(test_manager
);
127 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &test_file
, NULL
);
130 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
131 IBackgroundCopyJob_Release(test_job
);
132 IBackgroundCopyManager_Release(test_manager
);
139 /* Generic test cleanup */
140 static void teardown(void)
142 IBackgroundCopyFile_Release(test_file
);
143 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
144 IBackgroundCopyJob_Release(test_job
);
145 IBackgroundCopyManager_Release(test_manager
);
148 /* Test that the remote name is properly set */
149 static void test_GetRemoteName(void)
154 hres
= IBackgroundCopyFile_GetRemoteName(test_file
, &name
);
155 ok(hres
== S_OK
, "GetRemoteName failed: %08x\n", hres
);
156 ok(lstrcmpW(name
, test_remoteUrl
) == 0, "Got incorrect remote name\n");
160 /* Test that the local name is properly set */
161 static void test_GetLocalName(void)
166 hres
= IBackgroundCopyFile_GetLocalName(test_file
, &name
);
167 ok(hres
== S_OK
, "GetLocalName failed: %08x\n", hres
);
168 ok(lstrcmpW(name
, test_localFile
) == 0, "Got incorrect local name\n");
172 /* Test getting the progress of a file*/
173 static void test_GetProgress_PreTransfer(void)
176 BG_FILE_PROGRESS progress
;
178 hres
= IBackgroundCopyFile_GetProgress(test_file
, &progress
);
179 ok(hres
== S_OK
, "GetProgress failed: %08x\n", hres
);
180 ok(progress
.BytesTotal
== BG_SIZE_UNKNOWN
, "Got incorrect total size: %x%08x\n",
181 (DWORD
)(progress
.BytesTotal
>> 32), (DWORD
)progress
.BytesTotal
);
182 ok(progress
.BytesTransferred
== 0, "Got incorrect number of transferred bytes: %x%08x\n",
183 (DWORD
)(progress
.BytesTransferred
>> 32), (DWORD
)progress
.BytesTransferred
);
184 ok(progress
.Completed
== FALSE
, "Got incorrect completion status\n");
187 typedef void (*test_t
)(void);
191 static const test_t tests
[] = {
194 test_GetProgress_PreTransfer
,
202 if (FAILED(test_create_manager()))
205 win_skip("Failed to create Manager instance, skipping tests\n");
209 for (test
= tests
, i
= 0; *test
; ++test
, ++i
)
211 /* Keep state separate between tests. */
214 ok(0, "tests:%d: Unable to setup test\n", i
);