|
GnuCash 2.4.99
|
00001 00002 #include "config.h" 00003 #include <glib.h> 00004 #include <libguile.h> 00005 #include "guile-mappings.h" 00006 00007 #include "engine-helpers.h" 00008 #include "gnc-module.h" 00009 #include "test-engine-stuff.h" 00010 #include "test-stuff.h" 00011 #include "Query.h" 00012 #include "TransLog.h" 00013 00014 00015 static void 00016 test_query (Query *q, SCM val2str) 00017 { 00018 SCM scm_q; 00019 SCM str_q; 00020 SCM res_q; 00021 SCM args = SCM_EOL; 00022 Query *q2; 00023 char * str; 00024 gchar *str2 = NULL; 00025 00026 scm_q = gnc_query2scm (q); 00027 args = scm_cons (scm_q, SCM_EOL); 00028 str_q = scm_apply (val2str, args, SCM_EOL); 00029 00030 args = scm_cons (scm_makfrom0str ("'"), scm_cons (str_q, SCM_EOL)); 00031 str_q = scm_string_append (args); 00032 00033 scm_dynwind_begin (0); 00034 str = scm_to_locale_string (str_q); 00035 if (str) str2 = g_strdup(str); 00036 scm_dynwind_free (str); 00037 scm_dynwind_end (); 00038 if (str2) 00039 { 00040 res_q = scm_c_eval_string (str2); 00041 } 00042 else 00043 { 00044 res_q = SCM_BOOL_F; 00045 } 00046 00047 q2 = gnc_scm2query (res_q); 00048 00049 if (!qof_query_equal (q, q2)) 00050 { 00051 failure ("queries don't match"); 00052 fprintf (stderr, "%s\n\n", str2 ? str2 : "(null)"); 00053 scm_q = gnc_query2scm (q2); 00054 scm_display (scm_q, SCM_UNDEFINED); 00055 scm_newline (SCM_UNDEFINED); 00056 if (str2) g_free(str2); 00057 exit (1); 00058 } 00059 else 00060 { 00061 success ("queries match"); 00062 } 00063 if (str2) g_free(str2); 00064 if (q2) qof_query_destroy (q2); 00065 } 00066 00067 static void 00068 run_tests (void) 00069 { 00070 Query *q; 00071 SCM val2str; 00072 int i; 00073 00074 val2str = scm_c_eval_string ("gnc:value->string"); 00075 g_return_if_fail (scm_is_procedure (val2str)); 00076 00077 for (i = 0; i < 1000; i++) 00078 { 00079 q = get_random_query (); 00080 test_query (q, val2str); 00081 qof_query_destroy (q); 00082 fflush(stdout); 00083 } 00084 00085 { 00086 q = get_random_query (); 00087 test_query (q, val2str); 00088 qof_query_destroy (q); 00089 fflush(stdout); 00090 } 00091 00092 } 00093 00094 static void 00095 main_helper (void *closure, int argc, char **argv) 00096 { 00097 gnc_module_system_init (); 00098 gnc_module_load("gnucash/engine", 0); 00099 gnc_module_load("gnucash/app-utils", 0); 00100 00101 xaccLogDisable (); 00102 00103 /* scm conversion doesn't handle binary atm */ 00104 kvp_exclude_type (KVP_TYPE_BINARY); 00105 00106 /* double->string->double is not idempotent */ 00107 kvp_exclude_type (KVP_TYPE_DOUBLE); 00108 00109 /* Initialize to a known RNG position */ 00110 guid_init(); 00111 srand(1); 00112 00113 run_tests (); 00114 00115 print_test_results (); 00116 00117 exit (get_rv ()); 00118 } 00119 00120 int 00121 main (int argc, char **argv) 00122 { 00123 g_setenv ("GNC_UNINSTALLED", "1", TRUE); 00124 scm_boot_guile (argc, argv, main_helper, NULL); 00125 return 0; 00126 }
1.7.4