mshtml: Add tests for get_scrollLeft.
[wine] / dlls / shdocvw / tests / intshcut.c
1 /*
2  * Unit tests to document InternetShortcut's behaviour
3  *
4  * Copyright 2008 Damjan Jovanovic
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 #include <stdarg.h>
22 #include <stdio.h>
23 #include <wine/test.h>
24
25 #define COBJMACROS
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winreg.h"
30 #include "winerror.h"
31
32 #include "shlobj.h"
33 #include "shobjidl.h"
34 #include "shlguid.h"
35 #include "ole2.h"
36 #include "initguid.h"
37 #include "isguids.h"
38 #include "intshcut.h"
39
40 #include "wine/test.h"
41
42 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *pUnknown, REFIID riid, void **ppvObject)
43 {
44     if (IsEqualGUID(&IID_IUnknown, riid))
45     {
46         *ppvObject = pUnknown;
47         return S_OK;
48     }
49     return E_NOINTERFACE;
50 }
51
52 static ULONG WINAPI Unknown_AddRef(IUnknown *pUnknown)
53 {
54     return 2;
55 }
56
57 static ULONG WINAPI Unknown_Release(IUnknown *pUnknown)
58 {
59     return 1;
60 }
61
62 static IUnknownVtbl unknownVtbl = {
63     Unknown_QueryInterface,
64     Unknown_AddRef,
65     Unknown_Release
66 };
67
68 static IUnknown unknown = {
69     &unknownVtbl
70 };
71
72 static const char *printGUID(const GUID *guid)
73 {
74     static char guidSTR[39];
75
76     if (!guid) return NULL;
77
78     sprintf(guidSTR, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
79      guid->Data1, guid->Data2, guid->Data3,
80      guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
81      guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
82     return guidSTR;
83 }
84
85 static void test_Aggregability(void)
86 {
87     HRESULT hr;
88     IUnknown *pUnknown = NULL;
89
90     hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
91     ok(SUCCEEDED(hr), "could not create instance of CLSID_InternetShortcut with IID_IUnknown, hr = 0x%x\n", hr);
92     if (pUnknown)
93         IUnknown_Release(pUnknown);
94
95     hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&pUnknown);
96     ok(SUCCEEDED(hr), "could not create instance of CLSID_InternetShortcut with IID_IUniformResourceLocatorA, hr = 0x%x\n", hr);
97     if (pUnknown)
98         IUnknown_Release(pUnknown);
99
100     hr = CoCreateInstance(&CLSID_InternetShortcut, &unknown, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
101     ok(FAILED(hr), "aggregation didn't fail like it should, hr = 0x%x\n", hr);
102     if (pUnknown)
103         IUnknown_Release(pUnknown);
104 }
105
106 static void can_query_interface(IUnknown *pUnknown, REFIID riid)
107 {
108     HRESULT hr;
109     IUnknown *newInterface;
110     hr = IUnknown_QueryInterface(pUnknown, riid, (void**)&newInterface);
111     ok(SUCCEEDED(hr), "interface %s could not be queried\n", printGUID(riid));
112     if (SUCCEEDED(hr))
113         IUnknown_Release(newInterface);
114 }
115
116 static void test_QueryInterface(void)
117 {
118     HRESULT hr;
119     IUnknown *pUnknown;
120
121     hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
122     if (SUCCEEDED(hr))
123     {
124         can_query_interface(pUnknown, &IID_IUniformResourceLocatorA);
125         can_query_interface(pUnknown, &IID_IUniformResourceLocatorW);
126         can_query_interface(pUnknown, &IID_IPersistFile);
127         IUnknown_Release(pUnknown);
128     }
129     else
130         skip("could not create a CLSID_InternetShortcut for QueryInterface tests, hr=0x%x\n", hr);
131 }
132
133 static CHAR *set_and_get_url(IUniformResourceLocatorA *urlA, LPCSTR input, DWORD flags)
134 {
135     HRESULT hr;
136     hr = urlA->lpVtbl->SetURL(urlA, input, flags);
137     if (SUCCEEDED(hr))
138     {
139         CHAR *output;
140         hr = urlA->lpVtbl->GetURL(urlA, &output);
141         if (SUCCEEDED(hr))
142             return output;
143         else
144             skip("GetUrl failed, hr=0x%x\n", hr);
145     }
146     else
147         skip("SetUrl (%s, 0x%x) failed, hr=0x%x\n", input, flags, hr);
148     return NULL;
149 }
150
151 static void check_string_transform(IUniformResourceLocatorA *urlA, LPCSTR input, DWORD flags, LPCSTR expectedOutput)
152 {
153     CHAR *output = set_and_get_url(urlA, input, flags);
154     if (output != NULL)
155     {
156         ok(lstrcmpA(output, expectedOutput) == 0, "unexpected URL change %s -> %s (expected %s)\n",
157             input, output, expectedOutput);
158         CoTaskMemFree(output);
159     }
160 }
161
162 static void test_NullURLs(void)
163 {
164     HRESULT hr;
165     IUniformResourceLocatorA *urlA;
166
167     hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&urlA);
168     if (SUCCEEDED(hr))
169     {
170         LPSTR url = NULL;
171
172         hr = urlA->lpVtbl->GetURL(urlA, &url);
173         ok(SUCCEEDED(hr), "getting uninitialized URL unexpectedly failed, hr=0x%x\n", hr);
174         ok(url == NULL, "uninitialized URL is not NULL but %s\n", url);
175
176         hr = urlA->lpVtbl->SetURL(urlA, NULL, 0);
177         ok(SUCCEEDED(hr), "setting NULL URL unexpectedly failed, hr=0x%x\n", hr);
178
179         hr = urlA->lpVtbl->GetURL(urlA, &url);
180         ok(SUCCEEDED(hr), "getting NULL URL unexpectedly failed, hr=0x%x\n", hr);
181         ok(url == NULL, "URL unexpectedly not NULL but %s\n", url);
182
183         urlA->lpVtbl->Release(urlA);
184     }
185     else
186         skip("could not create a CLSID_InternetShortcut for NullURL tests, hr=0x%x\n", hr);
187 }
188
189 static void test_SetURLFlags(void)
190 {
191     HRESULT hr;
192     IUniformResourceLocatorA *urlA;
193
194     hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&urlA);
195     if (SUCCEEDED(hr))
196     {
197         check_string_transform(urlA, "somerandomstring", 0, "somerandomstring");
198         check_string_transform(urlA, "www.winehq.org", 0, "www.winehq.org");
199
200         todo_wine
201         {
202             check_string_transform(urlA, "www.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL, "http://www.winehq.org/");
203             check_string_transform(urlA, "ftp.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL, "ftp://ftp.winehq.org/");
204         }
205
206         urlA->lpVtbl->Release(urlA);
207     }
208     else
209         skip("could not create a CLSID_InternetShortcut for SetUrl tests, hr=0x%x\n", hr);
210 }
211
212 static void test_InternetShortcut(void)
213 {
214     test_Aggregability();
215     test_QueryInterface();
216     test_NullURLs();
217     test_SetURLFlags();
218 }
219
220 START_TEST(intshcut)
221 {
222     OleInitialize(NULL);
223     test_InternetShortcut();
224     OleUninitialize();
225 }