2 * Copyright 2021 RĂ©mi Bernon for CodeWeavers
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
24 #include "winstring.h"
29 #define WIDL_using_Windows_Foundation
30 #define WIDL_using_Windows_Foundation_Collections
31 #include "windows.foundation.h"
32 #define WIDL_using_Windows_System_UserProfile
33 #include "windows.system.userprofile.h"
35 #include "wine/test.h"
37 static HRESULT (WINAPI
*pRoActivateInstance
)(HSTRING
, IInspectable
**);
38 static HRESULT (WINAPI
*pRoGetActivationFactory
)(HSTRING
, REFIID
, void **);
39 static HRESULT (WINAPI
*pRoInitialize
)(RO_INIT_TYPE
);
40 static void (WINAPI
*pRoUninitialize
)(void);
41 static HRESULT (WINAPI
*pWindowsCreateString
)(LPCWSTR
, UINT32
, HSTRING
*);
42 static HRESULT (WINAPI
*pWindowsDeleteString
)(HSTRING
);
43 static WCHAR
*(WINAPI
*pWindowsGetStringRawBuffer
)(HSTRING
, UINT32
*);
45 static void test_GlobalizationPreferences(void)
47 static const WCHAR
*class_name
= L
"Windows.System.UserProfile.GlobalizationPreferences";
49 IGlobalizationPreferencesStatics
*preferences_statics
= NULL
;
50 IVectorView_HSTRING
*languages
= NULL
, *calendars
, *clocks
, *currencies
;
51 IActivationFactory
*factory
= NULL
;
52 IInspectable
*inspectable
= NULL
, *tmp_inspectable
= NULL
;
53 IAgileObject
*agile_object
= NULL
, *tmp_agile_object
= NULL
;
58 WCHAR
*buf
, locale
[LOCALE_NAME_MAX_LENGTH
], country
[16];
61 GetUserDefaultLocaleName(locale
, LOCALE_NAME_MAX_LENGTH
);
62 GetUserDefaultGeoName(country
, 16);
64 hr
= pRoInitialize(RO_INIT_MULTITHREADED
);
65 ok(hr
== S_OK
, "RoInitialize failed, hr %#x\n", hr
);
67 hr
= pWindowsCreateString(class_name
, wcslen(class_name
), &str
);
68 ok(hr
== S_OK
, "WindowsCreateString failed, hr %#x\n", hr
);
70 hr
= pRoGetActivationFactory(str
, &IID_IActivationFactory
, (void **)&factory
);
71 ok(hr
== S_OK
|| broken(hr
== REGDB_E_CLASSNOTREG
), "RoGetActivationFactory failed, hr %#x\n", hr
);
72 if (hr
== REGDB_E_CLASSNOTREG
)
74 win_skip("%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w(class_name
));
75 pWindowsDeleteString(str
);
80 hr
= IActivationFactory_QueryInterface(factory
, &IID_IInspectable
, (void **)&inspectable
);
81 ok(hr
== S_OK
, "IActivationFactory_QueryInterface IID_IInspectable failed, hr %#x\n", hr
);
83 hr
= IActivationFactory_QueryInterface(factory
, &IID_IAgileObject
, (void **)&agile_object
);
84 ok(hr
== S_OK
, "IActivationFactory_QueryInterface IID_IAgileObject failed, hr %#x\n", hr
);
86 hr
= IActivationFactory_QueryInterface(factory
, &IID_IGlobalizationPreferencesStatics
, (void **)&preferences_statics
);
87 ok(hr
== S_OK
, "IActivationFactory_QueryInterface IID_IGlobalizationPreferencesStatics failed, hr %#x\n", hr
);
89 hr
= IGlobalizationPreferencesStatics_QueryInterface(preferences_statics
, &IID_IInspectable
, (void **)&tmp_inspectable
);
90 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_QueryInterface IID_IInspectable failed, hr %#x\n", hr
);
91 ok(tmp_inspectable
== inspectable
, "IGlobalizationPreferencesStatics_QueryInterface IID_IInspectable returned %p, expected %p\n", tmp_inspectable
, inspectable
);
92 IInspectable_Release(tmp_inspectable
);
94 hr
= IGlobalizationPreferencesStatics_QueryInterface(preferences_statics
, &IID_IAgileObject
, (void **)&tmp_agile_object
);
95 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_QueryInterface IID_IAgileObject failed, hr %#x\n", hr
);
96 ok(tmp_agile_object
== agile_object
, "IGlobalizationPreferencesStatics_QueryInterface IID_IAgileObject returned %p, expected %p\n", tmp_agile_object
, agile_object
);
97 IAgileObject_Release(tmp_agile_object
);
99 hr
= IGlobalizationPreferencesStatics_get_HomeGeographicRegion(preferences_statics
, &tmp_str
);
100 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_HomeGeographicRegion failed, hr %#x\n", hr
);
102 buf
= pWindowsGetStringRawBuffer(tmp_str
, &len
);
103 ok(buf
!= NULL
&& len
> 0, "WindowsGetStringRawBuffer returned buf %p, len %u\n", buf
, len
);
104 ok(wcslen(country
) == len
&& !memcmp(buf
, country
, len
),
105 "IGlobalizationPreferencesStatics_get_HomeGeographicRegion returned len %u, str %s, expected %s\n",
106 len
, wine_dbgstr_w(buf
), wine_dbgstr_w(country
));
108 pWindowsDeleteString(tmp_str
);
110 hr
= IGlobalizationPreferencesStatics_get_Languages(preferences_statics
, &languages
);
111 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_Languages failed, hr %#x\n", hr
);
113 hr
= IVectorView_HSTRING_QueryInterface(languages
, &IID_IInspectable
, (void **)&tmp_inspectable
);
114 ok(hr
== S_OK
, "IVectorView_HSTRING_QueryInterface failed, hr %#x\n", hr
);
115 ok(tmp_inspectable
!= inspectable
, "IVectorView_HSTRING_QueryInterface returned %p, expected %p\n", tmp_inspectable
, inspectable
);
116 IInspectable_Release(tmp_inspectable
);
118 hr
= IVectorView_HSTRING_QueryInterface(languages
, &IID_IAgileObject
, (void **)&tmp_agile_object
);
119 ok(hr
== S_OK
, "IVectorView_HSTRING_QueryInterface failed, hr %#x\n", hr
);
120 ok(tmp_agile_object
!= agile_object
, "IVectorView_HSTRING_QueryInterface IID_IAgileObject returned agile_object\n");
121 IAgileObject_Release(tmp_agile_object
);
124 hr
= IVectorView_HSTRING_get_Size(languages
, &size
);
125 ok(hr
== S_OK
, "IVectorView_HSTRING_get_Size failed, hr %#x\n", hr
);
126 ok(size
!= 0 && size
!= 0xdeadbeef, "IVectorView_HSTRING_get_Size returned %u\n", size
);
128 hr
= IVectorView_HSTRING_GetAt(languages
, 0, &tmp_str
);
129 ok(hr
== S_OK
, "IVectorView_HSTRING_GetAt failed, hr %#x\n", hr
);
130 buf
= pWindowsGetStringRawBuffer(tmp_str
, &len
);
131 ok(buf
!= NULL
&& len
> 0, "WindowsGetStringRawBuffer returned buf %p, len %u\n", buf
, len
);
133 ok(wcslen(locale
) == len
&& !memcmp(buf
, locale
, len
),
134 "IGlobalizationPreferencesStatics_get_Languages 0 returned len %u, str %s, expected %s\n",
135 len
, wine_dbgstr_w(buf
), wine_dbgstr_w(locale
));
139 hr
= IVectorView_HSTRING_IndexOf(languages
, tmp_str
, &i
, &found
);
140 ok(hr
== S_OK
, "IVectorView_HSTRING_IndexOf failed, hr %#x\n", hr
);
141 ok(i
== 0 && found
== TRUE
, "IVectorView_HSTRING_IndexOf returned size %d, found %d\n", size
, found
);
143 pWindowsDeleteString(tmp_str
);
145 hr
= pWindowsCreateString(L
"deadbeef", 8, &tmp_str
);
146 ok(hr
== S_OK
, "WindowsCreateString failed, hr %#x\n", hr
);
150 hr
= IVectorView_HSTRING_IndexOf(languages
, tmp_str
, &i
, &found
);
151 ok(hr
== S_OK
, "IVectorView_HSTRING_IndexOf failed, hr %#x\n", hr
);
152 ok(i
== 0 && found
== FALSE
, "IVectorView_HSTRING_IndexOf returned size %d, found %d\n", size
, found
);
154 pWindowsDeleteString(tmp_str
);
156 tmp_str
= (HSTRING
)0xdeadbeef;
157 hr
= IVectorView_HSTRING_GetAt(languages
, size
, &tmp_str
);
158 ok(hr
== E_BOUNDS
, "IVectorView_HSTRING_GetAt failed, hr %#x\n", hr
);
159 ok(tmp_str
== NULL
, "IVectorView_HSTRING_GetAt returned %p\n", tmp_str
);
161 tmp_str
= (HSTRING
)0xdeadbeef;
162 hr
= IVectorView_HSTRING_GetMany(languages
, size
, 1, &tmp_str
, &i
);
163 ok(hr
== S_OK
, "IVectorView_HSTRING_GetAt failed, hr %#x\n", hr
);
164 ok(i
== 0 && tmp_str
== NULL
, "IVectorView_HSTRING_GetMany returned count %u, str %p\n", i
, tmp_str
);
166 hr
= IVectorView_HSTRING_GetMany(languages
, 0, 1, &tmp_str
, &i
);
167 ok(hr
== S_OK
, "IVectorView_HSTRING_GetAt failed, hr %#x\n", hr
);
168 ok(i
== 1, "IVectorView_HSTRING_GetMany returned count %u, expected 1\n", i
);
170 buf
= pWindowsGetStringRawBuffer(tmp_str
, &len
);
171 ok(buf
!= NULL
&& len
> 0, "WindowsGetStringRawBuffer returned buf %p, len %u\n", buf
, len
);
173 ok(wcslen(locale
) == len
&& !memcmp(buf
, locale
, len
),
174 "IGlobalizationPreferencesStatics_get_Languages 0 returned len %u, str %s, expected %s\n",
175 len
, wine_dbgstr_w(buf
), wine_dbgstr_w(locale
));
177 pWindowsDeleteString(tmp_str
);
179 IVectorView_HSTRING_Release(languages
);
182 hr
= IGlobalizationPreferencesStatics_get_Calendars(preferences_statics
, &calendars
);
183 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_Calendars failed, hr %#x\n", hr
);
186 hr
= IVectorView_HSTRING_get_Size(calendars
, &size
);
187 ok(hr
== S_OK
, "IVectorView_HSTRING_get_Size failed, hr %#x\n", hr
);
188 todo_wine
ok(size
!= 0 && size
!= 0xdeadbeef, "IVectorView_HSTRING_get_Size returned %u\n", size
);
190 IVectorView_HSTRING_Release(calendars
);
193 hr
= IGlobalizationPreferencesStatics_get_Clocks(preferences_statics
, &clocks
);
194 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_Clocks failed, hr %#x\n", hr
);
197 hr
= IVectorView_HSTRING_get_Size(clocks
, &size
);
198 ok(hr
== S_OK
, "IVectorView_HSTRING_get_Size failed, hr %#x\n", hr
);
199 todo_wine
ok(size
!= 0 && size
!= 0xdeadbeef, "IVectorView_HSTRING_get_Size returned %u\n", size
);
201 IVectorView_HSTRING_Release(clocks
);
204 hr
= IGlobalizationPreferencesStatics_get_Currencies(preferences_statics
, ¤cies
);
205 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_Currencies failed, hr %#x\n", hr
);
208 hr
= IVectorView_HSTRING_get_Size(currencies
, &size
);
209 ok(hr
== S_OK
, "IVectorView_HSTRING_get_Size failed, hr %#x\n", hr
);
210 todo_wine
ok(size
!= 0 && size
!= 0xdeadbeef, "IVectorView_HSTRING_get_Size returned %u\n", size
);
212 IVectorView_HSTRING_Release(currencies
);
215 IGlobalizationPreferencesStatics_Release(preferences_statics
);
217 IAgileObject_Release(agile_object
);
218 IInspectable_Release(inspectable
);
219 IActivationFactory_Release(factory
);
221 pWindowsDeleteString(str
);
226 START_TEST(globalization
)
230 if (!(combase
= LoadLibraryW(L
"combase.dll")))
232 win_skip("Failed to load combase.dll, skipping tests\n");
236 #define LOAD_FUNCPTR(x) \
237 if (!(p##x = (void*)GetProcAddress(combase, #x))) \
239 win_skip("Failed to find %s in combase.dll, skipping tests.\n", #x); \
243 LOAD_FUNCPTR(RoActivateInstance
);
244 LOAD_FUNCPTR(RoGetActivationFactory
);
245 LOAD_FUNCPTR(RoInitialize
);
246 LOAD_FUNCPTR(RoUninitialize
);
247 LOAD_FUNCPTR(WindowsCreateString
);
248 LOAD_FUNCPTR(WindowsDeleteString
);
249 LOAD_FUNCPTR(WindowsGetStringRawBuffer
);
252 test_GlobalizationPreferences();