samlib: Add stubbed samlib.dll.
[wine] / dlls / urlmon / tests / uri.c
1 /*
2  * UrlMon IUri tests
3  *
4  * Copyright 2010 Thomas Mullaly
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 /*
22  * IUri testing framework goals:
23  *  - Test invalid args
24  *      - invalid flags
25  *      - invalid args (IUri, uri string)
26  *  - Test parsing for components when no canonicalization occurs
27  *  - Test parsing for components when canonicalization occurs.
28  *  - More tests...
29  */
30
31 #include <wine/test.h>
32 #include <stdarg.h>
33 #include <stddef.h>
34
35 #define COBJMACROS
36
37 #include "windef.h"
38 #include "winbase.h"
39 #include "urlmon.h"
40
41 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
42
43 static const WCHAR http_urlW[] = { 'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
44         '.','o','r','g','/',0};
45
46 typedef struct _uri_create_flag_test {
47     DWORD   flags;
48     HRESULT expected;
49 } uri_create_flag_test;
50
51 static const uri_create_flag_test invalid_flag_tests[] = {
52     /* Set of invalid flag combinations to test for. */
53     {Uri_CREATE_DECODE_EXTRA_INFO | Uri_CREATE_NO_DECODE_EXTRA_INFO, E_INVALIDARG},
54     {Uri_CREATE_CANONICALIZE | Uri_CREATE_NO_CANONICALIZE, E_INVALIDARG},
55     {Uri_CREATE_CRACK_UNKNOWN_SCHEMES | Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES, E_INVALIDARG},
56     {Uri_CREATE_PRE_PROCESS_HTML_URI | Uri_CREATE_NO_PRE_PROCESS_HTML_URI, E_INVALIDARG},
57     {Uri_CREATE_IE_SETTINGS | Uri_CREATE_NO_IE_SETTINGS, E_INVALIDARG}
58 };
59
60 /*
61  * Simple tests to make sure the CreateUri function handles invalid flag combinations
62  * correctly.
63  */
64 static void test_CreateUri_InvalidFlags(void) {
65     DWORD i;
66
67     for(i = 0; i < sizeof(invalid_flag_tests)/sizeof(invalid_flag_tests[0]); ++i) {
68         HRESULT hr;
69         IUri *uri = (void*) 0xdeadbeef;
70
71         hr = pCreateUri(http_urlW, invalid_flag_tests[i].flags, 0, &uri);
72         todo_wine {
73             ok(hr == invalid_flag_tests[i].expected, "Error: CreateUri returned 0x%08x, expected 0x%08x, flags=0x%08x\n",
74                     hr, invalid_flag_tests[i].expected, invalid_flag_tests[i].flags);
75         }
76         todo_wine { ok(uri == NULL, "Error: expected the IUri to be NULL, but it was %p instead\n", uri); }
77     }
78 }
79
80 static void test_CreateUri_InvalidArgs(void) {
81     HRESULT hr;
82     IUri *uri = (void*) 0xdeadbeef;
83
84     hr = pCreateUri(http_urlW, 0, 0, NULL);
85     ok(hr == E_INVALIDARG, "Error: CreateUri returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
86
87     hr = pCreateUri(NULL, 0, 0, &uri);
88     ok(hr == E_INVALIDARG, "Error: CreateUri returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
89     ok(uri == NULL, "Error: Expected the IUri to be NULL, but it was %p instead\n", uri);
90 }
91
92 START_TEST(uri) {
93     HMODULE hurlmon;
94
95     hurlmon = GetModuleHandle("urlmon.dll");
96     pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
97
98     if(!pCreateUri) {
99         win_skip("CreateUri is not present, skipping tests.\n");
100         return;
101     }
102
103     trace("test CreateUri invalid flags...\n");
104     test_CreateUri_InvalidFlags();
105
106     trace("test CreateUri invalid args...\n");
107     test_CreateUri_InvalidArgs();
108 }