Skip to content

Commit b87fe2b

Browse files
committed
Issue #21 : Add usege of the mock for each class description.
Test passed. Doxygen generated document is Ok.
1 parent 7c7574c commit b87fe2b

6 files changed

Lines changed: 179 additions & 0 deletions

File tree

src/codec/adau1361.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,44 @@ namespace rpp_driver {
4040
kMClock, // Master clock of UMB-ADAU1361-A[Hz].
4141
codec_lower); // Inject Codec lower part dependency.
4242
* ```
43+
* ### Usage of mock
44+
* In the case of the testing of the user program which uses this class,
45+
* a programmer can use the pre-defined mock class ::rpp_driver::MockAdau1361
46+
* inside adau1361.hpp.
47+
*
48+
* ```cpp
49+
#include <gmock/gmock.h>
50+
#include <gtest/gtest.h>
51+
52+
#include "codec/adau1361.hpp"
53+
#include "codec/umbadau1361lower.hpp"
54+
#include "i2c/i2cmaster.hpp"
55+
56+
57+
class UserCodeTest : public ::testing::Test {
58+
protected:
59+
virtual void SetUp() {
60+
mock_i2c_ = new ::rpp_driver::MockI2cMaster(mock_sdk_);
61+
mock_codec_lower_ = new ::rpp_driver::MockAdau1361Lower(*mock_i2c_);
62+
mock_codec_ = new ::rpp_driver::MockAdau1361(*mock_codec_lower_);
63+
}
64+
65+
virtual void TearDown() {
66+
delete mock_codec_;
67+
delete mock_codec_lower_;
68+
delete mock_i2c_;
69+
}
70+
71+
::rpp_driver::SdkWrapper mock_sdk_;
72+
::rpp_driver::MockI2cMaster *mock_i2c_;
73+
::rpp_driver::MockAdau1361Lower *mock_codec_lower_;
74+
::rpp_driver::MockAdau1361 *mock_codec_;
75+
};
76+
77+
TEST_F(UserCodeTest, foo) {
78+
// Write Test code here.
79+
}
80+
* ```
4381
*/
4482
class Adau1361 {
4583
public:

src/gpio/gpiobasic.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,41 @@ namespace rpp_driver {
2929
* this class, pass a GPIO pin# through the constructor.
3030
* So, this class initialize and deinitialize that pin in the constructor and
3131
* destructor, respectively.
32+
*
33+
* ### Usage of mock
34+
* In the case of the testing of the user program which uses this class,
35+
* a programmer can use the pre-defined mock class ::rpp_driver::MockGpioBasic.
36+
* inside gpiobasic.hpp.
37+
*
38+
* ```cpp
39+
#include <gmock/gmock.h>
40+
#include <gtest/gtest.h>
41+
42+
#include "gpio/gpiobasic.hpp"
43+
#include "sdk/sdkwrapper.hpp"
44+
45+
46+
using ::testing::_;
47+
class UserCodeTest : public ::testing::Test {
48+
protected:
49+
::rpp_driver::MockSdkWrapper mock_sdk_;
50+
::rpp_driver::MockGpioBasic* mock_gpio_;
51+
52+
virtual void SetUp() {
53+
EXPECT_CALL(mock_sdk_, gpio_init(_)).Times(1);
54+
mock_gpio_ = new ::rpp_driver::MockGpioBasic(mock_sdk_);
55+
}
56+
57+
virtual void TearDown() {
58+
EXPECT_CALL(mock_sdk_, gpio_deinit(_)).Times(1);
59+
delete (mock_gpio_);
60+
}
61+
};
62+
63+
TEST_F(UserCodeTest, foo) {
64+
// Write Test code here.
65+
}
66+
* ```
3267
*/
3368
class GpioBasic {
3469
public:

src/i2c/i2cmaster.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
4582
class I2cMaster {
4683
public:

src/i2s/i2sslaveduplex.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ namespace rpp_driver {
5959
* output to PutFifoBLock(). To provide the high quality processing,
6060
* The first GetFifoBlocking() call should be as soon as possible, after
6161
* calling start() function.
62+
*
63+
* ### Usage of mock
64+
* In the case of the testing of the user program which uses this class,
65+
* a programmer can use the pre-defined mock class
66+
* ::rpp_driver::MockI2sSlaveDuplex inside i2sslaveduplex.hpp.
67+
*
68+
* ```cpp
69+
#include <gmock/gmock.h>
70+
#include <gtest/gtest.h>
71+
72+
#include "i2s/i2sslaveduplex.hpp"
73+
#include "sdk/sdkwrapper.hpp"
74+
75+
class UserCodeTest : public ::testing::Test {
76+
protected:
77+
::rpp_driver::MockSdkWrapper mock_sdk_;
78+
::rpp_driver::MockI2sSlaveDuplex* mock_i2sslaveduplex_;
79+
80+
virtual void SetUp() {
81+
mock_i2sslaveduplex_ = new ::rpp_driver::MockI2sSlaveDuplex(mock_sdk_);
82+
}
83+
84+
virtual void TearDown() { delete (mock_i2sslaveduplex_); }
85+
};
86+
87+
TEST_F(UserCodeTest, foo) {
88+
// Write Test code here.
89+
}
90+
* ```
6291
*/
6392
class I2sSlaveDuplex {
6493
private:

src/sdk/scripts/blocks/sdkwrapper_preumble.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ namespace rpp_driver {
5050
* the unit test.
5151
*
5252
* The mock of this class is declared in the same file with this class.
53+
* ### Usage of mock
54+
* In the case of the testing of the user program which uses this class,
55+
* a programmer can use the pre-defined mock class
56+
* ::rpp_driver::MockSdkWrapper inside sdkwrapper.hpp.
57+
*
58+
* ```cpp
59+
#include <gmock/gmock.h>
60+
#include <gtest/gtest.h>
61+
62+
#include "sdk/sdkwrapper.hpp"
63+
64+
class UserCodeTest : public ::testing::Test {
65+
protected:
66+
::rpp_driver::MockSdkWrapper mock_sdk_;
67+
};
68+
69+
TEST_F(UserCodeTest, foo) {
70+
// Write Test code here.
71+
}
72+
* ```
5373
*/
5474
class SdkWrapper {
5575
public:

src/sdk/sdkwrapper.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ namespace rpp_driver {
5050
* the unit test.
5151
*
5252
* The mock of this class is declared in the same file with this class.
53+
* ### Usage of mock
54+
* In the case of the testing of the user program which uses this class,
55+
* a programmer can use the pre-defined mock class
56+
* ::rpp_driver::MockSdkWrapper inside sdkwrapper.hpp.
57+
*
58+
* ```cpp
59+
#include <gmock/gmock.h>
60+
#include <gtest/gtest.h>
61+
62+
#include "sdk/sdkwrapper.hpp"
63+
64+
class UserCodeTest : public ::testing::Test {
65+
protected:
66+
::rpp_driver::MockSdkWrapper mock_sdk_;
67+
};
68+
69+
TEST_F(UserCodeTest, foo) {
70+
// Write Test code here.
71+
}
72+
* ```
5373
*/
5474
class SdkWrapper {
5575
public:

0 commit comments

Comments
 (0)