Skip to content

Commit db3354c

Browse files
committed
Added I2C address range assertion to the Adau1361Lower class.
Deth test passed .
1 parent 46a32e5 commit db3354c

5 files changed

Lines changed: 56 additions & 5 deletions

File tree

src/codec/adau1361lower.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
#include <algorithm>
66

7+
rpp_driver::Adau1361Lower::Adau1361Lower(
8+
::rpp_driver::I2cMasterInterface& controller, unsigned int i2c_device_addr)
9+
: i2c_(controller), device_addr_(i2c_device_addr) {
10+
assert((0x3C > device_addr_) &&
11+
"ADAU1361 I2C Address must be lower than 0x3C.");
12+
assert((device_addr_ > 0x37) &&
13+
"ADAU1361 I2C Address must be higher than 0x37.");
14+
}
15+
716
/*
817
* Send single command
918
* table : command table :

src/codec/adau1361lower.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ class Adau1361Lower {
4646
* deta sheet for details.
4747
*/
4848
Adau1361Lower(::rpp_driver::I2cMasterInterface& controller,
49-
unsigned int i2c_device_addr)
50-
: i2c_(controller), device_addr_(i2c_device_addr) {};
49+
unsigned int i2c_device_addr);
5150
Adau1361Lower() = delete;
5251
virtual ~Adau1361Lower() {}
5352
/**
@@ -225,7 +224,7 @@ class Adau1361Lower {
225224
class MockAdau1361Lower : public Adau1361Lower {
226225
public:
227226
explicit MockAdau1361Lower(::rpp_driver::I2cMasterInterface& controller)
228-
: Adau1361Lower(controller, 31) {};
227+
: Adau1361Lower(controller, 0x3A) {};
229228
MOCK_METHOD2(SendCommand, void(const uint8_t command[], int size));
230229
MOCK_METHOD2(SendCommandTable, void(const uint8_t table[][3], int rows));
231230
MOCK_METHOD0(IsI2CDeviceExisting, bool());

test/test_adau1361lower.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ class CutAdau1361Lower : public ::rpp_driver::Adau1361Lower {
1212
: ::rpp_driver::Adau1361Lower(controller, i2c_device_addr) {};
1313
virtual void ConfigureSignalPath() {};
1414
};
15+
1516
class Adau1361LowerTest : public ::testing::Test {
1617
protected:
1718
virtual void SetUp() {
18-
device_address_ = 31; // 7bit I2C address
19+
device_address_ = 0x38; // 7bit I2C address
1920
codec_lower_ = new ::CutAdau1361Lower(i2c_, device_address_);
2021
}
2122

@@ -28,6 +29,40 @@ class Adau1361LowerTest : public ::testing::Test {
2829

2930
typedef Adau1361LowerTest Adau1361LowerDeathTest;
3031

32+
// -----------------------------------------------------------------
33+
//
34+
// Constructor Death Test
35+
//
36+
// -----------------------------------------------------------------
37+
38+
TEST(Adau1361LowerConstructorDeathTest, lower_address) {
39+
unsigned int device_address; // 7bit I2C address
40+
::rpp_driver::MockI2cMasterInterface i2c;
41+
::rpp_driver::Adau1361Lower* codec_lower;
42+
43+
device_address = 0x37; // 7bit I2C address
44+
// check the assertion for bad I2C address for Analog Device ADAU1361.
45+
// See data sheet for details.
46+
#ifndef NDEBUG
47+
ASSERT_DEATH(codec_lower = new ::CutAdau1361Lower(i2c, device_address);
48+
, "ADAU1361 I2C Address must be higher than 0x37.");
49+
#endif
50+
}
51+
52+
TEST(Adau1361LowerConstructorDeathTest, higher_address) {
53+
unsigned int device_address; // 7bit I2C address
54+
::rpp_driver::MockI2cMasterInterface i2c;
55+
::rpp_driver::Adau1361Lower* codec_lower;
56+
57+
device_address = 0x3C; // 7bit I2C address
58+
// check the assertion for bad I2C address for Analog Device ADAU1361.
59+
// See data sheet for details.
60+
#ifndef NDEBUG
61+
ASSERT_DEATH(codec_lower = new ::CutAdau1361Lower(i2c, device_address);
62+
, "ADAU1361 I2C Address must be lower than 0x3C.");
63+
#endif
64+
}
65+
3166
// -----------------------------------------------------------------
3267
//
3368
// SendCommand()

test/test_umbadau1361lower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class UmbAdau1361LowerTest : public ::testing::Test {
88
protected:
99
virtual void SetUp() {
10-
device_address_ = 17; // 7bit I2C address
10+
device_address_ = 0x39; // 7bit I2C address
1111
codec_lower_ = new ::rpp_driver::UmbAdau1361Lower(i2c_, device_address_);
1212
}
1313

test/todo/test_adau1361lower.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#test_i2cmaster TDD
22

3+
## Adau1361Lower::Constructor
4+
- [x] Add assertion to the I2C address.
5+
- [x] Create death test to fail.
6+
- [x] Make it success.
7+
- [x] Remove the duplication.
8+
9+
## Old test
10+
311
- [x] Create Adau1361LowerTest.ConfigureSingalPath()to fail.
412
- [x] Make it success.
513
- [x] Remove the duplication.

0 commit comments

Comments
 (0)