Release 1.6-rc2.
[wine/testsucceed.git] / dlls / qmgr / tests / qmgr.c
blob092d009d0b2cd8c801684b41d168f9c41b06ecf6
1 /*
2 * Unit test suite for bits functions
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 "initguid.h"
27 #include "bits.h"
29 static WCHAR progname[MAX_PATH];
31 static void
32 test_CreateInstance(void)
34 HRESULT hres;
35 ULONG res;
36 IBackgroundCopyManager *manager = NULL;
38 /* Creating BITS instance */
39 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, CLSCTX_LOCAL_SERVER,
40 &IID_IBackgroundCopyManager, (void **) &manager);
42 if(hres == __HRESULT_FROM_WIN32(ERROR_SERVICE_DISABLED)) {
43 skip("Needed Service is disabled\n");
44 return;
46 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
47 if(hres != S_OK) {
48 skip("Unable to create bits instance.\n");
49 return;
52 /* Releasing bits manager */
53 res = IBackgroundCopyManager_Release(manager);
54 ok(res == 0, "Bad ref count on release: %u\n", res);
58 static void test_CreateJob(void)
60 /* Job information */
61 static const WCHAR copyNameW[] = {'T', 'e', 's', 't', 0};
62 IBackgroundCopyJob* job = NULL;
63 GUID tmpId;
64 HRESULT hres;
65 ULONG res;
66 IBackgroundCopyManager* manager = NULL;
68 /* Setup */
69 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
70 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
71 (void **) &manager);
72 if(hres != S_OK)
74 skip("Unable to create bits instance required for test.\n");
75 return;
78 /* Create bits job */
79 hres = IBackgroundCopyManager_CreateJob(manager, copyNameW,
80 BG_JOB_TYPE_DOWNLOAD, &tmpId,
81 &job);
82 ok(hres == S_OK, "CreateJob failed: %08x\n", hres);
83 if(hres != S_OK)
84 skip("Unable to create bits job.\n");
85 else
87 res = IBackgroundCopyJob_Release(job);
88 ok(res == 0, "Bad ref count on release: %u\n", res);
91 IBackgroundCopyManager_Release(manager);
94 static void test_EnumJobs(void)
96 /* Job Enumerator */
97 IEnumBackgroundCopyJobs* enumJobs;
99 static const WCHAR copyNameW[] = {'T', 'e', 's', 't', 0};
100 IBackgroundCopyManager *manager = NULL;
101 IBackgroundCopyJob *job = NULL;
102 HRESULT hres;
103 GUID tmpId;
104 ULONG res;
106 /* Setup */
107 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
108 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
109 (void **) &manager);
110 if(hres != S_OK)
112 skip("Unable to create bits instance required for test.\n");
113 return;
115 hres = IBackgroundCopyManager_CreateJob(manager, copyNameW,
116 BG_JOB_TYPE_DOWNLOAD, &tmpId,
117 &job);
118 if(hres != S_OK)
120 skip("Unable to create bits job.\n");
121 IBackgroundCopyManager_Release(manager);
122 return;
125 hres = IBackgroundCopyManager_EnumJobs(manager, 0, &enumJobs);
126 ok(hres == S_OK, "EnumJobs failed: %08x\n", hres);
127 if(hres != S_OK)
128 skip("Unable to create job enumerator.\n");
129 else
131 res = IEnumBackgroundCopyJobs_Release(enumJobs);
132 ok(res == 0, "Bad ref count on release: %u\n", res);
135 /* Tear down */
136 IBackgroundCopyJob_Release(job);
137 IBackgroundCopyManager_Release(manager);
140 static void run_child(WCHAR *secret)
142 static const WCHAR format[] = {'%','s',' ','q','m','g','r',' ','%','s', 0};
143 WCHAR cmdline[MAX_PATH];
144 PROCESS_INFORMATION info;
145 STARTUPINFOW startup;
147 memset(&startup, 0, sizeof startup);
148 startup.cb = sizeof startup;
150 wsprintfW(cmdline, format, progname, secret);
151 ok(CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
152 winetest_wait_child_process(info.hProcess);
153 ok(CloseHandle(info.hProcess), "CloseHandle\n");
154 ok(CloseHandle(info.hThread), "CloseHandle\n");
157 static void do_child(const char *secretA)
159 WCHAR secretW[MAX_PATH];
160 IBackgroundCopyManager *manager = NULL;
161 GUID id;
162 IBackgroundCopyJob *job;
163 HRESULT hres;
164 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
165 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
166 (void **) &manager);
167 if(hres != S_OK)
169 skip("Unable to create bits instance required for test.\n");
170 return;
173 MultiByteToWideChar(CP_ACP, 0, secretA, -1, secretW, MAX_PATH);
174 hres = IBackgroundCopyManager_CreateJob(manager, secretW,
175 BG_JOB_TYPE_DOWNLOAD, &id, &job);
176 ok(hres == S_OK, "CreateJob in child process\n");
177 IBackgroundCopyJob_Release(job);
178 IBackgroundCopyManager_Release(manager);
181 static void test_globalness(void)
183 static const WCHAR format[] = {'t','e','s','t','_','%','u', 0};
184 WCHAR secretName[MAX_PATH];
185 IEnumBackgroundCopyJobs* enumJobs;
186 IBackgroundCopyManager *manager = NULL;
187 HRESULT hres;
188 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
189 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
190 (void **) &manager);
191 if(hres != S_OK)
193 skip("Unable to create bits instance required for test.\n");
194 return;
197 wsprintfW(secretName, format, GetTickCount());
198 run_child(secretName);
200 hres = IBackgroundCopyManager_EnumJobs(manager, 0, &enumJobs);
201 ok(hres == S_OK, "EnumJobs failed: %08x\n", hres);
202 if(hres != S_OK)
203 skip("Unable to create job enumerator.\n");
204 else
206 ULONG i, n;
207 IBackgroundCopyJob *job;
208 BOOL found = FALSE;
210 hres = IEnumBackgroundCopyJobs_GetCount(enumJobs, &n);
211 ok(hres == S_OK, "GetCount failed: %08x\n", hres);
212 for (i = 0; i < n && !found; ++i)
214 LPWSTR name;
215 IEnumBackgroundCopyJobs_Next(enumJobs, 1, &job, NULL);
216 IBackgroundCopyJob_GetDisplayName(job, &name);
217 if (lstrcmpW(name, secretName) == 0)
218 found = TRUE;
219 CoTaskMemFree(name);
220 IBackgroundCopyJob_Release(job);
222 hres = IEnumBackgroundCopyJobs_Release(enumJobs);
223 ok(hres == S_OK, "Release failed: %08x\n", hres);
224 ok(found, "Adding a job in another process failed\n");
227 IBackgroundCopyManager_Release(manager);
230 START_TEST(qmgr)
232 char **argv;
233 int argc = winetest_get_mainargs(&argv);
234 MultiByteToWideChar(CP_ACP, 0, argv[0], -1, progname, MAX_PATH);
236 CoInitialize(NULL);
237 if (argc == 3)
238 do_child(argv[2]);
239 else
241 test_CreateInstance();
242 test_CreateJob();
243 test_EnumJobs();
244 test_globalness();
246 CoUninitialize();