Merge pull request #15 from nasa/Testing-Scripts

Completed Preliminary MATLAB Test Scripts
This commit is contained in:
Christopher Teubert
2014-11-28 17:09:56 -08:00
21 changed files with 256 additions and 19 deletions

View File

@@ -23,4 +23,6 @@ function [socket] = closeUDP(socket)
socket.close;
assert(isequal(socket.isClosed(),1),'closeUDP: Error- Could not close socket');
end

View File

@@ -36,4 +36,6 @@ if ~isempty(varargin)
end
end
assert(isequal(socket.isClosed(),0),'openUDP: Error- Could not open port');
end

View File

@@ -67,7 +67,7 @@ function [ sensor ] = readDATA( socket )
dim1 = sensor.raw(a);
dim2 = sensor.raw(a+1);
if dim1 == 0 %String
value = char(sensor.raw(a+2:a+1+dim2));
value = char(sensor.raw(a+2:a+1+dim2))';
a = a + dim2 + 2;
else
value = [];

View File

@@ -50,7 +50,7 @@ function [ data ] = readUDP( input )
data = int16(data);
data(data(:)<0) = uint8(data(data(:)<0) + 256); %fix signed issue
size = int16(data(5)); %size of data stream
%% trim trailing data
for i=1:floor(length(data)/256)+1
if data(size+1:end)==0

View File

@@ -36,7 +36,7 @@ import XPlaneConnect.*
%% Handle Input
% Optional parameters
if ~exist('IP','var'), IP = "127.0.0.1"; end
if ~exist('IP','var'), IP = '127.0.0.1'; end
if ~exist('port','var'), port = 49009; end
if ~exist('acft','var'), acft = 0; end
@@ -44,7 +44,7 @@ import XPlaneConnect.*
%%BODY
header = ['CTRL'-0,0];
dataStream = [header, acft];
dataStream = header; %TODO-ADD ACFT
% Deal with position update
control = [0, 0, 0, 0.8, 0, 1];
@@ -55,7 +55,7 @@ import XPlaneConnect.*
dataStream = [dataStream, typecast(single(control),'uint8')];
% Send DATA
status = sendUDP(IP, port, dataStream);
status = sendUDP(dataStream, IP, port);
end

View File

@@ -42,16 +42,8 @@ function [ status ] = sendUDP( data, IP, port )
end
end
try
IP = InetAddress.getByName(IP);
packet = DatagramPacket(data, length(data), IP, port); %create packet
socket.send(packet);
catch err
status = 1;
disp(err)
end
IP = InetAddress.getByName(IP);
packet = DatagramPacket(data, length(data), IP, port); %create packet
socket.send(packet);
end

View File

@@ -26,7 +26,7 @@
/* Begin PBXFileReference section */
BE7C5C001A28F72F00F246B9 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = "CPP Tests/main.cpp"; sourceTree = SOURCE_ROOT; };
BE7C5C011A28F72F00F246B9 /* XPC_Tests.1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.man; name = XPC_Tests.1; path = "CPP Tests/XPC_Tests.1"; sourceTree = SOURCE_ROOT; };
BE7C5C011A28F72F00F246B9 /* Cpp_Tests.1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.man; name = Cpp_Tests.1; path = "CPP Tests/Cpp_Tests.1"; sourceTree = SOURCE_ROOT; };
BE9C6BAB1A253FA100EBE08A /* Cpp Tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Cpp Tests"; sourceTree = BUILT_PRODUCTS_DIR; };
BEB0F4F61A28F7B0001975A6 /* xplaneConnect.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = xplaneConnect.c; path = ../C/src/xplaneConnect.c; sourceTree = "<group>"; };
BEB0F4F71A28F7B0001975A6 /* xplaneConnect.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = xplaneConnect.h; path = ../C/src/xplaneConnect.h; sourceTree = "<group>"; };
@@ -65,7 +65,7 @@
isa = PBXGroup;
children = (
BE7C5C001A28F72F00F246B9 /* main.cpp */,
BE7C5C011A28F72F00F246B9 /* XPC_Tests.1 */,
BE7C5C011A28F72F00F246B9 /* Cpp_Tests.1 */,
);
name = "Cpp Tests";
path = "XPC Tests";

View File

@@ -0,0 +1,26 @@
function CTRLTest( )
%CTRLTest Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
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'};
THROT = rand();
CTRL = [0.0, 0.0, 1.0, THROT, 0.0, 1.0];
sendCTRL(CTRL);
result = requestDREF(DREFS);
assert(isequal(length(result),6),'CTRLTest: requestDREF unsucessful-wrong number of elements returned');
assert(isequal(length(result{4}),8),'CTRLTest: requestDREF unsucessful- element 1 incorrect size (should be size 8)');
for i=1:length(CTRL)-1
assert(abs(result{i}(1)-CTRL(i))<1e-4,['CTRLTest: DATA set unsucessful-',num2str(i)]);
end
end

View File

@@ -0,0 +1,20 @@
function DATATest( )
%DATATest Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
DREFS = {'sim/flightmodel/engine/ENGN_thro'};
value = rand();
data = struct('h',25,'d',[value,-998,-998,-998,-998,-998,-998,-998]);
sendDATA(data);
result = requestDREF(DREFS);
assert(isequal(length(result),1),'DATATest: requestDREF unsucessful-wrong number of elements returned');
assert(isequal(length(result{1}),8),'DATATest: requestDREF unsucessful- element 1 incorrect size (should be size 8)');
assert(abs(result{1}(1)-value)<1e-4,'DATATest: DATA set unsucessful');
end

