2024-08-22 02:59:14 +00:00
|
|
|
/*
|
|
|
|
* Author: username
|
|
|
|
* Date: todays_date
|
|
|
|
* filename: test_LedController.c
|
|
|
|
* description: module_purpose
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "CppUTest/CommandLineTestRunner.h"
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#include "LedController.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_GROUP(test_LedController)
|
|
|
|
{
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
void teardown()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-08-24 16:42:54 +00:00
|
|
|
TEST(test_LedController, selftest)
|
|
|
|
{
|
|
|
|
CHECK_TRUE(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(test_LedController, LedSetHighWorks)
|
|
|
|
{
|
|
|
|
uint8_t fake_port = 0x00;
|
|
|
|
|
|
|
|
Led fake_led;
|
|
|
|
fake_led.port = &fake_port;
|
|
|
|
fake_led.pin_num = 0;
|
|
|
|
fake_led.state = false;
|
|
|
|
|
|
|
|
LedController_SetHigh(&fake_led);
|
|
|
|
|
|
|
|
//Check that it sets the correct bit.
|
|
|
|
CHECK_TRUE(fake_port & 0x01);
|
|
|
|
|
|
|
|
//It should set the state to true.
|
|
|
|
CHECK_TRUE(fake_led.state);
|
|
|
|
|
|
|
|
//Only the first bit should have been set
|
|
|
|
CHECK_TRUE(fake_port == 0x01);
|
|
|
|
}
|
2024-08-24 00:06:03 +00:00
|
|
|
|
2024-08-24 16:42:54 +00:00
|
|
|
TEST(test_LedController, LedSetHighMaintainsPortState)
|
2024-08-24 00:06:03 +00:00
|
|
|
{
|
2024-08-24 16:05:07 +00:00
|
|
|
uint8_t fake_port = 0x00;
|
|
|
|
|
|
|
|
Led fake_led;
|
|
|
|
fake_led.port = &fake_port;
|
|
|
|
fake_led.pin_num = 0;
|
|
|
|
fake_led.state = false;
|
2024-08-24 00:06:03 +00:00
|
|
|
|
2024-08-24 16:42:54 +00:00
|
|
|
Led led_two;
|
|
|
|
led_two.pin_num = 1;
|
|
|
|
led_two.port = &fake_port;
|
|
|
|
led_two.state = false;
|
|
|
|
|
|
|
|
LedController_SetHigh(&fake_led);
|
|
|
|
LedController_SetHigh(&led_two);
|
|
|
|
|
|
|
|
CHECK_TRUE(fake_port & 0x01);
|
|
|
|
CHECK_TRUE(fake_port & 0x02);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(test_LedController, LedSetLow)
|
|
|
|
{
|
|
|
|
uint8_t fake_port = 0x01;
|
|
|
|
|
|
|
|
Led fake_led;
|
|
|
|
fake_led.port = &fake_port;
|
|
|
|
fake_led.pin_num = 0;
|
|
|
|
fake_led.state = true;
|
|
|
|
|
|
|
|
LedController_SetLow(&fake_led);
|
|
|
|
|
|
|
|
CHECK_EQUAL(0x00, fake_port);
|
|
|
|
CHECK_EQUAL(false, fake_led.state);
|
2024-08-22 02:59:14 +00:00
|
|
|
}
|
2024-08-24 16:42:54 +00:00
|
|
|
|
2024-08-25 13:19:31 +00:00
|
|
|
/*
|
|
|
|
* what's the best way to handle an array of 8 leds. Should they
|
|
|
|
* reside in a structure? Or should it just be an array that the user defines?
|
|
|
|
*/
|
|
|
|
TEST(test_LedController, NewLedByte)
|
|
|
|
{
|
|
|
|
uint8_t fake_port = 0x00;
|
|
|
|
LedByte led_byte = LedController_New(&fake_port);
|
|
|
|
|
|
|
|
for(int i = 0; i < 8; i++){
|
|
|
|
CHECK_TRUE(led_byte.leds[i].state == false);
|
|
|
|
CHECK_EQUAL(&fake_port, led_byte.leds[i].port);
|
|
|
|
CHECK_EQUAL(false, led_byte.leds[i].state);
|
|
|
|
}
|
|
|
|
}
|
2024-08-24 16:42:54 +00:00
|
|
|
|
2024-08-25 13:38:10 +00:00
|
|
|
|
|
|
|
TEST(test_LedController, LedByteDisplay)
|
|
|
|
{
|
|
|
|
uint8_t fake_port = 0x00;
|
|
|
|
uint8_t byte = 0xFF;
|
|
|
|
LedByte led_byte = LedController_New(&fake_port);
|
|
|
|
|
|
|
|
LedController_ShowByte(&led_byte, byte);
|
|
|
|
|
|
|
|
for(int i = 0; i < 8; i++){
|
|
|
|
CHECK_TRUE(led_byte.leds[i].state);
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_EQUAL(0xFF, fake_port);
|
|
|
|
|
|
|
|
}
|
2024-08-25 13:44:32 +00:00
|
|
|
|
|
|
|
TEST(test_LedController, LedByteDisplayPattern)
|
|
|
|
{
|
|
|
|
uint8_t fake_port = 0x00;
|
|
|
|
uint8_t byte = 0xAA;
|
|
|
|
LedByte led_byte = LedController_New(&fake_port);
|
|
|
|
|
|
|
|
|
|
|
|
LedController_ShowByte(&led_byte, byte);
|
|
|
|
|
|
|
|
for(int i = 0; i < 8; i++){
|
|
|
|
if(byte & (1<<i)) {
|
|
|
|
CHECK_TRUE(led_byte.leds[i].state);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CHECK_TRUE(!led_byte.leds[i].state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_EQUAL(0xAA, fake_port);
|
|
|
|
}
|
2024-08-25 13:54:18 +00:00
|
|
|
|
|
|
|
TEST(test_LedController, ClearingLedByteWorks)
|
|
|
|
{
|
|
|
|
uint8_t fake_port = 0xFF;
|
|
|
|
LedByte led_byte = LedController_New(&fake_port);
|
|
|
|
|
|
|
|
for(int i = 0; i < 8; i++){
|
|
|
|
led_byte.leds[i].state = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
LedControler_ClearByte(&led_byte);
|
|
|
|
|
|
|
|
for(int i = 0; i < 8; i++){
|
|
|
|
CHECK_TRUE(!led_byte.leds[i].state);
|
|
|
|
/*loop body*/
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_EQUAL(0x00, fake_port);
|
|
|
|
}
|