# HG changeset patch # User Kai Habel # Date 1316027019 -7200 # Node ID 79b9a7669bb8a53b674a8e69b79ef925c94c843d # Parent af36cdb552a652231b5f99e3d6ebd053354c5812 Tests added for scripts/plot (plot/ishghandle.m, plot/text.m, plot/title.m, plot/xlabel.m, plot/ylabel.m, plot/zlabel.m): Tests added for plot functions. plot/whitebg.m: Fix typo. Change colors only for figure under test diff -r af36cdb552a6 -r 79b9a7669bb8 scripts/plot/ishghandle.m --- a/scripts/plot/ishghandle.m Wed Sep 14 13:50:33 2011 -0400 +++ b/scripts/plot/ishghandle.m Wed Sep 14 21:03:39 2011 +0200 @@ -26,3 +26,34 @@ ## no simulink equivalent. retval = ishandle (h); endfunction + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! assert (ishghandle (hf)); +%! assert (!ishghandle (-hf)); +%! l = line; +%! ax = gca(); +%! assert (ishghandle (ax)); +%! assert (!ishghandle (-ax)); +%! assert (ishghandle (l)); +%! assert (!ishghandle (-l)); +%! p = patch; +%! assert (ishghandle (p)); +%! assert (!ishghandle (-p)); +%! s = surface; +%! assert (ishghandle (s)); +%! assert (!ishghandle (-s)); +%! t = text; +%! assert (ishghandle (t)); +%! assert (!ishghandle (-t)); +%! i = image; +%! assert (ishghandle (i)); +%! assert (!ishghandle (-i)); +%! hg = hggroup; +%! assert (ishghandle (hg)); +%! assert (!ishghandle (-hg)); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + diff -r af36cdb552a6 -r 79b9a7669bb8 scripts/plot/text.m --- a/scripts/plot/text.m Wed Sep 14 13:50:33 2011 -0400 +++ b/scripts/plot/text.m Wed Sep 14 21:03:39 2011 +0200 @@ -218,3 +218,33 @@ %! ylabel (1:2) %! title (1:2) +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! h = text (0.5, 0.3, "char"); +%! assert ("char", class (get (h, "string"))) +%! h = text (0.5, 0.4, ["char row 1"; "char row 2"]); +%! assert ("char", class (get (h, "string"))) +%! h = text (0.5, 0.6, {"cell2str (1,1)", "cell2str (1,2)"; "cell2str (2,1)", "cell2str (2,2)"}); +%! assert ("cell", class (get (h, "string"))) +%! h = text (0.5, 0.8, "foobar"); +%! set (h, "string", 1:3) +%! h = text ([0.1, 0.1], [0.3, 0.4], "one string & two objects"); +%! assert ("char", class (get (h(1), "string"))) +%! assert ("char", class (get (h(2), "string"))) +%! h = text ([0.1, 0.1], [0.5, 0.6], {"one cellstr & two objects"}); +%! assert ("cell", class (get (h(1), "string"))) +%! assert ("cell", class (get (h(2), "string"))) +%! h = text ([0.1, 0.1], [0.7, 0.8], {"cellstr 1 object 1", "cellstr 2 object 2"}); +%! assert ("char", class (get (h(1), "string"))) +%! assert ("char", class (get (h(2), "string"))) +%! h = text ([0.1, 0.1], [0.1, 0.2], ["1st string & 1st object"; "2nd string & 2nd object"]); +%! assert ("char", class (get (h(1), "string"))) +%! assert ("char", class (get (h(2), "string"))) +%! h = text (0.7, 0.6, "single string"); +%! assert ("char", class (get (h, "string"))) +%! h = text (0.7, 0.5, {"single cell-string"}); +%! assert ("cell", class (get (h, "string"))) +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect diff -r af36cdb552a6 -r 79b9a7669bb8 scripts/plot/title.m --- a/scripts/plot/title.m Wed Sep 14 13:50:33 2011 -0400 +++ b/scripts/plot/title.m Wed Sep 14 21:03:39 2011 +0200 @@ -52,5 +52,24 @@ %! title("Testing title") %! assert(get(xl,"string"),"Testing title") -## Remove from test statistics. No real tests possible. -%!assert (1) +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! ax=axes(); +%! xl = get(ax,"title"); +%! title("Testing title") +%! assert(get(xl,"string"),"Testing title") +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! plot3 ([0,1], [0,1], [0,1]); +%! xl = get(gca (), "title"); +%! title("Testing title") +%! assert(get(xl,"string"),"Testing title") +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect diff -r af36cdb552a6 -r 79b9a7669bb8 scripts/plot/whitebg.m --- a/scripts/plot/whitebg.m Wed Sep 14 13:50:33 2011 -0400 +++ b/scripts/plot/whitebg.m Wed Sep 14 21:03:39 2011 +0200 @@ -40,7 +40,7 @@ h = 0; color = NaN; - if (nargin > 0 && nargin < 2) + if (nargin > 0 && nargin < 3) if (ishandle (varargin{1})) h = varargin{1}; if (nargin == 2) @@ -152,11 +152,11 @@ %! l = line; %! assert (get (hf, "color"), dfc); %! assert (get (gca, "color"), dac); -%! whitebg; +%! whitebg (hf); %! assert (get (hf, "color"), 1 - dfc); %! assert (get (gca, "color"), 1 - dac); %! c = [0.2 0.2 0.2]; -%! whitebg (c); +%! whitebg (hf, c); %! assert (get (hf, "color"), 1 - dfc); %! assert (get (gca, "color"), c); %! unwind_protect_cleanup diff -r af36cdb552a6 -r 79b9a7669bb8 scripts/plot/xlabel.m --- a/scripts/plot/xlabel.m Wed Sep 14 13:50:33 2011 -0400 +++ b/scripts/plot/xlabel.m Wed Sep 14 21:03:39 2011 +0200 @@ -53,3 +53,15 @@ endif endfunction + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! x = xlabel ("xlabel_string"); +%! assert (get(gca, "xlabel"), x); +%! assert (get(x, "type"), "text"); +%! assert (get(x, "visible"), "on"); +%! assert (get(x, "string"), "xlabel_string"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect diff -r af36cdb552a6 -r 79b9a7669bb8 scripts/plot/ylabel.m --- a/scripts/plot/ylabel.m Wed Sep 14 13:50:33 2011 -0400 +++ b/scripts/plot/ylabel.m Wed Sep 14 21:03:39 2011 +0200 @@ -47,3 +47,15 @@ endif endfunction + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! y = ylabel ("ylabel_string"); +%! assert (get(gca, "ylabel"), y); +%! assert (get(y, "type"), "text"); +%! assert (get(y, "visible"), "on"); +%! assert (get(y, "string"), "ylabel_string"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect diff -r af36cdb552a6 -r 79b9a7669bb8 scripts/plot/zlabel.m --- a/scripts/plot/zlabel.m Wed Sep 14 13:50:33 2011 -0400 +++ b/scripts/plot/zlabel.m Wed Sep 14 21:03:39 2011 +0200 @@ -47,3 +47,28 @@ endif endfunction + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! z = zlabel ("zlabel_string"); +%! assert (get(gca, "zlabel"), z); +%! assert (get(z, "type"), "text"); +%! assert (get(z, "visible"), "off"); +%! assert (get(z, "string"), "zlabel_string"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +%!test +%! hf = figure ("visible", "off"); +%! plot3 (0, 0, 0); +%! unwind_protect +%! z = zlabel ("zlabel_string"); +%! assert (get(gca, "zlabel"), z); +%! assert (get(z, "type"), "text"); +%! assert (get(z, "visible"), "off"); +%! assert (get(z, "string"), "zlabel_string"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect