public void conditionalVelocityAndSoundBlockTest()
        {
            String script = @"
:reverseSirens
  if ""rover cockpit"" backwards velocity > 1
    if ""reverse sirens"" are off
      turn on the ""reverse sirens""
  else
    turn off the ""reverse sirens""
";

            using (var test = new ScriptTest(script))
            {
                var mockRoverCockpit = new Mock <IMyCockpit>();
                mockRoverCockpit.Setup(b => b.WorldMatrix).Returns(MatrixD.CreateWorld(Vector3D.Zero));
                mockRoverCockpit.Setup(b => b.GetShipVelocities()).Returns(new MyShipVelocities(new Vector3D(0, 0, 2), Vector3D.Zero));
                var mockReverseSirens = new Mock <IMySoundBlock>();
                mockReverseSirens.Setup(b => b.CustomData).Returns("Playing=False");

                test.MockBlocksOfType("rover cockpit", mockRoverCockpit);
                test.MockBlocksInGroup("reverse sirens", mockReverseSirens);

                test.RunUntilDone();

                mockReverseSirens.Verify(b => b.Play(), Times.Once);
            }
        }
        public void updatedScriptAutoParsesAndRestarts()
        {
            String script = @"
            :main
            #This is a comment
            print 'Hello World'
            replay
            ";

            String newScript = @"
            :main
            #This is a comment
            print 'Hello New World'
            ";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();
                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Hello World", test.Logger[0]);
                test.setScript(newScript);
                test.Logger.Clear();
                test.RunOnce();
                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Hello New World", test.Logger[0]);
            }
        }
Esempio n. 3
0
        public void asyncCommandLocalVariablesTakePrecedenceOverGlobalVariables()
        {
            String script = @"
:main
assign global ""a"" to 1
async call printVariable
async call printVariable
call ""printGlobalVariable""

:printGlobalVariable
Print ""Global Variable is: "" + {a}
goto ""printGlobalVariable""

:printVariable
print 'Variable is: ' + {a}
assign ""a"" to {a} + 2
goto printVariable
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads which set their variable and print
                Assert.AreEqual(3, test.Logger.Count);
                Assert.AreEqual("Global Variable is: 1", test.Logger[0]);
                Assert.AreEqual("Variable is: 1", test.Logger[1]);
                Assert.AreEqual("Variable is: 1", test.Logger[2]);

                test.Logger.Clear();
                test.RunOnce();//Executing async threads again, expect variables are incremented independently
                Assert.AreEqual(3, test.Logger.Count);
                Assert.AreEqual("Global Variable is: 1", test.Logger[0]);
                Assert.AreEqual("Variable is: 3", test.Logger[1]);
                Assert.AreEqual("Variable is: 3", test.Logger[2]);
            }
        }
Esempio n. 4
0
        public void asyncCommandVariablesAreThreadLocal()
        {
            String script = @"
:main
async call printLocalVariable 1
async call printLocalVariable 2

:printLocalVariable ""a""
print 'Variable is: ' + {a}
assign ""a"" to {a} + 2
goto printLocalVariable {a}
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads which set their variable and print
                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Variable is: 1", test.Logger[0]);
                Assert.AreEqual("Variable is: 2", test.Logger[1]);

                test.Logger.Clear();
                test.RunOnce();//Executing async threads again, expect variables are incremented independently
                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Variable is: 3", test.Logger[0]);
                Assert.AreEqual("Variable is: 4", test.Logger[1]);
            }
        }
Esempio n. 5
0
        public void asyncCommandsShareGlobalVariables()
        {
            String script = @"
:main
assign global ""a"" to 1
async call printGlobalVariable
async call printGlobalVariable

:printGlobalVariable
print 'Variable is: ' + {a}
assign global ""a"" to {a} + 2
goto printGlobalVariable
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads which set their variable and print
                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Variable is: 1", test.Logger[0]);
                Assert.AreEqual("Variable is: 3", test.Logger[1]);

                test.Logger.Clear();
                test.RunOnce();//Executing async threads again, expect global variable is incremented cumulatively
                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Variable is: 5", test.Logger[0]);
                Assert.AreEqual("Variable is: 7", test.Logger[1]);
            }
        }
