Browse Source
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1227 f9c3cf11-9bcb-44bc-f272-b75c42450872master
mandrolic
14 years ago
9 changed files with 149 additions and 73 deletions
@ -1,44 +1,52 @@
@@ -1,44 +1,52 @@
|
||||
using ArducopterConfigurator; |
||||
using ArducopterConfigurator.PresentationModels; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ArducopterConfiguratorTest |
||||
{ |
||||
public abstract class VmTestBase<T> where T : MonitorVm |
||||
[TestFixture] |
||||
public class AltitudeHoldVmTest : VmTestBase<AltitudeHoldConfigVm> |
||||
{ |
||||
protected T _vm; |
||||
protected FakeComms _fakeComms; |
||||
protected string sampleLineOfData; |
||||
protected string getCommand; |
||||
protected string setCommand; |
||||
|
||||
[Test] |
||||
public void ActivateSendsCorrectCommand() |
||||
[SetUp] |
||||
public void Setup() |
||||
{ |
||||
_vm.Activate(); |
||||
Assert.AreEqual(1, _fakeComms.SentItems.Count); |
||||
Assert.AreEqual(getCommand, _fakeComms.SentItems[0]); |
||||
sampleLineOfData = "0.800,0.200,0.300"; |
||||
getCommand = "F"; |
||||
setCommand = "E"; |
||||
|
||||
_fakeComms = new FakeComms(); |
||||
_vm = new AltitudeHoldConfigVm(_fakeComms); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void ReceivedDataIgnoredWhenNotActive() |
||||
// For whatever reason, for Altitude the properties are sent in P, D ,I |
||||
// order, but received in P,I,D order |
||||
public void UpdateStringSentIsCorrect() |
||||
{ |
||||
bool inpcFired = false; |
||||
_vm.PropertyChanged += delegate { inpcFired = true; }; |
||||
_vm.P = 1.0F; |
||||
_vm.I = 2.0F; |
||||
_vm.D = 3.0F; |
||||
|
||||
_fakeComms.FireLineRecieve(sampleLineOfData); |
||||
Assert.False(inpcFired); |
||||
_vm.UpdateCommand.Execute(null); |
||||
|
||||
Assert.AreEqual(1, _fakeComms.SentItems.Count); |
||||
Assert.AreEqual("E1;3;2", _fakeComms.SentItems[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void UpdateStringReceivedPopulatesValues() |
||||
// For whatever reason, for Altitude the properties are sent in P, D ,I |
||||
// order, but received in P,I,D order |
||||
public void UpdateStringReceivedPopulatesValuesCorrectly() |
||||
{ |
||||
bool inpcFired = false; |
||||
_vm.PropertyChanged += delegate { inpcFired = true; }; |
||||
|
||||
_vm.Activate(); |
||||
_fakeComms.FireLineRecieve(sampleLineOfData); |
||||
|
||||
Assert.True(inpcFired); |
||||
Assert.AreEqual(0.8f, _vm.P); |
||||
Assert.AreEqual(0.2f, _vm.I); |
||||
Assert.AreEqual(0.3f, _vm.D); |
||||
} |
||||
|
||||
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
using ArducopterConfigurator.PresentationModels; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ArducopterConfiguratorTest |
||||
{ |
||||
[TestFixture] |
||||
public class CalibrationOffsetsDataVmTest : VmTestBase<CalibrationOffsetsDataVm> |
||||
{ |
||||
|
||||
[SetUp] |
||||
public void Setup() |
||||
{ |
||||
sampleLineOfData = "0.100,0.200,0.300,0.400,0.500,0.600"; |
||||
getCommand = "J"; |
||||
setCommand = "I"; |
||||
|
||||
_fakeComms = new FakeComms(); |
||||
_vm = new CalibrationOffsetsDataVm(_fakeComms); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
using ArducopterConfigurator.PresentationModels; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ArducopterConfiguratorTest |
||||
{ |
||||
[TestFixture] |
||||
public class PositionHoldConfigVmTest : VmTestBase<PositionHoldConfigVm> |
||||
{ |
||||
|
||||
[SetUp] |
||||
public void Setup() |
||||
{ |
||||
sampleLineOfData = "0.015,0.005,0.010,0.015,0.005,0.010,22.000,0.870"; |
||||
getCommand = "D"; |
||||
setCommand = "C"; |
||||
|
||||
_fakeComms = new FakeComms(); |
||||
_vm = new PositionHoldConfigVm(_fakeComms); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
using ArducopterConfigurator; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ArducopterConfiguratorTest |
||||
{ |
||||
public abstract class VmTestBase<T> where T : MonitorVm |
||||
{ |
||||
protected T _vm; |
||||
protected FakeComms _fakeComms; |
||||
protected string sampleLineOfData; // should be taken from a real APM if possible |
||||
protected string getCommand; |
||||
protected string setCommand; |
||||
|
||||
[Test] |
||||
public void ActivateSendsCorrectCommand() |
||||
{ |
||||
_vm.Activate(); |
||||
Assert.AreEqual(1, _fakeComms.SentItems.Count); |
||||
Assert.AreEqual(getCommand, _fakeComms.SentItems[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReceivedDataIgnoredWhenNotActive() |
||||
{ |
||||
bool inpcFired = false; |
||||
_vm.PropertyChanged += delegate { inpcFired = true; }; |
||||
|
||||
_fakeComms.FireLineRecieve(sampleLineOfData); |
||||
Assert.False(inpcFired); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReceivedDataIgnoredAfterDeActive() |
||||
{ |
||||
_vm.Activate(); |
||||
_fakeComms.FireLineRecieve(sampleLineOfData); |
||||
_vm.DeActivate(); |
||||
_fakeComms.FireLineRecieve(sampleLineOfData); |
||||
bool inpcFired = false; |
||||
_vm.PropertyChanged += delegate { inpcFired = true; }; |
||||
|
||||
Assert.False(inpcFired); |
||||
} |
||||
|
||||
[Test] |
||||
public void UpdateStringReceivedPopulatesValues() |
||||
{ |
||||
bool inpcFired = false; |
||||
_vm.PropertyChanged += delegate { inpcFired = true; }; |
||||
|
||||
_vm.Activate(); |
||||
_fakeComms.FireLineRecieve(sampleLineOfData); |
||||
|
||||
Assert.True(inpcFired); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue