1+ classdef troblocksForwarding < matlab .unittest .TestCase
2+ % troblocksForwarding Test block forwarding of blocks in roblocks library
3+ % We introduced block forwarding when we introduced the sub-libraries
4+ % generallib, mobilelib, and visualservolib.
5+
6+ % Copyright 2023-2025 Peter Corke, Witold Jachimczyk, Remo Pillat
7+
8+ properties (Constant )
9+ % ModelName - Name of Simulink model containing the old blocks
10+ ModelName = " mroblocksForwarding"
11+
12+ % LibraryName - Main Simulink library for RVC Toolbox
13+ LibraryName = " roblocks"
14+ end
15+
16+ properties
17+ % ForwardingTable - Forwarding table extracted from library
18+ % This will be a Nx3 string array.
19+ ForwardingTable
20+ end
21+
22+ properties (TestParameter )
23+ % BlockNames - Block names to test for forwarding
24+ % Each parameter contains 3 values
25+ % (1) The name of the block in ModelName
26+ % (2) The original block path
27+ % (3) The new, forwarded block path
28+ pBlockName = struct(...
29+ " angdiff" , {{" angdiff" , " roblocks/angdiff" , " generallib/angdiff" }}, ...
30+ " tform2delta" , {{" tform2delta" , " roblocks/tform2delta" , " generallib/tform2delta" }}, ...
31+ " wrapToPi" , {{" wrapToPi" , " roblocks/wrapToPi" , " generallib/wrapToPi" }}, ...
32+ " Quadrotor" , {{" Quadrotor" , " roblocks/Quadrotor" , " mobilelib/Quadrotor" }}, ...
33+ " ControlMixer" , {{" Control Mixer 4" , " roblocks/Control Mixer 4" , " mobilelib/Control Mixer 4" }}, ...
34+ " JointVLoop" , {{" Joint vloop" , " roblocks/Joint vloop" , " mobilelib/Joint vloop" }} ...
35+ )
36+ end
37+
38+ methods (TestClassSetup )
39+ function loadTestModel(testCase )
40+ % loadTestModel Load model with forwarded blocks
41+
42+ % Ensure model loads without any warnings. That's a good
43+ % initial sanity check that the forwarding is working.
44+ testCase .verifyWarningFree(@() load_system(testCase .ModelName ));
45+ testCase .addTeardown(@() close_system(testCase .ModelName ,0 ));
46+ end
47+
48+ function storeForwardingTable(testCase )
49+ % storeForwardingTable Extract forwarding table from library and store in class property
50+
51+ load_system(testCase .LibraryName );
52+ testCase .addTeardown(@() close_system(testCase .LibraryName , 0 ));
53+
54+ % Retrieve the actual forwarding table
55+ actualTableTemp = get_param(testCase .LibraryName , " ForwardingTable" );
56+ testCase .assertNotEmpty(actualTableTemp , " Expected forwarding table for library to exist" );
57+
58+ for k = 1 : numel(actualTableTemp )
59+ while length(actualTableTemp{k })< 3
60+ actualTableTemp{k }(end + 1 )={' ' };
61+ end
62+ testCase.ForwardingTable = [testCase .ForwardingTable ;string(actualTableTemp{k })];
63+ end
64+ end
65+ end
66+
67+ methods (Test )
68+ function blockForwarding(testCase , pBlockName )
69+ % blockForwarding Verify that block forwarding works correctly
70+
71+ [blockName , oldLibraryPath , newLibraryPath ] = pBlockName{: };
72+
73+ % Check that block exists in test model
74+ blockPath = testCase .ModelName + " /" + blockName ;
75+ testCase .assertNotEmpty(get_param(blockPath , " BlockType" ), " Expected block to exist." );
76+
77+ % Verify that forwarding is set up correctly
78+ fwdRow = find(testCase .ForwardingTable .matches(oldLibraryPath ));
79+ testCase .verifyNotEmpty(fwdRow , " No entry for block in forwarding table" )
80+ actualLibraryPath = get_param(blockPath , " ReferenceBlock" );
81+ testCase .verifyEqual(actualLibraryPath , char(newLibraryPath ));
82+ end
83+ end
84+
85+ end
0 commit comments