Esempio n. 6
0
        public void MultipleBlocksSameType()
        {
            String script = @"
:lightshow
set the ""intense light"" intensity to 10
set the ""intense light"" blinkInterval to 0.5
set the ""intense light"" blinkOffset to 0.25
set the ""intense light"" blinkLength to 2
set the ""cool light"" color to ""blue""
set the ""cool light"" falloff to 1
turn on the ""cool light""
turn on the ""intense light""
";

            using (ScriptTest test = new ScriptTest(script))
            {
                var mockCoolLight    = new Mock <IMyLightingBlock>();
                var mockIntenseLight = new Mock <IMyLightingBlock>();
                test.MockBlocksOfType("cool light", mockCoolLight);
                test.MockBlocksOfType("intense light", mockIntenseLight);

                test.RunUntilDone();

                mockIntenseLight.VerifySet(b => b.Intensity            = 10f);
                mockIntenseLight.VerifySet(b => b.BlinkIntervalSeconds = 0.5f);
                mockIntenseLight.VerifySet(b => b.BlinkOffset          = 0.25f);
                mockIntenseLight.VerifySet(b => b.BlinkLength          = 2);
                mockCoolLight.VerifySet(b => b.Color      = new Color(0, 0, 255));
                mockCoolLight.VerifySet(b => b.Falloff    = 1);
                mockCoolLight.VerifySet(b => b.Enabled    = true);
                mockIntenseLight.VerifySet(b => b.Enabled = true);
            }
        }
Esempio n. 7
0
        public void asyncThreadsAreAllExecuted()
        {
            String script = @"
:main
async call runAsync
async call runAsync
async call runAsync
print 'Main'

:runAsync
wait
print 'Async'
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads and execute wait in all 3

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Main", test.Logger[0]);

                test.RunOnce();//Execute print in all async threads

                Assert.AreEqual(4, test.Logger.Count);
                Assert.AreEqual("Async", test.Logger[1]);
                Assert.AreEqual("Async", test.Logger[2]);
                Assert.AreEqual("Async", test.Logger[3]);
            }
        }
        public void NoScannedTargetDeletesPreviouslyStoredTarget()
        {
            String script = @"
print ""Target: "" + avg ""mock camera"" target
";

            using (var test = new ScriptTest(script)) {
                var mockCamera = new Mock <IMyCameraBlock>();
                mockCamera.Setup(b => b.CanScan(1000)).Returns(false);
                mockCamera.Setup(b => b.CustomData).Returns("Target=1:2:3");

                test.MockBlocksOfType("mock camera", mockCamera);
                test.RunOnce();
                mockCamera.VerifySet(b => b.EnableRaycast = true);
                mockCamera.Verify(b => b.CanScan(1000));

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Target: 1:2:3", test.Logger[0]);

                test.Logger.Clear();
                mockCamera.Setup(b => b.CanScan(1000)).Returns(true);
                mockCamera.Setup(b => b.Raycast(1000, 0, 0)).Returns(MockNoDetectedEntity());
                mockCamera.Setup(b => b.CustomData).Returns("");
                test.RunOnce();

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Target: 0:0:0", test.Logger[0]);
                mockCamera.VerifySet(b => b.CustomData = "");
            }
        }
        public void cameraIsTriggeredGetTarget()
        {
            String script = @"
when ""mock camera"" is triggered
  print ""Target: "" + ""mock camera"" target
";

            using (var test = new ScriptTest(script)) {
                var mockCamera = new Mock <IMyCameraBlock>();
                mockCamera.Setup(b => b.CustomData).Returns("");
                mockCamera.Setup(b => b.CanScan(1000)).Returns(false);

                test.MockBlocksOfType("mock camera", mockCamera);
                test.RunOnce();

                Assert.AreEqual(0, test.Logger.Count);
                mockCamera.VerifySet(b => b.EnableRaycast = true);
                mockCamera.Verify(b => b.CanScan(1000));

                test.RunOnce();

                Assert.AreEqual(0, test.Logger.Count);
                mockCamera.Verify(b => b.CanScan(1000));

                mockCamera.Setup(b => b.CanScan(1000)).Returns(true);
                mockCamera.Setup(b => b.Raycast(1000, 0, 0)).Returns(MockDetectedEntity(new Vector3D(1, 2, 3)));
                mockCamera.Setup(b => b.CustomData).Returns("Target=1:2:3");
                test.RunOnce();

                mockCamera.VerifySet(b => b.CustomData = "Target=1:2:3");
                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Target: 1:2:3", test.Logger[0]);
            }
        }
Esempio n. 10
0
        public void TriggerTheSensorAndGetTarget()
        {
            String script = @"
when ""mock sensor"" is triggered
  print ""Target: "" + ""mock sensor"" target
";

            using (var test = new ScriptTest(script)) {
                var mockSensor = new Mock <IMySensorBlock>();
                mockSensor.Setup(b => b.CustomData).Returns("");
                mockSensor.Setup(b => b.IsActive).Returns(false);

                test.MockBlocksOfType("mock sensor", mockSensor);
                test.RunOnce();

                Assert.AreEqual(0, test.Logger.Count);

                test.RunOnce();

                Assert.AreEqual(0, test.Logger.Count);

                mockSensor.Setup(b => b.IsActive).Returns(true);
                mockSensor.Setup(b => b.LastDetectedEntity).Returns(MockDetectedEntity(new Vector3D(1, 2, 3)));
                test.RunOnce();

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Target: 1:2:3", test.Logger[0]);
            }
        }
