@@ -88,6 +88,96 @@ namespace Test::DynamicDependency
8888 MddBootstrapShutdown ();
8989 }
9090
91+ TEST_METHOD (GetCurrentPackageInfo_NotPackaged_InvalidParameter)
92+ {
93+ const UINT32 c_filter{ PACKAGE_FILTER_HEAD | PACKAGE_FILTER_DIRECT | PACKAGE_INFORMATION_BASIC };
94+
95+ {
96+ Assert::AreEqual (E_INVALIDARG, HRESULT_FROM_WIN32 (::GetCurrentPackageInfo (c_filter, nullptr , nullptr , nullptr )));
97+ }
98+ {
99+ UINT32 count{};
100+ Assert::AreEqual (E_INVALIDARG, HRESULT_FROM_WIN32 (::GetCurrentPackageInfo (c_filter, nullptr , nullptr , &count)));
101+ }
102+
103+ {
104+ UINT32 bufferLength{ 1 };
105+ Assert::AreEqual (E_INVALIDARG, HRESULT_FROM_WIN32 (::GetCurrentPackageInfo (c_filter, &bufferLength, nullptr , nullptr )));
106+ }
107+ {
108+ UINT32 bufferLength{ 1 };
109+ UINT32 count{};
110+ Assert::AreEqual (E_INVALIDARG, HRESULT_FROM_WIN32 (::GetCurrentPackageInfo (c_filter, &bufferLength, nullptr , &count)));
111+ }
112+
113+ {
114+ BYTE buffer[1 ]{};
115+ UINT32 bufferLength{ static_cast <UINT32>(ARRAYSIZE (buffer)) };
116+ Assert::AreEqual (E_INVALIDARG, HRESULT_FROM_WIN32 (::GetCurrentPackageInfo (c_filter, &bufferLength, buffer, nullptr )));
117+ }
118+ }
119+
120+ TEST_METHOD (GetCurrentPackageInfo_NotPackaged)
121+ {
122+ VerifyGetCurrentPackageInfo ();
123+
124+ winrt::hstring packageFamilyName{ Test::Packages::DynamicDependencyLifetimeManager::c_PackageFamilyName };
125+ auto applicationData{ winrt::Windows::Management::Core::ApplicationDataManager::CreateForPackageFamily (packageFamilyName) };
126+
127+ Assert::AreEqual (S_OK, MddBootstrapTestInitialize (Test::Packages::DynamicDependencyLifetimeManager::c_PackageNamePrefix, Test::Packages::DynamicDependencyLifetimeManager::c_PackagePublisherId));
128+
129+ // Version <major>.0.0.0 to find any framework package for this major version
130+ PACKAGE_VERSION minVersion{ static_cast <UINT64>(Test::Packages::DynamicDependencyLifetimeManager::c_Version.Major ) << 48 };
131+ Assert::AreEqual (S_OK, MddBootstrapInitialize (minVersion));
132+
133+ VerifyGetCurrentPackageInfo (HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER), 1 , 700 );
134+
135+ winrt::Windows::ApplicationModel::AppExtensions::AppExtensionCatalog::Open (L" Does.Not.Exist" );
136+
137+ MddBootstrapShutdown ();
138+
139+ VerifyGetCurrentPackageInfo ();
140+ }
141+
142+ #if defined(TODO_EnableAfterConvertingToTAEF)
143+ TEST_METHOD (GetCurrentPackageInfo_Packaged)
144+ {
145+ VerifyGetCurrentPackageInfo ();
146+
147+ winrt::hstring packageFamilyName{ Test::Packages::DynamicDependencyLifetimeManager::c_PackageFamilyName };
148+ auto applicationData{ winrt::Windows::Management::Core::ApplicationDataManager::CreateForPackageFamily (packageFamilyName) };
149+
150+ Assert::AreEqual (S_OK, MddBootstrapTestInitialize (Test::Packages::DynamicDependencyLifetimeManager::c_PackageNamePrefix, Test::Packages::DynamicDependencyLifetimeManager::c_PackagePublisherId));
151+
152+ // Version <major>.0.0.0 to find any framework package for this major version
153+ PACKAGE_VERSION minVersion{ static_cast <UINT64>(Test::Packages::DynamicDependencyLifetimeManager::c_Version.Major ) << 48 };
154+ Assert::AreEqual (HRESULT_FROM_WIN32 (ERROR_NOT_SUPPORTED), MddBootstrapInitialize (minVersion));
155+
156+ VerifyGetCurrentPackageInfo ();
157+ }
158+ #endif
159+
160+ private:
161+ static void VerifyGetCurrentPackageInfo (
162+ const HRESULT expectedHR = HRESULT_FROM_WIN32 (APPMODEL_ERROR_NO_PACKAGE),
163+ const UINT32 expectedCount = 0 ,
164+ const UINT32 minExpectedBufferLength = 0 )
165+ {
166+ UINT32 bufferLength{};
167+ UINT32 count{};
168+ Assert::AreEqual (expectedHR, HRESULT_FROM_WIN32 (::GetCurrentPackageInfo (PACKAGE_FILTER_HEAD | PACKAGE_FILTER_DIRECT | PACKAGE_INFORMATION_BASIC, &bufferLength, nullptr , &count)));
169+ Assert::AreEqual (expectedCount, count);
170+ if (minExpectedBufferLength > 0 )
171+ {
172+ auto message{ wil::str_printf<wil::unique_process_heap_string>(L" GetCurrentPackageInfo2() expectedBufferLength>=%u bufferLength=%u" , minExpectedBufferLength, bufferLength) };
173+ Assert::IsTrue (bufferLength >= minExpectedBufferLength, message.get ());
174+ }
175+ else
176+ {
177+ Assert::AreEqual (0u , bufferLength);
178+ }
179+ }
180+
91181 private:
92182 static wil::unique_hmodule m_bootstrapDll;
93183 };
0 commit comments