-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathexampleTest.cpp
More file actions
53 lines (45 loc) · 896 Bytes
/
exampleTest.cpp
File metadata and controls
53 lines (45 loc) · 896 Bytes
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
#include <iostream>
#include <gtest/gtest.h>
#include "example.cpp"
using namespace std;
// g++ -Wall -g -pthread exampleTest.cpp example.cpp -lgtest_main -lgtest -lpthread -o test
// test fixture
class ExampleTest : public testing::Test
{
protected:
Example *ex;
void SetUp()
{
ex = new Example;
cout<<"Created"<<std::endl;
}
void TearDown()
{
delete ex;
cout<<"Deleted"<<std::endl;
}
};
TEST_F(ExampleTest, test3)
{
ex->increase(100);
EXPECT_EQ(100,ex->ctr);
}
TEST(Example, test1)
{
Example inst;
inst.increase(100);
EXPECT_EQ(100, inst.ctr);
}
TEST(Example, test2)
{
Example inst;
inst.increase(100);
ASSERT_EQ(500, inst.ctr);
inst.decrease(50);
EXPECT_EQ(100, inst.ctr);
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}