Beispiel #1
0
        public void ShouldParseEnumWithDefinedIfdef()
        {
            var stream = GetStreamWitString(@"typedef enum {
                A_32 = 0,
                #ifdef XYZ
                B_64 = 1,
                #endif
                C_128 = 2
            } Registers;");

            var parser = new RegistersEnumParser(stream, new [] { "XYZ" });

            Assert.AreEqual(3, parser.Registers.Length);
            Assert.AreEqual(0, parser.RegisterGroups.Length);

            Assert.AreEqual("A", parser.Registers[0].Name);
            Assert.AreEqual(32, parser.Registers[0].Width);
            Assert.AreEqual(0, parser.Registers[0].Value);

            Assert.AreEqual("B", parser.Registers[1].Name);
            Assert.AreEqual(64, parser.Registers[1].Width);
            Assert.AreEqual(1, parser.Registers[1].Value);

            Assert.AreEqual("C", parser.Registers[2].Name);
            Assert.AreEqual(128, parser.Registers[2].Width);
            Assert.AreEqual(2, parser.Registers[2].Value);
        }
Beispiel #2
0
        public void ShouldParseEnumWithMultipleValues()
        {
            var stream = GetStreamWitString(@"typedef enum {
                A_32 = 0,
                B_64 = 1,
                C_128 = 2
            } Registers;");

            var parser = new RegistersEnumParser(stream);

            Assert.AreEqual(3, parser.Registers.Length);
            Assert.AreEqual(0, parser.RegisterGroups.Length);

            Assert.AreEqual("A", parser.Registers[0].Name);
            Assert.AreEqual(32, parser.Registers[0].Width);
            Assert.AreEqual(0, parser.Registers[0].Value);

            Assert.AreEqual("B", parser.Registers[1].Name);
            Assert.AreEqual(64, parser.Registers[1].Width);
            Assert.AreEqual(1, parser.Registers[1].Value);

            Assert.AreEqual("C", parser.Registers[2].Name);
            Assert.AreEqual(128, parser.Registers[2].Width);
            Assert.AreEqual(2, parser.Registers[2].Value);
        }
Beispiel #3
0
        public void ShouldParseEnumWithSimpleValue()
        {
            var stream = GetStreamWitString(@"typedef enum {
                A_32 = 0
            } Registers;");

            var parser = new RegistersEnumParser(stream);

            Assert.AreEqual(1, parser.Registers.Length);
            Assert.AreEqual(0, parser.RegisterGroups.Length);

            Assert.AreEqual("A", parser.Registers[0].Name);
            Assert.AreEqual(32, parser.Registers[0].Width);
            Assert.AreEqual(0, parser.Registers[0].Value);
        }
Beispiel #4
0
        public void ShouldParseEnumWithMultipleValuesWithIndices()
        {
            var stream = GetStreamWitString(@"typedef enum {
                A_1_32 = 15,
                A_2_32 = 16,
                A_3_32 = 17
            } Registers;");

            var parser = new RegistersEnumParser(stream);

            Assert.AreEqual(0, parser.Registers.Length);
            Assert.AreEqual(1, parser.RegisterGroups.Length);

            Assert.AreEqual("A", parser.RegisterGroups[0].Name);
            Assert.AreEqual(32, parser.RegisterGroups[0].Width);
            Assert.AreEqual(3, parser.RegisterGroups[0].IndexValueMap.Count);
            Assert.AreEqual(15, parser.RegisterGroups[0].IndexValueMap[1]);
            Assert.AreEqual(16, parser.RegisterGroups[0].IndexValueMap[2]);
            Assert.AreEqual(17, parser.RegisterGroups[0].IndexValueMap[3]);
        }