scrrun: Store compare method for dictionary.
[wine/multimedia.git] / dlls / scrrun / tests / dictionary.c
blobcad387deddbd904a1a04afc8e0ffd272c0a05d83
1 /*
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
19 #define COBJMACROS
20 #include <stdio.h>
22 #include "windows.h"
23 #include "ole2.h"
24 #include "oleauto.h"
25 #include "dispex.h"
27 #include "wine/test.h"
29 #include "scrrun.h"
31 static void test_interfaces(void)
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;
45 hr = CoCreateInstance(&CLSID_Dictionary, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
46 &IID_IDispatch, (void**)&disp);
47 ok(hr == S_OK, "got 0x%08x\n", hr);
49 VariantInit(&key);
50 VariantInit(&value);
52 hr = IDispatch_QueryInterface(disp, &IID_IDictionary, (void**)&dict);
53 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
55 hr = IDispatch_QueryInterface(disp, &IID_IObjectWithSite, (void**)&site);
56 ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
58 hr = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
59 ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
61 V_VT(&key) = VT_BSTR;
62 V_BSTR(&key) = SysAllocString(key_add);
63 V_VT(&value) = VT_BSTR;
64 V_BSTR(&value) = SysAllocString(key_add_value);
65 hr = IDictionary_Add(dict, &key, &value);
66 todo_wine ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
67 VariantClear(&value);
69 exists = VARIANT_FALSE;
70 hr = IDictionary_Exists(dict, &key, &exists);
71 todo_wine ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
72 todo_wine ok(exists == VARIANT_TRUE, "Expected TRUE but got FALSE.\n");
73 VariantClear(&key);
75 exists = VARIANT_TRUE;
76 V_VT(&key) = VT_BSTR;
77 V_BSTR(&key) = SysAllocString(key_non_exist);
78 hr = IDictionary_Exists(dict, &key, &exists);
79 todo_wine ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
80 todo_wine ok(exists == VARIANT_FALSE, "Expected FALSE but got TRUE.\n");
81 VariantClear(&key);
83 hr = IDictionary_get_Count(dict, &count);
84 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
85 todo_wine ok(count == 1, "got %d, expected 1\n", count);
87 IDictionary_Release(dict);
88 IDispatch_Release(disp);
91 static void test_comparemode(void)
93 CompareMethod method;
94 IDictionary *dict;
95 HRESULT hr;
97 hr = CoCreateInstance(&CLSID_Dictionary, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
98 &IID_IDictionary, (void**)&dict);
99 ok(hr == S_OK, "got 0x%08x\n", hr);
101 if (0) /* crashes on native */
102 hr = IDictionary_get_CompareMode(dict, NULL);
104 method = 10;
105 hr = IDictionary_get_CompareMode(dict, &method);
106 ok(hr == S_OK, "got 0x%08x\n", hr);
107 ok(method == BinaryCompare, "got %d\n", method);
109 /* invalid mode value is not checked */
110 hr = IDictionary_put_CompareMode(dict, 10);
111 ok(hr == S_OK, "got 0x%08x\n", hr);
113 hr = IDictionary_get_CompareMode(dict, &method);
114 ok(hr == S_OK, "got 0x%08x\n", hr);
115 ok(method == 10, "got %d\n", method);
117 hr = IDictionary_put_CompareMode(dict, DatabaseCompare);
118 ok(hr == S_OK, "got 0x%08x\n", hr);
120 hr = IDictionary_get_CompareMode(dict, &method);
121 ok(hr == S_OK, "got 0x%08x\n", hr);
122 ok(method == DatabaseCompare, "got %d\n", method);
124 IDictionary_Release(dict);
127 START_TEST(dictionary)
129 IDispatch *disp;
130 HRESULT hr;
132 CoInitialize(NULL);
134 hr = CoCreateInstance(&CLSID_Dictionary, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
135 &IID_IDispatch, (void**)&disp);
136 if(FAILED(hr)) {
137 win_skip("Dictionary object is not supported: %08x\n", hr);
138 CoUninitialize();
139 return;
141 IDispatch_Release(disp);
143 test_interfaces();
144 test_comparemode();
146 CoUninitialize();