160 lines
2.9 KiB
C++
160 lines
2.9 KiB
C++
/*
|
|
* Author: username
|
|
* Date: todays_date
|
|
* filename: test_I2C.c
|
|
* description: module_purpose
|
|
*/
|
|
|
|
#include "CppUTest/CommandLineTestRunner.h"
|
|
|
|
extern "C"
|
|
{
|
|
#include "I2C.h"
|
|
#include "I2C_internal.h"
|
|
}
|
|
|
|
TEST_GROUP(tg_I2C)
|
|
{
|
|
void setup()
|
|
{
|
|
|
|
}
|
|
void teardown()
|
|
{
|
|
|
|
}
|
|
};
|
|
|
|
/*
|
|
typedef struct
|
|
{
|
|
uint32_t clockspeed;
|
|
uint16_t mode;
|
|
uint16_t dutycycle;
|
|
uint16_t ownaddress1;
|
|
uint16_t ack;
|
|
uint16_t ack_address;
|
|
} i2c_config;
|
|
*/
|
|
|
|
TEST(tg_I2C, GetBusReturnsNonNullOnValidIndecies)
|
|
{
|
|
i2c_bus_typedef_p i2cbus_ptr = I2C_GetBus(0);
|
|
CHECK_TRUE_TEXT(i2cbus_ptr != nullptr, "The pointer should have been valid but was nullptr.");
|
|
}
|
|
|
|
TEST(tg_I2C, GetBusReturnsNullOnInvalid)
|
|
{
|
|
|
|
i2c_bus_typedef_p i2cbus_ptr = I2C_GetBus(I2C_BUS_QTY + 1);
|
|
CHECK_EQUAL_TEXT(nullptr, i2cbus_ptr, "The pointer should be null for invalid indecies.");
|
|
|
|
}
|
|
|
|
TEST(tg_I2C, BusFailsOnInvalidconfig)
|
|
{
|
|
|
|
}
|
|
|
|
TEST(tg_I2C, CreateI2CBus_10Bit)
|
|
{
|
|
i2c_config i2c1_config = {
|
|
.clockspeed = I2C_STD_SPEED,
|
|
.mode = I2C_MODE_MASTER,
|
|
.dutycycle = 0,
|
|
.ownaddress = 0,
|
|
.ack = true,
|
|
.ack_address = 0,
|
|
};
|
|
|
|
i2c_bus_typedef_p i2c1_ptr = I2C_GetBus(0);
|
|
|
|
bool ret = i2c1_ptr->Init(i2c1_ptr, &i2c1_config);
|
|
CHECK_TRUE(ret);
|
|
}
|
|
|
|
|
|
TEST_GROUP(tg_I2C_internal)
|
|
{
|
|
i2c_config config;
|
|
void setup()
|
|
{
|
|
config.clockspeed = 0;
|
|
config.mode = 0;
|
|
|
|
}
|
|
void teardown()
|
|
{
|
|
|
|
}
|
|
};
|
|
|
|
TEST(tg_I2C_internal, i2c_configchecksclockspeed)
|
|
{
|
|
bool ret = false;
|
|
|
|
for(config.clockspeed = 0; config.clockspeed < I2C_INVALID_SPEED; config.clockspeed++){
|
|
ret = is_i2c_config_valid(&config);
|
|
CHECK_TRUE(ret);
|
|
}
|
|
|
|
config.clockspeed = I2C_INVALID_SPEED;
|
|
ret = is_i2c_config_valid(&config);
|
|
CHECK_FALSE_TEXT(ret, "config check accepted invalid i2c clockspeed!");
|
|
}
|
|
|
|
TEST(tg_I2C_internal, i2c_configchecksmode)
|
|
{
|
|
bool ret = false;
|
|
|
|
for(config.mode = 0; config.mode < I2C_MODE_INVALID; config.mode++){
|
|
ret = is_i2c_config_valid(&config);
|
|
CHECK_TRUE(ret);
|
|
}
|
|
|
|
config.mode = I2C_MODE_INVALID;
|
|
ret = is_i2c_config_valid(&config);
|
|
CHECK_FALSE_TEXT(ret, "config check accepted invalid i2c mode!");
|
|
}
|
|
|
|
TEST(tg_I2C_internal, i2c_configchecksdutycycle)
|
|
{
|
|
bool ret = false;
|
|
|
|
for(config.dutycycle= 0; config.dutycycle < I2C_DUTYCYCLE_INVALID; config.dutycycle++){
|
|
ret = is_i2c_config_valid(&config);
|
|
CHECK_TRUE(ret);
|
|
}
|
|
|
|
config.dutycycle= I2C_DUTYCYCLE_INVALID;
|
|
ret = is_i2c_config_valid(&config);
|
|
CHECK_FALSE_TEXT(ret, "config check accepted invalid i2c dutycycle!");
|
|
}
|
|
|
|
TEST(tg_I2C_internal, is10bitaddresschecksCorrectly)
|
|
{
|
|
bool ret = false;
|
|
|
|
CHECK_FALSE_TEXT(ret, "check");
|
|
}
|
|
|
|
TEST(tg_I2C_internal, is7bitaddresschecksCorrectly)
|
|
{
|
|
bool ret = false;
|
|
|
|
CHECK_FALSE_TEXT(ret, "check");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|