[3/3] qmgr: Implement IBackgroundCopyManager_CreateJob with test.

Dan Hipschman dsh at linux.ucla.edu
Thu Feb 21 17:49:08 CST 2008


Implement IBackgroundCopyManager_CreateJob with test.

From: Roy Shea <roy at cs.hmc.edu>
Date: Thu Dec 20 18:38:31 CST 2007

---
 dlls/qmgr/job.c        |   42 ++++++++++++++++++++++++++++++++++++++++++
 dlls/qmgr/qmgr.c       |   18 +++++++++++-------
 dlls/qmgr/qmgr.h       |    2 ++
 dlls/qmgr/tests/qmgr.c |   37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 92 insertions(+), 7 deletions(-)

diff --git a/dlls/qmgr/job.c b/dlls/qmgr/job.c
index 7f8abb6..9a8d091 100644
--- a/dlls/qmgr/job.c
+++ b/dlls/qmgr/job.c
@@ -362,3 +362,45 @@ static const IBackgroundCopyJobVtbl BITS_IBackgroundCopyJob_Vtbl =
     BITS_IBackgroundCopyJob_GetProxySettings,
     BITS_IBackgroundCopyJob_TakeOwnership,
 };
+
+HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
+                                     GUID *pJobId, LPVOID *ppObj)
+{
+    HRESULT hr;
+    BackgroundCopyJobImpl *This;
+    int n;
+
+    TRACE("(%s,%d,%p)\n", debugstr_w(displayName), type, ppObj);
+
+    if (!pJobId || !ppObj)
+        return E_POINTER;
+
+    This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
+    if (!This)
+        return E_OUTOFMEMORY;
+
+    This->lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
+    This->ref = 1;
+    This->type = type;
+
+    n = (lstrlenW(displayName) + 1) *  sizeof *displayName;
+    This->displayName = HeapAlloc(GetProcessHeap(), 0, n);
+    if (!This->displayName)
+    {
+        HeapFree(GetProcessHeap(), 0, This);
+        return E_OUTOFMEMORY;
+    }
+    memcpy(This->displayName, displayName, n);
+
+    hr = CoCreateGuid(&This->jobId);
+    if (FAILED(hr))
+    {
+        HeapFree(GetProcessHeap(), 0, This->displayName);
+        HeapFree(GetProcessHeap(), 0, This);
+        return hr;
+    }
+    memcpy(pJobId, &This->jobId, sizeof(GUID));
+
+    *ppObj = &This->lpVtbl;
+    return S_OK;
+}
diff --git a/dlls/qmgr/qmgr.c b/dlls/qmgr/qmgr.c
index b257a16..730a749 100644
--- a/dlls/qmgr/qmgr.c
+++ b/dlls/qmgr/qmgr.c
@@ -85,14 +85,18 @@ static ULONG WINAPI BITS_IBackgroundCopyManager_Release(
 /*** IBackgroundCopyManager interface methods ***/
 
 static HRESULT WINAPI BITS_IBackgroundCopyManager_CreateJob(
-        IBackgroundCopyManager* iface,
-        LPCWSTR DisplayName,
-        BG_JOB_TYPE Type,
-        GUID *pJobId,
-        IBackgroundCopyJob **ppJob)
+    IBackgroundCopyManager* iface,
+    LPCWSTR DisplayName,
+    BG_JOB_TYPE Type,
+    GUID *pJobId,
+    IBackgroundCopyJob **ppJob)
 {
-    FIXME("Not implemented\n");
-    return E_NOTIMPL;
+    TRACE("\n");
+    if (!pJobId || !ppJob)
+        return E_POINTER;
+
+    return BackgroundCopyJobConstructor(DisplayName, Type, pJobId,
+                                        (LPVOID *) ppJob);
 }
 
 static HRESULT WINAPI BITS_IBackgroundCopyManager_GetJob(
diff --git a/dlls/qmgr/qmgr.h b/dlls/qmgr/qmgr.h
index 470026a..8bcc05f 100644
--- a/dlls/qmgr/qmgr.h
+++ b/dlls/qmgr/qmgr.h
@@ -57,6 +57,8 @@ typedef struct
 extern ClassFactoryImpl BITS_ClassFactory;
 
 HRESULT BackgroundCopyManagerConstructor(IUnknown *pUnkOuter, LPVOID *ppObj);
+HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
+                                     GUID *pJobId, LPVOID *ppObj);
 
 /* Little helper functions */
 static inline char *
diff --git a/dlls/qmgr/tests/qmgr.c b/dlls/qmgr/tests/qmgr.c
index 0051751..e36ff36 100644
--- a/dlls/qmgr/tests/qmgr.c
+++ b/dlls/qmgr/tests/qmgr.c
@@ -48,9 +48,46 @@ test_CreateInstance(void)
 
 }
 
+static void test_CreateJob(void)
+{
+    /* Job information */
+    static const WCHAR copyNameW[] = {'T', 'e', 's', 't', 0};
+    IBackgroundCopyJob* job = NULL;
+    GUID tmpId;
+    HRESULT hres;
+    ULONG res;
+    IBackgroundCopyManager* manager = NULL;
+
+    /* Setup */
+    hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
+                            CLSCTX_LOCAL_SERVER, &IID_IBackgroundCopyManager,
+                            (void **) &manager);
+    if(hres != S_OK)
+    {
+        skip("Unable to create bits instance required for test.\n");
+        return;
+    }
+
+    /* Create bits job */
+    hres = IBackgroundCopyManager_CreateJob(manager, copyNameW,
+                                            BG_JOB_TYPE_DOWNLOAD, &tmpId,
+                                            &job);
+    ok(hres == S_OK, "CreateJob failed: %08x\n", hres);
+    if(hres != S_OK)
+        skip("Unable to create bits job.\n");
+    else
+    {
+        res = IBackgroundCopyJob_Release(job);
+        ok(res == 0, "Bad ref count on release: %u\n", res);
+    }
+
+    IBackgroundCopyManager_Release(manager);
+}
+
 START_TEST(qmgr)
 {
     CoInitialize(NULL);
     test_CreateInstance();
+    test_CreateJob();
     CoUninitialize();
 }



More information about the wine-patches mailing list