twinapi.appcore: Stub Windows.System.UserProfile.AdvertisingManager factory.
[wine.git] / dlls / twinapi.appcore / tests / twinapi.c
blobe5251475e574715099468ea68f508faae14ab75c
1 /*
2 * Copyright 2023 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
19 #include <stdarg.h>
20 #include <stddef.h>
22 #include "windef.h"
23 #include "winbase.h"
25 #define COBJMACROS
26 #include "initguid.h"
27 #include "winstring.h"
28 #include "winternl.h"
29 #include "roapi.h"
31 #define WIDL_using_Windows_Foundation
32 #define WIDL_using_Windows_Foundation_Collections
33 #include "windows.foundation.h"
34 #define WIDL_using_Windows_Security_ExchangeActiveSyncProvisioning
35 #include "windows.security.exchangeactivesyncprovisioning.h"
36 #define WIDL_using_Windows_System_Profile
37 #include "windows.system.profile.h"
38 #define WIDL_using_Windows_System_UserProfile
39 #include "windows.system.userprofile.h"
41 #include "wine/test.h"
43 #define check_interface( a, b, c ) check_interface_( __LINE__, a, b, c, FALSE )
44 static void check_interface_( unsigned int line, void *iface_ptr, REFIID iid, BOOL supported, BOOL is_broken )
46 HRESULT hr, expected_hr, broken_hr;
47 IUnknown *iface = iface_ptr;
48 IUnknown *unk;
50 expected_hr = supported ? S_OK : E_NOINTERFACE;
51 broken_hr = supported ? E_NOINTERFACE : S_OK;
52 hr = IUnknown_QueryInterface( iface, iid, (void **)&unk );
53 ok_(__FILE__, line)( hr == expected_hr || broken( is_broken && hr == broken_hr ),
54 "got hr %#lx, expected %#lx.\n", hr, expected_hr );
55 if (SUCCEEDED(hr)) IUnknown_Release( unk );
58 static void test_EasClientDeviceInformation(void)
60 static const WCHAR *class_name = RuntimeClass_Windows_Security_ExchangeActiveSyncProvisioning_EasClientDeviceInformation;
61 IEasClientDeviceInformation *client_device_information;
62 IActivationFactory *factory;
63 HSTRING str;
64 HRESULT hr;
65 LONG ref;
67 hr = WindowsCreateString( class_name, wcslen( class_name ), &str );
68 ok( hr == S_OK, "got hr %#lx.\n", hr );
70 hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory );
71 WindowsDeleteString( str );
72 ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr );
73 if (hr == REGDB_E_CLASSNOTREG)
75 win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( class_name ) );
76 return;
79 check_interface( factory, &IID_IUnknown, TRUE );
80 check_interface( factory, &IID_IInspectable, TRUE );
81 check_interface( factory, &IID_IAgileObject, FALSE );
83 hr = IActivationFactory_ActivateInstance( factory, (IInspectable **)&client_device_information );
84 ok( hr == S_OK, "got hr %#lx.\n", hr );
86 check_interface( client_device_information, &IID_IUnknown, TRUE );
87 check_interface( client_device_information, &IID_IInspectable, TRUE );
88 check_interface( client_device_information, &IID_IAgileObject, FALSE );
90 hr = IEasClientDeviceInformation_get_OperatingSystem( client_device_information, &str );
91 ok( hr == S_OK, "got hr %#lx\n", hr );
92 WindowsDeleteString( str );
94 hr = IEasClientDeviceInformation_get_FriendlyName( client_device_information, &str );
95 ok( hr == S_OK, "got hr %#lx\n", hr );
96 WindowsDeleteString( str );
98 hr = IEasClientDeviceInformation_get_SystemManufacturer( client_device_information, &str );
99 ok( hr == S_OK, "got hr %#lx\n", hr );
100 WindowsDeleteString( str );
102 hr = IEasClientDeviceInformation_get_SystemProductName( client_device_information, &str );
103 ok( hr == S_OK, "got hr %#lx\n", hr );
104 WindowsDeleteString( str );
106 hr = IEasClientDeviceInformation_get_SystemSku( client_device_information, &str );
107 ok( hr == S_OK, "got hr %#lx\n", hr );
108 WindowsDeleteString( str );
110 ref = IEasClientDeviceInformation_Release( client_device_information );
111 ok( ref == 0, "got ref %ld.\n", ref );
113 ref = IActivationFactory_Release( factory );
114 ok( ref == 1, "got ref %ld.\n", ref );
117 static void test_AnalyticsVersionInfo(void)
119 static const WCHAR *class_name = RuntimeClass_Windows_System_Profile_AnalyticsInfo;
120 IAnalyticsInfoStatics *analytics_info_statics;
121 IAnalyticsVersionInfo *analytics_version_info;
122 IActivationFactory *factory;
123 HSTRING str, expect_str;
124 DWORD revision, size;
125 WCHAR buffer[32];
126 UINT64 version;
127 HRESULT hr;
128 INT32 res;
129 LONG ref;
131 hr = WindowsCreateString( class_name, wcslen( class_name ), &str );
132 ok( hr == S_OK, "got hr %#lx.\n", hr );
134 hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory );
135 WindowsDeleteString( str );
136 ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr );
137 if (hr == REGDB_E_CLASSNOTREG)
139 win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( class_name ) );
140 return;
143 check_interface( factory, &IID_IUnknown, TRUE );
144 check_interface( factory, &IID_IInspectable, TRUE );
145 check_interface( factory, &IID_IAgileObject, TRUE );
147 hr = IActivationFactory_QueryInterface( factory, &IID_IAnalyticsInfoStatics, (void **)&analytics_info_statics );
148 ok( hr == S_OK, "got hr %#lx.\n", hr );
150 hr = IAnalyticsInfoStatics_get_VersionInfo( analytics_info_statics, &analytics_version_info );
151 ok( hr == S_OK, "got hr %#lx.\n", hr );
153 check_interface( analytics_version_info, &IID_IUnknown, TRUE );
154 check_interface( analytics_version_info, &IID_IInspectable, TRUE );
155 check_interface( analytics_version_info, &IID_IAgileObject, TRUE );
157 hr = WindowsCreateString( L"Windows.Desktop", wcslen( L"Windows.Desktop" ), &expect_str );
158 ok( hr == S_OK, "got hr %#lx.\n", hr );
159 hr = IAnalyticsVersionInfo_get_DeviceFamily( analytics_version_info, &str );
160 ok( hr == S_OK, "got hr %#lx.\n", hr );
161 hr = WindowsCompareStringOrdinal( str, expect_str, &res );
162 ok( hr == S_OK, "got hr %#lx.\n", hr );
163 ok( !res, "got unexpected string %s.\n", debugstr_hstring(str) );
164 WindowsDeleteString( str );
165 WindowsDeleteString( expect_str );
167 if (RegGetValueW( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion", L"UBR",
168 RRF_RT_REG_DWORD, NULL, &revision, &size ))
169 revision = 0;
170 version = NtCurrentTeb()->Peb->OSMajorVersion & 0xffff;
171 version = (version << 16) | (NtCurrentTeb()->Peb->OSMinorVersion & 0xffff);
172 version = (version << 16) | (NtCurrentTeb()->Peb->OSBuildNumber & 0xffff);
173 version = (version << 16) | revision;
175 res = swprintf( buffer, ARRAY_SIZE(buffer), L"%I64u", version );
176 hr = WindowsCreateString( buffer, res, &expect_str );
177 ok( hr == S_OK, "got hr %#lx.\n", hr );
178 hr = IAnalyticsVersionInfo_get_DeviceFamilyVersion( analytics_version_info, &str );
179 ok( hr == S_OK, "got hr %#lx.\n", hr );
180 hr = WindowsCompareStringOrdinal( str, expect_str, &res );
181 ok( hr == S_OK, "got hr %#lx.\n", hr );
182 ok( !res || broken(revision == 0) /* Win11 */, "got unexpected string %s.\n", debugstr_hstring(str) );
183 WindowsDeleteString( str );
184 WindowsDeleteString( expect_str );
186 ref = IAnalyticsVersionInfo_Release( analytics_version_info );
187 ok( ref == 0, "got ref %ld.\n", ref );
189 ref = IAnalyticsInfoStatics_Release( analytics_info_statics );
190 ok( ref == 2, "got ref %ld.\n", ref );
191 ref = IActivationFactory_Release( factory );
192 ok( ref == 1, "got ref %ld.\n", ref );
195 static void test_AdvertisingManager(void)
197 static const WCHAR *class_name = RuntimeClass_Windows_System_UserProfile_AdvertisingManager;
198 IAdvertisingManagerStatics *advertising_manager_statics;
199 IActivationFactory *factory;
200 HSTRING str;
201 HRESULT hr;
202 LONG ref;
204 hr = WindowsCreateString( class_name, wcslen( class_name ), &str );
205 ok( hr == S_OK, "got hr %#lx.\n", hr );
207 hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory );
208 WindowsDeleteString( str );
209 ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr );
210 if (hr == REGDB_E_CLASSNOTREG)
212 win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( class_name ) );
213 return;
216 check_interface( factory, &IID_IUnknown, TRUE );
217 check_interface( factory, &IID_IInspectable, TRUE );
218 check_interface_( __LINE__, factory, &IID_IAgileObject, TRUE, TRUE );
220 hr = IActivationFactory_QueryInterface( factory, &IID_IAdvertisingManagerStatics, (void **)&advertising_manager_statics );
221 ok( hr == S_OK, "got hr %#lx.\n", hr );
223 ref = IAdvertisingManagerStatics_Release( advertising_manager_statics );
224 ok( ref == 2, "got ref %ld.\n", ref );
225 ref = IActivationFactory_Release( factory );
226 ok( ref == 1, "got ref %ld.\n", ref );
229 START_TEST(twinapi)
231 HRESULT hr;
233 hr = RoInitialize( RO_INIT_MULTITHREADED );
234 ok( hr == S_OK, "RoInitialize failed, hr %#lx\n", hr );
236 test_EasClientDeviceInformation();
237 test_AnalyticsVersionInfo();
238 test_AdvertisingManager();
240 RoUninitialize();