From 13dc44496bd2e1462030de6fdc5c21fa256f98b9 Mon Sep 17 00:00:00 2001 From: Kerstin Keller Date: Thu, 23 May 2024 15:27:27 +0200 Subject: [PATCH] [c#] Folder structure rework. All C# related code is not in the subfolder `lang/csharp`. The folders are then separated based on the functionality. All related samples share the same CMakeLists.txt file, which makes it easier to add new samples. --- lang/csharp/CMakeLists.txt | 22 ++++- .../CMakeLists.txt | 24 +++-- .../pubsub_minimal_rec.cs | 0 .../pubsub_minimal_rec_cb.cs | 0 .../pubsub_minimal_snd.cs | 0 .../service_minimal_client.cs | 0 .../service_minimal_server.cs | 0 .../Continental.eCAL.Core.Test/CMakeLists.txt | 51 ++++++++++ .../csharp/Continental.eCAL.Core.Test/test.cs | 59 ++++++++++++ .../AssemblyInfo.cpp | 0 .../CMakeLists.txt | 0 .../ecal_clr.cpp | 0 .../Core => Continental.eCAL.Core}/ecal_clr.h | 0 .../CMakeLists.txt | 6 +- .../animal.proto | 0 .../house.proto | 0 .../person.proto | 0 .../protobuf_csharp_helper.cmake | 0 .../CMakeLists.txt | 31 +++--- .../pubsub_person_rec.cs | 0 .../pubsub_person_rec_cb.cs | 0 .../pubsub_person_snd.cs | 0 .../CMakeLists.txt | 51 ++++++++++ .../Continental.eCAL.Protobuf.Test/test.cs | 96 +++++++++++++++++++ .../CMakeLists.txt | 0 .../ProtoHelper.cs | 0 .../ProtoPublisher.cs | 0 .../ProtoSubscriber.cs | 0 samples/csharp/CMakeLists.txt | 12 --- .../protobuf/person_rec_cb/CMakeLists.txt | 41 -------- .../pubsub/protobuf/person_snd/CMakeLists.txt | 41 -------- .../string/minimal_rec_cb/CMakeLists.txt | 32 ------- .../pubsub/string/minimal_snd/CMakeLists.txt | 32 ------- .../services/minimal_client/CMakeLists.txt | 28 ------ .../services/minimal_server/CMakeLists.txt | 28 ------ 35 files changed, 310 insertions(+), 244 deletions(-) rename {samples/csharp/pubsub/string/minimal_rec => lang/csharp/Continental.eCAL.Core.Samples}/CMakeLists.txt (59%) rename samples/csharp/pubsub/string/minimal_rec/minimal_rec.cs => lang/csharp/Continental.eCAL.Core.Samples/pubsub_minimal_rec.cs (100%) rename samples/csharp/pubsub/string/minimal_rec_cb/minimal_rec_cb.cs => lang/csharp/Continental.eCAL.Core.Samples/pubsub_minimal_rec_cb.cs (100%) rename samples/csharp/pubsub/string/minimal_snd/minimal_snd.cs => lang/csharp/Continental.eCAL.Core.Samples/pubsub_minimal_snd.cs (100%) rename samples/csharp/services/minimal_client/minimal_client.cs => lang/csharp/Continental.eCAL.Core.Samples/service_minimal_client.cs (100%) rename samples/csharp/services/minimal_server/minimal_server.cs => lang/csharp/Continental.eCAL.Core.Samples/service_minimal_server.cs (100%) create mode 100644 lang/csharp/Continental.eCAL.Core.Test/CMakeLists.txt create mode 100644 lang/csharp/Continental.eCAL.Core.Test/test.cs rename lang/csharp/{Continental/eCAL/Core => Continental.eCAL.Core}/AssemblyInfo.cpp (100%) rename lang/csharp/{Continental/eCAL/Core => Continental.eCAL.Core}/CMakeLists.txt (100%) rename lang/csharp/{Continental/eCAL/Core => Continental.eCAL.Core}/ecal_clr.cpp (100%) rename lang/csharp/{Continental/eCAL/Core => Continental.eCAL.Core}/ecal_clr.h (100%) rename {samples/csharp/pubsub/protobuf/protobuf => lang/csharp/Continental.eCAL.Protobuf.Person}/CMakeLists.txt (92%) rename {samples/csharp/pubsub/protobuf/protobuf => lang/csharp/Continental.eCAL.Protobuf.Person}/animal.proto (100%) rename {samples/csharp/pubsub/protobuf/protobuf => lang/csharp/Continental.eCAL.Protobuf.Person}/house.proto (100%) rename {samples/csharp/pubsub/protobuf/protobuf => lang/csharp/Continental.eCAL.Protobuf.Person}/person.proto (100%) rename {samples/csharp/pubsub/protobuf/protobuf => lang/csharp/Continental.eCAL.Protobuf.Person}/protobuf_csharp_helper.cmake (100%) rename {samples/csharp/pubsub/protobuf/person_rec => lang/csharp/Continental.eCAL.Protobuf.Samples}/CMakeLists.txt (57%) rename samples/csharp/pubsub/protobuf/person_rec/person_rec.cs => lang/csharp/Continental.eCAL.Protobuf.Samples/pubsub_person_rec.cs (100%) rename samples/csharp/pubsub/protobuf/person_rec_cb/person_rec_cb.cs => lang/csharp/Continental.eCAL.Protobuf.Samples/pubsub_person_rec_cb.cs (100%) rename samples/csharp/pubsub/protobuf/person_snd/person_snd.cs => lang/csharp/Continental.eCAL.Protobuf.Samples/pubsub_person_snd.cs (100%) create mode 100644 lang/csharp/Continental.eCAL.Protobuf.Test/CMakeLists.txt create mode 100644 lang/csharp/Continental.eCAL.Protobuf.Test/test.cs rename lang/csharp/{Continental/eCAL/Protobuf => Continental.eCAL.Protobuf}/CMakeLists.txt (100%) rename lang/csharp/{Continental/eCAL/Protobuf => Continental.eCAL.Protobuf}/ProtoHelper.cs (100%) rename lang/csharp/{Continental/eCAL/Protobuf => Continental.eCAL.Protobuf}/ProtoPublisher.cs (100%) rename lang/csharp/{Continental/eCAL/Protobuf => Continental.eCAL.Protobuf}/ProtoSubscriber.cs (100%) delete mode 100644 samples/csharp/CMakeLists.txt delete mode 100644 samples/csharp/pubsub/protobuf/person_rec_cb/CMakeLists.txt delete mode 100644 samples/csharp/pubsub/protobuf/person_snd/CMakeLists.txt delete mode 100644 samples/csharp/pubsub/string/minimal_rec_cb/CMakeLists.txt delete mode 100644 samples/csharp/pubsub/string/minimal_snd/CMakeLists.txt delete mode 100644 samples/csharp/services/minimal_client/CMakeLists.txt delete mode 100644 samples/csharp/services/minimal_server/CMakeLists.txt diff --git a/lang/csharp/CMakeLists.txt b/lang/csharp/CMakeLists.txt index 981aefb322..dd77ddb81b 100644 --- a/lang/csharp/CMakeLists.txt +++ b/lang/csharp/CMakeLists.txt @@ -2,12 +2,24 @@ project(ecal_csharp) set(CMAKE_DOTNET_SDK "") -set(ECAL_CSHARP_PROTOBUF_VERSION "3.11.4" CACHE STRING "Protobuf Version for C# build") +set(ECAL_CSHARP_PROTOBUF_VERSION "3.26.1" CACHE STRING "Protobuf Version for C# build") + option(ECAL_CSHARP_BUILD_SAMPLES "BUILD eCAL C# samples" ON) +option(ECAL_CSHARP_BUILD_TESTS "BUILD eCAL C# unittests" ON) -add_subdirectory(Continental/eCAL/Core) -add_subdirectory(Continental/eCAL/Protobuf) +add_subdirectory(Continental.eCAL.Core) +add_subdirectory(Continental.eCAL.Protobuf) +if (ECAL_CSHARP_BUILD_TESTS) +add_subdirectory(Continental.eCAL.Core.Test) +add_subdirectory(Continental.eCAL.Protobuf.Test) +endif() if (ECAL_CSHARP_BUILD_SAMPLES) -add_subdirectory(../../samples/csharp samples) -endif () \ No newline at end of file +add_subdirectory(Continental.eCAL.Core.Samples) +add_subdirectory(Continental.eCAL.Protobuf.Samples) +endif () + +if (ECAL_CSHARP_BUILD_SAMPLES OR ECAL_CSHARP_BUILD_TESTS) +#Contains the person.proto which are being compiled to cs files +add_subdirectory(Continental.eCAL.Protobuf.Person) +endif() diff --git a/samples/csharp/pubsub/string/minimal_rec/CMakeLists.txt b/lang/csharp/Continental.eCAL.Core.Samples/CMakeLists.txt similarity index 59% rename from samples/csharp/pubsub/string/minimal_rec/CMakeLists.txt rename to lang/csharp/Continental.eCAL.Core.Samples/CMakeLists.txt index a93183de86..cd5f8bd016 100644 --- a/samples/csharp/pubsub/string/minimal_rec/CMakeLists.txt +++ b/lang/csharp/Continental.eCAL.Core.Samples/CMakeLists.txt @@ -17,16 +17,26 @@ # ========================= eCAL LICENSE ================================= include(CSharpUtilities) -project(minimal_rec_cs LANGUAGES CSharp) +project(Continental.eCAL.Core.Samples LANGUAGES CSharp) find_package(eCAL REQUIRED) -set(minimal_rec_cs_src - minimal_rec.cs -) -ecal_add_sample(${PROJECT_NAME} ${minimal_rec_cs_src}) +macro(ecal_add_csharp_core_sample sample_name) + ecal_add_sample(${sample_name} ${sample_name}.cs) + target_link_libraries(${sample_name} Continental.eCAL.Core) + set_property(TARGET ${sample_name} PROPERTY FOLDER samples/csharp/core) +endmacro() + +ecal_add_csharp_core_sample(pubsub_minimal_rec) +ecal_add_csharp_core_sample(pubsub_minimal_rec_cb) +ecal_add_csharp_core_sample(pubsub_minimal_snd) + +ecal_add_csharp_core_sample(service_minimal_client) +ecal_add_csharp_core_sample(service_minimal_server) + + + + -target_link_libraries(${PROJECT_NAME} Continental.eCAL.Core) -set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/csharp/pubsub/string) diff --git a/samples/csharp/pubsub/string/minimal_rec/minimal_rec.cs b/lang/csharp/Continental.eCAL.Core.Samples/pubsub_minimal_rec.cs similarity index 100% rename from samples/csharp/pubsub/string/minimal_rec/minimal_rec.cs rename to lang/csharp/Continental.eCAL.Core.Samples/pubsub_minimal_rec.cs diff --git a/samples/csharp/pubsub/string/minimal_rec_cb/minimal_rec_cb.cs b/lang/csharp/Continental.eCAL.Core.Samples/pubsub_minimal_rec_cb.cs similarity index 100% rename from samples/csharp/pubsub/string/minimal_rec_cb/minimal_rec_cb.cs rename to lang/csharp/Continental.eCAL.Core.Samples/pubsub_minimal_rec_cb.cs diff --git a/samples/csharp/pubsub/string/minimal_snd/minimal_snd.cs b/lang/csharp/Continental.eCAL.Core.Samples/pubsub_minimal_snd.cs similarity index 100% rename from samples/csharp/pubsub/string/minimal_snd/minimal_snd.cs rename to lang/csharp/Continental.eCAL.Core.Samples/pubsub_minimal_snd.cs diff --git a/samples/csharp/services/minimal_client/minimal_client.cs b/lang/csharp/Continental.eCAL.Core.Samples/service_minimal_client.cs similarity index 100% rename from samples/csharp/services/minimal_client/minimal_client.cs rename to lang/csharp/Continental.eCAL.Core.Samples/service_minimal_client.cs diff --git a/samples/csharp/services/minimal_server/minimal_server.cs b/lang/csharp/Continental.eCAL.Core.Samples/service_minimal_server.cs similarity index 100% rename from samples/csharp/services/minimal_server/minimal_server.cs rename to lang/csharp/Continental.eCAL.Core.Samples/service_minimal_server.cs diff --git a/lang/csharp/Continental.eCAL.Core.Test/CMakeLists.txt b/lang/csharp/Continental.eCAL.Core.Test/CMakeLists.txt new file mode 100644 index 0000000000..6d85b740c3 --- /dev/null +++ b/lang/csharp/Continental.eCAL.Core.Test/CMakeLists.txt @@ -0,0 +1,51 @@ +# ========================= 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(CSharpUtilities) +project(Continental.eCAL.Core.Test LANGUAGES CSharp) + +add_library(${PROJECT_NAME} SHARED) + +target_sources(${PROJECT_NAME} + PRIVATE + test.cs +) + +target_link_libraries(${PROJECT_NAME} Continental.eCAL.Core) + +set_target_properties(${PROJECT_NAME} PROPERTIES + VS_GLOBAL_ROOTNAMESPACE ${PROJECT_NAME} + VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1" + # mark this is a unit testing project, see https://cmake.org/cmake/help/latest/prop_tgt/VS_GLOBAL_PROJECT_TYPES.html + VS_GLOBAL_PROJECT_TYPES "{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" +) + +set_property(TARGET ${PROJECT_NAME} PROPERTY + VS_PACKAGE_REFERENCES + "MSTest.TestFramework_2.2.10;MSTest.TestAdapter_2.2.10" +) + +install(TARGETS ${PROJECT_NAME} + # IMPORTANT: Add the library to the "export-set" + EXPORT eCALTargets + RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT runtime + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT sdk + PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/ecal" COMPONENT sdk +) + +set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER tests/csharp) diff --git a/lang/csharp/Continental.eCAL.Core.Test/test.cs b/lang/csharp/Continental.eCAL.Core.Test/test.cs new file mode 100644 index 0000000000..43ba740675 --- /dev/null +++ b/lang/csharp/Continental.eCAL.Core.Test/test.cs @@ -0,0 +1,59 @@ +/* ========================= 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 ================================= +*/ + +using System; +using Continental.eCAL.Core; + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; + +[TestClass] +public class eCALBinaryTest +{ + [TestInitialize] + public void Initialize() + { + Continental.eCAL.Core.Util.Initialize("Binary Test C#"); + Continental.eCAL.Core.Util.EnableLoopback(true); + } + + [TestCleanup] + public void Cleanup() + { + Continental.eCAL.Core.Util.Terminate(); + } + + // This test ensures that 0 values which are not present on the wire, are still deserialized correctly. (#1593) + [TestMethod] + public void PublishSubscribeTest() + { + // create a subscriber + Publisher publisher = new Publisher("Hello", "std::string", "base", ""); + Subscriber subscriber = new Subscriber("Hello", "std::string", "base", ""); + + { + string message = "HELLO WORLD FROM C#"; + publisher.Send(message, -1); + var received_message = subscriber.Receive(100); + Assert.IsNotNull(received_message); + Assert.IsTrue(message == received_message.data); + } + + } +} diff --git a/lang/csharp/Continental/eCAL/Core/AssemblyInfo.cpp b/lang/csharp/Continental.eCAL.Core/AssemblyInfo.cpp similarity index 100% rename from lang/csharp/Continental/eCAL/Core/AssemblyInfo.cpp rename to lang/csharp/Continental.eCAL.Core/AssemblyInfo.cpp diff --git a/lang/csharp/Continental/eCAL/Core/CMakeLists.txt b/lang/csharp/Continental.eCAL.Core/CMakeLists.txt similarity index 100% rename from lang/csharp/Continental/eCAL/Core/CMakeLists.txt rename to lang/csharp/Continental.eCAL.Core/CMakeLists.txt diff --git a/lang/csharp/Continental/eCAL/Core/ecal_clr.cpp b/lang/csharp/Continental.eCAL.Core/ecal_clr.cpp similarity index 100% rename from lang/csharp/Continental/eCAL/Core/ecal_clr.cpp rename to lang/csharp/Continental.eCAL.Core/ecal_clr.cpp diff --git a/lang/csharp/Continental/eCAL/Core/ecal_clr.h b/lang/csharp/Continental.eCAL.Core/ecal_clr.h similarity index 100% rename from lang/csharp/Continental/eCAL/Core/ecal_clr.h rename to lang/csharp/Continental.eCAL.Core/ecal_clr.h diff --git a/samples/csharp/pubsub/protobuf/protobuf/CMakeLists.txt b/lang/csharp/Continental.eCAL.Protobuf.Person/CMakeLists.txt similarity index 92% rename from samples/csharp/pubsub/protobuf/protobuf/CMakeLists.txt rename to lang/csharp/Continental.eCAL.Protobuf.Person/CMakeLists.txt index c7afb3af5d..6d077fb7b3 100644 --- a/samples/csharp/pubsub/protobuf/protobuf/CMakeLists.txt +++ b/lang/csharp/Continental.eCAL.Protobuf.Person/CMakeLists.txt @@ -24,9 +24,9 @@ include(CSharpUtilities) find_package(Protobuf REQUIRED) include(protobuf_csharp_helper.cmake) -project(person_protobufs_cs LANGUAGES CSharp) +project(Continental.eCAL.Protobuf.Person LANGUAGES CSharp) -add_library(person_protobufs_cs SHARED) +add_library(Continental.eCAL.Protobuf.Person SHARED) PROTOBUF_TARGET_CSHARP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/animal.proto @@ -44,4 +44,4 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY VS_PACKAGE_REFERENCES "Google.Protobuf_${ECAL_CSHARP_PROTOBUF_VERSION}" ) -set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/csharp/pubsub/protobuf) \ No newline at end of file +set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/csharp/protobuf) \ No newline at end of file diff --git a/samples/csharp/pubsub/protobuf/protobuf/animal.proto b/lang/csharp/Continental.eCAL.Protobuf.Person/animal.proto similarity index 100% rename from samples/csharp/pubsub/protobuf/protobuf/animal.proto rename to lang/csharp/Continental.eCAL.Protobuf.Person/animal.proto diff --git a/samples/csharp/pubsub/protobuf/protobuf/house.proto b/lang/csharp/Continental.eCAL.Protobuf.Person/house.proto similarity index 100% rename from samples/csharp/pubsub/protobuf/protobuf/house.proto rename to lang/csharp/Continental.eCAL.Protobuf.Person/house.proto diff --git a/samples/csharp/pubsub/protobuf/protobuf/person.proto b/lang/csharp/Continental.eCAL.Protobuf.Person/person.proto similarity index 100% rename from samples/csharp/pubsub/protobuf/protobuf/person.proto rename to lang/csharp/Continental.eCAL.Protobuf.Person/person.proto diff --git a/samples/csharp/pubsub/protobuf/protobuf/protobuf_csharp_helper.cmake b/lang/csharp/Continental.eCAL.Protobuf.Person/protobuf_csharp_helper.cmake similarity index 100% rename from samples/csharp/pubsub/protobuf/protobuf/protobuf_csharp_helper.cmake rename to lang/csharp/Continental.eCAL.Protobuf.Person/protobuf_csharp_helper.cmake diff --git a/samples/csharp/pubsub/protobuf/person_rec/CMakeLists.txt b/lang/csharp/Continental.eCAL.Protobuf.Samples/CMakeLists.txt similarity index 57% rename from samples/csharp/pubsub/protobuf/person_rec/CMakeLists.txt rename to lang/csharp/Continental.eCAL.Protobuf.Samples/CMakeLists.txt index a167549d0c..446a5b134c 100644 --- a/samples/csharp/pubsub/protobuf/person_rec/CMakeLists.txt +++ b/lang/csharp/Continental.eCAL.Protobuf.Samples/CMakeLists.txt @@ -21,21 +21,22 @@ project(person_rec_cs LANGUAGES CSharp) find_package(eCAL REQUIRED) -set(person_rec_cs_src - person_rec.cs -) - -ecal_add_sample(${PROJECT_NAME} ${person_rec_cs_src}) - -target_link_libraries(${PROJECT_NAME} Continental.eCAL.Protobuf person_protobufs_cs) - -set_target_properties(${PROJECT_NAME} PROPERTIES - VS_GLOBAL_ROOTNAMESPACE ${PROJECT_NAME} +macro(ecal_add_csharp_protobuf_sample sample_name) + ecal_add_sample(${sample_name} ${sample_name}.cs) + target_link_libraries(${sample_name} Continental.eCAL.Protobuf Continental.eCAL.Protobuf.Person) + set_property(TARGET ${sample_name} PROPERTY FOLDER samples/csharp/protobuf) + + set_target_properties(${sample_name} PROPERTIES + VS_GLOBAL_ROOTNAMESPACE ${sample_name} VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1" -) + ) + + set_property(TARGET ${sample_name} PROPERTY + VS_PACKAGE_REFERENCES "Google.Protobuf_${ECAL_CSHARP_PROTOBUF_VERSION}" + ) +endmacro() -set_property(TARGET ${PROJECT_NAME} PROPERTY - VS_PACKAGE_REFERENCES "Google.Protobuf_${ECAL_CSHARP_PROTOBUF_VERSION}" -) +ecal_add_csharp_protobuf_sample(pubsub_person_rec) +ecal_add_csharp_protobuf_sample(pubsub_person_rec_cb) +ecal_add_csharp_protobuf_sample(pubsub_person_snd) -set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/csharp/pubsub/protobuf) diff --git a/samples/csharp/pubsub/protobuf/person_rec/person_rec.cs b/lang/csharp/Continental.eCAL.Protobuf.Samples/pubsub_person_rec.cs similarity index 100% rename from samples/csharp/pubsub/protobuf/person_rec/person_rec.cs rename to lang/csharp/Continental.eCAL.Protobuf.Samples/pubsub_person_rec.cs diff --git a/samples/csharp/pubsub/protobuf/person_rec_cb/person_rec_cb.cs b/lang/csharp/Continental.eCAL.Protobuf.Samples/pubsub_person_rec_cb.cs similarity index 100% rename from samples/csharp/pubsub/protobuf/person_rec_cb/person_rec_cb.cs rename to lang/csharp/Continental.eCAL.Protobuf.Samples/pubsub_person_rec_cb.cs diff --git a/samples/csharp/pubsub/protobuf/person_snd/person_snd.cs b/lang/csharp/Continental.eCAL.Protobuf.Samples/pubsub_person_snd.cs similarity index 100% rename from samples/csharp/pubsub/protobuf/person_snd/person_snd.cs rename to lang/csharp/Continental.eCAL.Protobuf.Samples/pubsub_person_snd.cs diff --git a/lang/csharp/Continental.eCAL.Protobuf.Test/CMakeLists.txt b/lang/csharp/Continental.eCAL.Protobuf.Test/CMakeLists.txt new file mode 100644 index 0000000000..f30be22ed0 --- /dev/null +++ b/lang/csharp/Continental.eCAL.Protobuf.Test/CMakeLists.txt @@ -0,0 +1,51 @@ +# ========================= 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(CSharpUtilities) +project(Continental.eCAL.Protobuf.Test LANGUAGES CSharp) + +add_library(${PROJECT_NAME} SHARED) + +target_sources(${PROJECT_NAME} + PRIVATE + test.cs +) + +target_link_libraries(${PROJECT_NAME} Continental.eCAL.Protobuf Continental.eCAL.Protobuf.Person) + +set_target_properties(${PROJECT_NAME} PROPERTIES + VS_GLOBAL_ROOTNAMESPACE ${PROJECT_NAME} + VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1" + # mark this is a unit testing project, see https://cmake.org/cmake/help/latest/prop_tgt/VS_GLOBAL_PROJECT_TYPES.html + VS_GLOBAL_PROJECT_TYPES "{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" +) + +set_property(TARGET ${PROJECT_NAME} PROPERTY + VS_PACKAGE_REFERENCES + "Google.Protobuf_${ECAL_CSHARP_PROTOBUF_VERSION};MSTest.TestFramework_2.2.10;MSTest.TestAdapter_2.2.10" +) + +install(TARGETS ${PROJECT_NAME} + # IMPORTANT: Add the library to the "export-set" + EXPORT eCALTargets + RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT runtime + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT sdk + PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/ecal" COMPONENT sdk +) + +set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER tests/csharp) diff --git a/lang/csharp/Continental.eCAL.Protobuf.Test/test.cs b/lang/csharp/Continental.eCAL.Protobuf.Test/test.cs new file mode 100644 index 0000000000..04ebc9ae4b --- /dev/null +++ b/lang/csharp/Continental.eCAL.Protobuf.Test/test.cs @@ -0,0 +1,96 @@ +/* ========================= 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 ================================= +*/ + +using System; +using Continental.eCAL.Core; + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; + + +[TestClass] +public class ProtobufTest +{ + [TestInitialize] + public void Initialize() + { + Util.Initialize("Person Test C#"); + Util.EnableLoopback(true); + } + + [TestCleanup] + public void Cleanup() + { + Util.Terminate(); + } + + // This test ensures that 0 values which are not present on the wire, are still deserialized correctly. (#1593) + [TestMethod] + public void PublishSubscribeTest() + { + // Publisher + var publisher = new ProtobufPublisher("example_topic"); + var subscriber = new ProtobufSubscriber("example_topic"); + + var person0 = new Pb.People.Person + { + Id = 0, + Email = "max@online.de", + Name = "Max", + Stype = Pb.People.Person.Types.SType.Female, + Dog = new Pb.Animal.Dog { Name = "Brandy" }, + House = new Pb.Environment.House { Rooms = 4 } + }; + + var person1 = new Pb.People.Person + { + Id = 1, + Email = "max@online.de", + Name = "Max", + Stype = Pb.People.Person.Types.SType.Female, + Dog = new Pb.Animal.Dog { Name = "Brandy" }, + House = new Pb.Environment.House { Rooms = 4 } + }; + + Task.Delay(2000).Wait(); + + { + publisher.Send(person0); + var person_rec_0 = subscriber.Receive(100); + Assert.IsNotNull(person_rec_0); + Assert.IsTrue(person0.Id == person_rec_0.data.Id); + } + + { + publisher.Send(person1); + var person_rec_1 = subscriber.Receive(100); + Assert.IsNotNull(person_rec_1); + Assert.IsTrue(person1.Id == person_rec_1.data.Id); + } + + { + publisher.Send(person0); + var person_rec_0 = subscriber.Receive(100); + Assert.IsNotNull(person_rec_0); + Assert.IsTrue(person0.Id == person_rec_0.data.Id); + } + } +} + + diff --git a/lang/csharp/Continental/eCAL/Protobuf/CMakeLists.txt b/lang/csharp/Continental.eCAL.Protobuf/CMakeLists.txt similarity index 100% rename from lang/csharp/Continental/eCAL/Protobuf/CMakeLists.txt rename to lang/csharp/Continental.eCAL.Protobuf/CMakeLists.txt diff --git a/lang/csharp/Continental/eCAL/Protobuf/ProtoHelper.cs b/lang/csharp/Continental.eCAL.Protobuf/ProtoHelper.cs similarity index 100% rename from lang/csharp/Continental/eCAL/Protobuf/ProtoHelper.cs rename to lang/csharp/Continental.eCAL.Protobuf/ProtoHelper.cs diff --git a/lang/csharp/Continental/eCAL/Protobuf/ProtoPublisher.cs b/lang/csharp/Continental.eCAL.Protobuf/ProtoPublisher.cs similarity index 100% rename from lang/csharp/Continental/eCAL/Protobuf/ProtoPublisher.cs rename to lang/csharp/Continental.eCAL.Protobuf/ProtoPublisher.cs diff --git a/lang/csharp/Continental/eCAL/Protobuf/ProtoSubscriber.cs b/lang/csharp/Continental.eCAL.Protobuf/ProtoSubscriber.cs similarity index 100% rename from lang/csharp/Continental/eCAL/Protobuf/ProtoSubscriber.cs rename to lang/csharp/Continental.eCAL.Protobuf/ProtoSubscriber.cs diff --git a/samples/csharp/CMakeLists.txt b/samples/csharp/CMakeLists.txt deleted file mode 100644 index e4e9795f9a..0000000000 --- a/samples/csharp/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# pubsub -add_subdirectory(pubsub/protobuf/person_rec) -add_subdirectory(pubsub/protobuf/person_rec_cb) -add_subdirectory(pubsub/protobuf/person_snd) -add_subdirectory(pubsub/protobuf/protobuf) -add_subdirectory(pubsub/string/minimal_rec) -add_subdirectory(pubsub/string/minimal_rec_cb) -add_subdirectory(pubsub/string/minimal_snd) - -# services -add_subdirectory(services/minimal_client) -add_subdirectory(services/minimal_server) diff --git a/samples/csharp/pubsub/protobuf/person_rec_cb/CMakeLists.txt b/samples/csharp/pubsub/protobuf/person_rec_cb/CMakeLists.txt deleted file mode 100644 index 0c03648bb1..0000000000 --- a/samples/csharp/pubsub/protobuf/person_rec_cb/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# ========================= eCAL LICENSE ================================= -# -# Copyright (C) 2016 - 2019 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(CSharpUtilities) -project(person_rec_cb_cs LANGUAGES CSharp) - -find_package(eCAL REQUIRED) - -set(minimal_rec_cb_cs_src - person_rec_cb.cs -) - -ecal_add_sample(${PROJECT_NAME} ${minimal_rec_cb_cs_src}) - -target_link_libraries(${PROJECT_NAME} Continental.eCAL.Protobuf person_protobufs_cs) - -set_target_properties(${PROJECT_NAME} PROPERTIES - VS_GLOBAL_ROOTNAMESPACE ${PROJECT_NAME} - VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1" -) - -set_property(TARGET ${PROJECT_NAME} PROPERTY - VS_PACKAGE_REFERENCES "Google.Protobuf_${ECAL_CSHARP_PROTOBUF_VERSION}" -) - -set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/csharp/pubsub/protobuf) diff --git a/samples/csharp/pubsub/protobuf/person_snd/CMakeLists.txt b/samples/csharp/pubsub/protobuf/person_snd/CMakeLists.txt deleted file mode 100644 index 7540b23696..0000000000 --- a/samples/csharp/pubsub/protobuf/person_snd/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# ========================= eCAL LICENSE ================================= -# -# Copyright (C) 2016 - 2019 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(CSharpUtilities) -project(person_snd_cs LANGUAGES CSharp) - -find_package(eCAL REQUIRED) - -set(person_snd_cs_src - person_snd.cs -) - -ecal_add_sample(${PROJECT_NAME} ${person_snd_cs_src}) - -target_link_libraries(${PROJECT_NAME} Continental.eCAL.Protobuf person_protobufs_cs) - -set_target_properties(${PROJECT_NAME} PROPERTIES - VS_GLOBAL_ROOTNAMESPACE ${PROJECT_NAME} - VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1" -) - -set_property(TARGET ${PROJECT_NAME} PROPERTY - VS_PACKAGE_REFERENCES "Google.Protobuf_${ECAL_CSHARP_PROTOBUF_VERSION}" -) - -set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/csharp/pubsub/protobuf) diff --git a/samples/csharp/pubsub/string/minimal_rec_cb/CMakeLists.txt b/samples/csharp/pubsub/string/minimal_rec_cb/CMakeLists.txt deleted file mode 100644 index a310a1fd59..0000000000 --- a/samples/csharp/pubsub/string/minimal_rec_cb/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# ========================= eCAL LICENSE ================================= -# -# Copyright (C) 2016 - 2019 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(CSharpUtilities) -project(minimal_rec_cb_cs LANGUAGES CSharp) - -find_package(eCAL REQUIRED) - -set(minimal_rec_cb_cs_src - minimal_rec_cb.cs -) - -ecal_add_sample(${PROJECT_NAME} ${minimal_rec_cb_cs_src}) - -target_link_libraries(${PROJECT_NAME} Continental.eCAL.Core) - -set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/csharp/pubsub/string) diff --git a/samples/csharp/pubsub/string/minimal_snd/CMakeLists.txt b/samples/csharp/pubsub/string/minimal_snd/CMakeLists.txt deleted file mode 100644 index 6a532c0beb..0000000000 --- a/samples/csharp/pubsub/string/minimal_snd/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# ========================= eCAL LICENSE ================================= -# -# Copyright (C) 2016 - 2019 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(CSharpUtilities) -project(minimal_snd_cs LANGUAGES CSharp) - -find_package(eCAL REQUIRED) - -set(minimal_snd_cs_src - minimal_snd.cs -) - -ecal_add_sample(${PROJECT_NAME} ${minimal_snd_cs_src}) - -target_link_libraries(${PROJECT_NAME} Continental.eCAL.Core) - -set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/csharp/pubsub/string) diff --git a/samples/csharp/services/minimal_client/CMakeLists.txt b/samples/csharp/services/minimal_client/CMakeLists.txt deleted file mode 100644 index 5fad8e63f2..0000000000 --- a/samples/csharp/services/minimal_client/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# ========================= eCAL LICENSE ================================= -# -# Copyright (C) 2016 - 2019 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(CSharpUtilities) -project(minimal_client_cs LANGUAGES CSharp) - -find_package(eCAL REQUIRED) - -ecal_add_sample(minimal_client_cs minimal_client.cs) - -target_link_libraries(minimal_client_cs PRIVATE Continental.eCAL.Core) - -set_property(TARGET minimal_client_cs PROPERTY FOLDER samples/csharp/services/minimal) diff --git a/samples/csharp/services/minimal_server/CMakeLists.txt b/samples/csharp/services/minimal_server/CMakeLists.txt deleted file mode 100644 index 73ff6d6485..0000000000 --- a/samples/csharp/services/minimal_server/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# ========================= eCAL LICENSE ================================= -# -# Copyright (C) 2016 - 2019 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(CSharpUtilities) -project(minimal_server_cs LANGUAGES CSharp) - -find_package(eCAL REQUIRED) - -ecal_add_sample(minimal_server_cs minimal_server.cs) - -target_link_libraries(minimal_server_cs PRIVATE Continental.eCAL.Core) - -set_property(TARGET minimal_server_cs PROPERTY FOLDER samples/csharp/services/minimal)