diff --git a/ecal/tests/cpp/serialization_test/CMakeLists.txt b/ecal/tests/cpp/serialization_test/CMakeLists.txt index 2ae63f551c..20dc5ee454 100644 --- a/ecal/tests/cpp/serialization_test/CMakeLists.txt +++ b/ecal/tests/cpp/serialization_test/CMakeLists.txt @@ -71,20 +71,30 @@ set(ecal_serialize_src set(unit_test_src src/common_generate.cpp + src/common_generate.h src/logging_compare.cpp + src/logging_compare.h src/logging_generate.cpp + src/logging_generate.h src/logging_serialization_test.cpp src/monitoring_compare.cpp + src/monitoring_compare.h src/monitoring_generate.cpp + src/monitoring_generate.h src/monitoring_serialization_test.cpp + src/parallel_serialization_test.cpp src/payload_compare.cpp + src/payload_compare.h src/payload_generate.cpp + src/payload_generate.h src/payload_serialization_test.cpp - src/registration_compare.cpp src/registration_generate.cpp + src/registration_generate.h src/registration_serialization_test.cpp src/service_compare.cpp + src/service_compare.h src/service_generate.cpp + src/service_generate.h src/service_serialization_test.cpp ) diff --git a/ecal/tests/cpp/serialization_test/src/common_generate.cpp b/ecal/tests/cpp/serialization_test/src/common_generate.cpp index a5cd9a7e06..e81fdfd610 100644 --- a/ecal/tests/cpp/serialization_test/src/common_generate.cpp +++ b/ecal/tests/cpp/serialization_test/src/common_generate.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,9 @@ * ========================= eCAL LICENSE ================================= */ +#include "common_generate.h" + #include -#include -#include namespace eCAL { diff --git a/ecal/tests/cpp/serialization_test/src/common_generate.h b/ecal/tests/cpp/serialization_test/src/common_generate.h new file mode 100644 index 0000000000..b8966feee9 --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/common_generate.h @@ -0,0 +1,30 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include +#include + +namespace eCAL +{ + // Generate a random string of given length (may contain null character) + std::string GenerateString(size_t length); + std::vector GenerateRandomVector(size_t length); +} diff --git a/ecal/tests/cpp/serialization_test/src/logging_compare.cpp b/ecal/tests/cpp/serialization_test/src/logging_compare.cpp index cd1512d67a..cf8b004cef 100644 --- a/ecal/tests/cpp/serialization_test/src/logging_compare.cpp +++ b/ecal/tests/cpp/serialization_test/src/logging_compare.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ * ========================= eCAL LICENSE ================================= */ -#include +#include "logging_compare.h" namespace eCAL { diff --git a/ecal/tests/cpp/serialization_test/src/logging_compare.h b/ecal/tests/cpp/serialization_test/src/logging_compare.h new file mode 100644 index 0000000000..1e5c9dfa73 --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/logging_compare.h @@ -0,0 +1,30 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once +#include + +namespace eCAL +{ + namespace Logging + { + // compare two LogMessages for equality + bool CompareLogMessages(const SLogMessage& message1, const SLogMessage& message2); + } +} \ No newline at end of file diff --git a/ecal/tests/cpp/serialization_test/src/logging_generate.cpp b/ecal/tests/cpp/serialization_test/src/logging_generate.cpp index 03fe313402..f871a18e65 100644 --- a/ecal/tests/cpp/serialization_test/src/logging_generate.cpp +++ b/ecal/tests/cpp/serialization_test/src/logging_generate.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +17,13 @@ * ========================= eCAL LICENSE ================================= */ -#include +#include "logging_generate.h" +#include "common_generate.h" #include namespace eCAL { - std::string GenerateString(size_t length); - namespace Logging { SLogMessage GenerateLogMessage() diff --git a/ecal/tests/cpp/serialization_test/src/logging_generate.h b/ecal/tests/cpp/serialization_test/src/logging_generate.h new file mode 100644 index 0000000000..daab8f208c --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/logging_generate.h @@ -0,0 +1,29 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once +#include + +namespace eCAL +{ + namespace Logging + { + SLogMessage GenerateLogMessage(); + } +} \ No newline at end of file diff --git a/ecal/tests/cpp/serialization_test/src/logging_serialization_test.cpp b/ecal/tests/cpp/serialization_test/src/logging_serialization_test.cpp index 6c2badb85f..c9587b0d52 100644 --- a/ecal/tests/cpp/serialization_test/src/logging_serialization_test.cpp +++ b/ecal/tests/cpp/serialization_test/src/logging_serialization_test.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ * ========================= eCAL LICENSE ================================= */ -#include "../../serialization/ecal_serialize_logging.h" +#include + +#include "logging_generate.h" +#include "logging_compare.h" #include @@ -25,9 +28,6 @@ namespace eCAL { namespace Logging { - SLogMessage GenerateLogMessage(); - bool CompareLogMessages(const SLogMessage& message1, const SLogMessage& message2); - TEST(core_cpp_serialization, LogMessage2String) { SLogMessage message_in = GenerateLogMessage(); diff --git a/ecal/tests/cpp/serialization_test/src/monitoring_compare.cpp b/ecal/tests/cpp/serialization_test/src/monitoring_compare.cpp index 4081a580f9..74f5c61021 100644 --- a/ecal/tests/cpp/serialization_test/src/monitoring_compare.cpp +++ b/ecal/tests/cpp/serialization_test/src/monitoring_compare.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ * ========================= eCAL LICENSE ================================= */ +#include "monitoring_compare.h" + #include namespace eCAL diff --git a/ecal/tests/cpp/serialization_test/src/monitoring_compare.h b/ecal/tests/cpp/serialization_test/src/monitoring_compare.h new file mode 100644 index 0000000000..4d502e6942 --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/monitoring_compare.h @@ -0,0 +1,31 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Monitoring + { + // compare two monitoring structs + bool CompareMonitorings(const SMonitoring& monitoring1, const SMonitoring& monitoring2); + } +} diff --git a/ecal/tests/cpp/serialization_test/src/monitoring_generate.cpp b/ecal/tests/cpp/serialization_test/src/monitoring_generate.cpp index 3cffe86d18..e2c4aff2d8 100644 --- a/ecal/tests/cpp/serialization_test/src/monitoring_generate.cpp +++ b/ecal/tests/cpp/serialization_test/src/monitoring_generate.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +17,13 @@ * ========================= eCAL LICENSE ================================= */ -#include +#include "monitoring_generate.h" +#include "common_generate.h" #include namespace eCAL { - std::string GenerateString(size_t length); - namespace Monitoring { // generate process diff --git a/ecal/tests/cpp/serialization_test/src/monitoring_generate.h b/ecal/tests/cpp/serialization_test/src/monitoring_generate.h new file mode 100644 index 0000000000..2099f64c7b --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/monitoring_generate.h @@ -0,0 +1,46 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Monitoring + { + // generate process + SProcessMon GenerateProcess(); + + // generate topic + STopicMon GenerateTopic(const std::string& direction); + + // generate servicemethod + SMethodMon GenerateServiceMethod(); + + // generate service + SServerMon GenerateService(); + + // generate client + SClientMon GenerateClient(); + + // generate monitoring + SMonitoring GenerateMonitoring(); + } +} diff --git a/ecal/tests/cpp/serialization_test/src/monitoring_serialization_test.cpp b/ecal/tests/cpp/serialization_test/src/monitoring_serialization_test.cpp index b2dd57aeef..eb6f071fb2 100644 --- a/ecal/tests/cpp/serialization_test/src/monitoring_serialization_test.cpp +++ b/ecal/tests/cpp/serialization_test/src/monitoring_serialization_test.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,9 @@ * ========================= eCAL LICENSE ================================= */ -#include "../../serialization/ecal_serialize_monitoring.h" +#include +#include "monitoring_generate.h" +#include "monitoring_compare.h" #include @@ -25,9 +27,6 @@ namespace eCAL { namespace Monitoring { - SMonitoring GenerateMonitoring(); - bool CompareMonitorings(const SMonitoring& monitoring1, const SMonitoring& monitoring2); - TEST(core_cpp_serialization, Monitoring2String) { SMonitoring message_in = GenerateMonitoring(); diff --git a/ecal/tests/cpp/serialization_test/src/parallel_serialization_test.cpp b/ecal/tests/cpp/serialization_test/src/parallel_serialization_test.cpp new file mode 100644 index 0000000000..ccfd289f89 --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/parallel_serialization_test.cpp @@ -0,0 +1,70 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include "serialization/ecal_serialize_logging.h" +#include "serialization/ecal_serialize_sample_registration.h" + +#include "registration_generate.h" +#include "logging_generate.h" + +#include +#include + + +namespace eCAL +{ + void SerializeLogMessage() + { + Logging::SLogMessage message_in = Logging::GenerateLogMessage(); + + for (int i = 0; i < 10000; ++i) + { + std::string message_buffer; + SerializeToBuffer(message_in, message_buffer); + + Logging::SLogMessage message_out; + DeserializeFromBuffer(message_buffer.data(), message_buffer.size(), message_out); + } + } + + void SerializePayloadMessage() + { + Registration::Sample message_in = Registration::GenerateTopicSample(); + + for (int i = 0; i < 10000; ++i) + { + std::string message_buffer; + SerializeToBuffer(message_in, message_buffer); + + Registration::Sample message_out; + DeserializeFromBuffer(message_buffer.data(), message_buffer.size(), message_out); + } + } + + + TEST(core_cpp_serialization, ParallelSerialization) + { + std::thread logging_serializer_thread(SerializeLogMessage); + std::thread sample_serializer_thread(SerializePayloadMessage); + + logging_serializer_thread.join(); + sample_serializer_thread.join(); + } + +} diff --git a/ecal/tests/cpp/serialization_test/src/payload_compare.cpp b/ecal/tests/cpp/serialization_test/src/payload_compare.cpp index e6fa01482d..50266d51e3 100644 --- a/ecal/tests/cpp/serialization_test/src/payload_compare.cpp +++ b/ecal/tests/cpp/serialization_test/src/payload_compare.cpp @@ -17,7 +17,9 @@ * ========================= eCAL LICENSE ================================= */ -#include "../../serialization/ecal_struct_sample_payload.h" +#include "payload_compare.h" + +#include namespace eCAL { diff --git a/ecal/tests/cpp/serialization_test/src/payload_compare.h b/ecal/tests/cpp/serialization_test/src/payload_compare.h new file mode 100644 index 0000000000..a0c86a9f22 --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/payload_compare.h @@ -0,0 +1,29 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include + +namespace eCAL +{ + namespace Payload + { + // compare two samples for equality + bool ComparePayloadSamples(const Sample& sample1, const Sample& sample2); + } +} diff --git a/ecal/tests/cpp/serialization_test/src/payload_generate.cpp b/ecal/tests/cpp/serialization_test/src/payload_generate.cpp index b153a21fee..45ed68970b 100644 --- a/ecal/tests/cpp/serialization_test/src/payload_generate.cpp +++ b/ecal/tests/cpp/serialization_test/src/payload_generate.cpp @@ -17,15 +17,14 @@ * ========================= eCAL LICENSE ================================= */ -#include "../../serialization/ecal_struct_sample_payload.h" +#include "payload_generate.h" +#include "common_generate.h" +#include #include namespace eCAL { - std::string GenerateString(size_t length); - std::vector GenerateRandomVector(size_t length); - namespace Payload { // generate Topic diff --git a/ecal/tests/cpp/serialization_test/src/payload_generate.h b/ecal/tests/cpp/serialization_test/src/payload_generate.h new file mode 100644 index 0000000000..ce8286afe8 --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/payload_generate.h @@ -0,0 +1,49 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include + +#include + +namespace eCAL +{ + namespace Payload + { + // generate Topic + TopicInfo GenerateTopic(); + + // generate Payload + Payload GeneratePayload(const char* payload_addr, size_t payload_size); + + // generate Payload + Payload GeneratePayload(const std::vector& payload_vec); + + // generate Content + Content GenerateContent(const char* payload_addr, size_t payload_size); + + // generate Content + Content GenerateContent(const std::vector& payload_vec); + + // generate Payload Sample (payload raw pointer + size) + Sample GeneratePayloadSample(const char* payload_addr, size_t payload_size); + + // generate Payload Sample (payload vector) + Sample GeneratePayloadSample(const std::vector& payload_vec); + } +} diff --git a/ecal/tests/cpp/serialization_test/src/payload_serialization_test.cpp b/ecal/tests/cpp/serialization_test/src/payload_serialization_test.cpp index 4f42d055d8..dc9d4519ef 100644 --- a/ecal/tests/cpp/serialization_test/src/payload_serialization_test.cpp +++ b/ecal/tests/cpp/serialization_test/src/payload_serialization_test.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ * ========================= eCAL LICENSE ================================= */ -#include "../../serialization/ecal_serialize_sample_payload.h" +#include + +#include "payload_generate.h" +#include "payload_compare.h" #include #include @@ -44,11 +47,6 @@ namespace eCAL { namespace Payload { - Sample GeneratePayloadSample(const char* payload_addr, size_t payload_size); - Sample GeneratePayloadSample(const std::vector& payload_vec); - - bool ComparePayloadSamples(const Sample& sample1, const Sample& sample2); - TEST(core_cpp_serialization, RawPayload2String) { std::vector payload; diff --git a/ecal/tests/cpp/serialization_test/src/registration_compare.cpp b/ecal/tests/cpp/serialization_test/src/registration_compare.cpp deleted file mode 100644 index bc1c4f2040..0000000000 --- a/ecal/tests/cpp/serialization_test/src/registration_compare.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* ========================= eCAL LICENSE ================================= - * - * Copyright (C) 2016 - 2024 Continental Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ========================= eCAL LICENSE ================================= -*/ - -#include "../../serialization/ecal_struct_sample_registration.h" - -#include - -namespace eCAL -{ - namespace Registration - { - // compare two ProcessState objects - bool CompareProcessState(const ProcessState& state1, const ProcessState& state2) - { - return (state1.severity == state2.severity) && - (state1.severity_level == state2.severity_level) && - (state1.info == state2.info); - } - - // compare two Process objects - bool CompareProcess(const Process& process1, const Process& process2) - { - return (process1.rclock == process2.rclock) && - (process1.hgname == process2.hgname) && - (process1.pname == process2.pname) && - (process1.uname == process2.uname) && - (process1.pparam == process2.pparam) && - CompareProcessState(process1.state, process2.state) && - (process1.tsync_state == process2.tsync_state) && - (process1.tsync_mod_name == process2.tsync_mod_name) && - (process1.component_init_state == process2.component_init_state) && - (process1.component_init_info == process2.component_init_info) && - (process1.ecal_runtime_version == process2.ecal_runtime_version); - } - - // compare two Service objects - bool CompareService(const Service::Service& service1, const Service::Service& service2) - { - return (service1.rclock == service2.rclock) && - (service1.pname == service2.pname) && - (service1.uname == service2.uname) && - (service1.sname == service2.sname) && - (service1.methods == service2.methods) && - (service1.version == service2.version) && - (service1.tcp_port_v0 == service2.tcp_port_v0) && - (service1.tcp_port_v1 == service2.tcp_port_v1); - } - - // compare two Client objects - bool CompareClient(const Service::Client& client1, const Service::Client& client2) - { - return (client1.rclock == client2.rclock) && - (client1.pname == client2.pname) && - (client1.uname == client2.uname) && - (client1.sname == client2.sname) && - (client1.methods == client2.methods) && - (client1.version == client2.version); - } - - // compare two DataTypeInformation objects - bool CompareDataTypeInformation(const SDataTypeInformation& dt1, const SDataTypeInformation& dt2) - { - return (dt1.name == dt2.name) && (dt1.encoding == dt2.encoding) && (dt1.descriptor == dt2.descriptor); - } - - // compare two LayerParUdpMC objects - bool CompareLayerParUdpMC(const LayerParUdpMC& /*par1*/, const LayerParUdpMC& /*par2*/) - { - return true; - } - - // compare two LayerParTcp objects - bool CompareLayerParTcp(const LayerParTcp& par1, const LayerParTcp& par2) - { - return par1.port == par2.port; - } - - // compare two LayerParShm objects - bool CompareLayerParShm(const LayerParShm& par1, const LayerParShm& par2) - { - return par1.memory_file_list == par2.memory_file_list; - } - - // compare two ConnectionPar objects - bool CompareConnectionPar(const ConnectionPar& par1, const ConnectionPar& par2) - { - return CompareLayerParUdpMC(par1.layer_par_udpmc, par2.layer_par_udpmc) && - CompareLayerParTcp(par1.layer_par_tcp, par2.layer_par_tcp) && - CompareLayerParShm(par1.layer_par_shm, par2.layer_par_shm); - } - - // compare two TLayer vector objects - bool CompareTLayer(const Util::CExpandingVector& layer1_vec, const Util::CExpandingVector& layer2_vec) - { - // ensure that both vectors have the same size - if (layer1_vec.size() != layer2_vec.size()) { - return false; - } - - // compare vectors element-wise - return std::equal(layer1_vec.begin(), layer1_vec.end(), layer2_vec.begin(), - [](const TLayer& layer1, const TLayer& layer2) { - // compare TLayer objects for equality - return (layer1.type == layer2.type) && - (layer1.version == layer2.version) && - (layer1.enabled == layer2.enabled) && - (layer1.active == layer2.active) && - CompareConnectionPar(layer1.par_layer, layer2.par_layer); - }); - } - - // compare two Topic objects - bool CompareTopic(const Topic& topic1, const Topic& topic2) - { - return (topic1.rclock == topic2.rclock) && - (topic1.hgname == topic2.hgname) && - (topic1.pname == topic2.pname) && - (topic1.uname == topic2.uname) && - (topic1.tname == topic2.tname) && - (topic1.direction == topic2.direction) && - CompareDataTypeInformation(topic1.tdatatype, topic2.tdatatype) && - CompareTLayer(topic1.tlayer, topic2.tlayer) && - (topic1.tsize == topic2.tsize) && - (topic1.connections_loc == topic2.connections_loc) && - (topic1.connections_ext == topic2.connections_ext) && - (topic1.message_drops == topic2.message_drops) && - (topic1.did == topic2.did) && - (topic1.dclock == topic2.dclock) && - (topic1.dfreq == topic2.dfreq) && - (topic1.attr == topic2.attr); - } - - bool CompareIdentifier(const SampleIdentifier& identifier1, const SampleIdentifier& identifier2) - { - return (identifier1.entity_id == identifier2.entity_id) && - (identifier1.process_id == identifier2.process_id) && - (identifier1.host_name == identifier2.host_name); - } - - // compare two Registration Sample objects - bool CompareRegistrationSamples(const Sample& sample1, const Sample& sample2) - { - return (sample1.cmd_type == sample2.cmd_type) && - (sample1.host.hname == sample2.host.hname) && - CompareIdentifier(sample1.identifier, sample2.identifier) && - CompareProcess(sample1.process, sample2.process) && - CompareService(sample1.service, sample2.service) && - CompareClient(sample1.client, sample2.client) && - CompareTopic(sample1.topic, sample2.topic); - } - } -} diff --git a/ecal/tests/cpp/serialization_test/src/registration_serialization_test.cpp b/ecal/tests/cpp/serialization_test/src/registration_serialization_test.cpp index 0478247cf1..f184dc08e4 100644 --- a/ecal/tests/cpp/serialization_test/src/registration_serialization_test.cpp +++ b/ecal/tests/cpp/serialization_test/src/registration_serialization_test.cpp @@ -17,7 +17,7 @@ * ========================= eCAL LICENSE ================================= */ -#include "../../serialization/ecal_serialize_sample_registration.h" +#include #include "registration_generate.h" #include @@ -26,8 +26,6 @@ namespace eCAL { namespace Registration { - bool CompareRegistrationSamples(const Sample& sample1, const Sample& sample2); - class RegistrationSampleSerializationTest : public ::testing::Test { public: @@ -54,7 +52,7 @@ namespace eCAL Sample sample_out; EXPECT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_out)); - EXPECT_TRUE(CompareRegistrationSamples(sample_in, sample_out)); + EXPECT_EQ(sample_in, sample_out); } } @@ -68,7 +66,7 @@ namespace eCAL Sample sample_out; EXPECT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_out)); - EXPECT_TRUE(CompareRegistrationSamples(sample_in, sample_out)); + EXPECT_EQ(sample_in, sample_out); } } @@ -87,7 +85,7 @@ namespace eCAL EXPECT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_list_out)); EXPECT_TRUE(sample_list_in.size() == sample_list_out.size()); - EXPECT_TRUE(std::equal(sample_list_in.begin(), sample_list_in.end(), sample_list_out.begin(), CompareRegistrationSamples)); + EXPECT_EQ(sample_list_in, sample_list_out); } TEST_F(core_cpp_registration_serialization, RegistrationList2Vector) @@ -105,7 +103,7 @@ namespace eCAL EXPECT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_list_out)); EXPECT_TRUE(sample_list_in.size() == sample_list_out.size()); - EXPECT_TRUE(std::equal(sample_list_in.begin(), sample_list_in.end(), sample_list_out.begin(), CompareRegistrationSamples)); + EXPECT_EQ(sample_list_in, sample_list_out); } } } diff --git a/ecal/tests/cpp/serialization_test/src/service_compare.cpp b/ecal/tests/cpp/serialization_test/src/service_compare.cpp index 981a1ab150..1cf1200cbf 100644 --- a/ecal/tests/cpp/serialization_test/src/service_compare.cpp +++ b/ecal/tests/cpp/serialization_test/src/service_compare.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ * ========================= eCAL LICENSE ================================= */ -#include "../../serialization/ecal_struct_service.h" +#include "service_compare.h" namespace eCAL { diff --git a/ecal/tests/cpp/serialization_test/src/service_compare.h b/ecal/tests/cpp/serialization_test/src/service_compare.h new file mode 100644 index 0000000000..46d9234e2e --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/service_compare.h @@ -0,0 +1,35 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ +#pragma once + +#include + +namespace eCAL +{ + namespace Service + { + // compare two ServiceHeaders for equality + bool CompareServiceHeaders(const ServiceHeader& header1, const ServiceHeader& header2); + + bool CompareRequests(const Request& request1, const Request& request2); + + // compare two Responses for equality + bool CompareResponses(const Response& response1, const Response& response2); + } +} diff --git a/ecal/tests/cpp/serialization_test/src/service_generate.cpp b/ecal/tests/cpp/serialization_test/src/service_generate.cpp index 70dc55759a..61fa5d2b95 100644 --- a/ecal/tests/cpp/serialization_test/src/service_generate.cpp +++ b/ecal/tests/cpp/serialization_test/src/service_generate.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +17,14 @@ * ========================= eCAL LICENSE ================================= */ -#include "../../serialization/ecal_struct_service.h" +#include "service_generate.h" +#include "common_generate.h" +#include #include namespace eCAL { - std::string GenerateString(size_t length); - namespace Service { // generate ServiceHeader diff --git a/ecal/tests/cpp/serialization_test/src/service_generate.h b/ecal/tests/cpp/serialization_test/src/service_generate.h new file mode 100644 index 0000000000..40c4ca8366 --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/service_generate.h @@ -0,0 +1,37 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Service + { + // generate ServiceHeader + ServiceHeader GenerateServiceHeader(); + + // generate Request + Request GenerateRequest(); + + // generate Response + Response GenerateResponse(); + } +} diff --git a/ecal/tests/cpp/serialization_test/src/service_serialization_test.cpp b/ecal/tests/cpp/serialization_test/src/service_serialization_test.cpp index 06672857dc..f44896b6c8 100644 --- a/ecal/tests/cpp/serialization_test/src/service_serialization_test.cpp +++ b/ecal/tests/cpp/serialization_test/src/service_serialization_test.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,9 @@ * ========================= eCAL LICENSE ================================= */ -#include "../../serialization/ecal_serialize_service.h" +#include +#include "service_compare.h" +#include "service_generate.h" #include @@ -25,12 +27,6 @@ namespace eCAL { namespace Service { - Request GenerateRequest(); - bool CompareRequests(const Request& request1, const Request& request2); - - Response GenerateResponse(); - bool CompareResponses(const Response& response1, const Response& response2); - TEST(core_cpp_serialization, Request2String) { Request sample_in = GenerateRequest();