public void getUpperLimit()
        {
            String script = @"
print the avg ""hinge"" upper limit
";

            using (ScriptTest test = new ScriptTest(script)) {
                var mockHinge = new Mock <IMyMotorStator>();
                test.MockBlocksOfType("hinge", mockHinge);
                MockBlockDefinition(mockHinge, "LargeHinge");

                mockHinge.Setup(b => b.UpperLimitDeg).Returns(30);
                test.RunUntilDone();
                mockHinge.Verify(b => b.UpperLimitDeg);

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("30", test.Logger[0]);
            }
        }
        public void GetTurretTargetFromTargetedEntity()
        {
            String script = @"
print the ""turrets"" target
";

            using (ScriptTest test = new ScriptTest(script)) {
                var mockTurret = new Mock <IMyLargeTurretBase>();
                test.MockBlocksInGroup("turrets", mockTurret);

                mockTurret.Setup(b => b.CustomData).Returns("");
                mockTurret.Setup(b => b.HasTarget).Returns(true);
                mockTurret.Setup(b => b.GetTargetedEntity()).Returns(MockDetectedEntity(new Vector3D(1, 2, 3)));

                test.RunUntilDone();

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("1:2:3", test.Logger[0]);
            }
        }
        public void SetTurretTargetVelocityUsingTargetedEntity()
        {
            String script = @"
set the ""turrets"" targetVelocity to ""1:2:3""
";

            using (ScriptTest test = new ScriptTest(script)) {
                var mockTurret = new Mock <IMyLargeTurretBase>();
                test.MockBlocksInGroup("turrets", mockTurret);

                var target = MockDetectedEntity(new Vector3D(4, 5, 6));
                mockTurret.Setup(b => b.CustomData).Returns("");
                mockTurret.Setup(b => b.HasTarget).Returns(true);
                mockTurret.Setup(b => b.GetTargetedEntity()).Returns(target);
                test.RunUntilDone();

                mockTurret.Verify(b => b.GetTargetedEntity());
                mockTurret.Verify(b => b.TrackTarget(new Vector3D(4, 5, 6), new Vector3D(1, 2, 3)));
            }
        }
Ejemplo n.º 4
0
        public void queueCommandIsQueuedAtBack()
        {
            String script = @"
:main
queue print 'Queued'
print 'Main'
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

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

                test.RunUntilDone();

                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Queued", test.Logger[1]);
            }
        }
        public void SetProgrammableBlockKeyboardText()
        {
            String script = @"
set the ""test program"" display @ 1 text to ""Hello World""
";

            using (ScriptTest test = new ScriptTest(script)) {
                var mockProgram  = new Mock <IMyProgrammableBlock>();
                var mockDisplay  = new Mock <IMyTextSurface>();
                var mockKeyboard = new Mock <IMyTextSurface>();

                MockTextSurfaces(mockProgram, mockDisplay, mockKeyboard);

                test.MockBlocksOfType("test program", mockProgram);

                test.RunUntilDone();

                mockKeyboard.Verify(b => b.WriteText("Hello World", false));
            }
        }
        public void SetCockpitKeyboardText()
        {
            String script = @"
set the ""test cockpit"" display @ 1 text to ""Hello World""
";

            using (ScriptTest test = new ScriptTest(script)) {
                var mockCockpit  = new Mock <IMyCockpit>();
                var mockDisplay  = new Mock <IMyTextSurface>();
                var mockKeyboard = new Mock <IMyTextSurface>();

                MockTextSurfaces(mockCockpit, mockDisplay, mockKeyboard);

                test.MockBlocksOfType("test cockpit", mockCockpit);

                test.RunUntilDone();

                mockKeyboard.Verify(b => b.WriteText("Hello World", false));
            }
        }
Ejemplo n.º 7
0
        public void getCargoAmount()
        {
            String script = @"
assign ""a"" to ""mock cargo"" ""ore"" amount
print ""Ore Amount: "" + {a}
";

            using (var test = new ScriptTest(script)) {
                var mockContainer = new Mock <IMyCargoContainer>();
                var mockInventory = new Mock <IMyInventory>();
                MockInventories(mockContainer, mockInventory);

                MockInventoryItems(mockInventory, MockOre("Iron", 200), MockOre("Stone", 100));

                test.MockBlocksOfType("mock cargo", mockContainer);
                test.RunUntilDone();

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Ore Amount: 300", test.Logger[0]);
            }
        }
Ejemplo n.º 8
0
        public void getCargoVolume()
        {
            String script = @"
assign ""a"" to ""mock cargo"" volume
print ""Cargo Volume: "" + {a}
";

            using (var test = new ScriptTest(script)) {
                var mockContainer = new Mock <IMyCargoContainer>();
                var mockInventory = new Mock <IMyInventory>();
                MockInventories(mockContainer, mockInventory);

                mockInventory.Setup(i => i.CurrentVolume).Returns((MyFixedPoint)0.1);

                test.MockBlocksOfType("mock cargo", mockContainer);
                test.RunUntilDone();

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Cargo Volume: 100", test.Logger[0]);
            }
        }
