view testing/utp_1.1/utps/time/utp_time_timezone.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_TIMEZONE
%
% <MethodDescription>
%
% Tests time class 'timezone' 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_timezone.m,v 1.3 2011/04/28 07:06:27 hewitson Exp $

function results = utp_time_timezone(varargin)
  
  % check inputs
  if nargin == 0
    
    % some keywords
    class   = 'time';
    mthd    = 'timezone';
    
    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>
    % Call the static timezone method.
    % </SyntaxDescription>
    stest = false;
    try
      % <SyntaxCode>
      tz = time.timezone;
      % </SyntaxCode>
      stest = true;
    end
    
    atest = true;
    try
      % do not run algorithm tests if sintax tests failed
      assert(stest);
      
      % <AlgoDescription>
      % Check the resulting timezone object against the one in the user
      % preferences.
      % </AlgoDescription>
      % <AlgoCode>
      assert(strcmp(tz.getID(), char(prefs.getTimePrefs.getTimeTimezone)));
      % </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 timezone in the preferences then call the static timezone method.
    % </SyntaxDescription>
    stest = false;
    try
      % <SyntaxCode>
      prefs.getTimePrefs.setTimeTimezone('GMT-12:00');
      tz = time.timezone;
      % </SyntaxCode>
      stest = true;
    end
    
    atest = true;
    try
      % do not run algorithm tests if sintax tests failed
      assert(stest);
      
      % <AlgoDescription>
      % Check the resulting timezone object against the one in the user
      % preferences.
      % </AlgoDescription>
      % <AlgoCode>
      assert(strcmp(tz.getID(), char(prefs.getTimePrefs.getTimeTimezone)));
      % </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 timezone in the preferences then call the static timezone method.
    % </SyntaxDescription>
    stest = false;
    try
      % <SyntaxCode>
      prefs.getTimePrefs.setTimeTimezone('GMT+06:00');
      tz = time.timezone;
      % </SyntaxCode>
      stest = true;
    end
    
    atest = true;
    try
      % do not run algorithm tests if sintax tests failed
      assert(stest);
      
      % <AlgoDescription>
      % Check the resulting timezone object against the one in the user
      % preferences.
      % </AlgoDescription>
      % <AlgoCode>
      assert(strcmp(tz.getID(), char(prefs.getTimePrefs.getTimeTimezone)));
      % </AlgoCode>
    catch
      atest = false;
    end
    
    % return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end
  
end