[BRANCHES]
[reactos.git] / rostests / winetests / scrrun / dictionary.c
1 /*
2 * Copyright (C) 2012 Alistair Leslie-Hughes
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #define COBJMACROS
20 #include <stdio.h>
21
22 #include "windows.h"
23 #include "ole2.h"
24 #include "oleauto.h"
25 #include "dispex.h"
26
27 #include "wine/test.h"
28
29 #include "scrrun.h"
30
31 static void test_interfaces(void)
32 {
33 static const WCHAR key_add[] = {'a', 0};
34 static const WCHAR key_add_value[] = {'a', 0};
35 static const WCHAR key_non_exist[] = {'b', 0};
36 HRESULT hr;
37 IDispatch *disp;
38 IDispatchEx *dispex;
39 IDictionary *dict;
40 IObjectWithSite *site;
41 VARIANT key, value;
42 VARIANT_BOOL exists;
43 LONG count = 0;
44
45 hr = CoCreateInstance(&CLSID_Dictionary, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
46 &IID_IDispatch, (void**)&disp);
47 if(FAILED(hr)) {
48 win_skip("Could not create FileSystem object: %08x\n", hr);
49 return;
50 }
51
52 VariantInit(&key);
53 VariantInit(&value);
54
55 hr = IDispatch_QueryInterface(disp, &IID_IDictionary, (void**)&dict);
56 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
57
58 hr = IDispatch_QueryInterface(disp, &IID_IObjectWithSite, (void**)&site);
59 ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
60
61 hr = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
62 ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
63
64 V_VT(&key) = VT_BSTR;
65 V_BSTR(&key) = SysAllocString(key_add);
66 V_VT(&value) = VT_BSTR;
67 V_BSTR(&value) = SysAllocString(key_add_value);
68 hr = IDictionary_Add(dict, &key, &value);
69 todo_wine ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
70 VariantClear(&value);
71
72 exists = VARIANT_FALSE;
73 hr = IDictionary_Exists(dict, &key, &exists);
74 todo_wine ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
75 todo_wine ok(exists == VARIANT_TRUE, "Expected TRUE but got FALSE.\n");
76 VariantClear(&key);
77
78 exists = VARIANT_TRUE;
79 V_VT(&key) = VT_BSTR;
80 V_BSTR(&key) = SysAllocString(key_non_exist);
81 hr = IDictionary_Exists(dict, &key, &exists);
82 todo_wine ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
83 todo_wine ok(exists == VARIANT_FALSE, "Expected FALSE but got TRUE.\n");
84 VariantClear(&key);
85
86 hr = IDictionary_get_Count(dict, &count);
87 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
88 todo_wine ok(count == 1, "got %d, expected 1\n", count);
89
90 IDictionary_Release(dict);
91 IDispatch_Release(disp);
92 }
93
94 START_TEST(dictionary)
95 {
96 CoInitialize(NULL);
97
98 test_interfaces();
99
100
101 CoUninitialize();
102 }