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
);
58 return IBackgroundCopyJob_AddFile(test_job
, test_remoteUrl
, test_localFile
);
61 /* Generic test setup */
62 static BOOL
setup(void)
69 memset(&test_jobId
, 0, sizeof test_jobId
);
71 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
72 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
73 (void **) &test_manager
);
77 hres
= IBackgroundCopyManager_CreateJob(test_manager
, test_displayName
,
78 BG_JOB_TYPE_DOWNLOAD
, &test_jobId
, &test_job
);
81 IBackgroundCopyManager_Release(test_manager
);
85 if (addFileHelper(test_job
, test_localName
, test_remoteName
) != S_OK
86 || IBackgroundCopyJob_EnumFiles(test_job
, &test_enumFiles
) != S_OK
)
88 IBackgroundCopyJob_Release(test_job
);
89 IBackgroundCopyManager_Release(test_manager
);
93 hres
= IEnumBackgroundCopyFiles_Next(test_enumFiles
, 1, &test_file
, NULL
);
96 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
97 IBackgroundCopyJob_Release(test_job
);
98 IBackgroundCopyManager_Release(test_manager
);
105 /* Generic test cleanup */
106 static void teardown(void)
108 IBackgroundCopyFile_Release(test_file
);
109 IEnumBackgroundCopyFiles_Release(test_enumFiles
);
110 IBackgroundCopyJob_Release(test_job
);
111 IBackgroundCopyManager_Release(test_manager
);
114 /* Test that the remote name is properly set */
115 static void test_GetRemoteName(void)
120 hres
= IBackgroundCopyFile_GetRemoteName(test_file
, &name
);
121 ok(hres
== S_OK
, "GetRemoteName failed: %08x\n", hres
);
124 skip("Unable to get remote name of test_file.\n");
127 ok(lstrcmpW(name
, test_remoteUrl
) == 0, "Got incorrect remote name\n");
131 /* Test that the local name is properly set */
132 static void test_GetLocalName(void)
137 hres
= IBackgroundCopyFile_GetLocalName(test_file
, &name
);
138 ok(hres
== S_OK
, "GetLocalName failed: %08x\n", hres
);
141 skip("Unable to get local name of test_file.\n");
144 ok(lstrcmpW(name
, test_localFile
) == 0, "Got incorrect local name\n");
148 /* Test getting the progress of a file*/
149 static void test_GetProgress_PreTransfer(void)
152 BG_FILE_PROGRESS progress
;
154 hres
= IBackgroundCopyFile_GetProgress(test_file
, &progress
);
155 ok(hres
== S_OK
, "GetProgress failed: %08x\n", hres
);
158 skip("Unable to get progress of test_file.\n");
161 ok(progress
.BytesTotal
== BG_SIZE_UNKNOWN
, "Got incorrect total size: %x%08x\n",
162 (DWORD
)(progress
.BytesTotal
>> 32), (DWORD
)progress
.BytesTotal
);
163 ok(progress
.BytesTransferred
== 0, "Got incorrect number of transferred bytes: %x%08x\n",
164 (DWORD
)(progress
.BytesTransferred
>> 32), (DWORD
)progress
.BytesTransferred
);
165 ok(progress
.Completed
== FALSE
, "Got incorret completion status\n");
168 typedef void (*test_t
)(void);
172 static const test_t tests
[] = {
175 test_GetProgress_PreTransfer
,
181 for (test
= tests
; *test
; ++test
)
183 /* Keep state separate between tests. */
186 skip("Unable to setup test\n");