diff --git a/Python/xplaneConnect.sln b/Python/xplaneConnect.sln index 415b6fa..cc45d45 100644 --- a/Python/xplaneConnect.sln +++ b/Python/xplaneConnect.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "xplaneConnect", "xplaneConnect.pyproj", "{3C7A940D-17C8-4E91-882F-9BC8B1D2F54B}" EndProject +Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Tests", "..\TestScripts\Python Tests\Tests.pyproj", "{6931EBB2-4E01-4C5A-86B6-668C0E75051B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -13,6 +15,8 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {3C7A940D-17C8-4E91-882F-9BC8B1D2F54B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3C7A940D-17C8-4E91-882F-9BC8B1D2F54B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6931EBB2-4E01-4C5A-86B6-668C0E75051B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6931EBB2-4E01-4C5A-86B6-668C0E75051B}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TestScripts/Python Tests/Tests.py b/TestScripts/Python Tests/Tests.py new file mode 100644 index 0000000..412c890 --- /dev/null +++ b/TestScripts/Python Tests/Tests.py @@ -0,0 +1,85 @@ +import random +import unittest +import imp + +xplaneConnect = imp.load_source('xplaneConnect', '../../Python/src/xplaneConnect.py') + +class XPCTests(unittest.TestCase): + """Tests the functionality of the XPlaneConnect class.""" + + def test_init(self): + xpc = xplaneConnect.XPlaneConnect(49062, "127.0.0.1", 49009) + self.assertTrue(True) + + def test_close(self): + xpc = xplaneConnect.XPlaneConnect(49063, "127.0.0.1", 49009) + xpc.close() + self.assertIsNone(xpc.socket) + xpc = xplaneConnect.XPlaneConnect(49063, "127.0.0.1", 49009) + self.assertTrue(True) + + def test_send_read(self): + # Init + test = "\x00\x01\x02\x03\x05" + + # Setup + sender = xplaneConnect.XPlaneConnect(49064, "127.0.0.1", 49063) + receiver = xplaneConnect.XPlaneConnect(49063, "127.0.0.1", 49009) + + # Execution + sender.send_udp(test) + buf = receiver.read_udp() + + # Cleanup + sender.close() + receiver.close() + + # Tests + for a, b in zip(test, buf): + self.assertEqual(a, b) + + def test_request_dref(self): + # Init + dref_array = [] + + # Setup + sender = xplaneConnect.XPlaneConnect(49064, "127.0.0.1", 49009) + dref_array.append("sim/cockpit/switches/gear_handle_status") + dref_array.append("cockpit2/switches/panel_brightness_ratio") + + # Execution + result = sender.request_dref(dref_array) + + # Cleanup + sender.close() + receiver.close() + + # Tests + self.assertEqual(2, len(result)) + self.assertEqual(1, len(result[0])) + self.assertEqual(4, len(result[1])) + + def test_send_dref(self): + # Init + dref_array = [] + + # Setup + sender = xplaneConnect.XPlaneConnect(49066, "127.0.0.1", 49009) + receiver = xplaneConnect.XPlaneConnect(49008, "127.0.0.1", 49009) + dref_array.append("sim/cockpit/switches/gear_handle_status") + + # Execution + sender.send_dref(dref_array[0]) + result = receiver.request_dref(dref_array) + + # Cleanup + sender.close() + receiver.close() + + # Tests + self.assertEqual(1, len(result)) + self.assertEqual(1, len(result[0])) + self.assertEqual(0.0, result[0][0]) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/TestScripts/Python Tests/Tests.pyproj b/TestScripts/Python Tests/Tests.pyproj new file mode 100644 index 0000000..d084785 --- /dev/null +++ b/TestScripts/Python Tests/Tests.pyproj @@ -0,0 +1,46 @@ + + + + Debug + 2.0 + 6931ebb2-4e01-4c5a-86b6-668c0e75051b + . + Tests.py + + + . + . + Tests + Tests + {2af0f10d-7135-4994-9156-5d01c9c11b7e} + 2.7 + + + true + false + + + true + false + + + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets + + + + + + + + + + \ No newline at end of file