summaryrefslogtreecommitdiffstats
path: root/test cases/frameworks/3 gmock/gmocktest.cc
blob: a8bd2d39f3dd06cb08cb7b513e0cdf2972fcf926 (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
#include<gtest/gtest.h>
#include<gmock/gmock.h>

using ::testing::Return;

class Foo {
public:
    Foo() { x = 42; }
    virtual ~Foo() {};

    virtual int getValue() const { return x; }

private:
    int x;
};

class MockFoo : public Foo {
public:
    MOCK_CONST_METHOD0(getValue, int());
};

TEST(counttest, once) {
    MockFoo f;
    EXPECT_CALL(f, getValue()).Times(1).WillOnce(Return(42));

    EXPECT_EQ(f.getValue(), 42) << "Got wrong value";
}