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 */
31 static WCHAR test_localFile
[MAX_PATH
];
32 static WCHAR test_remoteUrl
[MAX_PATH
];
33 static IBackgroundCopyJob
*test_job
;
34 static IBackgroundCopyManager
*test_manager
;
35 static IEnumBackgroundCopyFiles
*test_enumFiles
;
36 static IBackgroundCopyFile
*test_file
;
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
41 static HRESULT
addFileHelper(IBackgroundCopyJob
* job
,
42 const WCHAR
*localName
, const WCHAR
*remoteName
)
46 GetCurrentDirectoryW(MAX_PATH
, test_localFile
);
47 PathAppendW(test_localFile
, localName
);
48 GetCurrentDirectoryW(MAX_PATH
, test_remoteUrl
);
49 PathAppendW(test_remoteUrl
, remoteName
);
51 UrlCreateFromPathW(test_remoteUrl
, test_remoteUrl
, &urlSize
, 0);
52 UrlUnescapeW(test_remoteUrl
, NULL
, &urlSize
, URL_UNESCAPE_INPLACE
);
54 return IBackgroundCopyJob_AddFile(job
, test_remoteUrl
, test_localFile
);
57 static HRESULT
test_create_manager(void)
60 IBackgroundCopyManager
*manager
= NULL
;
62 /* Creating BITS instance */
63 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
, CLSCTX_LOCAL_SERVER
,
64 &IID_IBackgroundCopyManager
, (void **) &manager
);
66 if(hres
== HRESULT_FROM_WIN32(ERROR_SERVICE_DISABLED
)) {
67 win_skip("Needed Service is disabled\n");
73 IBackgroundCopyJob
*job
;
76 hres
= IBackgroundCopyManager_CreateJob(manager
, L
"Test", BG_JOB_TYPE_DOWNLOAD
, &jobId
, &job
);
79 hres
= addFileHelper(job
, L
"local", L
"remote");
81 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
82 IBackgroundCopyJob_Release(job
);
84 IBackgroundCopyManager_Release(manager
);
90 /* Generic test setup */
91 static BOOL
setup(void)
98 memset(&test_jobId
, 0, sizeof test_jobId
);
100 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
101 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
102 (void **) &test_manager
);
106 hres
= IBackgroundCopyManager_CreateJob(test_manager
, L
"Test",
107 BG_JOB_TYPE_DOWNLOAD
, &test_jobId
, &test_job
);
110 IBackgroundCopyManager_Release(test_manager
);
114 if (addFileHelper(test_job
, L
"local", L
"remote") != S_OK
115 || IBackgroundCopyJob_EnumFiles(test_job
, &test_enumFiles
) != S_OK
)
117 IBackgroundCopyJob_Release(test_job
);
118 IBackgroundCopyManager_Release(test_manager
);
122 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &test_file
, NULL
);
125 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
126 IBackgroundCopyJob_Release(test_job
);
127 IBackgroundCopyManager_Release(test_manager
);
134 /* Generic test cleanup */
135 static void teardown(void)
137 IBackgroundCopyFile_Release(test_file
);
138 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
139 IBackgroundCopyJob_Release(test_job
);
140 IBackgroundCopyManager_Release(test_manager
);
143 /* Test that the remote name is properly set */
144 static void test_GetRemoteName(void)
149 hres
= IBackgroundCopyFile_GetRemoteName(test_file
, &name
);
150 ok(hres
== S_OK
, "GetRemoteName failed: %08x\n", hres
);
151 ok(lstrcmpW(name
, test_remoteUrl
) == 0, "Got incorrect remote name\n");
155 /* Test that the local name is properly set */
156 static void test_GetLocalName(void)
161 hres
= IBackgroundCopyFile_GetLocalName(test_file
, &name
);
162 ok(hres
== S_OK
, "GetLocalName failed: %08x\n", hres
);
163 ok(lstrcmpW(name
, test_localFile
) == 0, "Got incorrect local name\n");
167 /* Test getting the progress of a file*/
168 static void test_GetProgress_PreTransfer(void)
171 BG_FILE_PROGRESS progress
;
173 hres
= IBackgroundCopyFile_GetProgress(test_file
, &progress
);
174 ok(hres
== S_OK
, "GetProgress failed: %08x\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");
182 typedef void (*test_t
)(void);
186 static const test_t tests
[] = {
189 test_GetProgress_PreTransfer
,
197 if (FAILED(test_create_manager()))
200 win_skip("Failed to create Manager instance, skipping tests\n");
204 for (test
= tests
, i
= 0; *test
; ++test
, ++i
)
206 /* Keep state separate between tests. */
209 ok(0, "tests:%d: Unable to setup test\n", i
);