summaryrefslogtreecommitdiff
path: root/SDL_Core/test/gtest-example/example.cpp
blob: 794b13cb5ab2a5d21efe484475eb1d9c1ace52c4 (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
#include "gtest/gtest.h"
#include "gmock/gmock.h"

namespace test
{
    namespace gtest_example
    {
        TEST(gtest_example, initial_test) 
        {
            EXPECT_TRUE(1 == 1);
            ASSERT_FALSE(0 == 1);
            //ASSERT_FALSE(0 == 0); // Uncomment this and test will fail
        }
    }

    namespace gmock_example
    {
        // Class that we test
        class ClassToTest
        {
        public:
            virtual ~ClassToTest(){}
            virtual void doAction() = 0; // We will test that doAction will be called
            virtual void run()
            {
                doAction();
                //doAction(); // Uncomment this and test will fail
            }
        };

        // Our mock class
        class MockClassToTest: public ClassToTest
        {
        public:
            MOCK_METHOD0(doAction, void());
        };

        TEST(gmock_example, test)
        {
            MockClassToTest c;
            EXPECT_CALL(c, doAction())
                .Times(1)
            ;

            c.run();
        }
    }
}

int main(int argc, char **argv) {
  ::testing::InitGoogleMock(&argc, argv);
  return RUN_ALL_TESTS();
}