예제 #1
0
        public void SerializationWorksAsExpected()
        {
            // --- Arrange
            var dc = new DisassemblyAnnotation();

            dc.SetLabel(0x0100, "FirstLabel");
            dc.SetLabel(0x0200, "SecondLabel");
            dc.SetComment(0x0100, "FirstComment");
            dc.SetComment(0x0200, "SecondComment");
            dc.SetPrefixComment(0x0100, "FirstPrefixComment");
            dc.SetPrefixComment(0x0200, "SecondPrefixComment");
            dc.AddLiteral(0x0000, "Entry");
            dc.AddLiteral(0x0000, "Start");
            dc.AddLiteral(0x0028, "Calculator");
            dc.MemoryMap.Add(new MemorySection(0x0000, 0x3BFF));
            dc.MemoryMap.Add(new MemorySection(0x3C00, 0x3FFF, MemorySectionType.ByteArray));
            dc.SetLiteralReplacement(0x100, "Entry");
            dc.SetLiteralReplacement(0x1000, "Calculator");

            // --- Act
            var serialized = dc.Serialize();

            DisassemblyAnnotation.Deserialize(serialized, out var back);

            // --- Assert
            dc.Labels.Count.ShouldBe(back.Labels.Count);
            foreach (var item in dc.Labels)
            {
                back.Labels[item.Key].ShouldBe(item.Value);
            }
            dc.Comments.Count.ShouldBe(back.Comments.Count);
            foreach (var item in dc.Comments)
            {
                back.Comments[item.Key].ShouldBe(item.Value);
            }
            dc.PrefixComments.Count.ShouldBe(back.PrefixComments.Count);
            foreach (var item in dc.PrefixComments)
            {
                back.PrefixComments[item.Key].ShouldBe(item.Value);
            }
            dc.Literals.Count.ShouldBe(back.Literals.Count);
            foreach (var item in dc.Literals)
            {
                back.Literals[item.Key].ForEach(v => dc.Literals[item.Key].ShouldContain(v));
                dc.Literals[item.Key].ForEach(v => back.Literals[item.Key].ShouldContain(v));
            }
            dc.LiteralReplacements.Count.ShouldBe(back.LiteralReplacements.Count);
            foreach (var item in dc.LiteralReplacements)
            {
                back.LiteralReplacements[item.Key].ShouldBe(item.Value);
            }
            dc.MemoryMap.Count.ShouldBe(back.MemoryMap.Count);
            for (var i = 0; i < dc.MemoryMap.Count; i++)
            {
                dc.MemoryMap[i].ShouldBe(back.MemoryMap[i]);
            }
        }
        public void CreatePrefixCommentHandlesNoRemove()
        {
            // --- Arrange
            const string COMMENT = "MyComment";
            var          dc      = new DisassemblyAnnotation();

            dc.SetPrefixComment(0x1000, COMMENT);

            // --- Act
            var result = dc.SetPrefixComment(0x2000, null);

            // --- Assert
            result.ShouldBe(false);
            dc.PrefixComments.Count.ShouldBe(1);
        }
        public void CreatePrefixCommentRemovesWhitespaceComment()
        {
            // --- Arrange
            const string COMMENT = "MyComment";
            var          dc      = new DisassemblyAnnotation();

            dc.SetPrefixComment(0x1000, COMMENT);

            // --- Act
            var result = dc.SetPrefixComment(0x1000, "   \t\t \r ");

            // --- Assert
            result.ShouldBe(true);
            dc.PrefixComments.Count.ShouldBe(0);
        }
        public void CreatePrefixCommentOverwritesExistingComment()
        {
            // --- Arrange
            const string COMMENT  = "MyComment";
            const string COMMENT2 = "MyComment2";
            var          dc       = new DisassemblyAnnotation();

            dc.SetPrefixComment(0x1000, COMMENT);

            // --- Act
            var result = dc.SetPrefixComment(0x1000, COMMENT2);

            // --- Assert
            result.ShouldBe(true);
            dc.PrefixComments.Count.ShouldBe(1);
            dc.PrefixComments[0x1000].ShouldBe(COMMENT2);
        }
        public void CreatePrefixCommentWorksWithMultipleComments()
        {
            // --- Arrange
            const string COMMENT  = "MyComment";
            const string COMMENT2 = "MyComment2";
            var          dc       = new DisassemblyAnnotation();

            // --- Act
            var result1 = dc.SetPrefixComment(0x1000, COMMENT);
            var result2 = dc.SetPrefixComment(0x2000, COMMENT2);

            // --- Assert
            result1.ShouldBe(true);
            dc.PrefixComments.Count.ShouldBe(2);
            dc.PrefixComments[0x1000].ShouldBe(COMMENT);
            result2.ShouldBe(true);
            dc.PrefixComments[0x2000].ShouldBe(COMMENT2);
        }
        public void MergeWorksAsExpected()
        {
            // --- Arrange
            var dc = new DisassemblyAnnotation();

            dc.SetLabel(0x0100, "FirstLabel");
            dc.SetLabel(0x0200, "SecondLabel");
            dc.SetComment(0x0100, "FirstComment");
            dc.SetComment(0x0200, "SecondComment");
            dc.SetPrefixComment(0x0100, "FirstPrefixComment");
            dc.SetPrefixComment(0x0200, "SecondPrefixComment");
            dc.AddLiteral(0x0000, "Entry");
            dc.AddLiteral(0x0000, "Start");
            dc.AddLiteral(0x0028, "Calculator");
            dc.MemoryMap.Add(new MemorySection(0x0000, 0x3BFF));
            dc.MemoryMap.Add(new MemorySection(0x3C00, 0x3FFF, MemorySectionType.ByteArray));
            dc.SetLiteralReplacement(0x100, "Entry");
            dc.SetLiteralReplacement(0x1000, "Calculator");

            // --- Act
            var odc = new DisassemblyAnnotation();

            odc.SetLabel(0x0200, "SecondLabelA");
            odc.SetLabel(0x0300, "ThirdLabel");
            odc.SetComment(0x0100, "FirstCommentA");
            odc.SetComment(0x0300, "ThirdComment");
            odc.SetPrefixComment(0x0200, "SecondPrefixCommentA");
            odc.SetPrefixComment(0x0300, "ThirdPrefixComment");
            odc.AddLiteral(0x0000, "Start");
            odc.AddLiteral(0x0028, "CalculatorA");
            odc.MemoryMap.Add(new MemorySection(0x3C00, 0x5BFF, MemorySectionType.ByteArray));
            odc.SetLiteralReplacement(0x100, "Entry");
            odc.SetLiteralReplacement(0x200, "Other");
            odc.SetLiteralReplacement(0x1000, "CalculatorA");
            dc.Merge(odc);

            // --- Assert
            dc.Labels.Count.ShouldBe(3);
            dc.Labels[0x100].ShouldBe("FirstLabel");
            dc.Labels[0x200].ShouldBe("SecondLabelA");
            dc.Labels[0x300].ShouldBe("ThirdLabel");
            dc.Comments.Count.ShouldBe(3);
            dc.Comments[0x100].ShouldBe("FirstCommentA");
            dc.Comments[0x200].ShouldBe("SecondComment");
            dc.Comments[0x300].ShouldBe("ThirdComment");
            dc.PrefixComments.Count.ShouldBe(3);
            dc.PrefixComments[0x100].ShouldBe("FirstPrefixComment");
            dc.PrefixComments[0x200].ShouldBe("SecondPrefixCommentA");
            dc.PrefixComments[0x300].ShouldBe("ThirdPrefixComment");
            dc.Literals.Count.ShouldBe(2);
            dc.Literals[0x0000].Count.ShouldBe(2);
            dc.Literals[0x0000].ShouldContain("Start");
            dc.Literals[0x0000].ShouldContain("Entry");
            dc.Literals[0x0028].Count.ShouldBe(2);
            dc.Literals[0x0028].ShouldContain("Calculator");
            dc.Literals[0x0028].ShouldContain("CalculatorA");
            dc.MemoryMap.Count.ShouldBe(2);
            dc.MemoryMap[0].ShouldBe(new MemorySection(0x0000, 0x3BFF));
            dc.MemoryMap[1].ShouldBe(new MemorySection(0x3C00, 0x5BFF, MemorySectionType.ByteArray));
            dc.LiteralReplacements.Count.ShouldBe(3);
            dc.LiteralReplacements[0x100].ShouldBe("Entry");
            dc.LiteralReplacements[0x200].ShouldBe("Other");
            dc.LiteralReplacements[0x1000].ShouldBe("CalculatorA");
        }