Commit 8dfba77c authored by Roy Shea's avatar Roy Shea Committed by Alexandre Julliard

qmgr: Implement IEnumBackgroundCopyJobs_GetCount.

parent 4609eccd
......@@ -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;
}
......@@ -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 */
......
......@@ -7,6 +7,7 @@ IMPORTS = ole32 shlwapi user32 kernel32
CTESTS = \
enum_files.c \
enum_jobs.c \
file.c \
job.c \
qmgr.c
......
/*
* 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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment