using System.Runtime.InteropServices;
namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
static uint GalaxyCarrierFactsSelfTest()
{
var memory=Platform.Allocate(0x10000);if(memory==0)return 0;
try
{
var table=memory+0x1000;var expected=table-0x552B230;var source=memory+0x4000;
var set=source+0x48;var storage=memory+0x6000;var keys=storage+8;const ulong address=9007199254740993UL;
Write(source,table);Write(source-0x58,expected+0x552B100);Write(source-0x50,expected+0x552B130);
Write(table,expected+0x3B12D10);Write(table+0x18,expected+0x3B063A0);
bool Copy(out bool? value)=>CopyGalaxyCarrierFacts(source,expected,address,out value);
uint passed=0;if(Copy(out var value)&&value==false)passed|=1;
const ulong capacity=16;var slot=GalaxyNavRouteHash(address)&15;
Write(set+8,1UL);Write(set+0x10,capacity);Write(set+0x18,storage);Write(storage,1UL<<(int)slot);Write(keys+(nuint)slot*8,address);
if(Copy(out value)&&value==true)passed|=2;
var following=(slot+1)&15;Write(keys+(nuint)slot*8,address+1);Write(keys+(nuint)following*8,address);
Write(storage,(1UL<<(int)slot)|(1UL<<(int)following));Write(set+8,2UL);
if(Copy(out value)&&value==true)passed|=4;
Write(storage,0UL);Write(set+8,0UL);if(Copy(out value)&&value==false)passed|=8;
Write(source,table+8);var bad=!Copy(out _);Write(source,table);Write(table+0x18,expected+0x3B063A8);bad&=!Copy(out _);Write(table+0x18,expected+0x3B063A0);
Write(source-0x50,expected+0x552B138);bad&=!Copy(out _);Write(source-0x50,expected+0x552B130);if(bad)passed|=16;
Write(set+0x10,15UL);bad=!Copy(out _);Write(set+0x10,capacity);Write(set+8,17UL);bad&=!Copy(out _);Write(set+8,0UL);
Write(set+0x18,(nuint)1);bad&=!Copy(out _);Write(set+0x18,storage);if(bad)passed|=32;
Write(set+8,capacity);Write(storage,0xFFFFUL);for(nuint i=0;i<16;i++)Write(keys+i*8,address+i+1);
if(!Copy(out _)&&!CopyGalaxyCarrierFacts(source,expected,0,out _)&&!CopyGalaxyCarrierFacts(source,expected,1UL<<55,out _))passed|=64;
Write(set+8,0UL);Write(storage,0UL);var before=Platform.ReadBytes(memory,0x10000);
if(Copy(out value)&&value==false&&Platform.ReadBytes(memory,0x10000).AsSpan().SequenceEqual(before))passed|=128;
return passed;
}
finally{Platform.Free(memory);}
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyCarrierFactsSelfTest")]
internal static uint ExportGalaxyCarrierFactsSelfTest()=>RunTest(GalaxyCarrierFactsSelfTest);
#endif
}
using System.Runtime.InteropServices;
namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
static uint GalaxyCarrierFactsSelfTest()
{
var memory=Platform.Allocate(0x10000);if(memory==0)return 0;
try
{
var table=memory+0x1000;var expected=table-0x552B230;var source=memory+0x4000;
var set=source+0x48;var storage=memory+0x6000;var keys=storage+8;const ulong address=9007199254740993UL;
Write(source,table);Write(source-0x58,expected+0x552B100);Write(source-0x50,expected+0x552B130);
Write(table,expected+0x3B12D10);Write(table+0x18,expected+0x3B063A0);
bool Copy(out bool? value)=>CopyGalaxyCarrierFacts(source,expected,address,out value);
uint passed=0;if(Copy(out var value)&&value==false)passed|=1;
const ulong capacity=16;var slot=GalaxyNavRouteHash(address)&15;
Write(set+8,1UL);Write(set+0x10,capacity);Write(set+0x18,storage);Write(storage,1UL<<(int)slot);Write(keys+(nuint)slot*8,address);
if(Copy(out value)&&value==true)passed|=2;
var following=(slot+1)&15;Write(keys+(nuint)slot*8,address+1);Write(keys+(nuint)following*8,address);
Write(storage,(1UL<<(int)slot)|(1UL<<(int)following));Write(set+8,2UL);
if(Copy(out value)&&value==true)passed|=4;
Write(storage,0UL);Write(set+8,0UL);if(Copy(out value)&&value==false)passed|=8;
Write(source,table+8);var bad=!Copy(out _);Write(source,table);Write(table+0x18,expected+0x3B063A8);bad&=!Copy(out _);Write(table+0x18,expected+0x3B063A0);
Write(source-0x50,expected+0x552B138);bad&=!Copy(out _);Write(source-0x50,expected+0x552B130);if(bad)passed|=16;
Write(set+0x10,15UL);bad=!Copy(out _);Write(set+0x10,capacity);Write(set+8,17UL);bad&=!Copy(out _);Write(set+8,0UL);
Write(set+0x18,(nuint)1);bad&=!Copy(out _);Write(set+0x18,storage);if(bad)passed|=32;
Write(set+8,capacity);Write(storage,0xFFFFUL);for(nuint i=0;i<16;i++)Write(keys+i*8,address+i+1);
if(!Copy(out _)&&!CopyGalaxyCarrierFacts(source,expected,0,out _)&&!CopyGalaxyCarrierFacts(source,expected,1UL<<55,out _))passed|=64;
Write(set+8,0UL);Write(storage,0UL);var before=Platform.ReadBytes(memory,0x10000);
if(Copy(out value)&&value==false&&Platform.ReadBytes(memory,0x10000).AsSpan().SequenceEqual(before))passed|=128;
return passed;
}
finally{Platform.Free(memory);}
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyCarrierFactsSelfTest")]
internal static uint ExportGalaxyCarrierFactsSelfTest()=>RunTest(GalaxyCarrierFactsSelfTest);
#endif
}