2019-01-03 04:57:34 -08:00
|
|
|
/*
|
2019-12-01 22:52:54 -08:00
|
|
|
* @file test_cj125.cpp
|
2019-01-03 04:57:34 -08:00
|
|
|
*
|
|
|
|
* Created on: Jan 3, 2019
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2019-01-03 04:57:34 -08:00
|
|
|
*/
|
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2019-04-12 13:08:52 -07:00
|
|
|
#include "cj125_logic.h"
|
2019-02-01 20:16:34 -08:00
|
|
|
|
2019-02-01 22:06:45 -08:00
|
|
|
class TestSpi : public Cj125SpiStream {
|
|
|
|
public:
|
|
|
|
MOCK_METHOD1(ReadRegister, uint8_t(uint8_t));
|
|
|
|
MOCK_METHOD2(WriteRegister, void(uint8_t, uint8_t));
|
|
|
|
};
|
|
|
|
|
2019-02-01 20:16:34 -08:00
|
|
|
TEST(testCJ125, testInitialState) {
|
|
|
|
CJ125 cj;
|
|
|
|
|
|
|
|
ASSERT_EQ(cj.state, CJ125_INIT);
|
|
|
|
ASSERT_FALSE(cj.isWorkingState());
|
2019-02-01 20:48:11 -08:00
|
|
|
ASSERT_EQ(cj.heaterDuty, 0);
|
2019-02-01 20:16:34 -08:00
|
|
|
|
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
2019-01-03 04:57:34 -08:00
|
|
|
|
2021-05-07 06:38:41 -07:00
|
|
|
cj.StartHeaterControl(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2019-02-01 20:48:11 -08:00
|
|
|
ASSERT_EQ(cj.heaterDuty, CJ125_HEATER_IDLE_RATE);
|
|
|
|
|
2019-02-01 22:06:45 -08:00
|
|
|
TestSpi mock;
|
|
|
|
cj.spi = &mock;
|
|
|
|
|
2019-12-01 22:52:54 -08:00
|
|
|
EXPECT_CALL(mock, ReadRegister(IDENT_REG_RD)).Times(1).WillOnce(Return(CJ125_IDENT));
|
|
|
|
EXPECT_CALL(mock, ReadRegister(INIT_REG1_RD)).Times(1).WillOnce(Return(CJ125_INIT1_NORMAL_17));
|
|
|
|
EXPECT_CALL(mock, ReadRegister(INIT_REG2_RD)).Times(1).WillOnce(Return(CJ125_INIT2_DIAG));
|
2019-02-01 22:06:45 -08:00
|
|
|
EXPECT_CALL(mock, ReadRegister(DIAG_REG_RD)).Times(1);
|
|
|
|
|
2020-05-01 15:52:06 -07:00
|
|
|
cj.cjIdentify(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2019-12-01 22:52:54 -08:00
|
|
|
// validate that error state was not set
|
|
|
|
ASSERT_EQ(cj.state, CJ125_INIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(testCJ125, testFailedIdentify) {
|
|
|
|
CJ125 cj;
|
|
|
|
|
|
|
|
ASSERT_EQ(cj.state, CJ125_INIT);
|
2019-02-01 22:06:45 -08:00
|
|
|
|
2019-12-01 22:52:54 -08:00
|
|
|
TestSpi mock;
|
|
|
|
cj.spi = &mock;
|
|
|
|
|
2020-05-01 15:52:06 -07:00
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
|
|
|
|
|
|
|
cj.cjIdentify(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2019-12-01 22:52:54 -08:00
|
|
|
ASSERT_EQ(cj.errorCode, CJ125_ERROR_WRONG_IDENT);
|
|
|
|
ASSERT_EQ(cj.state, CJ125_ERROR);
|
2019-01-03 04:57:34 -08:00
|
|
|
}
|
|
|
|
|
2019-12-01 22:52:54 -08:00
|
|
|
TEST(testCJ125, testMode) {
|
2019-01-03 04:57:34 -08:00
|
|
|
|
2019-12-01 22:52:54 -08:00
|
|
|
|
|
|
|
|
|
|
|
}
|