File: | _build/../testsuite/test-language.c |
Warning: | line 92, column 15 Access of 'glob' at index 3, while it holds only 3 'const char *' elements |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */ | |||
2 | /* | |||
3 | * This file is part of CtkSourceView | |||
4 | * | |||
5 | * Copyright (C) 2013 - Paolo Borelli | |||
6 | * | |||
7 | * CtkSourceView is free software; you can redistribute it and/or | |||
8 | * modify it under the terms of the GNU Lesser General Public | |||
9 | * License as published by the Free Software Foundation; either | |||
10 | * version 2.1 of the License, or (at your option) any later version. | |||
11 | * | |||
12 | * CtkSourceView is distributed in the hope that it will be useful, | |||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
15 | * Lesser General Public License for more details. | |||
16 | * | |||
17 | * You should have received a copy of the GNU Lesser General Public License | |||
18 | * along with this library; if not, see <http://www.gnu.org/licenses/>. | |||
19 | */ | |||
20 | ||||
21 | #ifdef HAVE_CONFIG_H | |||
22 | #include <config.h> | |||
23 | #endif | |||
24 | ||||
25 | #include <stdlib.h> | |||
26 | #include <ctk/ctk.h> | |||
27 | #include <ctksourceview/ctksource.h> | |||
28 | ||||
29 | typedef struct _TestFixture TestFixture; | |||
30 | ||||
31 | struct _TestFixture { | |||
32 | CtkSourceLanguageManager *manager; | |||
33 | }; | |||
34 | ||||
35 | /* If we are running from the source dir (e.g. during make check) | |||
36 | * we override the path to read from the data dir | |||
37 | */ | |||
38 | static void | |||
39 | test_fixture_setup (TestFixture *fixture, | |||
40 | gconstpointer data) | |||
41 | { | |||
42 | gchar *dir; | |||
43 | gchar **lang_dirs; | |||
44 | ||||
45 | dir = g_build_filename (TOP_SRCDIR"/rootdir", "data", "language-specs", NULL((void*)0)); | |||
46 | ||||
47 | fixture->manager = ctk_source_language_manager_get_default (); | |||
48 | ||||
49 | if (g_file_test (dir, G_FILE_TEST_IS_DIR)) | |||
50 | { | |||
51 | lang_dirs = g_new0 (gchar *, 3)(gchar * *) (__extension__ ({ gsize __n = (gsize) (3); gsize __s = sizeof (gchar *); gpointer __p; if (__s == 1) __p = g_malloc0 (__n); else if (__builtin_constant_p (__n) && (__s == 0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p = g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p ; })); | |||
52 | lang_dirs[0] = dir; | |||
53 | lang_dirs[1] = g_test_build_filename (G_TEST_DIST, "language-specs", NULL((void*)0)); | |||
54 | } | |||
55 | else | |||
56 | { | |||
57 | const gchar * const *current; | |||
58 | int i; | |||
59 | ||||
60 | g_free (dir); | |||
61 | ||||
62 | current = ctk_source_language_manager_get_search_path (fixture->manager); | |||
63 | lang_dirs = g_new0 (gchar *, g_strv_length ((gchar **)current) + 2)(gchar * *) (__extension__ ({ gsize __n = (gsize) (g_strv_length ((gchar **)current) + 2); gsize __s = sizeof (gchar *); gpointer __p; if (__s == 1) __p = g_malloc0 (__n); else if (__builtin_constant_p (__n) && (__s == 0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p = g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p; })); | |||
64 | for (i = 0; current[i] != NULL((void*)0); i++) | |||
65 | { | |||
66 | lang_dirs[i] = g_strdup(current[i])g_strdup_inline (current[i]); | |||
67 | } | |||
68 | lang_dirs[i] = g_test_build_filename (G_TEST_DIST, "language-specs", NULL((void*)0)); | |||
69 | } | |||
70 | ||||
71 | ctk_source_language_manager_set_search_path (fixture->manager, lang_dirs); | |||
72 | g_strfreev (lang_dirs); | |||
73 | } | |||
74 | ||||
75 | static void | |||
76 | test_fixture_teardown (TestFixture *fixture, | |||
77 | gconstpointer data) | |||
78 | { | |||
79 | } | |||
80 | ||||
81 | static void | |||
82 | compare_strv_unordered (const gchar **strv, | |||
83 | const gchar **expected_strv) | |||
84 | { | |||
85 | if (expected_strv
| |||
86 | { | |||
87 | guint i; | |||
88 | ||||
89 | g_assert_cmpuint (g_strv_length ((gchar **) strv), ==,do { guint64 __n1 = (g_strv_length ((gchar **) strv)), __n2 = (g_strv_length ((gchar **) expected_strv)); if (__n1 == __n2 ) ; else g_assertion_message_cmpint ("CtkSourceView", "../testsuite/test-language.c" , 90, ((const char*) (__func__)), "g_strv_length ((gchar **) strv)" " " "==" " " "g_strv_length ((gchar **) expected_strv)", __n1 , "==", __n2, 'u'); } while (0) | |||
90 | g_strv_length ((gchar **) expected_strv))do { guint64 __n1 = (g_strv_length ((gchar **) strv)), __n2 = (g_strv_length ((gchar **) expected_strv)); if (__n1 == __n2 ) ; else g_assertion_message_cmpint ("CtkSourceView", "../testsuite/test-language.c" , 90, ((const char*) (__func__)), "g_strv_length ((gchar **) strv)" " " "==" " " "g_strv_length ((gchar **) expected_strv)", __n1 , "==", __n2, 'u'); } while (0); | |||
91 | ||||
92 | for (i = 0; expected_strv[i] != NULL((void*)0); i++) | |||
| ||||
93 | { | |||
94 | g_assert_true (g_strv_contains (strv, expected_strv[i]))do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_12 = 0; if (g_strv_contains (strv, expected_strv[i])) _g_boolean_var_12 = 1; _g_boolean_var_12; }), 1)) ; else g_assertion_message ( "CtkSourceView", "../testsuite/test-language.c", 94, ((const char *) (__func__)), "'" "g_strv_contains (strv, expected_strv[i])" "' should be TRUE"); } while (0); | |||
95 | } | |||
96 | } | |||
97 | else | |||
98 | { | |||
99 | g_assert_null (strv)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_13 = 0; if ((strv) == ((void*)0)) _g_boolean_var_13 = 1; _g_boolean_var_13 ; }), 1)) ; else g_assertion_message ("CtkSourceView", "../testsuite/test-language.c" , 99, ((const char*) (__func__)), "'" "strv" "' should be NULL" ); } while (0); | |||
100 | } | |||
101 | } | |||
102 | ||||
103 | static void | |||
104 | check_language (CtkSourceLanguage *language, | |||
105 | const gchar *id, | |||
106 | const gchar *expected_name, | |||
107 | const gchar *expected_section, | |||
108 | gboolean expected_hidden, | |||
109 | const gchar *expected_extra_meta, | |||
110 | const gchar **expected_mime, | |||
111 | const gchar **expected_glob, | |||
112 | const gchar **expected_styles, | |||
113 | const gchar *style_id, | |||
114 | const gchar *expected_style_name) | |||
115 | { | |||
116 | gchar **mime; | |||
117 | gchar **glob; | |||
118 | gchar **styles; | |||
119 | ||||
120 | g_assert_cmpstr (ctk_source_language_get_id (language), ==, id)do { const char *__s1 = (ctk_source_language_get_id (language )), *__s2 = (id); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-language.c", 120, ((const char*) (__func__)), "ctk_source_language_get_id (language)" " " "==" " " "id", __s1, "==", __s2); } while (0); | |||
121 | g_assert_cmpstr (ctk_source_language_get_name (language), ==, expected_name)do { const char *__s1 = (ctk_source_language_get_name (language )), *__s2 = (expected_name); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-language.c" , 121, ((const char*) (__func__)), "ctk_source_language_get_name (language)" " " "==" " " "expected_name", __s1, "==", __s2); } while (0); | |||
122 | g_assert_cmpstr (ctk_source_language_get_section (language), ==, expected_section)do { const char *__s1 = (ctk_source_language_get_section (language )), *__s2 = (expected_section); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-language.c" , 122, ((const char*) (__func__)), "ctk_source_language_get_section (language)" " " "==" " " "expected_section", __s1, "==", __s2); } while ( 0); | |||
123 | g_assert_cmpint (ctk_source_language_get_hidden (language), ==, expected_hidden)do { gint64 __n1 = (ctk_source_language_get_hidden (language) ), __n2 = (expected_hidden); if (__n1 == __n2) ; else g_assertion_message_cmpint ("CtkSourceView", "../testsuite/test-language.c", 123, ((const char*) (__func__)), "ctk_source_language_get_hidden (language)" " " "==" " " "expected_hidden", (guint64)__n1, "==", (guint64 )__n2, 'i'); } while (0); | |||
124 | g_assert_cmpstr (ctk_source_language_get_metadata (language, "extra-meta"), ==, expected_extra_meta)do { const char *__s1 = (ctk_source_language_get_metadata (language , "extra-meta")), *__s2 = (expected_extra_meta); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView" , "../testsuite/test-language.c", 124, ((const char*) (__func__ )), "ctk_source_language_get_metadata (language, \"extra-meta\")" " " "==" " " "expected_extra_meta", __s1, "==", __s2); } while (0); | |||
125 | ||||
126 | mime = ctk_source_language_get_mime_types (language); | |||
127 | compare_strv_unordered ((const gchar **) mime, expected_mime); | |||
128 | g_strfreev (mime); | |||
129 | ||||
130 | glob = ctk_source_language_get_globs (language); | |||
131 | compare_strv_unordered ((const gchar **) glob, expected_glob); | |||
132 | g_strfreev (glob); | |||
133 | ||||
134 | styles = ctk_source_language_get_style_ids (language); | |||
135 | compare_strv_unordered ((const gchar **) styles, expected_styles); | |||
136 | g_strfreev (styles); | |||
137 | ||||
138 | if (expected_style_name != NULL((void*)0)) | |||
139 | { | |||
140 | g_assert_cmpstr (ctk_source_language_get_style_name (language, style_id), ==, expected_style_name)do { const char *__s1 = (ctk_source_language_get_style_name ( language, style_id)), *__s2 = (expected_style_name); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView" , "../testsuite/test-language.c", 140, ((const char*) (__func__ )), "ctk_source_language_get_style_name (language, style_id)" " " "==" " " "expected_style_name", __s1, "==", __s2); } while (0); | |||
141 | } | |||
142 | } | |||
143 | ||||
144 | static void | |||
145 | test_language (TestFixture *fixture, | |||
146 | gconstpointer data) | |||
147 | { | |||
148 | CtkSourceLanguage *language; | |||
149 | const gchar *mime[] = { "text/x-test", "application/x-test", NULL((void*)0)}; | |||
150 | const gchar *glob[] = { "*.test", "*.tst", NULL((void*)0)}; | |||
151 | const gchar *styles[] = { "test-full:keyword", "test-full:string", NULL((void*)0)}; | |||
152 | ||||
153 | language = ctk_source_language_manager_get_language (fixture->manager, "test-full"); | |||
154 | check_language (language, "test-full", "Test Full", "Sources", FALSE(0), "extra", mime, glob, styles, "test-full:string", "String"); | |||
| ||||
155 | ||||
156 | language = ctk_source_language_manager_get_language (fixture->manager, "test-empty"); | |||
157 | check_language (language, "test-empty", "Test Empty", "Others", TRUE(!(0)), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0)); | |||
158 | } | |||
159 | ||||
160 | int | |||
161 | main (int argc, char** argv) | |||
162 | { | |||
163 | ctk_test_init (&argc, &argv); | |||
164 | ||||
165 | g_test_add ("/Language/language-properties", TestFixture, NULL, test_fixture_setup, test_language, test_fixture_teardown)do { void (*add_vtable) (const char*, gsize, gconstpointer, void (*) (TestFixture*, gconstpointer), void (*) (TestFixture*, gconstpointer ), void (*) (TestFixture*, gconstpointer)) = (void (*) (const gchar *, gsize, gconstpointer, void (*) (TestFixture*, gconstpointer ), void (*) (TestFixture*, gconstpointer), void (*) (TestFixture *, gconstpointer))) g_test_add_vtable; add_vtable ("/Language/language-properties" , sizeof (TestFixture), ((void*)0), test_fixture_setup, test_language , test_fixture_teardown); } while (0); | |||
166 | ||||
167 | return g_test_run(); | |||
168 | } |