using System.Runtime.InteropServices;
using System.Text.Json;
namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
static uint GalaxyPowerOuterWireSelfTest()
{
static JsonElement Parse(string text){using var document=JsonDocument.Parse(text);return document.RootElement.Clone();}
lock(galaxyFactsMutex)
{
var previous=galaxyFactsWork;var generation=galaxyFactsGeneration;
try
{
galaxyFactsWork=new();galaxyFactsGeneration=0;uint passed=0;
JsonElement Wire(string op,string request)=>Parse(GalaxyFilterFactsRequest(op,Parse(request)).ToJsonString());
Wire("galaxy.facts","{\"systemAddresses\":[\"9007199254740995\"]}");
galaxyFactsWork.items.Add((9007199254740995UL,default));galaxyFactsWork.done=true;
var first=Wire("galaxy.facts.result","{\"generation\":1}").GetProperty("items")[0];
if(!galaxyFactsWork.includePowerOuter&&first.GetProperty("powerOuter").ValueKind==JsonValueKind.Null)passed|=1;
Wire("galaxy.facts","{\"systemAddresses\":[\"9007199254740995\"],\"includePowerOuter\":true}");
galaxyFactsWork.items.Add((9007199254740995UL,default));
var unknown=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0];var outer=unknown.GetProperty("powerOuter");
if(galaxyFactsWork.includePowerOuter&&!galaxyFactsWork.includePowerActivity&&outer.ValueKind==JsonValueKind.Object&&
outer.EnumerateObject().Count()==7&&outer.GetProperty("influence").ValueKind==JsonValueKind.Null&&outer.GetProperty("style").ValueKind==JsonValueKind.Null&&outer.GetProperty("extent").ValueKind==JsonValueKind.Null&&outer.EnumerateObject().All(property=>property.Value.ValueKind==JsonValueKind.Null)&&
unknown.GetProperty("powerActivity").ValueKind==JsonValueKind.Null)passed|=2;
var bad=0;
foreach(var value in new[]{"null","1","\"true\"","{}","[]"})
try{Wire("galaxy.facts","{\"systemAddresses\":[\"300\"],\"includePowerOuter\":"+value+"}");}catch(InvalidDataException){bad++;}
if(bad==5)passed|=4;
var influence=new GalaxyPowerInfluenceFact(true,9007199254741001UL,9007199254740995UL,[1.25,-2.5,25899.96875],[6.25,-2.5,25899.96875],[.1f,.2f,.3f],0,-.375f,.25f,1234);
galaxyFactsWork.powerOuter[9007199254740995UL]=new(true,9007199254741001UL,[1.25,-2.5,25899.96875],100){style=new([.4f,.5f,1.5f],[.13286832f,.21404114f,2.5371552f],.7f,1),influence=influence};
outer=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("powerOuter");
if(outer.GetProperty("visible").GetBoolean()&&outer.GetProperty("centreSystemAddress").GetString()=="9007199254741001"&&
outer.GetProperty("centrePosition")[2].GetDouble()==25899.96875&&outer.GetProperty("radius").GetSingle()==100&&
outer.GetProperty("style").GetProperty("rawRgb")[2].GetSingle()==1.5f&&outer.GetProperty("style").GetProperty("linearRgb")[2].GetSingle()>2.5f&&
outer.GetProperty("style").GetProperty("size").GetSingle()==.7f&&outer.GetProperty("style").GetProperty("opacity").GetSingle()==1&&
outer.GetProperty("influence").GetProperty("toSystemAddress").GetString()=="9007199254740995"&&outer.GetProperty("influence").GetProperty("phase").GetSingle()==-.375f)passed|=8;
galaxyFactsWork.powerOuter[9007199254740995UL]=new(false,9007199254741001UL,[1.25,-2.5,25899.96875],100){influence=influence};
var hidden=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("powerOuter");
var knownFalse=!hidden.GetProperty("visible").GetBoolean()&&hidden.GetProperty("style").ValueKind==JsonValueKind.Null&&hidden.GetProperty("influence").ValueKind==JsonValueKind.Null;
galaxyFactsWork.powerOuter[9007199254740995UL]=new(null,9007199254741001UL,[1.25,-2.5,25899.96875],100);
outer=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("powerOuter");
if(knownFalse&&outer.GetProperty("visible").ValueKind==JsonValueKind.Null&&outer.GetProperty("centreSystemAddress").GetString()=="9007199254741001")passed|=16;
var old=galaxyFactsWork;var cancelled=Wire("galaxy.facts.cancel","{\"generation\":2}");
Wire("galaxy.facts","{\"systemAddresses\":[\"300\"],\"includePowerOuter\":false}");var mismatched=false;
try{Wire("galaxy.facts.result","{\"generation\":2}");}catch(InvalidOperationException){mismatched=true;}
if(cancelled.GetProperty("cancelled").GetBoolean()&&old.done&&mismatched&&!galaxyFactsWork.includePowerOuter&&galaxyFactsWork.powerOuter.Count==0)passed|=32;
galaxyFactsWork.items=Enumerable.Range(1,200).Select(value=>((ulong)value,default(GalaxyFilterFacts))).ToList();
var page=Wire("galaxy.facts.result","{\"generation\":3,\"limit\":9999}");
if(page.GetProperty("items").GetArrayLength()==96&&page.GetProperty("items").EnumerateArray().All(row=>row.GetProperty("powerOuter").ValueKind==JsonValueKind.Null))passed|=64;
var frame=new Snapshot{valid=true,entity=42,referenceWorld=100};var work=new GalaxyFilterFactsWork{expires=100,includePowerOuter=true};
var bound=BindGalaxyFilterFactsWork(work,frame,1);frame.entity=43;
if(bound&&!BindGalaxyFilterFactsWork(work,frame,2)&&work.done&&work.error.Contains("changed")&&work.powerOuter.Count==0)passed|=128;
return passed;
}
finally{galaxyFactsWork=previous;galaxyFactsGeneration=generation;}
}
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyPowerOuterWireSelfTest")]
internal static uint ExportGalaxyPowerOuterWireSelfTest()=>RunTest(GalaxyPowerOuterWireSelfTest);
#endif
}
using System.Runtime.InteropServices;
using System.Text.Json;
namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
static uint GalaxyPowerOuterWireSelfTest()
{
static JsonElement Parse(string text){using var document=JsonDocument.Parse(text);return document.RootElement.Clone();}
lock(galaxyFactsMutex)
{
var previous=galaxyFactsWork;var generation=galaxyFactsGeneration;
try
{
galaxyFactsWork=new();galaxyFactsGeneration=0;uint passed=0;
JsonElement Wire(string op,string request)=>Parse(GalaxyFilterFactsRequest(op,Parse(request)).ToJsonString());
Wire("galaxy.facts","{\"systemAddresses\":[\"9007199254740995\"]}");
galaxyFactsWork.items.Add((9007199254740995UL,default));galaxyFactsWork.done=true;
var first=Wire("galaxy.facts.result","{\"generation\":1}").GetProperty("items")[0];
if(!galaxyFactsWork.includePowerOuter&&first.GetProperty("powerOuter").ValueKind==JsonValueKind.Null)passed|=1;
Wire("galaxy.facts","{\"systemAddresses\":[\"9007199254740995\"],\"includePowerOuter\":true}");
galaxyFactsWork.items.Add((9007199254740995UL,default));
var unknown=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0];var outer=unknown.GetProperty("powerOuter");
if(galaxyFactsWork.includePowerOuter&&!galaxyFactsWork.includePowerActivity&&outer.ValueKind==JsonValueKind.Object&&
outer.EnumerateObject().Count()==7&&outer.GetProperty("influence").ValueKind==JsonValueKind.Null&&outer.GetProperty("style").ValueKind==JsonValueKind.Null&&outer.GetProperty("extent").ValueKind==JsonValueKind.Null&&outer.EnumerateObject().All(property=>property.Value.ValueKind==JsonValueKind.Null)&&
unknown.GetProperty("powerActivity").ValueKind==JsonValueKind.Null)passed|=2;
var bad=0;
foreach(var value in new[]{"null","1","\"true\"","{}","[]"})
try{Wire("galaxy.facts","{\"systemAddresses\":[\"300\"],\"includePowerOuter\":"+value+"}");}catch(InvalidDataException){bad++;}
if(bad==5)passed|=4;
var influence=new GalaxyPowerInfluenceFact(true,9007199254741001UL,9007199254740995UL,[1.25,-2.5,25899.96875],[6.25,-2.5,25899.96875],[.1f,.2f,.3f],0,-.375f,.25f,1234);
galaxyFactsWork.powerOuter[9007199254740995UL]=new(true,9007199254741001UL,[1.25,-2.5,25899.96875],100){style=new([.4f,.5f,1.5f],[.13286832f,.21404114f,2.5371552f],.7f,1),influence=influence};
outer=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("powerOuter");
if(outer.GetProperty("visible").GetBoolean()&&outer.GetProperty("centreSystemAddress").GetString()=="9007199254741001"&&
outer.GetProperty("centrePosition")[2].GetDouble()==25899.96875&&outer.GetProperty("radius").GetSingle()==100&&
outer.GetProperty("style").GetProperty("rawRgb")[2].GetSingle()==1.5f&&outer.GetProperty("style").GetProperty("linearRgb")[2].GetSingle()>2.5f&&
outer.GetProperty("style").GetProperty("size").GetSingle()==.7f&&outer.GetProperty("style").GetProperty("opacity").GetSingle()==1&&
outer.GetProperty("influence").GetProperty("toSystemAddress").GetString()=="9007199254740995"&&outer.GetProperty("influence").GetProperty("phase").GetSingle()==-.375f)passed|=8;
galaxyFactsWork.powerOuter[9007199254740995UL]=new(false,9007199254741001UL,[1.25,-2.5,25899.96875],100){influence=influence};
var hidden=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("powerOuter");
var knownFalse=!hidden.GetProperty("visible").GetBoolean()&&hidden.GetProperty("style").ValueKind==JsonValueKind.Null&&hidden.GetProperty("influence").ValueKind==JsonValueKind.Null;
galaxyFactsWork.powerOuter[9007199254740995UL]=new(null,9007199254741001UL,[1.25,-2.5,25899.96875],100);
outer=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("powerOuter");
if(knownFalse&&outer.GetProperty("visible").ValueKind==JsonValueKind.Null&&outer.GetProperty("centreSystemAddress").GetString()=="9007199254741001")passed|=16;
var old=galaxyFactsWork;var cancelled=Wire("galaxy.facts.cancel","{\"generation\":2}");
Wire("galaxy.facts","{\"systemAddresses\":[\"300\"],\"includePowerOuter\":false}");var mismatched=false;
try{Wire("galaxy.facts.result","{\"generation\":2}");}catch(InvalidOperationException){mismatched=true;}
if(cancelled.GetProperty("cancelled").GetBoolean()&&old.done&&mismatched&&!galaxyFactsWork.includePowerOuter&&galaxyFactsWork.powerOuter.Count==0)passed|=32;
galaxyFactsWork.items=Enumerable.Range(1,200).Select(value=>((ulong)value,default(GalaxyFilterFacts))).ToList();
var page=Wire("galaxy.facts.result","{\"generation\":3,\"limit\":9999}");
if(page.GetProperty("items").GetArrayLength()==96&&page.GetProperty("items").EnumerateArray().All(row=>row.GetProperty("powerOuter").ValueKind==JsonValueKind.Null))passed|=64;
var frame=new Snapshot{valid=true,entity=42,referenceWorld=100};var work=new GalaxyFilterFactsWork{expires=100,includePowerOuter=true};
var bound=BindGalaxyFilterFactsWork(work,frame,1);frame.entity=43;
if(bound&&!BindGalaxyFilterFactsWork(work,frame,2)&&work.done&&work.error.Contains("changed")&&work.powerOuter.Count==0)passed|=128;
return passed;
}
finally{galaxyFactsWork=previous;galaxyFactsGeneration=generation;}
}
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyPowerOuterWireSelfTest")]
internal static uint ExportGalaxyPowerOuterWireSelfTest()=>RunTest(GalaxyPowerOuterWireSelfTest);
#endif
}