| File: | _build/../testsuite/test-stylescheme.c |
| Warning: | line 92, column 4 Access of 'authors' 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) 2015 - 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 | CtkSourceStyleSchemeManager *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 **style_dirs; | |||
| 44 | ||||
| 45 | dir = g_build_filename (TOP_SRCDIR"/rootdir", "data", "styles", NULL((void*)0)); | |||
| 46 | ||||
| 47 | fixture->manager = ctk_source_style_scheme_manager_get_default (); | |||
| 48 | ||||
| 49 | if (g_file_test (dir, G_FILE_TEST_IS_DIR)) | |||
| 50 | { | |||
| 51 | style_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 | style_dirs[0] = dir; | |||
| 53 | style_dirs[1] = g_test_build_filename (G_TEST_DIST, "styles", 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_style_scheme_manager_get_search_path (fixture->manager); | |||
| 63 | style_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 | style_dirs[i] = g_strdup(current[i])g_strdup_inline (current[i]); | |||
| 67 | } | |||
| 68 | style_dirs[i] = g_test_build_filename (G_TEST_DIST, "styles", NULL((void*)0)); | |||
| 69 | } | |||
| 70 | ||||
| 71 | ctk_source_style_scheme_manager_set_search_path (fixture->manager, style_dirs); | |||
| 72 | g_strfreev (style_dirs); | |||
| 73 | } | |||
| 74 | ||||
| 75 | static void | |||
| 76 | test_fixture_teardown (TestFixture *fixture, | |||
| 77 | gconstpointer data) | |||
| 78 | { | |||
| 79 | } | |||
| 80 | ||||
| 81 | static void | |||
| 82 | compare_strv (const gchar **strv, | |||
| 83 | const gchar **expected_strv) | |||
| 84 | { | |||
| 85 | if (expected_strv
| |||
| 86 | { | |||
| 87 | guint n, i; | |||
| 88 | ||||
| 89 | n = g_strv_length ((gchar **) expected_strv); | |||
| 90 | for (i = 0; i < n; i++) | |||
| 91 | { | |||
| 92 | g_assert_cmpstr (strv[i], ==, expected_strv[i])do { const char *__s1 = (strv[i]), *__s2 = (expected_strv[i]) ; if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-stylescheme.c", 92, ((const char*) (__func__)), "strv[i]" " " "==" " " "expected_strv[i]" , __s1, "==", __s2); } while (0); | |||
| ||||
| 93 | } | |||
| 94 | } | |||
| 95 | else | |||
| 96 | { | |||
| 97 | g_assert_null (strv)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_15 = 0; if ((strv) == ((void*)0)) _g_boolean_var_15 = 1; _g_boolean_var_15 ; }), 1)) ; else g_assertion_message ("CtkSourceView", "../testsuite/test-stylescheme.c" , 97, ((const char*) (__func__)), "'" "strv" "' should be NULL" ); } while (0); | |||
| 98 | } | |||
| 99 | } | |||
| 100 | ||||
| 101 | static void | |||
| 102 | check_scheme (CtkSourceStyleScheme *scheme, | |||
| 103 | const gchar *expected_id, | |||
| 104 | const gchar *expected_name, | |||
| 105 | const gchar *expected_description, | |||
| 106 | const gchar **expected_authors, | |||
| 107 | const gchar *style_id, | |||
| 108 | const gchar *background_rgba) | |||
| 109 | { | |||
| 110 | CtkSourceStyle *style; | |||
| 111 | ||||
| 112 | g_assert_cmpstr (ctk_source_style_scheme_get_id (scheme), ==, expected_id)do { const char *__s1 = (ctk_source_style_scheme_get_id (scheme )), *__s2 = (expected_id); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-stylescheme.c" , 112, ((const char*) (__func__)), "ctk_source_style_scheme_get_id (scheme)" " " "==" " " "expected_id", __s1, "==", __s2); } while (0); | |||
| 113 | g_assert_cmpstr (ctk_source_style_scheme_get_name (scheme), ==, expected_name)do { const char *__s1 = (ctk_source_style_scheme_get_name (scheme )), *__s2 = (expected_name); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-stylescheme.c" , 113, ((const char*) (__func__)), "ctk_source_style_scheme_get_name (scheme)" " " "==" " " "expected_name", __s1, "==", __s2); } while (0); | |||
| 114 | g_assert_cmpstr (ctk_source_style_scheme_get_description (scheme), ==, expected_description)do { const char *__s1 = (ctk_source_style_scheme_get_description (scheme)), *__s2 = (expected_description); if (g_strcmp0 (__s1 , __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView" , "../testsuite/test-stylescheme.c", 114, ((const char*) (__func__ )), "ctk_source_style_scheme_get_description (scheme)" " " "==" " " "expected_description", __s1, "==", __s2); } while (0); | |||
| 115 | compare_strv ((const gchar **)ctk_source_style_scheme_get_authors (scheme), expected_authors); | |||
| 116 | ||||
| 117 | style = ctk_source_style_scheme_get_style (scheme, style_id); | |||
| 118 | g_assert_true (CTK_SOURCE_IS_STYLE (style))do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_16 = 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((style)); GType __t = ((ctk_source_style_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_16 = 1; _g_boolean_var_16; }), 1)) ; else g_assertion_message ( "CtkSourceView", "../testsuite/test-stylescheme.c", 118, ((const char*) (__func__)), "'" "CTK_SOURCE_IS_STYLE (style)" "' should be TRUE" ); } while (0); | |||
| 119 | ||||
| 120 | if (background_rgba != NULL((void*)0)) | |||
| 121 | { | |||
| 122 | gchar *background = NULL((void*)0); | |||
| 123 | ||||
| 124 | g_object_get (style, | |||
| 125 | "background", &background, | |||
| 126 | NULL((void*)0)); | |||
| 127 | ||||
| 128 | g_assert_cmpstr (background_rgba, ==, background)do { const char *__s1 = (background_rgba), *__s2 = (background ); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-stylescheme.c", 128, (( const char*) (__func__)), "background_rgba" " " "==" " " "background" , __s1, "==", __s2); } while (0); | |||
| 129 | g_free (background); | |||
| 130 | } | |||
| 131 | } | |||
| 132 | ||||
| 133 | static void | |||
| 134 | test_scheme_properties (TestFixture *fixture, | |||
| 135 | gconstpointer data) | |||
| 136 | { | |||
| 137 | CtkSourceStyleScheme *scheme; | |||
| 138 | const gchar *authors[] = { "Paolo Borelli", "John Doe", NULL((void*)0)}; | |||
| 139 | ||||
| 140 | scheme = ctk_source_style_scheme_manager_get_scheme (fixture->manager, "test"); | |||
| 141 | ||||
| 142 | check_scheme (scheme, "test", "Test", "Test color scheme", authors, "def:comment", NULL((void*)0)); | |||
| ||||
| 143 | ||||
| 144 | /* Check that net-address remapped correctly to "underlined" */ | |||
| 145 | check_scheme (scheme, "test", "Test", "Test color scheme", authors, "def:net-address", "#FFFFFF"); | |||
| 146 | } | |||
| 147 | ||||
| 148 | static void | |||
| 149 | test_named_color_alpha (TestFixture *fixture, | |||
| 150 | gconstpointer data) | |||
| 151 | { | |||
| 152 | CtkSourceStyleScheme *scheme; | |||
| 153 | CdkRGBA color1, color2; | |||
| 154 | gboolean res; | |||
| 155 | ||||
| 156 | scheme = ctk_source_style_scheme_manager_get_scheme (fixture->manager, "test"); | |||
| 157 | ||||
| 158 | /* Use these two semi private methods to compare a named color and a normal one */ | |||
| 159 | res = _ctk_source_style_scheme_get_current_line_color (scheme, &color1); | |||
| 160 | g_assert_true (res)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_17 = 0; if (res) _g_boolean_var_17 = 1; _g_boolean_var_17; }), 1 )) ; else g_assertion_message ("CtkSourceView", "../testsuite/test-stylescheme.c" , 160, ((const char*) (__func__)), "'" "res" "' should be TRUE" ); } while (0); | |||
| 161 | ||||
| 162 | res = _ctk_source_style_scheme_get_background_pattern_color (scheme, &color2); | |||
| 163 | g_assert_true (res)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_18 = 0; if (res) _g_boolean_var_18 = 1; _g_boolean_var_18; }), 1 )) ; else g_assertion_message ("CtkSourceView", "../testsuite/test-stylescheme.c" , 163, ((const char*) (__func__)), "'" "res" "' should be TRUE" ); } while (0); | |||
| 164 | ||||
| 165 | g_assert_true (cdk_rgba_equal (&color1, &color2))do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_19 = 0; if (cdk_rgba_equal (&color1, &color2)) _g_boolean_var_19 = 1; _g_boolean_var_19; }), 1)) ; else g_assertion_message ( "CtkSourceView", "../testsuite/test-stylescheme.c", 165, ((const char*) (__func__)), "'" "cdk_rgba_equal (&color1, &color2)" "' should be TRUE"); } while (0); | |||
| 166 | } | |||
| 167 | ||||
| 168 | int | |||
| 169 | main (int argc, char** argv) | |||
| 170 | { | |||
| 171 | ctk_test_init (&argc, &argv); | |||
| 172 | ||||
| 173 | g_test_add ("/StyleScheme/scheme-properties", TestFixture, NULL, test_fixture_setup, test_scheme_properties, 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 ("/StyleScheme/scheme-properties" , sizeof (TestFixture), ((void*)0), test_fixture_setup, test_scheme_properties , test_fixture_teardown); } while (0); | |||
| 174 | g_test_add ("/StyleScheme/named-colors-alpha", TestFixture, NULL, test_fixture_setup, test_named_color_alpha, 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 ("/StyleScheme/named-colors-alpha" , sizeof (TestFixture), ((void*)0), test_fixture_setup, test_named_color_alpha , test_fixture_teardown); } while (0); | |||
| 175 | ||||
| 176 | return g_test_run(); | |||
| 177 | } |