Added C Testing Scripts

This commit is contained in:
Chris Teubert
2014-11-28 10:57:21 -08:00
parent 6e05c4fe32
commit 2cb1d541d5
22 changed files with 913 additions and 16 deletions

View File

@@ -0,0 +1,79 @@
.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
.\"See Also:
.\"man mdoc.samples for a complete listing of options
.\"man mdoc for the short list of editing options
.\"/usr/share/misc/mdoc.template
.Dd 11/25/14 \" DATE
.Dt XPC Tests 1 \" Program name and manual section number
.Os Darwin
.Sh NAME \" Section Header - required - don't modify
.Nm XPC Tests,
.\" The following lines are read in generating the apropos(man -k) database. Use only key
.\" words here as the database is built based on the words here and in the .ND line.
.Nm Other_name_for_same_program(),
.Nm Yet another name for the same program.
.\" Use .Nm macro to designate other names for the documented program.
.Nd This line parsed for whatis database.
.Sh SYNOPSIS \" Section Header - required - don't modify
.Nm
.Op Fl abcd \" [-abcd]
.Op Fl a Ar path \" [-a path]
.Op Ar file \" [file]
.Op Ar \" [file ...]
.Ar arg0 \" Underlined argument - use .Ar anywhere to underline
arg2 ... \" Arguments
.Sh DESCRIPTION \" Section Header - required - don't modify
Use the .Nm macro to refer to your program throughout the man page like such:
.Nm
Underlining is accomplished with the .Ar macro like this:
.Ar underlined text .
.Pp \" Inserts a space
A list of items with descriptions:
.Bl -tag -width -indent \" Begins a tagged list
.It item a \" Each item preceded by .It macro
Description of item a
.It item b
Description of item b
.El \" Ends the list
.Pp
A list of flags and their descriptions:
.Bl -tag -width -indent \" Differs from above in tag removed
.It Fl a \"-a flag as a list item
Description of -a flag
.It Fl b
Description of -b flag
.El \" Ends the list
.Pp
.\" .Sh ENVIRONMENT \" May not be needed
.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
.\" .It Ev ENV_VAR_1
.\" Description of ENV_VAR_1
.\" .It Ev ENV_VAR_2
.\" Description of ENV_VAR_2
.\" .El
.Sh FILES \" File used or created by the topic of the man page
.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
.It Pa /usr/share/file_name
FILE_1 description
.It Pa /Users/joeuser/Library/really_long_file_name
FILE_2 description
.El \" Ends the list
.\" .Sh DIAGNOSTICS \" May not be needed
.\" .Bl -diag
.\" .It Diagnostic Tag
.\" Diagnostic informtion here.
.\" .It Diagnostic Tag
.\" Diagnostic informtion here.
.\" .El
.Sh SEE ALSO
.\" List links in ascending order by section, alphabetically within a section.
.\" Please do not reference files that do not exist without filing a bug report
.Xr a 1 ,
.Xr b 1 ,
.Xr c 1 ,
.Xr a 2 ,
.Xr b 2 ,
.Xr a 3 ,
.Xr b 3
.\" .Sh BUGS \" Document known, unremedied bugs
.\" .Sh HISTORY \" Document history if command behaves in a unique manner

View File

