changeset 12271:b894e2fba4d6 octave-forge

More extensive texinfo help text & fixed texinfo bugs
author prnienhuis
date Wed, 01 Jan 2014 21:33:04 +0000
parents f99d0e2a6719
children 4d72c0cf53f4
files main/io/inst/io_ods_testscript.m main/io/inst/io_xls_testscript.m main/io/inst/test_spsh.m
diffstat 3 files changed, 153 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/main/io/inst/io_ods_testscript.m	Wed Jan 01 21:32:20 2014 +0000
+++ b/main/io/inst/io_ods_testscript.m	Wed Jan 01 21:33:04 2014 +0000
@@ -12,8 +12,31 @@
 ##
 ## You should have received a copy of the GNU General Public License along with
 ## this program; if not, see <http://www.gnu.org/licenses/>.
-
-## (Internal function) Check proper operation of ODS spreadsheet scripts.
+
+## -*- texinfo -*- 
+## @deftypefn {Function File} io_ods_testscript (@var{intf1})
+## @deftypefnx {Function File} io_ods_testscript (@var{intf1}, @var{fname})
+## @deftypefnx {Function File} io_ods_testscript (@var{intf1}, @var{fname}, @var{intf2})
+## Try to check proper operation of ODS spreadsheet scripts using
+## interface @var{intf1}.
+##
+## @var{intf1} can be one of OTK, JOD, UNO, or OCT.  No checks
+## are made as to whether the requested interface is supported at all.  If
+## @var{fname} is supplied, that filename is used for the tests, otherwise
+## filename "io-test.ods" is chosen by default.
+##
+## If @var{intf2} is supplied, that interface will be used for writing the
+## spreadsheet file and @var{intf1} will be used for reading.  The OCT
+## interface doesn't have write support (yet), so it will read spreadsheet
+## files made by OTK (if supported) unless another interface is supplied
+## for @var{intf2}.
+##
+## As the tests are meant to be run interactively, no output arguments are
+## returned. The results of all test steps are printed on the terminal.
+##
+## @seealso {test_spsh, io_xls_testscript}
+##
+## @end deftypefn
 
 ## Author: Philip Nienhuis
 ## Created: 2012-02-25
@@ -22,6 +45,7 @@
 ## 2013-04-21 Made it into a function
 ## 2013-12-18 Add option to write and read with different interfaces (needed for OCT)
 ##     ''     Catch more erroneous read-back results
+## 2013-12-31 More extensive texinfo help text
 
 function io_ods_testscript (intf, fname, intf2='')
 
@@ -71,7 +95,7 @@
   printf ("\n 6. Read data back.\n");
   [num, txt, raw, lims] = odsread (fname, shnr, crange, intf); if (isuno); sleep (dly); endif
   
-  ## First check: has anything been read at all?x
+  ## First check: has anything been read at all?
   if (isempty (raw))
     printf ("No data at all have been read... test failed.\n");
     return
--- a/main/io/inst/io_xls_testscript.m	Wed Jan 01 21:32:20 2014 +0000
+++ b/main/io/inst/io_xls_testscript.m	Wed Jan 01 21:33:04 2014 +0000
@@ -13,8 +13,33 @@
 ## You should have received a copy of the GNU General Public License along with
 ## this program; if not, see <http://www.gnu.org/licenses/>.
 
-## (Internal function) Check proper operation of XLS spreadsheet scripts.
-
+## -*- texinfo -*- 
+## @deftypefn {Function File} io_xls_testscript (@var{intf1})
+## @deftypefnx {Function File} io_xls_testscript (@var{intf1}, @var{fname})
+## @deftypefnx {Function File} io_xls_testscript (@var{intf1}, @var{fname}, @var{intf2})
+## Try to check proper operation of XLS / XLSX spreadsheet scripts using
+## interface @var{intf1}.
+##
+## @var{intf1} can be one of COM, POI, JXL, OXS, UNO, or OCT.  No checks
+## are made as to whether the requested interface is supported at all.  If
+## @var{fname} is supplied, that filename is used for the tests, otherwise
+## filename "io-test.xls" is chosen by default.  This parameter is required
+## to have e.g., POI distinguish between testing .xls (BIFF8) and .xlsx
+## (OOXML) files.
+##
+## If @var{intf2} is supplied, that interface will be used for writing the
+## spreadsheet file and @var{intf1} will be used for reading.  The OCT
+## interface doesn't have write support (yet), so it will read spreadsheet
+## files made by POI (if supported) unless another interface is supplied
+## for @var{intf2}.
+##
+## As the tests are meant to be run interactively, no output arguments are
+## returned. The results of all test steps are printed on the terminal.
+##
+## @seealso {test_spsh, io_ods_testscript}
+##
+## @end deftypefn
+
 ## Author: Philip Nienhuis <pr.nienhuis at users.sf.net>
 ## Created: 2012-02-25
 ## Updates:
@@ -22,7 +47,11 @@
 ## 2012-09-04 Added delay between LibreOffice calls to avoid lockups with UNO
 ## 2013-04-21 Made it into a function
 ## 2013-12-12 Updated copyright strings
