GnuCash 2.4.99
test-scm-query.c
00001 
00002 #include "config.h"
00003 #include <glib.h>
00004 #include <libguile.h>
00005 
00006 #include "engine-helpers.h"
00007 #include "gnc-module.h"
00008 #include "test-engine-stuff.h"
00009 #include "test-stuff.h"
00010 #include "Query.h"
00011 #include "TransLog.h"
00012 
00013 
00014 static void
00015 test_query (QofQuery *q)
00016 {
00017     SCM scm_q;
00018     QofQuery *q2;
00019 
00020     scm_q = gnc_query2scm (q);
00021 
00022     q2 = gnc_scm2query (scm_q);
00023 
00024     if (!qof_query_equal (q, q2))
00025     {
00026         failure ("queries don't match");
00027         scm_display (scm_q, SCM_UNDEFINED);
00028         scm_newline (SCM_UNDEFINED);
00029         scm_q = gnc_query2scm (q2);
00030         scm_display (scm_q, SCM_UNDEFINED);
00031         scm_newline (SCM_UNDEFINED);
00032         exit (1);
00033     }
00034     else
00035     {
00036         success ("queries match");
00037     }
00038 
00039     qof_query_destroy (q2);
00040 }
00041 
00042 static void
00043 run_tests (void)
00044 {
00045     QofQuery *q;
00046     int i;
00047 
00048     test_query (NULL);
00049 
00050     q = qof_query_create_for(GNC_ID_SPLIT);
00051     test_query (q);
00052     qof_query_destroy (q);
00053 
00054     for (i = 0; i < 50; i++)
00055     {
00056         q = get_random_query ();
00057         test_query (q);
00058         qof_query_destroy (q);
00059     }
00060 }
00061 
00062 static void
00063 main_helper (void *closure, int argc, char **argv)
00064 {
00065     gnc_module_system_init ();
00066     gnc_module_load("gnucash/engine", 0);
00067 
00068     xaccLogDisable ();
00069 
00070     /* scm conversion doesn't handle binary atm */
00071     kvp_exclude_type (KVP_TYPE_BINARY);
00072 
00073     run_tests ();
00074 
00075     print_test_results ();
00076 
00077     exit (get_rv ());
00078 }
00079 
00080 int
00081 main (int argc, char **argv)
00082 {
00083     g_setenv ("GNC_UNINSTALLED", "1", TRUE);
00084     scm_boot_guile (argc, argv, main_helper, NULL);
00085     return 0;
00086 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines