%% Test Harness Callback Example
%
% This example shows how to use a post-create callback to customize a test
% harness. The callback changes one harness source from an Inport block to
% Constant block and enables signal logging in the test harness.

%% The Model
%
% In this example, you create a test harness for the |Roll Reference|
% subsystem.
%
open_system('RollAutopilotMdlRef')

%% Get Path to the Harness Customization Function
cbFile = 'harnessSourceLogCustomization.m';

%% The Customization Function and Test Harness Information
%
% The function |harnessSourceLogCustomization| changes the third source
% block, and enables signal logging on the component under test inputs
% and outputs. You can read the function by entering:
%
%    type(cbFile)
%
% As an alternative to including output logging code in the callback, 
% you can use *Log Output Signals* in the Create New Harness
% dialog box, or use |'LogHarnessOutputs',true| as an input to |sltest.harness.create|.
% These options log all component under test output signals in the test
% harness and return test results for those signals.

%% 
%
% The function |harnessSourceLogCustomization| uses an argument. The argument 
% is a struct listing test harness information. The information includes 
% handles to blocks in the test harness, including:
%
% * Component under test
% * Input subsystems
% * Sources and sinks
% * The harness owner in the main model

%%
% For example, 
% |harnessInfo.Sources| lists the handles to the test harness source
% blocks.

%% Create the Customized Test Harness
%
% 1. Copy the harness customization function to the temporary working
% directory.

copyfile(cbFile,tempdir);
cd(tempdir);

%%
% 2. In the |RollAutopilotMdlRef| model, right-click the |Roll Reference|
% subsystem and select *Test Harness > Create for Roll Reference*. 
%
% 3. In the harness creation dialog box, for *Post-create callback method*,
% enter |harnessSourceLogCustomization|. 
%
% 4. Click OK to create the test harness. The harness shows the signal
% logging and simulation stop time specified in the callback function.
%
% You can also use the |sltest.harness.create| function to create the
% test harness, specifying the callback function with the
% |'PostCreateCallback'| name-value pair.

sltest.harness.create('RollAutopilotMdlRef/Roll Reference',...
    'Name','LoggingHarness',...
    'PostCreateCallback','harnessSourceLogCustomization');

sltest.harness.open('RollAutopilotMdlRef/Roll Reference','LoggingHarness');

%%
close_system('RollAutopilotMdlRef',0);


%% 
% Copyright 2012 The MathWorks, Inc.