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"
28 static WCHAR progname
[MAX_PATH
];
30 static HRESULT
test_create_manager(void)
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");
45 IBackgroundCopyManager_Release(manager
);
50 static void test_CreateJob(void)
53 static const WCHAR copyNameW
[] = {'T', 'e', 's', 't', 0};
54 IBackgroundCopyJob
* job
= NULL
;
58 IBackgroundCopyManager
* manager
= NULL
;
61 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
62 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
64 ok(hres
== S_OK
, "got 0x%08x\n", hres
);
67 hres
= IBackgroundCopyManager_CreateJob(manager
, copyNameW
,
68 BG_JOB_TYPE_DOWNLOAD
, &tmpId
,
70 ok(hres
== S_OK
, "CreateJob failed: %08x\n", hres
);
72 res
= IBackgroundCopyJob_Release(job
);
73 ok(res
== 0, "Bad ref count on release: %u\n", res
);
74 IBackgroundCopyManager_Release(manager
);
77 static void test_EnumJobs(void)
80 IEnumBackgroundCopyJobs
* enumJobs
;
82 static const WCHAR copyNameW
[] = {'T', 'e', 's', 't', 0};
83 IBackgroundCopyManager
*manager
= NULL
;
84 IBackgroundCopyJob
*job
= NULL
;
89 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
90 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
92 ok(hres
== S_OK
, "got 0x%08x\n", hres
);
94 hres
= IBackgroundCopyManager_CreateJob(manager
, copyNameW
,
95 BG_JOB_TYPE_DOWNLOAD
, &tmpId
,
97 ok(hres
== S_OK
, "got 0x%08x\n", hres
);
99 hres
= IBackgroundCopyManager_EnumJobs(manager
, 0, &enumJobs
);
100 ok(hres
== S_OK
, "EnumJobs failed: %08x\n", hres
);
101 IEnumBackgroundCopyJobs_Release(enumJobs
);
104 IBackgroundCopyJob_Release(job
);
105 IBackgroundCopyManager_Release(manager
);
108 static void run_child(WCHAR
*secret
)
110 static const WCHAR format
[] = {'%','s',' ','q','m','g','r',' ','%','s', 0};
111 WCHAR cmdline
[MAX_PATH
];
112 PROCESS_INFORMATION info
;
113 STARTUPINFOW startup
;
115 memset(&startup
, 0, sizeof startup
);
116 startup
.cb
= sizeof startup
;
118 wsprintfW(cmdline
, format
, progname
, secret
);
119 ok(CreateProcessW(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
120 winetest_wait_child_process(info
.hProcess
);
121 ok(CloseHandle(info
.hProcess
), "CloseHandle\n");
122 ok(CloseHandle(info
.hThread
), "CloseHandle\n");
125 static void do_child(const char *secretA
)
127 WCHAR secretW
[MAX_PATH
];
128 IBackgroundCopyManager
*manager
= NULL
;
130 IBackgroundCopyJob
*job
;
132 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
133 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
135 ok(hres
== S_OK
, "got 0x%08x\n", hres
);
137 MultiByteToWideChar(CP_ACP
, 0, secretA
, -1, secretW
, MAX_PATH
);
138 hres
= IBackgroundCopyManager_CreateJob(manager
, secretW
,
139 BG_JOB_TYPE_DOWNLOAD
, &id
, &job
);
140 ok(hres
== S_OK
, "CreateJob in child process\n");
141 IBackgroundCopyJob_Release(job
);
142 IBackgroundCopyManager_Release(manager
);
145 static void test_globalness(void)
147 static const WCHAR format
[] = {'t','e','s','t','_','%','u', 0};
148 WCHAR secretName
[MAX_PATH
];
149 IEnumBackgroundCopyJobs
* enumJobs
;
150 IBackgroundCopyManager
*manager
= NULL
;
152 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
153 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
155 ok(hres
== S_OK
, "got 0x%08x\n", hres
);
157 wsprintfW(secretName
, format
, GetTickCount());
158 run_child(secretName
);
160 hres
= IBackgroundCopyManager_EnumJobs(manager
, 0, &enumJobs
);
161 ok(hres
== S_OK
, "EnumJobs failed: %08x\n", hres
);
163 skip("Unable to create job enumerator.\n");
167 IBackgroundCopyJob
*job
;
170 hres
= IEnumBackgroundCopyJobs_GetCount(enumJobs
, &n
);
171 ok(hres
== S_OK
, "GetCount failed: %08x\n", hres
);
172 for (i
= 0; i
< n
&& !found
; ++i
)
175 IEnumBackgroundCopyJobs_Next(enumJobs
, 1, &job
, NULL
);
176 IBackgroundCopyJob_GetDisplayName(job
, &name
);
177 if (lstrcmpW(name
, secretName
) == 0)
180 IBackgroundCopyJob_Release(job
);
183 IEnumBackgroundCopyJobs_Release(enumJobs
);
184 ok(found
, "Adding a job in another process failed\n");
187 IBackgroundCopyManager_Release(manager
);
193 int argc
= winetest_get_mainargs(&argv
);
194 MultiByteToWideChar(CP_ACP
, 0, argv
[0], -1, progname
, MAX_PATH
);
198 if (FAILED(test_create_manager()))
200 win_skip("Failed to create Manager instance, skipping tests\n");