Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Implemented CDR include IDL files #260

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions Native/OpenDDSharp.IdlGenerator/csharp_cdr_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,27 @@ csharp_cdr_generator::implement_to_cdr_field(AST_Type *field_type, std::string f
break;
}
case AST_Decl::NT_struct: {
ret.append(indent);
ret.append(" writer.WriteBytes(");
ret.append(field_name);
ret.append(".ToCDR());\n");
ret.append(" if (");
ret.append(field_name);
ret.append(" == null)\n");

ret.append(indent);
ret.append(" {\n");

ret.append(indent);
ret.append(" ");
ret.append(field_name);
ret.append(" = new ");
ret.append(replaceString(std::string(field_type->full_name()), std::string("::"), std::string(".")));
ret.append("();\n");

ret.append(indent);
ret.append(" }\n");

ret.append(indent);
ret.append(" ");
ret.append(field_name);
ret.append(".ToCDR(writer);\n");
break;
}
case AST_Decl::NT_string: {
Expand Down
79 changes: 79 additions & 0 deletions Tests/OpenDDSharp.UnitTest/CodeGeneratorCdrWrapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading;
using CdrWrapper;
using CdrWrapperInclude;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenDDSharp.DDS;
using OpenDDSharp.UnitTest.Helpers;
Expand Down Expand Up @@ -74,6 +75,84 @@ public void TestCleanup()
#endregion

#region Test Methods
/// <summary>
/// Test include idl files.
/// </summary>
[TestMethod]
[TestCategory(TEST_CATEGORY)]
public void TestInclude()
{
using var evt = new ManualResetEventSlim(false);

var test = new TestInclude();
Assert.AreEqual(typeof(IncludeStruct), test.IncludeField.GetType());
Assert.IsNotNull(test.IncludeField);
Assert.AreEqual(test.IncludeField.Message.GetType(), typeof(string));

var typeSupport = new TestIncludeTypeSupport();
var typeName = typeSupport.GetTypeName();
var ret = typeSupport.RegisterType(_participant, typeName);
Assert.AreEqual(ReturnCode.Ok, ret);

var topic = _participant.CreateTopic("TestTopic", typeName);
Assert.IsNotNull(topic);

var drQos = new DataReaderQos
{
Reliability =
{
Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos,
},
};
var dr = _subscriber.CreateDataReader(topic, drQos);
Assert.IsNotNull(dr);
var dataReader = new TestIncludeDataReader(dr);

var statusCondition = dr.StatusCondition;
Assert.IsNotNull(statusCondition);
statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus;
TestHelper.CreateWaitSetThread(evt, statusCondition);

var dw = _publisher.CreateDataWriter(topic);
Assert.IsNotNull(dw);
var dataWriter = new TestIncludeDataWriter(dw);

Assert.IsTrue(dataWriter.WaitForSubscriptions(1, 5000));
Assert.IsTrue(dataReader.WaitForPublications(1, 5000));

test = new TestInclude
{
Id = "1",
IncludeField = new IncludeStruct
{
Message = "Test",
},
};
ret = dataWriter.Write(test);
Assert.AreEqual(ReturnCode.Ok, ret);

ret = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, ret);

Assert.IsTrue(evt.Wait(1_500));

var received = new TestInclude();
var sampleInfo = new SampleInfo();
ret = dataReader.ReadNextSample(received, sampleInfo);
Assert.AreEqual(ReturnCode.Ok, ret);

Assert.AreEqual(test.Id, received.Id);
Assert.AreEqual(test.IncludeField.Message, received.IncludeField.Message);

dr.DeleteContainedEntities();
_subscriber.DeleteDataReader(dr);
_subscriber.DeleteContainedEntities();
_publisher.DeleteDataWriter(dw);
_publisher.DeleteContainedEntities();
_participant.DeleteTopic(topic);
_participant.DeleteContainedEntities();
}

/// <summary>
/// Test the code generated for the primitives types.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Tests/OpenDDSharp.UnitTest/OpenDDSharp.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.1" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions Tests/TestIdlCdr/IDL/Test.idl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "TestInclude.idl"

module CdrWrapper {

const short TEST_SHORT_CONST = -1;
Expand Down Expand Up @@ -149,6 +151,12 @@ module CdrWrapper {
StructMultiArrayType StructMultiArrayField;
};

@topic
struct TestInclude {
@key string Id;
CdrWrapperInclude::IncludeStruct IncludeField;
};

@topic
struct TestPrimitive {
boolean BoolField;
Expand Down
8 changes: 8 additions & 0 deletions Tests/TestIdlCdr/IDL/TestInclude.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module CdrWrapperInclude {

@topic
struct IncludeStruct {
@key string Message;
};

};
Loading