Trying to use a library
Dependencies: mbed-rtos mbed BlinkLib
Fork of NerfUS by
Diff: TESTS/GoogleMockTest.cpp
- Revision:
- 6:362affb5ac7e
- Parent:
- 3:aaf84424abb1
diff -r 917281f61abe -r 362affb5ac7e TESTS/GoogleMockTest.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TESTS/GoogleMockTest.cpp Sat Feb 04 23:10:53 2017 -0500 @@ -0,0 +1,38 @@ +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +class Adder +{ + public: + virtual ~Adder() {} + virtual int add(int a, int b) + { + return a + b; + } +}; + +class MockAdder : public Adder +{ + public: + MOCK_METHOD2(add, int(int a, int b)); +}; + +TEST(GoogleMockTest, ExpectCalled) +{ + MockAdder adder; + + EXPECT_CALL(adder, add(1, 2)); + + adder.add(1, 2); +} + +TEST(GoogleMockTest, DefineReturnedValue) +{ + using ::testing::Return; + MockAdder adder; + + EXPECT_CALL(adder, add(1, 2)) + .WillOnce(Return(42)); + + ASSERT_EQ(42, adder.add(1, 2)); +}