ReactOS 0.4.17-dev-966-gf06eace
job.c
Go to the documentation of this file.
1/*
2 * Unit test suite for Background Copy Job Interface
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#include "initguid.h"
28#include "bits2_0.h"
29#include "bits2_5.h"
30#include "bits5_0.h"
31
32/* Globals used by many tests */
40static BG_JOB_TYPE test_type;
41
46
48{
49 return CONTAINING_RECORD(iface, IBackgroundCopyCallback2Impl, IBackgroundCopyCallback2_iface);
50}
51
53{
55
56 if (!ppv)
57 {
58 return E_INVALIDARG;
59 }
60
61 *ppv = NULL;
62
64 IsEqualIID(riid, &IID_IBackgroundCopyCallback) ||
65 IsEqualIID(riid, &IID_IBackgroundCopyCallback2))
66 {
67 *ppv = &This->IBackgroundCopyCallback2_iface;
68 }
69 else
70 {
71 return E_NOINTERFACE;
72 }
73
74 IUnknown_AddRef((IUnknown*)*ppv);
75 return S_OK;
76}
77
79{
82
83 trace("IBackgroundCopyCallback2Impl_AddRef called (%p, ref = %ld)\n", This, ref);
84 return ref;
85}
86
88{
91
92 trace("IBackgroundCopyCallback2Impl_Release called (%p, ref = %ld)\n", This, ref);
93
94 if (ref == 0)
95 {
97 }
98
99 return ref;
100}
101
103{
104 trace("IBackgroundCopyCallback2Impl_JobError called (%p, %p, %p)\n", iface, pJob, pError);
105 return S_OK;
106}
107
109{
110 trace("IBackgroundCopyCallback2Impl_JobModification called (%p, %p)\n", iface, pJob);
111 return S_OK;
112}
113
115{
116 trace("IBackgroundCopyCallback2Impl_JobTransferred called (%p, %p)\n", iface, pJob);
117 return S_OK;
118}
119
121{
122 trace("IBackgroundCopyCallback2Impl_FileTransferred called (%p, %p, %p)\n", iface, pJob, pFile);
123 return S_OK;
124}
125
126
127static const IBackgroundCopyCallback2Vtbl copyCallback_vtbl =
128{
136};
137
139{
141 *copyCallback = NULL;
142
144
145 if (!obj)
146 {
147 trace("Out of memory creating IBackgroundCopyCallback2\n");
148 return FALSE;
149 }
150
151 obj->IBackgroundCopyCallback2_iface.lpVtbl = &copyCallback_vtbl;
152 obj->ref = 1;
153
154 *copyCallback = &obj->IBackgroundCopyCallback2_iface;
155
156 return TRUE;
157}
158
160{
162 IBackgroundCopyManager *manager = NULL;
163
164 /* Creating BITS instance */
165 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, CLSCTX_LOCAL_SERVER,
166 &IID_IBackgroundCopyManager, (void **) &manager);
167
169 win_skip("Needed Service is disabled\n");
170 return hres;
171 }
172
173 if (hres == S_OK)
174 IBackgroundCopyManager_Release(manager);
175
176 return hres;
177}
178
179static void init_paths(void)
180{
181 WCHAR tmpDir[MAX_PATH];
182 WCHAR prefix[] = L"qmgr";
183
184 GetTempPathW(MAX_PATH, tmpDir);
185
190}
191
192/* Generic test setup */
193static BOOL setup(void)
194{
196 IBackgroundCopyJob5* test_job_5;
197 BITS_JOB_PROPERTY_VALUE prop_val;
198
200 test_job = NULL;
201 memset(&test_jobId, 0, sizeof test_jobId);
202 test_type = BG_JOB_TYPE_DOWNLOAD;
203
204 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
205 CLSCTX_LOCAL_SERVER,
206 &IID_IBackgroundCopyManager,
207 (void **) &test_manager);
208 if(hres != S_OK)
209 return FALSE;
210
211 hres = IBackgroundCopyManager_CreateJob(test_manager, L"Test", test_type, &test_jobId, &test_job);
212 if(hres != S_OK)
213 {
214 IBackgroundCopyManager_Release(test_manager);
215 return FALSE;
216 }
217
218 /* The Wine TestBot Windows 10 VMs disable Windows Update by putting
219 the network connection in metered mode.
220
221 Unfortunately, this will make BITS jobs fail, since the default transfer policy
222 on Windows 10 prevents BITs job from running over a metered network
223
224 To allow these tests in this file to run on the testbot, we
225 set the BITS_JOB_PROPERTY_ID_COST_FLAGS property to BITS_COST_STATE_TRANSFER_ALWAYS,
226 ensuring that BITS will still try to run the job on a metered network */
227 prop_val.Dword = BITS_COST_STATE_TRANSFER_ALWAYS;
228 hres = IBackgroundCopyJob_QueryInterface(test_job, &IID_IBackgroundCopyJob5, (void **)&test_job_5);
229 /* BackgroundCopyJob5 was added in Windows 8, so this may not exist. The metered connection
230 workaround is only applied on Windows 10, so it's fine if this fails. */
231 if (SUCCEEDED(hres)) {
232 hres = IBackgroundCopyJob5_SetProperty(test_job_5, BITS_JOB_PROPERTY_ID_COST_FLAGS, prop_val);
233 ok(hres == S_OK, "Failed to set the cost flags: %08lx\n", hres);
234 IBackgroundCopyJob5_Release(test_job_5);
235 }
236
237 return TRUE;
238}
239
240/* Generic test cleanup */
241static void teardown(void)
242{
243 IBackgroundCopyJob_Cancel(test_job);
244 IBackgroundCopyJob_Release(test_job);
245 IBackgroundCopyManager_Release(test_manager);
246}
247
248static BOOL check_bits20(void)
249{
251 IBackgroundCopyManager *manager;
252 IBackgroundCopyJob *job, *job3;
253
254 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
255 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
256 (void **)&manager);
257 if (hres != S_OK) return FALSE;
258
259 hres = IBackgroundCopyManager_CreateJob(manager, L"Test", test_type, &test_jobId, &job);
260 if (hres != S_OK)
261 {
262 IBackgroundCopyManager_Release(manager);
263 return FALSE;
264 }
265
266 hres = IBackgroundCopyJob_QueryInterface(job, &IID_IBackgroundCopyJob3, (void **)&job3);
267 IBackgroundCopyJob_Cancel(job);
268 IBackgroundCopyJob_Release(job);
269 if (hres != S_OK)
270 {
271 IBackgroundCopyManager_Release(manager);
272 return FALSE;
273 }
274
275 IBackgroundCopyJob_Release(job3);
276 IBackgroundCopyManager_Release(manager);
277 return TRUE;
278}
279
280static BOOL check_bits25(void)
281{
283 IBackgroundCopyManager *manager;
286
287 hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
288 CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
289 (void **)&manager);
290 if (hres != S_OK) return FALSE;
291
292 hres = IBackgroundCopyManager_CreateJob(manager, L"Test", test_type, &test_jobId, &job);
293 if (hres != S_OK)
294 {
295 IBackgroundCopyManager_Release(manager);
296 return FALSE;
297 }
298
299 hres = IBackgroundCopyJob_QueryInterface(job, &IID_IBackgroundCopyJobHttpOptions, (void **)&options);
300 IBackgroundCopyJob_Cancel(job);
301 IBackgroundCopyJob_Release(job);
302 if (hres != S_OK)
303 {
304 IBackgroundCopyManager_Release(manager);
305 return FALSE;
306 }
307
308 IBackgroundCopyJobHttpOptions_Release(options);
309 IBackgroundCopyManager_Release(manager);
310 return TRUE;
311}
312
313/* Test that the jobId is properly set */
314static void test_GetId(void)
315{
317 GUID tmpId;
318
319 hres = IBackgroundCopyJob_GetId(test_job, &tmpId);
320 ok(hres == S_OK, "GetId failed: %08lx\n", hres);
321 ok(memcmp(&tmpId, &test_jobId, sizeof tmpId) == 0, "Got incorrect GUID\n");
322}
323
324/* Test that the type is properly set */
325static void test_GetType(void)
326{
328 BG_JOB_TYPE type;
329
330 hres = IBackgroundCopyJob_GetType(test_job, &type);
331 ok(hres == S_OK, "GetType failed: %08lx\n", hres);
332 ok(type == test_type, "Got incorrect type\n");
333}
334
335/* Test that the display name is properly set */
336static void test_GetName(void)
337{
340
341 hres = IBackgroundCopyJob_GetDisplayName(test_job, &displayName);
342 ok(hres == S_OK, "GetName failed: %08lx\n", hres);
343 ok(lstrcmpW(displayName, L"Test") == 0, "Got incorrect type\n");
345}
346
347/* Test adding a file */
348static void test_AddFile(void)
349{
351
352 hres = IBackgroundCopyJob_AddFile(test_job, test_remotePathA,
354 ok(hres == S_OK, "First call to AddFile failed: 0x%08lx\n", hres);
355
356 hres = IBackgroundCopyJob_AddFile(test_job, test_remotePathB,
358 ok(hres == S_OK, "Second call to AddFile failed: 0x%08lx\n", hres);
359}
360
361/* Test adding a set of files */
362static void test_AddFileSet(void)
363{
365 BG_FILE_INFO files[2] =
366 {
369 };
370 hres = IBackgroundCopyJob_AddFileSet(test_job, 2, files);
371 ok(hres == S_OK, "AddFileSet failed: 0x%08lx\n", hres);
372}
373
374/* Test creation of a job enumerator */
375static void test_EnumFiles(void)
376{
378 IEnumBackgroundCopyFiles *enumFiles;
379 ULONG res;
380
381 hres = IBackgroundCopyJob_AddFile(test_job, test_remotePathA,
383 ok(hres == S_OK, "got 0x%08lx\n", hres);
384
385 hres = IBackgroundCopyJob_EnumFiles(test_job, &enumFiles);
386 ok(hres == S_OK, "EnumFiles failed: 0x%08lx\n", hres);
387
388 res = IEnumBackgroundCopyFiles_Release(enumFiles);
389 ok(res == 0, "Bad ref count on release: %lu\n", res);
390}
391
392/* Test getting job progress */
394{
396 BG_JOB_PROGRESS progress;
397
398 hres = IBackgroundCopyJob_GetProgress(test_job, &progress);
399 ok(hres == S_OK, "GetProgress failed: 0x%08lx\n", hres);
400
401 ok(progress.BytesTotal == 0, "Incorrect BytesTotal: %s\n",
402 wine_dbgstr_longlong(progress.BytesTotal));
403 ok(progress.BytesTransferred == 0, "Incorrect BytesTransferred: %s\n",
404 wine_dbgstr_longlong(progress.BytesTransferred));
405 ok(progress.FilesTotal == 0, "Incorrect FilesTotal: %lu\n", progress.FilesTotal);
406 ok(progress.FilesTransferred == 0, "Incorrect FilesTransferred %lu\n", progress.FilesTransferred);
407}
408
409/* Test getting job state */
410static void test_GetState(void)
411{
413 BG_JOB_STATE state;
414
415 state = BG_JOB_STATE_ERROR;
416 hres = IBackgroundCopyJob_GetState(test_job, &state);
417 ok(hres == S_OK, "GetState failed: 0x%08lx\n", hres);
418 ok(state == BG_JOB_STATE_SUSPENDED, "Incorrect job state: %d\n", state);
419}
420
421/* Test resuming a job */
422static void test_ResumeEmpty(void)
423{
425 BG_JOB_STATE state;
426
427 hres = IBackgroundCopyJob_Resume(test_job);
428 ok(hres == BG_E_EMPTY, "Resume failed to return BG_E_EMPTY error: 0x%08lx\n", hres);
429
430 state = BG_JOB_STATE_ERROR;
431 hres = IBackgroundCopyJob_GetState(test_job, &state);
432 ok(hres == S_OK, "got 0x%08lx\n", hres);
433 ok(state == BG_JOB_STATE_SUSPENDED, "Incorrect job state: %d\n", state);
434}
435
436static void makeFile(WCHAR *name, const char *contents)
437{
438 HANDLE file;
440
444 ok(file != INVALID_HANDLE_VALUE, "CreateFile\n");
445 ok(WriteFile(file, contents, len, &w, NULL), "WriteFile\n");
447}
448
449static void compareFiles(WCHAR *n1, WCHAR *n2)
450{
451 char b1[256];
452 char b2[256];
453 DWORD s1, s2;
454 HANDLE f1, f2;
455
458 ok(f1 != INVALID_HANDLE_VALUE, "CreateFile\n");
459
462 ok(f2 != INVALID_HANDLE_VALUE, "CreateFile\n");
463
464 /* Neither of these files is very big */
465 ok(ReadFile(f1, b1, sizeof b1, &s1, NULL), "ReadFile\n");
466 ok(ReadFile(f2, b2, sizeof b2, &s2, NULL), "ReadFile\n");
467
470
471 ok(s1 == s2, "Files differ in length\n");
472 ok(memcmp(b1, b2, s1) == 0, "Files differ in contents\n");
473}
474
475/* Handles a timeout in the BG_JOB_STATE_ERROR or BG_JOB_STATE_TRANSIENT_ERROR state */
476static void handle_job_err(void)
477{
480 BG_ERROR_CONTEXT errContext;
481 HRESULT errCode;
482 LPWSTR contextDesc;
483 LPWSTR errDesc;
484
485 hres = IBackgroundCopyJob_GetError(test_job, &err);
486 if (SUCCEEDED(hres)) {
487 hres = IBackgroundCopyError_GetError(err, &errContext, &errCode);
488 if (SUCCEEDED(hres)) {
489 ok(0, "Got context: %d code: %ld\n", errContext, errCode);
490 } else {
491 ok(0, "Failed to get error info: 0x%08lx\n", hres);
492 }
493
494 hres = IBackgroundCopyError_GetErrorContextDescription(err, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), &contextDesc);
495 if (SUCCEEDED(hres)) {
496 ok(0, "Got context desc: %s\n", wine_dbgstr_w(contextDesc));
497 } else {
498 ok(0, "Failed to get context desc: 0x%08lx\n", hres);
499 }
500
501 hres = IBackgroundCopyError_GetErrorDescription(err, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), &errDesc);
502 if (SUCCEEDED(hres)) {
503 ok(0, "Got error desc: %s\n", wine_dbgstr_w(errDesc));
504 } else {
505 ok(0, "Failed to get error desc: 0x%08lx\n", hres);
506 }
507 } else {
508 ok(0, "Failed to get error: 0x%08lx\n", hres);
509 }
510}
511
512/* Test a complete transfer for local files */
513static void test_CompleteLocal(void)
514{
515 static const int timeout_sec = 30;
517 BG_JOB_STATE state;
518 int i;
519
522 makeFile(test_remotePathA, "This is a WINE test file for BITS\n");
523 makeFile(test_remotePathB, "This is another WINE test file for BITS\n");
524
525 hres = IBackgroundCopyJob_AddFile(test_job, test_remotePathA,
527 ok(hres == S_OK, "got 0x%08lx\n", hres);
528
529 hres = IBackgroundCopyJob_AddFile(test_job, test_remotePathB,
531 ok(hres == S_OK, "got 0x%08lx\n", hres);
532
533 hres = IBackgroundCopyJob_Resume(test_job);
534 ok(hres == S_OK, "IBackgroundCopyJob_Resume\n");
535
536 for (i = 0; i < timeout_sec; ++i)
537 {
538 hres = IBackgroundCopyJob_GetState(test_job, &state);
539 ok(hres == S_OK, "IBackgroundCopyJob_GetState\n");
540 ok(state == BG_JOB_STATE_QUEUED || state == BG_JOB_STATE_CONNECTING
541 || state == BG_JOB_STATE_TRANSFERRING || state == BG_JOB_STATE_TRANSFERRED
542 || state == BG_JOB_STATE_TRANSIENT_ERROR,
543 "Bad state: %d\n", state);
544
545 if (state == BG_JOB_STATE_TRANSIENT_ERROR) {
546 hres = IBackgroundCopyJob_Resume(test_job);
547 ok(hres == S_OK, "IBackgroundCopyJob_Resume\n");
548 }
549
550 if (state == BG_JOB_STATE_TRANSFERRED)
551 break;
552 Sleep(1000);
553 }
554
555 if (state == BG_JOB_STATE_ERROR || state == BG_JOB_STATE_TRANSIENT_ERROR)
557
558 ok(i < timeout_sec, "BITS jobs timed out\n");
559 hres = IBackgroundCopyJob_Complete(test_job);
560 ok(hres == S_OK, "IBackgroundCopyJob_Complete\n");
561 hres = IBackgroundCopyJob_GetState(test_job, &state);
562 ok(hres == S_OK, "IBackgroundCopyJob_GetState\n");
563 ok(state == BG_JOB_STATE_ACKNOWLEDGED, "Bad state: %d\n", state);
564
567
568 ok(DeleteFileW(test_remotePathA), "DeleteFile\n");
569 ok(DeleteFileW(test_remotePathB), "DeleteFile\n");
572}
573
574/* Test a complete transfer for local files */
575static void test_CompleteLocalURL(void)
576{
577 static const int timeout_sec = 30;
578 WCHAR *urlA, *urlB;
580 BG_JOB_STATE state;
581 int i;
582
585 makeFile(test_remotePathA, "This is a WINE test file for BITS\n");
586 makeFile(test_remotePathB, "This is another WINE test file for BITS\n");
587
588 urlA = HeapAlloc(GetProcessHeap(), 0,
589 (7 + lstrlenW(test_remotePathA) + 1) * sizeof urlA[0]);
590 urlB = HeapAlloc(GetProcessHeap(), 0,
591 (7 + lstrlenW(test_remotePathB) + 1) * sizeof urlB[0]);
592 if (!urlA || !urlB)
593 {
594 skip("Unable to allocate memory for URLs\n");
595 HeapFree(GetProcessHeap(), 0, urlA);
596 HeapFree(GetProcessHeap(), 0, urlB);
597 return;
598 }
599
600 lstrcpyW(urlA, L"file://");
602 lstrcpyW(urlB, L"file://");
604
605 hres = IBackgroundCopyJob_AddFile(test_job, urlA, test_localPathA);
606 ok(hres == S_OK, "got 0x%08lx\n", hres);
607
608 hres = IBackgroundCopyJob_AddFile(test_job, urlB, test_localPathB);
609 ok(hres == S_OK, "got 0x%08lx\n", hres);
610
611 hres = IBackgroundCopyJob_Resume(test_job);
612 ok(hres == S_OK, "IBackgroundCopyJob_Resume\n");
613
614 for (i = 0; i < timeout_sec; ++i)
615 {
616 hres = IBackgroundCopyJob_GetState(test_job, &state);
617 ok(hres == S_OK, "IBackgroundCopyJob_GetState\n");
618 ok(state == BG_JOB_STATE_QUEUED || state == BG_JOB_STATE_CONNECTING
619 || state == BG_JOB_STATE_TRANSFERRING || state == BG_JOB_STATE_TRANSFERRED
620 || state == BG_JOB_STATE_TRANSIENT_ERROR,
621 "Bad state: %d\n", state);
622
623 if (state == BG_JOB_STATE_TRANSIENT_ERROR) {
624 hres = IBackgroundCopyJob_Resume(test_job);
625 ok(hres == S_OK, "IBackgroundCopyJob_Resume\n");
626 }
627
628 if (state == BG_JOB_STATE_TRANSFERRED)
629 break;
630 Sleep(1000);
631 }
632
633 if (state == BG_JOB_STATE_ERROR || state == BG_JOB_STATE_TRANSIENT_ERROR)
635
636
637 ok(i < timeout_sec, "BITS jobs timed out\n");
638 hres = IBackgroundCopyJob_Complete(test_job);
639 ok(hres == S_OK, "IBackgroundCopyJob_Complete\n");
640 hres = IBackgroundCopyJob_GetState(test_job, &state);
641 ok(hres == S_OK, "IBackgroundCopyJob_GetState\n");
642 ok(state == BG_JOB_STATE_ACKNOWLEDGED, "Bad state: %d\n", state);
643
646
647 ok(DeleteFileW(test_remotePathA), "DeleteFile\n");
648 ok(DeleteFileW(test_remotePathB), "DeleteFile\n");
651
652 HeapFree(GetProcessHeap(), 0, urlA);
653 HeapFree(GetProcessHeap(), 0, urlB);
654}
655
656static void test_NotifyFlags(void)
657{
658 ULONG flags;
659 HRESULT hr;
660
661 /* check default flags */
662 flags = 0;
663 hr = IBackgroundCopyJob_GetNotifyFlags(test_job, &flags);
664 ok(hr == S_OK, "got 0x%08lx\n", hr);
665 ok(flags == (BG_NOTIFY_JOB_ERROR | BG_NOTIFY_JOB_TRANSFERRED), "flags 0x%08lx\n", flags);
666}
667
668static void test_NotifyInterface(void)
669{
670 HRESULT hr;
671 IUnknown *unk;
672
673 unk = (IUnknown*)0xdeadbeef;
674 hr = IBackgroundCopyJob_GetNotifyInterface(test_job, &unk);
675 ok(hr == S_OK, "got 0x%08lx\n", hr);
676 ok(unk == NULL, "got %p\n", unk);
677}
678
679static void test_Cancel(void)
680{
681 HRESULT hr;
682 BG_JOB_STATE state;
683
684 state = BG_JOB_STATE_ERROR;
685 hr = IBackgroundCopyJob_GetState(test_job, &state);
686 ok(hr == S_OK, "got 0x%08lx\n", hr);
687 ok(state != BG_JOB_STATE_CANCELLED, "got %u\n", state);
688
689 hr = IBackgroundCopyJob_Cancel(test_job);
690 ok(hr == S_OK, "got 0x%08lx\n", hr);
691
692 state = BG_JOB_STATE_ERROR;
693 hr = IBackgroundCopyJob_GetState(test_job, &state);
694 ok(hr == S_OK, "got 0x%08lx\n", hr);
695 ok(state == BG_JOB_STATE_CANCELLED, "got %u\n", state);
696
697 hr = IBackgroundCopyJob_Cancel(test_job);
698 ok(hr == BG_E_INVALID_STATE, "got 0x%08lx\n", hr);
699}
700
701static void test_HttpOptions(void)
702{
703 static const WCHAR winetestW[] = L"Wine: test\r\n";
704 static const unsigned int timeout = 30;
705 HRESULT hr;
708 BG_JOB_STATE state;
709 unsigned int i;
710 WCHAR *headers;
711 ULONG flags, orig_flags;
712 IBackgroundCopyCallback2 *copyCallback;
713 IUnknown *copyCallbackUnknown;
714
715 ok(create_background_copy_callback2(&copyCallback) == TRUE, "create_background_copy_callback2 failed\n");
716
717 hr = IBackgroundCopyCallback2_QueryInterface(copyCallback, &IID_IUnknown, (LPVOID*)&copyCallbackUnknown);
718 ok(hr == S_OK,"IBackgroundCopyCallback_QueryInterface(IID_IUnknown) failed: %08lx\n", hr);
719
720 hr = IBackgroundCopyJob_SetNotifyInterface(test_job, copyCallbackUnknown);
721 ok(hr == S_OK,"IBackgroundCopyCallback_SetNotifyInterface failed: %08lx\n", hr);
722
723 hr = IBackgroundCopyJob_SetNotifyFlags(test_job, BG_NOTIFY_JOB_TRANSFERRED | BG_NOTIFY_JOB_ERROR | BG_NOTIFY_DISABLE | BG_NOTIFY_JOB_MODIFICATION | BG_NOTIFY_FILE_TRANSFERRED);
724 ok(hr == S_OK,"IBackgroundCopyCallback_SetNotifyFlags failed: %08lx\n", hr);
725
726
728 hr = IBackgroundCopyJob_AddFile(test_job, L"http://test.winehq.org/", test_localPathA);
729 ok(hr == S_OK, "got 0x%08lx\n", hr);
730
731 hr = IBackgroundCopyJob_QueryInterface(test_job, &IID_IBackgroundCopyJobHttpOptions, (void **)&options);
732 ok(hr == S_OK, "got 0x%08lx\n", hr);
733
734 if (options)
735 {
736 headers = (WCHAR *)0xdeadbeef;
737 hr = IBackgroundCopyJobHttpOptions_GetCustomHeaders(options, &headers);
738 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
739 ok(headers == NULL, "got %p\n", headers);
740
741 hr = IBackgroundCopyJobHttpOptions_SetCustomHeaders(options, winetestW);
742 ok(hr == S_OK, "got 0x%08lx\n", hr);
743
744 headers = (WCHAR *)0xdeadbeef;
745 hr = IBackgroundCopyJobHttpOptions_GetCustomHeaders(options, &headers);
746 ok(hr == S_OK, "got 0x%08lx\n", hr);
747 if (hr == S_OK)
748 {
751 }
752
753 hr = IBackgroundCopyJobHttpOptions_SetCustomHeaders(options, NULL);
754 ok(hr == S_OK, "got 0x%08lx\n", hr);
755
756 headers = (WCHAR *)0xdeadbeef;
757 hr = IBackgroundCopyJobHttpOptions_GetCustomHeaders(options, &headers);
758 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
759 ok(headers == NULL, "got %p\n", headers);
760
761 orig_flags = 0xdeadbeef;
762 hr = IBackgroundCopyJobHttpOptions_GetSecurityFlags(options, &orig_flags);
763 ok(hr == S_OK, "got 0x%08lx\n", hr);
764 ok(!orig_flags, "got 0x%08lx\n", orig_flags);
765
766 hr = IBackgroundCopyJobHttpOptions_SetSecurityFlags(options, 0);
767 ok(hr == S_OK, "got 0x%08lx\n", hr);
768
769 flags = 0xdeadbeef;
770 hr = IBackgroundCopyJobHttpOptions_GetSecurityFlags(options, &flags);
771 ok(hr == S_OK, "got 0x%08lx\n", hr);
772 ok(!flags, "got 0x%08lx\n", flags);
773 }
774
775 hr = IBackgroundCopyJob_Resume(test_job);
776 ok(hr == S_OK, "got 0x%08lx\n", hr);
777
778 for (i = 0; i < timeout; i++)
779 {
780 hr = IBackgroundCopyJob_GetState(test_job, &state);
781 ok(hr == S_OK, "got 0x%08lx\n", hr);
782
783 ok(state == BG_JOB_STATE_QUEUED ||
784 state == BG_JOB_STATE_CONNECTING ||
785 state == BG_JOB_STATE_TRANSFERRING ||
786 state == BG_JOB_STATE_TRANSFERRED ||
787 state == BG_JOB_STATE_TRANSIENT_ERROR, "unexpected state: %u\n", state);
788
789 if (state == BG_JOB_STATE_TRANSIENT_ERROR) {
790 hr = IBackgroundCopyJob_Resume(test_job);
791 ok(hr == S_OK, "IBackgroundCopyJob_Resume\n");
792 }
793
794 if (state == BG_JOB_STATE_TRANSFERRED) break;
795 Sleep(1000);
796 }
797
798 if (state == BG_JOB_STATE_ERROR || state == BG_JOB_STATE_TRANSIENT_ERROR)
800
801
802 ok(i < timeout, "BITS job timed out\n");
803 if (i < timeout)
804 {
805 hr = IBackgroundCopyJob_GetError(test_job, &error);
806 ok(hr == BG_E_ERROR_INFORMATION_UNAVAILABLE, "got 0x%08lx\n", hr);
807 }
808
809 if (options)
810 {
811 headers = (WCHAR *)0xdeadbeef;
812 hr = IBackgroundCopyJobHttpOptions_GetCustomHeaders(options, &headers);
813 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
814 ok(headers == NULL, "got %p\n", headers);
815
816 hr = IBackgroundCopyJobHttpOptions_SetCustomHeaders(options, NULL);
817 ok(hr == S_OK, "got 0x%08lx\n", hr);
818
819 hr = IBackgroundCopyJobHttpOptions_GetCustomHeaders(options, &headers);
820 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
821
822 flags = 0xdeadbeef;
823 hr = IBackgroundCopyJobHttpOptions_GetSecurityFlags(options, &flags);
824 ok(hr == S_OK, "got 0x%08lx\n", hr);
825 ok(!flags, "got 0x%08lx\n", flags);
826
827 hr = IBackgroundCopyJobHttpOptions_SetSecurityFlags(options, orig_flags);
828 ok(hr == S_OK, "got 0x%08lx\n", hr);
829
830 IBackgroundCopyJobHttpOptions_Release(options);
831 }
832
833 hr = IBackgroundCopyJob_Complete(test_job);
834 ok(hr == S_OK, "got 0x%08lx\n", hr);
835
836 hr = IBackgroundCopyJob_GetState(test_job, &state);
837 ok(hr == S_OK, "got 0x%08lx\n", hr);
838 ok(state == BG_JOB_STATE_ACKNOWLEDGED, "unexpected state: %u\n", state);
839
840 hr = IBackgroundCopyJob_Complete(test_job);
841 ok(hr == BG_E_INVALID_STATE, "got 0x%08lx\n", hr);
842
844
845 hr = IBackgroundCopyJob_SetNotifyInterface(test_job, NULL);
846 ok(hr == BG_E_INVALID_STATE, "got 0x%08lx\n", hr);
847
848 IUnknown_Release(copyCallbackUnknown);
849 IBackgroundCopyCallback2_Release(copyCallback);
850}
851
852typedef void (*test_t)(void);
853
855{
856 static const test_t tests[] = {
865 0
866 };
867 static const test_t tests_bits20[] = {
873 test_Cancel, /* must be last */
874 0
875 };
876 static const test_t tests_bits25[] = {
878 0
879 };
880 const test_t *test;
881 int i;
883
884 init_paths();
885
886 /* CoInitializeEx and CoInitializeSecurity with RPC_C_IMP_LEVEL_IMPERSONATE
887 * are required to set the job transfer policy
888 */
890 if (FAILED(hres)) {
891 ok(0, "CoInitializeEx failed: %0lx\n", hres);
892 return;
893 }
894
898 NULL, EOAC_NONE, 0);
899 if (FAILED(hres)) {
900 ok(0, "CoInitializeSecurity failed: %0lx\n", hres);
901 return;
902 }
903
905 {
907 win_skip("Failed to create Manager instance, skipping tests\n");
908 return;
909 }
910
911 for (test = tests, i = 0; *test; ++test, ++i)
912 {
913 /* Keep state separate between tests. */
914 if (!setup())
915 {
916 ok(0, "tests:%d: Unable to setup test\n", i);
917 break;
918 }
919 (*test)();
920 teardown();
921 }
922
923 if (check_bits20())
924 {
925 for (test = tests_bits20, i = 0; *test; ++test, ++i)
926 {
927 /* Keep state separate between tests. */
928 if (!setup())
929 {
930 ok(0, "tests_bits20:%d: Unable to setup test\n", i);
931 break;
932 }
933 (*test)();
934 teardown();
935 }
936 }
937 else
938 {
939 win_skip("Tests need BITS 2.0 or higher\n");
940 }
941
942 if (check_bits25())
943 {
944 for (test = tests_bits25, i = 0; *test; ++test, ++i)
945 {
946 /* Keep state separate between tests. */
947 if (!setup())
948 {
949 ok(0, "tests_bits25:%d: Unable to setup test\n", i);
950 break;
951 }
952 (*test)();
953 teardown();
954 }
955 }
956 else
957 {
958 win_skip("Tests need BITS 2.5 or higher\n");
959 }
960
962}
static int state
Definition: maze.c:121
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
const GUID IID_IUnknown
#define BG_E_EMPTY
Definition: bitsmsg.h:40
#define BG_E_ERROR_INFORMATION_UNAVAILABLE
Definition: bitsmsg.h:45
#define BG_E_INVALID_STATE
Definition: bitsmsg.h:39
cd_progress_ptr progress
Definition: cdjpeg.h:152
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HRESULT WINAPI CoInitializeSecurity(PSECURITY_DESCRIPTOR sd, LONG cAuthSvc, SOLE_AUTHENTICATION_SERVICE *asAuthSvc, void *reserved1, DWORD authn_level, DWORD imp_level, void *reserved2, DWORD capabilities, void *reserved3)
Definition: combase.c:1163
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(void *reserved, DWORD model)
Definition: combase.c:2803
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 GetProcessHeap()
Definition: compat.h:736
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define lstrcpyW
Definition: compat.h:749
#define FILE_SHARE_READ
Definition: compat.h:136
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2098
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
#define L(x)
Definition: resources.c:13
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
MdFileObject pFile
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
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
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define wine_dbgstr_w
Definition: kernel32.h:34
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
struct S1 s1
#define win_skip
Definition: minitest.h:67
#define error(str)
Definition: mkdosfs.c:1605
#define CREATE_ALWAYS
Definition: disk.h:72
static struct test_info tests[]
static CRYPT_DATA_BLOB b2[]
Definition: msg.c:538
static CRYPT_DATA_BLOB b1[]
Definition: msg.c:529
HRESULT hres
Definition: protocol.c:432
static HANDLE job
Definition: process.c:79
static void test_AddFile(void)
Definition: job.c:348
static BOOL check_bits20(void)
Definition: job.c:248
static GUID test_jobId
Definition: job.c:39
static HRESULT WINAPI IBackgroundCopyCallback2Impl_JobError(IBackgroundCopyCallback2 *iface, IBackgroundCopyJob *pJob, IBackgroundCopyError *pError)
Definition: job.c:102
static void test_GetProgress_preTransfer(void)
Definition: job.c:393
static void init_paths(void)
Definition: job.c:179
static void test_NotifyInterface(void)
Definition: job.c:668
static WCHAR test_localPathA[MAX_PATH]
Definition: job.c:35
static void test_GetName(void)
Definition: job.c:336
static void teardown(void)
Definition: job.c:241
static ULONG WINAPI IBackgroundCopyCallback2Impl_Release(IBackgroundCopyCallback2 *iface)
Definition: job.c:87
static void test_CompleteLocal(void)
Definition: job.c:513
static HRESULT WINAPI IBackgroundCopyCallback2Impl_JobModification(IBackgroundCopyCallback2 *iface, IBackgroundCopyJob *pJob, DWORD dwReserved)
Definition: job.c:108
static WCHAR test_localPathB[MAX_PATH]
Definition: job.c:36
static HRESULT WINAPI IBackgroundCopyCallback2Impl_JobTransferred(IBackgroundCopyCallback2 *iface, IBackgroundCopyJob *pJob)
Definition: job.c:114
static IBackgroundCopyCallback2Impl * impl_from_IBackgroundCopyCallback2(IBackgroundCopyCallback2 *iface)
Definition: job.c:47
static void test_EnumFiles(void)
Definition: job.c:375
static void test_ResumeEmpty(void)
Definition: job.c:422
static void test_NotifyFlags(void)
Definition: job.c:656
static void test_GetState(void)
Definition: job.c:410
static WCHAR test_remotePathA[MAX_PATH]
Definition: job.c:33
static HRESULT WINAPI IBackgroundCopyCallback2Impl_QueryInterface(IBackgroundCopyCallback2 *iface, REFIID riid, void **ppv)
Definition: job.c:52
static void test_HttpOptions(void)
Definition: job.c:701
static void test_AddFileSet(void)
Definition: job.c:362
static void handle_job_err(void)
Definition: job.c:476
static WCHAR test_remotePathB[MAX_PATH]
Definition: job.c:34
static void makeFile(WCHAR *name, const char *contents)
Definition: job.c:436
static BOOL create_background_copy_callback2(IBackgroundCopyCallback2 **copyCallback)
Definition: job.c:138
static void test_GetId(void)
Definition: job.c:314
static BOOL setup(void)
Definition: job.c:193
static void test_CompleteLocalURL(void)
Definition: job.c:575
static void compareFiles(WCHAR *n1, WCHAR *n2)
Definition: job.c:449
static HRESULT WINAPI IBackgroundCopyCallback2Impl_FileTransferred(IBackgroundCopyCallback2 *iface, IBackgroundCopyJob *pJob, IBackgroundCopyFile *pFile)
Definition: job.c:120
static BG_JOB_TYPE test_type
Definition: job.c:40
static void test_Cancel(void)
Definition: job.c:679
static IBackgroundCopyJob * test_job
Definition: job.c:38
static BOOL check_bits25(void)
Definition: job.c:280
static void test_GetType(void)
Definition: job.c:325
static IBackgroundCopyManager * test_manager
Definition: job.c:37
static const IBackgroundCopyCallback2Vtbl copyCallback_vtbl
Definition: job.c:127
static HRESULT test_create_manager(void)
Definition: job.c:159
void(* test_t)(void)
Definition: job.c:852
static ULONG WINAPI IBackgroundCopyCallback2Impl_AddRef(IBackgroundCopyCallback2 *iface)
Definition: job.c:78
static const char * contents
Definition: parser.c:511
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED _In_opt_ LPTRANSMIT_FILE_BUFFERS _In_ DWORD dwReserved
Definition: mswsock.h:95
#define GENERIC_WRITE
Definition: nt_native.h:90
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:279
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
#define err(...)
#define test
Definition: rosglue.h:37
int n2
Definition: dwarfget.c:147
int n1
Definition: dwarfget.c:147
#define RPC_C_IMP_LEVEL_IMPERSONATE
Definition: rpcdce.h:176
#define RPC_C_AUTHN_LEVEL_CONNECT
Definition: rpcdce.h:147
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_ENGLISH
Definition: nls.h:52
#define SUBLANG_ENGLISH_US
Definition: nls.h:222
#define f2(x, y, z)
Definition: sha1.c:31
#define f1(x, y, z)
Definition: sha1.c:30
#define memset(x, y, z)
Definition: compat.h:39
vector< Header * > headers
Definition: sdkparse.cpp:39
PCWSTR s2
Definition: shell32_main.h:38
static const WCHAR winetestW[]
Definition: shelldispatch.c:47
IBackgroundCopyCallback2 IBackgroundCopyCallback2_iface
Definition: job.c:43
Definition: fci.c:123
Definition: name.c:39
Definition: send.c:48
Definition: dhcpd.h:248
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:726
Character const *const prefix
Definition: tempnam.cpp:195
char displayName[]
Definition: tftpd.cpp:35
uint16_t * LPWSTR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:3451
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define E_NOINTERFACE
Definition: winerror.h:3479
#define ERROR_SERVICE_DISABLED
Definition: winerror.h:933