]> git.0d.be Git - empathy.git/blob - tests/empathy-parser-test.c
dce91c72260ee5ca28dc31f50e994509fbf211d4
[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_replace_smiley (GString *string,
25                      const gchar *text,
26                      gssize len,
27                      gpointer user_data)
28 {
29   g_string_append_c (string, '<');
30   g_string_append_len (string, text, len);
31   g_string_append_c (string, '>');
32 }
33
34 static void
35 test_parsers (void)
36 {
37   guint i;
38   gchar *tests[] =
39     {
40       "http://foo.com", "[http://foo.com]",
41       ":)http://foo.com :D", "<:)>[http://foo.com] <:D>",
42       NULL, NULL
43     };
44   EmpathyStringParser parsers[] =
45     {
46       {empathy_string_match_link, test_replace_link},
47       {empathy_string_match_smiley, test_replace_smiley},
48       {NULL, NULL}
49     };
50
51   DEBUG ("Started");
52   for (i = 0; tests[i] != NULL; i += 2)
53     {
54       GString *string;
55
56       string = g_string_new (NULL);
57       empathy_string_parser_substr (string, tests[i], -1, parsers);
58
59       DEBUG ("'%s' => '%s'", tests[i], string->str);
60       g_assert_cmpstr (tests[i + 1], ==, string->str);
61
62       g_string_free (string, TRUE);
63     }
64 }
65
66 int
67 main (int argc,
68     char **argv)
69 {
70   int result;
71
72   test_init (argc, argv);
73
74   g_test_add_func ("/parsers", test_parsers);
75
76   result = g_test_run ();
77   test_deinit ();
78
79   return result;
80 }