From 4370846793489dc3f8af843a9c62aa4169c43c8b Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 28 Nov 2026 21:41:28 -0600 Subject: [PATCH 1/2] TestComponent: add composable classes with collection and IClosable ComposableVector, ComposableMap and ComposableClosable are unsealed classes that implement IVector, IMap and IClosable, as XAML's ResourceDictionary, DependencyObjectCollection and DesktopWindowXamlSource do. ComposableClosable records whether Close() was called. This allows testing that a projection gives a class derived from a composable class the collection and IClosable protocols of the class it derives from, without XAML. --- TestComponent/ComposableClosable.cpp | 16 ++++++++++++ TestComponent/ComposableClosable.h | 24 ++++++++++++++++++ TestComponent/ComposableMap.cpp | 21 ++++++++++++++++ TestComponent/ComposableMap.h | 28 +++++++++++++++++++++ TestComponent/ComposableVector.cpp | 21 ++++++++++++++++ TestComponent/ComposableVector.h | 28 +++++++++++++++++++++ TestComponent/TestComponent.idl | 22 ++++++++++++++++ TestComponent/TestComponent.vcxproj | 6 +++++ TestComponent/TestComponent.vcxproj.filters | 6 +++++ 9 files changed, 172 insertions(+) create mode 100644 TestComponent/ComposableClosable.cpp create mode 100644 TestComponent/ComposableClosable.h create mode 100644 TestComponent/ComposableMap.cpp create mode 100644 TestComponent/ComposableMap.h create mode 100644 TestComponent/ComposableVector.cpp create mode 100644 TestComponent/ComposableVector.h diff --git a/TestComponent/ComposableClosable.cpp b/TestComponent/ComposableClosable.cpp new file mode 100644 index 0000000..f270692 --- /dev/null +++ b/TestComponent/ComposableClosable.cpp @@ -0,0 +1,16 @@ +#include "pch.h" +#include "ComposableClosable.h" +#include "ComposableClosable.g.cpp" + +namespace winrt::TestComponent::implementation +{ + void ComposableClosable::Close() + { + m_closed = true; + } + + bool ComposableClosable::IsClosed() + { + return m_closed; + } +} diff --git a/TestComponent/ComposableClosable.h b/TestComponent/ComposableClosable.h new file mode 100644 index 0000000..0b6b322 --- /dev/null +++ b/TestComponent/ComposableClosable.h @@ -0,0 +1,24 @@ +#pragma once +#include "ComposableClosable.g.h" + +namespace winrt::TestComponent::implementation +{ + struct ComposableClosable : ComposableClosableT + { + private: + bool m_closed{}; + + public: + ComposableClosable() = default; + + void Close(); + bool IsClosed(); + }; +} + +namespace winrt::TestComponent::factory_implementation +{ + struct ComposableClosable : ComposableClosableT + { + }; +} diff --git a/TestComponent/ComposableMap.cpp b/TestComponent/ComposableMap.cpp new file mode 100644 index 0000000..b89af4b --- /dev/null +++ b/TestComponent/ComposableMap.cpp @@ -0,0 +1,21 @@ +#include "pch.h" +#include "ComposableMap.h" +#include "ComposableMap.g.cpp" + +namespace winrt::TestComponent::implementation +{ + std::map& ComposableMap::get_container() noexcept + { + return m_values; + } + + std::map const& ComposableMap::get_container() const noexcept + { + return m_values; + } + + Windows::Foundation::Collections::IMapView ComposableMap::GetView() const + { + return single_threaded_map(std::map(m_values)).GetView(); + } +} diff --git a/TestComponent/ComposableMap.h b/TestComponent/ComposableMap.h new file mode 100644 index 0000000..972ca11 --- /dev/null +++ b/TestComponent/ComposableMap.h @@ -0,0 +1,28 @@ +#pragma once +#include "ComposableMap.g.h" + +namespace winrt::TestComponent::implementation +{ + struct ComposableMap : ComposableMapT, map_base + { + private: + std::map m_values; + + public: + ComposableMap() = default; + + std::map& get_container() noexcept; + std::map const& get_container() const noexcept; + + // map_base's own GetView() returns the class itself, as a class that + // also implements IMapView does, which this class does not. + Windows::Foundation::Collections::IMapView GetView() const; + }; +} + +namespace winrt::TestComponent::factory_implementation +{ + struct ComposableMap : ComposableMapT + { + }; +} diff --git a/TestComponent/ComposableVector.cpp b/TestComponent/ComposableVector.cpp new file mode 100644 index 0000000..5f89991 --- /dev/null +++ b/TestComponent/ComposableVector.cpp @@ -0,0 +1,21 @@ +#include "pch.h" +#include "ComposableVector.h" +#include "ComposableVector.g.cpp" + +namespace winrt::TestComponent::implementation +{ + std::vector& ComposableVector::get_container() noexcept + { + return m_values; + } + + std::vector const& ComposableVector::get_container() const noexcept + { + return m_values; + } + + Windows::Foundation::Collections::IVectorView ComposableVector::GetView() const + { + return single_threaded_vector(std::vector(m_values)).GetView(); + } +} diff --git a/TestComponent/ComposableVector.h b/TestComponent/ComposableVector.h new file mode 100644 index 0000000..221783a --- /dev/null +++ b/TestComponent/ComposableVector.h @@ -0,0 +1,28 @@ +#pragma once +#include "ComposableVector.g.h" + +namespace winrt::TestComponent::implementation +{ + struct ComposableVector : ComposableVectorT, vector_base + { + private: + std::vector m_values; + + public: + ComposableVector() = default; + + std::vector& get_container() noexcept; + std::vector const& get_container() const noexcept; + + // vector_base's own GetView() returns the class itself, as a class + // that also implements IVectorView does, which this class does not. + Windows::Foundation::Collections::IVectorView GetView() const; + }; +} + +namespace winrt::TestComponent::factory_implementation +{ + struct ComposableVector : ComposableVectorT + { + }; +} diff --git a/TestComponent/TestComponent.idl b/TestComponent/TestComponent.idl index 16232ec..34509db 100644 --- a/TestComponent/TestComponent.idl +++ b/TestComponent/TestComponent.idl @@ -393,6 +393,28 @@ namespace TestComponent Int32 ReadOverridableValue(); } + // Composable classes that implement a collection or IClosable, as XAML's + // ResourceDictionary, DependencyObjectCollection and + // DesktopWindowXamlSource do, for testing that a projection gives a + // derived class the protocols of the class it derives from. + unsealed runtimeclass ComposableVector : Windows.Foundation.Collections.IVector + { + ComposableVector(); + } + + unsealed runtimeclass ComposableMap : Windows.Foundation.Collections.IMap + { + ComposableMap(); + } + + unsealed runtimeclass ComposableClosable : Windows.Foundation.IClosable + { + ComposableClosable(); + + // Whether Close() has been called. + Boolean IsClosed{ get; }; + } + // An async action whose every step the caller drives, for testing how a // projection waits for an operation, cancels it and lets go of it. // diff --git a/TestComponent/TestComponent.vcxproj b/TestComponent/TestComponent.vcxproj index 1df9352..593188a 100644 --- a/TestComponent/TestComponent.vcxproj +++ b/TestComponent/TestComponent.vcxproj @@ -152,6 +152,9 @@ + + + @@ -167,6 +170,9 @@ + + + diff --git a/TestComponent/TestComponent.vcxproj.filters b/TestComponent/TestComponent.vcxproj.filters index 10599f8..fb58f83 100644 --- a/TestComponent/TestComponent.vcxproj.filters +++ b/TestComponent/TestComponent.vcxproj.filters @@ -24,6 +24,9 @@ + + + @@ -40,6 +43,9 @@ + + + From c4e79102889a680735e77882562b26d0d0f9af9f Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 28 Nov 2026 21:45:14 -0600 Subject: [PATCH 2/2] v1.8.0 --- TestComponent/TestComponent.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestComponent/TestComponent.nuspec b/TestComponent/TestComponent.nuspec index 128ce60..df410ed 100644 --- a/TestComponent/TestComponent.nuspec +++ b/TestComponent/TestComponent.nuspec @@ -2,7 +2,7 @@ PyWinRT.TestWinRT - 1.7.0 + 1.8.0 TestWinRT Microsoft MIT