View File

@@ -0,0 +1,28 @@
function POSITest( )
%POSITest Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
DREFS = {'sim/flightmodel/position/latitude', ...
'sim/flightmodel/position/longitude', ...
'sim/flightmodel/position/y_agl', ...
'sim/flightmodel/position/phi', ...
'sim/flightmodel/position/theta', ...
'sim/flightmodel/position/psi', ...
'sim/cockpit/switches/gear_handle_status'};
POSI = [37.524, -122.06899, 2500, 0, 0, 0, 1]; % Gear
sendPOSI(POSI);
result = requestDREF(DREFS);
assert(isequal(length(result),7),'POSITest: requestDREF unsucessful-wrong number of elements returned');
for i=1:length(POSI)
if i==3
continue
end
assert(abs(result{i}(1)-POSI(i))<1e-4,['POSITest: DATA set unsucessful-',num2str(i)]);
end
end

View File

@@ -0,0 +1,12 @@
function openCloseTest()
%OPENCLOSETEST Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
socket = openUDP( 49007 );
closeUDP( socket );
end

View File

@@ -0,0 +1,25 @@
function pauseTest( )
%PauseTest Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
DREFS = {'sim/operation/override/override_planepath'};
value = 0; % Resume
pauseSim(value);
result = requestDREF(DREFS);
assert(isequal(length(result),1),'pauseTest: requestDREF unsucessful-wrong number of elements returned');
assert(abs(result{1}(1)-value)<1e-4,'pauseTest: Pause Unsuccessful');
value = 1; % Pause
pauseSim(value);
result = requestDREF(DREFS);
assert(isequal(length(result),1),'pauseTest: requestDREF unsucessful-wrong number of elements returned');
assert(abs(result{1}(1)-value)<1e-4,'pauseTest: Pause Unsuccessful');
end

View File

@@ -0,0 +1,17 @@
function requestDREFTest( )
%SENDREADTEST Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
DREFS = {'sim/cockpit/switches/gear_handle_status',...
'cockpit2/switches/panel_brightness_ratio'};
result = requestDREF(DREFS);
assert(isequal(length(result),2));
assert(isequal(length(result{1}),1));
assert(isequal(length(result{2}),4));
end

View File

@@ -0,0 +1,19 @@
function sendDREFTest( )
%SENDREADTEST Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
DREFS = {'sim/cockpit/switches/gear_handle_status'};
value = randi([0 10]);
sendDREF(DREFS{1},value);
result = requestDREF(DREFS);
assert(isequal(length(result),1),'sendDREFTest: requestDREF unsucessful-wrong number of elements returned');
assert(isequal(length(result{1}),1),'sendDREFTest: requestDREF unsucessful- element 1 incorrect size (should be size 1)');
assert(isequal(result{1},value),'sendDREFTest: DREF set unsucessful');
end

View File

@@ -0,0 +1,18 @@
function sendReadTest( )
%SENDREADTEST Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
recvPortNum = 49074;
recvPort = openUDP(49074);
sendUDP('test2'-0,'127.0.0.1',49074);
result = readUDP(recvPort);
closeUDP(recvPort);
assert(~isequal(result,-998), 'no data received');
assert(all(result(1:4)'=='test'-0));
end

View File

@@ -0,0 +1,18 @@
function setConnTest( )
disp('Not Functional Yet!')
%setConnTest Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
DREFS = {'sim/operation/override/override_planepath'};
value = 0; % Resume
setConn(value);
result = requestDREF(DREFS);
assert(isequal(length(result),1),'setConnTest: requestDREF unsucessful-wrong number of elements returned');
end

View File

@@ -0,0 +1,19 @@
function struTest( )
%STRUTEST Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')
import XPlaneConnect.*
recvNum = 49076;
recvPort = openUDP(recvNum);
testSTRU = struct('h',15,'d',[12, 34, 55, 99, 1, 0],'test','theTest');
sendSTRU(testSTRU,'127.0.0.1',recvNum);
resultSTRU = readDATA(recvPort);
closeUDP(recvPort);
resultSTRU = rmfield(resultSTRU,'raw');
assert(isequal(testSTRU,resultSTRU),'struTest: Error-structs are not equal');
end

View File

@@ -0,0 +1,39 @@
testsPassed=0;
testsFailed=0;
if ismac()
os = 'Mac';
elseif ispc()
os = 'Win';
else
os = 'Linux';
end
disp(['XPC Tests-MATLAB (', os, ')']);
theTests = {{@openCloseTest, 'Open/Close Test', 0},...
{@sendReadTest,'Send/Read Test', 0},...
{@requestDREFTest,'Request DREF Test', 0},...
{@sendDREFTest,'Send DREF Test', 0},...
{@DATATest,'DATA Test', 0},...
{@CTRLTest,'CTRL Test', 0},...
{@POSITest,'POSI Test', 0},...
{@pauseTest,'Pause Test', 0},...
{@struTest,'Struct Test', 0}};
for i=1:length(theTests)
fprintf(['Test ',num2str(i),': ',theTests{i}{2},' - ']);
try
theTests{i}{1}();
disp('SUCCESS');
theTests{i}{3} = 1;
testsPassed = testsPassed+1;
catch err
disp('FAILURE');
fprintf('\t%s\n',err.message);
theTests{i}{3} = -1;
testsFailed = testsFailed + 1;
end
end
disp('Results Summary:');
fprintf('Passed: %i\tFailed: %i\n',testsPassed, testsFailed);