mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add test to compare query->string conversion by converting to a
char* and then evaluating the string. Also re-add the ability to print out a bunch of queries. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6949 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
42761622b4
commit
ea90d5a3f1
@ -3,6 +3,7 @@ TESTS = \
|
|||||||
test-load-module \
|
test-load-module \
|
||||||
test-component-manager \
|
test-component-manager \
|
||||||
test-exp-parser \
|
test-exp-parser \
|
||||||
|
test-scm-query-string \
|
||||||
test-print-parse-amount
|
test-print-parse-amount
|
||||||
|
|
||||||
GNC_TEST_DEPS := \
|
GNC_TEST_DEPS := \
|
||||||
@ -36,7 +37,9 @@ LDADD = \
|
|||||||
noinst_PROGRAMS = \
|
noinst_PROGRAMS = \
|
||||||
test-link-module \
|
test-link-module \
|
||||||
test-exp-parser \
|
test-exp-parser \
|
||||||
test-print-parse-amount
|
test-print-parse-amount \
|
||||||
|
test-scm-query-string \
|
||||||
|
test-print-queries
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
test-load-module \
|
test-load-module \
|
||||||
@ -47,4 +50,5 @@ AM_CFLAGS = \
|
|||||||
-I${top_srcdir}/src/engine \
|
-I${top_srcdir}/src/engine \
|
||||||
-I${top_srcdir}/src/engine/test-core \
|
-I${top_srcdir}/src/engine/test-core \
|
||||||
-I${top_srcdir}/src/app-utils \
|
-I${top_srcdir}/src/app-utils \
|
||||||
|
-I${top_srcdir}/src/gnc-module \
|
||||||
${GLIB_CFLAGS}
|
${GLIB_CFLAGS}
|
||||||
|
79
src/app-utils/test/test-print-queries.c
Normal file
79
src/app-utils/test/test-print-queries.c
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <guile/gh.h>
|
||||||
|
|
||||||
|
#include "engine-helpers.h"
|
||||||
|
#include "gnc-module.h"
|
||||||
|
#include "test-engine-stuff.h"
|
||||||
|
#include "test-stuff.h"
|
||||||
|
#include "Query.h"
|
||||||
|
#include "TransLog.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_query (Query *q, SCM val2str)
|
||||||
|
{
|
||||||
|
SCM scm_q;
|
||||||
|
SCM str_q;
|
||||||
|
SCM args = SCM_EOL;
|
||||||
|
|
||||||
|
scm_q = gnc_query2scm (q);
|
||||||
|
args = gh_cons (scm_q, SCM_EOL);
|
||||||
|
str_q = gh_apply (val2str, args);
|
||||||
|
|
||||||
|
args = gh_cons (gh_str02scm ("'"), gh_cons (str_q, SCM_EOL));
|
||||||
|
str_q = scm_string_append (args);
|
||||||
|
|
||||||
|
gh_display (str_q); gh_newline (); gh_newline ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
run_tests (int count)
|
||||||
|
{
|
||||||
|
Query *q;
|
||||||
|
SCM val2str;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
val2str = gh_eval_str ("gnc:value->string");
|
||||||
|
g_return_if_fail (gh_procedure_p (val2str));
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
q = get_random_query ();
|
||||||
|
test_query (q, val2str);
|
||||||
|
xaccFreeQuery (q);
|
||||||
|
}
|
||||||
|
success ("");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
main_helper (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int count = 50;
|
||||||
|
|
||||||
|
gnc_module_load("gnucash/engine", 0);
|
||||||
|
gnc_module_load("gnucash/app-utils", 0);
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
count = atoi (argv[1]);
|
||||||
|
|
||||||
|
if (count < 0)
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
xaccLogDisable ();
|
||||||
|
|
||||||
|
/* scm conversion doesn't handle binary atm */
|
||||||
|
kvp_exclude_type (KVP_TYPE_BINARY);
|
||||||
|
|
||||||
|
run_tests (count);
|
||||||
|
|
||||||
|
print_test_results ();
|
||||||
|
|
||||||
|
exit (get_rv ());
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
gh_enter (argc, argv, main_helper);
|
||||||
|
return 0;
|
||||||
|
}
|
99
src/app-utils/test/test-scm-query-string.c
Normal file
99
src/app-utils/test/test-scm-query-string.c
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <guile/gh.h>
|
||||||
|
|
||||||
|
#include "engine-helpers.h"
|
||||||
|
#include "gnc-module.h"
|
||||||
|
#include "test-engine-stuff.h"
|
||||||
|
#include "test-stuff.h"
|
||||||
|
#include "Query.h"
|
||||||
|
#include "TransLog.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_query (Query *q, SCM val2str)
|
||||||
|
{
|
||||||
|
SCM scm_q;
|
||||||
|
SCM str_q;
|
||||||
|
SCM res_q;
|
||||||
|
SCM args = SCM_EOL;
|
||||||
|
Query *q2;
|
||||||
|
char * str;
|
||||||
|
|
||||||
|
scm_q = gnc_query2scm (q);
|
||||||
|
args = gh_cons (scm_q, SCM_EOL);
|
||||||
|
str_q = gh_apply (val2str, args);
|
||||||
|
|
||||||
|
args = gh_cons (gh_str02scm ("'"), gh_cons (str_q, SCM_EOL));
|
||||||
|
str_q = scm_string_append (args);
|
||||||
|
|
||||||
|
str = gh_scm2newstr (str_q, NULL);
|
||||||
|
|
||||||
|
if (str) {
|
||||||
|
res_q = gh_eval_str (str);
|
||||||
|
} else {
|
||||||
|
res_q = SCM_BOOL_F;
|
||||||
|
}
|
||||||
|
|
||||||
|
q2 = gnc_scm2query (res_q);
|
||||||
|
|
||||||
|
if (!xaccQueryEqual (q, q2))
|
||||||
|
{
|
||||||
|
failure ("queries don't match");
|
||||||
|
fprintf (stderr, "%s\n\n", str);
|
||||||
|
scm_q = gnc_query2scm (q2);
|
||||||
|
gh_display (scm_q); gh_newline ();
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
success ("queries match");
|
||||||
|
}
|
||||||
|
if (str) free (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
run_tests (void)
|
||||||
|
{
|
||||||
|
Query *q;
|
||||||
|
SCM val2str;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
val2str = gh_eval_str ("gnc:value->string");
|
||||||
|
g_return_if_fail (gh_procedure_p (val2str));
|
||||||
|
|
||||||
|
for (i = 0; i < 100; i++) {
|
||||||
|
q = get_random_query ();
|
||||||
|
test_query (q, val2str);
|
||||||
|
xaccFreeQuery (q);
|
||||||
|
}
|
||||||
|
success ("");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
main_helper (int argc, char **argv)
|
||||||
|
{
|
||||||
|
gnc_module_load("gnucash/engine", 0);
|
||||||
|
gnc_module_load("gnucash/app-utils", 0);
|
||||||
|
|
||||||
|
xaccLogDisable ();
|
||||||
|
|
||||||
|
/* scm conversion doesn't handle binary atm */
|
||||||
|
kvp_exclude_type (KVP_TYPE_BINARY);
|
||||||
|
|
||||||
|
/* double->string->double is not idempotent */
|
||||||
|
kvp_exclude_type (KVP_TYPE_DOUBLE);
|
||||||
|
|
||||||
|
run_tests ();
|
||||||
|
|
||||||
|
print_test_results ();
|
||||||
|
|
||||||
|
exit (get_rv ());
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
gh_enter (argc, argv, main_helper);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user