diff --git a/TestComponent/CountedFactory.cpp b/TestComponent/CountedFactory.cpp new file mode 100644 index 0000000..054f3a5 --- /dev/null +++ b/TestComponent/CountedFactory.cpp @@ -0,0 +1,33 @@ +#include "pch.h" +#include "CountedFactory.h" +#include "CountedFactory.g.cpp" + +#include + +namespace winrt::TestComponent::implementation +{ + void CountedFactory::StaticMethod() + { + } +} + +namespace winrt::TestComponent::factory_implementation +{ + // Factories are made and released on whatever thread asks for them. + static std::atomic s_count; + + CountedFactory::CountedFactory() noexcept + { + ++s_count; + } + + CountedFactory::~CountedFactory() + { + --s_count; + } + + uint32_t CountedFactory::Count() noexcept + { + return s_count; + } +} diff --git a/TestComponent/CountedFactory.h b/TestComponent/CountedFactory.h new file mode 100644 index 0000000..29076d8 --- /dev/null +++ b/TestComponent/CountedFactory.h @@ -0,0 +1,24 @@ +#pragma once +#include "CountedFactory.g.h" + +namespace winrt::TestComponent::implementation +{ + struct CountedFactory : CountedFactoryT + { + CountedFactory() = default; + + static void StaticMethod(); + }; +} + +namespace winrt::TestComponent::factory_implementation +{ + struct CountedFactory : CountedFactoryT + { + CountedFactory() noexcept; + ~CountedFactory(); + + // How many of these exist. + static uint32_t Count() noexcept; + }; +} diff --git a/TestComponent/FactoryCounter.cpp b/TestComponent/FactoryCounter.cpp new file mode 100644 index 0000000..95a81c5 --- /dev/null +++ b/TestComponent/FactoryCounter.cpp @@ -0,0 +1,12 @@ +#include "pch.h" +#include "FactoryCounter.h" +#include "FactoryCounter.g.cpp" +#include "CountedFactory.h" + +namespace winrt::TestComponent::implementation +{ + uint32_t FactoryCounter::CountedFactoryCount() + { + return factory_implementation::CountedFactory::Count(); + } +} diff --git a/TestComponent/FactoryCounter.h b/TestComponent/FactoryCounter.h new file mode 100644 index 0000000..6212c56 --- /dev/null +++ b/TestComponent/FactoryCounter.h @@ -0,0 +1,19 @@ +#pragma once +#include "FactoryCounter.g.h" + +namespace winrt::TestComponent::implementation +{ + struct FactoryCounter + { + FactoryCounter() = default; + + static uint32_t CountedFactoryCount(); + }; +} + +namespace winrt::TestComponent::factory_implementation +{ + struct FactoryCounter : FactoryCounterT + { + }; +} diff --git a/TestComponent/TestComponent.idl b/TestComponent/TestComponent.idl index 6eebb75..16232ec 100644 --- a/TestComponent/TestComponent.idl +++ b/TestComponent/TestComponent.idl @@ -447,4 +447,28 @@ namespace TestComponent void Cancel(); void InvokeCompletedHandler(); } + + // A class whose activation factories count themselves, for testing that a + // projection lets go of the activation factories it keeps. + // + // DllGetActivationFactory makes a new factory each time it is asked for + // one, and the component keeps none, so the count is how many factories + // its callers hold: a projection that keeps the factory it calls a + // constructor or a static through holds one for each factory it asked + // for, and none once it has let go of them. + [default_interface] + runtimeclass CountedFactory + { + CountedFactory(); + + static void StaticMethod(); + } + + // Reads the count of CountedFactory's activation factories through a + // factory of its own, so that reading it holds none of them. + static runtimeclass FactoryCounter + { + // How many activation factories of CountedFactory exist. + static UInt32 CountedFactoryCount{ get; }; + } } diff --git a/TestComponent/TestComponent.nuspec b/TestComponent/TestComponent.nuspec index d59294f..128ce60 100644 --- a/TestComponent/TestComponent.nuspec +++ b/TestComponent/TestComponent.nuspec @@ -2,7 +2,7 @@ PyWinRT.TestWinRT - 1.6.1 + 1.7.0 TestWinRT Microsoft MIT diff --git a/TestComponent/TestComponent.vcxproj b/TestComponent/TestComponent.vcxproj index 74c6c97..1df9352 100644 --- a/TestComponent/TestComponent.vcxproj +++ b/TestComponent/TestComponent.vcxproj @@ -152,8 +152,10 @@ + + @@ -165,8 +167,10 @@ + + diff --git a/TestComponent/TestComponent.vcxproj.filters b/TestComponent/TestComponent.vcxproj.filters index db02db5..10599f8 100644 --- a/TestComponent/TestComponent.vcxproj.filters +++ b/TestComponent/TestComponent.vcxproj.filters @@ -22,6 +22,8 @@ + + @@ -36,6 +38,8 @@ + +