5 /* This test is just to be used with valgrind */
9 gchar **array = g_new (gchar *, 4);
10 array [0] = g_strdup ("one");
11 array [1] = g_strdup ("two");
12 array [2] = g_strdup ("three");
24 gchar *x = g_strconcat ("Hello", ", ", "world", NULL);
25 if (strcmp (x, "Hello, world") != 0)
26 return g_strdup_printf ("concat failed, got: %s", x);
31 #define sfail(k,p) if (s->str [p] != k) { g_string_free (s,TRUE); return g_strdup_printf ("Got %s, Failed at %d, expected '%c'", s, p, k);}
36 GString *s = g_string_new_len ("My stuff", 2);
40 if (strcmp (s->str, "My") != 0)
41 return RESULT("Expected only 'My' on the string");
42 g_string_free (s, TRUE);
44 s = g_string_new_len ("My\0\0Rest", 6);
46 return RESULT("Null was not copied");
47 if (strcmp (s->str+4, "Re") != 0){
48 return RESULT("Did not find the 'Re' part");
51 g_string_append (s, "lalalalalalalalalalalalalalalalalalalalalalal");
53 return RESULT("Null as not copied");
54 if (strncmp (s->str+4, "Relala", 6) != 0){
55 return g_strdup_printf("Did not copy correctly, got: %s", s->str+4);
58 g_string_free (s, TRUE);
59 s = g_string_new ("");
60 for (i = 0; i < 1024; i++){
61 g_string_append (s, "x");
63 if (strlen (s->str) != 1024){
64 return g_strdup_printf("Incorrect string size, got: %s %d", s->str, strlen (s->str));
66 g_string_free (s, TRUE);
68 s = g_string_new ("");
69 for (i = 0; i < 1024; i++){
70 g_string_append_c (s, 'x');
72 if (strlen (s->str) != 1024){
73 return g_strdup_printf("Incorrect string size, got: %s %d\n", s->str, strlen (s->str));
75 g_string_free (s, TRUE);
77 s = g_string_new ("hola");
78 g_string_sprintfa (s, "%s%d", ", bola", 5);
79 if (strcmp (s->str, "hola, bola5") != 0){
80 return g_strdup_printf("Incorrect data, got: %s\n", s->str);
82 g_string_free (s, TRUE);
84 s = g_string_new ("Hola");
85 g_string_printf (s, "Dingus");
87 /* Test that it does not release it */
88 ret = g_string_free (s, FALSE);
91 s = g_string_new_len ("H\000H", 3);
92 g_string_append_len (s, "1\0002", 3);
99 g_string_free (s, TRUE);
107 gchar **v = g_strsplit("Hello world, how are we doing today?", " ", 0);
111 return RESULT("split failed, got NULL vector");
113 for(i = 0; v[i] != NULL; i++);
115 return g_strdup_printf("split failed, expected 7 tokens, got %d\n", i);
126 gchar *a = g_strdup ("onetwothree");
127 gchar *a_target = "eerhtowteno";
128 gchar *b = g_strdup ("onetwothre");
129 gchar *b_target = "erhtowteno";
132 if (strcmp (a, a_target)) {
135 return g_strdup_printf ("strreverse failed. Expecting: '%s' and got '%s'\n", a, a_target);
139 if (strcmp (b, b_target)) {
142 return g_strdup_printf ("strreverse failed. Expecting: '%s' and got '%s'\n", b, b_target);
149 static Test string_tests [] = {
150 {"g_strfreev", test_strfreev},
151 {"g_strconcat", test_concat},
152 {"GString", test_gstring},
153 {"g_strsplit", test_split},
154 {"g_strreverse", test_strreverse},
158 DEFINE_TEST_GROUP_INIT(string_tests_init, string_tests)