better pch usage and gmock constructors (#3426)
* break out mock constructors * comment and spacing * unnecessary compiler options * happy stepper Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
1a979805ce
commit
29ec0a5859
|
@ -188,7 +188,7 @@ bool StepDirectionStepper::pulse() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void StepperHw::sleep(void) {
|
||||
void StepperHw::sleep() {
|
||||
pause();
|
||||
}
|
||||
|
||||
|
@ -236,3 +236,7 @@ void StepDirectionStepper::initialize(brain_pin_e stepPin, brain_pin_e direction
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
void StepperHw::sleep() { }
|
||||
#endif // EFI_UNIT_TEST
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
// pause between steps
|
||||
void pause(int divisor = 1) const;
|
||||
// pause and enter the idle mode (less current consumption)
|
||||
virtual void sleep(void);
|
||||
virtual void sleep();
|
||||
|
||||
protected:
|
||||
void setReactionTime(float ms);
|
||||
|
@ -51,7 +51,7 @@ public:
|
|||
|
||||
bool step(bool positive) override;
|
||||
|
||||
void sleep(void) override;
|
||||
void sleep() override;
|
||||
|
||||
protected:
|
||||
bool update(float dutyMult);
|
||||
|
|
|
@ -101,7 +101,7 @@ bool DualHBridgeStepper::update(float dutyMult) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void DualHBridgeStepper::sleep(void) {
|
||||
void DualHBridgeStepper::sleep() {
|
||||
float sleepingCoef = minI(CONFIG(stepperMinDutyCycle), CONFIG(stepperMaxDutyCycle)) * phaseDutyCycleDivisor;
|
||||
update(sleepingCoef);
|
||||
pause();
|
||||
|
|
|
@ -35,4 +35,5 @@
|
|||
#include <gmock/gmock.h>
|
||||
#include "mocks.h"
|
||||
#include "engine_test_helper.h"
|
||||
#include "mock/mock_sensor.h"
|
||||
#endif
|
||||
|
|
|
@ -61,6 +61,7 @@ CPPSRC += $(ALLCPPSRC) \
|
|||
$(PROJECT_DIR)/../unit_tests/global_mocks.cpp \
|
||||
$(PROJECT_DIR)/console/binary/tooth_logger.cpp \
|
||||
$(PROJECT_DIR)/console/binary_log/log_field.cpp \
|
||||
$(PROJECT_DIR)/../unit_tests/mocks.cpp \
|
||||
|
||||
INCDIR += \
|
||||
$(PCH_DIR) \
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#include "pch.h"
|
||||
|
||||
// Constructors/destructors for all mocks live here. If they only exist
|
||||
// in the header (ie, implicitely defined), then that code has to be generated
|
||||
// in every cpp file, instead of generating them only once, which we do here.
|
||||
|
||||
// See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#making-the-compilation-faster
|
||||
|
||||
MockEtb::MockEtb() { }
|
||||
MockEtb::~MockEtb() { }
|
||||
|
||||
MockMotor::MockMotor() { }
|
||||
MockMotor::~MockMotor() { }
|
||||
|
||||
MockVp3d::MockVp3d() { }
|
||||
MockVp3d::~MockVp3d() { }
|
||||
|
||||
MockPwm::MockPwm() { }
|
||||
MockPwm::~MockPwm() { }
|
||||
|
||||
MockOutputPin::MockOutputPin() { }
|
||||
MockOutputPin::~MockOutputPin() { }
|
||||
|
||||
MockExecutor::MockExecutor() { }
|
||||
MockExecutor::~MockExecutor() { }
|
||||
|
||||
MockAirmass::MockAirmass() : AirmassVeModelBase(veTable) { }
|
||||
MockAirmass::~MockAirmass() { }
|
||||
|
||||
MockInjectorModel2::MockInjectorModel2() { }
|
||||
MockInjectorModel2::~MockInjectorModel2() { }
|
||||
|
||||
MockStepperHardware::MockStepperHardware() { }
|
||||
MockStepperHardware::~MockStepperHardware() { }
|
|
@ -12,6 +12,9 @@
|
|||
|
||||
class MockEtb : public IEtbController {
|
||||
public:
|
||||
MockEtb();
|
||||
virtual ~MockEtb();
|
||||
|
||||
// IEtbController mocks
|
||||
MOCK_METHOD(void, reset, (), (override));
|
||||
MOCK_METHOD(void, update, (), (override));
|
||||
|
@ -31,6 +34,9 @@ public:
|
|||
|
||||
class MockMotor : public DcMotor {
|
||||
public:
|
||||
MockMotor();
|
||||
virtual ~MockMotor();
|
||||
|
||||
MOCK_METHOD(bool, set, (float duty), (override));
|
||||
MOCK_METHOD(float, get, (), (const, override));
|
||||
MOCK_METHOD(void, enable, (), (override));
|
||||
|
@ -40,21 +46,33 @@ public:
|
|||
|
||||
class MockVp3d : public ValueProvider3D {
|
||||
public:
|
||||
MockVp3d();
|
||||
virtual ~MockVp3d();
|
||||
|
||||
MOCK_METHOD(float, getValue, (float xColumn, float yRow), (const, override));
|
||||
};
|
||||
|
||||
class MockPwm : public IPwm {
|
||||
public:
|
||||
MockPwm();
|
||||
virtual ~MockPwm();
|
||||
|
||||
MOCK_METHOD(void, setSimplePwmDutyCycle, (float dutyCycle), (override));
|
||||
};
|
||||
|
||||
class MockOutputPin : public OutputPin {
|
||||
public:
|
||||
MockOutputPin();
|
||||
virtual ~MockOutputPin();
|
||||
|
||||
MOCK_METHOD(void, setValue, (int value), (override));
|
||||
};
|
||||
|
||||
class MockExecutor : public TestExecutor {
|
||||
public:
|
||||
MockExecutor();
|
||||
virtual ~MockExecutor();
|
||||
|
||||
MOCK_METHOD(void, scheduleByTimestamp, (const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action), (override));
|
||||
MOCK_METHOD(void, scheduleByTimestampNt, (const char *msg, scheduling_s *scheduling, efitime_t timeUs, action_s action), (override));
|
||||
MOCK_METHOD(void, scheduleForLater, (scheduling_s *scheduling, int delayUs, action_s action), (override));
|
||||
|
@ -63,7 +81,8 @@ public:
|
|||
|
||||
class MockAirmass : public AirmassVeModelBase {
|
||||
public:
|
||||
MockAirmass() : AirmassVeModelBase(veTable) {}
|
||||
MockAirmass();
|
||||
virtual ~MockAirmass();
|
||||
|
||||
MockVp3d veTable;
|
||||
|
||||
|
@ -72,6 +91,9 @@ public:
|
|||
|
||||
class MockInjectorModel2 : public IInjectorModel {
|
||||
public:
|
||||
MockInjectorModel2();
|
||||
virtual ~MockInjectorModel2();
|
||||
|
||||
MOCK_METHOD(void, prepare, (), (override));
|
||||
MOCK_METHOD(floatms_t, getInjectionDuration, (float fuelMassGram), (const, override));
|
||||
MOCK_METHOD(float, getFuelMassForDuration, (floatms_t duration), (const, override));
|
||||
|
@ -79,5 +101,8 @@ public:
|
|||
|
||||
class MockStepperHardware : public StepperHw {
|
||||
public:
|
||||
MockStepperHardware();
|
||||
virtual ~MockStepperHardware();
|
||||
|
||||
MOCK_METHOD(bool, step, (bool positive), (override));
|
||||
};
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "pch.h"
|
||||
#include "injector_model.h"
|
||||
#include "mock/mock_sensor.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::StrictMock;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "pch.h"
|
||||
#include "rusefi_lua.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(LuaBasic, ReturnsNumber) {
|
||||
auto script = R"(
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include "mock/mock_sensor.h"
|
||||
#include "stored_value_sensor.h"
|
||||
|
||||
class SensorBasic : public ::testing::Test {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "func_chain.h"
|
||||
#include "pch.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "func_chain.h"
|
||||
|
||||
struct AddOne final : public SensorConverter {
|
||||
SensorResult convert(float input) const {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "function_pointer_sensor.h"
|
||||
#include "pch.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "function_pointer_sensor.h"
|
||||
|
||||
class SensorFunctionPointer : public ::testing::Test {
|
||||
protected:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "stored_value_sensor.h"
|
||||
#include "global.h"
|
||||
|
||||
struct MockSensor final : public StoredValueSensor
|
||||
{
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include "mock/mock_sensor.h"
|
||||
|
||||
class SensorMocking : public ::testing::Test {
|
||||
protected:
|
||||
MockSensor realSensor;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include "redundant_sensor.h"
|
||||
#include "redundant_ford_tps.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "mock/mock_sensor.h"
|
||||
|
||||
class SensorRedundant : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include "sensor_reader.h"
|
||||
|
||||
#include "mock/mock_sensor.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
class SensorBasicReader : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "deadband.h"
|
||||
|
||||
TEST(Deadband, OutsideDeadband) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include "buffered_writer.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "pch.h"
|
||||
|
||||
#include "error_accumulator.h"
|
||||
|
||||
TEST(errorAccumulator, ignoreSmallError) {
|
||||
|
|
|
@ -52,7 +52,7 @@ endif
|
|||
|
||||
# C++ specific options here (added to USE_OPT).
|
||||
ifeq ($(USE_CPPOPT),)
|
||||
USE_CPPOPT = -std=gnu++17 -fno-rtti -fpermissive -fexceptions -fno-use-cxa-atexit -Winvalid-pch
|
||||
USE_CPPOPT = -std=gnu++17 -fno-rtti -fno-use-cxa-atexit -Winvalid-pch
|
||||
endif
|
||||
|
||||
# Enable this if you want the linker to remove unused code and data
|
||||
|
|
Loading…
Reference in New Issue