forked from PhysicsX/ExampleCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cpp
More file actions
49 lines (40 loc) · 798 Bytes
/
Example.cpp
File metadata and controls
49 lines (40 loc) · 798 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
#include <iostream>
#include <gtest/gtest.h>
using namespace std;
class Example
{
public:
int foo()
{
return 1;
}
};
class ExampleFixture : public testing::Test
{
public:
ExampleFixture() : testExPtr(nullptr) {}
// Set testExPtr to nullptr after deallocation to avoid potential dangling pointer access.
// Moved initialization to SetUp
void SetUp() override {
testExPtr = new Example();
}
// Moved deallocation to TearDown
void TearDown() override {
delete testExPtr;
testExPtr = nullptr;
}
Example* testExPtr;
};
TEST_F(ExampleFixture, test1)
{
ASSERT_EQ(1, testExPtr->foo());
}
TEST_F(ExampleFixture, test2)
{
ASSERT_NE(0, testExPtr->foo());
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}