0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-19 20:01:17 +03:00
ParkanPlayground/X86DisassemblerTests/InstructionHandlerFactoryTests.cs

44 lines
1.5 KiB
C#
Raw Normal View History

2025-04-13 01:30:58 +03:00
using System.Reflection;
using X86Disassembler.X86;
using X86Disassembler.X86.Handlers;
namespace X86DisassemblerTests;
public class InstructionHandlerFactoryTests
{
2025-04-13 01:30:58 +03:00
[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);
}
}
}