mshtml: Handle protocols with no ports when checking target origin.
[wine.git] / dlls / qmgr / tests / qmgr.c
blobf032f577781a6745ae5706da08f4844cfee401de
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 "bits.h"
28 static WCHAR progname[MAX_PATH];
30 static HRESULT test_create_manager(void)
32 HRESULT hres;
33 IBackgroundCopyManager *manager = NULL;
35 /* Creating BITS instance */
36 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, CLSCTX_LOCAL_SERVER,
37 &IID_IBackgroundCopyManager, (void **) &manager);
39 if(hres == HRESULT_FROM_WIN32(ERROR_SERVICE_DISABLED)) {
40 win_skip("Needed Service is disabled\n");
41 return hres;
44 if (hres == S_OK)
45 IBackgroundCopyManager_Release(manager);
47 return hres;
50 static void test_CreateJob(void)
52 /* Job information */
53 IBackgroundCopyJob* job = NULL;
54 GUID tmpId;
55 HRESULT hres;
56 ULONG res;
57 IBackgroundCopyManager* manager = NULL;
59 /* Setup */
60 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
61 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
62 (void **) &manager);
63 ok(hres == S_OK, "got 0x%08lx\n", hres);
65 /* Create bits job */
66 hres = IBackgroundCopyManager_CreateJob(manager, L"Test", BG_JOB_TYPE_DOWNLOAD, &tmpId, &job);
67 ok(hres == S_OK, "CreateJob failed: %08lx\n", hres);
69 res = IBackgroundCopyJob_Release(job);
70 ok(res == 0, "Bad ref count on release: %lu\n", res);
71 IBackgroundCopyManager_Release(manager);
74 static void test_EnumJobs(void)
76 /* Job Enumerator */
77 IEnumBackgroundCopyJobs* enumJobs;
78 IBackgroundCopyManager *manager = NULL;
79 IBackgroundCopyJob *job = NULL;
80 HRESULT hres;
81 GUID tmpId;
83 /* Setup */
84 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
85 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
86 (void **) &manager);
87 ok(hres == S_OK, "got 0x%08lx\n", hres);
89 hres = IBackgroundCopyManager_CreateJob(manager, L"Test", BG_JOB_TYPE_DOWNLOAD, &tmpId, &job);
90 ok(hres == S_OK, "got 0x%08lx\n", hres);
92 hres = IBackgroundCopyManager_EnumJobs(manager, 0, &enumJobs);
93 ok(hres == S_OK, "EnumJobs failed: %08lx\n", hres);
94 IEnumBackgroundCopyJobs_Release(enumJobs);
96 /* Tear down */
97 IBackgroundCopyJob_Release(job);
98 IBackgroundCopyManager_Release(manager);
101 static void run_child(WCHAR *secret)
103 WCHAR cmdline[MAX_PATH];
104 PROCESS_INFORMATION info;
105 STARTUPINFOW startup;
107 memset(&startup, 0, sizeof startup);
108 startup.cb = sizeof startup;
110 wsprintfW(cmdline, L"%s qmgr %s", progname, secret);
111 ok(CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
112 wait_child_process(info.hProcess);
113 ok(CloseHandle(info.hProcess), "CloseHandle\n");
114 ok(CloseHandle(info.hThread), "CloseHandle\n");
117 static void do_child(const char *secretA)
119 WCHAR secretW[MAX_PATH];
120 IBackgroundCopyManager *manager = NULL;
121 GUID id;
122 IBackgroundCopyJob *job;
123 HRESULT hres;
124 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
125 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
126 (void **) &manager);
127 ok(hres == S_OK, "got 0x%08lx\n", hres);
129 MultiByteToWideChar(CP_ACP, 0, secretA, -1, secretW, MAX_PATH);
130 hres = IBackgroundCopyManager_CreateJob(manager, secretW,
131 BG_JOB_TYPE_DOWNLOAD, &id, &job);
132 ok(hres == S_OK, "CreateJob in child process\n");
133 IBackgroundCopyJob_Release(job);
134 IBackgroundCopyManager_Release(manager);
137 static void test_globalness(void)
139 WCHAR secretName[MAX_PATH];
140 IEnumBackgroundCopyJobs* enumJobs;
141 IBackgroundCopyManager *manager = NULL;
142 HRESULT hres;
143 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
144 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
145 (void **) &manager);
146 ok(hres == S_OK, "got 0x%08lx\n", hres);
148 wsprintfW(secretName, L"test_%u", GetTickCount());
149 run_child(secretName);
151 hres = IBackgroundCopyManager_EnumJobs(manager, 0, &enumJobs);
152 ok(hres == S_OK, "EnumJobs failed: %08lx\n", hres);
153 if(hres != S_OK)
154 skip("Unable to create job enumerator.\n");
155 else
157 ULONG i, n;
158 IBackgroundCopyJob *job;
159 BOOL found = FALSE;
161 hres = IEnumBackgroundCopyJobs_GetCount(enumJobs, &n);
162 ok(hres == S_OK, "GetCount failed: %08lx\n", hres);
163 for (i = 0; i < n && !found; ++i)
165 LPWSTR name;
166 IEnumBackgroundCopyJobs_Next(enumJobs, 1, &job, NULL);
167 IBackgroundCopyJob_GetDisplayName(job, &name);
168 if (lstrcmpW(name, secretName) == 0)
169 found = TRUE;
170 CoTaskMemFree(name);
171 IBackgroundCopyJob_Release(job);
174 IEnumBackgroundCopyJobs_Release(enumJobs);
175 ok(found, "Adding a job in another process failed\n");
178 IBackgroundCopyManager_Release(manager);
181 START_TEST(qmgr)
183 char **argv;
184 int argc = winetest_get_mainargs(&argv);
185 MultiByteToWideChar(CP_ACP, 0, argv[0], -1, progname, MAX_PATH);
187 CoInitialize(NULL);
189 if (FAILED(test_create_manager()))
191 win_skip("Failed to create Manager instance, skipping tests\n");
192 CoUninitialize();
193 return;
196 if (argc == 3)
197 do_child(argv[2]);
198 else
200 test_CreateJob();
201 test_EnumJobs();
202 test_globalness();
204 CoUninitialize();