From 84fe93c604b299e05f764cd859ad8b8787f5743a Mon Sep 17 00:00:00 2001 From: Christoph <367712+folkengine@users.noreply.github.com> Date: Wed, 24 Jan 2024 07:25:35 -0800 Subject: [PATCH 1/6] Added unit testing for v1.6 Smart Charging Validate Profile Signed-off-by: Christoph <367712+folkengine@users.noreply.github.com> --- tests/CMakeLists.txt | 1 + tests/database_handler_mock.hpp | 20 + tests/lib/ocpp/v16/CMakeLists.txt | 2 + .../ocpp/v16/test_smart_charging_handler.cpp | 509 ++++++++++++++++++ 4 files changed, 532 insertions(+) create mode 100644 tests/database_handler_mock.hpp create mode 100644 tests/lib/ocpp/v16/CMakeLists.txt create mode 100644 tests/lib/ocpp/v16/test_smart_charging_handler.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 371f9a535..d27fcefa1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,6 +32,7 @@ target_link_libraries(libocpp_unit_tests PRIVATE target_sources(libocpp_unit_tests PRIVATE comparators.cpp) + add_subdirectory(lib/ocpp/v16) add_subdirectory(lib/ocpp/v201) add_subdirectory(lib/ocpp/common) diff --git a/tests/database_handler_mock.hpp b/tests/database_handler_mock.hpp new file mode 100644 index 000000000..f8a873358 --- /dev/null +++ b/tests/database_handler_mock.hpp @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OCPP_DATABASE_HANDLE_MOCK_H +#define OCPP_DATABASE_HANDLE_MOCK_H + +#include +#include + +#include + +namespace ocpp { + +class DatabaseHandlerMock : public DatabaseHandler { +public: + +}; + +} // namespace ocpp + +#endif // DATABASE_HANDLE_MOCK_H \ No newline at end of file diff --git a/tests/lib/ocpp/v16/CMakeLists.txt b/tests/lib/ocpp/v16/CMakeLists.txt new file mode 100644 index 000000000..04cfe5e13 --- /dev/null +++ b/tests/lib/ocpp/v16/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(libocpp_unit_tests PRIVATE + test_smart_charging_handler.cpp) \ No newline at end of file diff --git a/tests/lib/ocpp/v16/test_smart_charging_handler.cpp b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp new file mode 100644 index 000000000..d4c0b93df --- /dev/null +++ b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp @@ -0,0 +1,509 @@ +#include +#include +#include +namespace fs = std::filesystem; + +#include +#include +#include +#include + +namespace ocpp { +namespace v16 { + +/** + * Chargepoint Test Fixture + * + * Test Matrix: + * + * Positive Boundary Conditions: + * - PB01 Valid Profile + * - PB02 Valid Profile No startSchedule & handler allows no startSchedule & profile.chargingProfileKind == Absolute + * - PB03 Valid Profile No startSchedule & handler allows no startSchedule & profile.chargingProfileKind == Relative + * - PB04 Absolute ChargePointMaxProfile Profile with connector id 0 + * - PB05 Absolute TxDefaultProfile + * - PB06 Absolute TxProfile && connector transaction != nullptr && transaction_id matches SKIPPED: was not able to test + * + * Negative Boundary Conditions: + * - NB01 Valid Profile, ConnectorID gt this->connectors.size() + * - NB02 Valid Profile, ConnectorID lt 0 + * - NB03 profile.stackLevel lt 0 + * - NB04 profile.stackLevel gt profile_max_stack_level + * - NB05 profile.chargingProfileKind == Absolute && !profile.chargingSchedule.startSchedule + * - NB06 Number of installed Profiles is > max_charging_profiles_installed + * - NB07 Invalid ChargingSchedule + * - NB08 profile.chargingProfileKind == Recurring && !profile.recurrencyKind + * - NB09 profile.chargingProfileKind == Recurring && !startSchedule + * - NB10 profile.chargingProfileKind == Recurring && !startSchedule && !allow_charging_profile_without_start_schedule + * - NB11 Absolute ChargePointMaxProfile Profile with connector id not 0 + * - NB12 Absolute TxProfile connector_id == 0 + */ +class ChargepointTestFixture : public testing::Test { +protected: + void SetUp() override { + } + + ChargingSchedule createChargeSchedule() { + return ChargingSchedule{{}}; + } + + ChargingSchedule createChargeSchedule(ChargingRateUnit chargingRateUnit) { + std::vector chargingSchedulePeriod; + std::optional duration; + std::optional startSchedule; + std::optional minChargingRate; + + return ChargingSchedule{chargingRateUnit, chargingSchedulePeriod, duration, startSchedule, minChargingRate}; + } + + ChargingProfile createChargingProfile(ChargingSchedule chargingSchedule) { + auto chargingProfileId = 1; + auto stackLevel = 1; + auto chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile; + auto chargingProfileKind = ChargingProfileKindType::Absolute; + auto recurrencyKind = RecurrencyKindType::Daily; + return ChargingProfile{ + chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + {}, // validFrom + {} // validTo + }; + } + + /** + * TxDefaultProfile, stack #1: time-of-day limitation to 2 kW, recurring every day from 17:00h to 20:00h. + * + * This profile is Example #1 taken from the OCPP 2.0.1 Spec Part 2, page 241. + */ + ChargingProfile createChargingProfile_Example1() { + auto chargingRateUnit = ChargingRateUnit::W; + auto chargingSchedulePeriod = std::vector{ChargingSchedulePeriod{0, 2000, 1}}; + auto duration = 1080; + auto startSchedule = ocpp::DateTime("2024-01-17T17:00:00"); + float minChargingRate = 0; + auto chargingSchedule = ChargingSchedule{ + chargingRateUnit, + chargingSchedulePeriod, + duration, + startSchedule, + minChargingRate + }; + + auto chargingProfileId = 1; + auto stackLevel = 1; + auto chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile; + auto chargingProfileKind = ChargingProfileKindType::Absolute; + auto recurrencyKind = RecurrencyKindType::Daily; + return ChargingProfile{ + chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + {}, // validFrom + {} // validTo + }; + } + + /** + * TxDefaultProfile, stack #2: overruling Sundays to no limit, recurring every week starting 2020-01-05. + * + * This profile is Example #2 taken from the OCPP 2.0.1 Spec Part 2, page 241. + */ + ChargingProfile createChargingProfile_Example2() { + auto chargingRateUnit = ChargingRateUnit::W; + auto chargingSchedulePeriod = std::vector{ChargingSchedulePeriod{0, 999999, 1}}; + auto duration = 0; + auto startSchedule = ocpp::DateTime("2020-01-19T00:00:00"); + float minChargingRate = 0; + auto chargingSchedule = ChargingSchedule{ + chargingRateUnit, + chargingSchedulePeriod, + duration, + startSchedule, + minChargingRate + }; + + auto chargingProfileId = 11; + auto stackLevel = 2; + auto chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile; + auto chargingProfileKind = ChargingProfileKindType::Recurring; + auto recurrencyKind = RecurrencyKindType::Weekly; + return ChargingProfile{ + chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + {}, + {} + }; + } + + SmartChargingHandler* createSmartChargingHandler() { + auto c1 = std::make_shared(Connector{1}); + connectors[1] = c1; + auto handler = new SmartChargingHandler(connectors, database_handler, true); + return handler; + } + + // Default values used within the tests + std::map> connectors; + std::shared_ptr database_handler; + + const int connector_id = 1; + bool ignore_no_transaction = true; + const int profile_max_stack_level = 1; + const int max_charging_profiles_installed = 1; + const int charging_schedule_max_periods = 1; +}; + +/** + * PB01 Valid Profile + */ +TEST_F(ChargepointTestFixture, ValidateProfile) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_TRUE(sut); +} + +/** + * PB01 Valid Profile: Example 1 + * + * This example is taken from the OCPP 2.0.1 Spec page. 241 + */ +TEST_F(ChargepointTestFixture, ValidateProfile__example1) { + auto profile = createChargingProfile_Example1(); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::W}; + auto handler = createSmartChargingHandler(); + + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_TRUE(sut); +} + +/** + * NB01 Valid Profile, ConnectorID gt this->connectors.size() + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ConnectorIdGreaterThanConnectorsSize__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + const int connector_id = INT_MAX; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * NB02 Valid Profile, ConnectorID lt 0 + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NegativeConnectorIdTest__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + const int connector_id = -1; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * NB03 profile.stackLevel lt 0 + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ConnectorIdZero__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + profile.stackLevel = -1; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * NB04 profile.stackLevel gt this->profile_max_stack_level + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_StackLevelGreaterThanMaxStackLevel__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + profile.stackLevel = profile_max_stack_level + 1; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * NB05 profile.chargingProfileKind == Absolute && !profile.chargingSchedule.startSchedule +*/ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ChargingProfileKindAbsoluteNoStartSchedule__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + // Create a SmartChargingHandler where allow_charging_profile_without_start_schedule is set to false + auto c1 = std::make_shared(Connector{1}); + connectors[1] = c1; + auto allow_charging_profile_without_start_schedule = false; + auto handler = new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); + + profile.chargingProfileKind = ChargingProfileKindType::Absolute; + profile.chargingSchedule.startSchedule = std::nullopt; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * PB02 Valid Profile No startSchedule & handler allows no startSchedule +*/ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_AllowsNoStartSchedule__ReturnsTrue) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + // Create a SmartChargingHandler where allow_charging_profile_without_start_schedule is set to false + auto handler = createSmartChargingHandler(); + + // Configure to have no start schedule + profile.chargingProfileKind = ChargingProfileKindType::Absolute; + profile.chargingSchedule.startSchedule = std::nullopt; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_TRUE(sut); +} + +/** + * NB06 Number of installed Profiles is > max_charging_profiles_installed + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_InstalledProfilesGreaterThanMaxInstalledProfiles__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + const int max_charging_profiles_installed = 0; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * NB07 Invalid ChargingSchedule + * + * Creating a ChargingProfile with a different ChargingRateUnit + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_InvalidChargingSchedule__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + profile.chargingSchedule.chargingSchedulePeriod = std::vector{}; + auto handler = createSmartChargingHandler(); + + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::W}; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * NB08 profile.chargingProfileKind == Recurring && !profile.recurrencyKind + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ChargingProfileKindRecurringNoRecurrencyKind__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + profile.chargingProfileKind = ChargingProfileKindType::Recurring; + profile.recurrencyKind = std::nullopt; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * NB09 profile.chargingProfileKind == Recurring && !profile.chargingSchedule.startSchedule + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ChargingProfileKindRecurringNoStartSchedule__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + // Create a SmartChargingHandler where allow_charging_profile_without_start_schedule is set to false + auto c1 = std::make_shared(Connector{1}); + connectors[1] = c1; + auto allow_charging_profile_without_start_schedule = false; + auto handler = new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); + + profile.chargingProfileKind = ChargingProfileKindType::Recurring; + profile.chargingSchedule.startSchedule = std::nullopt; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * PB03 Valid Profile No startSchedule & handler allows no startSchedule & profile.chargingProfileKind == Relative + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NoStartScheduleAllowedRelative__ReturnsTrue) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + profile.chargingProfileKind = ChargingProfileKindType::Recurring; + profile.chargingSchedule.startSchedule = std::nullopt; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_TRUE(sut); +} + +/** + * NB10 profile.chargingProfileKind == Recurring && !startSchedule && !allow_charging_profile_without_start_schedule + */ +TEST_F(ChargepointTestFixture, ValidateProfile__RecurringNoStartScheduleNotAllowed__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto c1 = std::make_shared(Connector{1}); + connectors[1] = c1; + auto allow_charging_profile_without_start_schedule = false; + auto handler = new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); + + profile.chargingProfileKind = ChargingProfileKindType::Recurring; + profile.chargingSchedule.startSchedule = std::nullopt; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * PB04 Absolute ChargePointMaxProfile Profile with connector id 0 + * + * Absolute ChargePointMaxProfile Profile need a connector id of 0 + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NotRecurrencyKindConnectorId0__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + profile.chargingProfilePurpose = ChargingProfilePurposeType::ChargePointMaxProfile; + profile.chargingProfileKind = ChargingProfileKindType::Absolute; + const int connector_id = 0; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_TRUE(sut); +} + +/** + * NB11 Absolute ChargePointMaxProfile Profile with connector id not 0 + * + * ChargePointMaxProfile Profiles where chargingProfileKind == Absolute need a connector id of 0 and not had a + * ChargingProfileKindType of Relative + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NotRecurrencyKindConnectorIdNot0__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + profile.chargingProfilePurpose = ChargingProfilePurposeType::ChargePointMaxProfile; + profile.chargingProfileKind = ChargingProfileKindType::Absolute; + const int connector_id = 1; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +/** + * PB05 Absolute TxDefaultProfile + */ +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfileTxDefaultProfile__ReturnsTrue) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + profile.chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile; + profile.chargingProfileKind = ChargingProfileKindType::Absolute; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_TRUE(sut); +} + +/** + * PB05 Absolute TxProfile ignore_no_transaction == true + */ +TEST_F(ChargepointTestFixture, ValidateProfile__AbsoluteTxProfileIgnoreNoTransaction__ReturnsTrue) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + profile.chargingProfilePurpose = ChargingProfilePurposeType::TxProfile; + profile.chargingProfileKind = ChargingProfileKindType::Absolute; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_TRUE(sut); +} + +/** + * NB12 Absolute TxProfile connector_id == 0 + */ +TEST_F(ChargepointTestFixture, ValidateProfile__AbsoluteTxProfileConnectorId0__ReturnsFalse) { + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + auto handler = createSmartChargingHandler(); + + profile.chargingProfileKind = ChargingProfileKindType::Absolute; + profile.chargingProfilePurpose = ChargingProfilePurposeType::TxProfile; + const int connector_id = 0; + bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, + max_charging_profiles_installed, charging_schedule_max_periods, + charging_schedule_allowed_charging_rate_units); + + ASSERT_FALSE(sut); +} + +} // namespace v16 +} // namespace ocpp \ No newline at end of file From 30581b6332d2ead67c68fc54cdfcb602af013043 Mon Sep 17 00:00:00 2001 From: Christoph <367712+folkengine@users.noreply.github.com> Date: Wed, 24 Jan 2024 07:52:31 -0800 Subject: [PATCH 2/6] Cleaned up test names Signed-off-by: Christoph <367712+folkengine@users.noreply.github.com> --- tests/lib/ocpp/v16/test_smart_charging_handler.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/lib/ocpp/v16/test_smart_charging_handler.cpp b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp index d4c0b93df..8694df5fa 100644 --- a/tests/lib/ocpp/v16/test_smart_charging_handler.cpp +++ b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp @@ -22,7 +22,8 @@ namespace v16 { * - PB03 Valid Profile No startSchedule & handler allows no startSchedule & profile.chargingProfileKind == Relative * - PB04 Absolute ChargePointMaxProfile Profile with connector id 0 * - PB05 Absolute TxDefaultProfile - * - PB06 Absolute TxProfile && connector transaction != nullptr && transaction_id matches SKIPPED: was not able to test + * - PB06 Absolute TxProfile ignore_no_transaction == true + * - PB07 Absolute TxProfile && connector transaction != nullptr && transaction_id matches SKIPPED: was not able to test * * Negative Boundary Conditions: * - NB01 Valid Profile, ConnectorID gt this->connectors.size() @@ -169,6 +170,8 @@ class ChargepointTestFixture : public testing::Test { /** * PB01 Valid Profile + * + * Happy path simple test */ TEST_F(ChargepointTestFixture, ValidateProfile) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); @@ -417,7 +420,7 @@ TEST_F(ChargepointTestFixture, ValidateProfile__RecurringNoStartScheduleNotAllow * * Absolute ChargePointMaxProfile Profile need a connector id of 0 */ -TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NotRecurrencyKindConnectorId0__ReturnsFalse) { +TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NotRecurrencyKindConnectorId0__ReturnsTrue) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; auto handler = createSmartChargingHandler(); @@ -471,7 +474,7 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfileTxDefaultProfile__Re } /** - * PB05 Absolute TxProfile ignore_no_transaction == true + * PB06 Absolute TxProfile ignore_no_transaction == true */ TEST_F(ChargepointTestFixture, ValidateProfile__AbsoluteTxProfileIgnoreNoTransaction__ReturnsTrue) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); From e2623ca0c0c1ba936e812ef6c1a047260b2c4f64 Mon Sep 17 00:00:00 2001 From: Christoph <367712+folkengine@users.noreply.github.com> Date: Wed, 24 Jan 2024 07:58:57 -0800 Subject: [PATCH 3/6] Cleaned up tests/CMakeLists.txt Signed-off-by: Christoph <367712+folkengine@users.noreply.github.com> --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d27fcefa1..cba7f4f30 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,7 @@ target_link_libraries(libocpp_unit_tests PRIVATE target_sources(libocpp_unit_tests PRIVATE comparators.cpp) - add_subdirectory(lib/ocpp/v16) +add_subdirectory(lib/ocpp/v16) add_subdirectory(lib/ocpp/v201) add_subdirectory(lib/ocpp/common) From 16e8676ac8dff5c509f2c3be0f058a55598d40cc Mon Sep 17 00:00:00 2001 From: Coury Richards <146002925+couryrr-afs@users.noreply.github.com> Date: Wed, 24 Jan 2024 12:32:55 -0500 Subject: [PATCH 4/6] Inital commit with database_handler_mock Signed-off-by: Coury Richards <146002925+couryrr-afs@users.noreply.github.com> --- include/ocpp/v16/database_handler.hpp | 4 +- tests/database_handler_mock.hpp | 8 +- .../ocpp/v16/test_smart_charging_handler.cpp | 215 +++++++++++------- 3 files changed, 142 insertions(+), 85 deletions(-) diff --git a/include/ocpp/v16/database_handler.hpp b/include/ocpp/v16/database_handler.hpp index 70cba7e64..db3cbc0f3 100644 --- a/include/ocpp/v16/database_handler.hpp +++ b/include/ocpp/v16/database_handler.hpp @@ -135,10 +135,10 @@ class DatabaseHandler : public ocpp::common::DatabaseHandlerBase { bool clear_local_authorization_list(); /// \brief Inserts or updates the given \p profile to CHARGING_PROFILES table - void insert_or_update_charging_profile(const int connector_id, const v16::ChargingProfile& profile); + virtual void insert_or_update_charging_profile(const int connector_id, const v16::ChargingProfile& profile); /// \brief Deletes the profile with the given \p profile_id - void delete_charging_profile(const int profile_id); + virtual void delete_charging_profile(const int profile_id); /// \brief Deletes all profiles from table CHARGING_PROFILES void delete_charging_profiles(); diff --git a/tests/database_handler_mock.hpp b/tests/database_handler_mock.hpp index f8a873358..8d7039968 100644 --- a/tests/database_handler_mock.hpp +++ b/tests/database_handler_mock.hpp @@ -10,9 +10,13 @@ namespace ocpp { -class DatabaseHandlerMock : public DatabaseHandler { +class DatabaseHandlerMock : public v16::DatabaseHandler { public: - + DatabaseHandlerMock(const std::string& chargepoint_id, const fs::path& database_path, + const fs::path& init_script_path) : + DatabaseHandler(chargepoint_id, database_path, init_script_path){}; + MOCK_METHOD(void, insert_or_update_charging_profile, (const int, const v16::ChargingProfile&), (override)); + MOCK_METHOD(void, delete_charging_profile, (const int profile_id), (override)); }; } // namespace ocpp diff --git a/tests/lib/ocpp/v16/test_smart_charging_handler.cpp b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp index 8694df5fa..3d73f4766 100644 --- a/tests/lib/ocpp/v16/test_smart_charging_handler.cpp +++ b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp @@ -3,28 +3,30 @@ #include namespace fs = std::filesystem; +#include #include #include #include #include + namespace ocpp { namespace v16 { /** - * Chargepoint Test Fixture + * Chargepoint Test Fixture * * Test Matrix: - * + * * Positive Boundary Conditions: * - PB01 Valid Profile * - PB02 Valid Profile No startSchedule & handler allows no startSchedule & profile.chargingProfileKind == Absolute * - PB03 Valid Profile No startSchedule & handler allows no startSchedule & profile.chargingProfileKind == Relative * - PB04 Absolute ChargePointMaxProfile Profile with connector id 0 - * - PB05 Absolute TxDefaultProfile + * - PB05 Absolute TxDefaultProfile * - PB06 Absolute TxProfile ignore_no_transaction == true * - PB07 Absolute TxProfile && connector transaction != nullptr && transaction_id matches SKIPPED: was not able to test - * + * * Negative Boundary Conditions: * - NB01 Valid Profile, ConnectorID gt this->connectors.size() * - NB02 Valid Profile, ConnectorID lt 0 @@ -37,7 +39,7 @@ namespace v16 { * - NB09 profile.chargingProfileKind == Recurring && !startSchedule * - NB10 profile.chargingProfileKind == Recurring && !startSchedule && !allow_charging_profile_without_start_schedule * - NB11 Absolute ChargePointMaxProfile Profile with connector id not 0 - * - NB12 Absolute TxProfile connector_id == 0 + * - NB12 Absolute TxProfile connector_id == 0 */ class ChargepointTestFixture : public testing::Test { protected: @@ -69,16 +71,16 @@ class ChargepointTestFixture : public testing::Test { chargingProfilePurpose, chargingProfileKind, chargingSchedule, - {}, // transactionId + {}, // transactionId recurrencyKind, - {}, // validFrom - {} // validTo + {}, // validFrom + {} // validTo }; } /** * TxDefaultProfile, stack #1: time-of-day limitation to 2 kW, recurring every day from 17:00h to 20:00h. - * + * * This profile is Example #1 taken from the OCPP 2.0.1 Spec Part 2, page 241. */ ChargingProfile createChargingProfile_Example1() { @@ -87,13 +89,8 @@ class ChargepointTestFixture : public testing::Test { auto duration = 1080; auto startSchedule = ocpp::DateTime("2024-01-17T17:00:00"); float minChargingRate = 0; - auto chargingSchedule = ChargingSchedule{ - chargingRateUnit, - chargingSchedulePeriod, - duration, - startSchedule, - minChargingRate - }; + auto chargingSchedule = + ChargingSchedule{chargingRateUnit, chargingSchedulePeriod, duration, startSchedule, minChargingRate}; auto chargingProfileId = 1; auto stackLevel = 1; @@ -106,16 +103,16 @@ class ChargepointTestFixture : public testing::Test { chargingProfilePurpose, chargingProfileKind, chargingSchedule, - {}, // transactionId + {}, // transactionId recurrencyKind, - {}, // validFrom - {} // validTo + {}, // validFrom + {} // validTo }; } /** * TxDefaultProfile, stack #2: overruling Sundays to no limit, recurring every week starting 2020-01-05. - * + * * This profile is Example #2 taken from the OCPP 2.0.1 Spec Part 2, page 241. */ ChargingProfile createChargingProfile_Example2() { @@ -124,36 +121,37 @@ class ChargepointTestFixture : public testing::Test { auto duration = 0; auto startSchedule = ocpp::DateTime("2020-01-19T00:00:00"); float minChargingRate = 0; - auto chargingSchedule = ChargingSchedule{ - chargingRateUnit, - chargingSchedulePeriod, - duration, - startSchedule, - minChargingRate - }; + auto chargingSchedule = + ChargingSchedule{chargingRateUnit, chargingSchedulePeriod, duration, startSchedule, minChargingRate}; auto chargingProfileId = 11; auto stackLevel = 2; auto chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile; auto chargingProfileKind = ChargingProfileKindType::Recurring; auto recurrencyKind = RecurrencyKindType::Weekly; - return ChargingProfile{ - chargingProfileId, - stackLevel, - chargingProfilePurpose, - chargingProfileKind, - chargingSchedule, - {}, // transactionId - recurrencyKind, - {}, - {} - }; + return ChargingProfile{chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + {}, + {}}; } SmartChargingHandler* createSmartChargingHandler() { - auto c1 = std::make_shared(Connector{1}); - connectors[1] = c1; + connectors[0] = std::make_shared(Connector{1}); + + const std::string chargepoint_id = "1"; + const fs::path database_path = "na"; + const fs::path init_script_path = "na"; + + std::shared_ptr database_handler = + std::make_shared(chargepoint_id, database_path, init_script_path); + auto handler = new SmartChargingHandler(connectors, database_handler, true); + return handler; } @@ -187,7 +185,7 @@ TEST_F(ChargepointTestFixture, ValidateProfile) { /** * PB01 Valid Profile: Example 1 - * + * * This example is taken from the OCPP 2.0.1 Spec page. 241 */ TEST_F(ChargepointTestFixture, ValidateProfile__example1) { @@ -225,7 +223,7 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NegativeConnectorId auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; auto handler = createSmartChargingHandler(); - + const int connector_id = -1; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, max_charging_profiles_installed, charging_schedule_max_periods, @@ -267,8 +265,8 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_StackLevelGreaterTh } /** - * NB05 profile.chargingProfileKind == Absolute && !profile.chargingSchedule.startSchedule -*/ + * NB05 profile.chargingProfileKind == Absolute && !profile.chargingSchedule.startSchedule + */ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ChargingProfileKindAbsoluteNoStartSchedule__ReturnsFalse) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; @@ -276,20 +274,21 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ChargingProfileKind auto c1 = std::make_shared(Connector{1}); connectors[1] = c1; auto allow_charging_profile_without_start_schedule = false; - auto handler = new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); + auto handler = + new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); profile.chargingProfileKind = ChargingProfileKindType::Absolute; profile.chargingSchedule.startSchedule = std::nullopt; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_FALSE(sut); } /** * PB02 Valid Profile No startSchedule & handler allows no startSchedule -*/ + */ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_AllowsNoStartSchedule__ReturnsTrue) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; @@ -302,14 +301,15 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_AllowsNoStartSchedu bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_TRUE(sut); } /** * NB06 Number of installed Profiles is > max_charging_profiles_installed */ -TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_InstalledProfilesGreaterThanMaxInstalledProfiles__ReturnsFalse) { +TEST_F(ChargepointTestFixture, + ValidateProfile__ValidProfile_InstalledProfilesGreaterThanMaxInstalledProfiles__ReturnsFalse) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; auto handler = createSmartChargingHandler(); @@ -318,13 +318,13 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_InstalledProfilesGr bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_FALSE(sut); } /** * NB07 Invalid ChargingSchedule - * + * * Creating a ChargingProfile with a different ChargingRateUnit */ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_InvalidChargingSchedule__ReturnsFalse) { @@ -334,16 +334,17 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_InvalidChargingSche const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::W}; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_FALSE(sut); } /** - * NB08 profile.chargingProfileKind == Recurring && !profile.recurrencyKind + * NB08 profile.chargingProfileKind == Recurring && !profile.recurrencyKind */ -TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ChargingProfileKindRecurringNoRecurrencyKind__ReturnsFalse) { +TEST_F(ChargepointTestFixture, + ValidateProfile__ValidProfile_ChargingProfileKindRecurringNoRecurrencyKind__ReturnsFalse) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; auto handler = createSmartChargingHandler(); @@ -351,30 +352,32 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ChargingProfileKind profile.chargingProfileKind = ChargingProfileKindType::Recurring; profile.recurrencyKind = std::nullopt; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_FALSE(sut); } /** * NB09 profile.chargingProfileKind == Recurring && !profile.chargingSchedule.startSchedule */ -TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ChargingProfileKindRecurringNoStartSchedule__ReturnsFalse) { +TEST_F(ChargepointTestFixture, + ValidateProfile__ValidProfile_ChargingProfileKindRecurringNoStartSchedule__ReturnsFalse) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; // Create a SmartChargingHandler where allow_charging_profile_without_start_schedule is set to false auto c1 = std::make_shared(Connector{1}); connectors[1] = c1; auto allow_charging_profile_without_start_schedule = false; - auto handler = new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); + auto handler = + new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); profile.chargingProfileKind = ChargingProfileKindType::Recurring; profile.chargingSchedule.startSchedule = std::nullopt; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_FALSE(sut); } @@ -389,9 +392,9 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NoStartScheduleAllo profile.chargingProfileKind = ChargingProfileKindType::Recurring; profile.chargingSchedule.startSchedule = std::nullopt; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_TRUE(sut); } @@ -404,20 +407,21 @@ TEST_F(ChargepointTestFixture, ValidateProfile__RecurringNoStartScheduleNotAllow auto c1 = std::make_shared(Connector{1}); connectors[1] = c1; auto allow_charging_profile_without_start_schedule = false; - auto handler = new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); + auto handler = + new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); profile.chargingProfileKind = ChargingProfileKindType::Recurring; profile.chargingSchedule.startSchedule = std::nullopt; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_FALSE(sut); } /** * PB04 Absolute ChargePointMaxProfile Profile with connector id 0 - * + * * Absolute ChargePointMaxProfile Profile need a connector id of 0 */ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NotRecurrencyKindConnectorId0__ReturnsTrue) { @@ -429,16 +433,16 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NotRecurrencyKindCo profile.chargingProfileKind = ChargingProfileKindType::Absolute; const int connector_id = 0; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_TRUE(sut); } /** * NB11 Absolute ChargePointMaxProfile Profile with connector id not 0 - * - * ChargePointMaxProfile Profiles where chargingProfileKind == Absolute need a connector id of 0 and not had a + * + * ChargePointMaxProfile Profiles where chargingProfileKind == Absolute need a connector id of 0 and not had a * ChargingProfileKindType of Relative */ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NotRecurrencyKindConnectorIdNot0__ReturnsFalse) { @@ -450,14 +454,14 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NotRecurrencyKindCo profile.chargingProfileKind = ChargingProfileKindType::Absolute; const int connector_id = 1; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_FALSE(sut); } /** - * PB05 Absolute TxDefaultProfile + * PB05 Absolute TxDefaultProfile */ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfileTxDefaultProfile__ReturnsTrue) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); @@ -467,9 +471,9 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfileTxDefaultProfile__Re profile.chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile; profile.chargingProfileKind = ChargingProfileKindType::Absolute; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_TRUE(sut); } @@ -484,29 +488,78 @@ TEST_F(ChargepointTestFixture, ValidateProfile__AbsoluteTxProfileIgnoreNoTransac profile.chargingProfilePurpose = ChargingProfilePurposeType::TxProfile; profile.chargingProfileKind = ChargingProfileKindType::Absolute; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); - + ASSERT_TRUE(sut); } /** - * NB12 Absolute TxProfile connector_id == 0 + * NB12 Absolute TxProfile connector_id == 0 */ TEST_F(ChargepointTestFixture, ValidateProfile__AbsoluteTxProfileConnectorId0__ReturnsFalse) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; auto handler = createSmartChargingHandler(); - + profile.chargingProfileKind = ChargingProfileKindType::Absolute; profile.chargingProfilePurpose = ChargingProfilePurposeType::TxProfile; const int connector_id = 0; bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, - max_charging_profiles_installed, charging_schedule_max_periods, + max_charging_profiles_installed, charging_schedule_max_periods, charging_schedule_allowed_charging_rate_units); ASSERT_FALSE(sut); } +/** + * + * 2. Testing the branches within clear_all_profiles_with_filter ClearAllProfilesWithFilter + * + */ + +/** + * NB + */ +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__AllOptionalsEmpty_DoNotCheckIdOnly__ReturnsFalse) { + auto handler = createSmartChargingHandler(); + + bool sut = handler->clear_all_profiles_with_filter({}, {}, {}, {}, false); + + ASSERT_FALSE(sut); +} + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__AllOptionalsEmpty_CheckIdOnly__ReturnsFalse) { + auto handler = createSmartChargingHandler(); + + bool sut = handler->clear_all_profiles_with_filter({}, {}, {}, {}, true); + + ASSERT_FALSE(sut); +} + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__OnlyOneMatchingProfileId_CheckIdOnly__ReturnsTrue) { + + auto handler = createSmartChargingHandler(); + + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + + handler->add_charge_point_max_profile(profile); + + bool sut = handler->clear_all_profiles_with_filter(1, {}, {}, {}, true); + + ASSERT_TRUE(sut); +} + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__NoMatchingProfileId_CheckIdOnly__ReturnsFalse) { + auto handler = createSmartChargingHandler(); + + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + + handler->add_charge_point_max_profile(profile); + + bool sut = handler->clear_all_profiles_with_filter(2, {}, {}, {}, true); + + ASSERT_FALSE(sut); +} } // namespace v16 } // namespace ocpp \ No newline at end of file From b5d66d470d4e9e13cc5282a01821e27a533d28d9 Mon Sep 17 00:00:00 2001 From: Coury Richards <146002925+couryrr-afs@users.noreply.github.com> Date: Mon, 26 Feb 2024 13:34:43 -0500 Subject: [PATCH 5/6] Recommitting full work Signed-off-by: Coury Richards <146002925+couryrr-afs@users.noreply.github.com> --- .ci/build-kit/install_and_test.sh | 5 +- .../ocpp/v16/test_smart_charging_handler.cpp | 602 +++++++++++++++++- 2 files changed, 580 insertions(+), 27 deletions(-) diff --git a/.ci/build-kit/install_and_test.sh b/.ci/build-kit/install_and_test.sh index 140ee13b0..e06c39c69 100755 --- a/.ci/build-kit/install_and_test.sh +++ b/.ci/build-kit/install_and_test.sh @@ -8,10 +8,13 @@ cmake \ -G Ninja \ -DBUILD_TESTING=ON \ -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_INSTALL_PREFIX="$WORKSPACE_PATH/dist" + -DCMAKE_INSTALL_PREFIX="$WORKSPACE_PATH/dist" \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ninja -j$(nproc) -C build install trap "cp build/Testing/Temporary/LastTest.log /ext/ctest-report" EXIT ninja -j$(nproc) -C build test + +# cmake -B build -G Ninja -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="./dist" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ No newline at end of file diff --git a/tests/lib/ocpp/v16/test_smart_charging_handler.cpp b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp index 3d73f4766..47b38e35f 100644 --- a/tests/lib/ocpp/v16/test_smart_charging_handler.cpp +++ b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace fs = std::filesystem; #include @@ -9,7 +10,6 @@ namespace fs = std::filesystem; #include #include - namespace ocpp { namespace v16 { @@ -46,6 +46,16 @@ class ChargepointTestFixture : public testing::Test { void SetUp() override { } + void addConnector(int id) { + auto connector = Connector{id}; + + auto timer = std::unique_ptr(); + + connector.transaction = + std::make_shared(id, "test", "test", 1, std::nullopt, ocpp::DateTime(), std::move(timer)); + connectors[id] = std::make_shared(connector); + } + ChargingSchedule createChargeSchedule() { return ChargingSchedule{{}}; } @@ -59,6 +69,25 @@ class ChargepointTestFixture : public testing::Test { return ChargingSchedule{chargingRateUnit, chargingSchedulePeriod, duration, startSchedule, minChargingRate}; } + ChargingProfile createMaxChargingProfile(ChargingSchedule chargingSchedule) { + auto chargingProfileId = 1; + auto stackLevel = 1; + auto chargingProfilePurpose = ChargingProfilePurposeType::ChargePointMaxProfile; + auto chargingProfileKind = ChargingProfileKindType::Absolute; + auto recurrencyKind = RecurrencyKindType::Daily; + return ChargingProfile{ + chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + {}, // validFrom + {} // validTo + }; + } + ChargingProfile createChargingProfile(ChargingSchedule chargingSchedule) { auto chargingProfileId = 1; auto stackLevel = 1; @@ -78,6 +107,41 @@ class ChargepointTestFixture : public testing::Test { }; } + ChargingProfile createTxChargingProfile(ChargingSchedule chargingSchedule) { + auto chargingProfileId = 1; + auto stackLevel = 1; + auto chargingProfilePurpose = ChargingProfilePurposeType::TxProfile; + auto chargingProfileKind = ChargingProfileKindType::Absolute; + auto recurrencyKind = RecurrencyKindType::Daily; + return ChargingProfile{ + chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + {}, // validFrom + {} // validTo + }; + } + + ChargingProfile createChargingProfile(int id, int stackLevel, ChargingProfilePurposeType chargingProfilePurpose, + ChargingProfileKindType chargingProfileKind, + RecurrencyKindType recurrencyKind, ChargingSchedule chargingSchedule) { + return ChargingProfile{ + id, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + {}, // validFrom + {} // validTo + }; + } + /** * TxDefaultProfile, stack #1: time-of-day limitation to 2 kW, recurring every day from 17:00h to 20:00h. * @@ -141,17 +205,12 @@ class ChargepointTestFixture : public testing::Test { } SmartChargingHandler* createSmartChargingHandler() { - connectors[0] = std::make_shared(Connector{1}); - const std::string chargepoint_id = "1"; const fs::path database_path = "na"; const fs::path init_script_path = "na"; - std::shared_ptr database_handler = std::make_shared(chargepoint_id, database_path, init_script_path); - auto handler = new SmartChargingHandler(connectors, database_handler, true); - return handler; } @@ -174,6 +233,8 @@ class ChargepointTestFixture : public testing::Test { TEST_F(ChargepointTestFixture, ValidateProfile) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + + addConnector(1); auto handler = createSmartChargingHandler(); bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, @@ -191,6 +252,8 @@ TEST_F(ChargepointTestFixture, ValidateProfile) { TEST_F(ChargepointTestFixture, ValidateProfile__example1) { auto profile = createChargingProfile_Example1(); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::W}; + + addConnector(1); auto handler = createSmartChargingHandler(); bool sut = handler->validate_profile(profile, connector_id, ignore_no_transaction, profile_max_stack_level, @@ -271,8 +334,7 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_ChargingProfileKind auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; // Create a SmartChargingHandler where allow_charging_profile_without_start_schedule is set to false - auto c1 = std::make_shared(Connector{1}); - connectors[1] = c1; + addConnector(1); auto allow_charging_profile_without_start_schedule = false; auto handler = new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); @@ -293,6 +355,7 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_AllowsNoStartSchedu auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; // Create a SmartChargingHandler where allow_charging_profile_without_start_schedule is set to false + addConnector(1); auto handler = createSmartChargingHandler(); // Configure to have no start schedule @@ -366,8 +429,7 @@ TEST_F(ChargepointTestFixture, auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; // Create a SmartChargingHandler where allow_charging_profile_without_start_schedule is set to false - auto c1 = std::make_shared(Connector{1}); - connectors[1] = c1; + addConnector(1); auto allow_charging_profile_without_start_schedule = false; auto handler = new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); @@ -387,6 +449,8 @@ TEST_F(ChargepointTestFixture, TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NoStartScheduleAllowedRelative__ReturnsTrue) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + + addConnector(1); auto handler = createSmartChargingHandler(); profile.chargingProfileKind = ChargingProfileKindType::Recurring; @@ -404,8 +468,8 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NoStartScheduleAllo TEST_F(ChargepointTestFixture, ValidateProfile__RecurringNoStartScheduleNotAllowed__ReturnsFalse) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; - auto c1 = std::make_shared(Connector{1}); - connectors[1] = c1; + + addConnector(1); auto allow_charging_profile_without_start_schedule = false; auto handler = new SmartChargingHandler(connectors, database_handler, allow_charging_profile_without_start_schedule); @@ -466,6 +530,8 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfile_NotRecurrencyKindCo TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfileTxDefaultProfile__ReturnsTrue) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + + addConnector(1); auto handler = createSmartChargingHandler(); profile.chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile; @@ -483,6 +549,8 @@ TEST_F(ChargepointTestFixture, ValidateProfile__ValidProfileTxDefaultProfile__Re TEST_F(ChargepointTestFixture, ValidateProfile__AbsoluteTxProfileIgnoreNoTransaction__ReturnsTrue) { auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); const std::vector& charging_schedule_allowed_charging_rate_units{ChargingRateUnit::A}; + + addConnector(1); auto handler = createSmartChargingHandler(); profile.chargingProfilePurpose = ChargingProfilePurposeType::TxProfile; @@ -513,53 +581,535 @@ TEST_F(ChargepointTestFixture, ValidateProfile__AbsoluteTxProfileConnectorId0__R } /** * - * 2. Testing the branches within clear_all_profiles_with_filter ClearAllProfilesWithFilter + * 2. Testing the branches within ClearAllProfilesWithFilter * */ -/** - * NB - */ -TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__AllOptionalsEmpty_DoNotCheckIdOnly__ReturnsFalse) { +// FIXME: Should this be ignored. There are no filter parameters. +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__AllOptionalsEmpty__ReturnsFalse) { + GTEST_SKIP() << "No parameter filter is clearing all profiles"; + + const int connector_id_1 = 1; + addConnector(connector_id_1); + + const int connector_id_2 = 2; + addConnector(connector_id_2); + auto handler = createSmartChargingHandler(); - bool sut = handler->clear_all_profiles_with_filter({}, {}, {}, {}, false); + auto profile_1 = + createChargingProfile(1, 1, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); - ASSERT_FALSE(sut); + auto profile_2 = + createChargingProfile(2, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_profile(profile_1, connector_id_1); + handler->add_tx_profile(profile_2, connector_id_2); + + auto profiles_1 = handler->get_valid_profiles({}, {}, connector_id_1); + auto profiles_2 = handler->get_valid_profiles({}, {}, connector_id_2); + ASSERT_EQ(1, profiles_1.size()); + ASSERT_EQ(1, profiles_2.size()); + + // All empty tokens + bool sut = handler->clear_all_profiles_with_filter(std::nullopt, std::nullopt, std::nullopt, std::nullopt, false); + + profiles_1 = handler->get_valid_profiles({}, {}, connector_id_1); + profiles_2 = handler->get_valid_profiles({}, {}, connector_id_2); + ASSERT_EQ(0, profiles_1.size()); + ASSERT_EQ(0, profiles_2.size()); + + ASSERT_TRUE(sut); } TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__AllOptionalsEmpty_CheckIdOnly__ReturnsFalse) { + const int connector_id = 1; + addConnector(connector_id); + auto handler = createSmartChargingHandler(); - bool sut = handler->clear_all_profiles_with_filter({}, {}, {}, {}, true); + auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_profile(profile, connector_id); + + // All empty tokens + bool sut = handler->clear_all_profiles_with_filter(std::nullopt, std::nullopt, std::nullopt, std::nullopt, true); + + ASSERT_FALSE(sut); +} + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__NoProfiles_ProfileId_CheckIdOnly__ReturnsFalse) { + auto handler = createSmartChargingHandler(); + + bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); ASSERT_FALSE(sut); } -TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__OnlyOneMatchingProfileId_CheckIdOnly__ReturnsTrue) { +/** + * There is an issue open https://github.com/EVerest/libocpp/issues/432 for the below clear_all_profiles_with_filter + * The current method call will allow for all parameters to be passed in at a single time and then act on all of them. + * The issue is that a call should either have a profile id and delete that specific profile or any combination of the + * other three to delete n number of profiles (to a single one if given all three). + * The logic is exclusionary but the method does not guard against it which can put the system in an odd state. + */ + +// 0, 1 and many connectors + +// max, default, tx profiles + +// profile id only +// or +// connector id only + +// stacklevel only + +// charging profile purpose only + +// a mix of them all + +// Max + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Max_OnlyOneMatchingProfileId_CheckIdOnly__ReturnsTrue) { + const int connector_id = 0; auto handler = createSmartChargingHandler(); - auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + auto profile = createMaxChargingProfile(createChargeSchedule(ChargingRateUnit::A)); handler->add_charge_point_max_profile(profile); - bool sut = handler->clear_all_profiles_with_filter(1, {}, {}, {}, true); + auto profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(1, profiles.size()); + + bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); + profiles = handler->get_valid_profiles({}, {}, connector_id); + ASSERT_EQ(0, profiles.size()); + + ASSERT_TRUE(sut); +} + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Max_MatchingProfileId_CheckIdOnly__ReturnsTrue) { + const int connector_id = 0; + + auto handler = createSmartChargingHandler(); + + auto profile_1 = createChargingProfile(1, 1, ChargingProfilePurposeType::ChargePointMaxProfile, + ChargingProfileKindType::Absolute, RecurrencyKindType::Daily, + createChargeSchedule(ChargingRateUnit::A)); + + auto profile_2 = createChargingProfile(2, 2, ChargingProfilePurposeType::ChargePointMaxProfile, + ChargingProfileKindType::Absolute, RecurrencyKindType::Daily, + createChargeSchedule(ChargingRateUnit::A)); + + handler->add_charge_point_max_profile(profile_1); + handler->add_charge_point_max_profile(profile_2); + + auto profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(2, profiles.size()); + + bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); + profiles = handler->get_valid_profiles({}, {}, connector_id); + ASSERT_EQ(1, profiles.size()); ASSERT_TRUE(sut); } -TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__NoMatchingProfileId_CheckIdOnly__ReturnsFalse) { +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Max_MultipleNoMatchingProfileId_CheckIdOnly__ReturnsFalse) { + const int connector_id = 0; + + auto handler = createSmartChargingHandler(); + + auto profile_1 = createChargingProfile(1, 1, ChargingProfilePurposeType::ChargePointMaxProfile, + ChargingProfileKindType::Absolute, RecurrencyKindType::Daily, + createChargeSchedule(ChargingRateUnit::A)); + + auto profile_2 = createChargingProfile(2, 2, ChargingProfilePurposeType::ChargePointMaxProfile, + ChargingProfileKindType::Absolute, RecurrencyKindType::Daily, + createChargeSchedule(ChargingRateUnit::A)); + + handler->add_charge_point_max_profile(profile_1); + handler->add_charge_point_max_profile(profile_2); + + auto profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(2, profiles.size()); + + bool sut = handler->clear_all_profiles_with_filter(3, std::nullopt, std::nullopt, std::nullopt, true); + profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(2, profiles.size()); + ASSERT_FALSE(sut); +} + +// Default + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Default_OnlyOneMatchingProfileId_CheckIdOnly__ReturnsTrue) { + const int connector_id = 1; + addConnector(connector_id); + auto handler = createSmartChargingHandler(); auto profile = createChargingProfile(createChargeSchedule(ChargingRateUnit::A)); - handler->add_charge_point_max_profile(profile); + handler->add_tx_default_profile(profile, connector_id); + + auto profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(1, profiles.size()); + + bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); + profiles = handler->get_valid_profiles({}, {}, connector_id); + ASSERT_EQ(0, profiles.size()); + + ASSERT_TRUE(sut); +} + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Default_MatchingProfileId_CheckIdOnly__ReturnsTrue) { + const int connector_id = 1; + addConnector(connector_id); - bool sut = handler->clear_all_profiles_with_filter(2, {}, {}, {}, true); + auto handler = createSmartChargingHandler(); + + auto profile_1 = + createChargingProfile(1, 1, ChargingProfilePurposeType::TxDefaultProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_2 = + createChargingProfile(2, 2, ChargingProfilePurposeType::TxDefaultProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_default_profile(profile_1, connector_id); + handler->add_tx_default_profile(profile_2, connector_id); + + auto profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(2, profiles.size()); + + bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); + profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(1, profiles.size()); + ASSERT_TRUE(sut); +} + +TEST_F(ChargepointTestFixture, + ClearAllProfilesWithFilter__Default_MultipleNoMatchingProfileId_CheckIdOnly__ReturnsFalse) { + const int connector_id = 1; + addConnector(connector_id); + + auto handler = createSmartChargingHandler(); + + auto profile_1 = + createChargingProfile(1, 1, ChargingProfilePurposeType::TxDefaultProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_2 = + createChargingProfile(2, 2, ChargingProfilePurposeType::TxDefaultProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_default_profile(profile_1, connector_id); + handler->add_tx_default_profile(profile_2, connector_id); + + auto profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(2, profiles.size()); + + bool sut = handler->clear_all_profiles_with_filter(3, std::nullopt, std::nullopt, std::nullopt, true); + profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(2, profiles.size()); + ASSERT_FALSE(sut); +} + +// TX + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Tx_OnlyOneMatchingProfileId_CheckIdOnly__ReturnsTrue) { + const int connector_id = 1; + addConnector(connector_id); + + auto handler = createSmartChargingHandler(); + + auto profile = createTxChargingProfile(createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_profile(profile, connector_id); + + auto profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(1, profiles.size()); + + bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); + profiles = handler->get_valid_profiles({}, {}, connector_id); + ASSERT_EQ(0, profiles.size()); + ASSERT_TRUE(sut); +} + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Tx_MatchingProfileId_CheckIdOnly__ReturnsTrue) { + const int connector_id = 1; + addConnector(connector_id); + + auto handler = createSmartChargingHandler(); + + auto profile_1 = + createChargingProfile(1, 1, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_2 = + createChargingProfile(2, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_profile(profile_1, connector_id); + handler->add_tx_profile(profile_2, connector_id); + + auto profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(2, profiles.size()); + + bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); + profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(1, profiles.size()); + ASSERT_TRUE(sut); +} + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Tx_MultipleNoMatchingProfileId_CheckIdOnly__ReturnsFalse) { + const int connector_id = 1; + addConnector(connector_id); + + auto handler = createSmartChargingHandler(); + + auto profile_1 = + createChargingProfile(1, 1, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_2 = + createChargingProfile(2, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_profile(profile_1, connector_id); + handler->add_tx_profile(profile_2, connector_id); + + auto profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(2, profiles.size()); + + bool sut = handler->clear_all_profiles_with_filter(3, std::nullopt, std::nullopt, std::nullopt, true); + profiles = handler->get_valid_profiles({}, {}, connector_id); + + ASSERT_EQ(2, profiles.size()); ASSERT_FALSE(sut); } +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__ConnectorId__ReturnsTrue) { + const int connector_id_1 = 100; + addConnector(connector_id_1); + + const int connector_id_2 = 200; + addConnector(connector_id_2); + + auto handler = createSmartChargingHandler(); + + auto profile_c1_1 = + createChargingProfile(1, 1, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c1_2 = + createChargingProfile(2, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c2_3 = + createChargingProfile(3, 1, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c2_4 = + createChargingProfile(4, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_profile(profile_c1_1, connector_id_1); + handler->add_tx_profile(profile_c1_2, connector_id_1); + + handler->add_tx_profile(profile_c2_3, connector_id_2); + handler->add_tx_profile(profile_c2_4, connector_id_2); + + auto connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); + auto connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + + ASSERT_EQ(2, connector_id_1_profiles.size()); + ASSERT_EQ(2, connector_id_2_profiles.size()); + + auto check_id_only = false; + + bool sut = handler->clear_all_profiles_with_filter(std::nullopt, connector_id_1, std::nullopt, std::nullopt, + check_id_only); + + connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); + connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + + ASSERT_EQ(0, connector_id_1_profiles.size()); + ASSERT_EQ(2, connector_id_2_profiles.size()); + ASSERT_TRUE(sut); +} + +// TODO: Needs negative + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__StackLevel__ReturnsTrue) { + const int connector_id_1 = 100; + addConnector(connector_id_1); + + const int connector_id_2 = 200; + addConnector(connector_id_2); + + auto handler = createSmartChargingHandler(); + + auto profile_c1_1 = + createChargingProfile(1, 1, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c1_2 = + createChargingProfile(2, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c2_3 = + createChargingProfile(3, 1, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c2_4 = + createChargingProfile(4, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_profile(profile_c1_1, connector_id_1); + handler->add_tx_profile(profile_c1_2, connector_id_1); + + handler->add_tx_profile(profile_c2_3, connector_id_2); + handler->add_tx_profile(profile_c2_4, connector_id_2); + + auto connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); + auto connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + + ASSERT_EQ(2, connector_id_1_profiles.size()); + ASSERT_EQ(2, connector_id_2_profiles.size()); + + auto check_id_only = false; + + bool sut = handler->clear_all_profiles_with_filter(std::nullopt, std::nullopt, 1, std::nullopt, check_id_only); + + connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); + connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + + ASSERT_EQ(1, connector_id_1_profiles.size()); + ASSERT_EQ(1, connector_id_2_profiles.size()); + ASSERT_TRUE(sut); +} + +// TODO: Needs negative + +TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__ChargingProfilePurposeType__ReturnsTrue) { + const int connector_id_1 = 100; + addConnector(connector_id_1); + + const int connector_id_2 = 200; + addConnector(connector_id_2); + + auto handler = createSmartChargingHandler(); + + auto profile_c1_1 = + createChargingProfile(1, 1, ChargingProfilePurposeType::TxDefaultProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c1_2 = + createChargingProfile(2, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c2_3 = + createChargingProfile(3, 1, ChargingProfilePurposeType::TxDefaultProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c2_4 = + createChargingProfile(4, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_default_profile(profile_c1_1, connector_id_1); + handler->add_tx_profile(profile_c1_2, connector_id_1); + + handler->add_tx_default_profile(profile_c2_3, connector_id_2); + handler->add_tx_profile(profile_c2_4, connector_id_2); + + auto connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); + auto connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + + ASSERT_EQ(2, connector_id_1_profiles.size()); + ASSERT_EQ(2, connector_id_2_profiles.size()); + + auto check_id_only = false; + + bool sut = handler->clear_all_profiles_with_filter(std::nullopt, std::nullopt, std::nullopt, + ChargingProfilePurposeType::TxDefaultProfile, check_id_only); + + connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); + connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + + ASSERT_EQ(1, connector_id_1_profiles.size()); + ASSERT_EQ(1, connector_id_2_profiles.size()); + ASSERT_TRUE(sut); +} + +// TODO: Needs negative + +TEST_F(ChargepointTestFixture, + ClearAllProfilesWithFilter__ConnectorIdStackLevelChargingProfilePurposeType__ReturnsTrue) { + const int connector_id_1 = 100; + addConnector(connector_id_1); + + const int connector_id_2 = 200; + addConnector(connector_id_2); + + auto handler = createSmartChargingHandler(); + + auto profile_c1_1 = + createChargingProfile(1, 1, ChargingProfilePurposeType::TxDefaultProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c1_2 = + createChargingProfile(2, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c2_3 = + createChargingProfile(3, 1, ChargingProfilePurposeType::TxDefaultProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + auto profile_c2_4 = + createChargingProfile(4, 2, ChargingProfilePurposeType::TxProfile, ChargingProfileKindType::Absolute, + RecurrencyKindType::Daily, createChargeSchedule(ChargingRateUnit::A)); + + handler->add_tx_default_profile(profile_c1_1, connector_id_1); + handler->add_tx_profile(profile_c1_2, connector_id_1); + + handler->add_tx_default_profile(profile_c2_3, connector_id_2); + handler->add_tx_profile(profile_c2_4, connector_id_2); + + auto connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); + auto connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + + ASSERT_EQ(2, connector_id_1_profiles.size()); + ASSERT_EQ(2, connector_id_2_profiles.size()); + + auto check_id_only = false; + + bool sut = handler->clear_all_profiles_with_filter(std::nullopt, 100, 1, + ChargingProfilePurposeType::TxDefaultProfile, check_id_only); + + connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); + connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + + ASSERT_EQ(1, connector_id_1_profiles.size()); + ASSERT_EQ(2, connector_id_2_profiles.size()); + ASSERT_TRUE(sut); +} + } // namespace v16 } // namespace ocpp \ No newline at end of file From 540202046806508a10fe7c2886b2a06c66e7433e Mon Sep 17 00:00:00 2001 From: Coury Richards <146002925+couryrr-afs@users.noreply.github.com> Date: Tue, 27 Feb 2024 09:20:44 -0500 Subject: [PATCH 6/6] Updated date for tests Signed-off-by: Coury Richards <146002925+couryrr-afs@users.noreply.github.com> --- .../ocpp/v16/test_smart_charging_handler.cpp | 182 +++++++++--------- 1 file changed, 87 insertions(+), 95 deletions(-) diff --git a/tests/lib/ocpp/v16/test_smart_charging_handler.cpp b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp index 47b38e35f..f551cec62 100644 --- a/tests/lib/ocpp/v16/test_smart_charging_handler.cpp +++ b/tests/lib/ocpp/v16/test_smart_charging_handler.cpp @@ -75,17 +75,15 @@ class ChargepointTestFixture : public testing::Test { auto chargingProfilePurpose = ChargingProfilePurposeType::ChargePointMaxProfile; auto chargingProfileKind = ChargingProfileKindType::Absolute; auto recurrencyKind = RecurrencyKindType::Daily; - return ChargingProfile{ - chargingProfileId, - stackLevel, - chargingProfilePurpose, - chargingProfileKind, - chargingSchedule, - {}, // transactionId - recurrencyKind, - {}, // validFrom - {} // validTo - }; + return ChargingProfile{chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + ocpp::DateTime("2024-01-01T00:00:00"), + ocpp::DateTime("2024-03-19T00:00:00")}; } ChargingProfile createChargingProfile(ChargingSchedule chargingSchedule) { @@ -94,17 +92,15 @@ class ChargepointTestFixture : public testing::Test { auto chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile; auto chargingProfileKind = ChargingProfileKindType::Absolute; auto recurrencyKind = RecurrencyKindType::Daily; - return ChargingProfile{ - chargingProfileId, - stackLevel, - chargingProfilePurpose, - chargingProfileKind, - chargingSchedule, - {}, // transactionId - recurrencyKind, - {}, // validFrom - {} // validTo - }; + return ChargingProfile{chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + ocpp::DateTime("2024-01-01T00:00:00"), + ocpp::DateTime("2024-03-19T00:00:00")}; } ChargingProfile createTxChargingProfile(ChargingSchedule chargingSchedule) { @@ -113,33 +109,29 @@ class ChargepointTestFixture : public testing::Test { auto chargingProfilePurpose = ChargingProfilePurposeType::TxProfile; auto chargingProfileKind = ChargingProfileKindType::Absolute; auto recurrencyKind = RecurrencyKindType::Daily; - return ChargingProfile{ - chargingProfileId, - stackLevel, - chargingProfilePurpose, - chargingProfileKind, - chargingSchedule, - {}, // transactionId - recurrencyKind, - {}, // validFrom - {} // validTo - }; + return ChargingProfile{chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + ocpp::DateTime("2024-01-01T00:00:00"), + ocpp::DateTime("2024-03-19T00:00:00")}; } ChargingProfile createChargingProfile(int id, int stackLevel, ChargingProfilePurposeType chargingProfilePurpose, ChargingProfileKindType chargingProfileKind, RecurrencyKindType recurrencyKind, ChargingSchedule chargingSchedule) { - return ChargingProfile{ - id, - stackLevel, - chargingProfilePurpose, - chargingProfileKind, - chargingSchedule, - {}, // transactionId - recurrencyKind, - {}, // validFrom - {} // validTo - }; + return ChargingProfile{id, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + ocpp::DateTime("2024-01-01T00:00:00"), + ocpp::DateTime("2024-03-19T00:00:00")}; } /** @@ -161,17 +153,15 @@ class ChargepointTestFixture : public testing::Test { auto chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile; auto chargingProfileKind = ChargingProfileKindType::Absolute; auto recurrencyKind = RecurrencyKindType::Daily; - return ChargingProfile{ - chargingProfileId, - stackLevel, - chargingProfilePurpose, - chargingProfileKind, - chargingSchedule, - {}, // transactionId - recurrencyKind, - {}, // validFrom - {} // validTo - }; + return ChargingProfile{chargingProfileId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + chargingSchedule, + {}, // transactionId + recurrencyKind, + ocpp::DateTime("2024-01-01T00:00:00"), + ocpp::DateTime("2024-03-19T00:00:00")}; } /** @@ -200,8 +190,8 @@ class ChargepointTestFixture : public testing::Test { chargingSchedule, {}, // transactionId recurrencyKind, - {}, - {}}; + ocpp::DateTime("2024-01-01T00:00:00"), + ocpp::DateTime("2024-03-19T00:00:00")}; } SmartChargingHandler* createSmartChargingHandler() { @@ -223,6 +213,8 @@ class ChargepointTestFixture : public testing::Test { const int profile_max_stack_level = 1; const int max_charging_profiles_installed = 1; const int charging_schedule_max_periods = 1; + const DateTime date_start_range = ocpp::DateTime("2023-01-01T00:00:00"); + const DateTime date_end_range = ocpp::DateTime("2024-03-19T00:00:00"); }; /** @@ -608,16 +600,16 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__AllOptionalsEmpty__Re handler->add_tx_profile(profile_1, connector_id_1); handler->add_tx_profile(profile_2, connector_id_2); - auto profiles_1 = handler->get_valid_profiles({}, {}, connector_id_1); - auto profiles_2 = handler->get_valid_profiles({}, {}, connector_id_2); + auto profiles_1 = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + auto profiles_2 = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(1, profiles_1.size()); ASSERT_EQ(1, profiles_2.size()); // All empty tokens bool sut = handler->clear_all_profiles_with_filter(std::nullopt, std::nullopt, std::nullopt, std::nullopt, false); - profiles_1 = handler->get_valid_profiles({}, {}, connector_id_1); - profiles_2 = handler->get_valid_profiles({}, {}, connector_id_2); + profiles_1 = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + profiles_2 = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(0, profiles_1.size()); ASSERT_EQ(0, profiles_2.size()); @@ -681,12 +673,12 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Max_OnlyOneMatchingPr handler->add_charge_point_max_profile(profile); - auto profiles = handler->get_valid_profiles({}, {}, connector_id); + auto profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(1, profiles.size()); bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); - profiles = handler->get_valid_profiles({}, {}, connector_id); + profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(0, profiles.size()); ASSERT_TRUE(sut); @@ -708,12 +700,12 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Max_MatchingProfileId handler->add_charge_point_max_profile(profile_1); handler->add_charge_point_max_profile(profile_2); - auto profiles = handler->get_valid_profiles({}, {}, connector_id); + auto profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(2, profiles.size()); bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); - profiles = handler->get_valid_profiles({}, {}, connector_id); + profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(1, profiles.size()); ASSERT_TRUE(sut); @@ -735,12 +727,12 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Max_MultipleNoMatchin handler->add_charge_point_max_profile(profile_1); handler->add_charge_point_max_profile(profile_2); - auto profiles = handler->get_valid_profiles({}, {}, connector_id); + auto profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(2, profiles.size()); bool sut = handler->clear_all_profiles_with_filter(3, std::nullopt, std::nullopt, std::nullopt, true); - profiles = handler->get_valid_profiles({}, {}, connector_id); + profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(2, profiles.size()); ASSERT_FALSE(sut); @@ -758,12 +750,12 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Default_OnlyOneMatchi handler->add_tx_default_profile(profile, connector_id); - auto profiles = handler->get_valid_profiles({}, {}, connector_id); + auto profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(1, profiles.size()); bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); - profiles = handler->get_valid_profiles({}, {}, connector_id); + profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(0, profiles.size()); ASSERT_TRUE(sut); @@ -786,12 +778,12 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Default_MatchingProfi handler->add_tx_default_profile(profile_1, connector_id); handler->add_tx_default_profile(profile_2, connector_id); - auto profiles = handler->get_valid_profiles({}, {}, connector_id); + auto profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(2, profiles.size()); bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); - profiles = handler->get_valid_profiles({}, {}, connector_id); + profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(1, profiles.size()); ASSERT_TRUE(sut); @@ -815,12 +807,12 @@ TEST_F(ChargepointTestFixture, handler->add_tx_default_profile(profile_1, connector_id); handler->add_tx_default_profile(profile_2, connector_id); - auto profiles = handler->get_valid_profiles({}, {}, connector_id); + auto profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(2, profiles.size()); bool sut = handler->clear_all_profiles_with_filter(3, std::nullopt, std::nullopt, std::nullopt, true); - profiles = handler->get_valid_profiles({}, {}, connector_id); + profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(2, profiles.size()); ASSERT_FALSE(sut); @@ -838,12 +830,12 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Tx_OnlyOneMatchingPro handler->add_tx_profile(profile, connector_id); - auto profiles = handler->get_valid_profiles({}, {}, connector_id); + auto profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(1, profiles.size()); bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); - profiles = handler->get_valid_profiles({}, {}, connector_id); + profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(0, profiles.size()); ASSERT_TRUE(sut); @@ -866,12 +858,12 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Tx_MatchingProfileId_ handler->add_tx_profile(profile_1, connector_id); handler->add_tx_profile(profile_2, connector_id); - auto profiles = handler->get_valid_profiles({}, {}, connector_id); + auto profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(2, profiles.size()); bool sut = handler->clear_all_profiles_with_filter(1, std::nullopt, std::nullopt, std::nullopt, true); - profiles = handler->get_valid_profiles({}, {}, connector_id); + profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(1, profiles.size()); ASSERT_TRUE(sut); @@ -894,12 +886,12 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__Tx_MultipleNoMatching handler->add_tx_profile(profile_1, connector_id); handler->add_tx_profile(profile_2, connector_id); - auto profiles = handler->get_valid_profiles({}, {}, connector_id); + auto profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(2, profiles.size()); bool sut = handler->clear_all_profiles_with_filter(3, std::nullopt, std::nullopt, std::nullopt, true); - profiles = handler->get_valid_profiles({}, {}, connector_id); + profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id); ASSERT_EQ(2, profiles.size()); ASSERT_FALSE(sut); @@ -936,8 +928,8 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__ConnectorId__ReturnsT handler->add_tx_profile(profile_c2_3, connector_id_2); handler->add_tx_profile(profile_c2_4, connector_id_2); - auto connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); - auto connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + auto connector_id_1_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + auto connector_id_2_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(2, connector_id_1_profiles.size()); ASSERT_EQ(2, connector_id_2_profiles.size()); @@ -947,8 +939,8 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__ConnectorId__ReturnsT bool sut = handler->clear_all_profiles_with_filter(std::nullopt, connector_id_1, std::nullopt, std::nullopt, check_id_only); - connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); - connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + connector_id_1_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + connector_id_2_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(0, connector_id_1_profiles.size()); ASSERT_EQ(2, connector_id_2_profiles.size()); @@ -988,8 +980,8 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__StackLevel__ReturnsTr handler->add_tx_profile(profile_c2_3, connector_id_2); handler->add_tx_profile(profile_c2_4, connector_id_2); - auto connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); - auto connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + auto connector_id_1_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + auto connector_id_2_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(2, connector_id_1_profiles.size()); ASSERT_EQ(2, connector_id_2_profiles.size()); @@ -998,8 +990,8 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__StackLevel__ReturnsTr bool sut = handler->clear_all_profiles_with_filter(std::nullopt, std::nullopt, 1, std::nullopt, check_id_only); - connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); - connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + connector_id_1_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + connector_id_2_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(1, connector_id_1_profiles.size()); ASSERT_EQ(1, connector_id_2_profiles.size()); @@ -1039,8 +1031,8 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__ChargingProfilePurpos handler->add_tx_default_profile(profile_c2_3, connector_id_2); handler->add_tx_profile(profile_c2_4, connector_id_2); - auto connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); - auto connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + auto connector_id_1_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + auto connector_id_2_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(2, connector_id_1_profiles.size()); ASSERT_EQ(2, connector_id_2_profiles.size()); @@ -1050,8 +1042,8 @@ TEST_F(ChargepointTestFixture, ClearAllProfilesWithFilter__ChargingProfilePurpos bool sut = handler->clear_all_profiles_with_filter(std::nullopt, std::nullopt, std::nullopt, ChargingProfilePurposeType::TxDefaultProfile, check_id_only); - connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); - connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + connector_id_1_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + connector_id_2_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(1, connector_id_1_profiles.size()); ASSERT_EQ(1, connector_id_2_profiles.size()); @@ -1092,8 +1084,8 @@ TEST_F(ChargepointTestFixture, handler->add_tx_default_profile(profile_c2_3, connector_id_2); handler->add_tx_profile(profile_c2_4, connector_id_2); - auto connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); - auto connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + auto connector_id_1_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + auto connector_id_2_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(2, connector_id_1_profiles.size()); ASSERT_EQ(2, connector_id_2_profiles.size()); @@ -1103,8 +1095,8 @@ TEST_F(ChargepointTestFixture, bool sut = handler->clear_all_profiles_with_filter(std::nullopt, 100, 1, ChargingProfilePurposeType::TxDefaultProfile, check_id_only); - connector_id_1_profiles = handler->get_valid_profiles({}, {}, connector_id_1); - connector_id_2_profiles = handler->get_valid_profiles({}, {}, connector_id_2); + connector_id_1_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_1); + connector_id_2_profiles = handler->get_valid_profiles(date_start_range, date_end_range, connector_id_2); ASSERT_EQ(1, connector_id_1_profiles.size()); ASSERT_EQ(2, connector_id_2_profiles.size());