wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / qmgr / tests / file.c
blobcb5ba5fbe3763348f7c4f9d5b3431160e8a7f9ad
1 /*
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
21 #include <stdio.h>
23 #include <shlwapi.h>
25 #define COBJMACROS
27 #include "wine/test.h"
28 #include "bits.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
40 the file. */
41 static HRESULT addFileHelper(IBackgroundCopyJob* job,
42 const WCHAR *localName, const WCHAR *remoteName)
44 DWORD urlSize;
46 GetCurrentDirectoryW(MAX_PATH, test_localFile);
47 PathAppendW(test_localFile, localName);
48 GetCurrentDirectoryW(MAX_PATH, test_remoteUrl);
49 PathAppendW(test_remoteUrl, remoteName);
50 urlSize = MAX_PATH;
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)
59 HRESULT hres;
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");
68 return hres;
71 if (hres == S_OK)
73 IBackgroundCopyJob *job;
74 GUID jobId;
76 hres = IBackgroundCopyManager_CreateJob(manager, L"Test", BG_JOB_TYPE_DOWNLOAD, &jobId, &job);
77 if (hres == S_OK)
79 hres = addFileHelper(job, L"local", L"remote");
80 if (hres != S_OK)
81 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
82 IBackgroundCopyJob_Release(job);
84 IBackgroundCopyManager_Release(manager);
87 return hres;
90 /* Generic test setup */
91 static BOOL setup(void)
93 HRESULT hres;
94 GUID test_jobId;
96 test_manager = NULL;
97 test_job = NULL;
98 memset(&test_jobId, 0, sizeof test_jobId);
100 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
101 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
102 (void **) &test_manager);
103 if(hres != S_OK)
104 return FALSE;
106 hres = IBackgroundCopyManager_CreateJob(test_manager, L"Test",
107 BG_JOB_TYPE_DOWNLOAD, &test_jobId, &test_job);
108 if(hres != S_OK)
110 IBackgroundCopyManager_Release(test_manager);
111 return FALSE;
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);
119 return FALSE;
122 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &test_file, NULL);
123 if(hres != S_OK)
125 IEnumBackgroundCopyFiles_Release(test_enumFiles);
126 IBackgroundCopyJob_Release(test_job);
127 IBackgroundCopyManager_Release(test_manager);
128 return FALSE;
131 return TRUE;
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)
146 HRESULT hres;
147 LPWSTR name;
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");
152 CoTaskMemFree(name);
155 /* Test that the local name is properly set */
156 static void test_GetLocalName(void)
158 HRESULT hres;
159 LPWSTR name;
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");
164 CoTaskMemFree(name);
167 /* Test getting the progress of a file*/
168 static void test_GetProgress_PreTransfer(void)
170 HRESULT hres;
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);
184 START_TEST(file)
186 static const test_t tests[] = {
187 test_GetRemoteName,
188 test_GetLocalName,
189 test_GetProgress_PreTransfer,
192 const test_t *test;
193 int i;
195 CoInitialize(NULL);
197 if (FAILED(test_create_manager()))
199 CoUninitialize();
200 win_skip("Failed to create Manager instance, skipping tests\n");
201 return;
204 for (test = tests, i = 0; *test; ++test, ++i)
206 /* Keep state separate between tests. */
207 if (!setup())
209 ok(0, "tests:%d: Unable to setup test\n", i);
210 break;
212 (*test)();
213 teardown();
215 CoUninitialize();