Module: wine Branch: master Commit: 1317e3115adc0e580a333602ae1f27f89730c6a8 URL: http://source.winehq.org/git/wine.git/?a=commit;h=1317e3115adc0e580a333602ae...
Author: Dan Hipschman dsh@linux.ucla.edu Date: Mon Mar 3 16:46:44 2008 -0800
qmgr: Implement IEnumBackgroundCopyJobs_Next.
---
dlls/qmgr/enum_jobs.c | 32 +++++++++++- dlls/qmgr/tests/enum_jobs.c | 113 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 4 deletions(-)
diff --git a/dlls/qmgr/enum_jobs.c b/dlls/qmgr/enum_jobs.c index 6d14791..98b9cb2 100644 --- a/dlls/qmgr/enum_jobs.c +++ b/dlls/qmgr/enum_jobs.c @@ -73,15 +73,41 @@ static ULONG WINAPI BITS_IEnumBackgroundCopyJobs_Release( return ref; }
-/*** IEnumBackgroundCopyJobs methods ***/ static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Next( IEnumBackgroundCopyJobs* iface, ULONG celt, IBackgroundCopyJob **rgelt, ULONG *pceltFetched) { - FIXME("Not implemented\n"); - return E_NOTIMPL; + EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface; + ULONG fetched; + ULONG i; + IBackgroundCopyJob *job; + + fetched = min(celt, This->numJobs - This->indexJobs); + if (pceltFetched) + *pceltFetched = fetched; + else + { + /* We need to initialize this array if the caller doesn't request + the length because length_is will default to celt. */ + for (i = 0; i < celt; ++i) + rgelt[i] = NULL; + + /* pceltFetched can only be NULL if celt is 1 */ + if (celt != 1) + return E_INVALIDARG; + } + + /* Fill in the array of objects */ + for (i = 0; i < fetched; ++i) + { + job = This->jobs[This->indexJobs++]; + IBackgroundCopyJob_AddRef(job); + rgelt[i] = job; + } + + return fetched == celt ? S_OK : S_FALSE; }
static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Skip( diff --git a/dlls/qmgr/tests/enum_jobs.c b/dlls/qmgr/tests/enum_jobs.c index 20344d3..93aaf15 100644 --- a/dlls/qmgr/tests/enum_jobs.c +++ b/dlls/qmgr/tests/enum_jobs.c @@ -1,7 +1,7 @@ /* * Unit test suite for Enum Background Copy Jobs Interface * - * Copyright 2007 Google (Roy Shea) + * Copyright 2007 Google (Roy Shea, Dan Hipschman) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,6 +31,7 @@ static const WCHAR test_displayNameB[] = {'T','e','s','t','B', 0}; static IBackgroundCopyManager *test_manager; static IBackgroundCopyJob *test_jobA; static IBackgroundCopyJob *test_jobB; +static ULONG test_jobCountB; static IEnumBackgroundCopyJobs *test_enumJobsA; static IEnumBackgroundCopyJobs *test_enumJobsB; static GUID test_jobIdA; @@ -73,6 +74,10 @@ static BOOL setup(void) if(hres != S_OK) return FALSE;
+ hres = IEnumBackgroundCopyJobs_GetCount(test_enumJobsB, &test_jobCountB); + if (hres != S_OK) + return FALSE; + return TRUE; }
@@ -125,12 +130,118 @@ static void test_GetCount(void) ok(jobCountB == jobCountA + 1, "Got incorrect count\n"); }
+/* Test Next with a NULL pceltFetched*/ +static void test_Next_walkListNull(void) +{ + HRESULT hres; + IBackgroundCopyJob *job; + ULONG i; + + /* Fetch the available jobs */ + for (i = 0; i < test_jobCountB; i++) + { + hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, NULL); + ok(hres == S_OK, "Next failed: %08x\n", hres); + if(hres != S_OK) + { + skip("Unable to get job from Next\n"); + return; + } + IBackgroundCopyJob_Release(job); + } + + /* Attempt to fetch one more than the number of available jobs */ + hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, NULL); + ok(hres == S_FALSE, "Next off end of available jobs failed: %08x\n", hres); +} + +/* Test Next */ +static void test_Next_walkList_1(void) +{ + HRESULT hres; + IBackgroundCopyJob *job; + ULONG fetched; + ULONG i; + + /* Fetch the available jobs */ + for (i = 0; i < test_jobCountB; i++) + { + fetched = 0; + hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, &fetched); + ok(hres == S_OK, "Next failed: %08x\n", hres); + if(hres != S_OK) + { + skip("Unable to get job from Next\n"); + return; + } + ok(fetched == 1, "Next returned the incorrect number of jobs: %08x\n", hres); + IBackgroundCopyJob_Release(job); + } + + /* Attempt to fetch one more than the number of available jobs */ + fetched = 0; + hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 1, &job, &fetched); + ok(hres == S_FALSE, "Next off end of available jobs failed: %08x\n", hres); + ok(fetched == 0, "Next returned the incorrect number of jobs: %08x\n", hres); +} + +/* Test Next by requesting multiple files at a time */ +static void test_Next_walkList_2(void) +{ + HRESULT hres; + IBackgroundCopyJob **jobs; + ULONG fetched; + ULONG i; + + jobs = HeapAlloc(GetProcessHeap(), 0, test_jobCountB * sizeof *jobs); + if (!jobs) + { + skip("Couldn't allocate memory\n"); + return; + } + + for (i = 0; i < test_jobCountB; i++) + jobs[i] = NULL; + + fetched = 0; + hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, test_jobCountB, jobs, &fetched); + ok(hres == S_OK, "Next failed: %08x\n", hres); + if(hres != S_OK) + { + skip("Unable to get file from test_enumJobs\n"); + return; + } + ok(fetched == test_jobCountB, "Next returned the incorrect number of jobs: %08x\n", hres); + + for (i = 0; i < test_jobCountB; i++) + { + ok(jobs[i] != NULL, "Next returned NULL\n"); + if (jobs[i]) + IBackgroundCopyFile_Release(jobs[i]); + } +} + +/* Test Next Error conditions */ +static void test_Next_errors(void) +{ + HRESULT hres; + IBackgroundCopyJob *jobs[2]; + + /* E_INVALIDARG: pceltFetched can ONLY be NULL if celt is 1 */ + hres = IEnumBackgroundCopyJobs_Next(test_enumJobsB, 2, jobs, NULL); + ok(hres != S_OK, "Invalid call to Next succeeded: %08x\n", hres); +} + typedef void (*test_t)(void);
START_TEST(enum_jobs) { static const test_t tests[] = { test_GetCount, + test_Next_walkListNull, + test_Next_walkList_1, + test_Next_walkList_2, + test_Next_errors, 0 }; const test_t *test;