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_Globalization
33 #include "windows.globalization.h"
34 #define WIDL_using_Windows_System_UserProfile
35 #include "windows.system.userprofile.h"
37 #include "wine/test.h"
41 static INT (WINAPI
*pGetUserDefaultGeoName
)(LPWSTR
, int);
44 static void test_GlobalizationPreferences(void)
46 static const WCHAR
*class_name
= L
"Windows.System.UserProfile.GlobalizationPreferences";
48 IGlobalizationPreferencesStatics
*preferences_statics
= NULL
;
49 IVectorView_HSTRING
*languages
= NULL
, *calendars
, *clocks
, *currencies
;
50 IActivationFactory
*factory
= NULL
;
51 IInspectable
*inspectable
= NULL
, *tmp_inspectable
= NULL
;
52 IAgileObject
*agile_object
= NULL
, *tmp_agile_object
= NULL
;
53 WCHAR locale
[LOCALE_NAME_MAX_LENGTH
];
61 GetUserDefaultLocaleName(locale
, LOCALE_NAME_MAX_LENGTH
);
63 hr
= RoInitialize(RO_INIT_MULTITHREADED
);
64 ok(hr
== S_OK
, "RoInitialize failed, hr %#lx\n", hr
);
66 hr
= WindowsCreateString(class_name
, wcslen(class_name
), &str
);
67 ok(hr
== S_OK
, "WindowsCreateString failed, hr %#lx\n", hr
);
69 hr
= RoGetActivationFactory(str
, &IID_IActivationFactory
, (void **)&factory
);
70 ok(hr
== S_OK
|| broken(hr
== REGDB_E_CLASSNOTREG
), "RoGetActivationFactory failed, hr %#lx\n", hr
);
71 if (hr
== REGDB_E_CLASSNOTREG
)
73 win_skip("%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w(class_name
));
74 WindowsDeleteString(str
);
79 hr
= IActivationFactory_QueryInterface(factory
, &IID_IInspectable
, (void **)&inspectable
);
80 ok(hr
== S_OK
, "IActivationFactory_QueryInterface IID_IInspectable failed, hr %#lx\n", hr
);
82 hr
= IActivationFactory_QueryInterface(factory
, &IID_IAgileObject
, (void **)&agile_object
);
83 ok(hr
== S_OK
, "IActivationFactory_QueryInterface IID_IAgileObject failed, hr %#lx\n", hr
);
85 hr
= IActivationFactory_QueryInterface(factory
, &IID_IGlobalizationPreferencesStatics
, (void **)&preferences_statics
);
86 ok(hr
== S_OK
, "IActivationFactory_QueryInterface IID_IGlobalizationPreferencesStatics failed, hr %#lx\n", hr
);
88 hr
= IGlobalizationPreferencesStatics_QueryInterface(preferences_statics
, &IID_IInspectable
, (void **)&tmp_inspectable
);
89 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_QueryInterface IID_IInspectable failed, hr %#lx\n", hr
);
90 ok(tmp_inspectable
== inspectable
, "IGlobalizationPreferencesStatics_QueryInterface IID_IInspectable returned %p, expected %p\n", tmp_inspectable
, inspectable
);
91 IInspectable_Release(tmp_inspectable
);
93 hr
= IGlobalizationPreferencesStatics_QueryInterface(preferences_statics
, &IID_IAgileObject
, (void **)&tmp_agile_object
);
94 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_QueryInterface IID_IAgileObject failed, hr %#lx\n", hr
);
95 ok(tmp_agile_object
== agile_object
, "IGlobalizationPreferencesStatics_QueryInterface IID_IAgileObject returned %p, expected %p\n", tmp_agile_object
, agile_object
);
96 IAgileObject_Release(tmp_agile_object
);
98 hr
= IGlobalizationPreferencesStatics_get_HomeGeographicRegion(preferences_statics
, &tmp_str
);
99 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_HomeGeographicRegion failed, hr %#lx\n", hr
);
101 buf
= WindowsGetStringRawBuffer(tmp_str
, &len
);
102 ok(buf
!= NULL
&& len
> 0, "WindowsGetStringRawBuffer returned buf %p, len %u\n", buf
, len
);
103 if (pGetUserDefaultGeoName
)
107 geolen
= pGetUserDefaultGeoName(country
, ARRAY_SIZE(country
));
108 ok(broken(geolen
== 1) || /* Win10 1709 */
109 (wcslen(country
) == len
&& !memcmp(buf
, country
, len
)),
110 "IGlobalizationPreferencesStatics_get_HomeGeographicRegion returned len %u, str %s, expected %s\n",
111 len
, wine_dbgstr_w(buf
), wine_dbgstr_w(country
));
114 WindowsDeleteString(tmp_str
);
116 hr
= IGlobalizationPreferencesStatics_get_Languages(preferences_statics
, &languages
);
117 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_Languages failed, hr %#lx\n", hr
);
119 hr
= IVectorView_HSTRING_QueryInterface(languages
, &IID_IInspectable
, (void **)&tmp_inspectable
);
120 ok(hr
== S_OK
, "IVectorView_HSTRING_QueryInterface failed, hr %#lx\n", hr
);
121 ok(tmp_inspectable
!= inspectable
, "IVectorView_HSTRING_QueryInterface returned %p, expected %p\n", tmp_inspectable
, inspectable
);
122 IInspectable_Release(tmp_inspectable
);
124 hr
= IVectorView_HSTRING_QueryInterface(languages
, &IID_IAgileObject
, (void **)&tmp_agile_object
);
125 ok(hr
== S_OK
, "IVectorView_HSTRING_QueryInterface failed, hr %#lx\n", hr
);
126 ok(tmp_agile_object
!= agile_object
, "IVectorView_HSTRING_QueryInterface IID_IAgileObject returned agile_object\n");
127 IAgileObject_Release(tmp_agile_object
);
130 hr
= IVectorView_HSTRING_get_Size(languages
, &size
);
131 ok(hr
== S_OK
, "IVectorView_HSTRING_get_Size failed, hr %#lx\n", hr
);
132 ok(size
!= 0 && size
!= 0xdeadbeef, "IVectorView_HSTRING_get_Size returned %u\n", size
);
134 hr
= IVectorView_HSTRING_GetAt(languages
, 0, &tmp_str
);
135 ok(hr
== S_OK
, "IVectorView_HSTRING_GetAt failed, hr %#lx\n", hr
);
136 buf
= WindowsGetStringRawBuffer(tmp_str
, &len
);
137 ok(buf
!= NULL
&& len
> 0, "WindowsGetStringRawBuffer returned buf %p, len %u\n", buf
, len
);
139 ok(wcslen(locale
) == len
&& !memcmp(buf
, locale
, len
),
140 "IGlobalizationPreferencesStatics_get_Languages 0 returned len %u, str %s, expected %s\n",
141 len
, wine_dbgstr_w(buf
), wine_dbgstr_w(locale
));
145 hr
= IVectorView_HSTRING_IndexOf(languages
, tmp_str
, &i
, &found
);
146 ok(hr
== S_OK
, "IVectorView_HSTRING_IndexOf failed, hr %#lx\n", hr
);
147 ok(i
== 0 && found
== TRUE
, "IVectorView_HSTRING_IndexOf returned size %d, found %d\n", size
, found
);
149 WindowsDeleteString(tmp_str
);
151 hr
= WindowsCreateString(L
"deadbeef", 8, &tmp_str
);
152 ok(hr
== S_OK
, "WindowsCreateString failed, hr %#lx\n", hr
);
156 hr
= IVectorView_HSTRING_IndexOf(languages
, tmp_str
, &i
, &found
);
157 ok(hr
== S_OK
, "IVectorView_HSTRING_IndexOf failed, hr %#lx\n", hr
);
158 ok(i
== 0 && found
== FALSE
, "IVectorView_HSTRING_IndexOf returned size %d, found %d\n", size
, found
);
160 WindowsDeleteString(tmp_str
);
162 tmp_str
= (HSTRING
)0xdeadbeef;
163 hr
= IVectorView_HSTRING_GetAt(languages
, size
, &tmp_str
);
164 ok(hr
== E_BOUNDS
, "IVectorView_HSTRING_GetAt failed, hr %#lx\n", hr
);
165 ok(tmp_str
== NULL
, "IVectorView_HSTRING_GetAt returned %p\n", tmp_str
);
167 tmp_str
= (HSTRING
)0xdeadbeef;
168 hr
= IVectorView_HSTRING_GetMany(languages
, size
, 1, &tmp_str
, &i
);
169 ok(hr
== S_OK
, "IVectorView_HSTRING_GetAt failed, hr %#lx\n", hr
);
170 ok(i
== 0 && tmp_str
== NULL
, "IVectorView_HSTRING_GetMany returned count %u, str %p\n", i
, tmp_str
);
172 hr
= IVectorView_HSTRING_GetMany(languages
, 0, 1, &tmp_str
, &i
);
173 ok(hr
== S_OK
, "IVectorView_HSTRING_GetAt failed, hr %#lx\n", hr
);
174 ok(i
== 1, "IVectorView_HSTRING_GetMany returned count %u, expected 1\n", i
);
176 buf
= WindowsGetStringRawBuffer(tmp_str
, &len
);
177 ok(buf
!= NULL
&& len
> 0, "WindowsGetStringRawBuffer returned buf %p, len %u\n", buf
, len
);
179 ok(wcslen(locale
) == len
&& !memcmp(buf
, locale
, len
),
180 "IGlobalizationPreferencesStatics_get_Languages 0 returned len %u, str %s, expected %s\n",
181 len
, wine_dbgstr_w(buf
), wine_dbgstr_w(locale
));
183 WindowsDeleteString(tmp_str
);
185 IVectorView_HSTRING_Release(languages
);
188 hr
= IGlobalizationPreferencesStatics_get_Calendars(preferences_statics
, &calendars
);
189 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_Calendars failed, hr %#lx\n", hr
);
192 hr
= IVectorView_HSTRING_get_Size(calendars
, &size
);
193 ok(hr
== S_OK
, "IVectorView_HSTRING_get_Size failed, hr %#lx\n", hr
);
194 todo_wine
ok(size
!= 0 && size
!= 0xdeadbeef, "IVectorView_HSTRING_get_Size returned %u\n", size
);
196 IVectorView_HSTRING_Release(calendars
);
199 hr
= IGlobalizationPreferencesStatics_get_Clocks(preferences_statics
, &clocks
);
200 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_Clocks failed, hr %#lx\n", hr
);
203 hr
= IVectorView_HSTRING_get_Size(clocks
, &size
);
204 ok(hr
== S_OK
, "IVectorView_HSTRING_get_Size failed, hr %#lx\n", hr
);
205 todo_wine
ok(size
!= 0 && size
!= 0xdeadbeef, "IVectorView_HSTRING_get_Size returned %u\n", size
);
207 IVectorView_HSTRING_Release(clocks
);
210 hr
= IGlobalizationPreferencesStatics_get_Currencies(preferences_statics
, ¤cies
);
211 ok(hr
== S_OK
, "IGlobalizationPreferencesStatics_get_Currencies failed, hr %#lx\n", hr
);
214 hr
= IVectorView_HSTRING_get_Size(currencies
, &size
);
215 ok(hr
== S_OK
, "IVectorView_HSTRING_get_Size failed, hr %#lx\n", hr
);
216 todo_wine
ok(size
!= 0 && size
!= 0xdeadbeef, "IVectorView_HSTRING_get_Size returned %u\n", size
);
218 IVectorView_HSTRING_Release(currencies
);
221 IGlobalizationPreferencesStatics_Release(preferences_statics
);
223 IAgileObject_Release(agile_object
);
224 IInspectable_Release(inspectable
);
225 IActivationFactory_Release(factory
);
227 WindowsDeleteString(str
);
232 static void test_Language(void)
234 static const WCHAR
*class_name
= L
"Windows.Globalization.Language";
236 IAgileObject
*agile_object
, *tmp_agile_object
;
237 IInspectable
*inspectable
, *tmp_inspectable
;
238 WCHAR buffer
[LOCALE_NAME_MAX_LENGTH
];
239 ILanguageFactory
*language_factory
;
240 IActivationFactory
*factory
;
246 hr
= RoInitialize(RO_INIT_MULTITHREADED
);
247 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
249 hr
= WindowsCreateString(class_name
, wcslen(class_name
), &str
);
250 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
252 hr
= RoGetActivationFactory(str
, &IID_IActivationFactory
, (void **)&factory
);
253 ok(hr
== S_OK
|| broken(hr
== REGDB_E_CLASSNOTREG
), "Unexpected hr %#lx.\n", hr
);
254 WindowsDeleteString(str
);
255 if (hr
== REGDB_E_CLASSNOTREG
)
257 win_skip("%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w(class_name
));
262 hr
= IActivationFactory_QueryInterface(factory
, &IID_IInspectable
, (void **)&inspectable
);
263 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
265 hr
= IActivationFactory_QueryInterface(factory
, &IID_IAgileObject
, (void **)&agile_object
);
266 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
268 hr
= IActivationFactory_QueryInterface(factory
, &IID_ILanguageFactory
, (void **)&language_factory
);
269 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
271 hr
= ILanguageFactory_QueryInterface(language_factory
, &IID_IInspectable
, (void **)&tmp_inspectable
);
272 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
273 ok(tmp_inspectable
== inspectable
, "Unexpected interface pointer %p, expected %p.\n", tmp_inspectable
, inspectable
);
274 IInspectable_Release(tmp_inspectable
);
276 hr
= ILanguageFactory_QueryInterface(language_factory
, &IID_IAgileObject
, (void **)&tmp_agile_object
);
277 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
278 ok(tmp_agile_object
== agile_object
, "Unexpected interface pointer %p, expected %p.\n", tmp_agile_object
, agile_object
);
279 IAgileObject_Release(tmp_agile_object
);
281 /* Invalid language tag */
282 hr
= WindowsCreateString(L
"test-tag", 8, &str
);
283 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
284 hr
= ILanguageFactory_CreateLanguage(language_factory
, str
, &language
);
285 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
287 ILanguage_Release(language
);
288 WindowsDeleteString(str
);
290 hr
= WindowsCreateString(L
"en-us", 5, &str
);
291 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
292 hr
= ILanguageFactory_CreateLanguage(language_factory
, str
, &language
);
293 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
294 WindowsDeleteString(str
);
296 hr
= ILanguage_get_LanguageTag(language
, &tag
);
297 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
298 buf
= WindowsGetStringRawBuffer(tag
, NULL
);
299 ok(!wcscmp(buf
, L
"en-US"), "Unexpected tag %s.\n", debugstr_w(buf
));
300 GetLocaleInfoEx(L
"en-us", LOCALE_SNAME
, buffer
, ARRAY_SIZE(buffer
));
301 ok(!wcscmp(buf
, buffer
), "Unexpected tag %s, locale name %s.\n", debugstr_w(buf
), debugstr_w(buffer
));
303 WindowsDeleteString(tag
);
305 ILanguage_Release(language
);
307 ILanguageFactory_Release(language_factory
);
309 IAgileObject_Release(agile_object
);
310 IInspectable_Release(inspectable
);
311 IActivationFactory_Release(factory
);
316 START_TEST(globalization
)
320 kernel32
= GetModuleHandleA("kernel32");
321 pGetUserDefaultGeoName
= (void*)GetProcAddress(kernel32
, "GetUserDefaultGeoName");
323 test_GlobalizationPreferences();