Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "config.h" | ||
2 | |||
3 | #include <glib.h> | ||
4 | #include <glib/gi18n.h> | ||
5 | #include <locale.h> | ||
6 | |||
7 | #include "pp-utils.h" | ||
8 | |||
9 | static void | ||
10 | 1 | test_shift (gconstpointer data) | |
11 | { | ||
12 | 1 | const char *contents = data; | |
13 | guint i; | ||
14 | char *str; | ||
15 | char **lines; | ||
16 | |||
17 | 1 | lines = g_strsplit (contents, "\n", -1); | |
18 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (lines == NULL) |
19 | { | ||
20 | ✗ | g_warning ("Test file is empty"); | |
21 | ✗ | g_test_fail (); | |
22 | ✗ | return; | |
23 | } | ||
24 | |||
25 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | for (i = 0; lines[i] != NULL; i++) |
26 | { | ||
27 | char **items; | ||
28 | char *utf8; | ||
29 | |||
30 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
|
9 | if (*lines[i] == '#') |
31 | 1 | continue; | |
32 | |||
33 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
|
8 | if (*lines[i] == '\0') |
34 | 1 | break; | |
35 | |||
36 | 7 | items = g_strsplit (lines[i], "\t", -1); | |
37 | 7 | str = g_strdup (items[0]); | |
38 | 7 | shift_string_left (str); | |
39 | 7 | utf8 = g_locale_from_utf8 (items[0], -1, NULL, NULL, NULL); | |
40 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | if (g_strcmp0 (str, items[1]) != 0) |
41 | { | ||
42 | ✗ | g_error ("Result for '%s' doesn't match '%s' (got: '%s')", | |
43 | utf8, items[1], str); | ||
44 | g_test_fail (); | ||
45 | } | ||
46 | else | ||
47 | { | ||
48 | 7 | g_debug ("Result for '%s' matches '%s'", | |
49 | utf8, str); | ||
50 | } | ||
51 | |||
52 | 7 | g_free (str); | |
53 | 7 | g_free (utf8); | |
54 | |||
55 | 7 | g_strfreev (items); | |
56 | } | ||
57 | |||
58 | 1 | g_strfreev (lines); | |
59 | |||
60 | } | ||
61 | |||
62 | int | ||
63 | 1 | main (int argc, char **argv) | |
64 | { | ||
65 | char *locale; | ||
66 | char *contents; | ||
67 | |||
68 | /* Running in some locales will | ||
69 | * break the tests as "ΓΌ" will be transliterated to | ||
70 | * "ue" in de_DE, and 'u"' in the C locale. | ||
71 | * | ||
72 | * Work around that by forcing en_US with UTF-8 in | ||
73 | * our tests | ||
74 | * https://bugzilla.gnome.org/show_bug.cgi?id=650342 */ | ||
75 | |||
76 | 1 | locale = setlocale (LC_ALL, "en_US.UTF-8"); | |
77 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (locale == NULL) |
78 | { | ||
79 | ✗ | g_debug("Missing en_US.UTF-8 locale, ignoring test."); | |
80 | ✗ | return 0; | |
81 | } | ||
82 | |||
83 | 1 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); | |
84 | 1 | g_test_init (&argc, &argv, NULL); | |
85 | |||
86 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (g_file_get_contents (TEST_SRCDIR "/shift-test.txt", &contents, NULL, NULL) == FALSE) |
87 | { | ||
88 | ✗ | g_warning ("Failed to load '%s'", TEST_SRCDIR "/shift-test.txt"); | |
89 | ✗ | return 1; | |
90 | } | ||
91 | |||
92 | 1 | g_test_add_data_func ("/printers/shift", contents, test_shift); | |
93 | |||
94 | 1 | return g_test_run (); | |
95 | } | ||
96 |