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
25 #define WIN32_NO_STATUS
27 #define COM_NO_WINDOWS_H
37 #include <wine/test.h>
40 /* Globals used by many tests */
41 static const WCHAR test_remoteName
[] = {'r','e','m','o','t','e', 0};
42 static const WCHAR test_localName
[] = {'l','o','c','a','l', 0};
43 static WCHAR test_localFile
[MAX_PATH
];
44 static WCHAR test_remoteUrl
[MAX_PATH
];
45 static const WCHAR test_displayName
[] = {'T','e','s','t', 0};
46 static IBackgroundCopyJob
*test_job
;
47 static IBackgroundCopyManager
*test_manager
;
48 static IEnumBackgroundCopyFiles
*test_enumFiles
;
49 static IBackgroundCopyFile
*test_file
;
51 /* Helper function to add a file to a job. The helper function takes base
52 file name and creates properly formed path and URL strings for creation of
54 static HRESULT
addFileHelper(IBackgroundCopyJob
* job
,
55 const WCHAR
*localName
, const WCHAR
*remoteName
)
59 GetCurrentDirectoryW(MAX_PATH
, test_localFile
);
60 PathAppendW(test_localFile
, localName
);
61 GetCurrentDirectoryW(MAX_PATH
, test_remoteUrl
);
62 PathAppendW(test_remoteUrl
, remoteName
);
64 UrlCreateFromPathW(test_remoteUrl
, test_remoteUrl
, &urlSize
, 0);
65 UrlUnescapeW(test_remoteUrl
, NULL
, &urlSize
, URL_UNESCAPE_INPLACE
);
67 return IBackgroundCopyJob_AddFile(job
, test_remoteUrl
, test_localFile
);
70 static HRESULT
test_create_manager(void)
73 IBackgroundCopyManager
*manager
= NULL
;
75 /* Creating BITS instance */
76 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
, CLSCTX_LOCAL_SERVER
,
77 &IID_IBackgroundCopyManager
, (void **) &manager
);
79 if(hres
== HRESULT_FROM_WIN32(ERROR_SERVICE_DISABLED
)) {
80 win_skip("Needed Service is disabled\n");
86 IBackgroundCopyJob
*job
;
89 hres
= IBackgroundCopyManager_CreateJob(manager
, test_displayName
, BG_JOB_TYPE_DOWNLOAD
, &jobId
, &job
);
92 hres
= addFileHelper(job
, test_localName
, test_remoteName
);
94 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
95 IBackgroundCopyJob_Release(job
);
97 IBackgroundCopyManager_Release(manager
);
103 /* Generic test setup */
104 static BOOL
setup(void)
111 memset(&test_jobId
, 0, sizeof test_jobId
);
113 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
114 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
115 (void **) &test_manager
);
119 hres
= IBackgroundCopyManager_CreateJob(test_manager
, test_displayName
,
120 BG_JOB_TYPE_DOWNLOAD
, &test_jobId
, &test_job
);
123 IBackgroundCopyManager_Release(test_manager
);
127 if (addFileHelper(test_job
, test_localName
, test_remoteName
) != S_OK
128 || IBackgroundCopyJob_EnumFiles(test_job
, &test_enumFiles
) != S_OK
)
130 IBackgroundCopyJob_Release(test_job
);
131 IBackgroundCopyManager_Release(test_manager
);
135 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &test_file
, NULL
);
138 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
139 IBackgroundCopyJob_Release(test_job
);
140 IBackgroundCopyManager_Release(test_manager
);
147 /* Generic test cleanup */
148 static void teardown(void)
150 IBackgroundCopyFile_Release(test_file
);
151 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
152 IBackgroundCopyJob_Release(test_job
);
153 IBackgroundCopyManager_Release(test_manager
);
156 /* Test that the remote name is properly set */
157 static void test_GetRemoteName(void)
162 hres
= IBackgroundCopyFile_GetRemoteName(test_file
, &name
);
163 ok(hres
== S_OK
, "GetRemoteName failed: %08x\n", hres
);
164 ok(lstrcmpW(name
, test_remoteUrl
) == 0, "Got incorrect remote name\n");
168 /* Test that the local name is properly set */
169 static void test_GetLocalName(void)
174 hres
= IBackgroundCopyFile_GetLocalName(test_file
, &name
);
175 ok(hres
== S_OK
, "GetLocalName failed: %08x\n", hres
);
176 ok(lstrcmpW(name
, test_localFile
) == 0, "Got incorrect local name\n");
180 /* Test getting the progress of a file*/
181 static void test_GetProgress_PreTransfer(void)
184 BG_FILE_PROGRESS progress
;
186 hres
= IBackgroundCopyFile_GetProgress(test_file
, &progress
);
187 ok(hres
== S_OK
, "GetProgress failed: %08x\n", hres
);
188 ok(progress
.BytesTotal
== BG_SIZE_UNKNOWN
, "Got incorrect total size: %s\n",
189 wine_dbgstr_longlong(progress
.BytesTotal
));
190 ok(progress
.BytesTransferred
== 0, "Got incorrect number of transferred bytes: %s\n",
191 wine_dbgstr_longlong(progress
.BytesTransferred
));
192 ok(progress
.Completed
== FALSE
, "Got incorrect completion status\n");
195 typedef void (*test_t
)(void);
199 static const test_t tests
[] = {
202 test_GetProgress_PreTransfer
,
210 if (FAILED(test_create_manager()))
213 win_skip("Failed to create Manager instance, skipping tests\n");
217 for (test
= tests
, i
= 0; *test
; ++test
, ++i
)
219 /* Keep state separate between tests. */
222 ok(0, "tests:%d: Unable to setup test\n", i
);