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
25 #include "wine/test.h"
29 static WCHAR progname[MAX_PATH];
32 test_CreateInstance(void)
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");
46 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
48 skip("Unable to create bits instance.\n");
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)
61 static const WCHAR copyNameW[] = {'T', 'e', 's', 't', 0};
62 IBackgroundCopyJob* job = NULL;
66 IBackgroundCopyManager* manager = NULL;
69 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
70 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
74 skip("Unable to create bits instance required for test.\n");
79 hres = IBackgroundCopyManager_CreateJob(manager, copyNameW,
80 BG_JOB_TYPE_DOWNLOAD, &tmpId,
82 ok(hres == S_OK, "CreateJob failed: %08x\n", hres);
84 skip("Unable to create bits job.\n");
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)
97 IEnumBackgroundCopyJobs* enumJobs;
99 static const WCHAR copyNameW[] = {'T', 'e', 's', 't', 0};
100 IBackgroundCopyManager *manager = NULL;
101 IBackgroundCopyJob *job = NULL;
107 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
108 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
112 skip("Unable to create bits instance required for test.\n");
115 hres = IBackgroundCopyManager_CreateJob(manager, copyNameW,
116 BG_JOB_TYPE_DOWNLOAD, &tmpId,
120 skip("Unable to create bits job.\n");
121 IBackgroundCopyManager_Release(manager);
125 hres = IBackgroundCopyManager_EnumJobs(manager, 0, &enumJobs);
126 ok(hres == S_OK, "EnumJobs failed: %08x\n", hres);
128 skip("Unable to create job enumerator.\n");
131 res = IEnumBackgroundCopyJobs_Release(enumJobs);
132 ok(res == 0, "Bad ref count on release: %u\n", res);
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;
162 IBackgroundCopyJob *job;
164 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
165 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
169 skip("Unable to create bits instance required for test.\n");
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;
188 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
189 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
193 skip("Unable to create bits instance required for test.\n");
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);
203 skip("Unable to create job enumerator.\n");
207 IBackgroundCopyJob *job;
210 hres = IEnumBackgroundCopyJobs_GetCount(enumJobs, &n);
211 ok(hres == S_OK, "GetCount failed: %08x\n", hres);
212 for (i = 0; i < n && !found; ++i)
215 IEnumBackgroundCopyJobs_Next(enumJobs, 1, &job, NULL);
216 IBackgroundCopyJob_GetDisplayName(job, &name);
217 if (lstrcmpW(name, secretName) == 0)
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);
233 int argc = winetest_get_mainargs(&argv);
234 MultiByteToWideChar(CP_ACP, 0, argv[0], -1, progname, MAX_PATH);
241 test_CreateInstance();