@@ -0,0 +1,410 @@
//
// main.cpp
// XPC Tests
//
// Created by Chris Teubert on 11/25/14.
// Copyright (c) 2014 Chris Teubert. All rights reserved.
//
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <exception>
#include "xplaneconnect.h"
int testFailed = 0;
int testPassed = 0;
void runTest(void (*f)())
{
try {
std::cout << "Test " << testPassed+testFailed+1<<": ";
(*f)(); // Run Test
std::cout << "PASSED\n";
testPassed++;
}
catch (int i)
{
std::cerr << "FAILED\n\tError: " << i << std::endl;
testFailed++;
}
catch (char c)
{
std::cerr << "FAILED\n\tError: " << c << std::endl;
testFailed++;
}
}
void test1() // openUDP Test
{
std::cout << "openUDP - ";
struct xpcSocket sendPort = openUDP( 49062, "127.0.0.1", 49009 );
}
void test2() // closeUDP test
{
std::cout << "closeUDP - ";
struct xpcSocket sendPort = openUDP( 49063, "127.0.0.1", 49009 );
closeUDP(sendPort);
}
void test3() // send/read Test
{
std::cout << "send/readUDP - ";
// Initialization
int i; // Iterator
char test[] = {0, 1, 2, 3};
char buf[5] = {0};
struct xpcSocket sendPort, recvPort;
// Setup
sendPort = openUDP( 49064, "127.0.0.1", 49063 );
recvPort = openUDP( 49063, "127.0.0.1", 49009 );
// Execution
sendUDP( sendPort, test, sizeof(test) );
readUDP( recvPort, buf, NULL ); // Test
// Close
closeUDP(sendPort);
closeUDP(recvPort);
// Tests
for (i=0; i<4; i++)
{
if (test[i] != buf[i]) // Not received correctly
{
throw 1;
}
}
}
void test4() // Request DREF Test (Required for next tests)
{
std::cout << "requestDREF - ";
// Initialization
int i; // Iterator
char DREFArray[100][100];
float *recDATA[100];
short DREFSizes[100];
struct xpcSocket sendPort, recvPort;
short result = 0;
// Setup
for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float));
memset(DREFArray[i],0,100);
}
sendPort = openUDP( 49064, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 );
strcpy(DREFArray[0],"sim/cockpit/switches/gear_handle_status");
strcpy(DREFArray[1],"cockpit2/switches/panel_brightness_ratio");
for (i=0;i<2;i++) {
DREFSizes[i] = (int) strlen(DREFArray[i]);
}
// Execution
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 2, recDATA, DREFSizes);
// Close
closeUDP(sendPort);
closeUDP(recvPort);
// Tests
if ( result < 0)// Request 2 values
{
throw 1;
}
if (DREFSizes[0] != 1 || DREFSizes[1] != 4)
{
throw 2;
}
}
void test5() // sendDREF test
{
std::cout << "sendDREF - ";
// Initialization
int i; // Iterator
char DREFArray[100][100];
float *recDATA[100];
short DREFSizes[100];
float value = 0.0;
struct xpcSocket sendPort, recvPort;
short result = 0;
// Setup
for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float));
memset(DREFArray[i],0,100);
}
sendPort = openUDP( 49066, "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]);
}
// Execution
sendDREF(sendPort, DREFArray[0], DREFSizes[0], &value, 1);
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, DREFSizes);
// Close
closeUDP(sendPort);
closeUDP(recvPort);
// Tests
if (result < 0)// Request 1 value
{
throw 1;
}
if (DREFSizes[0] != 1)
{
throw 2;
}
if (*recDATA[0] != value)
{
throw 3;
}
}
void test6() // sendDATA test
{
std::cout << "sendData - ";
// Initialize
int i,j; // Iterator
char DREFArray[100][100];
float data[4][9] = {0};
float *recDATA[100];
short DREFSizes[100];
struct xpcSocket sendPort, recvPort;
short result = 0;
// Setup
for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float));
memset(DREFArray[i],0,100);
}
sendPort = openUDP( 49066, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 );
strcpy(DREFArray[0],"sim/aircraft/parts/acf_gear_deploy");
for (i=0;i<1;i++) {
DREFSizes[i] = (int) strlen(DREFArray[i]);
}
for (i=0;i<4;i++) { // Set array to -999
for (j=0;j<9;j++) data[i][j] = -999;
}
data[0][0] = 14; // Gear
data[0][1] = 1;
data[0][2] = 0;
// Execution
sendDATA(sendPort, data, 1); // Gear
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, DREFSizes); // Test
// Close
closeUDP(sendPort);
closeUDP(recvPort);
// Tests
if ( result < 0 )// Request 1 value
{
throw 1;
}
if (DREFSizes[0] != 10)
{
throw 2;
}
if (*recDATA[0] != data[0][1])
{
throw 3;
}
}
void test7() // sendCTRL test
{
std::cout << "sendCTRL - ";
// Initialize
int i; // Iterator
char DREFArray[100][100];
float CTRL[5] = {0.0};
float *recDATA[100];
short DREFSizes[100];
struct xpcSocket sendPort, recvPort;
// Setup
for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float));
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]);
}
CTRL[3] = 0.8; // Throttle
// Execute
sendCTRL(sendPort, 4, CTRL);
// Close
closeUDP(sendPort);
closeUDP(recvPort);
// Test
// if (requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, DREFSizes) < 0)// Request 1 value
// {
// throw 1;
// }
// if (DREFSizes[0] != 1)
// {
// throw 2;
// }
// if (*recDATA[0] != value)
// {
// throw 3;
// }
}
void test8() // sendPOSI test
{
std::cout << "sendPOSI - ";
// Initialization
int i; // Iterator
char DREFArray[100][100];
float POSI[8] = {0.0};
float *recDATA[100];
short DREFSizes[100];
struct xpcSocket sendPort, recvPort;
// Setup
for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float));
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
sendPOSI( sendPort, 0, 7, POSI );
// Close
closeUDP(sendPort);
closeUDP(recvPort);
// Test
}
void test9() // pauseSim test
{
std::cout << "pauseSim - ";
// Initialize
struct xpcSocket sendPort, recvPort;
// Setup
sendPort = openUDP( 49067, "127.0.0.1", 49009 );
recvPort = openUDP( 49008, "127.0.0.1", 49009 );
// Execute
pauseSim(sendPort, 1);
// Close
closeUDP(sendPort);
closeUDP(recvPort);
// Test
}
void test10() // setConn test
{
std::cout << "setConn - ";
// Initialize
int i; // Iterator
char DREFArray[100][100];
float *recDATA[100];
short DREFSizes[100];
struct xpcSocket sendPort, recvPort;
short result = 0;
usleep(0);
// Setup
sendPort = openUDP( 49067, "127.0.0.1", 49009 );
recvPort = openUDP( 49055, "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]);
}
// Execution
setCONN(sendPort, 49055);
result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 1, recDATA, DREFSizes); // Test
// Close
closeUDP(sendPort);
closeUDP(recvPort);
// Test
if ( result < 0 )// No data received
{
throw 1;
}
// Set up for next test
sendPort = openUDP( 49067, "127.0.0.1", 49009 );
setCONN(sendPort, 49009);
closeUDP(sendPort);
}
int main(int argc, const char * argv[])
{
std::cout << "XPC Tests-cpp ";
#ifdef _WIN32
std::cout << "(Windows)\n";
#elif (__APPLE__)
std::cout << "(Mac) \n";
#elif (__linux)
std::cout << "(Linux) \n";
#endif
runTest(test1);
runTest(test2);
runTest(test3);
runTest(test4);
runTest(test5);
runTest(test6);
runTest(test7);
runTest(test8);
runTest(test9);
runTest(test10);
std::cout << "----------------\nTest Summary\n\tFailed: " << testFailed << "\n\tPassed: " << testPassed << std::endl;
return 0;
}