2 * Copyright (C) 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
20 #pragma makedep testdll
30 #include "winstring.h"
34 #define WIDL_using_Windows_Foundation
35 #define WIDL_using_Windows_Foundation_Collections
36 #include "windows.foundation.h"
37 #define WIDL_using_Windows_ApplicationModel
38 #define WIDL_using_Windows_Storage
39 #include "windows.applicationmodel.h"
41 #define WINE_WINRT_TEST
42 #include "winrt_test.h"
44 #define check_interface( obj, iid ) check_interface_( __LINE__, obj, iid )
45 static void check_interface_( unsigned int line
, void *obj
, const IID
*iid
)
47 IUnknown
*iface
= obj
;
51 hr
= IUnknown_QueryInterface( iface
, iid
, (void **)&unk
);
52 ok_(__FILE__
, line
)( hr
== S_OK
, "got hr %#lx.\n", hr
);
54 IUnknown_Release( unk
);
57 static void test_PackageStatics(void)
59 static const WCHAR
*package_statics_name
= L
"Windows.ApplicationModel.Package";
60 IPackageStatics
*package_statics
;
61 IStorageFolder
*storage_folder
;
62 IActivationFactory
*factory
;
63 IStorageItem
*storage_item
;
69 hr
= WindowsCreateString( package_statics_name
, wcslen( package_statics_name
), &str
);
70 ok( hr
== S_OK
, "got hr %#lx.\n", hr
);
72 hr
= RoGetActivationFactory( str
, &IID_IActivationFactory
, (void **)&factory
);
73 WindowsDeleteString( str
);
74 ok( hr
== S_OK
|| broken( hr
== REGDB_E_CLASSNOTREG
), "got hr %#lx.\n", hr
);
75 if (hr
== REGDB_E_CLASSNOTREG
)
77 win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( package_statics_name
) );
81 check_interface( factory
, &IID_IUnknown
);
82 check_interface( factory
, &IID_IInspectable
);
84 hr
= IActivationFactory_QueryInterface( factory
, &IID_IPackageStatics
, (void **)&package_statics
);
85 ok( hr
== S_OK
, "got hr %#lx.\n", hr
);
87 hr
= IPackageStatics_get_Current( package_statics
, NULL
);
88 ok( hr
== E_INVALIDARG
, "got hr %#lx.\n", hr
);
89 hr
= IPackageStatics_get_Current( package_statics
, &package
);
90 ok( hr
== S_OK
, "got hr %#lx.\n", hr
);
91 ok( package
!= NULL
, "got NULL package %p.\n", package
);
93 check_interface( package
, &IID_IUnknown
);
94 check_interface( package
, &IID_IInspectable
);
95 check_interface( package
, &IID_IAgileObject
);
96 check_interface( package
, &IID_IPackage
);
98 hr
= IPackage_get_InstalledLocation( package
, NULL
);
99 ok( hr
== E_INVALIDARG
, "got hr %#lx.\n", hr
);
100 hr
= IPackage_get_InstalledLocation( package
, &storage_folder
);
101 ok( hr
== S_OK
, "got hr %#lx.\n", hr
);
103 check_interface( storage_folder
, &IID_IUnknown
);
104 check_interface( storage_folder
, &IID_IInspectable
);
105 check_interface( storage_folder
, &IID_IStorageFolder
);
107 hr
= IStorageFolder_QueryInterface( storage_folder
, &IID_IStorageItem
, (void **)&storage_item
);
108 ok( hr
== S_OK
, "got hr %#lx.\n", hr
);
110 ref
= IStorageItem_Release( storage_item
);
111 ok( ref
== 1, "got ref %ld.\n", ref
);
112 ref
= IStorageFolder_Release( storage_folder
);
113 ok( !ref
, "got ref %ld.\n", ref
);
114 ref
= IPackage_Release( package
);
115 ok( !ref
, "got ref %ld.\n", ref
);
116 ref
= IPackageStatics_Release( package_statics
);
117 ok( ref
== 2, "got ref %ld.\n", ref
);
118 ref
= IActivationFactory_Release( factory
);
119 ok( ref
== 1, "got ref %ld.\n", ref
);
122 int main( int argc
, char const *argv
[] )
126 if (!winrt_test_init()) return -1;
128 hr
= RoInitialize( RO_INIT_MULTITHREADED
);
129 ok( hr
== S_OK
, "RoInitialize failed, hr %#lx\n", hr
);
131 test_PackageStatics();