1 /* 2 * Unit tests for Windows property system 3 * 4 * Copyright 2006 Paul Vriens 5 * Copyright 2010 Andrew Nguyen 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 */ 21 22 #define WIN32_NO_STATUS 23 #define _INC_WINDOWS 24 #define COM_NO_WINDOWS_H 25 26 #define COBJMACROS 27 28 //#include <stdarg.h> 29 #include <stdio.h> 30 31 #define NONAMELESSUNION 32 33 #include <windef.h> 34 #include <winbase.h> 35 #include <winreg.h> 36 #include <winnls.h> 37 //#include "objbase.h" 38 #include <ole2.h> 39 #include <initguid.h> 40 #include <propsys.h> 41 #include <propvarutil.h> 42 #include <wine/test.h> 43 44 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); 45 DEFINE_GUID(dummy_guid, 0xdeadbeef, 0xdead, 0xbeef, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0xba, 0xbe); 46 DEFINE_GUID(expect_guid, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12); 47 48 #define GUID_MEMBERS(g) {(g).Data1, (g).Data2, (g).Data3, {(g).Data4[0], (g).Data4[1], (g).Data4[2], (g).Data4[3], (g).Data4[4], (g).Data4[5], (g).Data4[6], (g).Data4[7]}} 49 50 static const char topic[] = "wine topic"; 51 static const WCHAR topicW[] = {'w','i','n','e',' ','t','o','p','i','c',0}; 52 static const WCHAR emptyW[] = {0}; 53 54 static int strcmp_wa(LPCWSTR strw, const char *stra) 55 { 56 CHAR buf[512]; 57 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL); 58 return lstrcmpA(stra, buf); 59 } 60 61 static void test_PSStringFromPropertyKey(void) 62 { 63 static const WCHAR fillerW[] = {'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X', 64 'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X', 65 'X','X','X','X','X','X','X','X','X','X'}; 66 static const WCHAR zero_fillerW[] = {'\0','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X', 67 'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X', 68 'X','X','X','X','X','X','X','X','X','X','X','X','X','X'}; 69 static const WCHAR zero_truncatedW[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0', 70 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0', 71 '0','0','0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'}; 72 static const WCHAR zero_truncated2W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0', 73 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0', 74 '0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'}; 75 static const WCHAR zero_truncated3W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0', 76 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0', 77 '0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'}; 78 static const WCHAR zero_truncated4W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0', 79 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0', 80 '0','0','0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'}; 81 static const WCHAR truncatedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0', 82 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0', 83 '0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'}; 84 static const WCHAR truncated2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0', 85 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0', 86 '0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'}; 87 static const WCHAR truncated3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0', 88 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0', 89 '0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'}; 90 static const WCHAR truncated4W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0', 91 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0', 92 '0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'}; 93 static const WCHAR expectedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0', 94 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0', 95 '0','}',' ','4','2','9','4','9','6','7','2','9','5',0}; 96 static const WCHAR expected2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0', 97 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0', 98 '0','}',' ','1','3','5','7','9','\0','X','X','X','X','X'}; 99 static const WCHAR expected3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0', 100 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0', 101 '0','}',' ','0','\0','X','X','X','X','X','X','X','X','X'}; 102 PROPERTYKEY prop = {GUID_MEMBERS(GUID_NULL), ~0U}; 103 PROPERTYKEY prop2 = {GUID_MEMBERS(GUID_NULL), 13579}; 104 PROPERTYKEY prop3 = {GUID_MEMBERS(GUID_NULL), 0}; 105 WCHAR out[PKEYSTR_MAX]; 106 HRESULT ret; 107 108 const struct 109 { 110 REFPROPERTYKEY pkey; 111 LPWSTR psz; 112 UINT cch; 113 HRESULT hr_expect; 114 const WCHAR *buf_expect; 115 BOOL hr_broken; 116 HRESULT hr2; 117 BOOL buf_broken; 118 const WCHAR *buf2; 119 } testcases[] = 120 { 121 {NULL, NULL, 0, E_POINTER}, 122 {&prop, NULL, 0, E_POINTER}, 123 {&prop, NULL, PKEYSTR_MAX, E_POINTER}, 124 {NULL, out, 0, E_NOT_SUFFICIENT_BUFFER, fillerW}, 125 {NULL, out, PKEYSTR_MAX, E_NOT_SUFFICIENT_BUFFER, zero_fillerW, FALSE, 0, TRUE, fillerW}, 126 {&prop, out, 0, E_NOT_SUFFICIENT_BUFFER, fillerW}, 127 {&prop, out, GUIDSTRING_MAX, E_NOT_SUFFICIENT_BUFFER, fillerW}, 128 {&prop, out, GUIDSTRING_MAX + 1, E_NOT_SUFFICIENT_BUFFER, fillerW}, 129 {&prop, out, GUIDSTRING_MAX + 2, E_NOT_SUFFICIENT_BUFFER, zero_truncatedW, TRUE, S_OK, TRUE, truncatedW}, 130 {&prop, out, PKEYSTR_MAX - 2, E_NOT_SUFFICIENT_BUFFER, zero_truncated2W, TRUE, S_OK, TRUE, truncated2W}, 131 {&prop, out, PKEYSTR_MAX - 1, E_NOT_SUFFICIENT_BUFFER, zero_truncated3W, TRUE, S_OK, TRUE, truncated3W}, 132 {&prop, out, PKEYSTR_MAX, S_OK, expectedW}, 133 {&prop2, out, GUIDSTRING_MAX + 2, E_NOT_SUFFICIENT_BUFFER, zero_truncated4W, TRUE, S_OK, TRUE, truncated4W}, 134 {&prop2, out, GUIDSTRING_MAX + 6, S_OK, expected2W}, 135 {&prop2, out, PKEYSTR_MAX, S_OK, expected2W}, 136 {&prop3, out, GUIDSTRING_MAX + 1, E_NOT_SUFFICIENT_BUFFER, fillerW}, 137 {&prop3, out, GUIDSTRING_MAX + 2, S_OK, expected3W}, 138 {&prop3, out, PKEYSTR_MAX, S_OK, expected3W}, 139 }; 140 141 int i; 142 143 for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++) 144 { 145 if (testcases[i].psz) 146 memcpy(testcases[i].psz, fillerW, PKEYSTR_MAX * sizeof(WCHAR)); 147 148 ret = PSStringFromPropertyKey(testcases[i].pkey, 149 testcases[i].psz, 150 testcases[i].cch); 151 ok(ret == testcases[i].hr_expect || 152 broken(testcases[i].hr_broken && ret == testcases[i].hr2), /* Vista/Win2k8 */ 153 "[%d] Expected PSStringFromPropertyKey to return 0x%08x, got 0x%08x\n", 154 i, testcases[i].hr_expect, ret); 155 156 if (testcases[i].psz) 157 ok(!memcmp(testcases[i].psz, testcases[i].buf_expect, PKEYSTR_MAX * sizeof(WCHAR)) || 158 broken(testcases[i].buf_broken && 159 !memcmp(testcases[i].psz, testcases[i].buf2, PKEYSTR_MAX * sizeof(WCHAR))), /* Vista/Win2k8 */ 160 "[%d] Unexpected output contents\n", i); 161 } 162 } 163 164 static void test_PSPropertyKeyFromString(void) 165 { 166 static const WCHAR fmtid_clsidW[] = {'S','t','d','F','o','n','t',' ','1',0}; 167 static const WCHAR fmtid_truncatedW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 168 '1','2','3','4','-',0}; 169 static const WCHAR fmtid_nobracketsW[] = {'1','2','3','4','5','6','7','8','-','1','2','3','4','-', 170 '1','2','3','4','-','1','2','3','4','-', 171 '1','2','3','4','5','6','7','8','9','0','1','2',0}; 172 static const WCHAR fmtid_badbracketW[] = {'X','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 173 '1','2','3','4','-','1','2','3','4','-', 174 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 175 static const WCHAR fmtid_badcharW[] = {'{','X','2','3','4','5','6','7','8','-','1','2','3','4','-', 176 '1','2','3','4','-','1','2','3','4','-', 177 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 178 static const WCHAR fmtid_badchar2W[] = {'{','1','2','3','4','5','6','7','X','-','1','2','3','4','-', 179 '1','2','3','4','-','1','2','3','4','-', 180 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 181 static const WCHAR fmtid_baddashW[] = {'{','1','2','3','4','5','6','7','8','X','1','2','3','4','-', 182 '1','2','3','4','-','1','2','3','4','-', 183 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 184 static const WCHAR fmtid_badchar3W[] = {'{','1','2','3','4','5','6','7','8','-','X','2','3','4','-', 185 '1','2','3','4','-','1','2','3','4','-', 186 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 187 static const WCHAR fmtid_badchar4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','X','-', 188 '1','2','3','4','-','1','2','3','4','-', 189 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 190 static const WCHAR fmtid_baddash2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','X', 191 '1','2','3','4','-','1','2','3','4','-', 192 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 193 static const WCHAR fmtid_badchar5W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 194 'X','2','3','4','-','1','2','3','4','-', 195 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 196 static const WCHAR fmtid_badchar6W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 197 '1','2','3','X','-','1','2','3','4','-', 198 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 199 static const WCHAR fmtid_baddash3W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 200 '1','2','3','4','X','1','2','3','4','-', 201 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 202 static const WCHAR fmtid_badchar7W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 203 '1','2','3','4','-','X','2','3','4','-', 204 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 205 static const WCHAR fmtid_badchar8W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 206 '1','2','3','4','-','1','2','3','X','-', 207 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 208 static const WCHAR fmtid_baddash4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 209 '1','2','3','4','-','1','2','3','4','X', 210 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 211 static const WCHAR fmtid_badchar9W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 212 '1','2','3','4','-','1','2','3','4','-', 213 'X','2','3','4','5','6','7','8','9','0','1','2','}',0}; 214 static const WCHAR fmtid_badchar9_adjW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 215 '1','2','3','4','-','1','2','3','4','-', 216 '1','X','3','4','5','6','7','8','9','0','1','2','}',0}; 217 static const WCHAR fmtid_badchar10W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 218 '1','2','3','4','-','1','2','3','4','-', 219 '1','2','X','4','5','6','7','8','9','0','1','2','}',0}; 220 static const WCHAR fmtid_badchar11W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 221 '1','2','3','4','-','1','2','3','4','-', 222 '1','2','3','4','X','6','7','8','9','0','1','2','}',0}; 223 static const WCHAR fmtid_badchar12W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 224 '1','2','3','4','-','1','2','3','4','-', 225 '1','2','3','4','5','6','X','8','9','0','1','2','}',0}; 226 static const WCHAR fmtid_badchar13W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 227 '1','2','3','4','-','1','2','3','4','-', 228 '1','2','3','4','5','6','7','8','X','0','1','2','}',0}; 229 static const WCHAR fmtid_badchar14W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 230 '1','2','3','4','-','1','2','3','4','-', 231 '1','2','3','4','5','6','7','8','9','0','X','2','}',0}; 232 static const WCHAR fmtid_badbracket2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 233 '1','2','3','4','-','1','2','3','4','-', 234 '1','2','3','4','5','6','7','8','9','0','1','2','X',0}; 235 static const WCHAR fmtid_spaceW[] = {' ','{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 236 '1','2','3','4','-','1','2','3','4','-', 237 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 238 static const WCHAR fmtid_spaceendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 239 '1','2','3','4','-','1','2','3','4','-', 240 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',0}; 241 static const WCHAR fmtid_spacesendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 242 '1','2','3','4','-','1','2','3','4','-', 243 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ',0}; 244 static const WCHAR fmtid_nopidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 245 '1','2','3','4','-','1','2','3','4','-', 246 '1','2','3','4','5','6','7','8','9','0','1','2','}',0}; 247 static const WCHAR fmtid_badpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 248 '1','2','3','4','-','1','2','3','4','-', 249 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','D','E','A','D',0}; 250 static const WCHAR fmtid_adjpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 251 '1','2','3','4','-','1','2','3','4','-', 252 '1','2','3','4','5','6','7','8','9','0','1','2','}','1','3','5','7','9',0}; 253 static const WCHAR fmtid_spacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 254 '1','2','3','4','-','1','2','3','4','-', 255 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ','1','3','5','7','9',0}; 256 static const WCHAR fmtid_negpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 257 '1','2','3','4','-','1','2','3','4','-', 258 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','1','3','5','7','9',0}; 259 static const WCHAR fmtid_negnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 260 '1','2','3','4','-','1','2','3','4','-', 261 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','1','3','5','7','9',0}; 262 static const WCHAR fmtid_negnegnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 263 '1','2','3','4','-','1','2','3','4','-', 264 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','-','1','3','5','7','9',0}; 265 static const WCHAR fmtid_negspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 266 '1','2','3','4','-','1','2','3','4','-', 267 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','1','3','5','7','9',0}; 268 static const WCHAR fmtid_negspacenegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 269 '1','2','3','4','-','1','2','3','4','-', 270 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-','1','3','5','7','9',0}; 271 static const WCHAR fmtid_negspacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 272 '1','2','3','4','-','1','2','3','4','-', 273 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-',' ','-','1','3','5','7','9',0}; 274 static const WCHAR fmtid_pospidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 275 '1','2','3','4','-','1','2','3','4','-', 276 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','1','3','5','7','9',0}; 277 static const WCHAR fmtid_posnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 278 '1','2','3','4','-','1','2','3','4','-', 279 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','-','+','-','1','3','5','7','9',0}; 280 static const WCHAR fmtid_symbolpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 281 '1','2','3','4','-','1','2','3','4','-', 282 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','/','$','-','1','3','5','7','9',0}; 283 static const WCHAR fmtid_letterpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 284 '1','2','3','4','-','1','2','3','4','-', 285 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','B','C','D','1','3','5','7','9',0}; 286 static const WCHAR fmtid_spacepadpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 287 '1','2','3','4','-','1','2','3','4','-', 288 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',' ',' ',' ',0}; 289 static const WCHAR fmtid_spacemixpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 290 '1','2','3','4','-','1','2','3','4','-', 291 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1',' ','3',' ','5','7','9',' ',' ',' ',0}; 292 static const WCHAR fmtid_tabpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 293 '1','2','3','4','-','1','2','3','4','-', 294 '1','2','3','4','5','6','7','8','9','0','1','2','}','\t','1','3','5','7','9',0}; 295 static const WCHAR fmtid_hexpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 296 '1','2','3','4','-','1','2','3','4','-', 297 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','0','x','D','E','A','D',0}; 298 static const WCHAR fmtid_mixedpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 299 '1','2','3','4','-','1','2','3','4','-', 300 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','9','B','5','C','3','D','1',0}; 301 static const WCHAR fmtid_overflowpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 302 '1','2','3','4','-','1','2','3','4','-', 303 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','2','3','4','5','6','7','8','9','0','1',0}; 304 static const WCHAR fmtid_commapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 305 '1','2','3','4','-','1','2','3','4','-', 306 '1','2','3','4','5','6','7','8','9','0','1','2','}',',','1','3','5','7','9',0}; 307 static const WCHAR fmtid_commaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 308 '1','2','3','4','-','1','2','3','4','-', 309 '1','2','3','4','5','6','7','8','9','0','1','2','}',',',',',',','1','3','5','7','9',0}; 310 static const WCHAR fmtid_commaspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 311 '1','2','3','4','-','1','2','3','4','-', 312 '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','1','3','5','7','9',0}; 313 static const WCHAR fmtid_spacecommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 314 '1','2','3','4','-','1','2','3','4','-', 315 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','1','3','5','7','9',0}; 316 static const WCHAR fmtid_spccommaspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 317 '1','2','3','4','-','1','2','3','4','-', 318 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','1','3','5','7','9',0}; 319 static const WCHAR fmtid_spacescommaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 320 '1','2','3','4','-','1','2','3','4','-', 321 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ',',','1','3','5','7','9',0}; 322 static const WCHAR fmtid_commanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 323 '1','2','3','4','-','1','2','3','4','-', 324 '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-','1','3','5','7','9',0}; 325 static const WCHAR fmtid_spccommanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 326 '1','2','3','4','-','1','2','3','4','-', 327 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','-','1','3','5','7','9',0}; 328 static const WCHAR fmtid_commaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 329 '1','2','3','4','-','1','2','3','4','-', 330 '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','-','1','3','5','7','9',0}; 331 static const WCHAR fmtid_spccommaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 332 '1','2','3','4','-','1','2','3','4','-', 333 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','-','1','3','5','7','9',0}; 334 static const WCHAR fmtid_commanegspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 335 '1','2','3','4','-','1','2','3','4','-', 336 '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-',' ','1','3','5','7','9',0}; 337 static const WCHAR fmtid_negcommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 338 '1','2','3','4','-','1','2','3','4','-', 339 '1','2','3','4','5','6','7','8','9','0','1','2','}','-',',','1','3','5','7','9',0}; 340 static const WCHAR fmtid_normalpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', 341 '1','2','3','4','-','1','2','3','4','-', 342 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',0}; 343 PROPERTYKEY out_init = {GUID_MEMBERS(dummy_guid), 0xdeadbeef}; 344 PROPERTYKEY out; 345 HRESULT ret; 346 347 const struct 348 { 349 LPCWSTR pwzString; 350 PROPERTYKEY *pkey; 351 HRESULT hr_expect; 352 PROPERTYKEY pkey_expect; 353 } testcases[] = 354 { 355 {NULL, NULL, E_POINTER}, 356 {NULL, &out, E_POINTER, {GUID_MEMBERS(out_init.fmtid), out_init.pid}}, 357 {emptyW, NULL, E_POINTER}, 358 {emptyW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}}, 359 {fmtid_clsidW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}}, 360 {fmtid_truncatedW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}}, 361 {fmtid_nobracketsW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}}, 362 {fmtid_badbracketW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}}, 363 {fmtid_badcharW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}}, 364 {fmtid_badchar2W, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}}, 365 {fmtid_baddashW, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}}, 366 {fmtid_badchar3W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}}, 367 {fmtid_badchar4W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}}, 368 {fmtid_baddash2W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}}, 369 {fmtid_badchar5W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}}, 370 {fmtid_badchar6W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}}, 371 {fmtid_baddash3W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}}, 372 {fmtid_badchar7W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}}, 373 {fmtid_badchar8W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}}, 374 {fmtid_baddash4W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}}, 375 {fmtid_badchar9W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}}, 376 {fmtid_badchar9_adjW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}}, 377 {fmtid_badchar10W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0,0,0,0,0}}, 0}}, 378 {fmtid_badchar11W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0,0,0,0}}, 0}}, 379 {fmtid_badchar12W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0,0,0}}, 0}}, 380 {fmtid_badchar13W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0,0}}, 0}}, 381 {fmtid_badchar14W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0}}, 0}}, 382 {fmtid_badbracket2W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x00}}, 0 }}, 383 {fmtid_spaceW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0 }}, 384 {fmtid_spaceendW, &out, E_INVALIDARG, {GUID_MEMBERS(expect_guid), 0}}, 385 {fmtid_spacesendW, &out, E_INVALIDARG, {GUID_MEMBERS(expect_guid), 0}}, 386 {fmtid_nopidW, &out, E_INVALIDARG, {GUID_MEMBERS(expect_guid), 0}}, 387 {fmtid_badpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 388 {fmtid_adjpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 389 {fmtid_spacespidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 390 {fmtid_negpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 391 {fmtid_negnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}}, 392 {fmtid_negnegnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 393 {fmtid_negspacepidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 394 {fmtid_negspacenegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}}, 395 {fmtid_negspacespidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 396 {fmtid_pospidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 397 {fmtid_posnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 398 {fmtid_symbolpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 399 {fmtid_letterpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 400 {fmtid_spacepadpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 401 {fmtid_spacemixpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 1}}, 402 {fmtid_tabpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 403 {fmtid_hexpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 404 {fmtid_mixedpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 405 {fmtid_overflowpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 3755744309U}}, 406 {fmtid_commapidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 407 {fmtid_commaspidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 408 {fmtid_commaspacepidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 409 {fmtid_spacecommapidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 410 {fmtid_spccommaspcpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 411 {fmtid_spacescommaspidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 412 {fmtid_commanegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}}, 413 {fmtid_spccommanegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}}, 414 {fmtid_commaspcnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}}, 415 {fmtid_spccommaspcnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}}, 416 {fmtid_commanegspcpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0U}}, 417 {fmtid_negcommapidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, 418 {fmtid_normalpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, 419 }; 420 421 int i; 422 423 for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++) 424 { 425 if (testcases[i].pkey) 426 *testcases[i].pkey = out_init; 427 428 ret = PSPropertyKeyFromString(testcases[i].pwzString, testcases[i].pkey); 429 ok(ret == testcases[i].hr_expect, 430 "[%d] Expected PSPropertyKeyFromString to return 0x%08x, got 0x%08x\n", 431 i, testcases[i].hr_expect, ret); 432 433 if (testcases[i].pkey) 434 { 435 ok(IsEqualGUID(&testcases[i].pkey->fmtid, &testcases[i].pkey_expect.fmtid), 436 "[%d] Expected GUID %s, got %s\n", 437 i, wine_dbgstr_guid(&testcases[i].pkey_expect.fmtid), wine_dbgstr_guid(&testcases[i].pkey->fmtid)); 438 ok(testcases[i].pkey->pid == testcases[i].pkey_expect.pid, 439 "[%d] Expected property ID %u, got %u\n", 440 i, testcases[i].pkey_expect.pid, testcases[i].pkey->pid); 441 } 442 } 443 } 444 445 static void test_PSRefreshPropertySchema(void) 446 { 447 HRESULT ret; 448 449 ret = PSRefreshPropertySchema(); 450 todo_wine 451 ok(ret == CO_E_NOTINITIALIZED, 452 "Expected PSRefreshPropertySchema to return CO_E_NOTINITIALIZED, got 0x%08x\n", ret); 453 454 CoInitialize(NULL); 455 456 ret = PSRefreshPropertySchema(); 457 ok(ret == S_OK, 458 "Expected PSRefreshPropertySchema to return S_OK, got 0x%08x\n", ret); 459 460 CoUninitialize(); 461 } 462 463 static void test_InitPropVariantFromGUIDAsString(void) 464 { 465 PROPVARIANT propvar; 466 VARIANT var; 467 HRESULT hres; 468 int i; 469 470 const struct { 471 REFGUID guid; 472 const char *str; 473 } testcases[] = { 474 {&IID_NULL, "{00000000-0000-0000-0000-000000000000}" }, 475 {&dummy_guid, "{DEADBEEF-DEAD-BEEF-DEAD-BEEFCAFEBABE}" }, 476 }; 477 478 hres = InitPropVariantFromGUIDAsString(NULL, &propvar); 479 ok(hres == E_FAIL, "InitPropVariantFromGUIDAsString returned %x\n", hres); 480 481 if(0) { 482 /* Returns strange data on Win7, crashes on older systems */ 483 InitVariantFromGUIDAsString(NULL, &var); 484 485 /* Crashes on windows */ 486 InitPropVariantFromGUIDAsString(&IID_NULL, NULL); 487 InitVariantFromGUIDAsString(&IID_NULL, NULL); 488 } 489 490 for(i=0; i<sizeof(testcases)/sizeof(testcases[0]); i++) { 491 memset(&propvar, 0, sizeof(PROPVARIANT)); 492 hres = InitPropVariantFromGUIDAsString(testcases[i].guid, &propvar); 493 ok(hres == S_OK, "%d) InitPropVariantFromGUIDAsString returned %x\n", i, hres); 494 ok(propvar.vt == VT_LPWSTR, "%d) propvar.vt = %d\n", i, propvar.vt); 495 ok(!strcmp_wa(propvar.u.pwszVal, testcases[i].str), "%d) propvar.u.pwszVal = %s\n", 496 i, wine_dbgstr_w(propvar.u.pwszVal)); 497 CoTaskMemFree(propvar.u.pwszVal); 498 499 memset(&var, 0, sizeof(VARIANT)); 500 hres = InitVariantFromGUIDAsString(testcases[i].guid, &var); 501 ok(hres == S_OK, "%d) InitVariantFromGUIDAsString returned %x\n", i, hres); 502 ok(V_VT(&var) == VT_BSTR, "%d) V_VT(&var) = %d\n", i, V_VT(&var)); 503 ok(SysStringLen(V_BSTR(&var)) == 38, "SysStringLen returned %d\n", 504 SysStringLen(V_BSTR(&var))); 505 ok(!strcmp_wa(V_BSTR(&var), testcases[i].str), "%d) V_BSTR(&var) = %s\n", 506 i, wine_dbgstr_w(V_BSTR(&var))); 507 VariantClear(&var); 508 } 509 } 510 511 static void test_InitPropVariantFromBuffer(void) 512 { 513 static const char data_in[] = "test"; 514 PROPVARIANT propvar; 515 VARIANT var; 516 HRESULT hres; 517 void *data_out; 518 LONG size; 519 520 hres = InitPropVariantFromBuffer(NULL, 0, &propvar); 521 ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres); 522 ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt); 523 ok(propvar.u.caub.cElems == 0, "cElems = %d\n", propvar.u.caub.cElems == 0); 524 PropVariantClear(&propvar); 525 526 hres = InitPropVariantFromBuffer(data_in, 4, &propvar); 527 ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres); 528 ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt); 529 ok(propvar.u.caub.cElems == 4, "cElems = %d\n", propvar.u.caub.cElems == 0); 530 ok(!memcmp(propvar.u.caub.pElems, data_in, 4), "Data inside array is incorrect\n"); 531 PropVariantClear(&propvar); 532 533 hres = InitVariantFromBuffer(NULL, 0, &var); 534 ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres); 535 ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var)); 536 size = SafeArrayGetDim(V_ARRAY(&var)); 537 ok(size == 1, "SafeArrayGetDim returned %d\n", size); 538 hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size); 539 ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres); 540 ok(size == 0, "LBound = %d\n", size); 541 hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size); 542 ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres); 543 ok(size == -1, "UBound = %d\n", size); 544 VariantClear(&var); 545 546 hres = InitVariantFromBuffer(data_in, 4, &var); 547 ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres); 548 ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var)); 549 size = SafeArrayGetDim(V_ARRAY(&var)); 550 ok(size == 1, "SafeArrayGetDim returned %d\n", size); 551 hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size); 552 ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres); 553 ok(size == 0, "LBound = %d\n", size); 554 hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size); 555 ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres); 556 ok(size == 3, "UBound = %d\n", size); 557 hres = SafeArrayAccessData(V_ARRAY(&var), &data_out); 558 ok(hres == S_OK, "SafeArrayAccessData failed %x\n", hres); 559 ok(!memcmp(data_in, data_out, 4), "Data inside safe array is incorrect\n"); 560 hres = SafeArrayUnaccessData(V_ARRAY(&var)); 561 ok(hres == S_OK, "SafeArrayUnaccessData failed %x\n", hres); 562 VariantClear(&var); 563 } 564 565 static void test_PropVariantToGUID(void) 566 { 567 PROPVARIANT propvar; 568 VARIANT var; 569 GUID guid; 570 HRESULT hres; 571 572 hres = InitPropVariantFromGUIDAsString(&IID_NULL, &propvar); 573 ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %x\n", hres); 574 575 hres = PropVariantToGUID(&propvar, &guid); 576 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres); 577 ok(!memcmp(&IID_NULL, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); 578 PropVariantClear(&propvar); 579 580 hres = InitPropVariantFromGUIDAsString(&dummy_guid, &propvar); 581 ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %x\n", hres); 582 583 hres = PropVariantToGUID(&propvar, &guid); 584 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres); 585 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); 586 587 ok(propvar.vt == VT_LPWSTR, "incorrect PROPVARIANT type: %d\n", propvar.vt); 588 propvar.u.pwszVal[1] = 'd'; 589 propvar.u.pwszVal[2] = 'E'; 590 propvar.u.pwszVal[3] = 'a'; 591 hres = PropVariantToGUID(&propvar, &guid); 592 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres); 593 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); 594 595 propvar.u.pwszVal[1] = 'z'; 596 hres = PropVariantToGUID(&propvar, &guid); 597 ok(hres == E_INVALIDARG, "PropVariantToGUID returned %x\n", hres); 598 PropVariantClear(&propvar); 599 600 601 hres = InitVariantFromGUIDAsString(&IID_NULL, &var); 602 ok(hres == S_OK, "InitVariantFromGUIDAsString failed %x\n", hres); 603 604 hres = VariantToGUID(&var, &guid); 605 ok(hres == S_OK, "VariantToGUID failed %x\n", hres); 606 ok(!memcmp(&IID_NULL, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); 607 VariantClear(&var); 608 609 hres = InitVariantFromGUIDAsString(&dummy_guid, &var); 610 ok(hres == S_OK, "InitVariantFromGUIDAsString failed %x\n", hres); 611 612 hres = VariantToGUID(&var, &guid); 613 ok(hres == S_OK, "VariantToGUID failed %x\n", hres); 614 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); 615 616 ok(V_VT(&var) == VT_BSTR, "incorrect VARIANT type: %d\n", V_VT(&var)); 617 V_BSTR(&var)[1] = 'z'; 618 hres = VariantToGUID(&var, &guid); 619 ok(hres == E_FAIL, "VariantToGUID returned %x\n", hres); 620 621 V_BSTR(&var)[1] = 'd'; 622 propvar.vt = V_VT(&var); 623 propvar.u.bstrVal = V_BSTR(&var); 624 V_VT(&var) = VT_EMPTY; 625 hres = PropVariantToGUID(&propvar, &guid); 626 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres); 627 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); 628 PropVariantClear(&propvar); 629 } 630 631 static void test_PropVariantToStringAlloc(void) 632 { 633 PROPVARIANT prop; 634 WCHAR *str; 635 HRESULT hres; 636 637 prop.vt = VT_NULL; 638 hres = PropVariantToStringAlloc(&prop, &str); 639 ok(hres == S_OK, "returned %x\n", hres); 640 ok(!lstrcmpW(str, emptyW), "got %s\n", wine_dbgstr_w(str)); 641 CoTaskMemFree(str); 642 643 prop.vt = VT_LPSTR; 644 prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1); 645 strcpy(prop.u.pszVal, topic); 646 hres = PropVariantToStringAlloc(&prop, &str); 647 ok(hres == S_OK, "returned %x\n", hres); 648 ok(!lstrcmpW(str, topicW), "got %s\n", wine_dbgstr_w(str)); 649 CoTaskMemFree(str); 650 PropVariantClear(&prop); 651 } 652 653 static void test_PropVariantCompare(void) 654 { 655 PROPVARIANT empty, null, emptyarray, i2_0, i2_2, i4_large, i4_largeneg, i4_2, str_2, str_02, str_b; 656 INT res; 657 static const WCHAR str_2W[] = {'2', 0}; 658 static const WCHAR str_02W[] = {'0', '2', 0}; 659 static const WCHAR str_bW[] = {'b', 0}; 660 SAFEARRAY emptysafearray; 661 662 PropVariantInit(&empty); 663 PropVariantInit(&null); 664 PropVariantInit(&emptyarray); 665 PropVariantInit(&i2_0); 666 PropVariantInit(&i2_2); 667 PropVariantInit(&i4_large); 668 PropVariantInit(&i4_largeneg); 669 PropVariantInit(&i4_2); 670 PropVariantInit(&str_2); 671 PropVariantInit(&str_b); 672 673 empty.vt = VT_EMPTY; 674 null.vt = VT_NULL; 675 emptyarray.vt = VT_ARRAY | VT_I4; 676 emptyarray.u.parray = &emptysafearray; 677 emptysafearray.cDims = 1; 678 emptysafearray.fFeatures = FADF_FIXEDSIZE; 679 emptysafearray.cbElements = 4; 680 emptysafearray.cLocks = 0; 681 emptysafearray.pvData = NULL; 682 emptysafearray.rgsabound[0].cElements = 0; 683 emptysafearray.rgsabound[0].lLbound = 0; 684 i2_0.vt = VT_I2; 685 i2_0.u.iVal = 0; 686 i2_2.vt = VT_I2; 687 i2_2.u.iVal = 2; 688 i4_large.vt = VT_I4; 689 i4_large.u.lVal = 65536; 690 i4_largeneg.vt = VT_I4; 691 i4_largeneg.u.lVal = -65536; 692 i4_2.vt = VT_I4; 693 i4_2.u.lVal = 2; 694 str_2.vt = VT_BSTR; 695 str_2.u.bstrVal = SysAllocString(str_2W); 696 str_02.vt = VT_BSTR; 697 str_02.u.bstrVal = SysAllocString(str_02W); 698 str_b.vt = VT_BSTR; 699 str_b.u.bstrVal = SysAllocString(str_bW); 700 701 res = PropVariantCompareEx(&empty, &empty, 0, 0); 702 ok(res == 0, "res=%i\n", res); 703 704 res = PropVariantCompareEx(&empty, &null, 0, 0); 705 ok(res == 0, "res=%i\n", res); 706 707 res = PropVariantCompareEx(&null, &emptyarray, 0, 0); 708 ok(res == 0, "res=%i\n", res); 709 710 res = PropVariantCompareEx(&null, &i2_0, 0, 0); 711 ok(res == -1, "res=%i\n", res); 712 713 res = PropVariantCompareEx(&i2_0, &null, 0, 0); 714 ok(res == 1, "res=%i\n", res); 715 716 res = PropVariantCompareEx(&null, &i2_0, 0, PVCF_TREATEMPTYASGREATERTHAN); 717 ok(res == 1, "res=%i\n", res); 718 719 res = PropVariantCompareEx(&i2_0, &null, 0, PVCF_TREATEMPTYASGREATERTHAN); 720 ok(res == -1, "res=%i\n", res); 721 722 res = PropVariantCompareEx(&i2_2, &i2_0, 0, 0); 723 ok(res == 1, "res=%i\n", res); 724 725 res = PropVariantCompareEx(&i2_0, &i2_2, 0, 0); 726 ok(res == -1, "res=%i\n", res); 727 728 /* Always return -1 if second value cannot be converted to first type */ 729 res = PropVariantCompareEx(&i2_0, &i4_large, 0, 0); 730 ok(res == -1, "res=%i\n", res); 731 732 res = PropVariantCompareEx(&i2_0, &i4_largeneg, 0, 0); 733 ok(res == -1, "res=%i\n", res); 734 735 res = PropVariantCompareEx(&i4_large, &i2_0, 0, 0); 736 ok(res == 1, "res=%i\n", res); 737 738 res = PropVariantCompareEx(&i4_largeneg, &i2_0, 0, 0); 739 ok(res == -1, "res=%i\n", res); 740 741 res = PropVariantCompareEx(&i2_2, &i4_2, 0, 0); 742 ok(res == 0, "res=%i\n", res); 743 744 res = PropVariantCompareEx(&i2_2, &str_2, 0, 0); 745 ok(res == 0, "res=%i\n", res); 746 747 res = PropVariantCompareEx(&i2_2, &str_02, 0, 0); 748 ok(res == 0, "res=%i\n", res); 749 750 res = PropVariantCompareEx(&str_2, &i2_2, 0, 0); 751 todo_wine ok(res == 0, "res=%i\n", res); 752 753 res = PropVariantCompareEx(&str_02, &i2_2, 0, 0); 754 ok(res == -1, "res=%i\n", res); 755 756 res = PropVariantCompareEx(&str_02, &str_2, 0, 0); 757 ok(res == -1, "res=%i\n", res); 758 759 res = PropVariantCompareEx(&str_02, &str_b, 0, 0); 760 ok(res == -1, "res=%i\n", res); 761 762 res = PropVariantCompareEx(&str_2, &str_02, 0, 0); 763 ok(res == 1, "res=%i\n", res); 764 765 res = PropVariantCompareEx(&i4_large, &str_b, 0, 0); 766 todo_wine ok(res == -5 /* ??? */, "res=%i\n", res); 767 768 SysFreeString(str_2.u.bstrVal); 769 SysFreeString(str_02.u.bstrVal); 770 SysFreeString(str_b.u.bstrVal); 771 } 772 773 static void test_intconversions(void) 774 { 775 PROPVARIANT propvar; 776 SHORT sval; 777 USHORT usval; 778 LONG lval; 779 ULONG ulval; 780 LONGLONG llval; 781 ULONGLONG ullval; 782 HRESULT hr; 783 784 propvar.vt = 0xdead; 785 hr = PropVariantClear(&propvar); 786 ok (FAILED(hr), "PropVariantClear fails on invalid vt.\n"); 787 788 propvar.vt = VT_I8; 789 PropVariantClear(&propvar); 790 791 propvar.vt = VT_I8; 792 propvar.u.hVal.QuadPart = (ULONGLONG)1 << 63; 793 794 hr = PropVariantToInt64(&propvar, &llval); 795 ok(hr == S_OK, "hr=%x\n", hr); 796 ok(llval == (ULONGLONG)1 << 63, "got wrong value %s\n", wine_dbgstr_longlong(llval)); 797 798 hr = PropVariantToUInt64(&propvar, &ullval); 799 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); 800 801 hr = PropVariantToInt32(&propvar, &lval); 802 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); 803 804 hr = PropVariantToUInt32(&propvar, &ulval); 805 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); 806 807 hr = PropVariantToInt16(&propvar, &sval); 808 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); 809 810 hr = PropVariantToUInt16(&propvar, &usval); 811 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); 812 813 propvar.vt = VT_UI8; 814 propvar.u.uhVal.QuadPart = 5; 815 816 hr = PropVariantToInt64(&propvar, &llval); 817 ok(hr == S_OK, "hr=%x\n", hr); 818 ok(llval == 5, "got wrong value %s\n", wine_dbgstr_longlong(llval)); 819 820 hr = PropVariantToUInt64(&propvar, &ullval); 821 ok(hr == S_OK, "hr=%x\n", hr); 822 ok(ullval == 5, "got wrong value %s\n", wine_dbgstr_longlong(ullval)); 823 824 hr = PropVariantToInt32(&propvar, &lval); 825 ok(hr == S_OK, "hr=%x\n", hr); 826 ok(lval == 5, "got wrong value %d\n", lval); 827 828 hr = PropVariantToUInt32(&propvar, &ulval); 829 ok(hr == S_OK, "hr=%x\n", hr); 830 ok(ulval == 5, "got wrong value %d\n", ulval); 831 832 hr = PropVariantToInt16(&propvar, &sval); 833 ok(hr == S_OK, "hr=%x\n", hr); 834 ok(sval == 5, "got wrong value %d\n", sval); 835 836 hr = PropVariantToUInt16(&propvar, &usval); 837 ok(hr == S_OK, "hr=%x\n", hr); 838 ok(usval == 5, "got wrong value %d\n", usval); 839 840 propvar.vt = VT_I8; 841 propvar.u.hVal.QuadPart = -5; 842 843 hr = PropVariantToInt64(&propvar, &llval); 844 ok(hr == S_OK, "hr=%x\n", hr); 845 ok(llval == -5, "got wrong value %s\n", wine_dbgstr_longlong(llval)); 846 847 hr = PropVariantToUInt64(&propvar, &ullval); 848 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); 849 850 hr = PropVariantToInt32(&propvar, &lval); 851 ok(hr == S_OK, "hr=%x\n", hr); 852 ok(lval == -5, "got wrong value %d\n", lval); 853 854 hr = PropVariantToUInt32(&propvar, &ulval); 855 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); 856 857 hr = PropVariantToInt16(&propvar, &sval); 858 ok(hr == S_OK, "hr=%x\n", hr); 859 ok(sval == -5, "got wrong value %d\n", sval); 860 861 hr = PropVariantToUInt16(&propvar, &usval); 862 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); 863 864 propvar.vt = VT_UI4; 865 propvar.u.ulVal = 6; 866 867 hr = PropVariantToInt64(&propvar, &llval); 868 ok(hr == S_OK, "hr=%x\n", hr); 869 ok(llval == 6, "got wrong value %s\n", wine_dbgstr_longlong(llval)); 870 871 propvar.vt = VT_I4; 872 propvar.u.lVal = -6; 873 874 hr = PropVariantToInt64(&propvar, &llval); 875 ok(hr == S_OK, "hr=%x\n", hr); 876 ok(llval == -6, "got wrong value %s\n", wine_dbgstr_longlong(llval)); 877 878 propvar.vt = VT_UI2; 879 propvar.u.uiVal = 7; 880 881 hr = PropVariantToInt64(&propvar, &llval); 882 ok(hr == S_OK, "hr=%x\n", hr); 883 ok(llval == 7, "got wrong value %s\n", wine_dbgstr_longlong(llval)); 884 885 propvar.vt = VT_I2; 886 propvar.u.iVal = -7; 887 888 hr = PropVariantToInt64(&propvar, &llval); 889 ok(hr == S_OK, "hr=%x\n", hr); 890 ok(llval == -7, "got wrong value %s\n", wine_dbgstr_longlong(llval)); 891 } 892 893 static void test_PropVariantChangeType_LPWSTR(void) 894 { 895 PROPVARIANT dest, src; 896 HRESULT hr; 897 898 PropVariantInit(&dest); 899 900 src.vt = VT_NULL; 901 hr = PropVariantChangeType(&dest, &src, 0, VT_LPWSTR); 902 ok(hr == S_OK, "hr=%x\n", hr); 903 ok(dest.vt == VT_LPWSTR, "got %d\n", dest.vt); 904 ok(!lstrcmpW(dest.u.pwszVal, emptyW), "got %s\n", wine_dbgstr_w(dest.u.pwszVal)); 905 PropVariantClear(&dest); 906 PropVariantClear(&src); 907 908 src.vt = VT_LPSTR; 909 src.u.pszVal = CoTaskMemAlloc(strlen(topic)+1); 910 strcpy(src.u.pszVal, topic); 911 hr = PropVariantChangeType(&dest, &src, 0, VT_LPWSTR); 912 ok(hr == S_OK, "hr=%x\n", hr); 913 ok(dest.vt == VT_LPWSTR, "got %d\n", dest.vt); 914 ok(!lstrcmpW(dest.u.pwszVal, topicW), "got %s\n", wine_dbgstr_w(dest.u.pwszVal)); 915 PropVariantClear(&dest); 916 PropVariantClear(&src); 917 918 src.vt = VT_LPWSTR; 919 src.u.pwszVal = CoTaskMemAlloc( (lstrlenW(topicW)+1) * sizeof(WCHAR)); 920 lstrcpyW(src.u.pwszVal, topicW); 921 hr = PropVariantChangeType(&dest, &src, 0, VT_LPWSTR); 922 ok(hr == S_OK, "hr=%x\n", hr); 923 ok(dest.vt == VT_LPWSTR, "got %d\n", dest.vt); 924 ok(!lstrcmpW(dest.u.pwszVal, topicW), "got %s\n", wine_dbgstr_w(dest.u.pwszVal)); 925 PropVariantClear(&dest); 926 PropVariantClear(&src); 927 } 928 929 START_TEST(propsys) 930 { 931 test_PSStringFromPropertyKey(); 932 test_PSPropertyKeyFromString(); 933 test_PSRefreshPropertySchema(); 934 test_InitPropVariantFromGUIDAsString(); 935 test_InitPropVariantFromBuffer(); 936 test_PropVariantToGUID(); 937 test_PropVariantToStringAlloc(); 938 test_PropVariantCompare(); 939 test_intconversions(); 940 test_PropVariantChangeType_LPWSTR(); 941 } 942