po: Remove duplicate spaces between sentences.
[wine/multimedia.git] / dlls / qmgr / tests / file.c
blob4afccfb74e9142c9375b8bfd8b5e8743765471a6
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);
58 return IBackgroundCopyJob_AddFile(test_job, test_remoteUrl, test_localFile);
61 /* Generic test setup */
62 static BOOL setup(void)
64 HRESULT hres;
65 GUID test_jobId;
67 test_manager = NULL;
68 test_job = NULL;
69 memset(&test_jobId, 0, sizeof test_jobId);
71 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
72 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
73 (void **) &test_manager);
74 if(hres != S_OK)
75 return FALSE;
77 hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayName,
78 BG_JOB_TYPE_DOWNLOAD, &test_jobId, &test_job);
79 if(hres != S_OK)
81 IBackgroundCopyManager_Release(test_manager);
82 return FALSE;
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);
90 return FALSE;
93 hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &test_file, NULL);
94 if(hres != S_OK)
96 IEnumBackgroundCopyFiles_Release(test_enumFiles);
97 IBackgroundCopyJob_Release(test_job);
98 IBackgroundCopyManager_Release(test_manager);
99 return FALSE;
102 return TRUE;
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)
117 HRESULT hres;
118 LPWSTR name;
120 hres = IBackgroundCopyFile_GetRemoteName(test_file, &name);
121 ok(hres == S_OK, "GetRemoteName failed: %08x\n", hres);
122 if(hres != S_OK)
124 skip("Unable to get remote name of test_file.\n");
125 return;
127 ok(lstrcmpW(name, test_remoteUrl) == 0, "Got incorrect remote name\n");
128 CoTaskMemFree(name);
131 /* Test that the local name is properly set */
132 static void test_GetLocalName(void)
134 HRESULT hres;
135 LPWSTR name;
137 hres = IBackgroundCopyFile_GetLocalName(test_file, &name);
138 ok(hres == S_OK, "GetLocalName failed: %08x\n", hres);
139 if(hres != S_OK)
141 skip("Unable to get local name of test_file.\n");
142 return;
144 ok(lstrcmpW(name, test_localFile) == 0, "Got incorrect local name\n");
145 CoTaskMemFree(name);
148 /* Test getting the progress of a file*/
149 static void test_GetProgress_PreTransfer(void)
151 HRESULT hres;
152 BG_FILE_PROGRESS progress;
154 hres = IBackgroundCopyFile_GetProgress(test_file, &progress);
155 ok(hres == S_OK, "GetProgress failed: %08x\n", hres);
156 if(hres != S_OK)
158 skip("Unable to get progress of test_file.\n");
159 return;
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 incorrect completion status\n");
168 typedef void (*test_t)(void);
170 START_TEST(file)
172 static const test_t tests[] = {
173 test_GetRemoteName,
174 test_GetLocalName,
175 test_GetProgress_PreTransfer,
178 const test_t *test;
180 CoInitialize(NULL);
181 for (test = tests; *test; ++test)
183 /* Keep state separate between tests. */
184 if (!setup())
186 skip("Unable to setup test\n");
187 break;
189 (*test)();
190 teardown();
192 CoUninitialize();