@@ -41,6 +41,43 @@ namespace rpp_driver {
4141 * The ReadBlocking() and WriteBlocking() functions has nostop parameter. To use
4242 * the restart condition, set this parameter to true.
4343 *
44+ * ### Usage of mock
45+ * In the case of the testing of the user program which uses this class,
46+ * a programmer can use the pre-defined mock class ::rpp_driver::MockI2cMaster.
47+ * inside i2cmaster.hpp.
48+ *
49+ * ```cpp
50+ #include <gmock/gmock.h>
51+ #include <gtest/gtest.h>
52+
53+ #include "i2c/i2cmaster.hpp"
54+
55+ using ::testing::_;
56+ class UserCodeTest : public ::testing::Test {
57+ protected:
58+ ::rpp_driver::MockSdkWrapper mock_sdk_;
59+ ::rpp_driver::MockI2cMaster* mock_i2c_;
60+
61+ virtual void SetUp() {
62+ // Constructor will call these functiions.
63+ EXPECT_CALL(mock_sdk_, i2c_init(_, _));
64+ EXPECT_CALL(mock_sdk_, gpio_set_function(_, GPIO_FUNC_I2C)).Times(2);
65+ EXPECT_CALL(mock_sdk_, gpio_pull_up(_)).Times(2);
66+
67+ mock_i2c_ = new ::rpp_driver::MockI2cMaster(mock_sdk_);
68+ }
69+
70+ virtual void TearDown() {
71+ // We can ignore these call inside destructor
72+ EXPECT_CALL(mock_sdk_, i2c_deinit(_));
73+ delete mock_i2c_;
74+ }
75+ };
76+
77+ TEST_F(UserCodeTest, foo) {
78+ // Write Test code here.
79+ }
80+ * ```
4481 */
4582class I2cMaster {
4683 public:
0 commit comments