Skip to content

Commit

Permalink
#80 Added new dbc for testing global properties and definitions and a…
Browse files Browse the repository at this point in the history
…dded unit tests
  • Loading branch information
angalbiati committed Sep 2, 2024
1 parent 89621f7 commit ec6d80c
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
126 changes: 126 additions & 0 deletions DbcFiles/ext_multiplexed.dbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
VERSION ""


NS_ :
NS_DESC_
CM_
BA_DEF_
BA_
VAL_
CAT_DEF_
CAT_
FILTER
BA_DEF_DEF_
EV_DATA_
ENVVAR_DATA_
SGTYPE_
SGTYPE_VAL_
BA_DEF_SGTYPE_
BA_SGTYPE_
SIG_TYPE_REF_
VAL_TABLE_
SIG_GROUP_
SIG_VALTYPE_
SIGTYPE_VALTYPE_
BO_TX_BU_
BA_DEF_REL_
BA_REL_
BA_DEF_DEF_REL_
BU_SG_REL_
BU_EV_REL_
BU_BO_REL_
SG_MUL_VAL_

BS_:

BU_:


BO_ 2348875518 ExtMX_Message: 5 Vector__XXX
SG_ S7 : 36|4@1+ (1,0) [0|0] "" Vector__XXX
SG_ S5 m6 : 4|24@1- (1,0) [0|0] "" Vector__XXX
SG_ S4 m5 : 4|24@1- (1,0) [0|0] "" Vector__XXX
SG_ S3 m4 : 20|16@1- (1,0) [0|0] "" Vector__XXX
SG_ S2 m4 : 4|16@1- (1,0) [0|0] "" Vector__XXX
SG_ S6 m1 : 2|32@1- (1,0) [0|0] "" Vector__XXX
SG_ S1_m m0M : 2|2@1+ (1,0) [0|0] "" Vector__XXX
SG_ S0_m M : 0|2@1+ (1,0) [0|0] "" Vector__XXX


BA_DEF_ SG_ "SigType" ENUM "Default","Range","RangeSigned","ASCII","Discrete","Control","ReferencePGN","DTC","StringDelimiter","StringLength","StringLengthControl","MessageCounter","MessageChecksum";
BA_DEF_ SG_ "GenSigEVName" STRING ;
BA_DEF_ SG_ "GenSigILSupport" ENUM "No","Yes";
BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType";
BA_DEF_ BO_ "GenMsgFastOnStart" INT 0 100000;
BA_DEF_ SG_ "GenSigInactiveValue" INT 0 0;
BA_DEF_ BO_ "GenMsgCycleTimeFast" INT 0 3600000;
BA_DEF_ BO_ "GenMsgNrOfRepetition" INT 0 1000000;
BA_DEF_ SG_ "GenSigStartValue" INT 0 2147483647;
BA_DEF_ BO_ "GenMsgDelayTime" INT 0 1000;
BA_DEF_ BO_ "GenMsgILSupport" ENUM "No","Yes";
BA_DEF_ BO_ "GenMsgStartDelayTime" INT 0 100000;
BA_DEF_ BU_ "NodeLayerModules" STRING ;
BA_DEF_ BU_ "ECU" STRING ;
BA_DEF_ BU_ "NmJ1939SystemInstance" INT 0 15;
BA_DEF_ BU_ "NmJ1939System" INT 0 127;
BA_DEF_ BU_ "NmJ1939ManufacturerCode" INT 0 2047;
BA_DEF_ BU_ "NmJ1939IndustryGroup" INT 0 7;
BA_DEF_ BU_ "NmJ1939IdentityNumber" INT 0 2097151;
BA_DEF_ BU_ "NmJ1939FunctionInstance" INT 0 7;
BA_DEF_ BU_ "NmJ1939Function" INT 0 255;
BA_DEF_ BU_ "NmJ1939ECUInstance" INT 0 3;
BA_DEF_ BU_ "NmJ1939AAC" INT 0 1;
BA_DEF_ BU_ "NmStationAddress" INT 0 255;
BA_DEF_ BO_ "GenMsgSendType" ENUM "cyclic","NotUsed","IfActive","NotUsed","NotUsed","NotUsed","NotUsed","NotUsed","noMsgSendType";
BA_DEF_ BO_ "GenMsgRequestable" INT 0 1;
BA_DEF_ BO_ "GenMsgCycleTime" INT 0 3600000;
BA_DEF_ SG_ "SPN" INT 0 524287;
BA_DEF_ "DBName" STRING ;
BA_DEF_ "BusType" STRING ;
BA_DEF_ "ProtocolType" STRING ;
BA_DEF_ BO_ "VFrameFormat" ENUM "StandardCAN","ExtendedCAN","reserved","J1939PG";
BA_DEF_ EV_ "Age" INT 0 100;
BA_DEF_DEF_ "SigType" "Default";
BA_DEF_DEF_ "GenSigEVName" "Env@Nodename_@Signame";
BA_DEF_DEF_ "GenSigILSupport" "Yes";
BA_DEF_DEF_ "GenSigSendType" "NoSigSendType";
BA_DEF_DEF_ "GenMsgFastOnStart" 0;
BA_DEF_DEF_ "GenSigInactiveValue" 0;
BA_DEF_DEF_ "GenMsgCycleTimeFast" 0;
BA_DEF_DEF_ "GenMsgNrOfRepetition" 0;
BA_DEF_DEF_ "GenSigStartValue" 0;
BA_DEF_DEF_ "GenMsgDelayTime" 0;
BA_DEF_DEF_ "GenMsgILSupport" "Yes";
BA_DEF_DEF_ "GenMsgStartDelayTime" 0;
BA_DEF_DEF_ "NodeLayerModules" "";
BA_DEF_DEF_ "ECU" "";
BA_DEF_DEF_ "NmJ1939SystemInstance" 0;
BA_DEF_DEF_ "NmJ1939System" 0;
BA_DEF_DEF_ "NmJ1939ManufacturerCode" 0;
BA_DEF_DEF_ "NmJ1939IndustryGroup" 0;
BA_DEF_DEF_ "NmJ1939IdentityNumber" 0;
BA_DEF_DEF_ "NmJ1939FunctionInstance" 0;
BA_DEF_DEF_ "NmJ1939Function" 0;
BA_DEF_DEF_ "NmJ1939ECUInstance" 0;
BA_DEF_DEF_ "NmJ1939AAC" 0;
BA_DEF_DEF_ "NmStationAddress" 254;
BA_DEF_DEF_ "GenMsgSendType" "noMsgSendType";
BA_DEF_DEF_ "GenMsgRequestable" 1;
BA_DEF_DEF_ "GenMsgCycleTime" 0;
BA_DEF_DEF_ "SPN" 0;
BA_DEF_DEF_ "DBName" "";
BA_DEF_DEF_ "BusType" "CAN";
BA_DEF_DEF_ "ProtocolType" "J1939";
BA_DEF_DEF_ "VFrameFormat" "StandardCAN";
BA_DEF_DEF_ "Age" 42;

