-
Notifications
You must be signed in to change notification settings - Fork 0
/
replicas_unittest.cpp
executable file
·77 lines (59 loc) · 1.83 KB
/
replicas_unittest.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
/* We use stringmachine to test replicas */
#include "replica_handler.h"
#include "stringmachine.h"
#include "gtest/gtest.h"
using namespace mp2;
using namespace std;
using boost::shared_ptr;
class ReplicaTest : public ::testing::Test {
protected:
StringMachineFactory factory;
Replica empty_1;
Replica oneSM_2;
static const string sm2_name;
static const string sm2_initstate;
static const string sm2_op;
ReplicaTest() : empty_1(1, factory, shared_ptr<Replicas>()), oneSM_2(2, factory, shared_ptr<Replicas>()) {}
virtual void SetUp() {
oneSM_2.create(sm2_name, sm2_initstate);
}
};
const string ReplicaTest::sm2_name = "machine name";
const string ReplicaTest::sm2_initstate = "initial state";
const string ReplicaTest::sm2_op = "operation";
TEST_F(ReplicaTest, Constructor) {
// check to see if the constructors set the IDs OK
EXPECT_EQ(empty_1.id, 1);
EXPECT_EQ(oneSM_2.id, 2);
}
TEST_F(ReplicaTest, NotFound) {
string result;
EXPECT_THROW(empty_1.apply(result, sm2_name, sm2_op), ReplicaError);
EXPECT_THROW(empty_1.getState(result, sm2_name), ReplicaError);
EXPECT_THROW(empty_1.remove(sm2_name), ReplicaError);
}
TEST_F(ReplicaTest, ReCreateError) {
EXPECT_THROW(oneSM_2.create(sm2_name, sm2_initstate), ReplicaError);
}
TEST_F(ReplicaTest, Create) {
string result;
oneSM_2.getState(result, sm2_name);
EXPECT_EQ(result, sm2_initstate);
}
TEST_F(ReplicaTest, Apply) {
string result;
oneSM_2.apply(result, sm2_name, sm2_op);
EXPECT_EQ(result, sm2_op);
string result2;
oneSM_2.getState(result2, sm2_name);
EXPECT_EQ(result2, sm2_op);
}
TEST_F(ReplicaTest, Remove) {
string result;
oneSM_2.remove(sm2_name);
EXPECT_THROW(oneSM_2.getState(result, sm2_name), ReplicaError);
}
typedef ReplicaTest ReplicaDeathTest;
TEST_F(ReplicaDeathTest, Exit) {
EXPECT_EXIT(empty_1.exit(), ::testing::ExitedWithCode(0), "Replica 1 exiting");
}