Thomas Mullaly : urlmon/tests: Added a few tests for CreateIUriBuilder.

Alexandre Julliard julliard at winehq.org
Thu Aug 19 11:44:03 CDT 2010


Module: wine
Branch: master
Commit: 516aac903aff360406e96c4a006b733a0cef7883
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=516aac903aff360406e96c4a006b733a0cef7883

Author: Thomas Mullaly <thomas.mullaly at gmail.com>
Date:   Tue Aug 10 22:37:33 2010 -0400

urlmon/tests: Added a few tests for CreateIUriBuilder.

---

 dlls/urlmon/tests/uri.c |   50 +++++++++++++++++++++++++++++++++++++---------
 dlls/urlmon/uri.c       |   13 +++++++++++-
 2 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/dlls/urlmon/tests/uri.c b/dlls/urlmon/tests/uri.c
index 88f89db..78ddf72 100644
--- a/dlls/urlmon/tests/uri.c
+++ b/dlls/urlmon/tests/uri.c
@@ -18,16 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-/*
- * IUri testing framework goals:
- *  - Test invalid args
- *      - invalid flags
- *      - invalid args (IUri, uri string)
- *  - Test parsing for components when no canonicalization occurs
- *  - Test parsing for components when canonicalization occurs.
- *  - More tests...
- */
-
 #include <wine/test.h>
 #include <stdarg.h>
 #include <stddef.h>
@@ -44,6 +34,7 @@
 
 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
 static HRESULT (WINAPI *pCreateUriWithFragment)(LPCWSTR, LPCWSTR, DWORD, DWORD_PTR, IUri**);
+static HRESULT (WINAPI *pCreateIUriBuilder)(IUri*, DWORD, DWORD_PTR, IUriBuilder**);
 
 static const WCHAR http_urlW[] = { 'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
         '.','o','r','g','/',0};
@@ -3756,6 +3747,11 @@ static inline DWORD strcmp_aw(LPCSTR strA, LPCWSTR strB) {
     return ret;
 }
 
+static inline ULONG get_refcnt(IUri *uri) {
+    IUri_AddRef(uri);
+    return IUri_Release(uri);
+}
+
 /*
  * Simple tests to make sure the CreateUri function handles invalid flag combinations
  * correctly.
@@ -4884,12 +4880,43 @@ static void test_CreateUriWithFragment(void) {
     }
 }
 
+static void test_CreateIUriBuilder(void) {
+    HRESULT hr;
+    IUriBuilder *builder = NULL;
+    IUri *uri;
+
+    hr = pCreateIUriBuilder(NULL, 0, 0, NULL);
+    ok(hr == E_POINTER, "Error: CreateIUriBuilder returned 0x%08x, expected 0x%08x\n",
+        hr, E_POINTER);
+
+    /* CreateIUriBuilder increases the ref count of the IUri it receives. */
+    hr = pCreateUri(http_urlW, 0, 0, &uri);
+    ok(hr == S_OK, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
+    if(SUCCEEDED(hr)) {
+        ULONG cur_count, orig_count;
+
+        orig_count = get_refcnt(uri);
+        hr = pCreateIUriBuilder(uri, 0, 0, &builder);
+        ok(hr == S_OK, "Error: CreateIUriBuilder returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
+        ok(builder != NULL, "Error: Expecting builder not to be NULL\n");
+
+        cur_count = get_refcnt(uri);
+        ok(cur_count == orig_count+1, "Error: Expected the ref count to be %u, but was %u instead.\n", orig_count+1, cur_count);
+
+        if(builder) IUriBuilder_Release(builder);
+        cur_count = get_refcnt(uri);
+        ok(cur_count == orig_count, "Error: Expected the ref count to be %u, but was %u instead.\n", orig_count, cur_count);
+    }
+    if(uri) IUri_Release(uri);
+}
+
 START_TEST(uri) {
     HMODULE hurlmon;
 
     hurlmon = GetModuleHandle("urlmon.dll");
     pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
     pCreateUriWithFragment = (void*) GetProcAddress(hurlmon, "CreateUriWithFragment");
+    pCreateIUriBuilder = (void*) GetProcAddress(hurlmon, "CreateIUriBuilder");
 
     if(!pCreateUri) {
         win_skip("CreateUri is not present, skipping tests.\n");
@@ -4937,4 +4964,7 @@ START_TEST(uri) {
 
     trace("test CreateUriWithFragment...\n");
     test_CreateUriWithFragment();
+
+    trace("test CreateIUriBuilder...\n");
+    test_CreateIUriBuilder();
 }
diff --git a/dlls/urlmon/uri.c b/dlls/urlmon/uri.c
index e977426..31de387 100644
--- a/dlls/urlmon/uri.c
+++ b/dlls/urlmon/uri.c
@@ -75,6 +75,8 @@ typedef struct {
 typedef struct {
     const IUriBuilderVtbl  *lpIUriBuilderVtbl;
     LONG ref;
+
+    IUri *uri;
 } UriBuilder;
 
 typedef struct {
@@ -4080,8 +4082,10 @@ static ULONG WINAPI UriBuilder_Release(IUriBuilder *iface)
 
     TRACE("(%p) ref=%d\n", This, ref);
 
-    if(!ref)
+    if(!ref) {
+        if(This->uri) IUri_Release(This->uri);
         heap_free(This);
+    }
 
     return ref;
 }
@@ -4300,6 +4304,9 @@ HRESULT WINAPI CreateIUriBuilder(IUri *pIUri, DWORD dwFlags, DWORD_PTR dwReserve
 
     TRACE("(%p %x %x %p)\n", pIUri, dwFlags, (DWORD)dwReserved, ppIUriBuilder);
 
+    if(!ppIUriBuilder)
+        return E_POINTER;
+
     ret = heap_alloc(sizeof(UriBuilder));
     if(!ret)
         return E_OUTOFMEMORY;
@@ -4307,6 +4314,10 @@ HRESULT WINAPI CreateIUriBuilder(IUri *pIUri, DWORD dwFlags, DWORD_PTR dwReserve
     ret->lpIUriBuilderVtbl = &UriBuilderVtbl;
     ret->ref = 1;
 
+    ret->uri = pIUri;
+    if(pIUri)
+        IUri_AddRef(pIUri);
+
     *ppIUriBuilder = URIBUILDER(ret);
     return S_OK;
 }




More information about the wine-cvs mailing list