view testing/utp_1.1/utps/time/utp_time_timeformat.m @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents
children
line wrap: on
line source

% UTP_TIME_TIMEFORMAT
%
% <MethodDescription>
%
% Tests time class 'timeformat' static property.
%
% </MethodDescription>
%
% NOTE: in this test we manipulate user preferences thus we should make
% sure we restore the original user preferences at the end of the testing
%
% $Id: utp_time_timeformat.m,v 1.3 2011/04/28 07:06:27 hewitson Exp $

function results = utp_time_timeformat(varargin)
  
  % check inputs
  if nargin == 0
    
    % some keywords
    class   = 'time';
    mthd    = 'timeformat';
    
    results = [];
    disp('******************************************************');
    disp(['****  Running UTPs for ' class '/' mthd]);
    disp('******************************************************');
    
    % get preferences
    prefs = getappdata(0, 'LTPDApreferences');
    oldTimezone   = char(prefs.getTimePrefs.getTimeTimezone);
    oldTimeformat = char(prefs.getTimePrefs.getTimestringFormat);
    
    % get preferences
    try
      results = [results utp_901];
      results = [results utp_902];
      results = [results utp_903];
    catch ex
      % restore preferences
      prefs.getTimePrefs.setTimeTimezone(oldTimezone);
      prefs.getTimePrefs.setTimestringFormat(oldTimeformat);
      rethrow(ex);
    end
    
    % restore preferences
    prefs.getTimePrefs.setTimeTimezone(oldTimezone);
    prefs.getTimePrefs.setTimestringFormat(oldTimeformat);
    
    disp('Done.');
    disp('******************************************************');
    
  elseif nargin == 1
    % check for UTP functions
    if strcmp(varargin{1}, 'isutp')
      results = 1;
    else
      results = 0;
    end
  else
    error('### Incorrect inputs')
  end
  
  %% UTP_901
  
  % <TestDescription>
  %
  % Tests that the method really returns what is in the user preferences.
  %
  % </TestDescription>
  function result = utp_901
    
    % <SyntaxDescription>
    % Check that the timeformat method runs without error.
    % </SyntaxDescription>
    stest = false;
    try
      % <SyntaxCode>
      frmt = time.timeformat;
      % </SyntaxCode>
      stest = true;
    end
    
    atest = true;
    try
      % do not run algorithm tests if sintax tests failed
      assert(stest);
      
      % <AlgoDescription>
      % Check that the returned value is the same as the one set in the
      % user preferences.
      % </AlgoDescription>
      
      % <AlgoCode>
      assert(strcmp(frmt, char(prefs.getTimePrefs.getTimestringFormat)));
      % </AlgoCode>
    catch ex
      atest = false;
      % rethrow(ex)
    end
    
    % return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end
  
  
  %% UTP_902
  
  % <TestDescription>
  %
  % Change user preferences and do it again.
  %
  % </TestDescription>
  function result = utp_902
    
    % <SyntaxDescription>
    % Set the time string format in the preferences and check that the
    % timeformat method runs without error.
    % </SyntaxDescription>
    stest = false;
    try
      % <SyntaxCode>
      prefs.getTimePrefs.setTimestringFormat('HH:MM:SS');
      frmt = time.timeformat;
      % </SyntaxCode>
      stest = true;
    end
    
    atest = true;
    try
      % do not run algorithm tests if sintax tests failed
      assert(stest);
      
      % <AlgoDescription>
      % Check that the returned value is the same as the one set in the
      % user preferences.
      % </AlgoDescription>
      
      % <AlgoCode>
      assert(strcmp(frmt, char(prefs.getTimePrefs.getTimestringFormat)));
      % </AlgoCode>
    catch ex
      atest = false;
      % rethrow(ex)
    end
    
    % return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end
  
  
  %% UTP_903
  
  % <TestDescription>
  %
  % Change user preferences and do it again.
  %
  % </TestDescription>
  function result = utp_903
    
    % <SyntaxDescription>
    % Set the time string format in the preferences and check that the
    % timeformat method runs without error.
    % </SyntaxDescription>
    stest = false;
    try
      % <SyntaxCode>
      prefs.getTimePrefs.setTimestringFormat('yyyy-mm-dd');
      frmt = time.timeformat;
      % </SyntaxCode>
      stest = true;
    end
    
    atest = true;
    try
      % do not run algorithm tests if sintax tests failed
      assert(stest);
      % <AlgoDescription>
      % Check that the returned value is the same as the one set in the
      % user preferences.
      % </AlgoDescription>
      
      % <AlgoCode>
      assert(strcmp(frmt, char(prefs.getTimePrefs.getTimestringFormat)));
      % </AlgoCode>
    catch ex
      atest = false;
      % rethrow(ex);
    end
    
    % return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end
  
end