Testing improvements- C/C++

This commit is contained in:
Chris Teubert
2014-12-01 15:36:37 -08:00
parent 9ea7011bfb
commit 851cebeea0
7 changed files with 375 additions and 80 deletions

View File

@@ -571,9 +571,8 @@ short parseRequest(const char my_message[], float *resultArray[], short arraySiz
int i, j; int i, j;
short count = my_message[5]; short count = my_message[5];
short place = 6; short place = 6;
float *tmp; float tmp;
float data[10]; float data[25];
tmp = malloc(sizeof(float));
for (i=0; i<count; i++) for (i=0; i<count; i++)
{ {
@@ -582,8 +581,8 @@ short parseRequest(const char my_message[], float *resultArray[], short arraySiz
for (j=0; j< arraySizes[i]; j++) for (j=0; j< arraySizes[i]; j++)
{ {
memcpy(tmp,&my_message[place+1],sizeof(float)); memcpy(&tmp,&my_message[place+1],sizeof(float));
data[j] = *tmp; data[j] = tmp;
} }
resultArray[i] = malloc(arraySizes[i]*sizeof(float)); resultArray[i] = malloc(arraySizes[i]*sizeof(float));
@@ -592,7 +591,6 @@ short parseRequest(const char my_message[], float *resultArray[], short arraySiz
place += 1 + arraySizes[i]*sizeof(float); place += 1 + arraySizes[i]*sizeof(float);
} }
free(tmp);
return count; return count;
} }

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<VariablesViewState
version = "1.0">
<ContextStates>
<ContextState
contextName = "parseRequest:xplaneConnect.c">
<PersistentStrings>
<PersistentString
value = "resultArray[i]">
</PersistentString>
</PersistentStrings>
</ContextState>
</ContextStates>
</VariablesViewState>

View File

@@ -2,4 +2,180 @@
<Bucket <Bucket
type = "1" type = "1"
version = "2.0"> version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "C Tests/main.c"
timestampString = "439166919.543326"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "368"
endingLineNumber = "368"
landmarkName = "test9()"
landmarkType = "7">
<Locations>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "test9"
moduleName = "C Tests"
urlString = "file:///Users/cteubert/Documents/XPC%20Project/XPlaneConnect/TestScripts/C%20Tests/main.c"
timestampString = "439166920.353158"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "368"
endingLineNumber = "368"
offsetFromSymbolStart = "39">
</Location>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "test9"
moduleName = "C Tests"
urlString = "file:///Users/cteubert/Documents/XPC%20Project/XPlaneConnect/TestScripts/C%20Tests/main.c"
timestampString = "439166920.355533"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "368"
endingLineNumber = "368"
offsetFromSymbolStart = "133">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "C Tests/main.c"
timestampString = "439166958.157499"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "371"
endingLineNumber = "371"
landmarkName = "test9()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "C Tests/main.c"
timestampString = "439166960.12566"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "372"
endingLineNumber = "372"
landmarkName = "test9()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "C Tests/main.c"
timestampString = "439166980.676448"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "383"
endingLineNumber = "383"
landmarkName = "test9()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../C/src/xplaneConnect.c"
timestampString = "439168827.040532"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "584"
endingLineNumber = "584"
landmarkName = "parseRequest()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "C Tests/main.c"
timestampString = "439168847.889951"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "327"
endingLineNumber = "327"
landmarkName = "test8()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "C Tests/main.c"
timestampString = "439168878.242947"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "369"
endingLineNumber = "369"
landmarkName = "test9()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "C Tests/main.c"
timestampString = "439168983.670569"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "411"
endingLineNumber = "411"
landmarkName = "test9()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "C Tests/main.c"
timestampString = "439169099.982578"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "412"
endingLineNumber = "412"
landmarkName = "test9()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket> </Bucket>

View File

@@ -44,6 +44,7 @@ short test2() // closeUDP test
printf("closeUDP - "); printf("closeUDP - ");
struct xpcSocket sendPort = openUDP( 49063, "127.0.0.1", 49009 ); struct xpcSocket sendPort = openUDP( 49063, "127.0.0.1", 49009 );
closeUDP(sendPort); closeUDP(sendPort);
sendPort = openUDP( 49063, "127.0.0.1", 49009 );
return 0; return 0;
} }
@@ -240,41 +241,47 @@ short test7() // sendCTRL test
float *recDATA[100]; float *recDATA[100];
short DREFSizes[100]; short DREFSizes[100];
struct xpcSocket sendPort, recvPort; struct xpcSocket sendPort, recvPort;
short result;
// Setup // Setup
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float)); recDATA[i] = (float *) malloc(40*sizeof(float));
memset(DREFArray[i],0,100); memset(DREFArray[i],0,100);
} }
sendPort = openUDP( 49067, "127.0.0.1", 49009 ); sendPort = openUDP( 49066, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 ); recvPort = openUDP( 49008, "127.0.0.1", 49009 );
strcpy(DREFArray[0],"sim/cockpit/switches/gear_handle_status"); strcpy(DREFArray[0],"sim/cockpit2/controls/yoke_pitch_ratio");
for (i=0;i<1;i++) { strcpy(DREFArray[1],"sim/cockpit2/controls/yoke_roll_ratio");
strcpy(DREFArray[2],"sim/cockpit2/controls/yoke_heading_ratio");
strcpy(DREFArray[3],"sim/flightmodel/engine/ENGN_thro");
strcpy(DREFArray[4],"sim/cockpit/switches/gear_handle_status");
strcpy(DREFArray[5],"sim/flightmodel/controls/flaprqsts");
for (i=0;i<5;i++) {
DREFSizes[i] = (int) strlen(DREFArray[i]); DREFSizes[i] = (int) strlen(DREFArray[i]);
} }
CTRL[3] = 0.8; // Throttle CTRL[3] = 0.8; // Throttle
// Execute // Execute
sendCTRL(sendPort, 4, CTRL); sendCTRL(sendPort, 4, CTRL);
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 6, recDATA, DREFSizes); // Test
// Close // Close
closeUDP(sendPort); closeUDP(sendPort);
closeUDP(recvPort); closeUDP(recvPort);
// Test // Tests
if ( result < 0 )// Request 1 value
// if (requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, DREFSizes) < 0)// Request 1 value {
// { return -6;
// return -1; }
// } for (i=0;i<6-1;i++)
// if (DREFSizes[0] != 1) {
// { if (abs(recDATA[i][0]-CTRL[i])>1e-4)
// return -2; {
// } return -i;
// if (*recDATA[0] != value) }
// { }
// return -3;
// }
return 0; return 0;
} }
@@ -289,16 +296,23 @@ short test8() // sendPOSI test
float *recDATA[100]; float *recDATA[100];
short DREFSizes[100]; short DREFSizes[100];
struct xpcSocket sendPort, recvPort; struct xpcSocket sendPort, recvPort;
short result;
// Setup // Setup
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float)); recDATA[i] = (float *) malloc(40*sizeof(float));
memset(DREFArray[i],0,100); memset(DREFArray[i],0,100);
} }
sendPort = openUDP( 49067, "127.0.0.1", 49009 ); sendPort = openUDP( 49063, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 ); recvPort = openUDP( 49008, "127.0.0.1", 49009 );
strcpy(DREFArray[0],"sim/cockpit/switches/gear_handle_status"); strcpy(DREFArray[0],"sim/flightmodel/position/latitude");
for (i=0;i<1;i++) { strcpy(DREFArray[1],"sim/flightmodel/position/longitude");
strcpy(DREFArray[2],"sim/flightmodel/position/y_agl");
strcpy(DREFArray[3],"sim/flightmodel/position/phi");
strcpy(DREFArray[4],"sim/flightmodel/position/theta");
strcpy(DREFArray[5],"sim/flightmodel/position/psi");
strcpy(DREFArray[6],"sim/cockpit/switches/gear_handle_status");
for (i=0;i<7;i++) {
DREFSizes[i] = (int) strlen(DREFArray[i]); DREFSizes[i] = (int) strlen(DREFArray[i]);
} }
POSI[0] = 37.524; // Lat POSI[0] = 37.524; // Lat
@@ -311,12 +325,29 @@ short test8() // sendPOSI test
// Execution // Execution
sendPOSI( sendPort, 0, 7, POSI ); sendPOSI( sendPort, 0, 7, POSI );
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 7, recDATA, DREFSizes); // Test
// Close // Close
closeUDP(sendPort); closeUDP(sendPort);
closeUDP(recvPort); closeUDP(recvPort);
// Test // Tests
if ( result < 0 )// Request 1 value
{
return -7;
}
for (i=0;i<7-1;i++)
{
if (i==2)
{
continue;
}
if (abs(recDATA[i][0]-POSI[i])>1e-4)
{
return -i;
}
}
return 0; return 0;
} }
@@ -326,20 +357,65 @@ short test9() // pauseSim test
printf("pauseSim - "); printf("pauseSim - ");
// Initialize // Initialize
int i; // Iterator
char DREFArray[100][100];
float *recDATA[100];
short DREFSizes[100],RECSizes[100];
struct xpcSocket sendPort, recvPort; struct xpcSocket sendPort, recvPort;
short result;
// Setup // Setup
sendPort = openUDP( 49067, "127.0.0.1", 49009 ); for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float));
memset(DREFArray[i],0,100);
}
// Setup
sendPort = openUDP( 49064, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 ); recvPort = openUDP( 49008, "127.0.0.1", 49009 );
strcpy(DREFArray[0],"sim/operation/override/override_planepath");
for (i=0;i<1;i++) {
DREFSizes[i] = (int) strlen(DREFArray[i]);
}
// Execute // Execute
pauseSim(sendPort, 1); pauseSim(sendPort, 1);
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, RECSizes); // Test
// Close // Close
closeUDP(sendPort); closeUDP(sendPort);
closeUDP(recvPort); closeUDP(recvPort);
// Test // Test
if (result < 0) {
return -1;
}
if (recDATA[0][0] != 1)
{
return -2;
}
// Reopen
sendPort = openUDP( 49064, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 );
// Execute 2
pauseSim(sendPort, 0);
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, RECSizes); // Test
// Close 2
closeUDP(sendPort);
closeUDP(recvPort);
// Test 2
if (result < 0)
{
return -3;
}
if (recDATA[0][0] != 0)
{
return -4;
}
return 0; return 0;
} }
@@ -389,7 +465,7 @@ short test10() // setConn test
int main(int argc, const char * argv[]) int main(int argc, const char * argv[])
{ {
printf("XPC Tests-cpp "); printf("XPC Tests-c ");
#ifdef _WIN32 #ifdef _WIN32
printf("(Windows)\n"); printf("(Windows)\n");

View File

@@ -48,6 +48,7 @@ void test2() // closeUDP test
std::cout << "closeUDP - "; std::cout << "closeUDP - ";
struct xpcSocket sendPort = openUDP( 49063, "127.0.0.1", 49009 ); struct xpcSocket sendPort = openUDP( 49063, "127.0.0.1", 49009 );
closeUDP(sendPort); closeUDP(sendPort);
sendPort = openUDP( 49063, "127.0.0.1", 49009 );
} }
void test3() // send/read Test void test3() // send/read Test
@@ -239,82 +240,112 @@ void test7() // sendCTRL test
float *recDATA[100]; float *recDATA[100];
short DREFSizes[100]; short DREFSizes[100];
struct xpcSocket sendPort, recvPort; struct xpcSocket sendPort, recvPort;
short result;
// Setup // Setup
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float)); recDATA[i] = (float *) malloc(40*sizeof(float));
memset(DREFArray[i],0,100); memset(DREFArray[i],0,100);
} }
sendPort = openUDP( 49067, "127.0.0.1", 49009 ); sendPort = openUDP( 49066, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 ); recvPort = openUDP( 49008, "127.0.0.1", 49009 );
strcpy(DREFArray[0],"sim/cockpit/switches/gear_handle_status"); strcpy(DREFArray[0],"sim/cockpit2/controls/yoke_pitch_ratio");
for (i=0;i<1;i++) { strcpy(DREFArray[1],"sim/cockpit2/controls/yoke_roll_ratio");
DREFSizes[i] = (int) strlen(DREFArray[i]); strcpy(DREFArray[2],"sim/cockpit2/controls/yoke_heading_ratio");
} strcpy(DREFArray[3],"sim/flightmodel/engine/ENGN_thro");
CTRL[3] = 0.8; // Throttle strcpy(DREFArray[4],"sim/cockpit/switches/gear_handle_status");
strcpy(DREFArray[5],"sim/flightmodel/controls/flaprqsts");
for (i=0;i<5;i++) {
DREFSizes[i] = (int) strlen(DREFArray[i]);
}
CTRL[3] = 0.8; // Throttle
// Execute // Execute
sendCTRL(sendPort, 4, CTRL); sendCTRL(sendPort, 4, CTRL);
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, DREFSizes); // Test
// Close // Close
closeUDP(sendPort); closeUDP(sendPort);
closeUDP(recvPort); closeUDP(recvPort);
// Test // Tests
if ( result < 0 )// Request 1 value
// if (requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, DREFSizes) < 0)// Request 1 value {
// { throw -6;
// throw 1; }
// } for (i=0;i<6-1;i++)
// if (DREFSizes[0] != 1) {
// { if (abs(recDATA[i][0]-CTRL[i])>1e-4)
// throw 2; {
// } throw -i;
// if (*recDATA[0] != value) }
// { }
// throw 3;
// }
} }
void test8() // sendPOSI test void test8() // sendPOSI test
{ {
std::cout << "sendPOSI - "; std::cout << "sendPOSI - ";
// Initialization // Initialize
int i; // Iterator int i; // Iterator
char DREFArray[100][100]; char DREFArray[100][100];
float POSI[8] = {0.0}; float *recDATA[100];
float *recDATA[100]; short DREFSizes[100],RECSizes[100];
short DREFSizes[100]; struct xpcSocket sendPort, recvPort;
struct xpcSocket sendPort, recvPort; short result;
// Setup // Setup
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float)); recDATA[i] = (float *) malloc(40*sizeof(float));
memset(DREFArray[i],0,100); memset(DREFArray[i],0,100);
} }
sendPort = openUDP( 49067, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 );
strcpy(DREFArray[0],"sim/cockpit/switches/gear_handle_status");
for (i=0;i<1;i++) {
DREFSizes[i] = (int) strlen(DREFArray[i]);
}
POSI[0] = 37.524; // Lat
POSI[1] = -122.06899; // Lon
POSI[2] = 2500; // Alt
POSI[3] = 0; // Pitch
POSI[4] = 0; // Roll
POSI[5] = 0; // Heading
POSI[6] = 1; // Gear
// Execution // Setup
sendPOSI( sendPort, 0, 7, POSI ); sendPort = openUDP( 49064, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 );
strcpy(DREFArray[0],"sim/operation/override/override_planepath");
for (i=0;i<1;i++) {
DREFSizes[i] = (int) strlen(DREFArray[i]);
}
// Execute
pauseSim(sendPort, 1);
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, RECSizes); // Test
// Close // Close
closeUDP(sendPort); closeUDP(sendPort);
closeUDP(recvPort); closeUDP(recvPort);
// Test // Test
if (result < 0) {
throw -1;
}
if (recDATA[0][0] != 1)
{
throw -2;
}
// Reopen
sendPort = openUDP( 49064, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 );
// Execute 2
pauseSim(sendPort, 0);
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, RECSizes); // Test
// Close 2
closeUDP(sendPort);
closeUDP(recvPort);
// Test 2
if (result < 0)
{
throw -3;
}
if (recDATA[0][0] != 0)
{
throw -4;
}
} }
void test9() // pauseSim test void test9() // pauseSim test