Fixed several bugs found by unit tests.

This commit is contained in:
Jason Watkins
2015-04-28 11:54:48 -07:00
parent 31095b716b
commit 685d121edd
3 changed files with 89 additions and 24 deletions

View File

@@ -8,15 +8,50 @@ class XPCTests(unittest.TestCase):
"""Tests the functionality of the XPlaneConnect class."""
def test_init(self):
xpc = xplaneConnect.XPlaneConnect()
self.assertTrue(True)
try:
xpc = xplaneConnect.XPlaneConnect()
except:
self.fail("Default constructor failed.")
try:
xpc = xplaneConnect.XPlaneConnect("I'm not a real host")
self.fail("Failed to catch invalid XP host.")
except ValueError:
pass
try:
xpc = xplaneConnect.XPlaneConnect("127.0.0.1", 90001)
self.fail("Failed to catch invalid XP port.")
except ValueError:
pass
try:
xpc = xplaneConnect.XPlaneConnect("127.0.0.1", -1)
self.fail("Failed to catch invalid XP port.")
except ValueError:
pass
try:
xpc = xplaneConnect.XPlaneConnect("127.0.0.1", 49009, 90001)
self.fail("Failed to catch invalid local port.")
except ValueError:
pass
try:
xpc = xplaneConnect.XPlaneConnect("127.0.0.1", 49009, -1)
self.fail("Failed to catch invalid XP port.")
except ValueError:
pass
try:
xpc = xplaneConnect.XPlaneConnect("127.0.0.1", 49009, 0, -1)
self.fail("Failed to catch invalid timeout.")
except ValueError:
pass
def test_close(self):
xpc = xplaneConnect.XPlaneConnect("127.0.0.1", 49009, 49063)
xpc.close()
self.assertIsNone(xpc.socket)
xpc = xplaneConnect.XPlaneConnect("127.0.0.1", 49009, 49063)
self.assertTrue(True)
def test_send_read(self):
# Init
@@ -38,10 +73,11 @@ class XPCTests(unittest.TestCase):
for a, b in zip(test, buf):
self.assertEqual(a, b)
def test_request_dref(self):
def test_getDREFs(self):
# Setup
xpc = xplaneConnect.XPlaneConnect()
drefs = ["sim/cockpit/switches/gear_handle_status", "cockpit2/switches/panel_brightness_ratio"]
drefs = ["sim/cockpit/switches/gear_handle_status",\
"sim/cockpit2/switches/panel_brightness_ratio"]
# Execution
result = xpc.getDREFs(drefs)
@@ -54,22 +90,47 @@ class XPCTests(unittest.TestCase):
self.assertEqual(1, len(result[0]))
self.assertEqual(4, len(result[1]))
def test_send_dref(self):
def test_sendDREF(self):
# Setup
xpc = xplaneConnect.XPlaneConnect()
dref = "sim/cockpit/switches/gear_handle_status"
# Execution
sender.sendDREF(dref_array)
result = receiver.getDREF(dref_array)
xpc.sendDREF(dref, 0.0)
result = xpc.getDREF(dref)
# Cleanup
xpc.close();
xpc.close()
# Tests
self.assertEqual(1, len(result))
self.assertEqual(1, len(result[0]))
self.assertEqual(0.0, result[0][0])
self.assertEqual(0.0, result[0])
def test_pauseSim(self):
# Setup
xpc = xplaneConnect.XPlaneConnect()
dref = "sim/operation/override/override_planepath"
# Execution 1
xpc.pauseSim(True)
result = xpc.getDREF(dref)
# Cleanup 1
xpc.close()
# Test 1
self.assertAlmostEqual(1.0, result[0])
# Execution 2
xpc = xplaneConnect.XPlaneConnect()
xpc.pauseSim(False)
result = xpc.getDREF(dref)
# Cleanup 2
xpc.close()
# Tests
self.assertEqual(0.0, result[0])
if __name__ == '__main__':
unittest.main()