Skip to content

Commit

Permalink
Fix and add unit tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
  • Loading branch information
maaikez committed Dec 11, 2024
1 parent 9ab13a3 commit 191c2d2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/lib/ocpp/v201/test_charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class ChargePointCommonTestFixtureV201 : public DatabaseTestingUtils {
callbacks.update_firmware_request_callback = update_firmware_request_callback_mock.AsStdFunction();
callbacks.security_event_callback = security_event_callback_mock.AsStdFunction();
callbacks.set_charging_profiles_callback = set_charging_profiles_callback_mock.AsStdFunction();
callbacks.reserve_now_callback = reserve_now_callback_mock.AsStdFunction();
callbacks.cancel_reservation_callback = cancel_reservation_callback_mock.AsStdFunction();
}

std::shared_ptr<DeviceModel> device_model;
Expand Down Expand Up @@ -191,6 +193,8 @@ class ChargePointCommonTestFixtureV201 : public DatabaseTestingUtils {
testing::MockFunction<void(const CiString<50>& event_type, const std::optional<CiString<255>>& tech_info)>
security_event_callback_mock;
testing::MockFunction<void()> set_charging_profiles_callback_mock;
testing::MockFunction<ReserveNowStatusEnum(const ReserveNowRequest& request)> reserve_now_callback_mock;
testing::MockFunction<bool(const int32_t reservationId)> cancel_reservation_callback_mock;
ocpp::v201::Callbacks callbacks;
};

Expand Down Expand Up @@ -492,6 +496,42 @@ TEST_F(ChargePointCommonTestFixtureV201,
EXPECT_TRUE(callbacks.all_callbacks_valid(device_model));
}

TEST_F(ChargePointCommonTestFixtureV201, ReservationAvailableReserveNowCallbackNotSet) {
configure_callbacks_with_mocks();
device_model->set_value(ControllerComponentVariables::ReservationCtrlrAvailable.component,
ControllerComponentVariables::ReservationCtrlrAvailable.variable.value(),
AttributeEnum::Actual, "true", "test", true);
callbacks.reserve_now_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid(device_model));
}

TEST_F(ChargePointCommonTestFixtureV201, ReservationAvailableCancelReservationCallbackNotSet) {
configure_callbacks_with_mocks();
device_model->set_value(ControllerComponentVariables::ReservationCtrlrAvailable.component,
ControllerComponentVariables::ReservationCtrlrAvailable.variable.value(),
AttributeEnum::Actual, "true", "test", true);
callbacks.cancel_reservation_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid(device_model));
}

TEST_F(ChargePointCommonTestFixtureV201, ReservationNotAvailableReserveNowCallbackNotSet) {
configure_callbacks_with_mocks();
device_model->set_value(ControllerComponentVariables::ReservationCtrlrAvailable.component,
ControllerComponentVariables::ReservationCtrlrAvailable.variable.value(),
AttributeEnum::Actual, "false", "test", true);
callbacks.reserve_now_callback = nullptr;
EXPECT_TRUE(callbacks.all_callbacks_valid(device_model));
}

TEST_F(ChargePointCommonTestFixtureV201, ReservationNotAvailableCancelReservationCallbackNotSet) {
configure_callbacks_with_mocks();
device_model->set_value(ControllerComponentVariables::ReservationCtrlrAvailable.component,
ControllerComponentVariables::ReservationCtrlrAvailable.variable.value(),
AttributeEnum::Actual, "false", "test", true);
callbacks.cancel_reservation_callback = nullptr;
EXPECT_TRUE(callbacks.all_callbacks_valid(device_model));
}

class ChargePointConstructorTestFixtureV201 : public ChargePointCommonTestFixtureV201 {
public:
ChargePointConstructorTestFixtureV201() :
Expand Down

0 comments on commit 191c2d2

Please sign in to comment.