diff --git a/TestScripts/C Tests.win/CTests.vcxproj b/TestScripts/C Tests.win/CTests.vcxproj index c057e7d..b546a64 100644 --- a/TestScripts/C Tests.win/CTests.vcxproj +++ b/TestScripts/C Tests.win/CTests.vcxproj @@ -21,9 +21,19 @@ + + + + + + + + + + {BC701AF4-552C-4C9D-82A1-B352542783A4} diff --git a/TestScripts/C Tests.win/CTests.vcxproj.filters b/TestScripts/C Tests.win/CTests.vcxproj.filters index cd3ca2c..6e294b0 100644 --- a/TestScripts/C Tests.win/CTests.vcxproj.filters +++ b/TestScripts/C Tests.win/CTests.vcxproj.filters @@ -21,10 +21,40 @@ Source Files + + Source Files + Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/TestScripts/C Tests/CtrlTests.h b/TestScripts/C Tests/CtrlTests.h new file mode 100644 index 0000000..3465f70 --- /dev/null +++ b/TestScripts/C Tests/CtrlTests.h @@ -0,0 +1,147 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef CTRLTESTS_H +#define CTRLTESTS_H + +#include "Test.h" +#include "xplaneConnect.h" + +int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[7]) +{ + float* data[7]; + int sizes[7]; + for (int i = 0; i < 7; ++i) + { + data[i] = (float*)malloc(sizeof(float) * 16); + sizes[i] = 16; + } + + // Execute command + XPCSocket sock = openUDP(IP); + int result = sendCTRL(sock, values, size, ac); + if (result >= 0) + { + result = getDREFs(sock, drefs, data, 7, sizes); + } + closeUDP(sock); + if (result < 0) + { + return -1; + } + + // Test values + float actual[7]; + for (int i = 0; i < 7; ++i) + { + actual[i] = data[i][0]; + } + return compareArray(expected, actual, 7); +} + +int basicCTRLTest(char** drefs, int ac) +{ + // Set control surfaces to known state. + float CTRL[6] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F }; + float expected[7] = { 0.0F, 0.0F, 0.0F, NAN, NAN, NAN, NAN }; + int result = doCTRLTest(drefs, CTRL, 3, ac, expected); + if (result < 0) + { + return -10000 + result; + } + + // Test control surfaces and set other values to known state. + expected[0] = CTRL[0] = 0.2F; + expected[1] = CTRL[1] = 0.1F; + expected[2] = CTRL[2] = 0.1F; + expected[3] = 0.8F; + expected[4] = 1.0F; + expected[5] = 0.5F; + result = doCTRLTest(drefs, CTRL, 6, ac, expected); + if (result < 0) + { + return -20000 + result; + } + + // Test other values and verify control surfaces unchanged. + CTRL[0] = -998; + CTRL[1] = -998; + CTRL[2] = -998; + expected[3] = CTRL[3] = 0.9F; + expected[4] = CTRL[4] = 0.0F; + expected[5] = CTRL[5] = 0.75F; + result = doCTRLTest(drefs, CTRL, 6, ac, expected); + if (result < 0) + { + return -30000 + result; + } +} + +int testCTRL_Player() +{ + char* drefs[] = + { + "sim/cockpit2/controls/yoke_pitch_ratio", + "sim/cockpit2/controls/yoke_roll_ratio", + "sim/cockpit2/controls/yoke_heading_ratio", + "sim/flightmodel/engine/ENGN_thro", + "sim/cockpit/switches/gear_handle_status", + "sim/flightmodel/controls/flaprqst", + "sim/flightmodel/controls/sbrkrqst" + }; + return basicCTRLTest(drefs, 0); +} + +int testCTRL_NonPlayer() +{ + char* drefs[] = + { + "sim/multiplayer/position/plane1_yolk_pitch", + "sim/multiplayer/position/plane1_yolk_roll", + "sim/multiplayer/position/plane1_yolk_yaw", + "sim/multiplayer/position/plane1_throttle", + "sim/multiplayer/position/plane1_gear_deploy", + "sim/multiplayer/position/plane1_flap_ratio", + "sim/multiplayer/position/plane1_sbrkrqst" + }; + return basicCTRLTest(drefs, 1); +} + +int testCTRL_Speedbrakes() +{ + char* drefs[] = + { + "sim/cockpit2/controls/yoke_pitch_ratio", + "sim/cockpit2/controls/yoke_roll_ratio", + "sim/cockpit2/controls/yoke_heading_ratio", + "sim/flightmodel/engine/ENGN_thro", + "sim/cockpit/switches/gear_handle_status", + "sim/flightmodel/controls/flaprqst", + "sim/flightmodel/controls/sbrkrqst" + }; + + // Arm + float CTRL[7] = { -998, -998, -998, -998, -998, -998, -0.5F }; + float expected[7] = { NAN, NAN, NAN, NAN, NAN, NAN, -0.5F }; + int result = doCTRLTest(drefs, CTRL, 7, 0, expected); + if (result < 0) + { + return -10000 + result; + } + + // Set to full + expected[6] = CTRL[6] = 1.5F; + result = doCTRLTest(drefs, CTRL, 7, 0, expected); + if (result < 0) + { + return -20000 + result; + } + + // Retract + expected[6] = CTRL[6] = 0.0F; + result = doCTRLTest(drefs, CTRL, 7, 0, expected); + if (result < 0) + { + return -30000 + result; + } +} +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/DataTests.h b/TestScripts/C Tests/DataTests.h new file mode 100644 index 0000000..2bf1564 --- /dev/null +++ b/TestScripts/C Tests/DataTests.h @@ -0,0 +1,62 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef DATATESTS_H +#define DATATESTS_H + +#include "Test.h" +#include "xplaneConnect.h" + +int testDATA() +{ + // Initialize + int i, j; // Iterator + char* drefs[100] = + { + "sim/aircraft/parts/acf_gear_deploy" + }; + float* data[100]; // array for result of getDREFs + int sizes[100]; + float DATA[4][9]; // Array for sendDATA + XPCSocket sock = openUDP(IP); + + // Setup + for (int i = 0; i < 100; ++i) + { + data[i] = (float*)malloc(40 * sizeof(float)); + sizes[i] = 40; + } + for (i = 0; i < 4; i++) + { + for (j = 0; j < 9; j++) + { + data[i][j] = -998; + } + } + DATA[0][0] = 14; // Gear + DATA[0][1] = 1; + DATA[0][2] = 0; + + // Execution + sendDATA(sock, DATA, 1); + int result = getDREFs(sock, drefs, data, 1, sizes); + + // Close + closeUDP(sock); + + // Tests + if (result < 0)// Request 1 value + { + return -1; + } + if (sizes[0] != 10) + { + return -2; + } + if (*data[0] != data[0][1]) + { + return -3; + } + return 0; +} + +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/DrefTests.h b/TestScripts/C Tests/DrefTests.h new file mode 100644 index 0000000..50338a7 --- /dev/null +++ b/TestScripts/C Tests/DrefTests.h @@ -0,0 +1,247 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef DREFTESTS_H +#define DREFTESTS_H + +#include "Test.h" +#include "xplaneConnect.h" + +int doGETDTest(char* drefs[], float* expected[], int count, int sizes[]) +{ + // Setup memory + int* asizes = (int*)malloc(sizeof(int) * count); + float** actual = (float**)malloc(sizeof(float*) * count); + for (int i = 0; i < count; ++i) + { + asizes[i] = sizes[i]; + actual[i] = (float*)malloc(sizeof(float) * sizes[i]); + } + + // Execute command + XPCSocket sock = openUDP(IP); + int result = getDREFs(sock, drefs, actual, count, asizes); + closeUDP(sock); + if (result < 0) + { + return -1; + } + + // Test sizes and values + result = compareArrays(expected, sizes, actual, asizes, count); + for (int i = 0; i < count; ++i) + { + free(actual[i]); + } + free(actual); + free(asizes); + return result; +} + +int doDREFTest(char* drefs[], float* values[], float* expected[], int count, int sizes[]) +{ + // Setup memory + int* asizes = (int*)malloc(sizeof(int) * count); + float** actual = (float**)malloc(sizeof(float*) * count); + for (int i = 0; i < count; ++i) + { + asizes[i] = sizes[i]; + actual[i] = (float*)malloc(sizeof(float) * sizes[i]); + } + + // Execute command + XPCSocket sock = openUDP(IP); + int result = sendDREFs(sock, drefs, values, sizes, count); + if (result >= 0) + { + result = getDREFs(sock, drefs, actual, count, asizes); + } + closeUDP(sock); + if (result < 0) + { + return -1; + } + + // Test sizes and values + result = compareArrays(expected, sizes, actual, asizes, count); + for (int i = 0; i < count; ++i) + { + free(actual[i]); + } + free(actual); + free(asizes); + return result; +} + +int testGETD_Basic() +{ + char* drefs[] = + { + "sim/cockpit/switches/gear_handle_status", //int + "sim/cockpit/autopilot/altitude", //float + "sim/aircraft/prop/acf_prop_type", //int[8] + "sim/cockpit2/switches/panel_brightness_ratio", //float[4] + "sim/aircraft/view/acf_tailnum", //byte[40] + "sim/flightmodel/position/elevation" //double + }; + int sizes[] = { 1, 1, 8, 4, 40, 1 }; + float* expected[6]; + for (int i = 0; i < 6; ++i) + { + expected[i] = (float*)malloc(sizeof(float) * sizes[i]); + for (int j = 0; j < sizes[i]; ++j) + { + expected[i][j] = NAN; + } + } + + return doGETDTest(drefs, expected, 6, sizes); +} + +int testGETD_TestFloat() +{ + char* dref = "sim/test/test_float"; + int size = 1; + float* expected[1]; + expected[0] = (float*)malloc(sizeof(float)); + expected[0][0] = 0.0F; + + int result = doGETDTest(&dref, &expected, 1, &size); + free(expected[0]); + return result; +} + +int testGETD_Types() +{ + char* drefs[] = + { + "sim/cockpit/switches/gear_handle_status", //int + "sim/cockpit/autopilot/altitude", //float + "sim/aircraft/prop/acf_prop_type", //int[8] + "sim/cockpit2/switches/panel_brightness_ratio", //float[4] + "sim/aircraft/view/acf_tailnum", //byte[40] + "sim/flightmodel/position/elevation" //double + }; + int sizes[] = { 1, 1, 8, 4, 40, 1 }; + float* data[6]; + for (int i = 0; i < 6; ++i) + { + data[i] = (float*)malloc(sizeof(float) * sizes[i]); + } + + // Execute command + XPCSocket sock = openUDP(IP); + int result = getDREFs(sock, drefs, data, 6, sizes); + closeUDP(sock); + + // Tests + if (result < 0) + { + return -1; + } + // Verify sizes + if (sizes[0] != 1 || sizes[1] != 1 || sizes[2] != 8 + || sizes[3] != 4 || sizes[4] != 40 || sizes[5] != 1) + { + return -2; + } + // Verify integer drefs are integers + if ((float)((int)data[0][0]) != data[0][0]) + { + return -3; + } + for (int i = 0; i < 8; ++i) + { + if ((float)((int)data[2][i]) != data[2][i]) + { + return -3; + } + } + for (int i = 0; i < 40; ++i) + { + if ((float)((char)data[4][i]) != data[4][i]) + { + return -3; + } + } + // Verify tail number has at least one valid character + if (data[4][0] <= 0 || data[4][0] > 127) + { + return -4; + } + return 0; +} + +int testDREF() +{ + char* drefs[] = + { + "sim/cockpit/switches/gear_handle_status", //int + "sim/cockpit/autopilot/altitude", //float + "sim/aircraft/prop/acf_prop_type", //int[8] + "sim/cockpit2/switches/panel_brightness_ratio", //float[4] + "sim/aircraft/view/acf_tailnum", //byte[40] + "sim/flightmodel/position/elevation" //double - Read only + }; + float* values[6]; + float* expected[6]; + int sizes[6]; + + // Setup + sizes[0] = 1; + values[0] = (float*)malloc(sizes[0] * sizeof(float)); + expected[0] = values[0]; + values[0][0] = 1; + + sizes[1] = 1; + values[1] = (float*)malloc(sizes[1] * sizeof(float)); + expected[1] = values[1]; + values[1][0] = 4000.0F; + + sizes[2] = 8; + values[2] = (float*)malloc(sizes[2] * sizeof(float)); + expected[2] = values[2]; + for (int i = 0; i < 8; ++i) + { + values[2][i] = 0; + } + + sizes[3] = 4; + values[3] = (float*)malloc(sizes[3] * sizeof(float)); + expected[3] = values[3]; + for (int i = 0; i < 4; ++i) + { + values[3][i] = 0.25F; + } + + sizes[4] = 40; + values[4] = (float*)malloc(sizes[4] * sizeof(float)); + expected[4] = (float*)malloc(sizes[4] * sizeof(float)); + memset(values[4], 0, sizes[4] * sizeof(float)); + values[4][0] = 78.0F; //N + values[4][1] = 55.0F; //7 + values[4][2] = 52.0F; //4 + values[4][3] = 56.0F; //8 + values[4][4] = 53.0F; //5 + values[4][5] = 89.0F; //Y + + expected[4][0] = 78.0F; //N + expected[4][1] = 55.0F; //7 + expected[4][2] = 52.0F; //4 + expected[4][3] = 56.0F; //8 + expected[4][4] = 53.0F; //5 + expected[4][5] = 89.0F; //Y + for (int i = 6; i < sizes[4]; ++i) + { + expected[4][i] = NAN; + } + + sizes[5] = 1; + values[5] = (float*)malloc(sizes[5] * sizeof(float)); + expected[5] = (float*)malloc(sizes[5] * sizeof(float)); + values[5][0] = 5000.0F; + expected[5][0] = NAN; + + return doDREFTest(drefs, values, expected, 6, sizes); +} + +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/PosiTests.h b/TestScripts/C Tests/PosiTests.h new file mode 100644 index 0000000..dfc7e07 --- /dev/null +++ b/TestScripts/C Tests/PosiTests.h @@ -0,0 +1,120 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef POSITESTS_H +#define POSITESTS_H + +#include "Test.h" +#include "xplaneConnect.h" + +int doPOSITest(char* drefs[7], float values[], int size, int ac, float expected[7]) +{ + float* data[7]; + int sizes[7]; + for (int i = 0; i < 7; ++i) + { + data[i] = (float*)malloc(sizeof(float) * 10); + sizes[i] = 10; + } + + // Execute command + XPCSocket sock = openUDP(IP); + pauseSim(sock, 1); + int result = sendPOSI(sock, values, size, ac); + if (result >= 0) + { + result = getDREFs(sock, drefs, data, 7, sizes); + } + pauseSim(sock, 0); + closeUDP(sock); + if (result < 0) + { + return -1; + } + + // Test values + float actual[7]; + for (int i = 0; i < 7; ++i) + { + actual[i] = data[i][0]; + } + return compareArray(expected, actual, 7); +} + +int basicPOSITest(char** drefs, int ac) +{ + // Set psoition and initial orientation + float POSI[7] = { 37.524F, -122.06899F, 2500, 0, 0, 0, 1 }; + float expected[7] = { 37.524F, -122.06899F, 2500, 0, 0, 0, 1 }; + int result = doPOSITest(drefs, POSI, 7, ac, expected); + if (result < 0) + { + return -10000 + result; + } + + // Set orientation + POSI[0] = -998.0F; + POSI[1] = -998.0F; + POSI[2] = -998.0F; + POSI[3] = 5.0F; + POSI[4] = -5.0F; + POSI[5] = 10.0F; + POSI[6] = 0; + + float *loc[3]; + for (int i = 0; i < 3; ++i) + { + loc[i] = (float*)malloc(sizeof(float)); + } + int sizes[3] = { 1, 1, 1 }; + XPCSocket sock = openUDP(IP); + pauseSim(sock, 1); + getDREFs(sock, drefs, loc, 3, sizes); + closeUDP(sock); + + expected[0] = loc[0][0]; + expected[1] = loc[1][0]; + expected[2] = loc[2][0]; + expected[3] = 5.0F; + expected[4] = -5.0F; + expected[5] = 10.0F; + expected[6] = 0.0F; + result = doPOSITest(drefs, POSI, 7, ac, expected); + if (result < 0) + { + return -20000 + result; + } +} + +int testPOSI_Player() +{ + char* drefs[] = + { + "sim/flightmodel/position/latitude", + "sim/flightmodel/position/longitude", + "sim/flightmodel/position/elevation", + "sim/flightmodel/position/theta", + "sim/flightmodel/position/phi", + "sim/flightmodel/position/psi", + "sim/cockpit/switches/gear_handle_status" + }; + return basicPOSITest(drefs, 0); +} + +int testPOSI_NonPlayer() +{ + char* drefs[] = + { + "sim/multiplayer/position/plane1_lat", + "sim/multiplayer/position/plane1_lon", + "sim/multiplayer/position/plane1_el", + "sim/multiplayer/position/plane1_the", + "sim/multiplayer/position/plane1_phi", + "sim/multiplayer/position/plane1_psi", + "sim/multiplayer/position/plane1_gear_deploy" + }; + return basicPOSITest(drefs, 1); +} + + + +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/SimuTests.h b/TestScripts/C Tests/SimuTests.h new file mode 100644 index 0000000..1c807b7 --- /dev/null +++ b/TestScripts/C Tests/SimuTests.h @@ -0,0 +1,80 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef SIMUTESTS_H +#define SIMIUTESTS_H + +#include "Test.h" +#include "xplaneConnect.h" + +int doSIMUTest(int value, float expected) +{ + int size = 20; + float actual[20]; + char* dref = "sim/operation/override/override_planepath"; + + XPCSocket sock = openUDP(IP); + int result = pauseSim(sock, value); + if (result >= 0) + { + result = getDREF(sock, dref, &actual, &size); + } + closeUDP(sock); + if (result < 0) + { + return -1; + } + + for (int i = 0; i < 20; ++i) + { + if (!feq(actual[i], expected) && !isnan(expected)) + { + return -100 - i; + } + } +} + +int testSIMU_Basic() +{ + int result = doSIMUTest(0, 0); + if (result < 0) + { + return -1; + } + + result = doSIMUTest(1, 1); + if (result < 0) + { + return -2; + } + + result = doSIMUTest(0, 0); + if (result < 0) + { + return -3; + } + return 0; +} + +int testSIMU_Toggle() +{ + int result = doSIMUTest(0, 0); + if (result < 0) + { + return -1; + } + + result = doSIMUTest(2, 1); + if (result < 0) + { + return -1; + } + + result = doSIMUTest(2, 0); + if (result < 0) + { + return -3; + } + return 0; +} + +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/Test.c b/TestScripts/C Tests/Test.c new file mode 100644 index 0000000..cce713c --- /dev/null +++ b/TestScripts/C Tests/Test.c @@ -0,0 +1,51 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#include "Test.h" + +int testFailed = 0; +int testPassed = 0; + +void runTest(int(*test)(), char* name) +{ + printf("Running test %s... ", name); + int result = test(); // Run Test + if (result == 0) + { + printf("PASSED\n"); + testPassed++; + } + else + { + printf("Test %s - FAILED\n\tError: %i\n", name, result); + testFailed++; + } +} + +int compareFloat(float expected, float actual) +{ + return feq(expected, actual) || isnan(expected) ? 0 : -1; +} + +int compareArray(float expected[], float actual[], int size) +{ + return compareArrays(&expected, &size, &actual, &size, 1); +} + +int compareArrays(float* expected[], int esizes[], float* actual[], int asizes[], int count) +{ + for (int i = 0; i < count; ++i) + { + if (esizes[i] != asizes[i]) + { + return -100 - i; + } + for (int j = 0; j < esizes[i]; ++j) + { + if (!feq(actual[i][j], expected[i][j]) && !isnan(expected[i][j])) + { + return -1000 - i * 100 - j; + } + } + } + return 0; +} \ No newline at end of file diff --git a/TestScripts/C Tests/Test.h b/TestScripts/C Tests/Test.h new file mode 100644 index 0000000..c05a5eb --- /dev/null +++ b/TestScripts/C Tests/Test.h @@ -0,0 +1,25 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef TESTRUNNER_H +#define TESTRUNNER_H + +#include +#include +#include +#include +#include + +#define feq(x, y) (fabs(x - y) < 1e-4) + +#define IP "127.0.0.1" + +extern int testFailed; +extern int testPassed; + +void runTest(int(*test)(), char* name); + +int compareFloat(float expected, float actual); +int compareArray(float expected[], float actual[], int size); +int compareArrays(float* expected[], int esizes[], float* actual[], int asizes[], int count); + +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/TextTests.h b/TestScripts/C Tests/TextTests.h new file mode 100644 index 0000000..badf16e --- /dev/null +++ b/TestScripts/C Tests/TextTests.h @@ -0,0 +1,32 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef TEXTTESTS_H +#define TEXTTESTS_H + +#include "Test.h" +#include "xplaneConnect.h" + +int testTEXT() +{ + // Setup + XPCSocket sendPort = openUDP(IP); + int x = 100; + int y = 700; + char* msg = "This is an X-Plane Connect test message.\nThis should be a new line.\r\nThat will be parsed as two line breaks."; + + // Test + sendTEXT(sendPort, msg, x, y); + // NOTE: Manually verify that msg appears on the screen in X-Plane! + + sendTEXT(sendPort, "Another test message", x, y); + // NOTE: Manually verify that msg appears on the screen and that no part of the previous + // message is visible. + + sendTEXT(sendPort, NULL, -1, -1); + + // Cleanup + closeUDP(sendPort); + return 0; +} + +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/UDPTests.h b/TestScripts/C Tests/UDPTests.h new file mode 100644 index 0000000..3c3d3fa --- /dev/null +++ b/TestScripts/C Tests/UDPTests.h @@ -0,0 +1,55 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef UDPTESTS_H +#define UDPTESTS_H + +#include "Test.h" +#include "xplaneConnect.h" + +int testOpen() +{ + XPCSocket sock = openUDP("localhost"); + int result = strncmp(sock.xpIP, "127.0.0.1", 16); + closeUDP(sock); + return result; +} + +int testClose() +{ + XPCSocket sendPort = aopenUDP(IP, 49009, 49063); + closeUDP(sendPort); + sendPort = aopenUDP(IP, 49009, 49063); + closeUDP(sendPort); + return 0; +} + +int testCONN() +{ + // Initialize + char* drefs[] = + { + "sim/cockpit/switches/gear_handle_status" + }; + float data[1]; + int size = 1; + XPCSocket sock = openUDP(IP); +#if (__APPLE__ || __linux) + usleep(0); +#endif + + // Execution + setCONN(&sock, 49055); + int result = getDREF(sock, drefs[0], data, &size); + + // Close + closeUDP(sock); + + // Test + if (result < 0)// No data received + { + return -1; + } + return 0; +} + +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/WyptTests.h b/TestScripts/C Tests/WyptTests.h new file mode 100644 index 0000000..fce3c2c --- /dev/null +++ b/TestScripts/C Tests/WyptTests.h @@ -0,0 +1,42 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef WYPTTESTS_H +#define WYPTTESTS_H + +#include "Test.h" +#include "xplaneConnect.h" + +int testWYPT() +{ + // Setup + XPCSocket sock = openUDP(IP); + float points[] = + { + 37.5245F, -122.06899F, 2500, + 37.455397F, -122.050037F, 2500, + 37.469567F, -122.051411F, 2500, + 37.479376F, -122.060509F, 2300, + 37.482237F, -122.076130F, 2100, + 37.474881F, -122.087288F, 1900, + 37.467660F, -122.079391F, 1700, + 37.466298F, -122.090549F, 1500, + 37.362562F, -122.039223F, 1000, + 37.361448F, -122.034416F, 1000, + 37.361994F, -122.026348F, 1000, + 37.365541F, -122.022572F, 1000, + 37.373727F, -122.024803F, 1000, + 37.403869F, -122.041283F, 50, + 37.418544F, -122.049222F, 6 + }; + + // Test + sendWYPT(sock, XPC_WYPT_CLR, NULL, 0); + sendWYPT(sock, XPC_WYPT_ADD, points, 15); + // NOTE: Visually ensure waypoints are added in the sim + + // Cleanup + closeUDP(sock); + return 0; +} + +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/main.c b/TestScripts/C Tests/main.c index 5f84eb8..ae01451 100644 --- a/TestScripts/C Tests/main.c +++ b/TestScripts/C Tests/main.c @@ -1,1029 +1,14 @@ -// -// main.cpp -// XPC Tests -// -// Created by Chris Teubert on 11/25/14. -// Copyright (c) 2014 Chris Teubert. All rights reserved. -// - -#include -#include -#include -#include -#include -#include "xplaneConnect.h" - -#define IP "127.0.0.1" - -int testFailed = 0; -int testPassed = 0; - -void runTest(int (*test)(), char* name) -{ - int result = test(); // Run Test - printf("Test %i: %s - ", testPassed + testFailed + 1, name); - if (result == 0) - { - printf("PASSED\n"); - testPassed++; - } - else - { - printf("FAILED\n\tError: %i\n", result); - testFailed++; - } -} - -int openTest() // openUDP Test -{ - XPCSocket sock = openUDP("localhost"); - int result = strncmp(sock.xpIP, "127.0.0.1", 16); - closeUDP(sock); - return result; -} - -int closeTest() // closeUDP test -{ - XPCSocket sendPort = aopenUDP(IP, 49009, 49063); - closeUDP(sendPort); - sendPort = aopenUDP(IP, 49009, 49063); - closeUDP(sendPort); - return 0; -} - -int sendTEXTTest() -{ - // Setup - XPCSocket sendPort = openUDP(IP); - int x = 100; - int y = 700; - char* msg = "This is an X-Plane Connect test message.\nThis should be a new line.\r\nThat will be parsed as two line breaks."; - - // Test - sendTEXT(sendPort, msg, x, y); - // NOTE: Manually verify that msg appears on the screen in X-Plane! - - sendTEXT(sendPort, "Another test message", x, y); - // NOTE: Manually verify that msg appears on the screen and that no part of the previous - // message is visible. - - sendTEXT(sendPort, NULL, -1, -1); - - // Cleanup - closeUDP(sendPort); - return 0; -} - -int getDREFTest() // Request DREF Test (Required for next tests) -{ - // Initialization - // Get one DREF of each type (int, float, int[], float[], double, byte[]) - #define GETD_COUNT 6 - char* drefs[GETD_COUNT] = - { - "sim/cockpit/switches/gear_handle_status", //int - "sim/cockpit/autopilot/altitude", //float - "sim/aircraft/prop/acf_prop_type", //int[8] - "sim/cockpit2/switches/panel_brightness_ratio", //float[4] - "sim/aircraft/view/acf_tailnum", //byte[40] - "sim/flightmodel/position/elevation" //double - }; - float* data[GETD_COUNT]; - int sizes[GETD_COUNT]; - XPCSocket sock = openUDP(IP); - - // Setup - for (int i = 0; i < GETD_COUNT; ++i) - { - data[i] = (float*)malloc(256 * sizeof(float)); - sizes[i] = 256; - } - - // Execution - int result = getDREFs(sock, drefs, data, GETD_COUNT, sizes); - - // Close - closeUDP(sock); - - // Tests - if (result < 0) - { - return -1; - } - // Verify sizes - if (sizes[0] != 1 || sizes[1] != 1 || sizes[2] != 8 - || sizes[3] != 4 || sizes[4] != 40 || sizes[5] != 1) - { - return -2; - } - // Verify integer drefs are integers - if ((float)((int)data[0][0]) != data[0][0]) - { - return -3; - } - for (int i = 0; i < 8; ++i) - { - if ((float)((int)data[2][i]) != data[2][i]) - { - return -3; - } - } - for (int i = 0; i < 40; ++i) - { - if ((float)((char)data[4][i]) != data[4][i]) - { - return -3; - } - } - // Verify tail number has at least one valid character - if (data[4][0] <= 0 || data[4][0] > 127) - { - return -4; - } - return 0; -} - -int sendDREFTest() // sendDREF test -{ - // Initialization - // Set one DREF of each type (int, float, int[], float[], double, byte[]) - // Also set one read-only to make sure it fails - #define DREF_COUNT 6 - char* drefs[DREF_COUNT] = - { - "sim/cockpit/switches/gear_handle_status", //int - "sim/cockpit/autopilot/altitude", //float - "sim/aircraft/prop/acf_prop_type", //int[8] - "sim/cockpit2/switches/panel_brightness_ratio", //float[4] - "sim/aircraft/view/acf_tailnum", //byte[40] - "sim/flightmodel/position/elevation" //double - Read only - }; - float* data[DREF_COUNT]; - int sizes[DREF_COUNT]; - float* values[DREF_COUNT]; - XPCSocket sock = openUDP(IP); - - // Setup - sizes[0] = 1; - values[0] = (float*)malloc(sizes[0] * sizeof(float)); - values[0][0] = 1; - - sizes[1] = 1; - values[1] = (float*)malloc(sizes[1] * sizeof(float)); - values[1][0] = 4000.0F; - - sizes[2] = 8; - values[2] = (float*)malloc(sizes[2] * sizeof(float)); - for (int i = 0; i < 8; ++i) - { - values[2][i] = 0; - } - - sizes[3] = 4; - values[3] = (float*)malloc(sizes[3] * sizeof(float)); - for (int i = 0; i < 4; ++i) - { - values[3][i] = 0.25F; - } - - sizes[4] = 40; - values[4] = (float*)malloc(sizes[4] * sizeof(float)); - memset(values[4], 0, sizes[4] * sizeof(float)); - values[4][0] = 78.0F; //N - values[4][1] = 55.0F; //7 - values[4][2] = 52.0F; //4 - values[4][3] = 56.0F; //8 - values[4][4] = 53.0F; //5 - values[4][5] = 89.0F; //Y - - sizes[5] = 1; - values[5] = (float*)malloc(sizes[5] * sizeof(float)); - values[5][0] = 5000.0F; - - // Execution - for (int i = 0; i < DREF_COUNT; ++i) - { - sendDREF(sock, drefs[i], values[i], sizes[i]); - data[i] = (float*)malloc(256 * sizeof(float)); - sizes[i] = 256; - } - int result = getDREFs(sock, drefs, data, DREF_COUNT, sizes); - - // Close - closeUDP(sock); - - // Tests - if (result < 0) - { - return -1; - } - // Verify gear handle was set - if (sizes[0] != 1 || data[0][0] != 1) - { - return -2; - } - // Verify autopilot altitude was set - if (sizes[1] != 1 || data[1][0] != 4000.0F) - { - return -3; - } - // Verify prop type was set - if (sizes[2] != 8) - { - return -4; - } - for (int i = 0; i < 8; ++i) - { - if (data[2][i] != values[2][i]) - { - return -4; - } - } - // Verify panel brightness was set - if (sizes[3] != 4) - { - return -5; - } - for (int i = 0; i < 4; ++i) - { - if (data[3][i] != values[3][i]) - { - return -5; - } - } - // Verify tail number was set - for (int i = 0; i < 6; ++i) - { - if (data[4][i] != values[4][i]) - { - return -6; - } - } - // Verify aircraft elevation was NOT set - if (sizes[5] != 1 || data[5][0] == 5000.0F) - { - return -7; - } - return 0; -} - -int sendDATATest() // sendDATA test -{ - // Initialize - int i,j; // Iterator - char* drefs[100] = - { - "sim/aircraft/parts/acf_gear_deploy" - }; - float* data[100]; // array for result of getDREFs - int sizes[100]; - float DATA[4][9]; // Array for sendDATA - XPCSocket sock = openUDP(IP); - - // Setup - for (int i = 0; i < 100; ++i) - { - data[i] = (float*)malloc(40 * sizeof(float)); - sizes[i] = 40; - } - for (i = 0; i < 4; i++) - { - for (j = 0; j < 9; j++) - { - data[i][j] = -998; - } - } - DATA[0][0] = 14; // Gear - DATA[0][1] = 1; - DATA[0][2] = 0; - - // Execution - sendDATA(sock, DATA, 1); - int result = getDREFs(sock, drefs, data, 1, sizes); - - // Close - closeUDP(sock); - - // Tests - if ( result < 0 )// Request 1 value - { - return -1; - } - if (sizes[0] != 10) - { - return -2; - } - if (*data[0] != data[0][1]) - { - return -3; - } - return 0; -} - -int psendCTRLTest() // sendCTRL test -{ - // Initialize - char* drefs[100] = - { - "sim/cockpit2/controls/yoke_pitch_ratio", - "sim/cockpit2/controls/yoke_roll_ratio", - "sim/cockpit2/controls/yoke_heading_ratio", - "sim/flightmodel/engine/ENGN_thro", - "sim/cockpit/switches/gear_handle_status", - "sim/flightmodel/controls/flaprqst" - }; - float* data[100]; - int sizes[100]; - float CTRL[6] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F }; - XPCSocket sock = openUDP(IP); - - // Setup - for (int i = 0; i < 100; i++) - { - data[i] = (float*)malloc(40 * sizeof(float)); - sizes[i] = 40; - } - - // Execute 1 - // 0 pitch, roll, yaw - sendCTRL(sock, CTRL, 3, 0); - int result = getDREFs(sock, drefs, data, 6, sizes); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -1; - } - for (int i = 0; i < 3; i++) - { - if (fabs(data[i][0] - CTRL[i]) > 1e-4) - { - return -i - 11; - } - } - - sock = openUDP(IP); - // Execute 2 - // Set non-zero pitch, roll, & yaw. Also set throttle, gear, and flaps - CTRL[0] = 0.2F; - CTRL[1] = 0.1F; - CTRL[2] = 0.1F; - sendCTRL(sock, CTRL, 6, 0); - result = getDREFs(sock, drefs, data, 6, sizes); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -2; - } - for (int i = 0; i < 6; i++) - { - if (fabs(data[i][0] - CTRL[i]) > 1e-4) - { - return -i - 21; - } - } - - sock = openUDP(IP); - // Execute 3 - // Set non-zero pitch, roll, & yaw. Also set throttle, gear, and flaps - float expected[] = { data[0][0], data[1][0], data[2][0], CTRL[3], CTRL[4], CTRL[5] }; - CTRL[0] = -998.0F; - CTRL[1] = -998.0F; - CTRL[2] = -998.0F; - sendCTRL(sock, CTRL, 6, 0); - result = getDREFs(sock, drefs, data, 6, sizes); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -3; - } - for (int i = 0; i < 6; i++) - { - if (fabs(data[i][0] - expected[i]) > 1e-2) - { - return -i - 31; - } - } - - return 0; -} - -int sendCTRLTest() -{ - // Initialize - char* drefs[100] = - { - "sim/multiplayer/position/plane1_yolk_pitch", - "sim/multiplayer/position/plane1_yolk_roll", - "sim/multiplayer/position/plane1_yolk_yaw", - "sim/multiplayer/position/plane1_throttle", - "sim/multiplayer/position/plane1_gear_deploy", - "sim/multiplayer/position/plane1_flap_ratio", - }; - float* data[100]; - int sizes[100]; - float CTRL[6] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F }; - XPCSocket sock = openUDP(IP); - - // Setup - for (int i = 0; i < 100; i++) - { - data[i] = (float*)malloc(40 * sizeof(float)); - sizes[i] = 40; - } - - // Execute 1 - // 0 pitch, roll, yaw - sendCTRL(sock, CTRL, 3, 1); - int result = getDREFs(sock, drefs, data, 6, sizes); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -1; - } - for (int i = 0; i < 3; i++) - { - if (fabs(data[i][0] - CTRL[i]) > 1e-4) - { - return -i - 11; - } - } - - sock = openUDP(IP); - // Execute 2 - // Set non-zero pitch, roll, & yaw. Also set throttle, gear, and flaps - CTRL[0] = 0.2F; - CTRL[1] = 0.1F; - CTRL[2] = 0.1F; - sendCTRL(sock, CTRL, 6, 1); - result = getDREFs(sock, drefs, data, 6, sizes); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -2; - } - for (int i = 0; i < 6; i++) - { - if (fabs(data[i][0] - CTRL[i]) > 1e-4) - { - return -i - 21; - } - } - - sock = openUDP(IP); - // Execute 3 - // Set non-zero pitch, roll, & yaw. Also set throttle, gear, and flaps - float expected[] = { data[0][0], data[1][0], data[2][0], CTRL[3], CTRL[4], CTRL[5] }; - CTRL[0] = -998.0F; - CTRL[1] = -998.0F; - CTRL[2] = -998.0F; - sendCTRL(sock, CTRL, 6, 1); - result = getDREFs(sock, drefs, data, 6, sizes); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -3; - } - for (int i = 0; i < 6; i++) - { - if (fabs(data[i][0] - expected[i]) > 1e-2) - { - return -i - 31; - } - } - - return 0; -} - - -int sendCTRLspeedbrakeTest() // sendCTRL test -{ - // Initialize - char* dref = "sim/flightmodel/controls/sbrkrqst"; - float data; - int size = 1; - float CTRL[7] = { -998.0F, -998.0F, -998.0F, -998.0F, -998.0F, -998.0F, -0.5F }; - XPCSocket sock = openUDP(IP); - - // Execute 1 - // Arm speedbrakes - sendCTRL(sock, CTRL, 7, 0); - int result = getDREF(sock, dref, &data, &size); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -1; - } - if (fabs(data - CTRL[6]) > 1e-4) - { - return -11; - } - - sock = openUDP(IP); - // Execute 2 - // Set full speedbrakes - CTRL[6] = 1.0F; - sendCTRL(sock, CTRL, 7, 0); - result = getDREF(sock, dref, &data, &size); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -2; - } - if (fabs(data - CTRL[6]) > 1e-4) - { - return -21; - } - - sock = openUDP(IP); - // Execute 3 - // Retract speedbrakes - CTRL[6] = 0.0F; - sendCTRL(sock, CTRL, 7, 0); - result = getDREF(sock, dref, &data, &size); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -3; - } - if (fabs(data - CTRL[6]) > 1e-4) - { - return -31; - } - - sock = openUDP(IP); - // Execute 4 - // Verify -998 does not change value. - CTRL[6] = -998.0F; - sendCTRL(sock, CTRL, 7, 0); - result = getDREF(sock, dref, &data, &size); - - // Close socket - closeUDP(sock); - - // Tests - if (result < 0) - { - return -4; - } - if (data> 1e-4) - { - return -41; - } - - return 0; -} - -int psendPOSITest() // sendPOSI test -{ - // Initialization - int i; // Iterator - char* drefs[100] = - { - "sim/flightmodel/position/latitude", - "sim/flightmodel/position/longitude", - "sim/flightmodel/position/elevation", - "sim/flightmodel/position/theta", - "sim/flightmodel/position/phi", - "sim/flightmodel/position/psi", - "sim/cockpit/switches/gear_handle_status" - }; - float* data[100]; - int sizes[100]; - float POSI[7] = { 37.524F, -122.06899F, 2500, 0, 0, 0, 1 }; - XPCSocket sock = openUDP(IP); - - // Setup - for (i = 0; i < 100; i++) - { - data[i] = (float*)malloc(40 * sizeof(float)); - sizes[i] = 40; - } - - // Execution 1 - pauseSim(sock, 1); - sendPOSI(sock, POSI, 7, 0); - int result = getDREFs(sock, drefs, data, 7, sizes); - pauseSim(sock, 0); - - // Close - closeUDP(sock); - - // Tests - if (result < 0) - { - return -1; - } - for (i = 0; i < 7; ++i) - { - if (fabs(data[i][0] - POSI[i]) > 1e-4) - { - return -i - 11; - } - } - - // Setup 2 - sock = openUDP(IP); - POSI[0] = -998.0F; - POSI[1] = -998.0F; - POSI[2] = -998.0F; - POSI[3] = 5.0F; - POSI[4] = -5.0F; - POSI[5] = 10.0F; - POSI[6] = 0; - - // Execution 2 - pauseSim(sock, 1); - float *loc[3]; - for(int i = 0; i < 3; ++i) - { - loc[i] = (float*)malloc(sizeof(float)); - } - getDREFs(sock, drefs, &loc, 3, sizes); - sendPOSI(sock, POSI, 7, 0); - result = getDREFs(sock, drefs, data, 7, sizes); - pauseSim(sock, 0); - - // Close - closeUDP(sock); - - // Tests - if (result < 0) - { - return -2; - } - // Compare position to make sure they weren't set - for (int i = 0; i < 3; ++i) - { - // Note: Because the sim was paused when both of these were read, we really do expect *exactly* - // the same value even though we are comparing floats. - if (data[i][0] != loc[i][0]) - { - return -i - 21; - } - } - // Compare everything else. - for (i = 3; i < 7; ++i) - { - if (fabs(data[i][0] - POSI[i]) > 1e-4) - { - return -i - 21; - } - } - - // Setup 3 - sock = openUDP(IP); - POSI[0] = 37.524F; - POSI[1] = -122.06899F; - POSI[2] = 20000; - POSI[3] = 15.0F; - POSI[4] = -25.0F; - POSI[5] = -10.0F; - POSI[6] = 1; - - // Execution 3 - pauseSim(sock, 1); - sendPOSI(sock, POSI, 3, 0); - result = getDREFs(sock, drefs, data, 7, sizes); - pauseSim(sock, 0); - - // Close - closeUDP(sock); - - // Tests - if (result < 0) - { - return -3; - } - // Compare position to make sure it was set. - for (int i = 0; i < 3; ++i) - { - if (fabs(data[i][0] - POSI[i]) > 1e-4) - { - return -i - 31; - } - } - // Compare everything else to make sure it *wasn't*. - for (i = 3; i < 7; ++i) - { - if (fabs(data[i][0] - POSI[i]) < 1) - { - return -i - 31; - } - } - - return 0; -} - -int sendPOSITest() // sendPOSI test -{ - // Initialization - int i; // Iterator - char* drefs[100] = - { - "sim/multiplayer/position/plane1_lat", - "sim/multiplayer/position/plane1_lon", - "sim/multiplayer/position/plane1_el", - "sim/multiplayer/position/plane1_the", - "sim/multiplayer/position/plane1_phi", - "sim/multiplayer/position/plane1_psi", - "sim/multiplayer/position/plane1_gear_deploy" - }; - float* data[100]; - int sizes[100]; - float POSI[7] = { 37.524F, -122.06899F, 2500, 0, 0, 0, 1 }; - XPCSocket sock = openUDP(IP); - - // Setup - for (i = 0; i < 100; i++) - { - data[i] = (float*)malloc(40 * sizeof(float)); - sizes[i] = 40; - } - - // Execution 1 - pauseSim(sock, 1); - sendPOSI(sock, POSI, 7, 1); - int result = getDREFs(sock, drefs, data, 7, sizes); - pauseSim(sock, 0); - - // Close - closeUDP(sock); - - // Tests - if (result < 0) - { - return -1; - } - for (i = 0; i < 7; ++i) - { - if (fabs(data[i][0] - POSI[i]) > 1e-4) - { - return -i - 11; - } - } - - // Setup 2 - sock = openUDP(IP); - POSI[0] = -998.0F; - POSI[1] = -998.0F; - POSI[2] = -998.0F; - POSI[3] = 5.0F; - POSI[4] = -5.0F; - POSI[5] = 10.0F; - POSI[6] = 0; - - // Execution 2 - pauseSim(sock, 1); - float* loc[3]; - for(int i = 0; i < 3; ++i) - { - loc[i] = (float*)malloc(sizeof(float)); - } - getDREFs(sock, drefs, loc, 3, sizes); - sendPOSI(sock, POSI, 7, 1); - result = getDREFs(sock, drefs, data, 7, sizes); - pauseSim(sock, 0); - - // Close - closeUDP(sock); - - // Tests - if (result < 0) - { - return -2; - } - // Compare position to make sure they weren't set - for (int i = 0; i < 3; ++i) - { - // Note: Because the sim was paused when both of these were read, we really do expect *exactly* - // the same value even though we are comparing floats. - if (data[i][0] != loc[i][0]) - { - return -i - 21; - } - } - // Compare everything else. - for (i = 3; i < 7; ++i) - { - if (fabs(data[i][0] - POSI[i]) > 1e-4) - { - return -i - 21; - } - } - - // Setup 3 - sock = openUDP(IP); - POSI[0] = 37.524F; - POSI[1] = -122.06899; - POSI[2] = 20000; - POSI[3] = 15.0F; - POSI[4] = -25.0F; - POSI[5] = -10.0F; - POSI[6] = 1; - - // Execution 2 - pauseSim(sock, 1); - sendPOSI(sock, POSI, 3, 1); - result = getDREFs(sock, drefs, data, 7, sizes); - pauseSim(sock, 0); - - // Close - closeUDP(sock); - - // Tests - if (result < 0) - { - return -3; - } - // Compare position to make sure it was set. - for (int i = 0; i < 3; ++i) - { - if (fabs(data[i][0] - POSI[i]) > 1e-4) - { - return -i - 31; - } - } - // Compare everything else to make sure it *wasn't*. - for (i = 3; i < 7; ++i) - { - if (fabs(data[i][0] - POSI[i]) < 1) - { - return -i - 31; - } - } - - return 0; -} - -int sendWYPTTest() -{ - // Setup - XPCSocket sock = openUDP(IP); - float points[] = - { - 37.5245F, -122.06899F, 2500, - 37.455397F, -122.050037F, 2500, - 37.469567F, -122.051411F, 2500, - 37.479376F, -122.060509F, 2300, - 37.482237F, -122.076130F, 2100, - 37.474881F, -122.087288F, 1900, - 37.467660F, -122.079391F, 1700, - 37.466298F, -122.090549F, 1500, - 37.362562F, -122.039223F, 1000, - 37.361448F, -122.034416F, 1000, - 37.361994F, -122.026348F, 1000, - 37.365541F, -122.022572F, 1000, - 37.373727F, -122.024803F, 1000, - 37.403869F, -122.041283F, 50, - 37.418544F, -122.049222F, 6 - }; - - // Test - sendWYPT(sock, XPC_WYPT_CLR, NULL, 0); - sendWYPT(sock, XPC_WYPT_ADD, points, 15); - // NOTE: Visually ensure waypoints are added in the sim - - // Cleanup - closeUDP(sock); - return 0; -} - -int pauseTest() // pauseSim test -{ - // Setup - // Note: Always run this test to the end so that the sim ends up unpaused in the - // case where commands are working but reading results isn't. - int result = 0; - char* dref = "sim/operation/override/override_planepath"; - int size = 20; - float data[20]; - XPCSocket sock = openUDP(IP); - - // Execute - pauseSim(sock, 0); - result = getDREF(sock, dref, data, &size); - - // Test - if (result < 0) - { - result = -1; - } - else if (data[0] != 0) - { - result = -2; - } - - if (result == 0) - { - // Execute 2 - pauseSim(sock, 2); - result = getDREF(sock, dref, data, &size); - - // Test 2 - if (result < 0) - { - result = -3; - } - else if (data[0] != 1) - { - result = -4; - } - } - - if (result == 0) - { - // Execute 3 - pauseSim(sock, 0); - result = getDREF(sock, dref, data, &size); - - // Test 2 - if (result < 0) - { - result = -5; - } - else if (data[0] != 0) - { - result = -6; - } - } - - // Close - closeUDP(sock); - - return result; -} - -int connTest() // setConn test -{ - // Initialize - char* drefs[100] = - { - "sim/cockpit/switches/gear_handle_status" - }; - float* data[100]; - int sizes[100]; - XPCSocket sock = openUDP(IP); -#if (__APPLE__ || __linux) - usleep(0); -#endif - - // Setup - for (int i = 0; i < 100; ++i) - { - data[i] = (float*)malloc(40 * sizeof(float)); - sizes[i] = 40; - } - - // Execution - setCONN(&sock, 49055); - int result = getDREF(sock, drefs[0], data[0], sizes); - - // Close - closeUDP(sock); - - // Test - if ( result < 0 )// No data received - { - return -1; - } - return 0; -} +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#include "Test.h" +#include "UDPTests.h" +#include "DrefTests.h" +#include "SimuTests.h" +#include "CtrlTests.h" +#include "PosiTests.h" +#include "DataTests.h" +#include "TextTests.h" +#include "WyptTests.h" int main(int argc, const char * argv[]) { @@ -1035,22 +20,36 @@ int main(int argc, const char * argv[]) printf("(Mac) \n"); #elif (__linux) printf("(Linux) \n"); +#else + printf("(Unable to determine operating system) \n") #endif - runTest(openTest, "open"); - runTest(closeTest, "close"); - runTest(pauseTest, "SIMU"); - runTest(getDREFTest, "GETD"); - runTest(sendDREFTest, "DREF"); - runTest(sendDATATest, "DATA"); - runTest(sendCTRLTest, "CTRL"); - runTest(psendCTRLTest, "CTRL (player)"); - runTest(sendCTRLspeedbrakeTest, "CTRL (speedbrake)"); - runTest(sendPOSITest, "POSI"); - runTest(psendPOSITest, "POSI (player)"); - runTest(sendWYPTTest, "WYPT"); - runTest(sendTEXTTest, "TEXT"); - runTest(connTest, "CONN"); + // Basic Networking + runTest(testOpen, "open"); + runTest(testClose, "close"); + // Datarefs + runTest(testGETD_Basic, "GETD"); + runTest(testGETD_Types, "GETD (types)"); + runTest(testGETD_TestFloat, "GETD (test float)"); + runTest(testDREF, "DREF"); + // Pause + runTest(testSIMU_Basic, "SIMU"); + runTest(testSIMU_Toggle, "SIMU (toggle)"); + // CTRL + runTest(testCTRL_Player, "CTRL (player)"); + runTest(testCTRL_NonPlayer, "CTRL (non-player)"); + runTest(testCTRL_Speedbrakes, "CTRL (speedbrakes)"); + // POSI + runTest(testPOSI_Player, "POSI (player)"); + runTest(testPOSI_NonPlayer, "POSI (non-player)"); + // Data + runTest(testDATA, "DATA"); + // Text + runTest(testTEXT, "TEXT"); + // Waypoints + runTest(testWYPT, "WYPT"); + // setConn + runTest(testCONN, "CONN"); printf( "----------------\nTest Summary\n\tFailed: %i\n\tPassed: %i\n", testFailed, testPassed );