and finally a unit test, like it shoud be!

This commit is contained in:
rusefi 2019-12-13 14:55:20 -05:00
parent fcf88778e5
commit aa1b7e2c6b
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,67 @@
/*
* @file test_etb.cpp
*
* @date Dec 13, 2019
* @author Andrey Belomutskiy, (c) 2012-2019
*/
#include "engine_test_helper.h"
#include "electronic_throttle.h"
#include "dc_motor.h"
class MockEtb : public IEtbController {
public:
// todo: somehow I am failinig to figure out GMOCK syntax here?
// todo: convert to GMOCK
int resetCount = 0;
int startCount = 0;
int initCount = 0;
void reset() {
resetCount++;
}
void Start() override {
startCount++;
}
void init(DcMotor *motor, int ownIndex, pid_s *pidParameters) {
initCount++;
};
void PeriodicTask() {
};
int getPeriodMs() {
return 1;
};
};
TEST(etb, singleEtbInitialization) {
MockEtb mocks[ETB_COUNT];
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
for (int i = 0; i < ETB_COUNT; i++) {
engine->etbControllers[i] = &mocks[i];
}
engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_9;
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
// assert that 1st ETB is initialized and started
ASSERT_EQ(1, mocks[0].initCount) << "1st init";
ASSERT_EQ(1, mocks[0].startCount);
// assert that 2nd ETB is initialized but not started
ASSERT_EQ(1, mocks[1].initCount) << "2nd init";
ASSERT_EQ(0, mocks[1].startCount) << "2nd start";
}

View File

@ -15,6 +15,7 @@ TESTS_SRC_CPP = \
tests/test_trigger_decoder.cpp \
tests/test_trigger_noiseless.cpp \
tests/test_issue_898.cpp \
tests/test_etb.cpp \
tests/test_ignition_scheduling.cpp \
tests/test_fuel_map.cpp \
tests/test_fuel_wall_wetting.cpp \