wined3d: Only use a single allocation for each struct private_data.
[wine.git] / dlls / qmgr / tests / file.c
blobafe4b53aead713ebba3ef1da69509091fe2f2723
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 #define NUM_FILES 1
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
45 the file. */
46 static HRESULT addFileHelper(IBackgroundCopyJob* job,
47 const WCHAR *localName, const WCHAR *remoteName)
49 DWORD urlSize;
51 GetCurrentDirectoryW(MAX_PATH, test_localFile);
52 PathAppendW(test_localFile, localName);
53 GetCurrentDirectoryW(MAX_PATH, test_remoteUrl);
54 PathAppendW(test_remoteUrl, remoteName);
55 urlSize = MAX_PATH;
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)
64 HRESULT hres;
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");
73 return hres;
76 if (hres == S_OK)
78 IBackgroundCopyJob *job;
79 GUID jobId;
81 hres = IBackgroundCopyManager_CreateJob(manager, test_displayName, BG_JOB_TYPE_DOWNLOAD, &jobId, &job);
82 if (hres == S_OK)
84 hres = addFileHelper(job, test_localName, test_remoteName);
85 if (hres != S_OK)
86 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
87 IBackgroundCopyJob_Release(job);
89 IBackgroundCopyManager_Release(manager);
92 return hres;
95 /* Generic test setup */
96 static BOOL setup(void)
98 HRESULT hres;
99 GUID test_jobId;
101 test_manager = NULL;
102 test_job = NULL;
103 memset(&test_jobId, 0, sizeof test_jobId);
105 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
106 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
107 (void **) &test_manager);
108 if(hres != S_OK)
109 return FALSE;
111 hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayName,
112 BG_JOB_TYPE_DOWNLOAD, &test_jobId, &test_job);
113 if(hres != S_OK)
115 IBackgroundCopyManager_Release(test_manager);
116 return FALSE;
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);
124 return FALSE;
127 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &test_file, NULL);
128 if(hres != S_OK)
130 IEnumBackgroundCopyFiles_Release(test_enumFiles);
131 IBackgroundCopyJob_Release(test_job);
132 IBackgroundCopyManager_Release(test_manager);
133 return FALSE;
136 return TRUE;
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)
151 HRESULT hres;
152 LPWSTR name;
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");
157 CoTaskMemFree(name);
160 /* Test that the local name is properly set */
161 static void test_GetLocalName(void)
163 HRESULT hres;
164 LPWSTR name;
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");
169 CoTaskMemFree(name);
172 /* Test getting the progress of a file*/
173 static void test_GetProgress_PreTransfer(void)
175 HRESULT hres;
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);
189 START_TEST(file)
191 static const test_t tests[] = {
192 test_GetRemoteName,
193 test_GetLocalName,
194 test_GetProgress_PreTransfer,
197 const test_t *test;
198 int i;
200 CoInitialize(NULL);
202 if (FAILED(test_create_manager()))
204 CoUninitialize();
205 win_skip("Failed to create Manager instance, skipping tests\n");
206 return;
209 for (test = tests, i = 0; *test; ++test, ++i)
211 /* Keep state separate between tests. */
212 if (!setup())
214 ok(0, "tests:%d: Unable to setup test\n", i);
215 break;
217 (*test)();
218 teardown();
220 CoUninitialize();