]> git.0d.be Git - empathy.git/blob - tests/empathy-parser-test.c
e1807251d946f9cca5da9fc99f2813c9634b195a
[empathy.git] / tests / empathy-parser-test.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include "test-helper.h"
6
7 #define DEBUG_FLAG EMPATHY_DEBUG_TESTS
8 #include <libempathy/empathy-debug.h>
9
10 #include <libempathy-gtk/empathy-ui-utils.h>
11
12 static void
13 test_replace_link (GString *string,
14                    const gchar *text,
15                    gssize len,
16                    gpointer user_data)
17 {
18   g_string_append_c (string, '[');
19   g_string_append_len (string, text, len);
20   g_string_append_c (string, ']');
21 }
22
23 static void
24 test_parsers (void)
25 {
26   guint i;
27   gchar *tests[] =
28     {
29       "http://foo.com", "[http://foo.com]",
30       NULL, NULL
31     };
32   EmpathyStringParser parsers[] =
33     {
34       {empathy_string_match_link, test_replace_link},
35       {NULL, NULL}
36     };
37
38   for (i = 0; tests[i] != NULL; i += 2)
39     {
40       GString *string;
41
42       string = g_string_new (NULL);
43       empathy_string_parser_substr (string, tests[i], -1, parsers);
44
45       DEBUG ("'%s' => '%s'", tests[i], string->str);
46       g_assert_cmpstr (tests[i + 1], ==, string->str);
47
48       g_string_free (string, TRUE);
49     }
50 }
51
52 int
53 main (int argc,
54     char **argv)
55 {
56   int result;
57
58   test_init (argc, argv);
59
60   g_test_add_func ("/parsers", test_parsers);
61
62   result = g_test_run ();
63   test_deinit ();
64
65   return result;
66 }