From ac2390c76d1966328c51a574b73ffc7bb098d062 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Wed, 26 Apr 2017 23:24:14 +0200 Subject: [PATCH] [Lexer] More tests. Fix return of double. --- include/theme.h | 2 +- source/theme.c | 4 ++-- test/theme-parser-test.c | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/include/theme.h b/include/theme.h index 7351577d..1cb7945c 100644 --- a/include/theme.h +++ b/include/theme.h @@ -344,7 +344,7 @@ int rofi_theme_get_boolean ( const widget *widget, const char *property, int * * @returns The string value of this property for this widget. */ -char *rofi_theme_get_string ( const widget *widget, const char *property, char *def ); +const char *rofi_theme_get_string ( const widget *widget, const char *property, char *def ); /** * @param widget The widget to query diff --git a/source/theme.c b/source/theme.c index 1ed0da63..95fed84c 100644 --- a/source/theme.c +++ b/source/theme.c @@ -527,7 +527,7 @@ int rofi_theme_get_boolean ( const widget *widget, const char *property, int def return def; } -char *rofi_theme_get_string ( const widget *widget, const char *property, char *def ) +const char *rofi_theme_get_string ( const widget *widget, const char *property, char *def ) { ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); Property *p = rofi_theme_find_property ( wid, P_STRING, property, FALSE ); @@ -542,7 +542,7 @@ double rofi_theme_get_double ( const widget *widget, const char *property, doubl ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); Property *p = rofi_theme_find_property ( wid, P_DOUBLE, property, FALSE ); if ( p ) { - return p->value.b; + return p->value.f; } g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property ); return def; diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index d9ce8132..4e5cafde 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -321,6 +321,13 @@ int main ( int argc, char ** argv ) TASSERT ( th.style == (HL_ITALIC|HL_UNDERLINE)); th = rofi_theme_get_highlight ( &wid, "italicu", th); TASSERT ( th.style == (HL_ITALIC|HL_UNDERLINE)); + + rofi_theme_parse_string ( "* { comb: bold #123; }"); + th = rofi_theme_get_highlight ( &wid, "comb", th); + TASSERT ( th.style == (HL_BOLD)); + TASSERT ( th.color.r == (1/15.0)); + TASSERT ( th.color.g == (2/15.0)); + TASSERT ( th.color.b == (3/15.0)); rofi_theme_free ( rofi_theme ); rofi_theme = NULL; } @@ -477,6 +484,40 @@ int main ( int argc, char ** argv ) rofi_theme_free ( rofi_theme ); rofi_theme = NULL; } + { + error = 0; + rofi_theme_parse_string ( "* { test: 10px 20px;}"); + TASSERT ( error == 0 ); + Distance d = (Distance){ 1, PW_PX, SOLID}; + Padding pi = (Padding){d,d,d,d}; + Padding p = rofi_theme_get_padding ( &wid, "test", pi); + TASSERT ( p.left.distance == 20 ); + TASSERT ( p.left.type == PW_PX ); + TASSERT ( p.right.distance == 20 ); + TASSERT ( p.right.type == PW_PX ); + TASSERT ( p.top.distance == 10 ); + TASSERT ( p.top.type == PW_PX ); + TASSERT ( p.bottom.distance == 10 ); + TASSERT ( p.bottom.type == PW_PX ); + TASSERT ( rofi_theme != NULL ); + rofi_theme_free ( rofi_theme ); + rofi_theme = NULL; + } + + { + rofi_theme = NULL; + error = 0; + rofi_theme_parse_string ( "* { font: \"blaat€\"; test: 123.432; }"); + TASSERT ( error == 0 ); + + const char *str= rofi_theme_get_string ( &wid, "font", NULL ); + TASSERT( str != NULL ); + TASSERT ( g_utf8_collate ( str, "blaat€" ) == 0 ); + + TASSERT ( rofi_theme_get_double ( &wid, "test", 0.0) == 123.432 ); + rofi_theme_free ( rofi_theme ); + rofi_theme = NULL; + } { rofi_theme = NULL; rofi_theme_parse_file ("/dev/null");