qmgr: Implement IBackgroundCopyJob_AddFile.
[wine.git] / dlls / qmgr / tests / job.c
blob7aec1a70191b6bcb8220b04e880da2777cd0d208
1 /*
2 * Unit test suite for Background Copy Job 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 #define COBJMACROS
25 #include "wine/test.h"
26 #include "bits.h"
28 /* Globals used by many tests */
29 static const WCHAR test_displayName[] = {'T', 'e', 's', 't', 0};
30 static const WCHAR test_remoteNameA[] = {'r','e','m','o','t','e','A', 0};
31 static const WCHAR test_remoteNameB[] = {'r','e','m','o','t','e','B', 0};
32 static const WCHAR test_localNameA[] = {'l','o','c','a','l','A', 0};
33 static const WCHAR test_localNameB[] = {'l','o','c','a','l','B', 0};
34 static WCHAR *test_currentDir;
35 static WCHAR *test_remotePathA;
36 static WCHAR *test_remotePathB;
37 static WCHAR *test_localPathA;
38 static WCHAR *test_localPathB;
39 static IBackgroundCopyManager *test_manager;
40 static IBackgroundCopyJob *test_job;
41 static GUID test_jobId;
42 static BG_JOB_TYPE test_type;
44 static BOOL init_paths(void)
46 static const WCHAR format[] = {'%','s','\\','%','s', 0};
47 DWORD n;
49 n = GetCurrentDirectoryW(0, NULL);
50 if (n == 0)
52 skip("Couldn't get current directory size\n");
53 return FALSE;
56 test_currentDir = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR));
57 test_localPathA
58 = HeapAlloc(GetProcessHeap(), 0,
59 (n + 1 + lstrlenW(test_localNameA)) * sizeof(WCHAR));
60 test_localPathB
61 = HeapAlloc(GetProcessHeap(), 0,
62 (n + 1 + lstrlenW(test_localNameB)) * sizeof(WCHAR));
63 test_remotePathA
64 = HeapAlloc(GetProcessHeap(), 0,
65 (n + 1 + lstrlenW(test_remoteNameA)) * sizeof(WCHAR));
66 test_remotePathB
67 = HeapAlloc(GetProcessHeap(), 0,
68 (n + 1 + lstrlenW(test_remoteNameB)) * sizeof(WCHAR));
70 if (!test_currentDir || !test_localPathA || !test_localPathB
71 || !test_remotePathA || !test_remotePathB)
73 skip("Couldn't allocate memory for full paths\n");
74 return FALSE;
77 if (GetCurrentDirectoryW(n, test_currentDir) != n - 1)
79 skip("Couldn't get current directory\n");
80 return FALSE;
83 wsprintfW(test_localPathA, format, test_currentDir, test_localNameA);
84 wsprintfW(test_localPathB, format, test_currentDir, test_localNameB);
85 wsprintfW(test_remotePathA, format, test_currentDir, test_remoteNameA);
86 wsprintfW(test_remotePathB, format, test_currentDir, test_remoteNameB);
88 return TRUE;
91 /* Generic test setup */
92 static BOOL setup(void)
94 HRESULT hres;
96 test_manager = NULL;
97 test_job = NULL;
98 memset(&test_jobId, 0, sizeof test_jobId);
99 test_type = BG_JOB_TYPE_DOWNLOAD;
101 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
102 CLSCTX_LOCAL_SERVER,
103 &IID_IBackgroundCopyManager,
104 (void **) &test_manager);
105 if(hres != S_OK)
106 return FALSE;
108 hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayName,
109 test_type, &test_jobId, &test_job);
110 if(hres != S_OK)
112 IBackgroundCopyManager_Release(test_manager);
113 return FALSE;
116 return TRUE;
119 /* Generic test cleanup */
120 static void teardown(void)
122 IBackgroundCopyJob_Release(test_job);
123 IBackgroundCopyManager_Release(test_manager);
126 /* Test that the jobId is properly set */
127 static void test_GetId(void)
129 HRESULT hres;
130 GUID tmpId;
132 hres = IBackgroundCopyJob_GetId(test_job, &tmpId);
133 ok(hres == S_OK, "GetId failed: %08x\n", hres);
134 if(hres != S_OK)
136 skip("Unable to get ID of test_job.\n");
137 return;
139 ok(memcmp(&tmpId, &test_jobId, sizeof tmpId) == 0, "Got incorrect GUID\n");
142 /* Test that the type is properly set */
143 static void test_GetType(void)
145 HRESULT hres;
146 BG_JOB_TYPE type;
148 hres = IBackgroundCopyJob_GetType(test_job, &type);
149 ok(hres == S_OK, "GetType failed: %08x\n", hres);
150 if(hres != S_OK)
152 skip("Unable to get type of test_job.\n");
153 return;
155 ok(type == test_type, "Got incorrect type\n");
158 /* Test that the display name is properly set */
159 static void test_GetName(void)
161 HRESULT hres;
162 LPWSTR displayName;
164 hres = IBackgroundCopyJob_GetDisplayName(test_job, &displayName);
165 ok(hres == S_OK, "GetName failed: %08x\n", hres);
166 if(hres != S_OK)
168 skip("Unable to get display name of test_job.\n");
169 return;
171 ok(lstrcmpW(displayName, test_displayName) == 0, "Got incorrect type\n");
172 CoTaskMemFree(displayName);
175 /* Test adding a file */
176 static void test_AddFile(void)
178 HRESULT hres;
180 hres = IBackgroundCopyJob_AddFile(test_job, test_remotePathA,
181 test_localPathA);
182 ok(hres == S_OK, "First call to AddFile failed: 0x%08x\n", hres);
183 if (hres != S_OK)
185 skip("Unable to add first file to job\n");
186 return;
189 hres = IBackgroundCopyJob_AddFile(test_job, test_remotePathB,
190 test_localPathB);
191 ok(hres == S_OK, "Second call to AddFile failed: 0x%08x\n", hres);
194 typedef void (*test_t)(void);
196 START_TEST(job)
198 static const test_t tests[] = {
199 test_GetId,
200 test_GetType,
201 test_GetName,
202 test_AddFile,
205 const test_t *test;
207 if (!init_paths())
208 return;
210 CoInitialize(NULL);
211 for (test = tests; *test; ++test)
213 /* Keep state seperate between tests. */
214 if (!setup())
216 skip("Unable to setup test\n");
217 break;
219 (*test)();
220 teardown();
222 CoUninitialize();