% <TestDescription>
%
% Tests that the constructor properly applies history in the struct constructor.
%
% </TestDescription>
function result = utp_62(cl, obj1, obj2, ple2)
  
  % <SyntaxDescription>
  %
  % Tests that the constructor properly applies history in the struct constructor.
  %
  % </SyntaxDescription>
  
  msg = '';
  try
    % <SyntaxCode>
    ssys1         = utils.prog.rstruct(obj1);
    ssys1.hist    = utils.prog.rstruct(obj1.hist);
    
    out1 = feval(cl, utils.prog.rstruct(obj2));
    out2 = feval(cl, ssys1);
    mout1 = rebuild(out1);
    mout2 = rebuild(out2);
    % </SyntaxCode>
    stest = true;
  catch err
   msg = err.message;
   disp(err.message)
   stest = false;
  end
  
  % <AlgoDescription>
  %
  % 1) Check that the last entry in the history of 'out'
  %    corresponds to the class name.
  % 2) Check that the 'rebuild' method produces the same object as 'out'.
  %
  % </AlgoDescription>
  
  atest = true;
  if stest
    % <AlgoCode>
    % Check that the output is a ssm object
    if ~isa(out1,cl), atest = false; end
    if ~isa(out2,cl), atest = false; end
    % Check the last step in the history of 'out'
    if ~strcmp(out1.hist.methodInfo.mname, 'setName') 
      msg = 'The last step in the history is not ''setName''';
      atest = false;
    end
    if ~strcmp(out2.hist.methodInfo.mname, 'setName')
      msg = 'The last step in the history is not ''setName''';
      atest = false;
    end
    % Check the rebuilt object
    if ~eq(mout1, out1, ple2)
      msg = ['The original and rebuilt objects are not equal: ' lastwarn];
      atest = false;
    end
    if ~eq(mout2, out2, ple2)
      msg = ['The original and rebuilt objects are not equal: ' lastwarn];
      atest = false;
    end
    % </AlgoCode>
  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_62