From 686be5856ce421edf79d147abd52954f7d0cb634 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 17 Aug 2017 19:04:01 +0200 Subject: [PATCH] Move PropertyType into rofi-types header and add check for names pairs. --- include/rofi-types.h | 37 ++++++++++++++++++++++++++++++++++++- include/theme.h | 31 ++----------------------------- source/rofi-types.c | 6 +++--- source/xrmoptions.c | 1 - subprojects/libnkutils | 2 +- test/theme-parser-test.c | 20 ++++++++++++++++++++ 6 files changed, 62 insertions(+), 35 deletions(-) diff --git a/include/rofi-types.h b/include/rofi-types.h index 4970e453..0e75c389 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -1,6 +1,41 @@ #ifndef INCLUDE_ROFI_TYPES_H #define INCLUDE_ROFI_TYPES_H -extern const char *PropertyTypeName[]; +/** + * Type of property + */ +typedef enum +{ + /** Integer */ + P_INTEGER, + /** Double */ + P_DOUBLE, + /** String */ + P_STRING, + /** Boolean */ + P_BOOLEAN, + /** Color */ + P_COLOR, + /** RofiPadding */ + P_PADDING, + /** Link to global setting */ + P_LINK, + /** Position */ + P_POSITION, + /** Highlight */ + P_HIGHLIGHT, + /** List */ + P_LIST, + /** Orientation */ + P_ORIENTATION, + /** Number of types. */ + P_NUM_TYPES, +} PropertyType; + +/** + * This array maps PropertyType to a user-readable name. + * It is important this is kept in sync. + */ +extern const char * const PropertyTypeName[P_NUM_TYPES]; #endif // INCLUDE_ROFI_TYPES_H diff --git a/include/theme.h b/include/theme.h index c0182e64..5e554b4c 100644 --- a/include/theme.h +++ b/include/theme.h @@ -31,7 +31,8 @@ #include #include #include -#include "theme.h" + +#include "rofi-types.h" /** Style of text highlight */ typedef enum @@ -95,34 +96,6 @@ typedef enum ROFI_ORIENTATION_VERTICAL, ROFI_ORIENTATION_HORIZONTAL } RofiOrientation; -/** - * Type of property - */ -typedef enum -{ - /** Integer */ - P_INTEGER, - /** Double */ - P_DOUBLE, - /** String */ - P_STRING, - /** Boolean */ - P_BOOLEAN, - /** Color */ - P_COLOR, - /** RofiPadding */ - P_PADDING, - /** Link to global setting */ - P_LINK, - /** Position */ - P_POSITION, - /** Highlight */ - P_HIGHLIGHT, - /** List */ - P_LIST, - /** Orientation */ - P_ORIENTATION, -} PropertyType; /** * Represent the color in theme. diff --git a/source/rofi-types.c b/source/rofi-types.c index d0676f40..ae42e97d 100644 --- a/source/rofi-types.c +++ b/source/rofi-types.c @@ -3,7 +3,7 @@ /** * Name of the property type */ -const char *PropertyTypeName[] = { +const char * const PropertyTypeName[P_NUM_TYPES] = { /** Integer */ "Integer", /** Double */ @@ -14,8 +14,8 @@ const char *PropertyTypeName[] = { "Boolean", /** Color */ "Color", - /** RofiPadding */ - "RofiPadding", + /** Padding */ + "Padding", /** Link to global setting */ "Reference", /** Position */ diff --git a/source/xrmoptions.c b/source/xrmoptions.c index af8fe846..1eff4246 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -391,7 +391,6 @@ void config_parse_cmd_options ( void ) static gboolean __config_parser_set_property ( XrmOption *option, const Property *p, char **error ) { - extern const char *PropertyTypeName[]; if ( option->type == xrm_String ) { if ( p->type != P_STRING && p->type != P_LIST ) { *error = g_strdup_printf ( "Option: %s needs to be set with a string not a %s.", option->name, PropertyTypeName[p->type] ); diff --git a/subprojects/libnkutils b/subprojects/libnkutils index 2c5f1b26..3467c6a4 160000 --- a/subprojects/libnkutils +++ b/subprojects/libnkutils @@ -1 +1 @@ -Subproject commit 2c5f1b2654a9b4480b857cd8395af127a6c55199 +Subproject commit 3467c6a4ee3b7a2f53dfd0e15cd72f00d782a0dd diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index b14b358a..cd9e6ca6 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -1233,6 +1233,25 @@ START_TEST ( test_prepare_path ) g_free ( current_dir ); } END_TEST + + +START_TEST(test_properties_types_names) +{ + ck_assert_str_eq ( PropertyTypeName[P_INTEGER], "Integer"); + ck_assert_str_eq ( PropertyTypeName[P_DOUBLE], "Double"); + ck_assert_str_eq ( PropertyTypeName[P_STRING], "String"); + ck_assert_str_eq ( PropertyTypeName[P_BOOLEAN], "Boolean"); + ck_assert_str_eq ( PropertyTypeName[P_COLOR], "Color"); + ck_assert_str_eq ( PropertyTypeName[P_PADDING], "Padding"); + ck_assert_str_eq ( PropertyTypeName[P_LINK], "Reference"); + ck_assert_str_eq ( PropertyTypeName[P_POSITION], "Position"); + ck_assert_str_eq ( PropertyTypeName[P_HIGHLIGHT], "Highlight"); + ck_assert_str_eq ( PropertyTypeName[P_LIST], "List"); + ck_assert_str_eq ( PropertyTypeName[P_ORIENTATION], "Orientation"); + +} +END_TEST + static Suite * theme_parser_suite (void) { Suite *s; @@ -1244,6 +1263,7 @@ static Suite * theme_parser_suite (void) { tc_core = tcase_create("Core"); tcase_add_checked_fixture(tc_core, theme_parser_setup, theme_parser_teardown); + tcase_add_test(tc_core, test_properties_types_names); tcase_add_test(tc_core, test_core_empty_string); tcase_add_test(tc_core, test_core_empty_global_section); tcase_add_test(tc_core, test_core_empty_section);