Skip to content

Commit

Permalink
EFeru#72 EFeru#69 EFeru#37 EFeru#14 Redfine all Model classes to be r…
Browse files Browse the repository at this point in the history
…eadonly for public access. Use FinishUp method to calc useful properties.
  • Loading branch information
Uight committed Aug 20, 2024
1 parent d269019 commit c4c24f5
Show file tree
Hide file tree
Showing 27 changed files with 1,167 additions and 1,099 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.suo
*.user
*.sln.docstates
.idea
.vs

# Build results
Expand Down
110 changes: 55 additions & 55 deletions DbcParserLib.Tests/DbcBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public void MessageIsAdded()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(1, dbc.Messages.First().ID);
Assert.IsFalse(dbc.Messages.First().IsExtID);
Assert.AreEqual(1, dbc.Messages.First().Value.ID);
Assert.IsFalse(dbc.Messages.First().Value.IsExtID);
}

[Test]
Expand All @@ -119,8 +119,8 @@ public void ExtendedMessageIsAdded()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(1, dbc.Messages.First().ID);
Assert.IsTrue(dbc.Messages.First().IsExtID);
Assert.AreEqual(1, dbc.Messages.First().Value.ID);
Assert.IsTrue(dbc.Messages.First().Value.IsExtID);
}

[Test]
Expand All @@ -134,8 +134,8 @@ public void CommentIsAddedToMessage()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("comment", dbc.Messages.First().Comment);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("comment", dbc.Messages.First().Value.Comment);
}

[Test]
Expand All @@ -149,8 +149,8 @@ public void CommentIsNotAddedToMissingMessage()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.IsNull(dbc.Messages.First().Comment);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.IsNull(dbc.Messages.First().Value.Comment);
}

[Test]
Expand Down Expand Up @@ -178,14 +178,14 @@ public void SignalIsAddedToCurrentMessage()
Assert.AreEqual(2, dbc.Messages.Count());

var messagesToArray = dbc.Messages.ToArray();
Assert.AreEqual(234, messagesToArray[0].ID);
Assert.AreEqual(1, messagesToArray[0].Signals.Count());
Assert.AreEqual("name1", messagesToArray[0].Signals.First().Name);

Assert.AreEqual(235, messagesToArray[1].ID);
Assert.AreEqual(2, messagesToArray[1].Signals.Count());
Assert.AreEqual("name2", messagesToArray[1].Signals.First().Name);
Assert.AreEqual("name3", messagesToArray[1].Signals.Skip(1).First().Name);
Assert.AreEqual(234, messagesToArray[0].Value.ID);
Assert.AreEqual(1, messagesToArray[0].Value.Signals.Count());
Assert.AreEqual("name1", messagesToArray[0].Value.Signals.First().Value.Name);

Assert.AreEqual(235, messagesToArray[1].Value.ID);
Assert.AreEqual(2, messagesToArray[1].Value.Signals.Count());
Assert.AreEqual("name2", messagesToArray[1].Value.Signals.First().Value.Name);
Assert.AreEqual("name3", messagesToArray[1].Value.Signals.Skip(1).First().Value.Name);
}

[Test]
Expand Down Expand Up @@ -213,9 +213,9 @@ public void CommentIsAddedToSignal()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.AreEqual("comment", dbc.Messages.First().Signals.First().Comment);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.AreEqual("comment", dbc.Messages.First().Value.Signals.First().Value.Comment);
}

[Test]
Expand All @@ -232,9 +232,9 @@ public void CommentIsNotAddedToMissingSignalMessageId()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.IsNull(dbc.Messages.First().Signals.First().Comment);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.IsNull(dbc.Messages.First().Value.Signals.First().Value.Comment);
}

[Test]
Expand All @@ -251,9 +251,9 @@ public void CommentIsNotAddedToMissingSignalName()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.IsNull(dbc.Messages.First().Signals.First().Comment);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.IsNull(dbc.Messages.First().Value.Signals.First().Value.Comment);
}

[Test]
Expand All @@ -271,11 +271,11 @@ public void TableValuesAreAddedToSignal()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.AreEqual(testValuesDict, dbc.Messages.First().Signals.First().ValueTableMap);
Assert.AreEqual(1, dbc.Messages.First().Signals.First().ValueTableMap.Keys.First());
Assert.AreEqual("fake", dbc.Messages.First().Signals.First().ValueTableMap.Values.First());
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.AreEqual(testValuesDict, dbc.Messages.First().Value.Signals.First().Value.ValueTableMap);
Assert.AreEqual(1, dbc.Messages.First().Value.Signals.First().Value.ValueTableMap.Keys.First());
Assert.AreEqual("fake", dbc.Messages.First().Value.Signals.First().Value.ValueTableMap.Values.First());
}

[Test]
Expand All @@ -293,11 +293,11 @@ public void TableValuesWithExtendedMessageIdAreAddedToSignal()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(message.ID, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.AreEqual(testValuesDict, dbc.Messages.First().Signals.First().ValueTableMap);
Assert.AreEqual(1, dbc.Messages.First().Signals.First().ValueTableMap.Keys.First());
Assert.AreEqual("fake", dbc.Messages.First().Signals.First().ValueTableMap.Values.First());
Assert.AreEqual(message.ID, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.AreEqual(testValuesDict, dbc.Messages.First().Value.Signals.First().Value.ValueTableMap);
Assert.AreEqual(1, dbc.Messages.First().Value.Signals.First().Value.ValueTableMap.Keys.First());
Assert.AreEqual("fake", dbc.Messages.First().Value.Signals.First().Value.ValueTableMap.Values.First());
}

[Test]
Expand All @@ -315,9 +315,9 @@ public void TableValueIsNotAddedToMissingSignalMessageId()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.IsEmpty(dbc.Messages.First().Signals.First().ValueTableMap);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.IsEmpty(dbc.Messages.First().Value.Signals.First().Value.ValueTableMap);
}

