Skip to content

Commit

Permalink
[c#] Folder structure rework.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KerstinKeller committed May 28, 2024
1 parent 419a1d1 commit 13dc444
Show file tree
Hide file tree
Showing 35 changed files with 310 additions and 244 deletions.
22 changes: 17 additions & 5 deletions lang/csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
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()
Original file line number Diff line number Diff line change
Expand Up @@ -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)
51 changes: 51 additions & 0 deletions lang/csharp/Continental.eCAL.Core.Test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
59 changes: 59 additions & 0 deletions lang/csharp/Continental.eCAL.Core.Test/test.cs
Original file line number Diff line number Diff line change
@@ -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);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/csharp/protobuf)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
51 changes: 51 additions & 0 deletions lang/csharp/Continental.eCAL.Protobuf.Test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
96 changes: 96 additions & 0 deletions lang/csharp/Continental.eCAL.Protobuf.Test/test.cs
Original file line number Diff line number Diff line change
@@ -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<Pb.People.Person>("example_topic");
var subscriber = new ProtobufSubscriber<Pb.People.Person>("example_topic");

var person0 = new Pb.People.Person
{
Id = 0,
Email = "[email protected]",
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 = "[email protected]",
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);
}
}
}


12 changes: 0 additions & 12 deletions samples/csharp/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 13dc444

Please sign in to comment.