Skip to content

Commit

Permalink
Enable pedantic compiler error and remove C++20 feature usage (#848)
Browse files Browse the repository at this point in the history
* Enable pedantic compiler error and remove C++20 feature usage

Removed designated initializer usage in library code and tests

Adaption to unit tests to not use designated initializers anymore

Fixed some test errors with missing chargingProfileKind being left uninitialized

Signed-off-by: Kai-Uwe Hermann <[email protected]>

* Remove extra ;

Signed-off-by: Kai-Uwe Hermann <[email protected]>

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored Oct 30, 2024
1 parent 3c0d64c commit a6f88c8
Show file tree
Hide file tree
Showing 11 changed files with 1,593 additions and 1,238 deletions.
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target_compile_options(ocpp
PRIVATE
#-Werror # turn warnings into errors
-Wimplicit-fallthrough # avoid unintended fallthroughs
-pedantic-errors
)

target_compile_definitions(ocpp
Expand Down
27 changes: 12 additions & 15 deletions lib/ocpp/v201/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,12 @@ CompositeSchedule calculate_composite_schedule(std::vector<period_entry_t>& in_c
const auto now = floor_seconds(in_now);
const auto end = floor_seconds(in_end);

CompositeSchedule composite{
.chargingSchedulePeriod = {},
.evseId = EVSEID_NOT_SET,
.duration = elapsed_seconds(end, now),
.scheduleStart = now,
.chargingRateUnit = selected_unit,
};
CompositeSchedule composite;
composite.chargingSchedulePeriod = {};
composite.evseId = EVSEID_NOT_SET;
composite.duration = elapsed_seconds(end, now);
composite.scheduleStart = now;
composite.chargingRateUnit = selected_unit;

// sort the combined_schedules in stack priority order
struct {
Expand Down Expand Up @@ -476,14 +475,12 @@ CompositeSchedule calculate_composite_schedule(const CompositeSchedule& charging
const CompositeScheduleDefaultLimits& default_limits,
int32_t supply_voltage) {

CompositeSchedule combined{
.chargingSchedulePeriod = {},
.evseId = EVSEID_NOT_SET,
.duration = tx_default.duration,
.scheduleStart = tx_default.scheduleStart,
.chargingRateUnit = tx_default.chargingRateUnit,

};
CompositeSchedule combined;
combined.chargingSchedulePeriod = {};
combined.evseId = EVSEID_NOT_SET;
combined.duration = tx_default.duration;
combined.scheduleStart = tx_default.scheduleStart;
combined.chargingRateUnit = tx_default.chargingRateUnit;

const float default_limit = (tx_default.chargingRateUnit == ChargingRateUnitEnum::A)
? static_cast<float>(default_limits.amps)
Expand Down
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ target_compile_definitions(libocpp_unit_tests
TEST_PROFILES_LOCATION_V201="${TEST_PROFILES_LOCATION_V201}"
)

target_compile_options(libocpp_unit_tests
PRIVATE
-pedantic-errors
)

target_compile_features(libocpp_unit_tests PUBLIC cxx_std_17)

add_custom_command(TARGET libocpp_unit_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/unittest_device_model.db ${CMAKE_CURRENT_BINARY_DIR}/resources/unittest_device_model.db
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/unittest_device_model_missing_required.db ${CMAKE_CURRENT_BINARY_DIR}/resources/unittest_device_model_missing_required.db
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/ocpp/common/test_message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class MessageQueueTest : public ::testing::Test {
this->call_marker_cond_var.notify_one();
return value;
});
};
}

void wait_for_calls(int expected_calls = 1) {
std::unique_lock<std::mutex> lock(call_marker_mutex);
Expand Down
42 changes: 22 additions & 20 deletions tests/lib/ocpp/v201/test_charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ class ChargePointCommonTestFixtureV201 : public DatabaseTestingUtils {
std::vector<ChargingSchedulePeriod> create_charging_schedule_periods(std::vector<int32_t> start_periods) {
auto charging_schedule_periods = std::vector<ChargingSchedulePeriod>();
for (auto start_period : start_periods) {
auto charging_schedule_period = ChargingSchedulePeriod{
.startPeriod = start_period,
};
ChargingSchedulePeriod charging_schedule_period;
charging_schedule_period.startPeriod = start_period;
charging_schedule_periods.push_back(charging_schedule_period);
}

Expand Down Expand Up @@ -114,16 +113,18 @@ class ChargePointCommonTestFixtureV201 : public DatabaseTestingUtils {
std::optional<ocpp::DateTime> validTo = {}) {
auto recurrency_kind = RecurrencyKindEnum::Daily;
std::vector<ChargingSchedule> charging_schedules = {charging_schedule};
return ChargingProfile{.id = charging_profile_id,
.stackLevel = stack_level,
.chargingProfilePurpose = charging_profile_purpose,
.chargingProfileKind = charging_profile_kind,
.chargingSchedule = charging_schedules,
.customData = {},
.recurrencyKind = recurrency_kind,
.validFrom = validFrom,
.validTo = validTo,
.transactionId = transaction_id};
ChargingProfile charging_profile;
charging_profile.id = charging_profile_id;
charging_profile.stackLevel = stack_level;
charging_profile.chargingProfilePurpose = charging_profile_purpose;
charging_profile.chargingProfileKind = charging_profile_kind;
charging_profile.chargingSchedule = charging_schedules;
charging_profile.customData = {};
charging_profile.recurrencyKind = recurrency_kind;
charging_profile.validFrom = validFrom;
charging_profile.validTo = validTo;
charging_profile.transactionId = transaction_id;
return charging_profile;
}

std::shared_ptr<DatabaseHandler> create_database_handler() {
Expand Down Expand Up @@ -625,11 +626,10 @@ class ChargePointFunctionalityTestFixtureV201 : public ChargePointCommonTestFixt
template <class T, MessageType M> EnhancedMessage<MessageType> request_to_enhanced_message(const T& req) {
auto message_id = uuid();
ocpp::Call<T> call(req, message_id);
EnhancedMessage<MessageType> enhanced_message{
.uniqueId = message_id,
.messageType = M,
.messageTypeId = MessageTypeId::CALL,
};
EnhancedMessage<MessageType> enhanced_message;
enhanced_message.uniqueId = message_id;
enhanced_message.messageType = M;
enhanced_message.messageTypeId = MessageTypeId::CALL;

call_to_json(enhanced_message.message, call);

Expand Down Expand Up @@ -782,7 +782,8 @@ TEST_F(ChargePointFunctionalityTestFixtureV201,

RequestStartTransactionRequest req;
req.evseId = DEFAULT_EVSE_ID;
req.idToken = IdToken{.idToken = "Local", .type = IdTokenEnum::Local};
req.idToken.idToken = "Local";
req.idToken.type = IdTokenEnum::Local;
req.chargingProfile = profile;

auto start_transaction_req =
Expand Down Expand Up @@ -908,7 +909,8 @@ TEST_F(ChargePointFunctionalityTestFixtureV201,

RequestStartTransactionRequest req;
req.evseId = DEFAULT_EVSE_ID;
req.idToken = IdToken{.idToken = "Local", .type = IdTokenEnum::Local};
req.idToken.idToken = "Local";
req.idToken.type = IdTokenEnum::Local;
req.chargingProfile = profile;

auto start_transaction_req =
Expand Down
Loading

0 comments on commit a6f88c8

Please sign in to comment.