From 5bce20206708de65728bc94cc29f073603d81423 Mon Sep 17 00:00:00 2001 From: kifir Date: Tue, 5 Nov 2024 18:57:25 +0200 Subject: [PATCH] only:refactoring: extract part of functionality into `TestPersistentConfiguration` class --- .../launch/test_ignition_angle_advance.cpp | 36 ++++++++++--------- unit_tests/tests/tests.mk | 1 + unit_tests/tests/util/test_base.cpp | 4 +++ unit_tests/tests/util/test_base.h | 2 ++ .../util/test_persistent_configuration.cpp | 21 +++++++++++ .../util/test_persistent_configuration.h | 16 +++++++++ 6 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 unit_tests/tests/util/test_persistent_configuration.cpp create mode 100644 unit_tests/tests/util/test_persistent_configuration.h diff --git a/unit_tests/tests/launch/test_ignition_angle_advance.cpp b/unit_tests/tests/launch/test_ignition_angle_advance.cpp index bb79edf779..cccf7d09db 100644 --- a/unit_tests/tests/launch/test_ignition_angle_advance.cpp +++ b/unit_tests/tests/launch/test_ignition_angle_advance.cpp @@ -127,24 +127,26 @@ namespace { }; void IgnitionAngleAdvanceTest::configureTestIgnitionTable() { + IgnitionTable testIgnitionTable; for (int loadIdx = 0; loadIdx < IGN_LOAD_COUNT; loadIdx++) { - config->ignitionTable[loadIdx][0] = TEST_IGNITION_650; - config->ignitionTable[loadIdx][1] = TEST_IGNITION_800; - config->ignitionTable[loadIdx][2] = TEST_IGNITION_1100; - config->ignitionTable[loadIdx][3] = TEST_IGNITION_1400; - config->ignitionTable[loadIdx][4] = TEST_IGNITION_1700; - config->ignitionTable[loadIdx][5] = TEST_IGNITION_2000; - config->ignitionTable[loadIdx][6] = TEST_IGNITION_2300; - config->ignitionTable[loadIdx][7] = TEST_IGNITION_2600; - config->ignitionTable[loadIdx][8] = TEST_IGNITION_2900; - config->ignitionTable[loadIdx][9] = TEST_IGNITION_3200; - config->ignitionTable[loadIdx][10] = TEST_IGNITION_3500; - config->ignitionTable[loadIdx][11] = TEST_IGNITION_3800; - config->ignitionTable[loadIdx][12] = TEST_IGNITION_4100; - config->ignitionTable[loadIdx][13] = TEST_IGNITION_4400; - config->ignitionTable[loadIdx][14] = TEST_IGNITION_4700; - config->ignitionTable[loadIdx][15] = TEST_IGNITION_7000; - } + testIgnitionTable[loadIdx][0] = TEST_IGNITION_650; + testIgnitionTable[loadIdx][1] = TEST_IGNITION_800; + testIgnitionTable[loadIdx][2] = TEST_IGNITION_1100; + testIgnitionTable[loadIdx][3] = TEST_IGNITION_1400; + testIgnitionTable[loadIdx][4] = TEST_IGNITION_1700; + testIgnitionTable[loadIdx][5] = TEST_IGNITION_2000; + testIgnitionTable[loadIdx][6] = TEST_IGNITION_2300; + testIgnitionTable[loadIdx][7] = TEST_IGNITION_2600; + testIgnitionTable[loadIdx][8] = TEST_IGNITION_2900; + testIgnitionTable[loadIdx][9] = TEST_IGNITION_3200; + testIgnitionTable[loadIdx][10] = TEST_IGNITION_3500; + testIgnitionTable[loadIdx][11] = TEST_IGNITION_3800; + testIgnitionTable[loadIdx][12] = TEST_IGNITION_4100; + testIgnitionTable[loadIdx][13] = TEST_IGNITION_4400; + testIgnitionTable[loadIdx][14] = TEST_IGNITION_4700; + testIgnitionTable[loadIdx][15] = TEST_IGNITION_7000; + }; + getTestPersistentConfiguration().setIgnitionTable(testIgnitionTable); } TEST_F(IgnitionAngleAdvanceTest, withDisabledLaunchControlAndWithoutLaunchRetardWithSatisfiedLaunchConditions) { diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index 5f5b7d47a6..ff6a10ba63 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -50,6 +50,7 @@ TESTS_SRC_CPP = \ tests/ignition_injection/test_three_cylinder.cpp \ tests/util/test_base.cpp \ tests/util/test_engine_configuration.cpp \ + tests/util/test_persistent_configuration.cpp \ tests/util/test_engine_state.cpp \ tests/ac/ac_test_base.cpp \ tests/ac/ac_pressure_test.cpp \ diff --git a/unit_tests/tests/util/test_base.cpp b/unit_tests/tests/util/test_base.cpp index d80f465786..73bb49c125 100644 --- a/unit_tests/tests/util/test_base.cpp +++ b/unit_tests/tests/util/test_base.cpp @@ -18,6 +18,10 @@ TestEngineConfiguration& TestBase::getTestEngineConfiguration() { return TestEngineConfiguration::getInstance(); } +TestPersistentConfiguration& TestBase::getTestPersistentConfiguration() { + return TestPersistentConfiguration::getInstance(); +} + TestEngineState& TestBase::getTestEngineState() { return TestEngineState::getInstance(); } diff --git a/unit_tests/tests/util/test_base.h b/unit_tests/tests/util/test_base.h index 2681a3b208..600238d818 100644 --- a/unit_tests/tests/util/test_base.h +++ b/unit_tests/tests/util/test_base.h @@ -6,6 +6,7 @@ #include "test_engine_configuration.h" #include "test_engine_state.h" +#include "test_persistent_configuration.h" class TestBase : public testing::Test { protected: @@ -14,6 +15,7 @@ protected: TestEngineConfiguration& getTestEngineConfiguration(); TestEngineState& getTestEngineState(); + TestPersistentConfiguration& getTestPersistentConfiguration(); void periodicFastCallback(); void periodicSlowCallback(); diff --git a/unit_tests/tests/util/test_persistent_configuration.cpp b/unit_tests/tests/util/test_persistent_configuration.cpp new file mode 100644 index 0000000000..2d95e456cc --- /dev/null +++ b/unit_tests/tests/util/test_persistent_configuration.cpp @@ -0,0 +1,21 @@ +// +// Created by kifir on 11/5/24. +// + +#include "pch.h" + +#include "test_persistent_configuration.h" + +TestPersistentConfiguration& TestPersistentConfiguration::getInstance() { + return instance; +} + +void TestPersistentConfiguration::setIgnitionTable(const IgnitionTable& ignitions) { + for (int i = 0; i < IGN_LOAD_COUNT; i++) { + for (int j = 0; j < IGN_RPM_COUNT; j++) { + config->ignitionTable[i][j] = ignitions[i][j]; + } + } +} + +TestPersistentConfiguration TestPersistentConfiguration::instance; \ No newline at end of file diff --git a/unit_tests/tests/util/test_persistent_configuration.h b/unit_tests/tests/util/test_persistent_configuration.h new file mode 100644 index 0000000000..5024f0bd2f --- /dev/null +++ b/unit_tests/tests/util/test_persistent_configuration.h @@ -0,0 +1,16 @@ +// +// Created by kifir on 11/5/24. +// + +#pragma once + +using IgnitionTable = std::array, IGN_RPM_COUNT>; + +class TestPersistentConfiguration { +public: + static TestPersistentConfiguration& getInstance(); + + void setIgnitionTable(const IgnitionTable& ignitions); +private: + static TestPersistentConfiguration instance; +};