0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-20 00:18:02 +03:00

unbreak tests

This commit is contained in:
bird_egop
2025-04-14 23:08:52 +03:00
parent 685eeda03d
commit 9117830ff1
41 changed files with 3820 additions and 736 deletions

View File

@ -1,4 +1,5 @@
using X86Disassembler.X86;
using X86Disassembler.X86.Operands;
namespace X86DisassemblerTests.InstructionTests;
@ -24,8 +25,23 @@ public class AndInstructionTests
// Assert
Assert.NotNull(instruction);
Assert.Equal("and", instruction.Mnemonic);
Assert.Equal("eax, 0x12345678", instruction.Operands);
Assert.Equal(InstructionType.And, instruction.Type);
// Check that we have two operands
Assert.Equal(2, instruction.StructuredOperands.Count);
// Check the first operand (EAX)
var eaxOperand = instruction.StructuredOperands[0];
Assert.IsType<RegisterOperand>(eaxOperand);
var registerOperand = (RegisterOperand)eaxOperand;
Assert.Equal(RegisterIndex.A, registerOperand.Register);
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EAX)
// Check the second operand (immediate value)
var immOperand = instruction.StructuredOperands[1];
Assert.IsType<ImmediateOperand>(immOperand);
var immediateOperand = (ImmediateOperand)immOperand;
Assert.Equal(0x12345678U, immediateOperand.Value);
}
/// <summary>
@ -45,15 +61,30 @@ public class AndInstructionTests
// Assert
Assert.NotNull(instruction);
Assert.Equal("and", instruction.Mnemonic);
Assert.Equal("eax, 0x00000042", instruction.Operands);
Assert.Equal(InstructionType.And, instruction.Type);
// Check that we have two operands
Assert.Equal(2, instruction.StructuredOperands.Count);
// Check the first operand (EAX)
var eaxOperand = instruction.StructuredOperands[0];
Assert.IsType<RegisterOperand>(eaxOperand);
var registerOperand = (RegisterOperand)eaxOperand;
Assert.Equal(RegisterIndex.A, registerOperand.Register);
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EAX)
// Check the second operand (immediate value)
var immOperand = instruction.StructuredOperands[1];
Assert.IsType<ImmediateOperand>(immOperand);
var immediateOperand = (ImmediateOperand)immOperand;
Assert.Equal(0x00000042U, immediateOperand.Value);
}
/// <summary>
/// Tests the AND r32, r/m32 instruction
/// Tests the AndRegMemHandler for decoding AND r32, r/m32 instruction
/// </summary>
[Fact]
public void And_DecodesAndR32Rm32_Correctly()
public void AndRegMemHandler_DecodesAndR32Rm32_Correctly()
{
// Arrange
// AND EAX, ECX (23 C1) - ModR/M byte C1 = 11 000 001 (mod=3, reg=0, rm=1)
@ -66,15 +97,31 @@ public class AndInstructionTests
// Assert
Assert.NotNull(instruction);
Assert.Equal("and", instruction.Mnemonic);
Assert.Equal("eax, ecx", instruction.Operands);
Assert.Equal(InstructionType.And, instruction.Type);
// Check that we have two operands
Assert.Equal(2, instruction.StructuredOperands.Count);
// Check the first operand (EAX)
var eaxOperand = instruction.StructuredOperands[0];
Assert.IsType<RegisterOperand>(eaxOperand);
var registerOperand = (RegisterOperand)eaxOperand;
Assert.Equal(RegisterIndex.A, registerOperand.Register);
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EAX)
// Check the second operand (ECX)
var ecxOperand = instruction.StructuredOperands[1];
Assert.IsType<RegisterOperand>(ecxOperand);
var ecxRegisterOperand = (RegisterOperand)ecxOperand;
Assert.Equal(RegisterIndex.C, ecxRegisterOperand.Register);
Assert.Equal(32, ecxRegisterOperand.Size); // Validate that it's a 32-bit register (ECX)
}
/// <summary>
/// Tests the AND r/m32, r32 instruction
/// Tests the AndMemRegHandler for decoding AND r/m32, r32 instruction
/// </summary>
[Fact]
public void And_DecodesAndRm32R32_Correctly()
public void AndMemRegHandler_DecodesAndRm32R32_Correctly()
{
// Arrange
// AND ECX, EAX (21 C1) - ModR/M byte C1 = 11 000 001 (mod=3, reg=0, rm=1)
@ -87,7 +134,23 @@ public class AndInstructionTests
// Assert
Assert.NotNull(instruction);
Assert.Equal("and", instruction.Mnemonic);
Assert.Equal("ecx, eax", instruction.Operands);
Assert.Equal(InstructionType.And, instruction.Type);
// Check that we have two operands
Assert.Equal(2, instruction.StructuredOperands.Count);
// Check the first operand (ECX)
var ecxOperand = instruction.StructuredOperands[0];
Assert.IsType<RegisterOperand>(ecxOperand);
var ecxRegisterOperand = (RegisterOperand)ecxOperand;
Assert.Equal(RegisterIndex.C, ecxRegisterOperand.Register);
Assert.Equal(32, ecxRegisterOperand.Size); // Validate that it's a 32-bit register (ECX)
// Check the second operand (EAX)
var eaxOperand = instruction.StructuredOperands[1];
Assert.IsType<RegisterOperand>(eaxOperand);
var registerOperand = (RegisterOperand)eaxOperand;
Assert.Equal(RegisterIndex.A, registerOperand.Register);
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EAX)
}
}