Completed Preliminary MATLAB Test Scripts
This commit is contained in:
26
TestScripts/MATLAB Tests/CTRLTest.m
Normal file
26
TestScripts/MATLAB Tests/CTRLTest.m
Normal 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
|
||||
|
||||
20
TestScripts/MATLAB Tests/DATATest.m
Normal file
20
TestScripts/MATLAB Tests/DATATest.m
Normal 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
|
||||
|
||||
28
TestScripts/MATLAB Tests/POSITest.m
Normal file
28
TestScripts/MATLAB Tests/POSITest.m
Normal 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
|
||||
|
||||
12
TestScripts/MATLAB Tests/openCloseTest.m
Normal file
12
TestScripts/MATLAB Tests/openCloseTest.m
Normal 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
|
||||
|
||||
25
TestScripts/MATLAB Tests/pauseTest.m
Normal file
25
TestScripts/MATLAB Tests/pauseTest.m
Normal 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
|
||||
|
||||
17
TestScripts/MATLAB Tests/requestDREFTest.m
Normal file
17
TestScripts/MATLAB Tests/requestDREFTest.m
Normal 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
|
||||
|
||||
19
TestScripts/MATLAB Tests/sendDREFTest.m
Normal file
19
TestScripts/MATLAB Tests/sendDREFTest.m
Normal 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
|
||||
|
||||
18
TestScripts/MATLAB Tests/sendReadTest.m
Normal file
18
TestScripts/MATLAB Tests/sendReadTest.m
Normal 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
|
||||
|
||||
18
TestScripts/MATLAB Tests/setConnTest.m
Normal file
18
TestScripts/MATLAB Tests/setConnTest.m
Normal 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
|
||||
|
||||
19
TestScripts/MATLAB Tests/struTest.m
Normal file
19
TestScripts/MATLAB Tests/struTest.m
Normal 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
|
||||
|
||||
39
TestScripts/MATLAB Tests/tests.m
Normal file
39
TestScripts/MATLAB Tests/tests.m
Normal 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);
|
||||
Reference in New Issue
Block a user