Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos HardwareInterface EthernetInterface WebSocketClient
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));
+}