d3d8/tests: Add a system memory miptree layout test.
[wine.git] / dlls / qmgr / tests / file.c
blob5e6eb34abdcdd2d6f9714468047d2a44ab0b0aba
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 const WCHAR test_remoteName[] = {'r','e','m','o','t','e', 0};
32 static const WCHAR test_localName[] = {'l','o','c','a','l', 0};
33 static WCHAR test_localFile[MAX_PATH];
34 static WCHAR test_remoteUrl[MAX_PATH];
35 static const WCHAR test_displayName[] = {'T','e','s','t', 0};
36 static IBackgroundCopyJob *test_job;
37 static IBackgroundCopyManager *test_manager;
38 static IEnumBackgroundCopyFiles *test_enumFiles;
39 static IBackgroundCopyFile *test_file;
41 /* Helper function to add a file to a job. The helper function takes base
42 file name and creates properly formed path and URL strings for creation of
43 the file. */
44 static HRESULT addFileHelper(IBackgroundCopyJob* job,
45 const WCHAR *localName, const WCHAR *remoteName)
47 DWORD urlSize;
49 GetCurrentDirectoryW(MAX_PATH, test_localFile);
50 PathAppendW(test_localFile, localName);
51 GetCurrentDirectoryW(MAX_PATH, test_remoteUrl);
52 PathAppendW(test_remoteUrl, remoteName);
53 urlSize = MAX_PATH;
54 UrlCreateFromPathW(test_remoteUrl, test_remoteUrl, &urlSize, 0);
55 UrlUnescapeW(test_remoteUrl, NULL, &urlSize, URL_UNESCAPE_INPLACE);
57 return IBackgroundCopyJob_AddFile(job, test_remoteUrl, test_localFile);
60 static HRESULT test_create_manager(void)
62 HRESULT hres;
63 IBackgroundCopyManager *manager = NULL;
65 /* Creating BITS instance */
66 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, CLSCTX_LOCAL_SERVER,
67 &IID_IBackgroundCopyManager, (void **) &manager);
69 if(hres == HRESULT_FROM_WIN32(ERROR_SERVICE_DISABLED)) {
70 win_skip("Needed Service is disabled\n");
71 return hres;
74 if (hres == S_OK)
76 IBackgroundCopyJob *job;
77 GUID jobId;
79 hres = IBackgroundCopyManager_CreateJob(manager, test_displayName, BG_JOB_TYPE_DOWNLOAD, &jobId, &job);
80 if (hres == S_OK)
82 hres = addFileHelper(job, test_localName, test_remoteName);
83 if (hres != S_OK)
84 win_skip("AddFile() with file:// protocol failed. Tests will be skipped.\n");
85 IBackgroundCopyJob_Release(job);
87 IBackgroundCopyManager_Release(manager);
90 return hres;
93 /* Generic test setup */
94 static BOOL setup(void)
96 HRESULT hres;
97 GUID test_jobId;
99 test_manager = NULL;
100 test_job = NULL;
101 memset(&test_jobId, 0, sizeof test_jobId);
103 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
104 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
105 (void **) &test_manager);
106 if(hres != S_OK)
107 return FALSE;
109 hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayName,
110 BG_JOB_TYPE_DOWNLOAD, &test_jobId, &test_job);
111 if(hres != S_OK)
113 IBackgroundCopyManager_Release(test_manager);
114 return FALSE;
117 if (addFileHelper(test_job, test_localName, test_remoteName) != S_OK
118 || IBackgroundCopyJob_EnumFiles(test_job, &test_enumFiles) != S_OK)
120 IBackgroundCopyJob_Release(test_job);
121 IBackgroundCopyManager_Release(test_manager);
122 return FALSE;
125 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &test_file, NULL);
126 if(hres != S_OK)
128 IEnumBackgroundCopyFiles_Release(test_enumFiles);
129 IBackgroundCopyJob_Release(test_job);
130 IBackgroundCopyManager_Release(test_manager);
131 return FALSE;
134 return TRUE;
137 /* Generic test cleanup */
138 static void teardown(void)
140 IBackgroundCopyFile_Release(test_file);
141 IEnumBackgroundCopyFiles_Release(test_enumFiles);
142 IBackgroundCopyJob_Release(test_job);
143 IBackgroundCopyManager_Release(test_manager);
146 /* Test that the remote name is properly set */
147 static void test_GetRemoteName(void)
149 HRESULT hres;
150 LPWSTR name;
152 hres = IBackgroundCopyFile_GetRemoteName(test_file, &name);
153 ok(hres == S_OK, "GetRemoteName failed: %08x\n", hres);
154 ok(lstrcmpW(name, test_remoteUrl) == 0, "Got incorrect remote name\n");
155 CoTaskMemFree(name);
158 /* Test that the local name is properly set */
159 static void test_GetLocalName(void)
161 HRESULT hres;
162 LPWSTR name;
164 hres = IBackgroundCopyFile_GetLocalName(test_file, &name);
165 ok(hres == S_OK, "GetLocalName failed: %08x\n", hres);
166 ok(lstrcmpW(name, test_localFile) == 0, "Got incorrect local name\n");
167 CoTaskMemFree(name);
170 /* Test getting the progress of a file*/
171 static void test_GetProgress_PreTransfer(void)
173 HRESULT hres;
174 BG_FILE_PROGRESS progress;
176 hres = IBackgroundCopyFile_GetProgress(test_file, &progress);
177 ok(hres == S_OK, "GetProgress failed: %08x\n", hres);
178 ok(progress.BytesTotal == BG_SIZE_UNKNOWN, "Got incorrect total size: %x%08x\n",
179 (DWORD)(progress.BytesTotal >> 32), (DWORD)progress.BytesTotal);
180 ok(progress.BytesTransferred == 0, "Got incorrect number of transferred bytes: %x%08x\n",
181 (DWORD)(progress.BytesTransferred >> 32), (DWORD)progress.BytesTransferred);
182 ok(progress.Completed == FALSE, "Got incorrect completion status\n");
185 typedef void (*test_t)(void);
187 START_TEST(file)
189 static const test_t tests[] = {
190 test_GetRemoteName,
191 test_GetLocalName,
192 test_GetProgress_PreTransfer,
195 const test_t *test;
196 int i;
198 CoInitialize(NULL);
200 if (FAILED(test_create_manager()))
202 CoUninitialize();
203 win_skip("Failed to create Manager instance, skipping tests\n");
204 return;
207 for (test = tests, i = 0; *test; ++test, ++i)
209 /* Keep state separate between tests. */
210 if (!setup())
212 ok(0, "tests:%d: Unable to setup test\n", i);
213 break;
215 (*test)();
216 teardown();
218 CoUninitialize();