mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-19 03:41:18 +03:00
add factory tests
This commit is contained in:
parent
c701fdb435
commit
28ba47bfab
@ -1,4 +1,4 @@
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticImmediate;
|
||||
namespace X86Disassembler.X86.Handlers.Add;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ADD r/m32, imm32 instruction (0x81 /0)
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticImmediate;
|
||||
namespace X86Disassembler.X86.Handlers.Add;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ADD r/m32, imm8 (sign-extended) instruction (0x83 /0)
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticImmediate;
|
||||
namespace X86Disassembler.X86.Handlers.Add;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ADD r/m8, imm8 instruction (0x80 /0)
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticImmediate;
|
||||
namespace X86Disassembler.X86.Handlers.Cmp;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for CMP r/m32, imm32 instruction (0x81 /7)
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticImmediate;
|
||||
namespace X86Disassembler.X86.Handlers.Cmp;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for CMP r/m32, imm8 (sign-extended) instruction (0x83 /7)
|
||||
|
@ -1,6 +1,44 @@
|
||||
namespace X86DisassemblerTests;
|
||||
using System.Reflection;
|
||||
using X86Disassembler.X86;
|
||||
using X86Disassembler.X86.Handlers;
|
||||
|
||||
namespace X86DisassemblerTests;
|
||||
|
||||
public class InstructionHandlerFactoryTests
|
||||
{
|
||||
[Fact]
|
||||
public void Factory_ShouldNotContainDuplicates()
|
||||
{
|
||||
byte[] code = new byte[] {0xCC, 0xCC, 0xCC};
|
||||
var sut = new InstructionHandlerFactory(code, new InstructionDecoder(code, code.Length), code.Length);
|
||||
|
||||
var handlers = (List<IInstructionHandler>) sut.GetType()
|
||||
.GetField("_handlers", BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.GetValue(sut)!;
|
||||
|
||||
var distinctHandlersCount = handlers.Distinct()
|
||||
.Count();
|
||||
|
||||
Assert.Equal(distinctHandlersCount, handlers.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Factory_ShouldContainAllKnownHandlers()
|
||||
{
|
||||
byte[] code = new byte[] {0xCC, 0xCC, 0xCC};
|
||||
var sut = new InstructionHandlerFactory(code, new InstructionDecoder(code, code.Length), code.Length);
|
||||
|
||||
var handlers = (List<IInstructionHandler>) sut.GetType()
|
||||
.GetField("_handlers", BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.GetValue(sut)!;
|
||||
|
||||
var handlerTypes = typeof(InstructionHandler).Assembly.GetExportedTypes()
|
||||
.Where(x => x.IsAssignableTo(typeof(InstructionHandler)) && x is {IsAbstract: false, IsInterface: false})
|
||||
.ToList();
|
||||
|
||||
foreach (var handlerType in handlerTypes)
|
||||
{
|
||||
Assert.Contains(handlers, x => x.GetType() == handlerType);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user