BA_ "DBName" "z_mx";
BA_ "VFrameFormat" BO_ 2348875518 3;
SIG_VALTYPE_ 2348875518 S6 : 1;

SG_MUL_VAL_ 2348875518 S5 S1_m 6-6;
SG_MUL_VAL_ 2348875518 S4 S1_m 5-5;
SG_MUL_VAL_ 2348875518 S3 S1_m 4-4;
SG_MUL_VAL_ 2348875518 S2 S1_m 4-4;
SG_MUL_VAL_ 2348875518 S6 S0_m 1-1;
SG_MUL_VAL_ 2348875518 S1_m S0_m 0-0, 2-2;
47 changes: 47 additions & 0 deletions DbcParserLib.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,5 +419,52 @@ public void MultipleEnvironmentVariableToOneNodeTest()
Assert.That(dbc.Nodes.First().EnvironmentVariables.Last().Key, Is.EqualTo("EnvVarName3"));
Assert.That(dbc.Nodes.First().EnvironmentVariables.Last().Value.Type, Is.EqualTo(EnvDataType.Data));
}

[Test]
public void CheckGlobalPropertiesTest()
{
var file = @"..\..\..\..\DbcFiles\ext_multiplexed.dbc";
var dbc = Parser.ParseFromPath(file);

Assert.That(dbc.GlobalProperties.Count(), Is.EqualTo(3));

var dbName = dbc.GlobalProperties.FirstOrDefault(x => x.CustomPropertyDefinition.Name.Equals("DBName"));
Assert.That(dbName, Is.Not.Null);
Assert.That(dbName.CustomPropertyDefinition.DataType, Is.EqualTo(CustomPropertyDataType.String));
Assert.That(dbName.CustomPropertyDefinition.StringCustomProperty, Is.Not.Null);
Assert.That(dbName.CustomPropertyDefinition.StringCustomProperty.Default, Is.EqualTo(string.Empty));
Assert.That(dbName.StringCustomProperty, Is.Not.Null);
//Assert.That(dbName.StringCustomProperty.Value, Is.EqualTo("z_mx"));

var busType = dbc.GlobalProperties.FirstOrDefault(x => x.CustomPropertyDefinition.Name.Equals("BusType"));
Assert.That(busType, Is.Not.Null);
Assert.That(busType.CustomPropertyDefinition.DataType, Is.EqualTo(CustomPropertyDataType.String));
Assert.That(busType.CustomPropertyDefinition.StringCustomProperty, Is.Not.Null);
Assert.That(busType.CustomPropertyDefinition.StringCustomProperty.Default, Is.EqualTo("CAN"));
Assert.That(busType.StringCustomProperty, Is.Not.Null);
Assert.That(busType.StringCustomProperty.Value, Is.EqualTo("CAN"));

var protocolType = dbc.GlobalProperties.FirstOrDefault(x => x.CustomPropertyDefinition.Name.Equals("ProtocolType"));
Assert.That(protocolType, Is.Not.Null);
Assert.That(protocolType.CustomPropertyDefinition.DataType, Is.EqualTo(CustomPropertyDataType.String));
Assert.That(protocolType.CustomPropertyDefinition.StringCustomProperty, Is.Not.Null);
Assert.That(protocolType.CustomPropertyDefinition.StringCustomProperty.Default, Is.EqualTo("J1939"));
Assert.That(protocolType.StringCustomProperty, Is.Not.Null);
Assert.That(protocolType.StringCustomProperty.Value, Is.EqualTo("J1939"));


var targetMessage = dbc.Messages.FirstOrDefault(x => x.ID == 201391870); // Extended ID
Assert.That(targetMessage, Is.Not.Null);
Assert.That(targetMessage.CustomProperties, Has.Count.EqualTo(10));
Assert.That(targetMessage.CustomProperties["VFrameFormat"].EnumCustomProperty.Value, Is.EqualTo("J1939PG"));

Assert.That(targetMessage.Signals.Count, Is.EqualTo(8));

var floatSignal = targetMessage.Signals.FirstOrDefault(x => x.Name.Equals("S6"));
Assert.That(floatSignal, Is.Not.Null);
Assert.That(floatSignal.ValueType, Is.EqualTo(DbcValueType.IEEEFloat)); // Set with a property

// Should check the extended multiplexing stuff once implemented
}
}
}
29 changes: 29 additions & 0 deletions DbcParserLib.Tests/PropertiesLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,35 @@ public void StringDefinitionCustomPropertyIsParsedTest()
Assert.That(ParseLine(@"BA_DEF_DEF_ ""AttributeName"" ""DefaultString"";", customPropertyLineParsers, builder, nextLineProvider), Is.True);
}

