2 * Unit tests for misc shdocvw functions
4 * Copyright 2008 Detlef Riekenberg
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.
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.
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
29 #include "wine/test.h"
31 /* ################ */
33 static HMODULE hshdocvw;
34 static HRESULT (WINAPI *pURLSubRegQueryA)(LPCSTR, LPCSTR, DWORD, LPVOID, DWORD, DWORD);
36 static CHAR appdata[] = "AppData";
37 static CHAR common_appdata[] = "Common AppData";
38 static CHAR default_page_url[] = "Default_Page_URL";
39 static CHAR does_not_exist[] = "does_not_exist";
40 static CHAR regpath_iemain[] = "Software\\Microsoft\\Internet Explorer\\Main";
41 static CHAR regpath_shellfolders[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
42 static CHAR start_page[] = "Start Page";
44 /* ################ */
46 static void init_functions(void)
48 hshdocvw = LoadLibraryA("shdocvw.dll");
49 pURLSubRegQueryA = (void *) GetProcAddress(hshdocvw, (LPSTR) 151);
52 /* ################ */
54 static void test_URLSubRegQueryA(void)
56 CHAR buffer[INTERNET_MAX_URL_LENGTH];
61 if (!pURLSubRegQueryA) {
62 skip("URLSubRegQueryA not found\n");
66 memset(buffer, '#', sizeof(buffer)-1);
67 buffer[sizeof(buffer)-1] = '\0';
68 /* called by inetcpl.cpl */
69 hr = pURLSubRegQueryA(regpath_iemain, default_page_url, REG_SZ, buffer, INTERNET_MAX_URL_LENGTH, -1);
70 ok(hr == E_FAIL || hr == S_OK, "got 0x%x (expected E_FAIL or S_OK)\n", hr);
72 memset(buffer, '#', sizeof(buffer)-1);
73 buffer[sizeof(buffer)-1] = '\0';
74 /* called by inetcpl.cpl */
75 hr = pURLSubRegQueryA(regpath_iemain, start_page, REG_SZ, buffer, INTERNET_MAX_URL_LENGTH, -1);
76 len = lstrlenA(buffer);
77 /* respect privacy: do not dump the url */
78 ok(hr == S_OK, "got 0x%x and %d (expected S_OK)\n", hr, len);
80 /* test buffer length: just large enough */
81 memset(buffer, '#', sizeof(buffer)-1);
82 buffer[sizeof(buffer)-1] = '\0';
83 hr = pURLSubRegQueryA(regpath_iemain, start_page, REG_SZ, buffer, len+1, -1);
84 used = lstrlenA(buffer);
85 /* respect privacy: do not dump the url */
86 ok((hr == S_OK) && (used == len),
87 "got 0x%x and %d (expected S_OK and %d)\n", hr, used, len);
89 /* no space for terminating 0: result is truncated */
90 memset(buffer, '#', sizeof(buffer)-1);
91 buffer[sizeof(buffer)-1] = '\0';
92 hr = pURLSubRegQueryA(regpath_iemain, start_page, REG_SZ, buffer, len, -1);
93 used = lstrlenA(buffer);
94 ok((hr == S_OK) && (used == len - 1),
95 "got 0x%x and %d (expected S_OK and %d)\n", hr, used, len - 1);
97 /* no space for the complete result: truncate another char */
99 memset(buffer, '#', sizeof(buffer)-1);
100 buffer[sizeof(buffer)-1] = '\0';
101 hr = pURLSubRegQueryA(regpath_iemain, start_page, REG_SZ, buffer, len-1, -1);
102 used = lstrlenA(buffer);
103 ok((hr == S_OK) && (used == (len - 2)),
104 "got 0x%x and %d (expected S_OK and %d)\n", hr, used, len - 2);
107 /* only space for the terminating 0: function still succeded */
108 memset(buffer, '#', sizeof(buffer)-1);
109 buffer[sizeof(buffer)-1] = '\0';
110 hr = pURLSubRegQueryA(regpath_iemain, start_page, REG_SZ, buffer, 1, -1);
111 used = lstrlenA(buffer);
112 ok((hr == S_OK) && !used,
113 "got 0x%x and %d (expected S_OK and 0)\n", hr, used);
115 /* size of buffer is 0, but the function still succeed */
116 memset(buffer, '#', sizeof(buffer)-1);
117 buffer[sizeof(buffer)-1] = '\0';
118 hr = pURLSubRegQueryA(regpath_iemain, start_page, REG_SZ, buffer, 0, -1);
119 used = lstrlenA(buffer);
120 ok((hr == S_OK) && (used == INTERNET_MAX_URL_LENGTH - 1), "got 0x%x and %d\n", hr, used);
122 /* still succeed without a buffer for the result */
123 hr = pURLSubRegQueryA(regpath_iemain, start_page, REG_SZ, NULL, 0, -1);
124 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
126 /* still succeed, when a length is given without a buffer */
127 hr = pURLSubRegQueryA(regpath_iemain, start_page, REG_SZ, NULL, INTERNET_MAX_URL_LENGTH, -1);
128 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
130 /* this value does not exist */
131 memset(buffer, '#', sizeof(buffer)-1);
132 buffer[sizeof(buffer)-1] = '\0';
133 hr = pURLSubRegQueryA(regpath_iemain, does_not_exist, REG_SZ, buffer, INTERNET_MAX_URL_LENGTH, -1);
134 /* random bytes are copied to the buffer */
135 ok((hr == E_FAIL), "got 0x%x (expected E_FAIL)\n", hr);
137 /* the third parameter is ignored. Is it really a type? (data is REG_SZ) */
138 memset(buffer, '#', sizeof(buffer)-1);
139 buffer[sizeof(buffer)-1] = '\0';
140 hr = pURLSubRegQueryA(regpath_iemain, start_page, REG_DWORD, buffer, INTERNET_MAX_URL_LENGTH, -1);
141 used = lstrlenA(buffer);
142 ok((hr == S_OK) && (used == len),
143 "got 0x%x and %d (expected S_OK and %d)\n", hr, used, len);
145 /* the function works for HKCU and HKLM */
146 memset(buffer, '#', sizeof(buffer)-1);
147 buffer[sizeof(buffer)-1] = '\0';
148 hr = pURLSubRegQueryA(regpath_shellfolders, appdata, REG_SZ, buffer, INTERNET_MAX_URL_LENGTH, -1);
149 used = lstrlenA(buffer);
150 ok(hr == S_OK, "got 0x%x and %d (expected S_OK)\n", hr, used);
152 memset(buffer, '#', sizeof(buffer)-1);
153 buffer[sizeof(buffer)-1] = '\0';
154 hr = pURLSubRegQueryA(regpath_shellfolders, common_appdata, REG_SZ, buffer, INTERNET_MAX_URL_LENGTH, -1);
155 used = lstrlenA(buffer);
156 ok(hr == S_OK, "got 0x%x and %d (expected S_OK)\n", hr, used);
158 /* todo: what does the last parameter mean? */
161 /* ################ */
166 test_URLSubRegQueryA();