|
| 1 | +#include <Mock/actuators.hpp> |
| 2 | +#include <Mock/error_handler.hpp> |
| 3 | +#include <Mock/flightcomputer.hpp> |
| 4 | +#include <Mock/imu.hpp> |
| 5 | +#include <Mock/mode_handler.hpp> |
| 6 | +#include <Mock/remote.hpp> |
| 7 | +#include <Mock/system.hpp> |
| 8 | +#include <gtest/gtest.h> |
| 9 | + |
| 10 | +extern "C" { |
| 11 | +#include <Application/application.h> |
| 12 | +} |
| 13 | + |
| 14 | +TEST(TEST_NAME, init) { |
| 15 | + auto actuatorsHandle = mock::actuators.getHandle(); |
| 16 | + auto errorHandlerHandle = mock::error_handler.getHandle(); |
| 17 | + auto flighcomputerHandle = mock::flightcomputer.getHandle(); |
| 18 | + auto imuHandle = mock::imu.getHandle(); |
| 19 | + auto modeHandlerHandle = mock::mode_handler.getHandle(); |
| 20 | + auto remoteHandlerHandle = mock::remote.getHandle(); |
| 21 | + auto systemHandle = mock::system.getHandle(); |
| 22 | + |
| 23 | + systemHandle.overrideFunc<system_reset_watchdog>( |
| 24 | + []() { throw std::runtime_error{"EXCEPTION TO BREAK LOOP FOR TESTS"}; }); |
| 25 | + |
| 26 | + EXPECT_THROW(application_init(), std::runtime_error); |
| 27 | + |
| 28 | + EXPECT_TRUE(systemHandle.functionGotCalled<system_pre_init>(std::ignore)); |
| 29 | + EXPECT_TRUE(errorHandlerHandle.functionGotCalled<error_handler_init>()); |
| 30 | + EXPECT_TRUE(imuHandle.functionGotCalled<imu_init>()); |
| 31 | + EXPECT_TRUE(remoteHandlerHandle.functionGotCalled<remote_init>()); |
| 32 | + EXPECT_TRUE(flighcomputerHandle.functionGotCalled<flightcomputer_init>()); |
| 33 | + EXPECT_TRUE(actuatorsHandle.functionGotCalled<actuators_init>()); |
| 34 | + EXPECT_TRUE(modeHandlerHandle.functionGotCalled<mode_handler_init>()); |
| 35 | + EXPECT_TRUE(systemHandle.functionGotCalled<system_post_init>()); |
| 36 | +} |
| 37 | + |
| 38 | +TEST(TEST_NAME, timer) { |
| 39 | + auto actuatorsHandle = mock::actuators.getHandle(); |
| 40 | + auto errorHandlerHandle = mock::error_handler.getHandle(); |
| 41 | + auto flighcomputerHandle = mock::flightcomputer.getHandle(); |
| 42 | + auto imuHandle = mock::imu.getHandle(); |
| 43 | + auto modeHandlerHandle = mock::mode_handler.getHandle(); |
| 44 | + auto remoteHandlerHandle = mock::remote.getHandle(); |
| 45 | + auto systemHandle = mock::system.getHandle(); |
| 46 | + |
| 47 | + system_timer_16_384ms_callback timer_callback = nullptr; |
| 48 | + systemHandle.overrideFunc<system_pre_init>( |
| 49 | + [&timer_callback](system_timer_16_384ms_callback callback) { timer_callback = callback; }); |
| 50 | + systemHandle.overrideFunc<system_reset_watchdog>( |
| 51 | + []() { throw std::runtime_error{"EXCEPTION TO BREAK LOOP FOR TESTS"}; }); |
| 52 | + |
| 53 | + EXPECT_THROW(application_init(), std::runtime_error); |
| 54 | + |
| 55 | + EXPECT_TRUE(systemHandle.functionGotCalled<system_pre_init>(std::ignore)); |
| 56 | + EXPECT_TRUE(errorHandlerHandle.functionGotCalled<error_handler_init>()); |
| 57 | + EXPECT_TRUE(imuHandle.functionGotCalled<imu_init>()); |
| 58 | + EXPECT_TRUE(remoteHandlerHandle.functionGotCalled<remote_init>()); |
| 59 | + EXPECT_TRUE(flighcomputerHandle.functionGotCalled<flightcomputer_init>()); |
| 60 | + EXPECT_TRUE(actuatorsHandle.functionGotCalled<actuators_init>()); |
| 61 | + EXPECT_TRUE(modeHandlerHandle.functionGotCalled<mode_handler_init>()); |
| 62 | + EXPECT_TRUE(systemHandle.functionGotCalled<system_post_init>()); |
| 63 | + |
| 64 | + // Actual test |
| 65 | +} |
0 commit comments