|
GnuCash 2.4.99
|
00001 #include "config.h" 00002 00003 #include <stdlib.h> 00004 00005 #include "sixtp-dom-parsers.h" 00006 #include "sixtp-dom-generators.h" 00007 00008 #include "gnc-engine.h" 00009 00010 #include "test-stuff.h" 00011 #include "test-engine-stuff.h" 00012 #include "test-file-stuff.h" 00013 00014 #define GNC_V2_STRING "gnc-v2" 00015 const gchar *gnc_v2_xml_version_string = GNC_V2_STRING; 00016 00017 static void 00018 test_binary() 00019 { 00020 int i; 00021 for (i = 0; i < 20; i++) 00022 { 00023 bin_data *test_data1; 00024 void *test_data2; 00025 guint64 test_data2_len; 00026 gchar *converted; 00027 00028 test_data1 = get_random_binary_data(); 00029 00030 converted = binary_to_string(test_data1->data, test_data1->len); 00031 00032 if (!converted) 00033 { 00034 failure_args("binary_data", __FILE__, __LINE__, "binary_to_string returned NULL"); 00035 continue; 00036 } 00037 00038 if (!string_to_binary(converted, &test_data2, &test_data2_len)) 00039 { 00040 failure_args("binary_data", __FILE__, __LINE__, 00041 "string_to_binary returned FALSE with data:\n%s\n", 00042 converted); 00043 continue; 00044 } 00045 00046 if (test_data2_len != test_data1->len) 00047 { 00048 failure_args("binary_data", __FILE__, __LINE__, 00049 "lengths don't match: %" G_GINT64_FORMAT " vs %d", 00050 test_data2_len, test_data1->len); 00051 continue; 00052 } 00053 00054 { 00055 int j; 00056 guchar *d1 = test_data1->data; 00057 guchar *d2 = (guchar*)test_data2; 00058 00059 for (j = 0; j < test_data2_len; j++) 00060 { 00061 if (d1[j] != d2[j]) 00062 { 00063 failure_args("binary_data", __FILE__, __LINE__, 00064 "data doesn't match at point %d.\n%d vs %d", 00065 i, d1[j], d2[j]); 00066 continue; 00067 } 00068 } 00069 } 00070 00071 success("binary_data"); 00072 } 00073 } 00074 00075 00076 static char *test_strings[] = 00077 { 00078 "FooBar", 00079 "<Ugly crap>", 00080 "Something with a & in it", 00081 "Ugly(*!&@#$NTHOEAUTF\"ntaheu09.h,. \n\t", 00082 "\n\t\n\t", 00083 NULL 00084 }; 00085 00086 static void 00087 test_string_converters(void) 00088 { 00089 char *mark; 00090 int i; 00091 00092 for (i = 0, mark = test_strings[i]; mark; i++, mark = test_strings[i]) 00093 { 00094 xmlNodePtr test_node; 00095 gchar *backout; 00096 test_node = text_to_dom_tree("test-string", mark); 00097 00098 backout = dom_tree_to_text(test_node); 00099 00100 do_test_args( 00101 safe_strcmp(backout, mark) == 0, 00102 "string converting", __FILE__, __LINE__, "with string %s", mark); 00103 } 00104 } 00105 00106 int 00107 main(int argc, char **argv) 00108 { 00109 qof_log_init(); 00110 test_binary(); 00111 fflush(stdout); 00112 test_string_converters(); 00113 fflush(stdout); 00114 print_test_results(); 00115 exit(get_rv()); 00116 }
1.7.4