Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions TestComponent/CountedFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "pch.h"
#include "CountedFactory.h"
#include "CountedFactory.g.cpp"

#include <atomic>

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<uint32_t> s_count;

CountedFactory::CountedFactory() noexcept
{
++s_count;
}

CountedFactory::~CountedFactory()
{
--s_count;
}

uint32_t CountedFactory::Count() noexcept
{
return s_count;
}
}
24 changes: 24 additions & 0 deletions TestComponent/CountedFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include "CountedFactory.g.h"

namespace winrt::TestComponent::implementation
{
struct CountedFactory : CountedFactoryT<CountedFactory>
{
CountedFactory() = default;

static void StaticMethod();
};
}

namespace winrt::TestComponent::factory_implementation
{
struct CountedFactory : CountedFactoryT<CountedFactory, implementation::CountedFactory>
{
CountedFactory() noexcept;
~CountedFactory();

// How many of these exist.
static uint32_t Count() noexcept;
};
}
12 changes: 12 additions & 0 deletions TestComponent/FactoryCounter.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
}
19 changes: 19 additions & 0 deletions TestComponent/FactoryCounter.h
Original file line number Diff line number Diff line change
@@ -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<FactoryCounter, implementation::FactoryCounter>
{
};
}
24 changes: 24 additions & 0 deletions TestComponent/TestComponent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
}
}
2 changes: 1 addition & 1 deletion TestComponent/TestComponent.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>PyWinRT.TestWinRT</id>
<version>1.6.1</version>
<version>1.7.0</version>
<title>TestWinRT</title>
<authors>Microsoft</authors>
<license type="expression">MIT</license>
Expand Down
4 changes: 4 additions & 0 deletions TestComponent/TestComponent.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@
<ClInclude Include="ControlledAsync.h" />
<ClInclude Include="Class.h" />
<ClInclude Include="Composable.h" />
<ClInclude Include="CountedFactory.h" />
<ClInclude Include="Derived.h" />
<ClInclude Include="DerivedOverride.h" />
<ClInclude Include="FactoryCounter.h" />
<ClInclude Include="OverloadClass.h" />
<ClInclude Include="Override.h" />
<ClInclude Include="ProtectedMembers.h" />
Expand All @@ -165,8 +167,10 @@
<ClCompile Include="AsyncOperationSource.cpp" />
<ClCompile Include="Class.cpp" />
<ClCompile Include="Composable.cpp" />
<ClCompile Include="CountedFactory.cpp" />
<ClCompile Include="Derived.cpp" />
<ClCompile Include="DerivedOverride.cpp" />
<ClCompile Include="FactoryCounter.cpp" />
<ClCompile Include="OverloadClass.cpp" />
<ClCompile Include="Override.cpp" />
<ClCompile Include="ProtectedMembers.cpp" />
Expand Down
4 changes: 4 additions & 0 deletions TestComponent/TestComponent.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<ClCompile Include="ProtectedMembers.cpp" />
<ClCompile Include="AsyncActionSource.cpp" />
<ClCompile Include="AsyncOperationSource.cpp" />
<ClCompile Include="CountedFactory.cpp" />
<ClCompile Include="FactoryCounter.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
Expand All @@ -36,6 +38,8 @@
<ClInclude Include="AsyncActionSource.h" />
<ClInclude Include="AsyncOperationSource.h" />
<ClInclude Include="ControlledAsync.h" />
<ClInclude Include="CountedFactory.h" />
<ClInclude Include="FactoryCounter.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="TestComponent.idl" />
Expand Down
Loading