using System.Runtime.InteropServices;
using System.Text.Json;
namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
static uint GalaxyCellBudgetSelfTest()
{
static JsonElement Request(string text){using var doc=JsonDocument.Parse(text);return doc.RootElement.Clone();}
lock(galaxyMutex)
{
var saved=galaxyWork;var savedGeneration=galaxyGeneration;
try
{
uint passed=0;
if(GalaxyRowLimit(new(){region=true,cells=[7]})==24000&&GalaxyRowLimit(new(){region=true,cellMode=true,cells=[0,7]})==24000)passed|=1;
if(GalaxyRowLimit(new(){region=true,cellMode=true,cells=[7]})==131072)passed|=2;
var row=new GalaxyItem{id=(1UL<<23)|7,name="Budget fixture",position=[1,2,3]};
galaxyWork=new(){generation=91,region=true,cellMode=true,cells=[7],cellIndex=1,done=true,minimumMass=7,
origin=[1,2,3],items=Enumerable.Repeat(row,24001).ToList()};
JsonElement Result()=>Request(GalaxyCatalogueRequest("galaxy.result",Request("{\"generation\":91,\"limit\":0}")).ToJsonString());
var result=Result();
if(result.GetProperty("total").GetInt32()==24001&&result.GetProperty("rowLimit").GetInt32()==131072&&result.GetProperty("complete").GetBoolean()&&!result.GetProperty("truncated").GetBoolean())passed|=4;
galaxyWork.items=Enumerable.Repeat(row,131072).ToList();result=Result();
if(result.GetProperty("total").GetInt32()==131072&&result.GetProperty("complete").GetBoolean()&&!result.GetProperty("truncated").GetBoolean())passed|=8;
galaxyWork.cellIndex=0;result=Result();
if(!result.GetProperty("complete").GetBoolean()&&result.GetProperty("truncated").GetBoolean())passed|=16;
galaxyWork.cellIndex=1;galaxyWork.failedRows=1;
if(!Result().GetProperty("complete").GetBoolean())passed|=32;
galaxyWork.failedRows=0;galaxyWork.cells=[0,7];galaxyWork.cellIndex=2;result=Result();
if(result.GetProperty("rowLimit").GetInt32()==24000&&!result.GetProperty("complete").GetBoolean()&&result.GetProperty("truncated").GetBoolean())passed|=64;
galaxyWork=new(){done=true};var before=GetTickCount64();
GalaxyCatalogueRequest("galaxy.cells",Request("{\"centre\":[0,0,0],\"radii\":[1,1,1,1,1,1,1,1],\"cellAddresses\":[\"7\"]}"));
var deadline=galaxyWork.expires>=before+89000&&galaxyWork.expires<=GetTickCount64()+90000;
var bound=new GalaxyWork{started=true,region=true,cellMode=true,origin=[1,2,3],cells=[7]};
var services=new GalaxyServices{origin=[32,64,96]};
var same=GalaxyRegionOriginMatches(services,bound)&&!GalaxyRegionOriginMatches(new(){origin=[32,64]},bound)&&
!GalaxyRegionOriginMatches(services,new(){started=true,origin=[1,2,double.NaN]});
services.origin=[32,64,97];StepGalaxyRegion(services,bound);
galaxyWork=bound;bound.generation=91;result=Result();
if(deadline&&same&&bound.done&&bound.error.Contains("原点")&&!result.GetProperty("complete").GetBoolean()&&
result.GetProperty("origin")[2].GetDouble()==3&&bound.entry==0&&bound.cellIndex==0)passed|=128;
return passed;
}
finally{galaxyWork=saved;galaxyGeneration=savedGeneration;}
}
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyCellBudgetSelfTest")]
internal static uint ExportGalaxyCellBudgetSelfTest()=>RunTest(GalaxyCellBudgetSelfTest);
#endif
}
using System.Runtime.InteropServices;
using System.Text.Json;
namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
static uint GalaxyCellBudgetSelfTest()
{
static JsonElement Request(string text){using var doc=JsonDocument.Parse(text);return doc.RootElement.Clone();}
lock(galaxyMutex)
{
var saved=galaxyWork;var savedGeneration=galaxyGeneration;
try
{
uint passed=0;
if(GalaxyRowLimit(new(){region=true,cells=[7]})==24000&&GalaxyRowLimit(new(){region=true,cellMode=true,cells=[0,7]})==24000)passed|=1;
if(GalaxyRowLimit(new(){region=true,cellMode=true,cells=[7]})==131072)passed|=2;
var row=new GalaxyItem{id=(1UL<<23)|7,name="Budget fixture",position=[1,2,3]};
galaxyWork=new(){generation=91,region=true,cellMode=true,cells=[7],cellIndex=1,done=true,minimumMass=7,
origin=[1,2,3],items=Enumerable.Repeat(row,24001).ToList()};
JsonElement Result()=>Request(GalaxyCatalogueRequest("galaxy.result",Request("{\"generation\":91,\"limit\":0}")).ToJsonString());
var result=Result();
if(result.GetProperty("total").GetInt32()==24001&&result.GetProperty("rowLimit").GetInt32()==131072&&result.GetProperty("complete").GetBoolean()&&!result.GetProperty("truncated").GetBoolean())passed|=4;
galaxyWork.items=Enumerable.Repeat(row,131072).ToList();result=Result();
if(result.GetProperty("total").GetInt32()==131072&&result.GetProperty("complete").GetBoolean()&&!result.GetProperty("truncated").GetBoolean())passed|=8;
galaxyWork.cellIndex=0;result=Result();
if(!result.GetProperty("complete").GetBoolean()&&result.GetProperty("truncated").GetBoolean())passed|=16;
galaxyWork.cellIndex=1;galaxyWork.failedRows=1;
if(!Result().GetProperty("complete").GetBoolean())passed|=32;
galaxyWork.failedRows=0;galaxyWork.cells=[0,7];galaxyWork.cellIndex=2;result=Result();
if(result.GetProperty("rowLimit").GetInt32()==24000&&!result.GetProperty("complete").GetBoolean()&&result.GetProperty("truncated").GetBoolean())passed|=64;
galaxyWork=new(){done=true};var before=GetTickCount64();
GalaxyCatalogueRequest("galaxy.cells",Request("{\"centre\":[0,0,0],\"radii\":[1,1,1,1,1,1,1,1],\"cellAddresses\":[\"7\"]}"));
var deadline=galaxyWork.expires>=before+89000&&galaxyWork.expires<=GetTickCount64()+90000;
var bound=new GalaxyWork{started=true,region=true,cellMode=true,origin=[1,2,3],cells=[7]};
var services=new GalaxyServices{origin=[32,64,96]};
var same=GalaxyRegionOriginMatches(services,bound)&&!GalaxyRegionOriginMatches(new(){origin=[32,64]},bound)&&
!GalaxyRegionOriginMatches(services,new(){started=true,origin=[1,2,double.NaN]});
services.origin=[32,64,97];StepGalaxyRegion(services,bound);
galaxyWork=bound;bound.generation=91;result=Result();
if(deadline&&same&&bound.done&&bound.error.Contains("原点")&&!result.GetProperty("complete").GetBoolean()&&
result.GetProperty("origin")[2].GetDouble()==3&&bound.entry==0&&bound.cellIndex==0)passed|=128;
return passed;
}
finally{galaxyWork=saved;galaxyGeneration=savedGeneration;}
}
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyCellBudgetSelfTest")]
internal static uint ExportGalaxyCellBudgetSelfTest()=>RunTest(GalaxyCellBudgetSelfTest);
#endif
}