Ejemplo n.º 9
0
        public void UseVariableAsImplicitBlockSelectorInConditionAndBlockCommand()
        {
            String script = @"
assign ""myLights"" to 'test lights'
if $myLights are on
  Print 'You Left The Lights On'
  turn off $myLights
";

            using (ScriptTest test = new ScriptTest(script)) {
                var mockLight = new Mock <IMyLightingBlock>();
                test.MockBlocksInGroup("test lights", mockLight);
                mockLight.Setup(b => b.Enabled).Returns(true);

                test.RunUntilDone();

                mockLight.VerifySet(b => b.Enabled = false);

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("You Left The Lights On", test.Logger[0]);
            }
        }
Ejemplo n.º 10
0
        public void asyncCommandGotoStaysInSameThread()
        {
            String script = @"
:main
async call runAsync
async call runAsync
print 'Main'
wait
print 'Still Main'

:runAsync
wait
print 'Async'
goto ""stillInThread""

:stillInThread
print 'Still Async'
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads which wait 1 turn

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

                test.RunOnce();//Execute print in both async threads. execute goto in both async threads

                Assert.AreEqual(4, test.Logger.Count);
                Assert.AreEqual("Still Main", test.Logger[1]);
                Assert.AreEqual("Async", test.Logger[2]);
                Assert.AreEqual("Async", test.Logger[3]);

                test.RunUntilDone(); //Execute stillInThread in both async threads, which should complete and terminate.

                Assert.AreEqual(6, test.Logger.Count);
                Assert.AreEqual("Still Async", test.Logger[4]);
                Assert.AreEqual("Still Async", test.Logger[5]);
            }
        }
Ejemplo n.º 11
0
        public void IterateOverListByKeys()
        {
            String script = @"
:main
assign myList to [1,2,3]
assign myList[""key1""] to ""value1""
assign myList[""key2""] to ""value2""
assign myKeys to myList keys
Print ""Keys: "" + myKeys
assign i to 0
until i >= count of myKeys[]
  Print ""myList["" + myKeys[i] + ""] = "" + myList[myKeys[i]]
  assign i to i + 1
";

            using (var test = new ScriptTest(script)) {
                test.RunUntilDone();

                Assert.IsTrue(test.Logger.Contains("Keys: [key1,key2]"));
                Assert.IsTrue(test.Logger.Contains("myList[key1] = value1"));
                Assert.IsTrue(test.Logger.Contains("myList[key2] = value2"));
            }
        }
Ejemplo n.º 12
0
        public void BlocksAloneAndInGroups()
        {
            String script = @"
:lightshow
set the ""single light"" intensity to 10
set the ""hangar lights"" blinkInterval to 0.5
set the ""hangar lights"" blinkOffset to 0.25
turn on the ""hangar lights""
";

            using (ScriptTest test = new ScriptTest(script))
            {
                // In this test, single light and other light are both in
                // a group called "hangar lights"
                // We want to ensure that we're manipulating both lights when we
                // perform commands on the group, but that we can still interact
                // with just one of the lights when we want to
                var mockSingleLight = new Mock <IMyLightingBlock>();
                var mockOtherLight  = new Mock <IMyLightingBlock>();
                test.MockBlocksInGroup("hangar lights", mockSingleLight, mockOtherLight);
                test.MockBlocksOfType("other light", mockOtherLight);
                test.MockBlocksOfType("single light", mockSingleLight);

                test.RunUntilDone();

                mockSingleLight.VerifySet(b => b.Intensity            = 10f);
                mockSingleLight.VerifySet(b => b.BlinkIntervalSeconds = 0.5f);
                mockSingleLight.VerifySet(b => b.BlinkOffset          = 0.25f);
                mockOtherLight.VerifySet(b => b.BlinkIntervalSeconds  = 0.5f);
                mockOtherLight.VerifySet(b => b.BlinkOffset           = 0.25f);
                mockSingleLight.VerifySet(b => b.Enabled = true);
                mockOtherLight.VerifySet(b => b.Enabled  = true);
                // We should have never manipulated the intensity of "other light"
                mockOtherLight.VerifySet(b => b.Intensity = 10f, Times.Never);
            }
        }
Ejemplo n.º 13
0
        public void programRunsUntilAsyncMethodsComplete()
        {
            String script = @"
:main
async call runAsync
print 'Main'

:runAsync
wait 10 ticks
print 'Async'
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async thread

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

                test.RunUntilDone();

                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Async", test.Logger[1]);
            }
        }