Merge branch 'master' into develop

# Conflicts:
#	xpcPlugin/XPlaneConnect/mac.xpl
#	xpcPlugin/xpcPlugin.xcodeproj/project.pbxproj
This commit is contained in:
Chris Teubert
2016-02-29 12:48:30 -08:00
parent 8d5af7e47e
commit cfdd183214
100 changed files with 4224 additions and 1912 deletions

View File

@@ -21,9 +21,20 @@
<ItemGroup>
<ClCompile Include="..\..\C\src\xplaneConnect.c" />
<ClCompile Include="..\C Tests\main.c" />
<ClCompile Include="..\C Tests\Test.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\C\src\xplaneConnect.h" />
<ClInclude Include="..\C Tests\CtrlTests.h" />
<ClInclude Include="..\C Tests\DataTests.h" />
<ClInclude Include="..\C Tests\DrefTests.h" />
<ClInclude Include="..\C Tests\PosiTests.h" />
<ClInclude Include="..\C Tests\SimuTests.h" />
<ClInclude Include="..\C Tests\Test.h" />
<ClInclude Include="..\C Tests\TextTests.h" />
<ClInclude Include="..\C Tests\UDPTests.h" />
<ClInclude Include="..\C Tests\ViewTests.h" />
<ClInclude Include="..\C Tests\WyptTests.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{BC701AF4-552C-4C9D-82A1-B352542783A4}</ProjectGuid>

View File

