This commit is contained in:
Kenny Kerr 2020-02-05 07:27:40 -08:00 коммит произвёл GitHub
Родитель fa9090c34c
Коммит b27c5c43c0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 96 добавлений и 21 удалений

Просмотреть файл

@ -3,24 +3,24 @@ namespace TestComponent
{
struct Blittable
{
Boolean A;
UInt8 B;
UInt16 C;
UInt32 D;
UInt64 E;
Int16 F;
Int32 G;
Int64 H;
Single I;
Double J;
Char K;
Guid L;
UInt8 A;
UInt16 B;
UInt32 C;
UInt64 D;
Int16 E;
Int32 F;
Int64 G;
Single H;
Double I;
Char J;
Guid K;
};
struct NonBlittable
{
String A;
Windows.Foundation.IReference<Int64> B;
Boolean A;
String B;
Windows.Foundation.IReference<Int64> C;
};
struct Nested
@ -165,6 +165,12 @@ namespace TestComponent
void Async2Call(Async2Handler handler);
void Async3Call(Async3Handler handler);
void Async4Call(Async4Handler handler);
event Windows.Foundation.EventHandler<Int32> Event1;
event Windows.Foundation.TypedEventHandler<ITests, Int32> Event2;
void Event1Call(Int32 value);
void Event2Call(Int32 value);
}
delegate void TestHandler(ITests tests);

Просмотреть файл

@ -32,7 +32,9 @@ namespace winrt::TestComponent::implementation
private:
uint32_t m_counter{};
const uint32_t m_total{ 89 };
const uint32_t m_total{ 97 };
event<EventHandler<int32_t>> m_event1;
event<TypedEventHandler<ITests, int32_t>> m_event2;
public:
@ -137,9 +139,9 @@ namespace winrt::TestComponent::implementation
TEST_REQUIRE_N(L"Param", number, a == b && a == c); \
}
TEST_GEN(13, Blittable, (Blittable{ false, 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'X', guid_of<ITests>() }));
TEST_GEN(14, NonBlittable, (NonBlittable{ L"WinRT", 1234 }));
TEST_GEN(15, Nested, (Nested{ { false, 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'X', guid_of<ITests>() }, { L"WinRT", 1234 } }));
TEST_GEN(13, Blittable, (Blittable{ 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'X', guid_of<ITests>() }));
TEST_GEN(14, NonBlittable, (NonBlittable{ false, L"WinRT", 1234 }));
TEST_GEN(15, Nested, (Nested{ { 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'X', guid_of<ITests>() }, { true, L"WinRT", 1234 } }));
#undef TEST_GEN
@ -195,9 +197,9 @@ namespace winrt::TestComponent::implementation
TEST_GEN(10, double, (4.0f, 5.0f, 6.0f));
TEST_GEN(11, char16_t, (L'W', L'i', L'n'));
TEST_GEN(12, hstring, (L"C++", L"C#", L"Rust"));
TEST_GEN(13, Blittable, (Blittable{ false, 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'X', guid_of<ITests>() }, Blittable{ true, 10, 20, 30, 40, -50, -60, -70, 80.0f, 90.0, L'Y', guid_of<IStringable>() }, Blittable{ false, 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'Z', guid_of<IInspectable>() }));
TEST_GEN(14, NonBlittable, (NonBlittable{ L"First", 123 }, NonBlittable{ L"Second", 456 }, NonBlittable{ L"Third", 789 }));
TEST_GEN(15, Nested, (Nested{ { false, 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'X', guid_of<ITests>() }, { L"First", 123 } }, Nested{ { true, 10, 20, 30, 40, -50, -60, -70, 80.0f, 90.0, L'Y', guid_of<IStringable>() }, { L"Second", 456 } }, Nested{ { false, 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'Z', guid_of<IInspectable>() }, { L"Third", 789 } }));
TEST_GEN(13, Blittable, (Blittable{ 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'X', guid_of<ITests>() }, Blittable{ 10, 20, 30, 40, -50, -60, -70, 80.0f, 90.0, L'Y', guid_of<IStringable>() }, Blittable{ 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'Z', guid_of<IInspectable>() }));
TEST_GEN(14, NonBlittable, (NonBlittable{ false, L"First", 123 }, NonBlittable{ true, L"Second", 456 }, NonBlittable{ false, L"Third", 789 }));
TEST_GEN(15, Nested, (Nested{ { 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'X', guid_of<ITests>() }, { false, L"First", 123 } }, Nested{ { 10, 20, 30, 40, -50, -60, -70, 80.0f, 90.0, L'Y', guid_of<IStringable>() }, { true, L"Second", 456 } }, Nested{ { 1, 2, 3, 4, -5, -6, -7, 8.0f, 9.0, L'Z', guid_of<IInspectable>() }, { false, L"Third", 789 } }));
#undef TEST_GEN
@ -494,6 +496,37 @@ namespace winrt::TestComponent::implementation
TEST_REQUIRE(L"Async4", progress == 321);
}
}
event_token Event1(EventHandler<int32_t> const& handler)
{
return m_event1.add(handler);
}
void Event1(event_token token) noexcept
{
m_event1.remove(token);
}
event_token Event2(TypedEventHandler<ITests, int32_t> const& handler)
{
return m_event2.add(handler);
}
void Event2(event_token token)
{
m_event2.remove(token);
}
void Event1Call(int32_t value)
{
m_event1(*this, value);
}
void Event2Call(int32_t value)
{
m_event2(*this, value);
}
};
void RunTests(ITests const& tests)
@ -548,6 +581,42 @@ namespace winrt::TestComponent::implementation
TEST_GEN(Async, 4);
#undef TEST_GEN
{
int32_t counter = 0;
auto token = tests.Event1([&](IInspectable const& sender, int32_t args)
{
TEST_REQUIRE(L"Event1", sender == tests);
TEST_REQUIRE(L"Event1", args == 123);
TEST_REQUIRE(L"Event1", counter == 0);
++counter;
});
tests.Event1Call(123);
TEST_REQUIRE(L"Event1", counter == 1);
tests.Event1(token);
tests.Event1Call(456);
TEST_REQUIRE(L"Event1", counter == 1);
}
{
int32_t counter = 0;
auto token = tests.Event2([&](ITests const& sender, int32_t args)
{
TEST_REQUIRE(L"Event2", sender == tests);
TEST_REQUIRE(L"Event2", args == 123);
TEST_REQUIRE(L"Event2", counter == 0);
++counter;
});
tests.Event2Call(123);
TEST_REQUIRE(L"Event2", counter == 1);
tests.Event2(token);
tests.Event2Call(456);
TEST_REQUIRE(L"Event2", counter == 1);
}
}
void TestRunner::TestProducer(ITests const& tests)