using System.Runtime.InteropServices; using System.Text.Json; namespace XFEEDToolBox.Plugin; internal static unsafe partial class Navigation { // Protocol/coverage checks use only fixture work records. No game process, // game function, pointer dereference or input is involved. static uint GalaxyCoverageSelfTest() { static JsonElement Request(string text){using var d=JsonDocument.Parse(text);return d.RootElement.Clone();} static bool Rejected(Action action){try{action();return false;}catch{return true;}} lock(galaxyMutex) { var saved=galaxyWork;var savedGeneration=galaxyGeneration; try { uint passed=0; JsonElement Result()=>Request(GalaxyCatalogueRequest("galaxy.result",Request("{\"generation\":91,\"limit\":96}")).ToJsonString()); galaxyWork=new(){generation=91,region=true,done=true,cells=[1,2],cellIndex=2}; var complete=Result(); if(complete.GetProperty("complete").GetBoolean()&&!complete.GetProperty("truncated").GetBoolean()&&complete.GetProperty("items").GetArrayLength()==0)passed|=1; galaxyWork.minimumMass=1; if(!Result().GetProperty("complete").GetBoolean())passed|=2; galaxyWork.minimumMass=0;galaxyWork.failedCells=1; if(!Result().GetProperty("complete").GetBoolean()&&Result().GetProperty("failedCells").GetInt32()==1)passed|=4; galaxyWork.failedCells=0;galaxyWork.failedRows=1; if(!Result().GetProperty("complete").GetBoolean()&&Result().GetProperty("failedCells").GetInt32()==1)passed|=8; galaxyWork.failedRows=0;galaxyWork.cellIndex=1; if(Result().GetProperty("truncated").GetBoolean()&&!Result().GetProperty("complete").GetBoolean())passed|=16; galaxyWork.cellIndex=2;galaxyWork.done=false; galaxyWork.items=Enumerable.Range(0,100).Select(i=>new GalaxyItem{id=(ulong)i+1,name="Fixture "+i,position=[i,0,0]}).ToList(); var first=Result(); var second=Request(GalaxyCatalogueRequest("galaxy.result",Request("{\"generation\":91,\"offset\":96,\"limit\":96}")).ToJsonString()); if(!first.GetProperty("done").GetBoolean()&&first.GetProperty("items").GetArrayLength()==96&&second.GetProperty("items").GetArrayLength()==4)passed|=32; galaxyWork.items=Enumerable.Repeat(new GalaxyItem{id=1,name="Fixture",position=[0,0,0]},24000).ToList();galaxyWork.done=true; if(Result().GetProperty("truncated").GetBoolean()&&!Result().GetProperty("complete").GetBoolean())passed|=64; galaxyWork=new(){generation=91,region=true,cellObject=123}; var pending=Request(GalaxyCatalogueRequest("galaxy.cancel",Request("{\"generation\":91}")).ToJsonString()); if(galaxyWork.cancelRequested&&!pending.GetProperty("done").GetBoolean()&&galaxyWork.cellObject==123)passed|=128; galaxyWork.cellObject=0; var cancelled=Request(GalaxyCatalogueRequest("galaxy.cancel",Request("{\"generation\":91}")).ToJsonString()); if(cancelled.GetProperty("done").GetBoolean()&&cancelled.GetProperty("cancelled").GetBoolean()&&!cancelled.GetProperty("complete").GetBoolean()&& Rejected(()=>GalaxyCatalogueRequest("galaxy.cancel",Request("{\"generation\":90}"))))passed|=256; galaxyGeneration=91; var fine=Request(GalaxyCatalogueRequest("galaxy.region",Request("{\"centre\":[0,0,0],\"radius\":0.05}")).ToJsonString()); if(fine.GetProperty("generation").GetUInt64()==92&&galaxyWork.radius==.05)passed|=512; var services=new GalaxyServices{origin=[1600000,1600000,1600000]}; var small=new GalaxyWork{centre=[0,0,0],radius=1};BuildGalaxyRegionCells(small,services); var large=new GalaxyWork{centre=[0,0,0],radius=700};BuildGalaxyRegionCells(large,services); if(small.minimumMass==0&&small.cells.Count>0&&small.cells.Count<=512&&large.minimumMass>0&&large.cells.Count<=512)passed|=1024; galaxyWork.done=true; GalaxyCatalogueRequest("galaxy.resolve",Request("{\"systemAddress\":\"9007199254740995\"}")); if(galaxyWork.address==9007199254740995&&galaxyWork.query.Length==0&& Rejected(()=>GalaxyCatalogueRequest("galaxy.resolve",Request("{\"systemAddress\":0}")))&& Rejected(()=>GalaxyCatalogueRequest("galaxy.resolve",Request("{\"systemAddress\":1.25}"))))passed|=2048; if(galaxyStarClasses.Length==48&&GalaxyStarClass(9)=="TTS"&&GalaxyStarClass(10)=="AeBe"&&GalaxyStarClass(11)=="Y"&&GalaxyStarClass(43)=="X"&&GalaxyStarClass(47)=="NoSystem"&&GalaxyStarClass(48)=="Unknown")passed|=4096; return passed; } finally{galaxyWork=saved;galaxyGeneration=savedGeneration;} } } #if PLUGIN_NAVIGATION [UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyCoverageSelfTest")] internal static uint ExportGalaxyCoverageSelfTest()=>RunTest(GalaxyCoverageSelfTest); #endif }