-## 2013-12-19 Add option to write and read with different interfaces (needed for OCT)
+## 2013-12-19 Add option to write and read with different interfaces (needed for OCT)
+## 2013-12-31 More extensive texinfo help text
+## 2013-12-31 Style fixes
+##     ''     Also delay a bit if write intf2 = UNO to avoid unzip errors
+## 2014-01-01 Provisionally fall back to COM or POI for intf2
 
 function io_xls_testscript (intf, fname, intf2=[])
 
@@ -30,21 +59,23 @@
 
   isuno = false;
   dly = 0.25;
-  if (strcmpi (intf, 'oxs') || strcmpi (intf, 'oct'))
-    if (isempty (intf2))
+  if (strcmpi (intf, 'oct'))
+  ## FIXME commented out/replaced until UNO & OXS OOXML write support is fixed
+##  if (isempty (intf2))
+    if (isempty (intf2) || ! strcmpi (intf2, "com"))
       intf2 = 'poi';
     endif
-    if (strcmpi (intf2, 'uno'))
-      isuno = true;
-    endif
-    printf ("OXS / OCT interface has no write support enabled - writing is done with %s.\n", intf2);
-  elseif (strcmpi (intf, 'uno'));
-    isuno = true;
-  endif
+    printf ("OCT interface has no write support enabled - writing is done with %s.\n", intf2);
+  endif
+  ## If no intf2 is supplied, write with intf1
   if (isempty (intf2))
     intf2 = intf;
   endif
-  
+  ## Allow the OS some delay to accomodate for file operations (zipping etc.)
+  if (strcmpi (intf, "uno") || strcmpi (intf2, "uno"));
+    isuno = true;
+  endif
+
   ## 1. Initialize test arrays
   printf ("\n 1. Initialize arrays.\n");
   arr1 = [ 1 2; 3 4.5];
@@ -53,20 +84,35 @@
 
   ## 2. Insert empty sheet
   printf ("\n 2. Insert first empty sheet.\n");
-  xlswrite (fname, {''}, 'EmptySheet', 'b4', intf2); if (isuno); sleep (dly); endif
+  xlswrite (fname, {''}, 'EmptySheet', 'b4', intf2); 
+  if (isuno)
+    sleep (dly);
+  endif
   
   ## 3. Add data to test sheet
   printf ("\n 3. Add data to test sheet.\n");
-  xlswrite (fname, arr1, 'Testsheet', 'c2:d3', intf2); if (isuno); sleep (dly); endif
-  xlswrite (fname, arr2, 'Testsheet', 'd4:z20', intf2); if (isuno); sleep (dly); endif
+  xlswrite (fname, arr1, 'Testsheet', 'c2:d3', intf2);
+  if (isuno)
+    sleep (dly);
+  endif
+  xlswrite (fname, arr2, 'Testsheet', 'd4:z20', intf2);
+  if (isuno)
+    sleep (dly);
+  endif
   
   ## 4. Insert another sheet
   printf ("\n 4. Add another sheet with just one number in A1.\n");
-  xlswrite (fname, [1], 'JustOne', 'A1', intf2); if (isuno); sleep (dly); endif
+  xlswrite (fname, [1], 'JustOne', 'A1', intf2);
+  if (isuno)
+    sleep (dly);
+  endif
 
   ## 5. Get sheet info & find sheet with data and data range
   printf ("\n 5. Explore sheet info.\n");
-  [~, shts] = xlsfinfo (fname, intf); if (isuno); sleep (dly); endif
+  [~, shts] = xlsfinfo (fname, intf);
+  if (isuno)
+    sleep (dly);
+  endif
   shnr = strmatch ('Testsheet', shts(:, 1));      ## Note case!
   if (isempty (shnr))
     printf ("Worksheet with data not found - not properly written ... test failed.\n");
@@ -79,7 +125,10 @@
   
   ## 6. Read data back
   printf ("\n 6. Read data back.\n");
-  [num, txt, raw, lims] = xlsread (fname, shnr, crange, intf); if (isuno); sleep (dly); endif
+  [num, txt, raw, lims] = xlsread (fname, shnr, crange, intf);
+  if (isuno)
+    sleep (dly);
+  endif
   
   ## First check: has anything been read at all?x
   if (isempty (raw))
@@ -146,9 +195,18 @@
   ## Check if "formulas_as_text" option works:
   printf ("\n 8. Repeat reading, now return formulas as text\n");
   opts.formulas_as_text = 1;
-  xls = xlsopen (fname, 0, intf); if (isuno); sleep (dly); endif
-  raw = xls2oct (xls, shnr, crange, opts); if (isuno); sleep (dly); endif
-  xls = xlsclose (xls); if (isuno); sleep (dly); endif
+  xls = xlsopen (fname, 0, intf);
+  if (isuno)
+    sleep (dly);
+  endif
+  raw = xls2oct (xls, shnr, crange, opts);
+  if (isuno)
+    sleep (dly);
+  endif
+  xls = xlsclose (xls);
+  if (isuno)
+    sleep (dly);
+  endif
   clear xls;
 
   ## 9. Here come the tests, part 2.
