GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-string-converters.c
1 #include "config.h"
2 
3 #include <stdlib.h>
4 
5 #include "sixtp-dom-parsers.h"
6 #include "sixtp-dom-generators.h"
7 
8 #include "gnc-engine.h"
9 
10 #include "test-stuff.h"
11 #include "test-engine-stuff.h"
12 #include "test-file-stuff.h"
13 
14 #define GNC_V2_STRING "gnc-v2"
15 const gchar *gnc_v2_xml_version_string = GNC_V2_STRING;
16 
17 static char *test_strings[] =
18 {
19  "FooBar",
20  "<Ugly crap>",
21  "Something with a & in it",
22  "Ugly(*!&@#$NTHOEAUTF\"ntaheu09.h,. \n\t",
23  "\n\t\n\t",
24  NULL
25 };
26 
27 static void
28 test_string_converters(void)
29 {
30  char *mark;
31  int i;
32 
33  for (i = 0, mark = test_strings[i]; mark; i++, mark = test_strings[i])
34  {
35  xmlNodePtr test_node;
36  gchar *backout;
37  test_node = text_to_dom_tree("test-string", mark);
38 
39  backout = dom_tree_to_text(test_node);
40 
41  do_test_args(
42  g_strcmp0(backout, mark) == 0,
43  "string converting", __FILE__, __LINE__, "with string %s", mark);
44  }
45 }
46 
47 static void
48 test_bad_string (void)
49 {
50  gchar *badstr = "foo\abar";
51  gchar *sanitized = "foo?bar";
52  gchar *backout;
53  xmlNodePtr test_node = text_to_dom_tree ("test-string", badstr);
54 
55  backout = dom_tree_to_text (test_node);
56  do_test_args (g_strcmp0 (backout, sanitized) == 0,
57  "string sanitizing", __FILE__, __LINE__,
58  "with string %s", badstr);
59 }
60 
61 int
62 main(int argc, char **argv)
63 {
64  qof_log_init();
65  fflush(stdout);
66  test_string_converters();
67  test_bad_string ();
68  fflush(stdout);
69  print_test_results();
70  exit(get_rv());
71 }
void qof_log_init(void)
All type declarations for the whole Gnucash engine.