GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-scm-query.c
1 
2 #include "config.h"
3 #include <glib.h>
4 #include <libguile.h>
5 
6 #include "engine-helpers-guile.h"
7 #include "gnc-module.h"
8 #include "test-engine-stuff.h"
9 #include "test-stuff.h"
10 #include "Query.h"
11 #include "TransLog.h"
12 
13 
14 static void
15 test_query (QofQuery *q)
16 {
17  SCM scm_q;
18  QofQuery *q2;
19 
20  scm_q = gnc_query2scm (q);
21 
22  q2 = gnc_scm2query (scm_q);
23 
24  if (!qof_query_equal (q, q2))
25  {
26  failure ("queries don't match");
27  scm_display (scm_q, SCM_UNDEFINED);
28  scm_newline (SCM_UNDEFINED);
29  scm_q = gnc_query2scm (q2);
30  scm_display (scm_q, SCM_UNDEFINED);
31  scm_newline (SCM_UNDEFINED);
32  exit (1);
33  }
34  else
35  {
36  success ("queries match");
37  }
38 
39  qof_query_destroy (q2);
40 }
41 
42 static void
43 run_tests (void)
44 {
45  QofQuery *q;
46  int i;
47 
48  test_query (NULL);
49 
50  q = qof_query_create_for(GNC_ID_SPLIT);
51  test_query (q);
53 
54  for (i = 0; i < 50; i++)
55  {
56  q = get_random_query ();
57  test_query (q);
59  }
60 }
61 
62 static void
63 main_helper (void *closure, int argc, char **argv)
64 {
65  gnc_module_system_init ();
66  gnc_module_load("gnucash/engine", 0);
67 
68  xaccLogDisable ();
69 
70  run_tests ();
71 
72  print_test_results ();
73 
74  exit (get_rv ());
75 }
76 
77 int
78 main (int argc, char **argv)
79 {
80  g_setenv ("GNC_UNINSTALLED", "1", TRUE);
81  scm_boot_guile (argc, argv, main_helper, NULL);
82  return 0;
83 }
void xaccLogDisable(void)
Definition: TransLog.c:93
gboolean qof_query_equal(const QofQuery *q1, const QofQuery *q2)
struct _QofQuery QofQuery
Definition: qofquery.h:90
void qof_query_destroy(QofQuery *q)
API for the transaction logger.