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
|
#include <gtest/gtest.h>
#include <crepe/ValueBroker.h>
#include <crepe/util/Proxy.h>
using namespace std;
using namespace crepe;
using namespace testing;
class ValueBrokerTest : public Test {
public:
int read_count = 0;
int write_count = 0;
int value = 0;
ValueBroker<int> broker {
[this](const int & target) -> void {
this->write_count++;
this->value = target;
},
[this]() -> const int & {
this->read_count++;
return this->value;
},
};
Proxy<int> proxy{broker};
void SetUp() override {
ASSERT_EQ(read_count, 0);
ASSERT_EQ(write_count, 0);
}
};
TEST_F(ValueBrokerTest, BrokerWrite) {
broker.set(0);
EXPECT_EQ(read_count, 0);
EXPECT_EQ(write_count, 1);
}
TEST_F(ValueBrokerTest, BrokerRead) {
broker.get();
EXPECT_EQ(read_count, 1);
EXPECT_EQ(write_count, 0);
}
TEST_F(ValueBrokerTest, ProxyWrite) {
proxy = 0;
EXPECT_EQ(read_count, 0);
EXPECT_EQ(write_count, 1);
}
void dummy(int) { }
TEST_F(ValueBrokerTest, ProxyRead) {
dummy(proxy);
EXPECT_EQ(read_count, 1);
EXPECT_EQ(write_count, 0);
}
TEST_F(ValueBrokerTest, ProxyReadWrite) {
proxy = proxy;
ASSERT_EQ(read_count, 1);
ASSERT_EQ(write_count, 1);
}
|