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);
41 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
43 skip("Unable to create bits instance.\n");
47 /* Releasing bits manager */
48 res = IBackgroundCopyManager_Release(manager);
49 ok(res == 0, "Bad ref count on release: %u\n", res);
53 static void test_CreateJob(void)
56 static const WCHAR copyNameW[] = {'T', 'e', 's', 't', 0};
57 IBackgroundCopyJob* job = NULL;
61 IBackgroundCopyManager* manager = NULL;
64 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
65 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
69 skip("Unable to create bits instance required for test.\n");
74 hres = IBackgroundCopyManager_CreateJob(manager, copyNameW,
75 BG_JOB_TYPE_DOWNLOAD, &tmpId,
77 ok(hres == S_OK, "CreateJob failed: %08x\n", hres);
79 skip("Unable to create bits job.\n");
82 res = IBackgroundCopyJob_Release(job);
83 ok(res == 0, "Bad ref count on release: %u\n", res);
86 IBackgroundCopyManager_Release(manager);
89 static void test_EnumJobs(void)
92 IEnumBackgroundCopyJobs* enumJobs;
94 static const WCHAR copyNameW[] = {'T', 'e', 's', 't', 0};
95 IBackgroundCopyManager *manager = NULL;
96 IBackgroundCopyJob *job = NULL;
102 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
103 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
107 skip("Unable to create bits instance required for test.\n");
110 hres = IBackgroundCopyManager_CreateJob(manager, copyNameW,
111 BG_JOB_TYPE_DOWNLOAD, &tmpId,
115 skip("Unable to create bits job.\n");
116 IBackgroundCopyManager_Release(manager);
120 hres = IBackgroundCopyManager_EnumJobs(manager, 0, &enumJobs);
121 ok(hres == S_OK, "EnumJobs failed: %08x\n", hres);
123 skip("Unable to create job enumerator.\n");
126 res = IEnumBackgroundCopyJobs_Release(enumJobs);
127 ok(res == 0, "Bad ref count on release: %u\n", res);
131 IBackgroundCopyJob_Release(job);
132 IBackgroundCopyManager_Release(manager);
135 static void run_child(WCHAR *secret)
137 static const WCHAR format[] = {'%','s',' ','q','m','g','r',' ','%','s', 0};
138 WCHAR cmdline[MAX_PATH];
139 PROCESS_INFORMATION info;
140 STARTUPINFOW startup;
142 memset(&startup, 0, sizeof startup);
143 startup.cb = sizeof startup;
145 wsprintfW(cmdline, format, progname, secret);
146 ok(CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
147 winetest_wait_child_process(info.hProcess);
148 ok(CloseHandle(info.hProcess), "CloseHandle\n");
149 ok(CloseHandle(info.hThread), "CloseHandle\n");
152 static void do_child(const char *secretA)
154 WCHAR secretW[MAX_PATH];
155 IBackgroundCopyManager *manager = NULL;
157 IBackgroundCopyJob *job;
159 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
160 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
164 skip("Unable to create bits instance required for test.\n");
168 MultiByteToWideChar(CP_ACP, 0, secretA, -1, secretW, MAX_PATH);
169 hres = IBackgroundCopyManager_CreateJob(manager, secretW,
170 BG_JOB_TYPE_DOWNLOAD, &id, &job);
171 ok(hres == S_OK, "CreateJob in child process\n");
172 IBackgroundCopyJob_Release(job);
173 IBackgroundCopyManager_Release(manager);
176 static void test_globalness(void)
178 static const WCHAR format[] = {'t','e','s','t','_','%','u', 0};
179 WCHAR secretName[MAX_PATH];
180 IEnumBackgroundCopyJobs* enumJobs;
181 IBackgroundCopyManager *manager = NULL;
183 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
184 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
188 skip("Unable to create bits instance required for test.\n");
192 wsprintfW(secretName, format, GetTickCount());
193 run_child(secretName);
195 hres = IBackgroundCopyManager_EnumJobs(manager, 0, &enumJobs);
196 ok(hres == S_OK, "EnumJobs failed: %08x\n", hres);
198 skip("Unable to create job enumerator.\n");
202 IBackgroundCopyJob *job;
205 hres = IEnumBackgroundCopyJobs_GetCount(enumJobs, &n);
206 for (i = 0; i < n && !found; ++i)
209 IEnumBackgroundCopyJobs_Next(enumJobs, 1, &job, NULL);
210 IBackgroundCopyJob_GetDisplayName(job, &name);
211 if (lstrcmpW(name, secretName) == 0)
214 IBackgroundCopyJob_Release(job);
216 hres = IEnumBackgroundCopyJobs_Release(enumJobs);
217 ok(found, "Adding a job in another process failed\n");
220 IBackgroundCopyManager_Release(manager);
226 int argc = winetest_get_mainargs(&argv);
227 MultiByteToWideChar(CP_ACP, 0, argv[0], -1, progname, MAX_PATH);
234 test_CreateInstance();