Mercurial > hg > ltpda
diff testing/utp_1.1/utps/rational/utp_rational_loadobj.m @ 45:a59cdb8aaf31 database-connection-manager
Merge
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 19:07:22 +0100 |
parents | 409a22968d5e |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing/utp_1.1/utps/rational/utp_rational_loadobj.m Tue Dec 06 19:07:22 2011 +0100 @@ -0,0 +1,151 @@ +% UTP_RATIONAL_LOADOBJ a set of UTPs for the rational/loadobj method +% +% M Hewitson 06-08-08 +% +% $Id: utp_rational_loadobj.m,v 1.1 2009/02/08 16:37:26 ingo Exp $ +% + +% <MethodDescription> +% +% The loadobj method of the rational class will be automatically called by +% MATLAB if an older object is not compatible with the current object structure. +% This happens only for objects which are stored as a MATLAB formatted +% (MAT-file). The load mechanism for XML formated files calls always the +% 'update_struct' method to keep the stored objects up to date. The +% 'update_struct' method convert the read object structure to the object +% structure which is used in the currend LTPDA version. +% This UTP will load old objects which are stored with an older LTPDA version. +% +% REMARK: Since LTPDA version 1.9.2 will be an object which should be saved as a +% MAT file stored as a struct and not as the object. +% +% </MethodDescription> + +function results = utp_rational_loadobj(varargin) + + % Check the inputs + if nargin == 0 + + % Some keywords + class = 'rational'; + mthd = 'loadobj'; + + results = []; + disp('******************************************************'); + disp(['**** Running UTPs for ' class '/' mthd]); + disp('******************************************************'); + + % Run the tests + results = [results utp_01]; % getInfo call + + 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_01 + + % <TestDescription> + % + % Tests that the getInfo call works for this method. + % + % </TestDescription> + function result = utp_01 + + + % <SyntaxDescription> + % + % Test that the getInfo call works for no sets, all sets, and each set + % individually. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + % Get all .MAT and .XML files + path = fullfile(fileparts(which(mfilename)), '..', '..', 'utp_test_files'); + + matfiles = utils.prog.filescan(path, '.mat'); + xmlfiles = utils.prog.filescan(path, '.xml'); + + % Load .MAT files + obj_no = 1; + for ii=1:numel(matfiles) + fn = matfiles{ii}; + [path, name] = fileparts(fn); + cl = strtok(name, '_'); + + if strcmp(cl, class) + objs(obj_no).fname = name; + objs(obj_no).obj = rational(fn); + obj_no = obj_no+1; + end + end + + % Load .XML files + for ii=1:numel(xmlfiles) + fn = xmlfiles{ii}; + [path, name] = fileparts(fn); + cl = strtok(name, '_'); + + if strcmp(cl, class) + objs(obj_no).fname = name; + objs(obj_no).obj = rational(fn); + obj_no = obj_no+1; + end + end + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check the shape of the loaded objects. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + for ii = 1:numel(objs) + obj = objs(ii).obj; + fname = objs(ii).fname; + + if ~isempty(strfind(fname, '_vec')) + % Loaded object must be a vector + if ~isvector(obj), atest = false; end + elseif ~isempty(strfind(fname, '_mat')) + % Loaded object must be a matrix + % REMARK: Known error in LTPDA version 1.9.2 + % A saved matrix doesn't keep the shape of the matrix. + if isempty(strfind(fname, '_192')) + if ~(size(obj,1) > 1 && size(obj,2) > 1), atest = false; end + end + else + % Loaded object must be a single object + if ~(size(obj,1) == 1 && size(obj,2) == 1), + atest = false; end + end + + end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_01 + +end