--- a/main/io/inst/test_spsh.m	Wed Jan 01 21:32:20 2014 +0000
+++ b/main/io/inst/test_spsh.m	Wed Jan 01 21:33:04 2014 +0000
@@ -15,15 +15,27 @@
 ## <http://www.gnu.org/licenses/>.  
 
 ## -*- texinfo -*- 
-## @deftypefn {Function File}  [ @var{ret} ] = test_sprdsh ()
-## @deftypefnx {Function File} [ @var{ret} ] = test_sprdsh (@var{interface})
-## Internal function meant for testing functionality of spreadsheet functions.
+## @deftypefn {Function File}  [ @var{void} ] = test_sprdsh ()
+## Test functionality of supported spreadsheet interfaces.
+##
+## test_spsh tests simply tests all interfaces that are found to be
+## supported by chk_spreadsheet_support() function, one by one.
+## It invokes the functions io_xls_testscript.m and io_ods_testscript.m
+## for the actual testing.
+##
+## As it is meant to be used interactively, no output arguments
+## are returned.
+##
+## @seealso {io_xls_testscript, io_ods_testscript}
+##
+## @end deftypefn
 
 ## Author: Philip Nienhuis <prnienhuis@users.sf.net>
 ## Created: 2013-04-21
 ## Updates:
 ## 2013-12-20 Updated texinfo header & copyright strings
-##     ''     Added OCT interface tests conditional of writing interfaces
+##     ''     Added OCT interface tests conditional of writing interfaces
+## 2013-12-31 Extended texinfo help text
 
 function [] = test_spsh (numb = [])
 
@@ -32,27 +44,29 @@
 
   ## Get available interfaces
   avail_intf = uint16 (chk_spreadsheet_support ());
-
-  if (! isempty (numb))
-    ## Check if numb makes sense
-    if (ischar (numb))
-      numb = lower (numb);
-      ## First check if it is recognized in the list ofinterfaces
-      if (ismember (numb, xls_intf) || ismember (numb, ods_intf))
-        idx = strmatch (numb, [xls_intf ods_intf]);
-        ## It is known; now check if it's actually supported at the moment
-        if (bitget (avail_intf, idx))
-          ## It is, set just that bit of avail_intf that's related to intf 'numb'
-          avail_intf = bitset (uint16 (0), idx, 1);
-        else
-          ## It isn't, notify user
-          error ("Requested interface \"%s\" presently not available\n", numb);
-        endif
-      else
-        error ("Unknown interface - %s\n", numb);
-      endif
-    endif
-  endif
+
+  ## FIXME Sort out below code so that arbitrary bit patterns can be tested
+  ##       resembling the one returned by uint16 (chk_spreadsheet_support)
+  ##if (! isempty (numb))
+  ##  ## Check if numb makes sense
+  ##  if (ischar (numb))
+  ##    numb = lower (numb);
+  ##    ## First check if it is recognized in the list ofinterfaces
+  ##    if (ismember (numb, xls_intf) || ismember (numb, ods_intf))
+  ##      idx = strmatch (numb, [xls_intf ods_intf]);
+  ##      ## It is known; now check if it's actually supported at the moment
+  ##      if (bitget (avail_intf, idx))
+  ##        ## It is, set just that bit of avail_intf that's related to intf 'numb'
+  ##        avail_intf = bitset (uint16 (0), idx, 1);
+  ##      else
+  ##        ## It isn't, notify user
+  ##        error ("Requested interface \"%s\" presently not available\n", numb);
+  ##      endif
+  ##    else
+  ##      error ("Unknown interface - %s\n", numb);
+  ##    endif
+  ##  endif
+  ##endif
 
   ## First all Excel xls/xlsx interfaces
   intf2 = '';
@@ -82,9 +96,11 @@
     if (! isempty (intf))
       printf ("\nInterface \"%s\" found.\n", upper (intf));
       io_xls_testscript (intf, fname);
-    endif
+    endif
+    ## Allow the OS some time for cleaning up
+    sleep (0.25);
   endfor
-  ## Test OCT interface if possible
+  ## Test OCT interface if possible. Intf2 = last used in above for loop
   if (! isempty (intf2))
     printf ("\nInterface \"OCT\"....\n");
     io_xls_testscript ("OCT", 'io-test.xlsx', intf2);
@@ -110,8 +126,10 @@
       printf ("\nInterface \"%s\" found.\n", upper (intf));
       io_ods_testscript (intf, 'io-test.ods');
     endif
+    ## Allow the OS some time for cleaning up
+    sleep (0.25);
   endfor
-  ## Test OCT interface if possible
+  ## Test OCT interface if possible. Intf2 = last used in above for loop
   if (! isempty (intf2))
     printf ("\nInterface \"OCT\"....\n");
     io_ods_testscript ("OCT", 'io-test.ods', intf2);