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 CreateLabelHandlesNoRemove() { // --- Arrange const string LABEL = "MyLabel"; var dc = new DisassemblyAnnotation(); dc.SetLabel(0x1000, LABEL); // --- Act var result = dc.SetLabel(0x2000, null); // --- Assert result.ShouldBe(false); dc.Labels.Count.ShouldBe(1); }
public void CreateLabelRemovesWhitespaceLabel() { // --- Arrange const string LABEL = "MyLabel"; var dc = new DisassemblyAnnotation(); dc.SetLabel(0x1000, LABEL); // --- Act var result = dc.SetLabel(0x1000, " \t\t \r "); // --- Assert result.ShouldBe(true); dc.Labels.Count.ShouldBe(0); }
public void CreateLabelForbidsDuplicateLabelName() { // --- Arrange const string LABEL = "MyLabel"; var dc = new DisassemblyAnnotation(); dc.SetLabel(0x1000, LABEL); // --- Act var result = dc.SetLabel(0x1100, LABEL); // --- Assert result.ShouldBe(false); dc.Labels.Count.ShouldBe(1); dc.Labels[0x1000].ShouldBe(LABEL); }
public void CreateLabelOverwritesExistingLabel() { // --- Arrange const string LABEL = "MyLabel"; const string LABEL2 = "MyLabel2"; var dc = new DisassemblyAnnotation(); dc.SetLabel(0x1000, LABEL); // --- Act var result = dc.SetLabel(0x1000, LABEL2); // --- Assert result.ShouldBe(true); dc.Labels.Count.ShouldBe(1); dc.Labels[0x1000].ShouldBe(LABEL2); }
public void CreateLabelWorksWithMultipleLabels() { // --- Arrange const string LABEL = "MyLabel"; const string LABEL2 = "MyLabel2"; var dc = new DisassemblyAnnotation(); // --- Act var result1 = dc.SetLabel(0x1000, LABEL); var result2 = dc.SetLabel(0x2000, LABEL2); // --- Assert result1.ShouldBe(true); dc.Labels.Count.ShouldBe(2); dc.Labels[0x1000].ShouldBe(LABEL); result2.ShouldBe(true); dc.Labels[0x2000].ShouldBe(LABEL2); }
public void CreateLabelDoesNotSaveInvalidLabel() { // --- Arrange const string LABEL = "My$$Label$$"; var dc = new DisassemblyAnnotation(); // --- Act var result = dc.SetLabel(0x1000, LABEL); // --- Assert result.ShouldBe(false); dc.Labels.Count.ShouldBe(0); }
public void CreateLabelWorksAsExpected() { // --- Arrange const string LABEL = "MyLabel"; var dc = new DisassemblyAnnotation(); // --- Act var result = dc.SetLabel(0x1000, LABEL); // --- Assert result.ShouldBe(true); dc.Labels.Count.ShouldBe(1); dc.Labels[0x1000].ShouldBe(LABEL); }
public void CreateLabelTruncatesTooLongLabel() { // --- Arrange const string LABEL = "Label012345678901234567890123456789"; var dc = new DisassemblyAnnotation(); // --- Act var result = dc.SetLabel(0x1000, LABEL); // --- Assert result.ShouldBe(true); dc.Labels.Count.ShouldBe(1); dc.Labels[0x1000].ShouldBe(LABEL.Substring(0, DisassemblyAnnotation.MAX_LABEL_LENGTH)); }
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"); }