changeset 12250:12f2bcb222eb octave-forge

Various fixes, more error checks & diagnostics
author prnienhuis
date Sun, 29 Dec 2013 22:32:11 +0000
parents 4f7c6be6d3df
children a8435f9ef9fa
files main/io/inst/io_xls_testscript.m
diffstat 1 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/main/io/inst/io_xls_testscript.m	Sun Dec 29 22:31:26 2013 +0000
+++ b/main/io/inst/io_xls_testscript.m	Sun Dec 29 22:32:11 2013 +0000
@@ -50,7 +50,7 @@
   arr1 = [ 1 2; 3 4.5];
   arr2 = {'r1c1', '=c2+d2'; '', 'r2c2'; true, -83.4};
   opts = struct ("formulas_as_text", 0);
-  
+
   ## 2. Insert empty sheet
   printf ("\n 2. Insert first empty sheet.\n");
   xlswrite (fname, {''}, 'EmptySheet', 'b4', intf2); if (isuno); sleep (dly); endif
@@ -67,11 +67,15 @@
   ## 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
-  shnr = strmatch ('Testsheet', shts(:, 1));        ## Note case!
-  crange = shts{shnr, 2};                           ## Range can be unreliable
+  shnr = strmatch ('Testsheet', shts(:, 1));      ## Note case!
+  if (isempty (shnr))
+    printf ("Worksheet with data not found - not properly written ... test failed.\n");
+    return
+  endif
+  crange = shts{shnr, 2};                       ## Range can be unreliable
   if (strcmpi (crange, "A1:A1"))
     crange = ''
-  endif
+  endif
   
   ## 6. Read data back
   printf ("\n 6. Read data back.\n");
@@ -152,16 +156,20 @@
 
   try
     # Just check if it contains any string
-    assert ( (ischar (raw{3, 3}) && ~isempty (raw(3, 3)) && raw{3, 3}(1) == "="), true); 
+    assert ( (ischar (raw{3, 3}) && ! isempty (raw(3, 3)) && raw{3, 3}(1) == "="), true); 
     printf ("    ...OK, formula recovered ('%s').\n", raw{3, 3});
   catch
-    printf ("Hmmm.... error, see 'raw(3, 3)'");
-    if (isempty (raw{3, 3}))
-      printf (" (empty, should be a string like '=c2+d2')\n");
-    elseif (isnumeric (raw{3, 3}))
-      printf (" (equals %f, should be a string like '=c2+d2')\n", raw{3, 3}); 
-    else
-      printf ("\n");
+    printf ("Hmmm.... error, see 'raw(3, 3)'");
+    if (size (raw, 1) >= 3 && size (raw, 2) >= 3)
+      if (isempty (raw{3, 3}))
+        printf (" (empty, should be a string like '=c2+d2')\n");
+      elseif (isnumeric (raw{3, 3}))
+        printf (" (equals %f, should be a string like '=c2+d2')\n", raw{3, 3}); 
+      else
+        printf ("\n");
+      endif
+    else
+      printf (".. raw{3, 3} doesn't even exist, array too small... Test failed.\n");
     endif
   end_try_catch