Skip to content

Commit

Permalink
[CSharp] Add meta attribute PRESENCE to generated codecs. Issue real-…
Browse files Browse the repository at this point in the history
  • Loading branch information
billsegall committed Aug 3, 2017
1 parent 963814f commit 5c8c9cb
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ csharp/sbe-generated/baseline
csharp/sbe-generated/baseline-bigendian
csharp/sbe-generated/extension
csharp/sbe-generated/issue435
csharp/sbe-generated/issue483
csharp/sbe-generated/since-deprecated
csharp/sbe-generated/mktdata/*.cs
csharp/sbe-generated/uk_co_real_logic_sbe_benchmarks_fix
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ task(generateCSharpCodecs, type: JavaExec) {
'sbe.validation.xsd': validationXsdPath)
args = ['sbe-tool/src/test/resources/FixBinary.xml',
'sbe-tool/src/test/resources/issue435.xml',
'sbe-tool/src/test/resources/issue483.xml',
'sbe-tool/src/test/resources/since-deprecated-test-schema.xml',
'sbe-tool/src/test/resources/example-bigendian-test-schema.xml',
'sbe-samples/src/main/resources/example-schema.xml',
Expand Down
2 changes: 1 addition & 1 deletion csharp/runtests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MSTEST='/c/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/MSTest.exe'
"$MSTEST" /testcontainer:sbe-tests/bin/Debug/Org.SbeTool.Sbe.UnitTests.dll
"$MSTEST" /testcontainer:sbe-tests/bin/Debug/net45/Org.SbeTool.Sbe.UnitTests.dll

5 changes: 5 additions & 0 deletions csharp/sbe-generated/sbe-generated.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<Description />
</PropertyGroup>

<ItemGroup>
<None Remove="baseline\bill%40harri" />
<None Remove="baseline\Car.cs.good" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\sbe-dll\sbe-dll.csproj" />
</ItemGroup>
Expand Down
44 changes: 44 additions & 0 deletions csharp/sbe-tests/Issue483Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2017 MarketFactory, Inc
//
// 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.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Org.SbeTool.Sbe.Dll;

namespace Org.SbeTool.Sbe.Tests
{
[TestClass]
public unsafe class Issue483Tests
{
private Issue483.Issue483 _issue483;

[TestInitialize]
public void SetUp()
{
_issue483 = new Issue483.Issue483();

}

[TestMethod]
public void PresenceTest()
{
// Check our attributes for their presence meta attribute
Assert.AreEqual(Issue483.Issue483.UnsetMetaAttribute(Issue483.MetaAttribute.Presence), "required");
Assert.AreEqual(Issue483.Issue483.RequiredMetaAttribute(Issue483.MetaAttribute.Presence), "required");
Assert.AreEqual(Issue483.Issue483.ConstantMetaAttribute(Issue483.MetaAttribute.Presence), "constant");
Assert.AreEqual(Issue483.Issue483.OptionalMetaAttribute(Issue483.MetaAttribute.Presence), "optional");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ private void generateMetaAttributeEnum() throws IOException
INDENT + "{\n" +
INDENT + INDENT + "Epoch,\n" +
INDENT + INDENT + "TimeUnit,\n" +
INDENT + INDENT + "SemanticType\n" +
INDENT + INDENT + "SemanticType,\n" +
INDENT + INDENT + "Presence\n" +
INDENT + "}\n" +
"}\n"
);
Expand Down Expand Up @@ -1092,6 +1093,7 @@ private void generateFieldMetaAttributeMethod(final StringBuilder sb, final Toke
final String epoch = encoding.epoch() == null ? "" : encoding.epoch();
final String timeUnit = encoding.timeUnit() == null ? "" : encoding.timeUnit();
final String semanticType = encoding.semanticType() == null ? "" : encoding.semanticType();
final String presence = encoding.presence() == null ? "" : encoding.presence().toString().toLowerCase();

sb.append(String.format(
"\n" +
Expand All @@ -1102,13 +1104,15 @@ private void generateFieldMetaAttributeMethod(final StringBuilder sb, final Toke
indent + INDENT + INDENT + "case MetaAttribute.Epoch: return \"%s\";\n" +
indent + INDENT + INDENT + "case MetaAttribute.TimeUnit: return \"%s\";\n" +
indent + INDENT + INDENT + "case MetaAttribute.SemanticType: return \"%s\";\n" +
indent + INDENT + INDENT + "case MetaAttribute.Presence: return \"%s\";\n" +
indent + INDENT + "}\n\n" +
indent + INDENT + "return \"\";\n" +
indent + "}\n",
toUpperFirstChar(token.name()),
epoch,
timeUnit,
semanticType));
semanticType,
presence));
}

private CharSequence generateEnumFieldNotPresentCondition(
Expand Down
23 changes: 23 additions & 0 deletions sbe-tool/src/test/resources/issue483.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
package="issue483"
id="483"
version="0"
semanticVersion="1.0"
description="issue 483 test case"
byteOrder="bigEndian">
<types>
<composite name="messageHeader" description="Message identifiers and length of message root">
<type name="blockLength" primitiveType="uint16"/>
<type name="templateId" primitiveType="uint16"/>
<type name="schemaId" primitiveType="uint16"/>
<type name="version" primitiveType="uint16"/>
</composite>
</types>
<sbe:message name="issue483" id="1" description="issue 483 test">
<field name="unset" type="uint64" id="2"/>
<field name="required" type="uint64" id="3" presence="required"/>
<field name="constant" type="uint64" id="4" presence="constant"/>
<field name="optional" type="uint64" id="5" presence="optional"/>
</sbe:message>
</sbe:messageSchema>

0 comments on commit 5c8c9cb

Please sign in to comment.