[Gnucash-changes] r12306 - gnucash/trunk/src/app-utils - Don't test numeric parsing for numbers that overflow, we'd fail.

Chris Shoemaker chris at cvs.gnucash.org
Sun Jan 8 22:33:47 EST 2006


Author: chris
Date: 2006-01-08 22:33:46 -0500 (Sun, 08 Jan 2006)
New Revision: 12306
Trac: http://svn.gnucash.org/trac/changeset/12306

Modified:
   gnucash/trunk/src/app-utils/gnc-ui-util.c
   gnucash/trunk/src/app-utils/test/test-print-parse-amount.c
Log:
Don't test numeric parsing for numbers that overflow, we'd fail.


Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c	2006-01-08 22:39:47 UTC (rev 12305)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c	2006-01-09 03:33:46 UTC (rev 12306)
@@ -1488,7 +1488,8 @@
   /* hack alert -- this is not thread safe ... */
   static char buf[1024];
 
-  xaccSPrintAmount (buf, val, info);
+  if (!xaccSPrintAmount (buf, val, info))
+      buf[0] = '\0';
 
   /* its OK to return buf, since we declared it static */
   return buf;

Modified: gnucash/trunk/src/app-utils/test/test-print-parse-amount.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-print-parse-amount.c	2006-01-08 22:39:47 UTC (rev 12305)
+++ gnucash/trunk/src/app-utils/test/test-print-parse-amount.c	2006-01-09 03:33:46 UTC (rev 12306)
@@ -12,9 +12,12 @@
 {
   gnc_numeric n_parsed = gnc_numeric_zero();
   const char *s;
-  gboolean ok;
+  gboolean ok, print_ok;
 
   s = xaccPrintAmount (n, print_info);
+  print_ok = (s && s[0] != '\0');
+  if (!print_ok)
+      return;
 
   ok = xaccParseAmount (s, print_info.monetary, &n_parsed, NULL);
 
@@ -53,7 +56,8 @@
 
     n1 = gnc_numeric_convert (n, fraction, GNC_RND_ROUND);
     if (gnc_numeric_check(n1)) {
-      do_test_args(0, "BAD NUMERIC CONVERSION", __FILE__, __LINE__,
+        do_test_args((gnc_numeric_check(n1) == GNC_ERROR_OVERFLOW), 
+                     "BAD NUMERIC CONVERSION", __FILE__, __LINE__,
 		   "num: %s, fraction: %d", gnc_numeric_to_string(n), fraction);
       continue;
     }
@@ -78,14 +82,15 @@
   }
 }
 
-#define IS_VALID_NUM(n,m)				\
-  if (gnc_numeric_check(n)) {				\
-    do_test_args(0, "BAD NUMERIC", __FILE__, __LINE__,	\
-		 "num: %s (from %s)",			\
-		 gnc_numeric_to_string(n),		\
-		 gnc_numeric_to_string(m));		\
-    continue;						\
-  } else { m = n; }
+#define IS_VALID_NUM(n,m)                                               \
+    if (gnc_numeric_check(n)) {                                         \
+        do_test_args(gnc_numeric_check(n) == GNC_ERROR_OVERFLOW,        \
+                     "BAD NUMERIC", __FILE__, __LINE__,                 \
+                     "num: %s (from %s)",                               \
+                     gnc_numeric_to_string(n),                          \
+                     gnc_numeric_to_string(m));                         \
+        continue;                                                       \
+    } else { m = n; }
 
 static void
 run_tests (void)



More information about the gnucash-changes mailing list