#35 first unit test with a mock!

This commit is contained in:
rusefi 2019-01-08 01:20:18 -05:00
parent 778c1968e7
commit 60e747481f
5 changed files with 45 additions and 3 deletions

View File

@ -185,7 +185,7 @@ void setHip9011FrankensoPinout(void) {
// boardConfiguration->hip9011CsPin = GPIOD_0; // rev 0.1
boardConfiguration->isHip9011Enabled = true;
engineConfiguration->hip9011PrescalerAndSDO = 6; // 8MHz chip
engineConfiguration->hip9011PrescalerAndSDO = _8MHZ_PRESCALER; // 8MHz chip
boardConfiguration->is_enabled_spi_2 = true;
// todo: convert this to rusEfi, hardware-independent enum
#if EFI_PROD_CODE

View File

@ -103,4 +103,6 @@ int getHip9011GainIndex(DEFINE_HIP_PARAMS);
// 0b10000000
#define SET_GAIN_CMD 0x80
#define _8MHZ_PRESCALER 6
#endif /* HW_LAYER_HIP9011_LOGIC_H_ */

View File

@ -111,6 +111,7 @@ CSRC = $(UTILSRC) \
# setting.
CPPSRC = $(UTILSRC_CPP) \
gtest-all.cpp \
gmock-all.cpp \
$(CONTROLLERS_ALGO_SRC_CPP) \
$(TRIGGER_DECODERS_SRC_CPP) \
$(ENGINES_SRC_CPP) \
@ -170,6 +171,7 @@ INCDIR = . \
$(PROJECT_DIR)/hw_layer/algo \
$(PROJECT_DIR)/hw_layer/sensors/ \
test_data_structures \
googletest/googlemock/include \
googletest/googletest \
googletest/googletest/include \
tests \

8
unit_tests/gmock-all.cpp Normal file
View File

@ -0,0 +1,8 @@
// this is a work-around since our Makefile does not recognice .cc format
// todo: adjust the makefile so that we can remove this
#include "googletest/googlemock/src/gmock-cardinalities.cc"
#include "googletest/googlemock/src/gmock-internal-utils.cc"
#include "googletest/googlemock/src/gmock-matchers.cc"
#include "googletest/googlemock/src/gmock-spec-builders.cc"
#include "googletest/googlemock/src/gmock.cc"

View File

@ -9,6 +9,7 @@
#include "HIP9011_logic.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
using ::testing::_;
TEST(hip9011, lookup) {
assertEqualsM2("", 3183.1013, getRpmByAngleWindowAndTimeUs(600, 360), 0.1);
@ -54,7 +55,36 @@ public:
MOCK_METHOD1(sendCommand, void(unsigned char));
};
TEST(hip9011, takeValue) {
TEST(hip9011, configurationCommands) {
HIP9011 instace(NULL);
MockHip9011Hardware mock;
HIP9011 instance(&mock);
instance.prepareHip9011RpmLookup(50);
// want to invoke method with same parameters a few times
#define PARAMETERS 600, _8MHZ_PRESCALER, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1
// Not making assumptions on the message send ...
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);
EXPECT_CALL(mock, sendCommand(SET_GAIN_CMD + 0xE)).Times(1);
instance.handleValue(PARAMETERS);
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);
EXPECT_CALL(mock, sendCommand(SET_INTEGRATOR_CMD + 0x1C)).Times(1);
instance.handleValue(PARAMETERS);
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);
EXPECT_CALL(mock, sendCommand(SET_BAND_PASS_CMD + 0x2A)).Times(1);
instance.handleValue(PARAMETERS);
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);
EXPECT_CALL(mock, sendCommand(SET_PRESCALER_CMD + 6)).Times(1);
instance.handleValue(PARAMETERS);
// initialization is over, no commands should be sent
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);
EXPECT_CALL(mock, sendCommand(_)).Times(0);
instance.handleValue(PARAMETERS);
}