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 IBackgroundCopyJob
* job
= NULL
;
57 IBackgroundCopyManager
* manager
= NULL
;
60 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
61 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
63 ok(hres
== S_OK
, "got 0x%08lx\n", hres
);
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)
77 IEnumBackgroundCopyJobs
* enumJobs
;
78 IBackgroundCopyManager
*manager
= NULL
;
79 IBackgroundCopyJob
*job
= NULL
;
84 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
85 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
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
);
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
;
122 IBackgroundCopyJob
*job
;
124 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
125 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
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
;
143 hres
= CoCreateInstance(&CLSID_BackgroundCopyManager
, NULL
,
144 CLSCTX_LOCAL_SERVER
, &IID_IBackgroundCopyManager
,
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
);
154 skip("Unable to create job enumerator.\n");
158 IBackgroundCopyJob
*job
;
161 hres
= IEnumBackgroundCopyJobs_GetCount(enumJobs
, &n
);
162 ok(hres
== S_OK
, "GetCount failed: %08lx\n", hres
);
163 for (i
= 0; i
< n
&& !found
; ++i
)
166 IEnumBackgroundCopyJobs_Next(enumJobs
, 1, &job
, NULL
);
167 IBackgroundCopyJob_GetDisplayName(job
, &name
);
168 if (lstrcmpW(name
, secretName
) == 0)
171 IBackgroundCopyJob_Release(job
);
174 IEnumBackgroundCopyJobs_Release(enumJobs
);
175 ok(found
, "Adding a job in another process failed\n");
178 IBackgroundCopyManager_Release(manager
);
184 int argc
= winetest_get_mainargs(&argv
);
185 MultiByteToWideChar(CP_ACP
, 0, argv
[0], -1, progname
, MAX_PATH
);
189 if (FAILED(test_create_manager()))
191 win_skip("Failed to create Manager instance, skipping tests\n");