public void FromBinary_ContentsShouldMatchThatOfBinary_Version3BigEndian() { var binary = FlowScriptBinary.FromFile("TestResources\\Version3BigEndian.bf", BinaryFormatVersion.Version3BigEndian); var script = FlowScript.FromBinary(binary); Assert.AreEqual(script.UserId, binary.Header.UserId); // Compare label names for (int i = 0; i < script.Procedures.Count; i++) { Assert.AreEqual(binary.ProcedureLabelSection[i].Name, script.Procedures[i].Name); } /* * for ( int i = 0; i < script.JumpLabels.Count; i++ ) * { * Assert.AreEqual( binary.JumpLabelSection[i].Name, script.JumpLabels[i].Name ); * } */ // Compare instructions int binaryIndex = 0; foreach (var instruction in script.EnumerateInstructions()) { var binaryInstruction = binary.TextSection[binaryIndex++]; Assert.AreEqual(binaryInstruction.Opcode, instruction.Opcode); if (instruction.Operand != null) { switch (instruction.Operand.Kind) { case Operand.ValueKind.Int16: if (instruction.Opcode != Opcode.IF && instruction.Opcode != Opcode.GOTO) { Assert.AreEqual(binaryInstruction.OperandShort, instruction.Operand.Int16Value); } break; case Operand.ValueKind.Int32: Assert.AreEqual(binary.TextSection[binaryIndex++].OperandInt, instruction.Operand.Int32Value); break; case Operand.ValueKind.Single: Assert.AreEqual(binary.TextSection[binaryIndex++].OperandFloat, instruction.Operand.SingleValue); break; case Operand.ValueKind.String: break; } } } }
public void ToBinary_ContentsShouldMatchThatOfSourceBinary_Version3BigEndian() { var binaryIn = FlowScriptBinary.FromFile("TestResources\\Version3BigEndian.bf"); var script = FlowScript.FromBinary(binaryIn); var binaryOut = script.ToBinary(); // Compare headers Assert.AreEqual(binaryIn.Header.FileType, binaryOut.Header.FileType); Assert.AreEqual(binaryIn.Header.Compressed, binaryOut.Header.Compressed); Assert.AreEqual(binaryIn.Header.UserId, binaryOut.Header.UserId); Assert.AreEqual(binaryIn.Header.FileSize, binaryOut.Header.FileSize); Assert.IsTrue(binaryIn.Header.Magic.SequenceEqual(binaryOut.Header.Magic)); Assert.AreEqual(binaryIn.Header.Field0C, binaryOut.Header.Field0C); Assert.AreEqual(binaryIn.Header.SectionCount, binaryOut.Header.SectionCount); Assert.AreEqual(binaryIn.Header.LocalIntVariableCount, binaryOut.Header.LocalIntVariableCount); Assert.AreEqual(binaryIn.Header.LocalFloatVariableCount, binaryOut.Header.LocalFloatVariableCount); Assert.AreEqual(binaryIn.Header.Endianness, binaryOut.Header.Endianness); Assert.AreEqual(binaryIn.Header.Field1A, binaryOut.Header.Field1A); Assert.AreEqual(binaryIn.Header.Padding, binaryOut.Header.Padding); // Compare section headers for (int i = 0; i < binaryIn.SectionHeaders.Count; i++) { Assert.AreEqual(binaryIn.SectionHeaders[i].SectionType, binaryOut.SectionHeaders[i].SectionType); Assert.AreEqual(binaryIn.SectionHeaders[i].ElementSize, binaryOut.SectionHeaders[i].ElementSize); Assert.AreEqual(binaryIn.SectionHeaders[i].ElementCount, binaryOut.SectionHeaders[i].ElementCount); Assert.AreEqual(binaryIn.SectionHeaders[i].FirstElementAddress, binaryOut.SectionHeaders[i].FirstElementAddress); } // Compare labels for (int i = 0; i < binaryIn.ProcedureLabelSection.Count; i++) { Assert.AreEqual(binaryIn.ProcedureLabelSection[i].Name, binaryOut.ProcedureLabelSection[i].Name); Assert.AreEqual(binaryIn.ProcedureLabelSection[i].InstructionIndex, binaryOut.ProcedureLabelSection[i].InstructionIndex); Assert.AreEqual(binaryIn.ProcedureLabelSection[i].Reserved, binaryOut.ProcedureLabelSection[i].Reserved); } for (int i = 0; i < binaryIn.JumpLabelSection.Count; i++) { Assert.AreEqual(binaryIn.JumpLabelSection[i].Name, binaryOut.JumpLabelSection[i].Name); Assert.AreEqual(binaryIn.JumpLabelSection[i].InstructionIndex, binaryOut.JumpLabelSection[i].InstructionIndex); Assert.AreEqual(binaryIn.JumpLabelSection[i].Reserved, binaryOut.JumpLabelSection[i].Reserved); } // Compare instructions for (int i = 0; i < binaryIn.TextSection.Count; i++) { var inInstruction = binaryIn.TextSection[i]; var outInstruction = binaryOut.TextSection[i]; Assert.AreEqual(inInstruction.Opcode, outInstruction.Opcode); if (inInstruction.Opcode == Opcode.PUSHI || inInstruction.Opcode == Opcode.PUSHF) { ++i; continue; } if (inInstruction.Opcode == Opcode.IF || inInstruction.Opcode == Opcode.GOTO) { Assert.AreEqual(binaryIn.JumpLabelSection[inInstruction.OperandShort].Name, binaryOut.JumpLabelSection[outInstruction.OperandShort].Name); } else { Assert.AreEqual(inInstruction.OperandShort, outInstruction.OperandShort); } } // Compare message script //Assert.IsTrue(binaryIn.MessageScriptSection.SequenceEqual(binaryOut.MessageScriptSection)); // Compare strings Assert.IsTrue(binaryIn.StringSection.SequenceEqual(binaryOut.StringSection)); }