Esempio n. 11
0
        public void threadNamesAreProperlySet()
        {
            String script = @"
:main
async call runAsync
print 'Main'

:runAsync
wait
print 'Async'

:handleMessage
Print ""Message""
";

            using (var test = new ScriptTest(script)) {
                test.program.logLevel = LogLevel.INFO;
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("[Main] main"));
                Assert.IsTrue(test.Logger.Contains("[Async] runAsync"));

                test.program.Main("call handleMessage");

                Assert.IsTrue(test.Logger.Contains("[Request] call handleMessage"));
            }
        }
Esempio n. 12
0
        public void GetShipProximityStoppedTarget()
        {
            using (ScriptTest test = new ScriptTest(script)) {
                var mockCamera = new Mock <IMyCameraBlock>();
                test.MockBlocksOfType("My Camera", mockCamera);
                mockCamera.Setup(b => b.CanScan(1000)).Returns(false);
                mockCamera.Setup(b => b.CustomData).Returns("Range=10000");

                test.RunOnce();

                mockCamera.VerifySet(b => b.CustomData = "Range=10000");

                Assert.AreEqual(0, test.Logger.Count);

                mockCamera.Setup(b => b.Position).Returns(Vector3I.Zero);
                mockCamera.Setup(b => b.CanScan(10000)).Returns(true);
                mockCamera.Setup(b => b.Raycast(10000, 0, 0)).Returns(MockDetectedEntity(new Vector3D(1100, 1100, 0), new Vector3D(0, 0, 0)));
                mockCamera.Setup(b => b.CustomData).Returns(@"
Range=10000
Target=1100:1100:0
Velocity=0:0:0
");

                test.RunOnce();

                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Distance To Target: 1.56km", test.Logger[0]);
                Assert.AreEqual("Closest Approach: 1.56km", test.Logger[1]);
            }
        }
        public void ConnectTheLaserAntenna()
        {
            using (ScriptTest test = new ScriptTest(@"connect the ""test laser""")) {
                Mock <IMyLaserAntenna> mockLaserAntenna = new Mock <IMyLaserAntenna>();
                test.MockBlocksOfType("test laser", mockLaserAntenna);
                test.RunUntilDone();

                mockLaserAntenna.Verify(b => b.Connect());
            }
        }
        public void SetPropertyWithOnlyProperty()
        {
            using (ScriptTest test = new ScriptTest(@"detonate the ""test bomb""")) {
                Mock <IMyWarhead> mockBomb = new Mock <IMyWarhead>();
                test.MockBlocksOfType("test bomb", mockBomb);

                test.RunUntilDone();

                mockBomb.Verify(b => b.Detonate());
            }
        }
        public void TellTheEjectorToStopCollecting()
        {
            using (ScriptTest test = new ScriptTest(@"tell the ""test ejector"" to stop collecting")) {
                Mock <IMyShipConnector> mockEjector = new Mock <IMyShipConnector>();
                test.MockBlocksOfType("test ejector", mockEjector);

                test.RunUntilDone();

                mockEjector.VerifySet(b => b.CollectAll = false);
            }
        }
        public void SetPropertyWithNot()
        {
            using (ScriptTest test = new ScriptTest(@"tell the ""test vent"" not to pressurize")) {
                Mock <IMyAirVent> mockVent = new Mock <IMyAirVent>();
                test.MockBlocksOfType("test vent", mockVent);

                test.RunUntilDone();

                mockVent.VerifySet(b => b.Depressurize = true);
            }
        }
        public void SetPropertyWithNotWithoutProperty()
        {
            using (ScriptTest test = new ScriptTest(@"stop the ""test assembler""")) {
                Mock <IMyAssembler> mockAssembler = new Mock <IMyAssembler>();
                test.MockBlocksOfType("test assembler", mockAssembler);

                test.RunUntilDone();

                mockAssembler.Verify(b => b.ClearQueue());
            }
        }
        public void MovePropertyWithActionAndDirectionWithoutProperty()
        {
            using (ScriptTest test = new ScriptTest(@"raise the ""test piston""")) {
                Mock <IMyPistonBase> mockPiston = new Mock <IMyPistonBase>();
                test.MockBlocksOfType("test piston", mockPiston);

                test.RunUntilDone();

                mockPiston.Verify(b => b.Extend());
            }
        }
        public void SetPropertyWithValueWithoutProperty()
        {
            using (ScriptTest test = new ScriptTest(@"""test beacon"" to 200")) {
                Mock <IMyBeacon> mockBeacon = new Mock <IMyBeacon>();
                test.MockBlocksOfType("test beacon", mockBeacon);

                test.RunUntilDone();

                mockBeacon.VerifySet(b => b.Radius = 200);
            }
        }
Esempio n. 20
0
        public void TellTheConnectorToCollect()
        {
            using (ScriptTest test = new ScriptTest(@"tell the ""test connector"" to collect")) {
                Mock <IMyShipConnector> mockConnector = new Mock <IMyShipConnector>();
                test.MockBlocksOfType("test connector", mockConnector);

                test.RunUntilDone();

                mockConnector.VerifySet(b => b.CollectAll = true);
            }
        }
        public void SetPropertyWithDirectionAndValue()
        {
            using (ScriptTest test = new ScriptTest(@"up the ""test beacon"" range to 200")) {
                Mock <IMyBeacon> mockBeacon = new Mock <IMyBeacon>();
                test.MockBlocksOfType("test beacon", mockBeacon);

                test.RunUntilDone();

                mockBeacon.VerifySet(b => b.Radius = 200);
            }
        }
Esempio n. 22
0
        public void SetTheConnectorStrengthImplicit()
        {
            using (ScriptTest test = new ScriptTest(@"set the ""test connector"" to 0.2")) {
                Mock <IMyShipConnector> mockConnector = new Mock <IMyShipConnector>();
                test.MockBlocksOfType("test connector", mockConnector);

                test.RunUntilDone();

                mockConnector.VerifySet(b => b.PullStrength = 0.2f);
            }
        }
        public void TurnOnTheDecoy()
        {
            using (ScriptTest test = new ScriptTest(@"turn on the ""test decoy""")) {
                Mock <IMyDecoy> mockDecoy = new Mock <IMyDecoy>();
                test.MockBlocksOfType("test decoy", mockDecoy);

                test.RunUntilDone();

                mockDecoy.VerifySet(b => b.Enabled = true);
            }
        }
Esempio n. 24
0
        public void SetTheAntennaText()
        {
            using (ScriptTest test = new ScriptTest(@"set the ""test antenna"" text to ""Hello World!""")) {
                Mock <IMyRadioAntenna> mockAntenna = new Mock <IMyRadioAntenna>();
                test.MockBlocksOfType("test antenna", mockAntenna);

                test.RunUntilDone();

                mockAntenna.VerifySet(b => b.HudText = "Hello World!");
            }
        }
Esempio n. 25
0
        public void TellTheConnectorToStopDraining()
        {
            using (ScriptTest test = new ScriptTest(@"tell the ""test connector"" to stop draining")) {
                Mock <IMyShipConnector> mockConnector = new Mock <IMyShipConnector>();
                test.MockBlocksOfType("test connector", mockConnector);

                test.RunUntilDone();

                mockConnector.VerifySet(b => b.ThrowOut = false);
            }
        }
        public void TellTheEjectorToDrain()
        {
            using (ScriptTest test = new ScriptTest(@"tell the ""test ejector"" to drain")) {
                Mock <IMyShipConnector> mockEjector = new Mock <IMyShipConnector>();
                test.MockBlocksOfType("test ejector", mockEjector);

                test.RunUntilDone();

                mockEjector.VerifySet(b => b.ThrowOut = true);
            }
        }
Esempio n. 27
0
        public void TurnOnTheAntenna()
        {
            using (ScriptTest test = new ScriptTest(@"turn on the ""test antenna""")) {
                Mock <IMyRadioAntenna> mockAntenna = new Mock <IMyRadioAntenna>();
                test.MockBlocksOfType("test antenna", mockAntenna);

                test.RunUntilDone();

                mockAntenna.VerifySet(b => b.EnableBroadcasting = true);
            }
        }
Esempio n. 28
0
        public void SetTheAntennaRange()
        {
            using (ScriptTest test = new ScriptTest(@"set the ""test antenna"" range to 5000")) {
                Mock <IMyRadioAntenna> mockAntenna = new Mock <IMyRadioAntenna>();
                test.MockBlocksOfType("test antenna", mockAntenna);

                test.RunUntilDone();

                mockAntenna.VerifySet(b => b.Radius = 5000f);
            }
        }
        public void TellAssemblerToConsume()
        {
            using (ScriptTest test = new ScriptTest(@"tell the ""test assembler"" to consume")) {
                Mock <IMyAssembler> mockAssembler = new Mock <IMyAssembler>();
                test.MockBlocksOfType("test assembler", mockAssembler);

                test.RunUntilDone();

                mockAssembler.VerifySet(b => b.Mode = MyAssemblerMode.Disassembly);
            }
        }
Esempio n. 30
0
        public void UnlockTheConnector()
        {
            using (ScriptTest test = new ScriptTest(@"unlock the ""test connector""")) {
                Mock <IMyShipConnector> mockConnector = new Mock <IMyShipConnector>();
                test.MockBlocksOfType("test connector", mockConnector);

                test.RunUntilDone();

                mockConnector.Verify(b => b.Disconnect());
            }
        }