Skip to content

Commit

Permalink
Add tests for optional functions being validated.
Browse files Browse the repository at this point in the history
Signed-off-by: Gianfranco Berardi <[email protected]>
  • Loading branch information
gberardi-pillar committed May 8, 2024
1 parent 55b5be7 commit 8b3bf6e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class UnexpectedMessageTypeFromCSMS : public std::runtime_error {

struct Callbacks {
///\brief Function to check if the callback struct is completely filled. All std::functions should hold a function,
/// all std::optional<std::functions> should either be emtpy or hold a function.
/// all std::optional<std::functions> should either be empty or hold a function.
///
///\retval false if any of the normal callbacks are nullptr or any of the optional ones are filled with a nullptr
/// true otherwise
Expand Down
69 changes: 68 additions & 1 deletion tests/lib/ocpp/v201/test_charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,71 @@ TEST_F(ChargePointFixture, CallbacksValidityChecksIfSetChargingProfilesCallbackE
EXPECT_FALSE(callbacks.all_callbacks_valid());
}

} // namespace ocpp::v201
TEST_F(ChargePointFixture, CallbacksValidityChecksIfOptionalVariableChangedCallbackIsNotSetOrNotNull) {
configure_callbacks_with_mocks();

callbacks.variable_changed_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid());

testing::MockFunction<void(const SetVariableData& set_variable_data)> variable_changed_callback_mock;
callbacks.variable_changed_callback = variable_changed_callback_mock.AsStdFunction();
EXPECT_TRUE(callbacks.all_callbacks_valid());
}

TEST_F(ChargePointFixture, CallbacksValidityChecksIfOptionalVariableNetworkProfileCallbackIsNotSetOrNotNull) {
configure_callbacks_with_mocks();

callbacks.validate_network_profile_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid());

testing::MockFunction<SetNetworkProfileStatusEnum(
const int32_t configuration_slot, const NetworkConnectionProfile& network_connection_profile)> validate_network_profile_callback_mock;
callbacks.validate_network_profile_callback = validate_network_profile_callback_mock.AsStdFunction();
EXPECT_TRUE(callbacks.all_callbacks_valid());
}

TEST_F(ChargePointFixture, CallbacksValidityChecksIfOptionalConfigureNetworkConnectionProfileCallbackIsNotSetOrNotNull) {
configure_callbacks_with_mocks();

callbacks.configure_network_connection_profile_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid());

testing::MockFunction<bool(const NetworkConnectionProfile& network_connection_profile)> configure_network_connection_profile_callback_mock;
callbacks.configure_network_connection_profile_callback = configure_network_connection_profile_callback_mock.AsStdFunction();
EXPECT_TRUE(callbacks.all_callbacks_valid());
}

TEST_F(ChargePointFixture, CallbacksValidityChecksIfOptionalTimeSyncCallbackIsNotSetOrNotNull) {
configure_callbacks_with_mocks();

callbacks.time_sync_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid());

testing::MockFunction<void(const ocpp::DateTime& currentTime)> time_sync_callback_mock;
callbacks.time_sync_callback = time_sync_callback_mock.AsStdFunction();
EXPECT_TRUE(callbacks.all_callbacks_valid());
}

TEST_F(ChargePointFixture, CallbacksValidityChecksIfOptionalBootNotificationCallbackIsNotSetOrNotNull) {
configure_callbacks_with_mocks();

callbacks.boot_notification_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid());

testing::MockFunction<void(const ocpp::v201::RegistrationStatusEnum& reg_status)> boot_notification_callback_mock;
callbacks.boot_notification_callback = boot_notification_callback_mock.AsStdFunction();
EXPECT_TRUE(callbacks.all_callbacks_valid());
}

TEST_F(ChargePointFixture, CallbacksValidityChecksIfOptionalOCPPMessagesCallbackIsNotSetOrNotNull) {
configure_callbacks_with_mocks();

callbacks.ocpp_messages_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid());

testing::MockFunction<void(const std::string& message, MessageDirection direction)> ocpp_messages_callback_mock;
callbacks.ocpp_messages_callback = ocpp_messages_callback_mock.AsStdFunction();
EXPECT_TRUE(callbacks.all_callbacks_valid());
}

} // namespace ocpp::v201

0 comments on commit 8b3bf6e

Please sign in to comment.