-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathTest_ST_Policy.cpp
84 lines (63 loc) · 2.6 KB
/
Test_ST_Policy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <list>
#include "CppUnitTest.h"
#include "Test_Base.hpp"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Nano_Tests
{
TEST_CLASS(Test_ST_Policy)
{
const int N = 64;
using Moo_T = Moo<Observer_ST>;
using Subject = Signal_Rng_ST;
TEST_METHOD(Test_Global_Signal)
{
Subject subject;
std::size_t count = 0;
Rng rng;
for (; count < N; ++count)
{
std::list<Moo_T> moo(N);
for (auto& moo_instance : moo)
{
subject.connect<&Moo_T::slot_next_random>(moo_instance);
}
subject.fire(rng);
}
Assert::IsTrue(subject.is_empty(), L"A signal was found not empty.");
}
//----------------------------------------------------------------------
TEST_METHOD(Test_Signal_Move)
{
Moo_T foo1;
Moo_T foo2;
auto rng1 = Rng();
auto rng2 = Rng();
auto sig1 = new Subject();
auto sig2 = new Subject();
auto fun1 = [](Rng& rng) { rng.discard(1); };
sig1->connect<&Moo_T::slot_next_random>(foo1);
sig1->connect(fun1);
sig1->connect<&Moo_T::slot_static_next_random>();
sig1->connect<&slot_next_random_free_function>();
sig2->connect<&Moo_T::slot_next_random>(foo2);
sig2->connect(fun1);
sig2->connect<&Moo_T::slot_static_next_random>();
sig2->connect<&slot_next_random_free_function>();
{
// This should remove all connections from sig2 and add all sig1 connections
*sig2 = std::move(*sig1);
Assert::IsTrue(sig1->is_empty(), L"Signal failed to remove connections during move.");
Assert::IsTrue(foo2.is_empty(), L"Signal failed to remove connections prior to move.");
Assert::IsFalse(foo1.is_empty(), L"Signal failed to move subject connections to target.");
Assert::IsFalse(sig2->is_empty(), L"Signal failed to move signal connections to target.");
// Should have four connections
sig2->fire(rng1);
rng2.discard(4);
Assert::IsTrue(rng1 == rng2, L"Signal failed to move all connections.");
delete sig2;
}
Assert::IsTrue(foo1.is_empty(), L"Signal failed to dispose connections.");
Assert::IsTrue(foo2.is_empty(), L"Signal failed to dispose connections.");
}
};
}