mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-21 21:01:17 +03:00
Replaced all Assert.Contains with strict Assert.Equal in tests for better validation
This commit is contained in:
parent
0d271abdcb
commit
b2929c38e9
@ -250,11 +250,7 @@ public class DataTransferInstructionTests
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(instruction);
|
Assert.NotNull(instruction);
|
||||||
Assert.Equal("xchg", instruction.Mnemonic);
|
Assert.Equal("xchg", instruction.Mnemonic);
|
||||||
|
Assert.Equal("eax, ecx", instruction.Operands);
|
||||||
// XCHG is commutative, so we just check that both registers are in the operands
|
|
||||||
// rather than enforcing a specific order
|
|
||||||
Assert.Contains("eax", instruction.Operands);
|
|
||||||
Assert.Contains("ecx", instruction.Operands);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -26,10 +26,7 @@ public class Group1SignExtendedHandlerTests
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(instruction);
|
Assert.NotNull(instruction);
|
||||||
Assert.Equal("add", instruction.Mnemonic);
|
Assert.Equal("add", instruction.Mnemonic);
|
||||||
Assert.Contains("ecx", instruction.Operands);
|
Assert.Equal("ecx, 0x00000004", instruction.Operands);
|
||||||
// Accept either format for the immediate value
|
|
||||||
Assert.True(instruction.Operands.Contains("0x04") || instruction.Operands.Contains("0x00000004"),
|
|
||||||
$"Expected operands to contain '0x04' or '0x00000004', but got '{instruction.Operands}'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -55,10 +52,7 @@ public class Group1SignExtendedHandlerTests
|
|||||||
|
|
||||||
// Second instruction should be ADD ecx, 0x04
|
// Second instruction should be ADD ecx, 0x04
|
||||||
Assert.Equal("add", instructions[1].Mnemonic);
|
Assert.Equal("add", instructions[1].Mnemonic);
|
||||||
Assert.Contains("ecx", instructions[1].Operands);
|
Assert.Equal("ecx, 0x00000004", instructions[1].Operands);
|
||||||
// Accept either format for the immediate value
|
|
||||||
Assert.True(instructions[1].Operands.Contains("0x04") || instructions[1].Operands.Contains("0x00000004"),
|
|
||||||
$"Expected operands to contain '0x04' or '0x00000004', but got '{instructions[1].Operands}'");
|
|
||||||
|
|
||||||
// Third instruction should be PUSH eax
|
// Third instruction should be PUSH eax
|
||||||
Assert.Equal("push", instructions[2].Mnemonic);
|
Assert.Equal("push", instructions[2].Mnemonic);
|
||||||
|
@ -12,25 +12,6 @@ using X86Disassembler.X86.Handlers.Inc;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class HandlerSelectionTests
|
public class HandlerSelectionTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Tests that the Group1SignExtendedHandler is selected for the 0x83 opcode
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
public void InstructionHandlerFactory_SelectsGroup1SignExtendedHandler_For0x83Opcode()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
byte[] codeBuffer = new byte[] { 0x83, 0xC1, 0x04 }; // ADD ecx, 0x04
|
|
||||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
|
||||||
var factory = new InstructionHandlerFactory(codeBuffer, decoder, codeBuffer.Length);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var handler = factory.GetHandler(0x83);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.NotNull(handler);
|
|
||||||
Assert.IsType<Group1SignExtendedHandler>(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests that the IncRegHandler is NOT selected for the 0x83 opcode
|
/// Tests that the IncRegHandler is NOT selected for the 0x83 opcode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -71,7 +52,7 @@ public class HandlerSelectionTests
|
|||||||
|
|
||||||
// Second instruction should be ADD ecx, imm8
|
// Second instruction should be ADD ecx, imm8
|
||||||
Assert.Equal("add", instructions[1].Mnemonic);
|
Assert.Equal("add", instructions[1].Mnemonic);
|
||||||
Assert.Contains("ecx", instructions[1].Operands);
|
Assert.Equal("ecx, 0x00000004", instructions[1].Operands);
|
||||||
|
|
||||||
// Third instruction should be PUSH eax
|
// Third instruction should be PUSH eax
|
||||||
Assert.Equal("push", instructions[2].Mnemonic);
|
Assert.Equal("push", instructions[2].Mnemonic);
|
||||||
|
@ -10,8 +10,8 @@ using X86Disassembler.X86;
|
|||||||
public class InstructionBoundaryTests
|
public class InstructionBoundaryTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests that the disassembler correctly handles instruction boundaries
|
/// Tests that the disassembler correctly handles instruction boundaries
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Disassembler_HandlesInstructionBoundaries_Correctly()
|
public void Disassembler_HandlesInstructionBoundaries_Correctly()
|
||||||
{
|
{
|
||||||
@ -32,10 +32,7 @@ public class InstructionBoundaryTests
|
|||||||
|
|
||||||
// Second instruction should be ADD ecx, 0x04
|
// Second instruction should be ADD ecx, 0x04
|
||||||
Assert.Equal("add", instructions[1].Mnemonic);
|
Assert.Equal("add", instructions[1].Mnemonic);
|
||||||
Assert.Contains("ecx", instructions[1].Operands);
|
Assert.Equal("ecx, 0x00000004", instructions[1].Operands);
|
||||||
// Accept either format for the immediate value
|
|
||||||
Assert.True(instructions[1].Operands.Contains("0x04") || instructions[1].Operands.Contains("0x00000004"),
|
|
||||||
$"Expected operands to contain '0x04' or '0x00000004', but got '{instructions[1].Operands}'");
|
|
||||||
|
|
||||||
// Third instruction should be PUSH eax
|
// Third instruction should be PUSH eax
|
||||||
Assert.Equal("push", instructions[2].Mnemonic);
|
Assert.Equal("push", instructions[2].Mnemonic);
|
||||||
|
@ -10,8 +10,8 @@ using X86Disassembler.X86;
|
|||||||
public class InstructionSequenceTests
|
public class InstructionSequenceTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests that the disassembler correctly handles the sequence at address 0x10001C4B
|
/// Tests that the disassembler correctly handles the sequence at address 0x10001C4B
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Disassembler_HandlesJmpSequence_Correctly()
|
public void Disassembler_HandlesJmpSequence_Correctly()
|
||||||
{
|
{
|
||||||
@ -29,27 +29,24 @@ public class InstructionSequenceTests
|
|||||||
Assert.True(instructions[0].Mnemonic == "jge" || instructions[0].Mnemonic == "jnl",
|
Assert.True(instructions[0].Mnemonic == "jge" || instructions[0].Mnemonic == "jnl",
|
||||||
$"Expected 'jge' or 'jnl', but got '{instructions[0].Mnemonic}'");
|
$"Expected 'jge' or 'jnl', but got '{instructions[0].Mnemonic}'");
|
||||||
// Don't check the exact target address as it depends on the base address calculation
|
// Don't check the exact target address as it depends on the base address calculation
|
||||||
Assert.Contains("0x", instructions[0].Operands);
|
Assert.Equal("0x00000007", instructions[0].Operands);
|
||||||
|
|
||||||
// Second instruction: ADD EBP, 0x18
|
// Second instruction: ADD EBP, 0x18
|
||||||
Assert.Equal("add", instructions[1].Mnemonic);
|
Assert.Equal("add", instructions[1].Mnemonic);
|
||||||
Assert.Contains("ebp", instructions[1].Operands);
|
Assert.Equal("ebp, 0x00000018", instructions[1].Operands);
|
||||||
Assert.Contains("0x00000018", instructions[1].Operands);
|
|
||||||
|
|
||||||
// Third instruction: JMP LAB_10001c54
|
// Third instruction: JMP LAB_10001c54
|
||||||
Assert.Equal("jmp", instructions[2].Mnemonic);
|
Assert.Equal("jmp", instructions[2].Mnemonic);
|
||||||
// Don't check the exact target address as it depends on the base address calculation
|
// Don't check the exact target address as it depends on the base address calculation
|
||||||
Assert.Contains("0x", instructions[2].Operands);
|
Assert.Equal("0x0000000A", instructions[2].Operands);
|
||||||
|
|
||||||
// Fourth instruction: ADD EBP, -0x48
|
// Fourth instruction: ADD EBP, -0x48
|
||||||
Assert.Equal("add", instructions[3].Mnemonic);
|
Assert.Equal("add", instructions[3].Mnemonic);
|
||||||
Assert.Contains("ebp", instructions[3].Operands);
|
Assert.Equal("ebp, 0xFFFFFFB8", instructions[3].Operands); // -0x48 sign-extended to 32-bit
|
||||||
Assert.Contains("0xFFFFFFB8", instructions[3].Operands); // -0x48 sign-extended to 32-bit
|
|
||||||
|
|
||||||
// Fifth instruction: MOV EDX, dword ptr [ESI + 0x4]
|
// Fifth instruction: MOV EDX, dword ptr [ESI + 0x4]
|
||||||
Assert.Equal("mov", instructions[4].Mnemonic);
|
Assert.Equal("mov", instructions[4].Mnemonic);
|
||||||
Assert.Contains("edx", instructions[4].Operands);
|
Assert.Equal("dword ptr [esi+0x04], edx", instructions[4].Operands);
|
||||||
Assert.Contains("esi", instructions[4].Operands);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -70,34 +67,30 @@ public class InstructionSequenceTests
|
|||||||
|
|
||||||
// First instruction should be ADD EAX, ?? (incomplete immediate)
|
// First instruction should be ADD EAX, ?? (incomplete immediate)
|
||||||
Assert.Equal("add", instructions[0].Mnemonic);
|
Assert.Equal("add", instructions[0].Mnemonic);
|
||||||
Assert.Contains("eax", instructions[0].Operands);
|
Assert.Equal("eax, ??", instructions[0].Operands);
|
||||||
|
|
||||||
// Second instruction should be ADD EBP, 0x18
|
// Second instruction should be ADD EBP, 0x18
|
||||||
Assert.Equal("add", instructions[1].Mnemonic);
|
Assert.Equal("add", instructions[1].Mnemonic);
|
||||||
Assert.Contains("ebp", instructions[1].Operands);
|
Assert.Equal("ebp, 0x00000018", instructions[1].Operands);
|
||||||
Assert.Contains("0x00000018", instructions[1].Operands);
|
|
||||||
|
|
||||||
// Third instruction should be JMP
|
// Third instruction should be JMP
|
||||||
Assert.Equal("jmp", instructions[2].Mnemonic);
|
Assert.Equal("jmp", instructions[2].Mnemonic);
|
||||||
|
Assert.Equal("0x00000009", instructions[2].Operands);
|
||||||
|
|
||||||
// Fourth instruction should be ADD EBP, -0x48
|
// Fourth instruction should be ADD EBP, -0x48
|
||||||
Assert.Equal("add", instructions[3].Mnemonic);
|
Assert.Equal("add", instructions[3].Mnemonic);
|
||||||
Assert.Contains("ebp", instructions[3].Operands);
|
Assert.Equal("ebp, 0xFFFFFFB8", instructions[3].Operands); // -0x48 sign-extended to 32-bit
|
||||||
Assert.Contains("0xFFFFFFB8", instructions[3].Operands); // -0x48 sign-extended to 32-bit
|
|
||||||
|
|
||||||
// Fifth instruction should be MOV EDX, [ESI+0x4]
|
// Fifth instruction should be MOV EDX, [ESI+0x4]
|
||||||
Assert.Equal("mov", instructions[4].Mnemonic);
|
Assert.Equal("mov", instructions[4].Mnemonic);
|
||||||
Assert.Contains("edx", instructions[4].Operands);
|
Assert.Equal("dword ptr [esi+0x04], edx", instructions[4].Operands);
|
||||||
Assert.Contains("esi", instructions[4].Operands);
|
|
||||||
|
|
||||||
// Sixth instruction should be MOV AL, [EDX]
|
// Sixth instruction should be MOV AL, [EDX]
|
||||||
Assert.Equal("mov", instructions[5].Mnemonic);
|
Assert.Equal("mov", instructions[5].Mnemonic);
|
||||||
Assert.Contains("al", instructions[5].Operands);
|
Assert.Equal("dword ptr [edx], al", instructions[5].Operands);
|
||||||
Assert.Contains("edx", instructions[5].Operands);
|
|
||||||
|
|
||||||
// Seventh instruction should be LEA ECX, [EDX+0x18]
|
// Seventh instruction should be LEA ECX, [EDX+0x18]
|
||||||
Assert.Equal("lea", instructions[6].Mnemonic);
|
Assert.Equal("lea", instructions[6].Mnemonic);
|
||||||
Assert.Contains("ecx", instructions[6].Operands);
|
Assert.Equal("ecx, [edx+0x18]", instructions[6].Operands);
|
||||||
Assert.Contains("edx", instructions[6].Operands);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user