
%

%   Copyright 2012 The MathWorks, Inc.

classdef TestRunner < coder.rtiostreamtest.Test
    %TESTRUNNER takes a list of Tests and runs them in order 
    %   Based on the Composite OOP pattern. Allows to build a tree-like
    %   structure of tests.
    
    % Available parameters defined here
    properties (Constant, GetAccess = 'protected')
        param_verbose   = 'verbose';
        
        default_verbose = false;
    end
    
	properties (GetAccess = 'protected', SetAccess = 'private')
        % The array of tests
        tests;
    end
    
    methods
        
        function this = TestRunner(tests, name)
            % TESTS - array of tests
            % NAME  - optional name of the current TESTRUNNER
            
            if nargin == 1, name = 'TestRunner'; end;
            this = this@coder.rtiostreamtest.Test(name);
            this.tests = tests;
        end
        
        function runTest(this, connection, parameters)   

            import coder.rtiostreamtest.*;
            
            % Whether verbose information should be printed
            verbose = TestRunner.getSetting(parameters, this.param_verbose, this.default_verbose);
            
            % For measuring the overall runtime
            time = tic;
            
            % Perform the specified tests in order
            for i = 1:numel(this.tests)
                
                % If this test is to be skipped
                if this.tests{i}.skip, continue; end;
                
                % Print the id and the subtitle of the test
                TestStr = Test.message('TestText', i);
                TestName = this.tests{i}.toString();
                fprintf([TestStr ' (' TestName '): ']);
                
                % For measuring the runtime of the current test
                testtime = tic;
               
                % Run the test
                this.tests{i}.runTest(connection, parameters);
                
                % Print verbose information about the runtime of the test
                fprintf('\n');
                Test.verboseln(verbose, 'VerboseRuntime', toc(testtime));
            end
            
            % Print verbose information about the overall runtime
            elapsed = toc(time);
            Test.verboseln(verbose, 'VerboseTotalRuntime', elapsed);
        end
        
    end
    
end

