From 6400638073bb88e1db8943fee88519cc21f5e91a Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Mon, 9 Jan 2006 03:33:46 +0000 Subject: [PATCH] Don't test numeric parsing for numbers that overflow, we'd fail. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12306 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-utils/gnc-ui-util.c | 3 ++- src/app-utils/test/test-print-parse-amount.c | 25 ++++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/app-utils/gnc-ui-util.c b/src/app-utils/gnc-ui-util.c index 9a577399e1..bc1e7f01a8 100644 --- a/src/app-utils/gnc-ui-util.c +++ b/src/app-utils/gnc-ui-util.c @@ -1488,7 +1488,8 @@ xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info) /* 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; diff --git a/src/app-utils/test/test-print-parse-amount.c b/src/app-utils/test/test-print-parse-amount.c index 33fecb4c24..4b683b281e 100644 --- a/src/app-utils/test/test-print-parse-amount.c +++ b/src/app-utils/test/test-print-parse-amount.c @@ -12,9 +12,12 @@ test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line) { 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 @@ test_num (gnc_numeric n) 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 @@ test_num (gnc_numeric n) } } -#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)