public void TraceWithoutPacketHeaderThrows() { var metadataText = "trace {" + " major = 1;" + " minor = 8;" + "};"; var parser = GetParser(metadataText); var metadataContext = parser.file(); this.ValidateEmptyErrorListener(); var metadataCustomization = new TestCtfMetadataCustomization(); var listener = new CtfListener(parser, metadataCustomization, metadataCustomization); Assert.IsNotNull(listener.GlobalScope); var treeWalker = new ParseTreeWalker(); Assert.ThrowsException <CtfMetadataException>(() => treeWalker.Walk(listener, metadataContext)); }
public void StringScopeGenerated() { var metadataText = "typealias string { encoding=UTF8; } := utf8_string;"; var parser = GetParser(metadataText); var metadataContext = parser.file(); this.ValidateEmptyErrorListener(); var metadataCustomization = new TestCtfMetadataCustomization(); var listener = new CtfListener(parser, metadataCustomization, metadataCustomization); Assert.IsNotNull(listener.GlobalScope); var treeWalker = new ParseTreeWalker(); treeWalker.Walk(listener, metadataContext); Assert.IsTrue(listener.GlobalScope.Children.Count == 0); }
public void ClockScopeGenerated() { var metadataText = "clock { name = \"testClock\"; };"; var parser = GetParser(metadataText); var metadataContext = parser.file(); this.ValidateEmptyErrorListener(); var metadataCustomization = new TestCtfMetadataCustomization(); var listener = new CtfListener(parser, metadataCustomization, metadataCustomization); Assert.IsNotNull(listener.GlobalScope); var treeWalker = new ParseTreeWalker(); treeWalker.Walk(listener, metadataContext); Assert.IsTrue(listener.GlobalScope.Children.Count == 1); Assert.IsTrue(StringComparer.CurrentCulture.Equals(listener.GlobalScope.Children.First().Key, "clock")); Assert.IsNotNull(listener.GlobalScope.Children["clock"]); }
public void IntegerScopeGenerated() { var metadataText = "typealias integer { size=32; } := uint32;"; var parser = GetParser(metadataText); var metadataContext = parser.file(); this.ValidateEmptyErrorListener(); var metadataCustomization = new TestCtfMetadataCustomization(); var listener = new CtfListener(parser, metadataCustomization, metadataCustomization); Assert.IsNotNull(listener.GlobalScope); var treeWalker = new ParseTreeWalker(); treeWalker.Walk(listener, metadataContext); Assert.IsTrue(listener.GlobalScope.Children.Count == 0); }
private void NamedEnumTest( string typeName, bool baseTypeSigned, ushort baseTypeSize, IList <EnumeratorTestValue> mappings) { var metadataText = new StringBuilder( $"enum {typeName} : integer " + $"{{ size = {baseTypeSize.ToString()}; signed = {baseTypeSigned.ToString()}; }} {{ "); foreach (var mapping in mappings) { metadataText.Append(mapping.ToString()); } metadataText.Append("};"); var parser = GetParser(metadataText.ToString()); var metadataContext = parser.file(); this.ValidateEmptyErrorListener(); var metadataCustomization = new TestCtfMetadataCustomization(); var listener = new CtfListener(parser, metadataCustomization, metadataCustomization); Assert.IsNotNull(listener.GlobalScope); var treeWalker = new ParseTreeWalker(); treeWalker.Walk(listener, metadataContext); bool typeExists = listener.GlobalScope.Types.TryGetValue(typeName, out var typeDeclaration); Assert.IsTrue(typeExists); var ctfMetadataType = typeDeclaration.Type; Assert.IsTrue(ctfMetadataType is CtfEnumDescriptor); var enumType = (CtfEnumDescriptor)ctfMetadataType; Assert.AreEqual(baseTypeSigned, enumType.BaseType.Signed); Assert.AreEqual(baseTypeSize, enumType.BaseType.Size); // According to spec 1.8.2 section 4.1.5, integers that are a multiple of 8-bits are 8-bit aligned. // Otherwise they are one bit aligned Assert.AreEqual((baseTypeSize & 0x07) == 0 ? 8 : 1, enumType.Align); var enumValues = enumType.EnumeratorValues.ToList(); var enumValuesByName = new Dictionary <string, ICtfNamedRange>(); foreach (var enumValue in enumValues) { enumValuesByName.Add(enumValue.Name, enumValue); } Assert.AreEqual(mappings.Count, enumValues.Count()); foreach (var mapping in mappings) { bool mappingExists = enumValuesByName.TryGetValue(mapping.Name.Trim('"'), out var enumValue); Assert.IsTrue(mappingExists); ValidateEnumValue(enumType.BaseType.Signed, enumValue, mapping); } }