ReactOS 0.4.17-dev-970-gcf0f1a6
qmgr.c
Go to the documentation of this file.
1/*
2 * Unit test suite for bits functions
3 *
4 * Copyright 2007 Google (Roy Shea)
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <stdio.h>
22
23#define COBJMACROS
24
25#include "wine/test.h"
26#include "bits.h"
27
29
31{
34
35 /* Creating BITS instance */
36 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, CLSCTX_LOCAL_SERVER,
37 &IID_IBackgroundCopyManager, (void **) &manager);
38
40 win_skip("Needed Service is disabled\n");
41 return hres;
42 }
43
44 if (hres == S_OK)
45 IBackgroundCopyManager_Release(manager);
46
47 return hres;
48}
49
50static void test_CreateJob(void)
51{
52 /* Job information */
54 GUID tmpId;
56 ULONG res;
58
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);
64
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);
68
69 res = IBackgroundCopyJob_Release(job);
70 ok(res == 0, "Bad ref count on release: %lu\n", res);
71 IBackgroundCopyManager_Release(manager);
72}
73
74static void test_EnumJobs(void)
75{
76 /* Job Enumerator */
81 GUID tmpId;
82
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);
88
89 hres = IBackgroundCopyManager_CreateJob(manager, L"Test", BG_JOB_TYPE_DOWNLOAD, &tmpId, &job);
90 ok(hres == S_OK, "got 0x%08lx\n", hres);
91
92 hres = IBackgroundCopyManager_EnumJobs(manager, 0, &enumJobs);
93 ok(hres == S_OK, "EnumJobs failed: %08lx\n", hres);
94 IEnumBackgroundCopyJobs_Release(enumJobs);
95
96 /* Tear down */
97 IBackgroundCopyJob_Release(job);
98 IBackgroundCopyManager_Release(manager);
99}
100
101static void run_child(WCHAR *secret)
102{
106
107 memset(&startup, 0, sizeof startup);
108 startup.cb = sizeof startup;
109
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");
115}
116
117static void do_child(const char *secretA)
118{
119 WCHAR secretW[MAX_PATH];
120 IBackgroundCopyManager *manager = NULL;
121 GUID id;
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);
128
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);
135}
136
137static void test_globalness(void)
138{
139 WCHAR secretName[MAX_PATH];
140 IEnumBackgroundCopyJobs* enumJobs;
141 IBackgroundCopyManager *manager = NULL;
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);
147
148 wsprintfW(secretName, L"test_%u", GetTickCount());
149 run_child(secretName);
150
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
156 {
157 ULONG i, n;
159 BOOL found = FALSE;
160
161 hres = IEnumBackgroundCopyJobs_GetCount(enumJobs, &n);
162 ok(hres == S_OK, "GetCount failed: %08lx\n", hres);
163 for (i = 0; i < n && !found; ++i)
164 {
165 LPWSTR name;
166 IEnumBackgroundCopyJobs_Next(enumJobs, 1, &job, NULL);
167 IBackgroundCopyJob_GetDisplayName(job, &name);
168 if (lstrcmpW(name, secretName) == 0)
169 found = TRUE;
171 IBackgroundCopyJob_Release(job);
172 }
173
174 IEnumBackgroundCopyJobs_Release(enumJobs);
175 ok(found, "Adding a job in another process failed\n");
176 }
177
178 IBackgroundCopyManager_Release(manager);
179}
180
182{
183 char **argv;
186
188
190 {
191 win_skip("Failed to create Manager instance, skipping tests\n");
193 return;
194 }
195
196 if (argc == 3)
197 do_child(argv[2]);
198 else
199 {
203 }
205}
static void startup(void)
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
#define CloseHandle
Definition: compat.h:739
#define CP_ACP
Definition: compat.h:109
#define MAX_PATH
Definition: compat.h:34
#define MultiByteToWideChar
Definition: compat.h:110
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4491
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
ULONG WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
Definition: sync.c:182
MonoAssembly int argc
Definition: metahost.c:107
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble n
Definition: glext.h:7729
GLuint res
Definition: glext.h:9613
GLuint id
Definition: glext.h:5910
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define win_skip
Definition: minitest.h:67
HRESULT hres
Definition: protocol.c:432
static HANDLE job
Definition: process.c:79
static void test_CreateJob(void)
Definition: qmgr.c:50
static void test_globalness(void)
Definition: qmgr.c:137
static WCHAR progname[MAX_PATH]
Definition: qmgr.c:28
static void run_child(WCHAR *secret)
Definition: qmgr.c:101
static void test_EnumJobs(void)
Definition: qmgr.c:74
static HRESULT test_create_manager(void)
Definition: qmgr.c:30
static void do_child(void)
Definition: cursoricon.c:358
#define argv
Definition: mplay32.c:18
short WCHAR
Definition: pedump.c:58
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
int winetest_get_mainargs(char ***pargv)
#define wait_child_process
Definition: test.h:161
#define memset(x, y, z)
Definition: compat.h:39
TCHAR * cmdline
Definition: stretchblt.cpp:32
Definition: name.c:39
uint16_t * LPWSTR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_SERVICE_DISABLED
Definition: winerror.h:933