using System.Runtime.InteropServices;
using System.Text.Json;
namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
static uint GalaxyAccountFleetWireSelfTest()
{
static JsonElement Request(string text){using var d=JsonDocument.Parse(text);return d.RootElement.Clone();}
lock(galaxyAccountMutex)lock(snapshotLock)
{
var savedFrame=snapshot;var savedInGame=inGame;var savedFleet=galaxyAccountFleet;var savedVersion=galaxyFleetVersion;
try
{
uint passed=0;var now=GetTickCount64();inGame=true;snapshot=new(){valid=true,entity=42,tick=now};galaxyFleetVersion=7;
var rows=Enumerable.Range(0,97).Select(i=>new GalaxyAccountFleetItem(i+1,3000000000U+(uint)i,9007199254740993UL+(ulong)(i%2))).ToArray();
galaxyAccountFleet=new(now,42,19,rows);
JsonElement Read(string request)=>Request(GalaxyFleetDescription(Request(request)).ToJsonString());
var first=Read("{}");var page=Read("{\"generation\":7,\"offset\":96}");
if(first.GetProperty("available").GetBoolean()&&!first.GetProperty("complete").GetBoolean()&&first.GetProperty("items").GetArrayLength()==96)passed|=1;
var item=page.GetProperty("items")[0];
if(page.GetProperty("items").GetArrayLength()==1&&item.GetProperty("id").GetInt32()==97&&item.GetProperty("shipId").GetUInt32()==3000000096U&&item.GetProperty("systemAddress").GetString()=="9007199254740993")passed|=2;
if(first.GetProperty("currentShipId").GetUInt32()==19&&Read("{\"limit\":4096}").GetProperty("items").GetArrayLength()==96)passed|=4;
var rejected=false;try{Read("{\"generation\":8}");}catch(InvalidOperationException){rejected=true;}if(rejected)passed|=8;
snapshot.entity=43;var other=Read("{}");
if(!other.GetProperty("available").GetBoolean()&&other.GetProperty("items").GetArrayLength()==0&&other.GetProperty("currentShipId").ValueKind==JsonValueKind.Null)passed|=16;
snapshot.entity=42;galaxyAccountFleet=new(now-6001,42,19,rows);
if(!Read("{}").GetProperty("available").GetBoolean())passed|=32;
galaxyAccountFleet=new(now,42,null,[]);var empty=Read("{}");
if(empty.GetProperty("available").GetBoolean()&&empty.GetProperty("currentShipId").ValueKind==JsonValueKind.Null&&!empty.GetProperty("complete").GetBoolean()&&empty.GetProperty("total").GetInt32()==0)passed|=64;
inGame=false;if(!Read("{}").GetProperty("available").GetBoolean()&&Read("{}").GetProperty("entityId").GetString()=="")passed|=128;
return passed;
}
finally{snapshot=savedFrame;inGame=savedInGame;galaxyAccountFleet=savedFleet;galaxyFleetVersion=savedVersion;}
}
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyAccountFleetWireSelfTest")]
internal static uint ExportGalaxyAccountFleetWireSelfTest()=>RunTest(GalaxyAccountFleetWireSelfTest);
#endif
}
using System.Runtime.InteropServices;
using System.Text.Json;
namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
static uint GalaxyAccountFleetWireSelfTest()
{
static JsonElement Request(string text){using var d=JsonDocument.Parse(text);return d.RootElement.Clone();}
lock(galaxyAccountMutex)lock(snapshotLock)
{
var savedFrame=snapshot;var savedInGame=inGame;var savedFleet=galaxyAccountFleet;var savedVersion=galaxyFleetVersion;
try
{
uint passed=0;var now=GetTickCount64();inGame=true;snapshot=new(){valid=true,entity=42,tick=now};galaxyFleetVersion=7;
var rows=Enumerable.Range(0,97).Select(i=>new GalaxyAccountFleetItem(i+1,3000000000U+(uint)i,9007199254740993UL+(ulong)(i%2))).ToArray();
galaxyAccountFleet=new(now,42,19,rows);
JsonElement Read(string request)=>Request(GalaxyFleetDescription(Request(request)).ToJsonString());
var first=Read("{}");var page=Read("{\"generation\":7,\"offset\":96}");
if(first.GetProperty("available").GetBoolean()&&!first.GetProperty("complete").GetBoolean()&&first.GetProperty("items").GetArrayLength()==96)passed|=1;
var item=page.GetProperty("items")[0];
if(page.GetProperty("items").GetArrayLength()==1&&item.GetProperty("id").GetInt32()==97&&item.GetProperty("shipId").GetUInt32()==3000000096U&&item.GetProperty("systemAddress").GetString()=="9007199254740993")passed|=2;
if(first.GetProperty("currentShipId").GetUInt32()==19&&Read("{\"limit\":4096}").GetProperty("items").GetArrayLength()==96)passed|=4;
var rejected=false;try{Read("{\"generation\":8}");}catch(InvalidOperationException){rejected=true;}if(rejected)passed|=8;
snapshot.entity=43;var other=Read("{}");
if(!other.GetProperty("available").GetBoolean()&&other.GetProperty("items").GetArrayLength()==0&&other.GetProperty("currentShipId").ValueKind==JsonValueKind.Null)passed|=16;
snapshot.entity=42;galaxyAccountFleet=new(now-6001,42,19,rows);
if(!Read("{}").GetProperty("available").GetBoolean())passed|=32;
galaxyAccountFleet=new(now,42,null,[]);var empty=Read("{}");
if(empty.GetProperty("available").GetBoolean()&&empty.GetProperty("currentShipId").ValueKind==JsonValueKind.Null&&!empty.GetProperty("complete").GetBoolean()&&empty.GetProperty("total").GetInt32()==0)passed|=64;
inGame=false;if(!Read("{}").GetProperty("available").GetBoolean()&&Read("{}").GetProperty("entityId").GetString()=="")passed|=128;
return passed;
}
finally{snapshot=savedFrame;inGame=savedInGame;galaxyAccountFleet=savedFleet;galaxyFleetVersion=savedVersion;}
}
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyAccountFleetWireSelfTest")]
internal static uint ExportGalaxyAccountFleetWireSelfTest()=>RunTest(GalaxyAccountFleetWireSelfTest);
#endif
}