public ScriptTest(String script) { Logger = new List <String>(); RunCounter = 0; // Setup the CUSTOM_DATA to return the given script // And other required config for mocking mockGrid = new MockGridTerminalSystem(); me = new Mock <IMyProgrammableBlock>(); MockBlocksOfType("Script Program", me); MDKFactory.ProgramConfig config = default; config.GridTerminalSystem = mockGrid; config.ProgrammableBlock = me.Object; config.Echo = (message) => Logger.Add(message); program = MDKFactory.CreateProgram <Program>(config); program.functionParseAmount = 1000; program.logLevel = Program.LogLevel.SCRIPT_ONLY; // Default behavior for broadcast messages // TODO: Replace this with mock objects passed to config setup in Program program.broadcastMessageProvider = () => new List <MyIGCMessage>(); setScript(script); }
public void BeforeEach() { this.connector = new MockShipConnector() { CubeGrid = new MockCubeGrid() { GridSizeEnum = VRage.Game.MyCubeSize.Small }, CustomData = @"[connection-client] connector-name=connector name server-channel=server channel ", CustomName = "connector name", DisplayNameText = "connector name", WorldMatrix = MatrixD.Identity, WorldPosition = new Vector3D(5, 15, 25) }; this.gts = new MockGridTerminalSystem() { this.connector }; this.listener = new MockUnicastListener(); this.igc = new MockIntergridCommunicationSystem() { UnicastListener = this.listener }; this.manager = Program.Process.CreateManager(null); this.commandLine = new Program.CommandLine("test", null, this.manager); }
public void BeforeEach() { this.baseGrid = this.getMockCubeGrid("base grid", true); this.programableBlock = new MockProgrammableBlock { CubeGrid = this.baseGrid, CustomData = "[solar-manager]\nkeyword=solar", CustomName = "main pb", EntityId = GetId(), ProgramType = typeof(Program) }; this.gts = new MockGridTerminalSystem { this.programableBlock }; this.program = null; this.run = null; this.solarManager = null; }
public void Everything() { var grid = new MockCubeGrid { GridSizeEnum = VRage.Game.MyCubeSize.Small }; var controller = new MockShipController { CubeGrid = grid, ShipMass = new Sandbox.ModAPI.Ingame.MyShipMass(1820, 1820, 1820), WorldPosition = Vector3D.Zero, WorldMatrix = MatrixD.Identity }; var gts = new MockGridTerminalSystem { PowerWheelTest.GetSuspension(new Vector3D(-1, 0, -1), true, grid), PowerWheelTest.GetSuspension(new Vector3D(1, 0, -1), false, grid), PowerWheelTest.GetSuspension(new Vector3D(-1, 0, 1), true, grid), PowerWheelTest.GetSuspension(new Vector3D(1, 0, 1), false, grid), }; var transformer = new Program.CoordinatesTransformer(controller); var ini = new VRage.Game.ModAPI.Ingame.Utilities.MyIni(); ini.TryParse(@""); var saveManager = new Program.ProcessSpawnerMock(); var command = new Program.CommandLine("mock", null, saveManager); var wc = new Program.WheelsController(command, controller, gts, ini, saveManager, transformer); Assert.AreEqual(new Vector3D(0, 1, 0), wc.GetContactPlaneW()); Assert.AreEqual(new Vector3D(0, -1.75, -1), wc.GetPointOfContactW(new Vector3D(0, 0, -1))); wc.SetPosition("0.5"); // too anoying to test }
public CodeEditorEmulator() { GridTerminalSystem = new MockGridTerminalSystem(); }
public static void Main() { // In order for your program to actually run, you will need to provide a mockup of all the facilities // your script uses from the game, since they're not available outside of the game. var grid = new MockGridTerminalSystem(); var cubeGrid = new MockCubeGrid() { CustomName = "Debug Test Station", IsStatic = true, GridSizeEnum = VRage.Game.MyCubeSize.Large }; var programmableBlock = Mock <MockProgrammableBlock>(options: b => b.CubeGrid = cubeGrid); programmableBlock.Program = new Program(new DebugInfo { ProgrammableBlock = programmableBlock, GridTerminalSystem = grid, RuntimeInfo = new MockGridProgramRuntimeInfo() }); var echo = programmableBlock.Program.Echo; programmableBlock.Program.Echo = message => { echo(message); Console.WriteLine(message); }; var ventZone1 = Mock <MockAirVent>(options: b => b.CanPressurize = true, zones: "room-1"); var lightNormalZone1 = Mock <MockInteriorLight>(zones: "room-1"); var lightAlertZone1 = Mock <MockInteriorLight>(BlockFunction.Alert, zones: "room-1"); var ventZone2 = Mock <MockAirVent>(options: b => b.CanPressurize = true, zones: "room-2"); var lightNormalZone2 = Mock <MockInteriorLight>(zones: "room-2"); var lightAlertZone2 = Mock <MockInteriorLight>(BlockFunction.Alert, zones: "room-2"); grid.Add(new IMyTerminalBlock[] { programmableBlock, ventZone1, lightNormalZone1, lightAlertZone1, ventZone2, lightNormalZone2, lightAlertZone2 }); { RunUntil(programmableBlock, p => p.CurrentTick > 2); Assert.Equals("", programmableBlock.GetSurface(0).GetText(), "Programmable Block Grid Status"); } { RunCycle(programmableBlock); var pbSurface0 = programmableBlock.GetSurface(0) as MockTextSurface; var pbSprite0 = pbSurface0.SpriteBuffer.First(); var pbSurface1 = programmableBlock.GetSurface(1) as MockTextSurface; var pbSprite1 = pbSurface1.SpriteBuffer.First(); Assert.True(SpriteType.TEXT == pbSprite0.Type, "Programmable Block main screen texture type"); Assert.Equals("Station Normal\r\n room-1 Normal\r\n room-2 Normal\r\n", pbSprite0.Data, "Programmable Block main screen text"); Assert.True(SpriteType.TEXT == pbSprite1.Type, "Programmable Block keyboard texture type"); Assert.Equals("Time: 0ms (0ms max)\r\nIOPS: 0/0, (0 max)\r\nTick: 2/7\r\n", pbSprite1.Data, "Programmable Block keyboard text"); Assert.Equals(lightNormalZone1.Color, new Color(255, 255, 255), "Zone 1 normal light color"); Assert.True(lightNormalZone1.Enabled, "Zone 2 normal light should be enabled"); Assert.Equals(lightAlertZone1.Color, new Color(255, 255, 255), "Zone 1 alert light color"); Assert.True(lightAlertZone1.Enabled, "Zone 1 alert light should be enabled"); Assert.Equals(lightNormalZone2.Color, new Color(255, 255, 255), "Zone 1 normal light color"); Assert.True(lightNormalZone2.Enabled, "Zone 2 normal light should be enabled"); Assert.Equals(lightAlertZone2.Color, new Color(255, 255, 255), "Zone 1 alert light color"); Assert.True(lightAlertZone2.Enabled, "Zone 1 alert light should be enabled"); } ventZone1.CanPressurize = false; { RunCycle(programmableBlock); Assert.Equals("Station Normal\r\n room-1 Decompressed\r\n room-2 Normal\r\n", GetMockSpriteText(programmableBlock, 0), "Programmable Block main screen text"); Assert.Equals("Time: 0ms (0ms max)\r\nIOPS: 0/0, (0 max)\r\nTick: 2/7\r\n", GetMockSpriteText(programmableBlock, 1), "Programmable Block keyboard text"); Assert.Equals(lightNormalZone1.Color, new Color(255, 255, 255), "Zone 1 normal light color"); Assert.False(lightNormalZone1.Enabled, "Zone 1 normal light should be disabled"); Assert.Equals(lightAlertZone1.Color, new Color(0, 0, 255, 255), "Zone 1 alert light color"); Assert.True(lightAlertZone1.Enabled, "Zone 1 alert light should be enabled"); Assert.Equals(lightNormalZone2.Color, new Color(255, 255, 255), "Zone 1 normal light color"); Assert.True(lightNormalZone2.Enabled, "Zone 2 normal light should be enabled"); Assert.Equals(lightAlertZone2.Color, new Color(255, 255, 255), "Zone 1 alert light color"); Assert.True(lightAlertZone2.Enabled, "Zone 2 alert light should be enabled"); } programmableBlock.Run("toggle battle", UpdateType.Terminal); { RunCycle(programmableBlock); Assert.Equals("Station Battle Stations\r\n room-1 Decompressed\r\n room-2 Normal\r\n", GetMockSpriteText(programmableBlock, 0), "Programmable Block main screen text"); Assert.Equals("Time: 0ms (0ms max)\r\nIOPS: 0/0, (0 max)\r\nTick: 2/7\r\n", GetMockSpriteText(programmableBlock, 1), "Programmable Block keyboard text"); Assert.Equals(lightNormalZone1.Color, new Color(255, 255, 255), "Zone 1 normal light color"); Assert.False(lightNormalZone1.Enabled, "Zone 1 normal light should be disabled"); Assert.Equals(lightAlertZone1.Color, new Color(0, 0, 255, 255), "Zone 1 alert light color"); Assert.True(lightAlertZone1.Enabled, "Zone 1 alert light should be enabled"); Assert.Equals(lightNormalZone2.Color, new Color(255, 255, 255), "Zone 1 normal light color"); Assert.False(lightNormalZone1.Enabled, "Zone 2 normal light should be disabled"); Assert.Equals(lightAlertZone2.Color, new Color(255, 0, 0), "Zone 1 alert light color"); Assert.True(lightAlertZone2.Enabled, "Zone 2 alert light should be enabled"); } programmableBlock.Run("toggle battle", UpdateType.Terminal); ventZone1.CanPressurize = true; ventZone2.CanPressurize = false; { RunCycle(programmableBlock); Assert.Equals("Station Normal\r\n room-1 Normal\r\n room-2 Decompressed\r\n", GetMockSpriteText(programmableBlock, 0), "Programmable Block main screen text"); Assert.Equals("Time: 0ms (0ms max)\r\nIOPS: 0/0, (0 max)\r\nTick: 2/7\r\n", GetMockSpriteText(programmableBlock, 1), "Programmable Block keyboard text"); Assert.Equals(lightNormalZone1.Color, new Color(255, 255, 255), "Zone 1 normal light color"); Assert.True(lightNormalZone1.Enabled, "Zone 1 normal light should be enabled"); Assert.Equals(lightAlertZone1.Color, new Color(255, 255, 255, 255), "Zone 1 alert light color"); Assert.True(lightAlertZone1.Enabled, "Zone 1 alert light should be enabled"); Assert.Equals(lightNormalZone2.Color, new Color(255, 255, 255), "Zone 1 normal light color"); Assert.False(lightNormalZone2.Enabled, "Zone 1 normal light should be disabled"); Assert.Equals(lightAlertZone2.Color, new Color(0, 0, 255), "Zone 1 alert light color"); Assert.True(lightAlertZone2.Enabled, "Zone 1 alert light should be enabled"); } Console.WriteLine("Mock completed, press any key to exit."); Console.ReadKey(true); }