[Test]
Expand All @@ -335,9 +335,9 @@ public void TableValueIsNotAddedToMissingSignalName()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.IsEmpty(dbc.Messages.First().Signals.First().ValueTableMap);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.IsEmpty(dbc.Messages.First().Value.Signals.First().Value.ValueTableMap);
}

[Test]
Expand All @@ -357,11 +357,11 @@ public void NamedTableValuesAreAddedToSignal()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.AreEqual(testValuesDict, dbc.Messages.First().Signals.First().ValueTableMap);
Assert.AreEqual(1, dbc.Messages.First().Signals.First().ValueTableMap.Keys.First());
Assert.AreEqual("fake", dbc.Messages.First().Signals.First().ValueTableMap.Values.First());
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.AreEqual(testValuesDict, dbc.Messages.First().Value.Signals.First().Value.ValueTableMap);
Assert.AreEqual(1, dbc.Messages.First().Value.Signals.First().Value.ValueTableMap.Keys.First());
Assert.AreEqual("fake", dbc.Messages.First().Value.Signals.First().Value.ValueTableMap.Values.First());
}

[Test]
Expand All @@ -381,9 +381,9 @@ public void NamedTableValueIsNotAddedToMissingSignalMessageId()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.IsEmpty(dbc.Messages.First().Signals.First().ValueTableMap);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.IsEmpty(dbc.Messages.First().Value.Signals.First().Value.ValueTableMap);
}

[Test]
Expand All @@ -403,9 +403,9 @@ public void NamedTableValueIsNotAddedToMissingSignalName()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.IsEmpty(dbc.Messages.First().Signals.First().ValueTableMap);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.IsEmpty(dbc.Messages.First().Value.Signals.First().Value.ValueTableMap);
}

[Test]
Expand All @@ -422,9 +422,9 @@ public void NamedTableValueIsNotAddedIfTableNameDoesNotExist()

Assert.IsEmpty(dbc.Nodes);
Assert.AreEqual(1, dbc.Messages.Count());
Assert.AreEqual(234, dbc.Messages.First().ID);
Assert.AreEqual("name1", dbc.Messages.First().Signals.First().Name);
Assert.IsEmpty(dbc.Messages.First().Signals.First().ValueTableMap);
Assert.AreEqual(234, dbc.Messages.First().Value.ID);
Assert.AreEqual("name1", dbc.Messages.First().Value.Signals.First().Value.Name);
Assert.IsEmpty(dbc.Messages.First().Value.Signals.First().Value.ValueTableMap);
}

[Test]
Expand Down
3 changes: 1 addition & 2 deletions DbcParserLib.Tests/DbcParserLib.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
100 changes: 0 additions & 100 deletions DbcParserLib.Tests/ExtensionMethodsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,106 +35,6 @@ public void IntelTest()
Assert.IsTrue(sig.Lsb());
}

[Test]
public void NoMultiplexingTest()
{
var sig = new Signal
{
Multiplexing = null,
};

var multiplexing = sig.MultiplexingInfo();
Assert.AreEqual(MultiplexingRole.None, multiplexing.Role);
Assert.AreEqual(0, multiplexing.Group);
}

[Test]
public void MultiplexorTest()
{
var sig = new Signal
{
Multiplexing = "M",
};

var multiplexing = sig.MultiplexingInfo();
Assert.AreEqual(MultiplexingRole.Multiplexor, multiplexing.Role);
Assert.AreEqual(0, multiplexing.Group);
}

[Test]
public void MultiplexedSingleDigitTest()
{
var sig = new Signal
{
Multiplexing = "m3",
};

var multiplexing = sig.MultiplexingInfo();
Assert.AreEqual(MultiplexingRole.Multiplexed, multiplexing.Role);
Assert.AreEqual(3, multiplexing.Group);
}

[Test]
public void ExtendedMultiplexingIsPartiallySupportedTest()
{
var sig = new Signal
{
Multiplexing = "m3M",
};

var multiplexing = sig.MultiplexingInfo();
Assert.AreEqual(MultiplexingRole.Multiplexed, multiplexing.Role);
Assert.AreEqual(3, multiplexing.Group);
}

[Test]
public void MultiplexedDoubleDigitTest()
{
var sig = new Signal
{
Multiplexing = "m12",
};

var multiplexing = sig.MultiplexingInfo();
Assert.AreEqual(MultiplexingRole.Multiplexed, multiplexing.Role);
Assert.AreEqual(12, multiplexing.Group);
}

[Test]
public void MultiplexedMessageTest()
{
var sig = new Signal
{
Multiplexing = "M",
};

var message = new Message();
message.Signals.Add(sig);

Assert.IsTrue(message.IsMultiplexed());
}

[Test]
public void MessageWithNoMutiplexorIsNotMultiplexedTest()
{
var sig = new Signal
{
Multiplexing = null,
};

var message = new Message();
message.Signals.Add(sig);

Assert.IsFalse(message.IsMultiplexed());
}

[Test]
public void EmptyMessageIsNotMultiplexedTest()
{
var message = new Message();
Assert.IsFalse(message.IsMultiplexed());
}

[TestCase("1 \"First\" 2 \"Second\" 3 \"Third\"")]
[TestCase("1 \"First with spaces\" 2 \" Second \" 3 \"T h i r d\"")]
[TestCase("1 \"First with spaces\" 2 \" \" 3 \"\"")]
Expand Down
Loading

0 comments on commit c4c24f5

Please sign in to comment.