blob: f0d2b1a31ced0e6514390207bff39ad5ffd441bd (
plain)
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
|
#include <gtest/gtest.h>
#include <crepe/util/Private.h>
using namespace std;
using namespace crepe;
using namespace testing;
class PrivateTest : public Test {
public:
static unsigned constructors;
static unsigned destructors;
void SetUp() override {
PrivateTest::constructors = 0;
PrivateTest::destructors = 0;
}
class TestClass {
public:
TestClass() { PrivateTest::constructors++; }
~TestClass() { PrivateTest::destructors++; }
};
class Unrelated {};
};
unsigned PrivateTest::constructors;
unsigned PrivateTest::destructors;
TEST_F(PrivateTest, Empty) {
{
Private foo;
}
EXPECT_EQ(PrivateTest::constructors, 0);
EXPECT_EQ(PrivateTest::destructors, 0);
}
TEST_F(PrivateTest, WithObject) {
{
Private foo;
foo.set<TestClass>();
EXPECT_EQ(PrivateTest::constructors, 1);
EXPECT_EQ(PrivateTest::destructors, 0);
}
EXPECT_EQ(PrivateTest::constructors, 1);
EXPECT_EQ(PrivateTest::destructors, 1);
}
TEST_F(PrivateTest, EmptyException) {
Private foo;
EXPECT_THROW(foo.get<TestClass>(), std::out_of_range);
foo.set<TestClass>();
EXPECT_NO_THROW(foo.get<TestClass>());
}
TEST_F(PrivateTest, IncorrectTypeException) {
Private foo;
foo.set<TestClass>();
EXPECT_THROW(foo.get<Unrelated>(), std::logic_error);
EXPECT_NO_THROW(foo.get<TestClass>());
}
|