@@ -21,10 +21,40 @@
<ClCompile Include="..\..\C\src\xplaneConnect.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\C Tests\Test.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\C\src\xplaneConnect.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\C Tests\UDPTests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\C Tests\DrefTests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\C Tests\TextTests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\C Tests\SimuTests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\C Tests\CtrlTests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\C Tests\DataTests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\C Tests\PosiTests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\C Tests\WyptTests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\C Tests\Test.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
BE7CF6311B0CFA34008B1E07 /* Test.c in Sources */ = {isa = PBXBuildFile; fileRef = BE7CF62B1B0CFA34008B1E07 /* Test.c */; };
BEB0F5071A28F9A3001975A6 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = BEB0F5061A28F9A3001975A6 /* main.c */; };
BEB0F5091A28F9A3001975A6 /* C_Tests.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BEB0F5081A28F9A3001975A6 /* C_Tests.1 */; };
BEB0F5111A28F9D5001975A6 /* xplaneConnect.c in Sources */ = {isa = PBXBuildFile; fileRef = BEB0F50F1A28F9D5001975A6 /* xplaneConnect.c */; };
@@ -27,6 +28,17 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
BE7CF6261B0CFA34008B1E07 /* CtrlTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CtrlTests.h; sourceTree = "<group>"; };
BE7CF6271B0CFA34008B1E07 /* DataTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataTests.h; sourceTree = "<group>"; };
BE7CF6281B0CFA34008B1E07 /* DrefTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrefTests.h; sourceTree = "<group>"; };
BE7CF6291B0CFA34008B1E07 /* PosiTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PosiTests.h; sourceTree = "<group>"; };
BE7CF62A1B0CFA34008B1E07 /* SimuTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimuTests.h; sourceTree = "<group>"; };
BE7CF62B1B0CFA34008B1E07 /* Test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Test.c; sourceTree = "<group>"; };
BE7CF62C1B0CFA34008B1E07 /* Test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Test.h; sourceTree = "<group>"; };
BE7CF62D1B0CFA34008B1E07 /* TextTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTests.h; sourceTree = "<group>"; };
BE7CF62E1B0CFA34008B1E07 /* UDPTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UDPTests.h; sourceTree = "<group>"; };
BE7CF62F1B0CFA34008B1E07 /* ViewTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewTests.h; sourceTree = "<group>"; };
BE7CF6301B0CFA34008B1E07 /* WyptTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WyptTests.h; sourceTree = "<group>"; };
BEB0F5031A28F9A3001975A6 /* C Tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "C Tests"; sourceTree = BUILT_PRODUCTS_DIR; };
BEB0F5061A28F9A3001975A6 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
BEB0F5081A28F9A3001975A6 /* C_Tests.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = C_Tests.1; sourceTree = "<group>"; };
@@ -66,6 +78,17 @@
BEB0F5051A28F9A3001975A6 /* C Tests */ = {
isa = PBXGroup;
children = (
BE7CF6261B0CFA34008B1E07 /* CtrlTests.h */,
BE7CF6271B0CFA34008B1E07 /* DataTests.h */,
BE7CF6281B0CFA34008B1E07 /* DrefTests.h */,
BE7CF6291B0CFA34008B1E07 /* PosiTests.h */,
BE7CF62A1B0CFA34008B1E07 /* SimuTests.h */,
BE7CF62B1B0CFA34008B1E07 /* Test.c */,
BE7CF62C1B0CFA34008B1E07 /* Test.h */,
BE7CF62D1B0CFA34008B1E07 /* TextTests.h */,
BE7CF62E1B0CFA34008B1E07 /* UDPTests.h */,
BE7CF62F1B0CFA34008B1E07 /* ViewTests.h */,
BE7CF6301B0CFA34008B1E07 /* WyptTests.h */,
BEB0F5061A28F9A3001975A6 /* main.c */,
BEB0F5081A28F9A3001975A6 /* C_Tests.1 */,
);
@@ -126,6 +149,7 @@
BEB0F5111A28F9D5001975A6 /* xplaneConnect.c in Sources */,
BEB0F5121A28F9D5001975A6 /* xplaneConnect.h in Sources */,
BEB0F5071A28F9A3001975A6 /* main.c in Sources */,
BE7CF6311B0CFA34008B1E07 /* Test.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -0,0 +1,188 @@
//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 doGETCTest(float values[7], int ac, float expected[7])
{
// Execute Test
float actual[7];
XPCSocket sock = openUDP(IP);
int result = sendCTRL(sock, values, 7, ac);
if (result >= 0)
{
result = getCTRL(sock, actual, ac);
}
closeUDP(sock);
if (result < 0)
{
return -1;
}
// Test values
for (int i = 0; i < 7; ++i)
{
if (fabs(expected[i] - actual[i]) > 1e-4)
{
return -10 - i;
}
}
return 0;
}
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;
}
return 0;
}
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;
}
return 0;
}
int testGETC()
{
float CTRL[7] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F, -1.5F };
return doGETCTest(CTRL, 0, CTRL);
}
int testGETC_NonPlayer()
{
float CTRL[7] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F, -1.5F };
return doGETCTest(CTRL, 2, CTRL);
}
#endif

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,158 @@
//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 doGETPTest(float values[7], int ac, float expected[7])
{
// Execute Test
float actual[7];
XPCSocket sock = openUDP(IP);
int result = sendPOSI(sock, values, 7, ac);
if (result >= 0)
{
result = getPOSI(sock, actual, ac);
}
closeUDP(sock);
if (result < 0)
{
return -1;
}
// Test values
for (int i = 0; i < 7; ++i)
{
if (fabs(expected[i] - actual[i]) > 1e-4)
{
return -10 - i;
}
}
return 0;
}
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;
}
return 0;
}
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);
}
int testGetPOSI_Player()
{
float POSI[7] = { 37.524F, -122.06899F, 2500, 0, 0, 0, 1 };
return doGETPTest(POSI, 0, POSI);
}
int testGetPOSI_NonPlayer()
{
float POSI[7] = { 37.624F, -122.06899F, 1500, 0, 0, 0, 1 };
return doGETPTest(POSI, 3, POSI);
}
#endif

View File

@@ -0,0 +1,81 @@
//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;
}
}
return 0;
}
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

View File

@@ -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;
}

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
#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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,73 @@
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
//National Aeronautics and Space Administration. All Rights Reserved.
#ifndef VIEWTESTS_H
#define VIEWTESTS_H
#include "Test.h"
#include "xplaneConnect.h"
typedef enum
{
XPC_VDREF_FORWARDS = 1000,
XPC_VDREF_DOWN4 = 1001,
XPC_VDREF_DOWN8 = 1002,
XPC_VDREF_LEFT45 = 1004,
XPC_VDREF_RIGHT45 = 1005,
XPC_VDREF_LEFT90 = 1006,
XPC_VDREF_RIGHT90 = 1007,
XPC_VDREF_LEFT135 = 1008,
XPC_VDREF_RIGHT135 = 1009,
XPC_VDREF_BACKWARD = 1010,
XPC_VDREF_LEFTUP = 1011,
XPC_VDREF_RIGHTUP = 1012,
XPC_VDREF_AIRPORTBEACONTOWER = 1014,
XPC_VDREF_ONRUNWAY = 1015,
XPC_VDREF_CHASE = 1017,
XPC_VDREF_FOLLOW = 1018,
XPC_VDREF_FOLLOWWITHPANEL = 1019,
XPC_VDREF_SPOT = 1020,
XPC_VDREF_SPOTMOVING = 1021,
XPC_VDREF_FULLSCREENWITHHUD = 1023,
XPC_VDREF_FULLSCREENNOHUD = 1024,
XPC_VDREF_STRAIGHTDOWN = 1025,
XPC_VDREF_3DCOCKPIT = 1026
} VIEW_DREF;
int doViewTest(VIEW_TYPE viewCommand, VIEW_DREF viewResult)
{
// Setup
char* dref = "sim/graphics/view/view_type";
float value;
int size = 1;
// Execute command
XPCSocket sock = openUDP(IP);
int result = sendVIEW(sock, viewCommand);
if (result >= 0)
{
result = getDREF(sock, dref, &value, &size);
}
closeUDP(sock);
if (result < 0)
{
return -1;
}
if ((int)value != viewResult)
{
return -2;
}
return 0;
}
int testView()
{
int result = doViewTest(XPC_VIEW_FORWARDS, XPC_VDREF_FORWARDS);
if (result < 0)
{
return -1;
}
return doViewTest(XPC_VIEW_CHASE, XPC_VDREF_CHASE);
}
#endif

View File

@@ -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

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
package gov.nasa.xpc.test;
import gov.nasa.xpc.ViewType;
import gov.nasa.xpc.WaypointOp;
import gov.nasa.xpc.XPlaneConnect;
@@ -333,6 +334,33 @@ public class XPlaneConnectTest
}
}
@Test
public void testSendDREFs() throws IOException
{
String[] drefs =
{
"sim/cockpit/switches/gear_handle_status",
"sim/cockpit/autopilot/altitude"
};
try(XPlaneConnect xpc = new XPlaneConnect())
{
float[][] values = {{1}, {2000}};
xpc.sendDREFs(drefs, values);
float[][] result = xpc.getDREFs(drefs);
assertEquals(values[0][0], result[0][0], 1e-4);
assertEquals(values[1][0], result[1][0], 1e-4);
values[0][0] = 0;
values[1][0] = 4000;
xpc.sendDREFs(drefs, values);
result = xpc.getDREFs(drefs);
assertEquals(values[0][0], result[0][0], 1e-4);
assertEquals(values[1][0], result[1][0], 1e-4);
}
}
@Test(expected = IllegalArgumentException.class)
public void testSendDREF_NullDREF() throws IOException
{
@@ -650,4 +678,51 @@ public class XPlaneConnectTest
fail();
}
}
@Test
public void testSendView() throws IOException
{
String dref = "sim/graphics/view/view_type";
float fwd = 1000;
float chase = 1017;
try(XPlaneConnect xpc = new XPlaneConnect())
{
xpc.sendVIEW(ViewType.Forwards);
float result = xpc.getDREF(dref)[0];
assertEquals(fwd, result, 1e-4);
xpc.sendVIEW(ViewType.Chase);
result = xpc.getDREF(dref)[0];
assertEquals(chase, result, 1e-4);
}
}
@Test
public void testGetPOSI() throws IOException
{
float[] values = { 37.524F, -122.06899F, 2500.0F, 45.0F, -45.0F, 15.0F, 1.0F };
try(XPlaneConnect xpc = new XPlaneConnect())
{
xpc.pauseSim(true);
xpc.sendPOSI(values);
float[] actual = xpc.getPOSI(0);
assertArrayEquals(values, actual, 1e-4F);
}
}
@Test
public void testGetCTRL() throws IOException
{
float[] values = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F, -1.5F };
try(XPlaneConnect xpc = new XPlaneConnect())
{
xpc.sendCTRL(values);
float[] actual = xpc.getCTRL(0);
assertArrayEquals(values, actual, 1e-4F);
}
}
}

View File

@@ -0,0 +1,15 @@
function getCTRLTest()
%GETCTRLTEST Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
values = [10.0, 5.0, -5.0, 0.8, 1.0, 0.5, -1.5];
sendCTRL(values, 0);
actual = getCTRL(0);
assert(isequal(length(actual), length(values)));
for i = 1:length(actual)
assert(abs(actual(i) - values(i)) <1e-4)
end
end

View File

@@ -0,0 +1,17 @@
function getPOSITest()
%GETCTRLTEST Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
values = [ 37.524, -122.06899, 2500, 45, -45, 15, 1 ];
pauseSim(1);
sendPOSI(values, 0);
actual = getPOSI(0);
pauseSim(0);
assert(isequal(length(actual), length(values)));
for i = 1:length(actual)
assert(abs(actual(i) - values(i)) <1e-4)
end
end

View File

@@ -1,4 +1,4 @@
function CTRLTest( )
function sendCTRLTest( )
%CTRLTest Summary of this function goes here
% Detailed explanation goes here
%% Test player aircraft

View File

@@ -1,4 +1,4 @@
function POSITest( )
function sendPOSITest( )
%POSITest Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')

View File

@@ -0,0 +1,26 @@
function sendVIEWTest()
%% Setup
addpath('../../MATLAB')
import XPlaneConnect.*
if ~exist('gov.nasa.xpc.ViewType', 'class')
[folder, ~, ~] = fileparts(which('XPlaneConnect.openUDP'));
javaaddpath(fullfile(folder, 'XPlaneConnect.jar'));
end
dref = 'sim/graphics/view/view_type';
fwd = 1000;
chase = 1017;
%% Excecute
sendVIEW(gov.nasa.xpc.ViewType.Forwards);
result = getDREFs(dref);
assert(isequal(result, fwd))
sendVIEW(gov.nasa.xpc.ViewType.Chase);
result = getDREFs(dref);
assert(isequal(result, chase))
end

View File

@@ -1,3 +1,6 @@
addpath('../../MATLAB')
import XPlaneConnect.*
testsPassed=0;
testsFailed=0;
if ismac()
@@ -15,12 +18,16 @@ theTests = {{@openCloseTest, 'Open/Close Test', 0},...
{@getDREFsTest,'Request DREF Test', 0},...
{@sendDREFTest,'Send DREF Test', 0},...
{@DATATest,'DATA Test', 0},...
{@CTRLTest,'CTRL Test', 0},...
{@POSITest,'POSI Test', 0},...
{@sendCTRLTest,'sendCTRL Test', 0},...
{@getCTRLTest,'getCTRL Test', 0},...
{@sendPOSITest,'sendPOSI Test', 0},...
{@getPOSITest,'getPOSI Test', 0},...
{@sendWYPTTest,'WYPT Test', 0},...
{@sendVIEWTest,'VIEW Test', 0},...
{@pauseTest,'Pause Test', 0},...
{@setConnTest, 'setConn Test', 0}};
socket = openUDP();
for i=1:length(theTests)
fprintf(['Test ',num2str(i),': ',theTests{i}{2},' - ']);
try
@@ -35,6 +42,7 @@ for i=1:length(theTests)
testsFailed = testsFailed + 1;
end
end
closeUDP(socket);
disp('Results Summary:');
fprintf('Passed: %i\tFailed: %i\n',testsPassed, testsFailed);

View File

@@ -3,7 +3,7 @@ import unittest
import imp
import time
import xpc
xpc = imp.load_source('xpc', '../../Python/src/xpc.py')
class XPCTests(unittest.TestCase):
"""Tests the functionality of the XPlaneConnect class."""
@@ -117,6 +117,37 @@ class XPCTests(unittest.TestCase):
value = 0
do_test()
def test_sendDREFs(self):
drefs = [\
"sim/cockpit/switches/gear_handle_status",\
"sim/cockpit/autopilot/altitude"]
values = None
def do_test():
# Setup
client = xpc.XPlaneConnect()
# Execute
client.sendDREFs(drefs, values)
result = client.getDREFs(drefs)
# Cleanup
client.close()
# Tests
self.assertEqual(2, len(result))
self.assertEqual(1, len(result[0]))
self.assertEqual(values[0], result[0][0])
self.assertEqual(1, len(result[1]))
self.assertEqual(values[1], result[1][0])
# Test 1
values = [1, 2000]
do_test()
# Test 2
values = [0, 4000]
do_test()
def test_sendDATA(self):
# Setup
dref = "sim/aircraft/parts/acf_gear_deploy"
@@ -171,6 +202,29 @@ class XPCTests(unittest.TestCase):
expected = 0.0
do_test()
def test_getCTRL(self):
values = None
ac = 0
expected = None
def do_test():
with xpc.XPlaneConnect() as client:
# Execute
client.sendCTRL(values, ac)
result = client.getCTRL(ac)
# Test
self.assertEqual(len(result), len(expected))
for a, e in zip(result, expected):
self.assertAlmostEqual(a, e, 4)
values = [0.0, 0.0, 0.0, 0.8, 1.0, 0.5, -1.5]
expected = values
ac = 0
do_test()
ac = 3
do_test()
def test_sendCTRL(self):
# Setup
@@ -239,6 +293,31 @@ class XPCTests(unittest.TestCase):
ctrl[6] = 0.0
do_test()
def test_getPOSI(self):
values = None
ac = 0
expected = None
def do_test():
with xpc.XPlaneConnect() as client:
# Execute
client.pauseSim(True)
client.sendPOSI(values, ac)
result = client.getPOSI(ac)
client.pauseSim(False)
# Test
self.assertEqual(len(result), len(expected))
for a, e in zip(result, expected):
self.assertAlmostEqual(a, e, 4)
values = [ 37.524, -122.06899, 2500, 45, -45, 15, 1 ]
expected = values
ac = 0
do_test()
ac = 3
do_test()
def test_sendPOSI(self):
# Setup
drefs = ["sim/flightmodel/position/latitude",\
@@ -288,6 +367,22 @@ class XPCTests(unittest.TestCase):
# Cleanup
client.close()
def test_sendView(self):
# Setup
dref = "sim/graphics/view/view_type"
fwd = 1000
chase = 1017
#Execution
with xpc.XPlaneConnect() as client:
client.sendVIEW(xpc.ViewType.Forwards)
result = client.getDREF(dref)
self.assertAlmostEqual(fwd, result[0], 1e-4)
client.sendVIEW(xpc.ViewType.Chase)
result = client.getDREF(dref)
self.assertAlmostEqual(chase, result[0], 1e-4)
def test_sendWYPT(self):
# Setup
client = xpc.XPlaneConnect()