[Test]
public void StringDefinitionCustomPropertyOnEnvironmentVariableIsParsedTest()
{
var builder = new DbcBuilder(new SilentFailureObserver());

var customPropertyLineParsers = CreateParser();
var nextLineProvider = new NextLineProvider(new StringReader(string.Empty));
Assert.That(ParseLine(@"BA_DEF_ EV_ ""AttributeName"" STRING;", customPropertyLineParsers, builder, nextLineProvider), Is.True);
Assert.That(ParseLine(@"BA_DEF_DEF_ ""AttributeName"" ""DefaultString"";", customPropertyLineParsers, builder, nextLineProvider), Is.True);
}

[Test]
public void StringDefinitionCustomPropertyAsGlobalIsParsedTest()
{
var builder = new DbcBuilder(new SilentFailureObserver());

var customPropertyLineParsers = CreateParser();
var nextLineProvider = new NextLineProvider(new StringReader(string.Empty));
Assert.That(ParseLine(@"BA_DEF_ ""AttributeName"" STRING;", customPropertyLineParsers, builder, nextLineProvider), Is.True);
Assert.That(ParseLine(@"BA_DEF_DEF_ ""AttributeName"" ""DefaultString"";", customPropertyLineParsers, builder, nextLineProvider), Is.True);

var dbc = builder.Build();

var globalProperty = dbc.GlobalProperties.FirstOrDefault(x => x.CustomPropertyDefinition.Name.Equals("AttributeName"));
Assert.That(globalProperty, Is.Not.Null);
Assert.That(globalProperty.StringCustomProperty, Is.Not.Null);
Assert.That(globalProperty.StringCustomProperty.Value, Is.EqualTo("DefaultString"));
}

[Test]
public void EnumDefinitionCustomPropertyIsParsedTest()
{
Expand Down

0 comments on commit ec6d80c

Please sign in to comment.