* @brief Test fixture class for TaskScheduler unit tests * * Provides common setup and teardown functionality for all scheduler tests. * Ensures clean test state between test runs and provides utility methods * for common test operations like running scheduler with timeout conditions. */
| 81 | * for common test operations like running scheduler with timeout conditions. |
| 82 | */ |
| 83 | class SchedulerTest : public ::testing::Test { |
| 84 | protected: |
| 85 | /** |
| 86 | * @brief Set up test environment before each test |
| 87 | * |
| 88 | * Clears any previous test output and initializes timing system. |
| 89 | * Called automatically by Google Test framework before each test method. |
| 90 | * Ensures each test starts with a clean, predictable state. |
| 91 | */ |
| 92 | void SetUp() override { |
| 93 | clearTestOutput(); |
| 94 | // Reset time by creating new static start point |
| 95 | millis(); // Initialize timing |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @brief Clean up test environment after each test |
| 100 | * |
| 101 | * Clears test output to prevent interference between tests. |
| 102 | * Called automatically by Google Test framework after each test method. |
| 103 | * Ensures no test artifacts affect subsequent tests. |
| 104 | */ |
| 105 | void TearDown() override { |
| 106 | clearTestOutput(); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @brief Helper method to run scheduler until condition is met or timeout |
| 111 | * |
| 112 | * Executes the scheduler repeatedly until either the specified condition |
| 113 | * returns true or the timeout period expires. Essential for testing |
| 114 | * time-dependent scheduler behavior without creating infinite loops. |
| 115 | * |
| 116 | * @param ts Reference to the Scheduler object to execute |
| 117 | * @param condition Lambda function that returns true when test condition is met |
| 118 | * @param timeout_ms Maximum time to wait before giving up (default: 1000ms) |
| 119 | * @return true if condition was met within timeout, false otherwise |
| 120 | */ |
| 121 | bool runSchedulerUntil(Scheduler& ts, std::function<bool()> condition, unsigned long timeout_ms = 1000) { |
| 122 | return waitForCondition([&]() { |
| 123 | ts.execute(); |
| 124 | return condition(); |
| 125 | }, timeout_ms); |
| 126 | } |
| 127 | }; |
| 128 | |
| 129 | /** |
| 130 | * @brief Test basic scheduler object creation |
nothing calls this directly
no outgoing calls
no test coverage detected