2 * Copyright (C) 2012 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
32 static void test_interfaces(void)
34 static const WCHAR key_add
[] = {'a', 0};
35 static const WCHAR key_add_value
[] = {'a', 0};
36 static const WCHAR key_non_exist
[] = {'b', 0};
41 IObjectWithSite
*site
;
46 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
47 &IID_IDispatch
, (void**)&disp
);
48 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
53 hr
= IDispatch_QueryInterface(disp
, &IID_IDictionary
, (void**)&dict
);
54 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
56 hr
= IDispatch_QueryInterface(disp
, &IID_IObjectWithSite
, (void**)&site
);
57 ok(hr
== E_NOINTERFACE
, "got 0x%08x, expected 0x%08x\n", hr
, E_NOINTERFACE
);
59 hr
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
60 ok(hr
== E_NOINTERFACE
, "got 0x%08x, expected 0x%08x\n", hr
, E_NOINTERFACE
);
63 V_BSTR(&key
) = SysAllocString(key_add
);
64 V_VT(&value
) = VT_BSTR
;
65 V_BSTR(&value
) = SysAllocString(key_add_value
);
66 hr
= IDictionary_Add(dict
, &key
, &value
);
67 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
70 exists
= VARIANT_FALSE
;
71 hr
= IDictionary_Exists(dict
, &key
, &exists
);
72 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
73 ok(exists
== VARIANT_TRUE
, "Expected TRUE but got FALSE.\n");
76 exists
= VARIANT_TRUE
;
78 V_BSTR(&key
) = SysAllocString(key_non_exist
);
79 hr
= IDictionary_Exists(dict
, &key
, &exists
);
80 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
81 ok(exists
== VARIANT_FALSE
, "Expected FALSE but got TRUE.\n");
84 hr
= IDictionary_get_Count(dict
, &count
);
85 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
86 ok(count
== 1, "got %d, expected 1\n", count
);
88 IDictionary_Release(dict
);
89 IDispatch_Release(disp
);
92 static void test_comparemode(void)
99 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
100 &IID_IDictionary
, (void**)&dict
);
101 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
103 if (0) /* crashes on native */
104 hr
= IDictionary_get_CompareMode(dict
, NULL
);
107 hr
= IDictionary_get_CompareMode(dict
, &method
);
108 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
109 ok(method
== BinaryCompare
, "got %d\n", method
);
111 /* invalid mode value is not checked */
112 hr
= IDictionary_put_CompareMode(dict
, 10);
113 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
115 hr
= IDictionary_get_CompareMode(dict
, &method
);
116 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
117 ok(method
== 10, "got %d\n", method
);
119 hr
= IDictionary_put_CompareMode(dict
, DatabaseCompare
);
120 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
122 hr
= IDictionary_get_CompareMode(dict
, &method
);
123 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
124 ok(method
== DatabaseCompare
, "got %d\n", method
);
126 /* try to change mode of a non-empty dict */
130 hr
= IDictionary_Add(dict
, &key
, &item
);
131 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
133 hr
= IDictionary_put_CompareMode(dict
, BinaryCompare
);
134 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
, "got 0x%08x\n", hr
);
136 IDictionary_Release(dict
);
139 static DWORD
get_str_hash(const WCHAR
*str
, CompareMethod method
)
146 if (method
== TextCompare
|| method
== DatabaseCompare
)
147 ch
= PtrToInt(CharLowerW(IntToPtr(*str
)));
151 hash
+= (hash
<< 4) + ch
;
158 static DWORD
get_num_hash(FLOAT num
)
160 return (*((DWORD
*)&num
)) % 1201;
168 unsigned int exp_bias
: 8;
169 unsigned int sign
: 1;
178 unsigned int m_lo
: 32; /* 52 bits of precision */
179 unsigned int m_hi
: 20;
180 unsigned int exp_bias
: 11; /* bias == 1023 */
181 unsigned int sign
: 1;
186 static void test_hash_value(void)
188 /* string test data */
189 static const WCHAR str_hash_tests
[][10] = {
191 {'a','B','C','d','1',0},
198 static const int int_hash_tests
[] = {
202 static const FLOAT float_hash_tests
[] = {
203 0.0, -1.0, 100.0, 1.0, 255.0, 1.234
213 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
214 &IID_IDictionary
, (void**)&dict
);
215 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
217 V_VT(&key
) = VT_BSTR
;
220 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
221 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
222 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
223 ok(V_I4(&hash
) == 0, "got %d\n", V_I4(&hash
));
225 for (i
= 0; i
< sizeof(str_hash_tests
)/sizeof(str_hash_tests
[0]); i
++) {
226 DWORD expected
= get_str_hash(str_hash_tests
[i
], BinaryCompare
);
228 hr
= IDictionary_put_CompareMode(dict
, BinaryCompare
);
229 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
231 V_VT(&key
) = VT_BSTR
;
232 V_BSTR(&key
) = SysAllocString(str_hash_tests
[i
]);
234 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
235 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
236 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
237 ok(V_I4(&hash
) == expected
, "%d: binary mode: got hash 0x%08x, expected 0x%08x\n", i
, V_I4(&hash
),
241 expected
= get_str_hash(str_hash_tests
[i
], TextCompare
);
242 hr
= IDictionary_put_CompareMode(dict
, TextCompare
);
243 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
245 V_VT(&key
) = VT_BSTR
;
246 V_BSTR(&key
) = SysAllocString(str_hash_tests
[i
]);
248 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
249 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
250 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
251 ok(V_I4(&hash
) == expected
, "%d: text mode: got hash 0x%08x, expected 0x%08x\n", i
, V_I4(&hash
),
255 expected
= get_str_hash(str_hash_tests
[i
], DatabaseCompare
);
256 hr
= IDictionary_put_CompareMode(dict
, DatabaseCompare
);
257 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
259 V_VT(&key
) = VT_BSTR
;
260 V_BSTR(&key
) = SysAllocString(str_hash_tests
[i
]);
262 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
263 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
264 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
265 ok(V_I4(&hash
) == expected
, "%d: db mode: got hash 0x%08x, expected 0x%08x\n", i
, V_I4(&hash
),
273 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
274 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
|| broken(hr
== S_OK
) /* win2k, win2k3 */, "got 0x%08x\n", hr
);
275 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
276 ok(V_I4(&hash
) == ~0u, "got hash 0x%08x\n", V_I4(&hash
));
278 V_VT(&key
) = VT_UINT
;
281 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
282 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
|| broken(hr
== S_OK
) /* win2k, win2k3 */, "got 0x%08x\n", hr
);
283 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
284 ok(V_I4(&hash
) == ~0u, "got hash 0x%08x\n", V_I4(&hash
));
289 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
290 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
|| broken(hr
== S_OK
) /* win2k, win2k3 */, "got 0x%08x\n", hr
);
291 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
292 ok(V_I4(&hash
) == ~0u || broken(V_I4(&hash
) == 0xa1), "got hash 0x%08x\n", V_I4(&hash
));
297 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
298 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
|| broken(hr
== S_OK
) /* win2k, win2k3 */, "got 0x%08x\n", hr
);
299 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
300 ok(V_I4(&hash
) == ~0u, "got hash 0x%08x\n", V_I4(&hash
));
305 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
306 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
|| broken(hr
== S_OK
) /* win2k, win2k3 */, "got 0x%08x\n", hr
);
307 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
308 ok(V_I4(&hash
) == ~0u, "got hash 0x%08x\n", V_I4(&hash
));
313 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
314 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
|| broken(hr
== S_OK
) /* win2k, win2k3 */, "got 0x%08x\n", hr
);
315 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
316 ok(V_I4(&hash
) == ~0u, "got hash 0x%08x\n", V_I4(&hash
));
318 for (i
= 0; i
< sizeof(int_hash_tests
)/sizeof(int_hash_tests
[0]); i
++) {
319 DWORD expected
= get_num_hash(int_hash_tests
[i
]);
322 V_I2(&key
) = int_hash_tests
[i
];
324 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
325 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
326 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
327 ok(V_I4(&hash
) == expected
, "%d: got hash 0x%08x, expected 0x%08x\n", i
, V_I4(&hash
),
331 V_I4(&key
) = int_hash_tests
[i
];
333 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
334 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
335 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
336 ok(V_I4(&hash
) == expected
, "%d: got hash 0x%08x, expected 0x%08x\n", i
, V_I4(&hash
),
339 expected
= get_num_hash((FLOAT
)(BYTE
)int_hash_tests
[i
]);
341 V_UI1(&key
) = int_hash_tests
[i
];
343 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
344 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
345 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
346 ok(V_I4(&hash
) == expected
, "%d: got hash 0x%08x, expected 0x%08x\n", i
, V_I4(&hash
),
352 fx4
.i
.exp_bias
= 0xff;
357 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
358 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
|| broken(hr
== S_OK
) /* win2k, win2k3 */, "got 0x%08x\n", hr
);
359 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
360 ok(V_I4(&hash
) == ~0u || broken(V_I4(&hash
) == 0 /* win2k */ ||
361 V_I4(&hash
) == 0x1f4 /* vista, win2k8 */), "got hash 0x%08x\n", V_I4(&hash
));
366 fx4
.i
.exp_bias
= 0xff;
371 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
372 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
373 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
374 ok(V_I4(&hash
) == 0, "got hash 0x%08x\n", V_I4(&hash
));
378 fx8
.i
.exp_bias
= 0x7ff;
383 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
384 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
|| broken(hr
== S_OK
) /* win2k, win2k3 */, "got 0x%08x\n", hr
);
385 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
386 ok(V_I4(&hash
) == ~0u || broken(V_I4(&hash
) == 0 /* win2k */ ||
387 V_I4(&hash
) == 0x1f4 /* vista, win2k8 */), "got hash 0x%08x\n", V_I4(&hash
));
393 fx8
.i
.exp_bias
= 0x7ff;
398 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
399 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
400 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
401 ok(V_I4(&hash
) == 0, "got hash 0x%08x\n", V_I4(&hash
));
403 for (i
= 0; i
< sizeof(float_hash_tests
)/sizeof(float_hash_tests
[0]); i
++) {
404 DWORD expected
= get_num_hash(float_hash_tests
[i
]);
407 V_R4(&key
) = float_hash_tests
[i
];
409 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
410 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
411 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
412 ok(V_I4(&hash
) == expected
, "%d: got hash 0x%08x, expected 0x%08x\n", i
, V_I4(&hash
),
416 V_R8(&key
) = float_hash_tests
[i
];
418 hr
= IDictionary_get_HashVal(dict
, &key
, &hash
);
419 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
420 ok(V_VT(&hash
) == VT_I4
, "got %d\n", V_VT(&hash
));
421 ok(V_I4(&hash
) == expected
, "%d: got hash 0x%08x, expected 0x%08x\n", i
, V_I4(&hash
),
425 IDictionary_Release(dict
);
428 static void test_Exists(void)
435 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
436 &IID_IDictionary
, (void**)&dict
);
437 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
439 if (0) /* crashes on native */
440 hr
= IDictionary_Exists(dict
, NULL
, NULL
);
444 hr
= IDictionary_Exists(dict
, &key
, NULL
);
445 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
, "got 0x%08x\n", hr
);
449 exists
= VARIANT_TRUE
;
450 hr
= IDictionary_Exists(dict
, &key
, &exists
);
451 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
452 ok(exists
== VARIANT_FALSE
, "got %x\n", exists
);
455 hr
= IDictionary_Add(dict
, &key
, &item
);
456 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
460 hr
= IDictionary_Add(dict
, &key
, &item
);
461 ok(hr
== CTL_E_KEY_ALREADY_EXISTS
, "got 0x%08x\n", hr
);
465 hr
= IDictionary_Exists(dict
, &key
, NULL
);
466 ok(hr
== CTL_E_ILLEGALFUNCTIONCALL
, "got 0x%08x\n", hr
);
470 exists
= VARIANT_FALSE
;
471 hr
= IDictionary_Exists(dict
, &key
, &exists
);
472 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
473 ok(exists
== VARIANT_TRUE
, "got %x\n", exists
);
475 /* key of different type, but resolves to same hash value */
478 exists
= VARIANT_FALSE
;
479 hr
= IDictionary_Exists(dict
, &key
, &exists
);
480 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
481 ok(exists
== VARIANT_TRUE
, "got %x\n", exists
);
483 IDictionary_Release(dict
);
486 static void test_Keys(void)
488 VARIANT key
, keys
, item
;
493 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
494 &IID_IDictionary
, (void**)&dict
);
495 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
497 hr
= IDictionary_Keys(dict
, NULL
);
498 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
501 hr
= IDictionary_Keys(dict
, &keys
);
502 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
503 ok(V_VT(&keys
) == (VT_ARRAY
|VT_VARIANT
), "got %d\n", V_VT(&keys
));
509 hr
= IDictionary_Add(dict
, &key
, &item
);
510 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
513 hr
= IDictionary_Keys(dict
, &keys
);
514 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
515 ok(V_VT(&keys
) == (VT_ARRAY
|VT_VARIANT
), "got %d\n", V_VT(&keys
));
519 hr
= SafeArrayGetElement(V_ARRAY(&keys
), &index
, &key
);
520 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
521 ok(V_VT(&key
) == VT_R4
, "got %d\n", V_VT(&key
));
523 index
= SafeArrayGetDim(V_ARRAY(&keys
));
524 ok(index
== 1, "got %d\n", index
);
526 hr
= SafeArrayGetUBound(V_ARRAY(&keys
), 1, &index
);
527 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
528 ok(index
== 0, "got %d\n", index
);
532 IDictionary_Release(dict
);
535 static void test_Remove(void)
541 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
542 &IID_IDictionary
, (void**)&dict
);
543 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
546 hr
= IDictionary_Remove(dict
, NULL
);
548 /* nothing added yet */
551 hr
= IDictionary_Remove(dict
, &key
);
552 ok(hr
== CTL_E_ELEMENT_NOT_FOUND
, "got 0x%08x\n", hr
);
555 hr
= IDictionary_Add(dict
, &key
, &item
);
556 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
558 hr
= IDictionary_Remove(dict
, &key
);
559 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
561 IDictionary_Release(dict
);
564 static void test_Item(void)
570 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
571 &IID_IDictionary
, (void**)&dict
);
572 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
578 hr
= IDictionary_get_Item(dict
, &key
, &item
);
579 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
580 ok(V_VT(&item
) == VT_EMPTY
, "got %d\n", V_VT(&item
));
585 hr
= IDictionary_get_Item(dict
, &key
, &item
);
586 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
587 ok(V_VT(&item
) == VT_EMPTY
, "got %d\n", V_VT(&item
));
589 IDictionary_Release(dict
);
592 static void test_Add(void)
594 static const WCHAR testW
[] = {'t','e','s','t','W',0};
600 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
601 &IID_IDictionary
, (void**)&dict
);
602 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
604 str
= SysAllocString(testW
);
607 V_VT(&item
) = VT_BSTR
|VT_BYREF
;
608 V_BSTRREF(&item
) = &str
;
609 hr
= IDictionary_Add(dict
, &key
, &item
);
610 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
612 hr
= IDictionary_get_Item(dict
, &key
, &item
);
613 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
614 ok(V_VT(&item
) == VT_BSTR
, "got %d\n", V_VT(&item
));
618 IDictionary_Release(dict
);
621 static void test_IEnumVARIANT(void)
623 IUnknown
*enum1
, *enum2
;
624 IEnumVARIANT
*enumvar
;
630 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
631 &IID_IDictionary
, (void**)&dict
);
632 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
634 if (0) /* crashes on native */
635 hr
= IDictionary__NewEnum(dict
, NULL
);
637 hr
= IDictionary__NewEnum(dict
, &enum1
);
638 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
640 hr
= IDictionary__NewEnum(dict
, &enum2
);
641 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
642 ok(enum1
!= enum2
, "got %p, %p\n", enum2
, enum1
);
643 IUnknown_Release(enum2
);
645 hr
= IUnknown_QueryInterface(enum1
, &IID_IEnumVARIANT
, (void**)&enumvar
);
646 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
647 IUnknown_Release(enum1
);
649 /* dictionary is empty */
650 hr
= IEnumVARIANT_Skip(enumvar
, 1);
651 ok(hr
== S_FALSE
, "got 0x%08x\n", hr
);
653 hr
= IEnumVARIANT_Skip(enumvar
, 0);
654 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
660 hr
= IDictionary_Add(dict
, &key
, &item
);
661 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
663 hr
= IEnumVARIANT_Skip(enumvar
, 0);
664 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
666 hr
= IEnumVARIANT_Reset(enumvar
);
667 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
668 hr
= IEnumVARIANT_Skip(enumvar
, 1);
669 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
670 hr
= IEnumVARIANT_Skip(enumvar
, 1);
671 ok(hr
== S_FALSE
, "got 0x%08x\n", hr
);
677 hr
= IDictionary_Add(dict
, &key
, &item
);
678 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
684 hr
= IDictionary_Add(dict
, &key
, &item
);
685 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
687 hr
= IEnumVARIANT_Reset(enumvar
);
688 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
691 hr
= IEnumVARIANT_Next(enumvar
, 1, &key
, &fetched
);
692 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
693 ok(V_VT(&key
) == VT_I2
, "got %d\n", V_VT(&key
));
694 ok(V_I2(&key
) == 1, "got %d\n", V_I2(&key
));
695 ok(fetched
== 1, "got %u\n", fetched
);
697 hr
= IEnumVARIANT_Reset(enumvar
);
698 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
700 hr
= IDictionary_Remove(dict
, &key
);
701 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
704 hr
= IEnumVARIANT_Next(enumvar
, 1, &key
, &fetched
);
705 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
706 ok(V_VT(&key
) == VT_I2
, "got %d\n", V_VT(&key
));
707 ok(V_I2(&key
) == 4000, "got %d\n", V_I2(&key
));
708 ok(fetched
== 1, "got %u\n", fetched
);
711 hr
= IEnumVARIANT_Next(enumvar
, 1, &key
, &fetched
);
712 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
713 ok(V_VT(&key
) == VT_I2
, "got %d\n", V_VT(&key
));
714 ok(V_I2(&key
) == 0, "got %d\n", V_I2(&key
));
715 ok(fetched
== 1, "got %u\n", fetched
);
717 /* enumeration reached the bottom, add one more pair */
719 hr
= IEnumVARIANT_Next(enumvar
, 1, &key
, &fetched
);
720 ok(hr
== S_FALSE
, "got 0x%08x\n", hr
);
726 hr
= IDictionary_Add(dict
, &key
, &item
);
727 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
729 /* still doesn't work until Reset() */
731 hr
= IEnumVARIANT_Next(enumvar
, 1, &key
, &fetched
);
732 ok(hr
== S_FALSE
, "got 0x%08x\n", hr
);
734 IEnumVARIANT_Release(enumvar
);
735 IDictionary_Release(dict
);
738 START_TEST(dictionary
)
745 hr
= CoCreateInstance(&CLSID_Dictionary
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
746 &IID_IDispatch
, (void**)&disp
);
748 win_skip("Dictionary object is not supported: %08x\n", hr
);
752 IDispatch_Release(disp
);