%% Custom Criteria Programmatic Interface Example
% This example shows how to set and get custom criteria using the programmatic interface.
% Before running this example, temporarily disable warnings that result from verification failures.

warning off Stateflow:Runtime:TestVerificationFailed;
warning off Stateflow:cdr:VerifyDangerousComparison;

%
%% Load a Test File and Get Test Case Object

tf = sltest.testmanager.load('AutopilotTestFile.mldatx');

ts = getTestSuiteByName(tf,'Basic Design Test Cases');

tc = getTestCaseByName(ts,'Requirement 1.3 Test');

%
%% Create the Custom Criteria Object and Set Criteria
% Create the custom criteria object.

tcCriteria = getCustomCriteria(tc)

%
% Create the custom criteria expression. This script gets the last value of the signal Phi and verifies that it equals 0.

criteria = ...
    sprintf(['lastPhi = test.SimOut.get(''Signals_Req1_3'')',...
	'.get(''Phi'').Values.Data(end);\n',...
	'test.verifyEqual(lastPhi,0,[''Final: '',num2str(lastPhi),''.'']);'])

%
% Set and enable the criteria.

tcCriteria.Callback = criteria;
tcCriteria.Enabled = true;

%
%% Run the Test Case and Get the Results
% Run the test case.

tcResultSet = run(tc);

%
% Get the test case results.

tcResult = getTestCaseResults(tcResultSet);

%
% Get the custom criteria result.

ccResult = getCustomCriteriaResult(tcResult)

%
% Restore warnings from verification failures.

warning on Stateflow:Runtime:TestVerificationFailed;
warning on Stateflow:cdr:VerifyDangerousComparison;

%

sltest.testmanager.clearResults
sltest.testmanager.clear
sltest.testmanager.close

% Copyright 2012 The MathWorks, Inc.