Mercurial > hg > ltpda
diff testing/utp_1.1/utps/plist/utp_plist_plist.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 diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing/utp_1.1/utps/plist/utp_plist_plist.m Tue Dec 06 18:42:11 2011 +0100 @@ -0,0 +1,835 @@ +% UTP_PLIST_PLIST a set of UTPs for the plist/plist method +% +% M Hewitson 06-08-08 +% +% $Id: utp_plist_plist.m,v 1.14 2011/03/01 11:31:53 ingo Exp $ +% + +% <MethodDescription> +% +% The plist method of the plist class constructs PLIST objects. +% +% </MethodDescription> + +function results = utp_plist_plist(varargin) + + % Check the inputs + if nargin == 0 + + % Some keywords + class = 'plist'; + mthd = 'plist'; + + results = []; + disp('******************************************************'); + disp(['**** Running UTPs for ' class '/' mthd]); + disp('******************************************************'); + + % Test PLIST objects + [pl1, pl2, pl3, pl4, plv, plm] = get_test_objects_plist; + + % Exception list for the UTPs: + [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); + + % Run the tests + results = [results utp_01]; % getInfo call + results = [results utp_02]; % Vector input + results = [results utp_03]; % Matrix input + results = [results utp_04]; % List input + results = [results utp_05]; % Test with mixed input + results = [results utp_06]; % Test history is working with MAT file constructor + results = [results utp_07]; % Test history is working with XML file constructor + results = [results utp_08]; % Test struct constructor + results = [results utp_09]; % Test param-object constructor + results = [results utp_10]; % Test plist(filename) constructor + results = [results utp_11]; % Test plist(hostname) constructor + results = [results utp_12]; % Test history is working with conn+Id constructor + results = [results utp_13]; % Test history is working with a + b + fs constructor + + disp('Done.'); + disp('******************************************************'); + + elseif nargin == 1 % Check for UTP functions + if strcmp(varargin{1}, 'isutp') + results = 1; + elseif strcmpi(varargin{1}, 'needs repository') + results = 2; + 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> + % Call for no sets + io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); + % Call for all sets + io(2) = eval([class '.getInfo(''' mthd ''')']); + % Call for each set + for kk=1:numel(io(2).sets) + io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); + end + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that getInfo call returned an minfo object in all cases. + % 2) Check that all plists have the correct parameters. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % check we have minfo objects + if isa(io, 'minfo') + %%% SET 'None' + if ~isempty(io(1).sets), atest = false; end + if ~isempty(io(1).plists), atest = false; end + %%% Check all Sets + if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end + if ~any(strcmpi(io(2).sets, 'From MAT File')), atest = false; end + if ~any(strcmpi(io(2).sets, 'From XML File')), atest = false; end + if ~any(strcmpi(io(2).sets, 'From Repository')), atest = false; end + if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end + %%%%%%%%%% SET 'Default' + if io(3).plists.nparams ~= 0, atest = false; end + % Check key + % Check default value + % Check options + %%%%%%%%%% SET 'From MAT File' + pn = 4; + if io(pn).plists.nparams ~= 1, atest = false; end + % Check key + if ~io(pn).plists.isparam('filename'), atest = false; end + % Check default value + if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end + % Check options + if ~isequal(io(pn).plists.getOptionsForParam('filename'), {''}), atest = false; end + %%%%%%%%%% SET 'From XML File' + pn = 5; + if io(pn).plists.nparams ~= 1, atest = false; end + % Check key + if ~io(pn).plists.isparam('filename'), atest = false; end + % Check default value + if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end + % Check options + if ~isequal(io(pn).plists.getOptionsForParam('filename'), {''}), atest = false; end + %%%%%%%%%% SET 'From Repository' + pn = 6; + if io(pn).plists.nparams ~= 7, atest = false; end + % Check key + if ~io(pn).plists.isparam('hostname'), atest = false; end + if ~io(pn).plists.isparam('id'), atest = false; end + if ~io(pn).plists.isparam('cid'), atest = false; end + if ~io(pn).plists.isparam('database'), atest = false; end + if ~io(pn).plists.isparam('binary'), atest = false; end + if ~io(pn).plists.isparam('username'), atest = false; end + if ~io(pn).plists.isparam('password'), atest = false; end + % Check default value + if ~isEmptyDouble(io(pn).plists.find('id')), atest = false; end + if ~isEmptyDouble(io(pn).plists.find('cid')), atest = false; end + if ~isequal(io(pn).plists.find('binary'), 'yes'), atest = false; end + % Check options + if ~isequal(io(pn).plists.getOptionsForParam('id'), {[]}), atest = false; end + if ~isequal(io(pn).plists.getOptionsForParam('cid'), {[]}), atest = false; end + if ~isequal(io(pn).plists.getOptionsForParam('binary'), {'yes', 'no'}), atest = false; end + end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_01 + + %% UTP_02 + + % <TestDescription> + % + % Tests that the plist method works with a vector of PLIST objects as input. + % + % </TestDescription> + function result = utp_02 + + % <SyntaxDescription> + % + % Test that the plist method works with a vector of PLIST objects as input. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out = plist(plv); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the shape of the output PLISTs is the same as the input shape. + % 2) Check that each output PLIST is a copy of the input PLIST. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check we have the correct shape + if size(out) ~= size(plv), atest = false; end + + % Check that the output is a copy. + for ii = 1:numel(out) + % Check that the output is the same + if ~eq(plv(ii), out(ii), ple1), atest = false; end + % Change the output to make sure that it is a 'real' copy + out(ii).setDescription('my desc'); + if eq(plv(ii), out(ii), ple1), atest = false; end + end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_02 + + %% UTP_03 + + % <TestDescription> + % + % Tests that the plist method works with a matrix of PLIST objects as input. + % + % </TestDescription> + function result = utp_03 + + % <SyntaxDescription> + % + % Test that the plist method works with a matrix of PLIST objects as input. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out = plist(plm); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the shape of the output PLISTs is the same as the input shape. + % 2) Check that each output PLIST is a copy of the input PLIST. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check we have the correct number of outputs + if size(out) ~= size(plm), atest = false; end + + % Check that the output is a copy. + for ii = 1:numel(out) + % Check that the output is the same + if ~eq(plm(ii), out(ii), ple1), atest = false; end + % Change the output to make sure that it is a 'real' copy + out(ii).setDescription('my desc'); + if eq(plm(ii), out(ii), ple1), atest = false; end + end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_03 + + %% UTP_04 + + % <TestDescription> + % + % Tests that the plist method works with a list of PLIST objects as input. + % + % </TestDescription> + function result = utp_04 + + % <SyntaxDescription> + % + % Test that the plist method works with a list of PLIST objects as input. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out = plist(pl1, pl2, pl3, pl4); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the number of elements in 'out' is the same of the + % number in the input. + % 2) Check that each output PLIST is a copy of the input PLIST. + % + % </AlgoDescription> + + atest = true; + plin = [pl1, pl2, pl3, pl4]; + if stest + % <AlgoCode> + % Check we have the correct number of outputs + if numel(out) ~= numel(plin), atest = false; end + + % Check that the output is a copy. + for ii = 1:numel(out) + % Check that the output is the same + if ~eq(plin(ii), out(ii), ple1), atest = false; end + % Change the output to make sure that it is a 'real' copy + out(ii).setDescription('my desc'); + if eq(plin(ii), out(ii), ple1), atest = false; end + end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_04 + + %% UTP_05 + + % <TestDescription> + % + % Tests that the plist method works with a mix of different shaped PLISTs as + % input. + % + % </TestDescription> + function result = utp_05 + + % <SyntaxDescription> + % + % Test that the plist method works with a mix of different shaped PLISTs as + % input. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out = plist(pl1,plv,pl2,plm,pl3); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the number of elements in 'out' is the same of the + % number in the input. + % 2) Check that each output PLIST is a copy of the input PLIST. + % + % </AlgoDescription> + + atest = true; + plin = [pl1, reshape(plv, 1, []), pl2, reshape(plm, 1, []), pl3]; + if stest + % <AlgoCode> + % Check we have the correct number of outputs + if numel(out) ~= 3+numel(plv)+numel(plm), atest = false; end + + % Check that the output is a copy. + for ii = 1:numel(out) + % Check that the output is the same + if ~eq(plin(ii), out(ii), ple1), atest = false; end + % Change the output to make sure that it is a 'real' copy + out(ii).setDescription('my desc'); + if eq(plin(ii), out(ii), ple1), atest = false; end + end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_05 + + %% UTP_06 + + % <TestDescription> + % + % Tests the MAT-file constructor. + % + % </TestDescription> + function result = utp_06 + + % <SyntaxDescription> + % + % Tests the MAT-file constructor. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + filename = 'pl.mat'; + save(pl3, filename); + out = plist(filename); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the saved object is the same as the loaded object. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + if ~eq(out, pl3), atest = false; end + % </AlgoCode> + delete(filename); + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_06 + + + %% UTP_07 + + % <TestDescription> + % + % Tests the XML-file constructor. + % + % </TestDescription> + function result = utp_07 + + % <SyntaxDescription> + % + % Tests the XML-file constructor. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + filename = 'pl.xml'; + save(pl3, filename); + out = plist(filename); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the saved object is the same as the loaded object. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + if ~eq(out, pl3), atest = false; end + % </AlgoCode> + delete(filename); + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_07 + + + %% UTP_08 + + % <TestDescription> + % + % Tests that the plist method for a struct as an input. + % + % </TestDescription> + function result = utp_08 + + % <SyntaxDescription> + % + % Tests that the plist method for a struct as an input. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + + spl = utils.prog.rstruct(pl2); + + out1 = plist(struct(pl4)); + out2 = plist(spl); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 2) Check the built object. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + if ~eq(out1, pl4), atest = false; end + if ~eq(out2, pl2), atest = false; end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_08 + + %% UTP_09 + + % <TestDescription> + % + % Tests the param constructor. + % + % </TestDescription> + function result = utp_09 + + % <SyntaxDescription> + % + % Tests the param constructor. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + p1 = param('a', 1); + p2 = param('b', 2); + p3 = param('c', 3); + out1 = plist(p1); + out2 = plist([p1 p2 p3]); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the output contains the input parameter objects + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check that the output is a PLIST object + if ~isa(out1,'plist'), atest = false; end + if ~isa(out2,'plist'), atest = false; end + % Check the number of parameter objects in the PLIST + if out1.nparams ~= 1, atest = false; end + if out2.nparams ~= 3, atest = false; end + % Check that the parameter objects exist in the plist object + if ~isequal(out1.find('a'), 1), atest = false; end + if ~isequal(out2.find('a'), 1), atest = false; end + if ~isequal(out2.find('b'), 2), atest = false; end + if ~isequal(out2.find('c'), 3), atest = false; end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_09 + + %% UTP_10 + + % <TestDescription> + % + % Tests the plist(filename) constructor. + % + % </TestDescription> + function result = utp_10 + + % <SyntaxDescription> + % + % Tests the plist(filename) constructor. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + filename1 = 'pl.xml'; + filename2 = 'pl.mat'; + + save(pl1, filename1); + save(pl2, filename2); + + out1 = plist(plist('filename', filename1)); + out2 = plist(plist('filename', filename2)); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the loaded object is the same as the saved object + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + if ~eq(out1, pl1), atest = false; end + if ~eq(out2, pl2), atest = false; end + % </AlgoCode> + % delete test file + delete(filename1) + delete(filename2) + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_10 + + %% UTP_11 + + % <TestDescription> + % + % Tests the plist(conn) constructor. + % + % </TestDescription> + function result = utp_11 + + % <SyntaxDescription> + % + % Tests the plist(conn) constructor. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + conn = utpGetConnection(); + + sinfo.conn = conn; + sinfo.experiment_title = 'utp_plist_plist_11: submit plist vector'; + sinfo.experiment_description = 'utp_plist_plist_11: &description'; + sinfo.analysis_description = '<utp_plist_plist_11>'; + sinfo.quantity = 'none'; + sinfo.keywords = 'none'; + sinfo.reference_ids = ''; + sinfo.additional_comments = 'none'; + sinfo.additional_authors = 'no one'; + + plForAutoTest = plist('no dialog', true, 'use selector', false); + ids = submit(plv, sinfo, plForAutoTest); + + out = plist(plist('hostname', utpGetHostname, 'database', utpGetDatabase, 'conn', conn, 'id', ids)); + % </SyntaxCode> + utpCloseConnection(conn); + stest = true; + catch err + disp(err.message) + % Close connection + utpCloseConnection(conn); + stest = false; + end + + % <AlgoDescription> + % + % 1) Check the retrieved object against the submitted object. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + if ~eq(out, plv), atest = false; end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_11 + + %% UTP_12 + + % <TestDescription> + % + % Tests the conn+Id constructor. + % + % </TestDescription> + function result = utp_12 + + % <SyntaxDescription> + % + % Tests the conn+Id constructor. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + conn = utpGetConnection(); + + sinfo.conn = conn; + sinfo.experiment_title = 'utp_plist_plist_12: submit plist'; + sinfo.experiment_description = 'utp_plist_plist_12: description'; + sinfo.analysis_description = 'utp_plist_plist_12'; + sinfo.quantity = 'none'; + sinfo.keywords = 'none'; + sinfo.reference_ids = ''; + sinfo.additional_comments = 'none'; + sinfo.additional_authors = 'no one'; + + plForAutoTest = plist('no dialog', true, 'use selector', false); + [ids] = submit(pl3, sinfo, plForAutoTest); + + out = plist(conn, ids); + % </SyntaxCode> + utpCloseConnection(conn); + stest = true; + catch err + disp(err.message) + utpCloseConnection(conn); + stest = false; + end + + % <AlgoDescription> + % + % 1) Check the retrieved object against the submitted object. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + if ~eq(out, pl3), atest = false; end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_12 + + %% UTP_13 + + % <TestDescription> + % + % Tests the key/value constructor + % + % </TestDescription> + function result = utp_13 + + % <SyntaxDescription> + % + % Tests the key/value constructor + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out1 = plist('a', 1); + out2 = plist('a', 1, 'b', 2); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check the right number of parameter in the PLIST object + % 2) Check the parameter in the PLIST object + % 3) Check that the key is in capital letter. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the right number of parameter in the PLIST object + if out1.nparams ~= 1, atest = false; end + if out2.nparams ~= 2, atest = false; end + % Check the parameter in the PLIST object + if ~isequal(out1.find('a'), 1), atest = false; end + if ~isequal(out2.find('a'), 1), atest = false; end + if ~isequal(out2.find('b'), 2), atest = false; end + % Check that the key is in capital letter. + if ~isequal(out1.params(1).key, 'A'), atest = false; end + if ~isequal(out2.params(1).key, 'A'), atest = false; end + if ~isequal(out2.params(2).key, 'B'), atest = false; end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_13 + +end