/**
 * @file test_swtimer.cpp
 * @brief Unit tests for Software Timer component
 * @author Mahmoud Elmohtady
 * @company Nabd solutions - ASF
 * @copyright Copyright (c) 2025
 */

#include "unity.h"
#include "swtimer.hpp"

extern "C" {

void setUp(void)
{
    // Set up test fixtures before each test
}

void tearDown(void)
{
    // Clean up test fixtures after each test
}

/**
 * @brief Test timer creation with valid parameters
 */
void test_swtimer_create_valid(void)
{
    SoftwareTimer timer;
    bool result = timer.create(1000, TimerType::ONE_SHOT, [](){});
    TEST_ASSERT_TRUE(result);
    TEST_ASSERT_FALSE(timer.isActive());
    TEST_ASSERT_EQUAL(1000, timer.getInterval());
}

/**
 * @brief Test timer creation with zero interval
 */
void test_swtimer_create_zero_interval(void)
{
    SoftwareTimer timer;
    bool result = timer.create(0, TimerType::ONE_SHOT, [](){});
    TEST_ASSERT_FALSE(result);
}

/**
 * @brief Test timer start
 */
void test_swtimer_start(void)
{
    SoftwareTimer timer;
    timer.create(1000, TimerType::ONE_SHOT, [](){});
    
    bool result = timer.start();
    TEST_ASSERT_TRUE(result);
    TEST_ASSERT_TRUE(timer.isActive());
}

/**
 * @brief Test timer stop
 */
void test_swtimer_stop(void)
{
    SoftwareTimer timer;
    timer.create(1000, TimerType::ONE_SHOT, [](){});
    timer.start();
    
    bool result = timer.stop();
    TEST_ASSERT_TRUE(result);
    TEST_ASSERT_FALSE(timer.isActive());
}

/**
 * @brief Test timer reset
 */
void test_swtimer_reset(void)
{
    SoftwareTimer timer;
    timer.create(1000, TimerType::ONE_SHOT, [](){});
    timer.start();
    
    bool result = timer.reset();
    TEST_ASSERT_TRUE(result);
    TEST_ASSERT_TRUE(timer.isActive());
}

/**
 * @brief Test timer one-shot type
 */
void test_swtimer_one_shot(void)
{
    SoftwareTimer timer;
    timer.create(1000, TimerType::ONE_SHOT, [](){});
    TEST_ASSERT_TRUE(timer.start());
}

/**
 * @brief Test timer periodic type
 */
void test_swtimer_periodic(void)
{
    SoftwareTimer timer;
    timer.create(500, TimerType::PERIODIC, [](){});
    TEST_ASSERT_TRUE(timer.start());
}

} // extern "C"

