Skip to content

Commit

Permalink
Test valid cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
gberardi-pillar committed Mar 1, 2024
1 parent 813177d commit c40d131
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions tests/lib/ocpp/v201/test_smart_charging_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ namespace ocpp::v201 {
static const int STATION_WIDE_ID = 0;
static const int DEFAULT_EVSE_ID = 1;
static const int DEFAULT_PROFILE_ID = 1;
static const int DEFAULT_STACK_LEVEL = 1;

class ChargepointTestFixtureV201 : public ::testing::TestWithParam<std::tuple<int, int, ProfileValidationResultEnum>> {
class ChargepointTestFixtureV201 : public ::testing::TestWithParam<std::tuple<int, int, int, int, ProfileValidationResultEnum>> {
protected:
void SetUp() override {
}
Expand All @@ -53,7 +54,7 @@ class ChargepointTestFixtureV201 : public ::testing::TestWithParam<std::tuple<in
};
}

ChargingProfile create_charging_profile(int32_t charging_profile_id, ChargingProfilePurposeEnum charging_profile_purpose, ChargingSchedule charging_schedule, std::string transaction_id, int stack_level = 1) {
ChargingProfile create_charging_profile(int32_t charging_profile_id, ChargingProfilePurposeEnum charging_profile_purpose, ChargingSchedule charging_schedule, std::string transaction_id, int stack_level = DEFAULT_STACK_LEVEL) {
auto charging_profile_kind = ChargingProfileKindEnum::Absolute;
auto recurrency_kind = RecurrencyKindEnum::Daily;
std::vector<ChargingSchedule> charging_schedules = {charging_schedule};
Expand All @@ -70,8 +71,8 @@ class ChargepointTestFixtureV201 : public ::testing::TestWithParam<std::tuple<in
}

ChargingProfile create_tx_profile_with_missing_transaction_id(ChargingSchedule charging_schedule) {
auto charging_profile_id = 1;
auto stack_level = 1;
auto charging_profile_id = DEFAULT_PROFILE_ID;
auto stack_level = DEFAULT_STACK_LEVEL;
auto charging_profile_purpose = ChargingProfilePurposeEnum::TxProfile;
auto charging_profile_kind = ChargingProfileKindEnum::Absolute;
auto recurrency_kind = RecurrencyKindEnum::Daily;
Expand Down Expand Up @@ -139,9 +140,6 @@ class ChargepointTestFixtureV201 : public ::testing::TestWithParam<std::tuple<in
std::shared_ptr<DatabaseHandler> database_handler;

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;
DeviceModel device_model = create_device_model();
SmartChargingHandler handler = create_smart_charging_handler();
boost::uuids::random_generator uuid_generator = boost::uuids::random_generator();
Expand Down Expand Up @@ -243,18 +241,22 @@ TEST_F(ChargepointTestFixtureV201,
INSTANTIATE_TEST_SUITE_P(TxDefaultProfileValidationV201_Param_Test_Instantiate,
ChargepointTestFixtureV201,
testing::Values(
std::make_tuple(DEFAULT_EVSE_ID, STATION_WIDE_ID, ProfileValidationResultEnum::DuplicateTxDefaultProfileFound),
std::make_tuple(STATION_WIDE_ID, DEFAULT_EVSE_ID, ProfileValidationResultEnum::DuplicateTxDefaultProfileFound),
std::make_tuple(STATION_WIDE_ID, STATION_WIDE_ID, ProfileValidationResultEnum::Valid),
std::make_tuple(DEFAULT_EVSE_ID, DEFAULT_EVSE_ID, ProfileValidationResultEnum::Valid)
std::make_tuple(DEFAULT_EVSE_ID, STATION_WIDE_ID, DEFAULT_PROFILE_ID + 1, DEFAULT_STACK_LEVEL, ProfileValidationResultEnum::DuplicateTxDefaultProfileFound),
std::make_tuple(STATION_WIDE_ID, DEFAULT_EVSE_ID, DEFAULT_PROFILE_ID + 1, DEFAULT_STACK_LEVEL, ProfileValidationResultEnum::DuplicateTxDefaultProfileFound),
std::make_tuple(STATION_WIDE_ID, STATION_WIDE_ID, DEFAULT_PROFILE_ID + 1, DEFAULT_STACK_LEVEL, ProfileValidationResultEnum::Valid),
std::make_tuple(DEFAULT_EVSE_ID, DEFAULT_EVSE_ID, DEFAULT_PROFILE_ID + 1, DEFAULT_STACK_LEVEL, ProfileValidationResultEnum::Valid),
std::make_tuple(DEFAULT_EVSE_ID, STATION_WIDE_ID, DEFAULT_PROFILE_ID, DEFAULT_STACK_LEVEL, ProfileValidationResultEnum::Valid),
std::make_tuple(STATION_WIDE_ID, DEFAULT_EVSE_ID, DEFAULT_PROFILE_ID, DEFAULT_STACK_LEVEL, ProfileValidationResultEnum::Valid),
std::make_tuple(DEFAULT_EVSE_ID, STATION_WIDE_ID, DEFAULT_PROFILE_ID + 1, DEFAULT_STACK_LEVEL + 1, ProfileValidationResultEnum::Valid),
std::make_tuple(STATION_WIDE_ID, DEFAULT_EVSE_ID, DEFAULT_PROFILE_ID + 1, DEFAULT_STACK_LEVEL + 1, ProfileValidationResultEnum::Valid)
));

TEST_P(ChargepointTestFixtureV201, TxDefaultProfileValidationV201Tests) {
auto [existing_evse_id, added_evse_id, expected] = GetParam();
TEST_P(ChargepointTestFixtureV201, K01FR52_and_K01FR53_TxDefaultProfileValidationV201Tests) {
auto [existing_evse_id, added_evse_id, added_profile_id, added_stack_level, expected] = GetParam();
install_profile_on_evse(existing_evse_id, DEFAULT_PROFILE_ID);

create_evse_with_id(added_evse_id);
auto profile = create_charging_profile(DEFAULT_PROFILE_ID + 1, ChargingProfilePurposeEnum::TxDefaultProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid());
auto profile = create_charging_profile(added_profile_id, ChargingProfilePurposeEnum::TxDefaultProfile, create_charge_schedule(ChargingRateUnitEnum::A), uuid(), added_stack_level);
auto sut = handler.validate_tx_default_profile(profile, *evses[added_evse_id]);

EXPECT_THAT(sut, testing::Eq(expected));
Expand Down

0 comments on commit c40d131

Please sign in to comment.