StocMessage.PromptContext 0x44, PromptContextCodec (23 bytes), EngineApi.ygol_query_prompt_context, Capability.ProtocolVersion 12, tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
82 lines
3.2 KiB
C#
82 lines
3.2 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text.RegularExpressions;
|
|
using NUnit.Framework;
|
|
using YGOLegacy.Engine;
|
|
|
|
namespace YGOLegacy.Engine.Tests
|
|
{
|
|
internal static class ContractFiles
|
|
{
|
|
private const string RepoRoot = "../../../../..";
|
|
|
|
public static string OcgApiHeader => Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, RepoRoot, "contract", "ocgapi.h"));
|
|
public static string CommonHeader => Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, RepoRoot, "core", "common.h"));
|
|
}
|
|
|
|
public class EngineApiParityTests
|
|
{
|
|
private static readonly Regex Export = new Regex(@"^\s*(?:OCGCORE_API|YGOSERVER_API)\s+.*?\b(\w+)\s*\(", RegexOptions.Compiled);
|
|
|
|
private static List<string> HeaderNames()
|
|
{
|
|
return File.ReadLines(ContractFiles.OcgApiHeader)
|
|
.Select(line => Export.Match(line))
|
|
.Where(m => m.Success)
|
|
.Select(m => m.Groups[1].Value)
|
|
.ToList();
|
|
}
|
|
|
|
private static List<string> ExternNames()
|
|
{
|
|
return typeof(EngineApi)
|
|
.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly)
|
|
.Where(m => m.GetCustomAttribute<DllImportAttribute>() != null)
|
|
.Select(m => m.Name)
|
|
.ToList();
|
|
}
|
|
|
|
[Test]
|
|
public void HeaderHas47Exports()
|
|
{
|
|
Assert.That(HeaderNames().Count, Is.EqualTo(47));
|
|
}
|
|
|
|
[Test]
|
|
public void EveryHeaderExportHasAnExtern()
|
|
{
|
|
var missing = HeaderNames().Except(ExternNames()).ToList();
|
|
Assert.That(missing, Is.Empty, "header exports without an EngineApi extern");
|
|
}
|
|
|
|
[Test]
|
|
public void EveryExternIsAHeaderExport()
|
|
{
|
|
var extra = ExternNames().Except(HeaderNames()).ToList();
|
|
Assert.That(extra, Is.Empty, "EngineApi externs that are not in contract/ocgapi.h");
|
|
}
|
|
|
|
[Test]
|
|
public void EveryExternIsPublicCdeclOnYgolEngine()
|
|
{
|
|
var methods = typeof(EngineApi)
|
|
.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly)
|
|
.Where(m => m.GetCustomAttribute<DllImportAttribute>() != null)
|
|
.ToList();
|
|
foreach (var method in methods)
|
|
{
|
|
var import = method.GetCustomAttribute<DllImportAttribute>();
|
|
Assert.That(method.IsPublic, method.Name + " is not public");
|
|
Assert.That(import.Value, Is.EqualTo("ygol-engine"), method.Name);
|
|
Assert.That(import.CallingConvention, Is.EqualTo(CallingConvention.Cdecl), method.Name);
|
|
Assert.That(import.EntryPoint, Is.Null.Or.EqualTo(method.Name), method.Name + " renames its entry point");
|
|
Assert.That(import.CharSet, Is.Not.EqualTo(CharSet.Unicode), method.Name + " uses CharSet.Unicode");
|
|
}
|
|
Assert.That(methods.Select(m => m.Name).Distinct().Count(), Is.EqualTo(methods.Count), "an export has an overload");
|
|
}
|
|
}
|
|
}
|