[Gnucash-changes] print out more info when trying to print/parse
numerics.
Derek Atkins
warlord at cvs.gnucash.org
Sat Jun 26 11:30:50 EDT 2004
Log Message:
-----------
print out more info when trying to print/parse numerics. There's
an overflow condition in the function being tested that needs to be fixed.
Modified Files:
--------------
gnucash/src/app-utils/test:
test-print-parse-amount.c
Revision Data
-------------
Index: test-print-parse-amount.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-utils/test/test-print-parse-amount.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lsrc/app-utils/test/test-print-parse-amount.c -Lsrc/app-utils/test/test-print-parse-amount.c -u -r1.3 -r1.4
--- src/app-utils/test/test-print-parse-amount.c
+++ src/app-utils/test/test-print-parse-amount.c
@@ -8,9 +8,9 @@
static void
-test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info)
+test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line)
{
- gnc_numeric n_parsed;
+ gnc_numeric n_parsed = gnc_numeric_zero();
const char *s;
gboolean ok;
@@ -19,14 +19,14 @@
ok = xaccParseAmount (s, print_info.monetary, &n_parsed, NULL);
do_test_args (ok, "parsing failure", __FILE__, __LINE__,
- "num: %s, string %s", gnc_numeric_to_string (n), s);
+ "num: %s, string %s (line %d)", gnc_numeric_to_string (n), s, line);
ok = gnc_numeric_equal (n, n_parsed);
do_test_args (ok, "not equal", __FILE__, __LINE__,
- "start: %s, string %s, finish: %s",
+ "start: %s, string %s, finish: %s (line %d)",
gnc_numeric_to_string (n), s,
- gnc_numeric_to_string (n_parsed));
+ gnc_numeric_to_string (n_parsed), line);
}
static void
@@ -52,27 +52,41 @@
print_info.round = 0;
n1 = gnc_numeric_convert (n, fraction, GNC_RND_ROUND);
+ if (gnc_numeric_check(n1)) {
+ do_test_args(0, "BAD NUMERIC CONVERSION", __FILE__, __LINE__,
+ "num: %s, fraction: %d", gnc_numeric_to_string(n), fraction);
+ continue;
+ }
- test_num_print_info (n1, print_info);
+ test_num_print_info (n1, print_info, __LINE__);
print_info.monetary = 0;
- test_num_print_info (n1, print_info);
+ test_num_print_info (n1, print_info, __LINE__);
print_info.use_separators = 0;
- test_num_print_info (n1, print_info);
+ test_num_print_info (n1, print_info, __LINE__);
print_info.round = 1;
- test_num_print_info (n1, print_info);
+ test_num_print_info (n1, print_info, __LINE__);
print_info.round = 0;
print_info.force_fit = 1;
- test_num_print_info (n1, print_info);
+ test_num_print_info (n1, print_info, __LINE__);
print_info.round = 1;
- test_num_print_info (n1, print_info);
+ test_num_print_info (n1, print_info, __LINE__);
}
}
+#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; }
+
static void
run_tests (void)
{
@@ -81,14 +95,18 @@
for (i = 0; i < 50; i++)
{
gnc_numeric n;
+ gnc_numeric n1;
n = get_random_gnc_numeric ();
+ IS_VALID_NUM(n,n);
test_num (n);
- n = gnc_numeric_mul (n, n, n.denom, GNC_RND_ROUND);
+ n1 = gnc_numeric_mul (n, n, n.denom, GNC_RND_ROUND);
+ IS_VALID_NUM(n1,n);
test_num (n);
- n = gnc_numeric_mul (n, n, n.denom, GNC_RND_ROUND);
+ n1 = gnc_numeric_mul (n, n, n.denom, GNC_RND_ROUND);
+ IS_VALID_NUM(n1,n);
test_num (n);
}
}
More information about the gnucash-changes
mailing list