view testing/utp_1.1/generic_utps/utp_61.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

% <TestDescription>
%
% Tests that the constructor properly applies history to the read
% XML-file constructor.
%
% </TestDescription>
function result = utp_61(cl, obj1, ple2)
  
  % <SyntaxDescription>
  %
  % Tests that the constructor properly applies history to the read
  % XML-file constructor.
  %
  % </SyntaxDescription>
  
  msg = '';
  try
    % <SyntaxCode>
    filename = 'obj.xml';
    amat = feval(cl, obj1);
    save(amat, filename);
    
    out  = feval(cl, filename);
    mout = rebuild(out);
    % </SyntaxCode>
    stest = true;
  catch err
    msg = err.message;
    disp(err.message)
    stest = false;
  end
  
  % <AlgoDescription>
  %
  % 1) Check that the history is the same as the history of the saved
  %    object. Because save and load shouldn't add a history step.
  % 2) Check that the 'rebuild' method produces the same object as 'out'.
  %
  % </AlgoDescription>
  
  atest = true;
  if stest
    % <AlgoCode>
    % Check the last step in the history of 'out'
    if ~eq(out, amat)
      msg = ['The original and rebuilt objects are not equal: ' lastwarn];
      atest = false;
    end
    
    % Check the rebuilt object
    for kk = 1:numel(out)
      if ~eq(mout(kk), out(kk), ple2)
        msg = ['The original and rebuilt objects are not equal: ' lastwarn];
        atest = false;
      end
    end
    % </AlgoCode>
    delete(filename);
  else
    atest = false;
  end
  
  % Return a result structure
  dd = dbstack;
  mfilename = dd(2).file(1:end-2);  
  result = utp_prepare_result(atest, stest, dbstack, mfilename, msg);
end % END UTP_09