Core: ygol_query_tag_cards(pduel, playerid, out) reads the waiting tag partner's tag_list_hand / tag_list_extra (bit 31 = face-up, like MSG_TAG_SWAP) and tag_list_main sorted ascending; returns the byte length, 0 when not a tag duel. Read only. Server: STOC_TAG_PARTNER_CARDS 0x5F = u8 side + those bytes, no stamp, to that side's two seats only (never the other team, never an observer): after start_duel, after every MSG_TAG_SWAP, and in a seated duelist's field resync. FEATURE_TAG_PARTNER_CARDS 0x2000 advertised by single_duel and tag_duel; FEATURE_PROTOCOL 8 -> 9. 0x800 / 0x1000 stay reserved for proposals 44 / 45. Binding: StocMessage.TagPartnerCards, FeatureFlags.TagPartnerCards, the TagPartnerCards record + StocCodecs.TagPartnerCards, EngineApi.ygol_query_tag_cards, Capability.ProtocolVersion 9, tests. Contract rows, CHANGELOG v1.2.0, the probe's tag partner cards room, the export gates 334 / 855 / 849 -> 335 / 856 / 850. Co-Authored-By: Claude Fable 5.1 <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 HeaderHas46Exports()
|
|
{
|
|
Assert.That(HeaderNames().Count, Is.EqualTo(46));
|
|
}
|
|
|
|
[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");
|
|
}
|
|
}
|
|
}
|