Module: wine Branch: master Commit: 8dfba77c8cfcf235ee2c6b8927059c8b97f9ac0b URL: http://source.winehq.org/git/wine.git/?a=commit;h=8dfba77c8cfcf235ee2c6b8927...
Author: Roy Shea roy@cs.hmc.edu Date: Mon Mar 3 16:46:08 2008 -0800
qmgr: Implement IEnumBackgroundCopyJobs_GetCount.
---
dlls/qmgr/enum_jobs.c | 39 +++++++++++- dlls/qmgr/qmgr.h | 3 + dlls/qmgr/tests/Makefile.in | 1 + dlls/qmgr/tests/enum_jobs.c | 152 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 193 insertions(+), 2 deletions(-)
diff --git a/dlls/qmgr/enum_jobs.c b/dlls/qmgr/enum_jobs.c index 54ecaab..6d14791 100644 --- a/dlls/qmgr/enum_jobs.c +++ b/dlls/qmgr/enum_jobs.c @@ -25,6 +25,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
static void EnumBackgroundCopyJobsDestructor(EnumBackgroundCopyJobsImpl *This) { + ULONG i; + + for(i = 0; i < This->numJobs; i++) + IBackgroundCopyJob_Release(This->jobs[i]); + + HeapFree(GetProcessHeap(), 0, This->jobs); HeapFree(GetProcessHeap(), 0, This); }
@@ -105,8 +111,9 @@ static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_GetCount( IEnumBackgroundCopyJobs* iface, ULONG *puCount) { - FIXME("Not implemented\n"); - return E_NOTIMPL; + EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface; + *puCount = This->numJobs; + return S_OK; }
static const IEnumBackgroundCopyJobsVtbl BITS_IEnumBackgroundCopyJobs_Vtbl = @@ -124,7 +131,10 @@ static const IEnumBackgroundCopyJobsVtbl BITS_IEnumBackgroundCopyJobs_Vtbl = HRESULT EnumBackgroundCopyJobsConstructor(LPVOID *ppObj, IBackgroundCopyManager* copyManager) { + BackgroundCopyManagerImpl *qmgr = (BackgroundCopyManagerImpl *) copyManager; EnumBackgroundCopyJobsImpl *This; + BackgroundCopyJobImpl *job; + ULONG i;
TRACE("%p, %p)\n", ppObj, copyManager);
@@ -134,6 +144,31 @@ HRESULT EnumBackgroundCopyJobsConstructor(LPVOID *ppObj, This->lpVtbl = &BITS_IEnumBackgroundCopyJobs_Vtbl; This->ref = 1;
+ /* Create array of jobs */ + This->indexJobs = 0; + This->numJobs = list_count(&qmgr->jobs); + + if (0 < This->numJobs) + { + This->jobs = HeapAlloc(GetProcessHeap(), 0, + This->numJobs * sizeof *This->jobs); + if (!This->jobs) + { + HeapFree(GetProcessHeap(), 0, This); + return E_OUTOFMEMORY; + } + } + else + This->jobs = NULL; + + i = 0; + LIST_FOR_EACH_ENTRY(job, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr) + { + IBackgroundCopyJob *iJob = (IBackgroundCopyJob *) job; + IBackgroundCopyJob_AddRef(iJob); + This->jobs[i++] = iJob; + } + *ppObj = &This->lpVtbl; return S_OK; } diff --git a/dlls/qmgr/qmgr.h b/dlls/qmgr/qmgr.h index f5629c6..2ab3f57 100644 --- a/dlls/qmgr/qmgr.h +++ b/dlls/qmgr/qmgr.h @@ -48,6 +48,9 @@ typedef struct { const IEnumBackgroundCopyJobsVtbl *lpVtbl; LONG ref; + IBackgroundCopyJob **jobs; + ULONG numJobs; + ULONG indexJobs; } EnumBackgroundCopyJobsImpl;
/* Enum background copy files vtbl and related data */ diff --git a/dlls/qmgr/tests/Makefile.in b/dlls/qmgr/tests/Makefile.in index 840676d..9a3c596 100644 --- a/dlls/qmgr/tests/Makefile.in +++ b/dlls/qmgr/tests/Makefile.in @@ -7,6 +7,7 @@ IMPORTS = ole32 shlwapi user32 kernel32
CTESTS = \ enum_files.c \ + enum_jobs.c \ file.c \ job.c \ qmgr.c diff --git a/dlls/qmgr/tests/enum_jobs.c b/dlls/qmgr/tests/enum_jobs.c new file mode 100644 index 0000000..20344d3 --- /dev/null +++ b/dlls/qmgr/tests/enum_jobs.c @@ -0,0 +1,152 @@ +/* + * Unit test suite for Enum Background Copy Jobs Interface + * + * Copyright 2007 Google (Roy Shea) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdio.h> + +#define COBJMACROS + +#include "wine/test.h" +#include "bits.h" + +/* Globals used by many tests */ +static const WCHAR test_displayNameA[] = {'T','e','s','t','A', 0}; +static const WCHAR test_displayNameB[] = {'T','e','s','t','B', 0}; +static IBackgroundCopyManager *test_manager; +static IBackgroundCopyJob *test_jobA; +static IBackgroundCopyJob *test_jobB; +static IEnumBackgroundCopyJobs *test_enumJobsA; +static IEnumBackgroundCopyJobs *test_enumJobsB; +static GUID test_jobIdA; +static GUID test_jobIdB; + +/* Generic test setup */ +static BOOL setup(void) +{ + HRESULT hres; + + test_manager = NULL; + test_jobA = NULL; + test_jobB = NULL; + memset(&test_jobIdA, 0, sizeof test_jobIdA); + memset(&test_jobIdB, 0, sizeof test_jobIdB); + + hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL, + CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager, + (void **) &test_manager); + if(hres != S_OK) + return FALSE; + + hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayNameA, + BG_JOB_TYPE_DOWNLOAD, &test_jobIdA, + &test_jobA); + if(hres != S_OK) + return FALSE; + + hres = IBackgroundCopyManager_EnumJobs(test_manager, 0, &test_enumJobsA); + if(hres != S_OK) + return FALSE; + + hres = IBackgroundCopyManager_CreateJob(test_manager, test_displayNameB, + BG_JOB_TYPE_DOWNLOAD, &test_jobIdB, + &test_jobB); + if(hres != S_OK) + return FALSE; + + hres = IBackgroundCopyManager_EnumJobs(test_manager, 0, &test_enumJobsB); + if(hres != S_OK) + return FALSE; + + return TRUE; +} + +/* Generic test cleanup */ +static void teardown(void) +{ + if (test_enumJobsB) + IEnumBackgroundCopyJobs_Release(test_enumJobsB); + test_enumJobsB = NULL; + if (test_jobB) + IBackgroundCopyJob_Release(test_jobB); + test_jobB = NULL; + if (test_enumJobsA) + IEnumBackgroundCopyJobs_Release(test_enumJobsA); + test_enumJobsA = NULL; + if (test_jobA) + IBackgroundCopyJob_Release(test_jobA); + test_jobA = NULL; + if (test_manager) + IBackgroundCopyManager_Release(test_manager); + test_manager = NULL; +} + +/* We can't assume the job count will start at any fixed number since esp + when testing on Windows there may be other jobs created by other + processes. Even this approach of creating two jobs and checking the + difference in counts could fail if a job was created in between, but + it's probably not worth worrying about in sane test environments. */ +static void test_GetCount(void) +{ + HRESULT hres; + ULONG jobCountA, jobCountB; + + hres = IEnumBackgroundCopyJobs_GetCount(test_enumJobsA, &jobCountA); + ok(hres == S_OK, "GetCount failed: %08x\n", hres); + if(hres != S_OK) + { + skip("Couldn't get job count\n"); + return; + } + + hres = IEnumBackgroundCopyJobs_GetCount(test_enumJobsB, &jobCountB); + ok(hres == S_OK, "GetCount failed: %08x\n", hres); + if(hres != S_OK) + { + skip("Couldn't get job count\n"); + return; + } + + ok(jobCountB == jobCountA + 1, "Got incorrect count\n"); +} + +typedef void (*test_t)(void); + +START_TEST(enum_jobs) +{ + static const test_t tests[] = { + test_GetCount, + 0 + }; + const test_t *test; + + CoInitialize(NULL); + for (test = tests; *test; ++test) + { + /* Keep state seperate between tests. */ + if (!setup()) + { + teardown(); + skip("Unable to setup test\n"); + break; + } + (*test)(); + teardown(); + } + CoUninitialize(); +}