/*
 * Author: username
 * Date: todays_date
 * filename: test_blink.c
 * description: module_purpose
 */

#include "CppUTest/CommandLineTestRunner.h"

extern "C"
{
#include "blink.h"
}

volatile uint32_t  fake_bshr_reg  = 0;
volatile uint32_t *GPIO_PORT_BSHR = &fake_bshr_reg;

unsigned int       called;
void               fake_delay(unsigned int ms)
{
    called += 1;
    return;
}

TEST_GROUP(test_blink){
    void setup(){
        fake_bshr_reg = 0;
called = 0;
}
void teardown()
{
}
}
;

TEST(test_blink, UninitializedFuncPointer)
{
    blink_led(5);
    CHECK_EQUAL(0, fake_bshr_reg);
}

TEST(test_blink, BlinkChangesReg)
{
    // Set the function pointer.
    delay_ms = fake_delay;

    blink_led(1);

    CHECK_EQUAL_TEXT(2, called, "Delay function not called expeced number of times");

    CHECK(fake_bshr_reg & (1 << 0));
    CHECK(fake_bshr_reg & (1 << (0 + 16)));

    // Unset function pointer
    delay_ms = 0;
}
