2017-04-15 06:32:05 -04:00
/*
* rofi
*
* MIT / X11 License
* Copyright © 2013 - 2017 Qball Cow < qball @ gmpclient . org >
*
* Permission is hereby granted , free of charge , to any person obtaining
* a copy of this software and associated documentation files ( the
* " Software " ) , to deal in the Software without restriction , including
* without limitation the rights to use , copy , modify , merge , publish ,
* distribute , sublicense , and / or sell copies of the Software , and to
* permit persons to whom the Software is furnished to do so , subject to
* the following conditions :
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS
* OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY , FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT .
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN AN ACTION OF CONTRACT ,
* TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE .
*
*/
2017-04-04 02:56:19 -04:00
# include <assert.h>
# include <locale.h>
# include <glib.h>
# include <stdio.h>
# include <helper.h>
# include <string.h>
# include <xcb/xcb_ewmh.h>
# include "xcb-internal.h"
# include "rofi.h"
# include "settings.h"
2017-06-02 08:54:21 -04:00
# include "display.h"
2017-05-31 18:12:03 -04:00
# include "xcb.h"
2017-04-04 02:56:19 -04:00
# include "theme.h"
2017-05-15 16:46:33 -04:00
# include "css-colors.h"
2017-04-04 17:02:08 -04:00
# include "widgets/widget-internal.h"
2017-05-04 08:54:38 -04:00
# include "widgets/textbox.h"
2017-04-04 02:56:19 -04:00
2017-04-30 11:44:53 -04:00
# include <check.h>
2017-04-04 02:56:19 -04:00
int rofi_view_error_dialog ( const char * msg , G_GNUC_UNUSED int markup )
{
fputs ( msg , stderr ) ;
return TRUE ;
}
void rofi_view_get_current_monitor ( int * width , int * height )
{
if ( width ) {
2017-04-04 17:02:08 -04:00
* width = 1920 ;
2017-04-04 02:56:19 -04:00
}
if ( height ) {
2017-04-04 17:02:08 -04:00
* height = 1080 ;
2017-04-04 02:56:19 -04:00
}
}
double textbox_get_estimated_char_height ( void )
{
return 16.0 ;
}
2017-05-31 18:12:03 -04:00
2017-09-05 07:52:21 -04:00
double textbox_get_estimated_ch ( void )
{
return 8.0 ;
}
2017-05-31 18:12:03 -04:00
int monitor_active ( G_GNUC_UNUSED workarea * mon )
{
return 0 ;
}
2017-06-02 08:54:21 -04:00
void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext * context , G_GNUC_UNUSED GSpawnChildSetupFunc * child_setup , G_GNUC_UNUSED gpointer * user_data )
{
}
2017-04-30 11:44:53 -04:00
# ifndef _ck_assert_ptr_null
/* Pointer against NULL comparison macros with improved output
* compared to ck_assert ( ) . */
/* OP may only be == or != */
# define _ck_assert_ptr_null(X, OP) do { \
const void * _ck_x = ( X ) ; \
ck_assert_msg ( _ck_x OP NULL , \
" Assertion '%s' failed: %s == %#x " , \
# X" "#OP" NULL", \
# X, _ck_x); \
} while ( 0 )
2017-04-04 02:56:19 -04:00
2017-04-30 11:44:53 -04:00
# define ck_assert_ptr_null(X) _ck_assert_ptr_null(X, ==)
# define ck_assert_ptr_nonnull(X) _ck_assert_ptr_null(X, !=)
# endif
gboolean error = FALSE ;
GString * error_msg = NULL ;
void rofi_add_error_message ( GString * msg )
2017-04-04 02:56:19 -04:00
{
2017-05-10 14:54:16 -04:00
ck_assert_ptr_null ( error_msg ) ;
2017-04-30 11:44:53 -04:00
error_msg = msg ;
error = TRUE ;
}
2017-04-04 02:56:19 -04:00
2017-05-04 08:53:35 -04:00
static void theme_parser_setup ( void )
2017-04-30 11:44:53 -04:00
{
error = 0 ;
2017-04-06 03:12:03 -04:00
2017-04-30 11:44:53 -04:00
}
2017-05-04 08:53:35 -04:00
static void theme_parser_teardown ( void )
2017-04-30 11:44:53 -04:00
{
ck_assert_ptr_null ( error_msg ) ;
ck_assert_int_eq ( error , 0 ) ;
2017-04-04 02:56:19 -04:00
rofi_theme_free ( rofi_theme ) ;
rofi_theme = NULL ;
2017-04-30 11:44:53 -04:00
}
START_TEST ( test_core_empty_string )
{
rofi_theme_parse_string ( " " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_ptr_null ( rofi_theme - > widgets ) ;
ck_assert_ptr_null ( rofi_theme - > properties ) ;
ck_assert_ptr_null ( rofi_theme - > parent ) ;
ck_assert_str_eq ( rofi_theme - > name , " Root " ) ;
}
END_TEST
START_TEST ( test_core_empty_global_section )
{
rofi_theme_parse_string ( " * {} " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_ptr_null ( rofi_theme - > widgets ) ;
ck_assert_ptr_null ( rofi_theme - > properties ) ;
ck_assert_ptr_null ( rofi_theme - > parent ) ;
ck_assert_str_eq ( rofi_theme - > name , " Root " ) ;
}
END_TEST
START_TEST ( test_core_empty_section )
{
rofi_theme_parse_string ( " #test {} " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_ptr_nonnull ( rofi_theme - > widgets ) ;
ck_assert_ptr_null ( rofi_theme - > properties ) ;
ck_assert_ptr_null ( rofi_theme - > parent ) ;
ck_assert_str_eq ( rofi_theme - > name , " Root " ) ;
ck_assert_str_eq ( rofi_theme - > widgets [ 0 ] - > name , " test " ) ;
ck_assert_ptr_null ( rofi_theme - > widgets [ 0 ] - > properties ) ;
ck_assert_ptr_eq ( rofi_theme - > widgets [ 0 ] - > parent , rofi_theme ) ;
}
END_TEST
START_TEST ( test_core_error_root )
{
rofi_theme_parse_string ( " Blaat " ) ;
ck_assert_int_eq ( error , 1 ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_ptr_null ( rofi_theme - > widgets ) ;
ck_assert_ptr_null ( rofi_theme - > properties ) ;
ck_assert_ptr_null ( rofi_theme - > parent ) ;
ck_assert_str_eq ( error_msg - > str , " <big><b>Error while parsing theme:</b></big> <i>Blaat</i> \n " \
" \t Parser error: <span size= \" smaller \" style= \" italic \" >syntax error, unexpected error from file parser, expecting end of file or "Element section ('# {name} { ... }')" or "Default settings section ( '* { ... }')" or Configuration block</span> \n Location: line 1 column 1 to line 1 column 2 \n " ) ;
g_string_free ( error_msg , TRUE ) ;
error_msg = NULL ;
error = 0 ;
}
END_TEST
START_TEST ( test_core_comments )
{
2017-04-04 17:02:08 -04:00
rofi_theme_parse_string ( " // Random comments // /*test */ " ) ;
rofi_theme_parse_string ( " /* test /* aap */ */ " ) ;
rofi_theme_parse_string ( " // Random comments \n // /*test */ " ) ;
2017-04-30 11:44:53 -04:00
rofi_theme_parse_string ( " /* test \n * \n * /* aap */ */ " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_ptr_null ( rofi_theme - > widgets ) ;
ck_assert_ptr_null ( rofi_theme - > properties ) ;
ck_assert_ptr_null ( rofi_theme - > parent ) ;
ck_assert_str_eq ( rofi_theme - > name , " Root " ) ;
2017-04-04 17:02:08 -04:00
2017-06-14 10:19:17 -04:00
// Test comment on last lines
rofi_theme_parse_string ( " // c++ style " ) ;
rofi_theme_parse_string ( " /* c style " ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
2017-04-30 14:15:49 -04:00
START_TEST ( test_core_newline )
{
rofi_theme_parse_string ( " \r \n \n \r \n \n /* \r \n */ " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_ptr_null ( rofi_theme - > widgets ) ;
ck_assert_ptr_null ( rofi_theme - > properties ) ;
ck_assert_ptr_null ( rofi_theme - > parent ) ;
ck_assert_str_eq ( rofi_theme - > name , " Root " ) ;
}
END_TEST
2017-04-04 17:02:08 -04:00
2017-04-30 11:44:53 -04:00
START_TEST ( test_properties_boolean )
{
2017-04-04 17:02:08 -04:00
widget wid ;
wid . name = " blaat " ;
2017-04-04 17:26:35 -04:00
wid . state = NULL ;
2017-04-04 17:02:08 -04:00
/** Boolean property */
rofi_theme_parse_string ( " *{ test: true; test2:/* inline */false; } " ) ;
2017-04-30 11:44:53 -04:00
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_ptr_null ( rofi_theme - > widgets ) ;
ck_assert_ptr_nonnull ( rofi_theme - > properties ) ;
ck_assert_ptr_null ( rofi_theme - > parent ) ;
ck_assert_int_eq ( rofi_theme_get_boolean ( & wid , " test " , FALSE ) , TRUE ) ;
ck_assert_int_eq ( rofi_theme_get_boolean ( & wid , " test2 " , TRUE ) , FALSE ) ;
}
END_TEST
2017-04-04 17:02:08 -04:00
2017-04-30 11:44:53 -04:00
START_TEST ( test_properties_boolean_reference )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
2017-04-04 17:02:08 -04:00
rofi_theme_parse_string ( " * { test: true; test2:/* inline */false;} *{ a:@test; b:@test2;} " ) ;
2017-04-30 11:44:53 -04:00
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_int_eq ( rofi_theme_get_boolean ( & wid , " test " , FALSE ) , TRUE ) ;
ck_assert_int_eq ( rofi_theme_get_boolean ( & wid , " b " , TRUE ) , FALSE ) ;
ck_assert_int_eq ( rofi_theme_get_boolean ( & wid , " a " , FALSE ) , TRUE ) ;
ck_assert_int_eq ( rofi_theme_get_boolean ( & wid , " test2 " , TRUE ) , FALSE ) ;
}
END_TEST
2017-04-04 17:02:08 -04:00
2017-04-30 11:44:53 -04:00
START_TEST ( test_properties_distance_em )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test: 10em;} " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
2017-06-02 10:25:47 -04:00
RofiDistance d = ( RofiDistance ) { 1 , ROFI_PU_PX , ROFI_HL_SOLID } ;
2017-06-02 10:44:16 -04:00
RofiPadding pi = ( RofiPadding ) { d , d , d , d } ;
RofiPadding p = rofi_theme_get_padding ( & wid , " test " , pi ) ;
2017-04-30 11:44:53 -04:00
ck_assert_int_eq ( p . left . distance , 10 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_EM ) ;
ck_assert_int_eq ( p . left . style , ROFI_HL_SOLID ) ;
2017-04-25 17:34:48 -04:00
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_distance_em_linestyle )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { sol: 1.3em solid; dash: 1.5em dash;} " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
2017-06-02 10:25:47 -04:00
RofiDistance d = ( RofiDistance ) { 1 , ROFI_PU_PX , ROFI_HL_SOLID } ;
2017-06-02 10:44:16 -04:00
RofiPadding pi = ( RofiPadding ) { d , d , d , d } ;
RofiPadding p = rofi_theme_get_padding ( & wid , " sol " , pi ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . left . distance , 1.3 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_EM ) ;
ck_assert_int_eq ( p . left . style , ROFI_HL_SOLID ) ;
2017-04-30 11:44:53 -04:00
p = rofi_theme_get_padding ( & wid , " dash " , pi ) ;
ck_assert_double_eq ( p . left . distance , 1.5 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_EM ) ;
ck_assert_int_eq ( p . left . style , ROFI_HL_DASH ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_distance_px )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test: 10px;} " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
2017-06-02 10:25:47 -04:00
RofiDistance d = ( RofiDistance ) { 1 , ROFI_PU_EM , ROFI_HL_DASH } ;
2017-06-02 10:44:16 -04:00
RofiPadding pi = ( RofiPadding ) { d , d , d , d } ;
RofiPadding p = rofi_theme_get_padding ( & wid , " test " , pi ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . left . distance , 10.0 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_PX ) ;
ck_assert_int_eq ( p . left . style , ROFI_HL_SOLID ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_distance_px_linestyle )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { sol: 10px solid; dash: 14px dash;} " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
2017-06-02 10:25:47 -04:00
RofiDistance d = ( RofiDistance ) { 1 , ROFI_PU_EM , ROFI_HL_DASH } ;
2017-06-02 10:44:16 -04:00
RofiPadding pi = ( RofiPadding ) { d , d , d , d } ;
RofiPadding p = rofi_theme_get_padding ( & wid , " sol " , pi ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . left . distance , 10.0 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_PX ) ;
ck_assert_int_eq ( p . left . style , ROFI_HL_SOLID ) ;
2017-04-30 11:44:53 -04:00
p = rofi_theme_get_padding ( & wid , " dash " , pi ) ;
ck_assert_double_eq ( p . left . distance , 14.0 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_PX ) ;
ck_assert_int_eq ( p . left . style , ROFI_HL_DASH ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_distance_percent )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test: 10%;} " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
2017-06-02 10:25:47 -04:00
RofiDistance d = ( RofiDistance ) { 1 , ROFI_PU_EM , ROFI_HL_DASH } ;
2017-06-02 10:44:16 -04:00
RofiPadding pi = ( RofiPadding ) { d , d , d , d } ;
RofiPadding p = rofi_theme_get_padding ( & wid , " test " , pi ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . left . distance , 10.0 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_PERCENT ) ;
ck_assert_int_eq ( p . left . style , ROFI_HL_SOLID ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_distance_percent_linestyle )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { sol: 10% solid; dash: 10% dash;} " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
2017-06-02 10:25:47 -04:00
RofiDistance d = ( RofiDistance ) { 1 , ROFI_PU_EM , ROFI_HL_DASH } ;
2017-06-02 10:44:16 -04:00
RofiPadding pi = ( RofiPadding ) { d , d , d , d } ;
RofiPadding p = rofi_theme_get_padding ( & wid , " sol " , pi ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . left . distance , 10.0 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_PERCENT ) ;
ck_assert_int_eq ( p . left . style , ROFI_HL_SOLID ) ;
2017-04-30 11:44:53 -04:00
p = rofi_theme_get_padding ( & wid , " dash " , pi ) ;
ck_assert_double_eq ( p . left . distance , 10 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_PERCENT ) ;
ck_assert_int_eq ( p . left . style , ROFI_HL_DASH ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_position )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { center: center; east: east; west: west; south: south; north:north;} " ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " center " , WL_SOUTH ) , WL_CENTER ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " south " , WL_EAST ) , WL_SOUTH ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " east " , WL_WEST ) , WL_EAST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " west " , WL_NORTH ) , WL_WEST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " north " , WL_CENTER ) , WL_NORTH ) ;
rofi_theme_parse_string ( " * { southwest: southwest; southeast: southeast; northwest: northwest; northeast:northeast;} " ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " southwest " , WL_EAST ) , WL_SOUTH_WEST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " southeast " , WL_WEST ) , WL_SOUTH_EAST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " northwest " , WL_NORTH ) , WL_NORTH_WEST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " northeast " , WL_CENTER ) , WL_NORTH_EAST ) ;
2017-05-09 07:53:45 -04:00
rofi_theme_parse_string ( " * { southwest: south west; southeast: south east; northwest: north west; northeast:north east;} " ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " southwest " , WL_EAST ) , WL_SOUTH_WEST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " southeast " , WL_WEST ) , WL_SOUTH_EAST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " northwest " , WL_NORTH ) , WL_NORTH_WEST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " northeast " , WL_CENTER ) , WL_NORTH_EAST ) ;
rofi_theme_parse_string ( " * { westsouth: westsouth; eastsouth: eastsouth; westnorth: westnorth; eastnorth:eastnorth;} " ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " westsouth " , WL_EAST ) , WL_SOUTH_WEST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " eastsouth " , WL_WEST ) , WL_SOUTH_EAST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " westnorth " , WL_NORTH ) , WL_NORTH_WEST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " eastnorth " , WL_CENTER ) , WL_NORTH_EAST ) ;
rofi_theme_parse_string ( " * { westsouth: west south; eastsouth: east south; westnorth: west north; eastnorth:east north;} " ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " westsouth " , WL_EAST ) , WL_SOUTH_WEST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " eastsouth " , WL_WEST ) , WL_SOUTH_EAST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " westnorth " , WL_NORTH ) , WL_NORTH_WEST ) ;
ck_assert_int_eq ( rofi_theme_get_position ( & wid , " eastnorth " , WL_CENTER ) , WL_NORTH_EAST ) ;
rofi_theme_parse_string ( " * { westeast: west east;} " ) ;
// Should return error.
// TODO: check error message.
g_string_free ( error_msg , TRUE ) ;
error_msg = NULL ;
error = 0 ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_style )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
2017-05-21 07:34:58 -04:00
rofi_theme_parse_string ( " * { none: none; bold: bold; underline: underline; italic: italic; st: italic strikethrough;} " ) ;
2017-06-02 10:46:28 -04:00
RofiHighlightColorStyle th = { ROFI_HL_BOLD , { 0.0 , 0.0 , 0.0 , 0.0 } } ;
2017-04-30 11:44:53 -04:00
th = rofi_theme_get_highlight ( & wid , " none " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ROFI_HL_NONE ) ;
2017-04-30 11:44:53 -04:00
th = rofi_theme_get_highlight ( & wid , " underline " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ROFI_HL_UNDERLINE ) ;
2017-04-30 11:44:53 -04:00
th = rofi_theme_get_highlight ( & wid , " italic " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ROFI_HL_ITALIC ) ;
2017-04-30 11:44:53 -04:00
th = rofi_theme_get_highlight ( & wid , " bold " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ROFI_HL_BOLD ) ;
2017-05-21 07:34:58 -04:00
th = rofi_theme_get_highlight ( & wid , " st " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ROFI_HL_ITALIC | ROFI_HL_STRIKETHROUGH ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_style2 )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { boldu: bold underline ; boldi: bold italic; underlinei: underline italic; italicu: italic underline;} " ) ;
2017-06-02 10:46:28 -04:00
RofiHighlightColorStyle th = { ROFI_HL_BOLD , { 0.0 , 0.0 , 0.0 , 0.0 } } ;
2017-04-30 11:44:53 -04:00
th = rofi_theme_get_highlight ( & wid , " boldu " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ( ROFI_HL_UNDERLINE | ROFI_HL_BOLD ) ) ;
2017-04-30 11:44:53 -04:00
th = rofi_theme_get_highlight ( & wid , " boldi " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ( ROFI_HL_ITALIC | ROFI_HL_BOLD ) ) ;
2017-04-30 11:44:53 -04:00
th = rofi_theme_get_highlight ( & wid , " underlinei " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ( ROFI_HL_ITALIC | ROFI_HL_UNDERLINE ) ) ;
2017-04-30 11:44:53 -04:00
th = rofi_theme_get_highlight ( & wid , " italicu " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ( ROFI_HL_ITALIC | ROFI_HL_UNDERLINE ) ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_style_color )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { comb: bold #123; } " ) ;
2017-06-02 10:46:28 -04:00
RofiHighlightColorStyle th = { ROFI_HL_BOLD , { 0.0 , 0.0 , 0.0 , 0.0 } } ;
2017-04-30 11:44:53 -04:00
th = rofi_theme_get_highlight ( & wid , " comb " , th ) ;
2017-06-02 10:09:20 -04:00
ck_assert_int_eq ( th . style , ( ROFI_HL_BOLD | ROFI_HL_COLOR ) ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( th . color . red , ( 1 / 15.0 ) ) ;
ck_assert_double_eq ( th . color . green , ( 2 / 15.0 ) ) ;
ck_assert_double_eq ( th . color . blue , ( 3 / 15.0 ) ) ;
}
END_TEST
START_TEST ( test_properties_color_h3 )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { red: #F00; green: #0F0; blue: #00F; } " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
START_TEST ( test_properties_color_h6 )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { red: #FF0000; green: #00FF00; blue: #0000FF; } " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
2017-05-16 15:55:52 -04:00
START_TEST ( test_properties_color_h4 )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { red: #F003; green: #0F02; blue: #00F1; } " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.2 ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1 / 7.5 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1 / 15.0 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
2017-04-30 11:44:53 -04:00
START_TEST ( test_properties_color_h8 )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
2017-05-16 15:55:52 -04:00
rofi_theme_parse_string ( " * { red: #FF000033; green: #00FF0022; blue: #0000FF11; } " ) ;
2017-04-30 11:44:53 -04:00
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.2 ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1 / 7.5 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1 / 15.0 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
START_TEST ( test_properties_color_rgb )
2017-05-17 02:24:28 -04:00
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { red: rgb(100%,0%,0%); green: rgb(0%,100%,0%); blue: rgb(0%,0%,100%); } " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
START_TEST ( test_properties_color_rgba_p )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { red: rgba(100%,0%,0%,0.3); green: rgba(0%,100%,0%,0.2); blue: rgba(0%,0%,100%,0.7); } " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.3 ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.2 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.7 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
START_TEST ( test_properties_color_rgba_percent_p )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
2017-05-18 12:04:52 -04:00
rofi_theme_parse_string ( " * { red: rgba(100%,0%,0%,30%); green: rgba(0%,100%,0%,20%); blue: rgba(0% 0% 100%/70.0%); } " ) ;
2017-05-17 02:24:28 -04:00
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.3 ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.2 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.7 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
START_TEST ( test_properties_color_rgb_p )
2017-04-30 11:44:53 -04:00
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { red: rgb(255,0,0); green: rgb(0,255,0); blue: rgb(0,0,255); } " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
START_TEST ( test_properties_color_rgba )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
2017-05-18 12:04:52 -04:00
rofi_theme_parse_string ( " * { red: rgba(255,0,0,0.3); green: rgba(0,255,0,0.2); blue: rgba(0 0 255 /0.7); } " ) ;
2017-04-30 11:44:53 -04:00
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.3 ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.2 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.7 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
2017-05-10 14:54:16 -04:00
START_TEST ( test_properties_color_rgba_percent )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { red: rgba(255,0,0,30%); green: rgba(0,255,0,20%); blue: rgba(0,0,255,70.0%); } " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.3 ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.2 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.7 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
2017-04-30 11:44:53 -04:00
START_TEST ( test_properties_color_argb )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { red: argb:33FF0000; green: argb:2200FF00; blue: argb:110000FF; } " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " red " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.2 ) ;
ck_assert_double_eq ( p - > value . color . red , 1 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " green " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1 / 7.5 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 1 ) ;
ck_assert_double_eq ( p - > value . color . blue , 0 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " blue " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1 / 15.0 ) ;
ck_assert_double_eq ( p - > value . color . red , 0 ) ;
ck_assert_double_eq ( p - > value . color . green , 0 ) ;
ck_assert_double_eq ( p - > value . color . blue , 1 ) ;
}
END_TEST
2017-05-10 14:54:16 -04:00
START_TEST ( test_properties_color_hsl )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
2017-05-15 03:10:02 -04:00
rofi_theme_parse_string ( " * { test1: hsl(127,40%,66.66666%); test2: hsl(0, 100%, 50%); testa: hsl(127,40%, 66.66666%, 30%);} " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " test1 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x88 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0xcd / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0x90 / 255.0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " test2 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 1 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " testa " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.3 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x88 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0xcd / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0x90 / 255.0 , 0.004 ) ;
}
END_TEST
START_TEST ( test_properties_color_hsla )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
2017-05-21 07:34:58 -04:00
rofi_theme_parse_string ( " * { test1: hsla(127,40%,66.66666%, 40%); test2: hsla(0, 100%, 50%,55%); } " ) ;
2017-05-10 14:54:16 -04:00
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " test1 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
2017-05-21 07:34:58 -04:00
ck_assert_double_eq ( p - > value . color . alpha , 0.4 ) ;
2017-05-10 14:54:16 -04:00
ck_assert_double_eq_tol ( p - > value . color . red , 0x88 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0xcd / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0x90 / 255.0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " test2 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
2017-05-21 07:34:58 -04:00
ck_assert_double_eq ( p - > value . color . alpha , 0.55 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 1 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0 , 0.004 ) ;
}
END_TEST
START_TEST ( test_properties_color_hsl_ws )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test1: hsl(127 40% 66.66666%); test2: hsl(0 100% 50%); testa: hsl(127 40% 66.66666% / 30%);} " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " test1 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x88 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0xcd / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0x90 / 255.0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " test2 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
2017-05-10 14:54:16 -04:00
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 1 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0 , 0.004 ) ;
2017-05-21 07:34:58 -04:00
p = rofi_theme_find_property ( twid , P_COLOR , " testa " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.3 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x88 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0xcd / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0x90 / 255.0 , 0.004 ) ;
}
END_TEST
START_TEST ( test_properties_color_hsla_ws )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test1: hsla(127 40% 66.66666% / 0.3); test2: hsla(0 100% 50%/ 55%); } " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " test1 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.3 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x88 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0xcd / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0x90 / 255.0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " test2 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.55 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 1 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0 , 0.004 ) ;
2017-05-10 14:54:16 -04:00
}
END_TEST
2017-05-13 16:51:10 -04:00
START_TEST ( test_properties_color_hwb )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
2017-05-15 09:05:40 -04:00
rofi_theme_parse_string ( " * { test1: hwb(190,65%,0%); test2: hwb(265, 31%, 29%); testa: hwb(265, 31%, 29%, 40%); } " ) ;
2017-05-13 16:51:10 -04:00
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " test2 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x7a / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0x4f / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0xb5 / 255.0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " test1 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 166 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 240 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 255 / 255.0 , 0.004 ) ;
2017-05-15 09:05:40 -04:00
p = rofi_theme_find_property ( twid , P_COLOR , " testa " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.4 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x7a / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0x4f / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0xb5 / 255.0 , 0.004 ) ;
}
END_TEST
START_TEST ( test_properties_color_hwb_ws )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
2017-05-18 02:14:41 -04:00
rofi_theme_parse_string ( " * { test1: hwb(190 deg 65 %0%); test2: hwb(295 grad 31% 29%);testa: hwb(0.736 turn 31% 29% / 40%); rada: hwb(0.2 rad 30% 30%/40%); } " ) ;
2017-05-15 09:05:40 -04:00
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " test2 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x7a / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0x4f / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0xb5 / 255.0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " test1 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 166 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 240 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 255 / 255.0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " testa " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.4 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x7a / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0x4f / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0xb5 / 255.0 , 0.004 ) ;
2017-05-18 02:14:41 -04:00
p = rofi_theme_find_property ( twid , P_COLOR , " rada " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.4 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0.7 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0.376 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0.3 , 0.004 ) ;
2017-05-13 16:51:10 -04:00
}
END_TEST
2017-05-10 14:54:16 -04:00
START_TEST ( test_properties_color_cmyk )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test1: cmyk ( 41%, 0%, 100%, 0%); test2: cmyk ( 0, 1.0, 1.0, 0);} " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " test1 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x96 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 1.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0.0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " test2 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 1 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0 , 0.004 ) ;
}
END_TEST
2017-05-15 09:05:40 -04:00
START_TEST ( test_properties_color_cmyk_ws )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test1: cmyk ( 41% 0% 100% 0%); test2: cmyk ( 0 1.0 1.0 0);} " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
Property * p = rofi_theme_find_property ( twid , P_COLOR , " test1 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0x96 / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 1.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0.0 , 0.004 ) ;
p = rofi_theme_find_property ( twid , P_COLOR , " test2 " , FALSE ) ;
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 1 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0 , 0.004 ) ;
}
END_TEST
2017-05-15 16:46:33 -04:00
START_TEST ( test_properties_color_names )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
for ( unsigned int iter = 0 ; iter < num_CSSColors ; iter + + ) {
char * str = g_strdup_printf ( " * { color: %s;} " , CSSColors [ iter ] . name ) ;
rofi_theme_parse_string ( str ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
2017-09-07 14:03:21 -04:00
Property * p = rofi_theme_find_property ( twid , P_COLOR , " text-color " , FALSE ) ;
2017-05-15 16:46:33 -04:00
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 1.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , CSSColors [ iter ] . r / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , CSSColors [ iter ] . g / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , CSSColors [ iter ] . b / 255.0 , 0.004 ) ;
g_free ( str ) ;
}
2017-05-21 07:34:58 -04:00
{
rofi_theme_parse_string ( " * {color: transparent;} " ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
2017-09-07 14:03:21 -04:00
Property * p = rofi_theme_find_property ( twid , P_COLOR , " text-color " , FALSE ) ;
2017-05-21 07:34:58 -04:00
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , 0.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , 0.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , 0.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , 0.0 , 0.004 ) ;
}
2017-05-15 16:46:33 -04:00
}
END_TEST
START_TEST ( test_properties_color_names_alpha )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
for ( unsigned int iter = 0 ; iter < num_CSSColors ; iter + + ) {
char * str = g_strdup_printf ( " * { color: %s / %d %%;} " , CSSColors [ iter ] . name , iter % 101 ) ;
rofi_theme_parse_string ( str ) ;
ThemeWidget * twid = rofi_theme_find_widget ( wid . name , wid . state , FALSE ) ;
2017-09-07 14:03:21 -04:00
Property * p = rofi_theme_find_property ( twid , P_COLOR , " text-color " , FALSE ) ;
2017-05-15 16:46:33 -04:00
ck_assert_ptr_nonnull ( p ) ;
ck_assert_double_eq ( p - > value . color . alpha , ( iter % 101 ) / 100.0 ) ;
ck_assert_double_eq_tol ( p - > value . color . red , CSSColors [ iter ] . r / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . green , CSSColors [ iter ] . g / 255.0 , 0.004 ) ;
ck_assert_double_eq_tol ( p - > value . color . blue , CSSColors [ iter ] . b / 255.0 , 0.004 ) ;
g_free ( str ) ;
}
}
END_TEST
2017-04-30 11:44:53 -04:00
START_TEST ( test_properties_padding_2 )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test: 10px 20px;} " ) ;
2017-06-02 10:25:47 -04:00
RofiDistance d = ( RofiDistance ) { 1 , ROFI_PU_PX , ROFI_HL_SOLID } ;
2017-06-02 10:44:16 -04:00
RofiPadding pi = ( RofiPadding ) { d , d , d , d } ;
RofiPadding p = rofi_theme_get_padding ( & wid , " test " , pi ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . left . distance , 20 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . right . distance , 20 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . right . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . top . distance , 10 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . top . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . bottom . distance , 10 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . bottom . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_padding_3 )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test: 10px 30px 20px;} " ) ;
2017-06-02 10:25:47 -04:00
RofiDistance d = ( RofiDistance ) { 1 , ROFI_PU_PX , ROFI_HL_SOLID } ;
2017-06-02 10:44:16 -04:00
RofiPadding pi = ( RofiPadding ) { d , d , d , d } ;
RofiPadding p = rofi_theme_get_padding ( & wid , " test " , pi ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . left . distance , 30 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . right . distance , 30 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . right . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . top . distance , 10 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . top . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . bottom . distance , 20 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . bottom . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
START_TEST ( test_properties_padding_4 )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test: 10px 30px 20px 40px;} " ) ;
2017-06-02 10:25:47 -04:00
RofiDistance d = ( RofiDistance ) { 1 , ROFI_PU_PX , ROFI_HL_SOLID } ;
2017-06-02 10:44:16 -04:00
RofiPadding pi = ( RofiPadding ) { d , d , d , d } ;
RofiPadding p = rofi_theme_get_padding ( & wid , " test " , pi ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . left . distance , 40 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . left . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . right . distance , 30 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . right . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . top . distance , 10 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . top . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
ck_assert_double_eq ( p . bottom . distance , 20 ) ;
2017-06-02 10:21:05 -04:00
ck_assert_int_eq ( p . bottom . type , ROFI_PU_PX ) ;
2017-04-30 11:44:53 -04:00
}
END_TEST
2017-06-26 17:00:41 -04:00
START_TEST ( test_properties_string_escape )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { font: \" aap \" noot \" mies \" ; \n test: \" '123.432' \" ; } " ) ;
const char * str = rofi_theme_get_string ( & wid , " font " , NULL ) ;
ck_assert_ptr_nonnull ( str ) ;
ck_assert_int_eq ( g_utf8_collate ( str , " aap \" noot \" mies " ) , 0 ) ;
const char * str2 = rofi_theme_get_string ( & wid , " test " , NULL ) ;
ck_assert_ptr_nonnull ( str2 ) ;
ck_assert_int_eq ( g_utf8_collate ( str2 , " '123.432' " ) , 0 ) ;
}
END_TEST
2017-04-30 11:44:53 -04:00
START_TEST ( test_properties_string )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { font: \" blaat€ \" ; test: 123.432; } " ) ;
const char * str = rofi_theme_get_string ( & wid , " font " , NULL ) ;
ck_assert_ptr_nonnull ( str ) ;
ck_assert_int_eq ( g_utf8_collate ( str , " blaat€ " ) , 0 ) ;
}
END_TEST
START_TEST ( test_properties_double )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { test: 123.432; } " ) ;
ck_assert_double_eq ( rofi_theme_get_double ( & wid , " test " , 0.0 ) , 123.432 ) ;
}
END_TEST
START_TEST ( test_properties_integer )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { yoffset: 4; } " ) ;
ck_assert_int_eq ( rofi_theme_get_integer ( & wid , " yoffset " , 0 ) , 4 ) ;
}
END_TEST
2017-06-02 16:12:00 -04:00
START_TEST ( test_properties_orientation )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { vert: vertical; hori: horizontal; } " ) ;
ck_assert_int_eq ( rofi_theme_get_orientation ( & wid , " vert " , ROFI_ORIENTATION_HORIZONTAL ) , ROFI_ORIENTATION_VERTICAL ) ;
ck_assert_int_eq ( rofi_theme_get_orientation ( & wid , " hori " , ROFI_ORIENTATION_VERTICAL ) , ROFI_ORIENTATION_HORIZONTAL ) ;
// default propagation
ck_assert_int_eq ( rofi_theme_get_orientation ( & wid , " notfo " , ROFI_ORIENTATION_HORIZONTAL ) , ROFI_ORIENTATION_HORIZONTAL ) ;
ck_assert_int_eq ( rofi_theme_get_orientation ( & wid , " notfo " , ROFI_ORIENTATION_VERTICAL ) , ROFI_ORIENTATION_VERTICAL ) ;
}
END_TEST
START_TEST ( test_properties_orientation_case )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " * { vert: Vertical; hori: HoriZonTal;} " ) ;
ck_assert_int_eq ( rofi_theme_get_orientation ( & wid , " vert " , ROFI_ORIENTATION_HORIZONTAL ) , ROFI_ORIENTATION_VERTICAL ) ;
ck_assert_int_eq ( rofi_theme_get_orientation ( & wid , " hori " , ROFI_ORIENTATION_VERTICAL ) , ROFI_ORIENTATION_HORIZONTAL ) ;
}
END_TEST
2017-06-14 02:18:59 -04:00
START_TEST ( test_properties_list )
{
widget wid ;
wid . name = " blaat " ;
wid . state = NULL ;
rofi_theme_parse_string ( " #blaat { liste: []; list1: [ one ]; list2: [ one, two ];} " ) ;
GList * list = rofi_theme_get_list ( & wid , " liste " , NULL ) ;
ck_assert_ptr_null ( list ) ;
list = rofi_theme_get_list ( & wid , " list1 " , NULL ) ;
ck_assert_ptr_nonnull ( list ) ;
ck_assert_str_eq ( ( char * ) list - > data , " one " ) ;
g_list_free_full ( list , ( GDestroyNotify ) g_free ) ;
list = rofi_theme_get_list ( & wid , " list2 " , NULL ) ;
ck_assert_ptr_nonnull ( list ) ;
ck_assert_int_eq ( g_list_length ( list ) , 2 ) ;
ck_assert_str_eq ( ( char * ) list - > data , " one " ) ;
ck_assert_str_eq ( ( char * ) list - > next - > data , " two " ) ;
g_list_free_full ( list , ( GDestroyNotify ) g_free ) ;
list = rofi_theme_get_list ( & wid , " blaat " , " aap,noot,mies " ) ;
ck_assert_ptr_nonnull ( list ) ;
ck_assert_int_eq ( g_list_length ( list ) , 3 ) ;
ck_assert_str_eq ( ( char * ) list - > data , " aap " ) ;
ck_assert_str_eq ( ( char * ) list - > next - > data , " noot " ) ;
ck_assert_str_eq ( ( char * ) list - > next - > next - > data , " mies " ) ;
g_list_free_full ( list , ( GDestroyNotify ) g_free ) ;
}
END_TEST
2017-06-02 16:12:00 -04:00
2017-04-30 11:44:53 -04:00
START_TEST ( test_configuration )
{
rofi_theme_parse_string ( " configuration { font: \" blaat€ \" ; yoffset: 4; } " ) ;
ck_assert_int_eq ( g_utf8_collate ( config . menu_font , " blaat€ " ) , 0 ) ;
ck_assert_int_eq ( config . y_offset , 4 ) ;
}
END_TEST
START_TEST ( test_parse_file_empty )
{
rofi_theme_parse_file ( " /dev/null " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_ptr_null ( rofi_theme - > widgets ) ;
ck_assert_ptr_null ( rofi_theme - > properties ) ;
ck_assert_ptr_null ( rofi_theme - > parent ) ;
ck_assert_str_eq ( rofi_theme - > name , " Root " ) ;
}
END_TEST
START_TEST ( test_parse_file_not_existing )
{
rofi_theme_parse_file ( " /not-existing-file.rasi " ) ;
ck_assert_ptr_null ( rofi_theme ) ;
ck_assert_int_eq ( error , 1 ) ;
ck_assert_str_eq ( error_msg - > str , " Failed to open theme: <i>/not-existing-file.rasi</i> \n Error: <b>No such file or directory</b> " ) ;
g_string_free ( error_msg , TRUE ) ;
error_msg = NULL ;
error = 0 ;
}
END_TEST
START_TEST ( test_import_empty )
{
rofi_theme_parse_string ( " @import \" /dev/null \" " ) ;
ck_assert_ptr_nonnull ( rofi_theme ) ;
ck_assert_ptr_null ( rofi_theme - > widgets ) ;
ck_assert_ptr_null ( rofi_theme - > properties ) ;
ck_assert_ptr_null ( rofi_theme - > parent ) ;
ck_assert_str_eq ( rofi_theme - > name , " Root " ) ;
}
END_TEST
2017-05-11 12:23:36 -04:00
START_TEST ( test_core_properties_error )
{
rofi_theme_parse_string ( " * { test: cmky(a,e,3); } " ) ;
const char * errstr = " <big><b>Error while parsing theme:</b></big> <i> * { test: cmky(a,e,3); }</i> \n " \
" Parser error: <span size= \" smaller \" style= \" italic \" >syntax error, unexpected invalid property value</span> \n " \
2017-05-15 16:46:33 -04:00
" Location: line 1 column 11 to line 1 column 23 \n " ;
2017-05-11 12:23:36 -04:00
ck_assert_int_eq ( error , 1 ) ;
ck_assert_str_eq ( error_msg - > str , errstr ) ;
g_string_free ( error_msg , TRUE ) ;
error_msg = NULL ;
error = 0 ;
2017-05-21 07:34:58 -04:00
const char * errstr2 = " <big><b>Error while parsing theme:</b></big> <i></i> \n " \
" Parser error: <span size= \" smaller \" style= \" italic \" >Value out of range: \n " \
" Value: X = 500.00; \n " \
" Range: 0.00 <= X <= 360.00.</span> \n " \
" Location: line 0 column 15 to line 0 column 18 \n " ;
rofi_theme_parse_string ( " * { test: hsl(500, 100% 10% ); } " ) ;
ck_assert_int_eq ( error , 1 ) ;
ck_assert_str_eq ( error_msg - > str , errstr2 ) ;
g_string_free ( error_msg , TRUE ) ;
error_msg = NULL ;
error = 0 ;
2017-05-11 12:23:36 -04:00
}
END_TEST
2017-05-14 11:21:34 -04:00
START_TEST ( test_import_error )
{
2017-05-14 11:42:05 -04:00
rofi_theme_parse_string ( " @import \" /non-existing-file.rasi \" " ) ;
2017-05-14 11:21:34 -04:00
const char * errstr =
2017-05-14 11:42:05 -04:00
" Failed to open theme: <i>/non-existing-file.rasi</i> \n " \
2017-05-14 11:21:34 -04:00
" Error: <b>No such file or directory</b> " ;
ck_assert_int_eq ( error , 1 ) ;
ck_assert_str_eq ( error_msg - > str , errstr ) ;
g_string_free ( error_msg , TRUE ) ;
error_msg = NULL ;
error = 0 ;
}
END_TEST
2017-06-14 10:19:17 -04:00
START_TEST ( test_prepare_path )
{
char * current_dir = g_get_current_dir ( ) ;
ck_assert_ptr_nonnull ( current_dir ) ;
char * f = rofi_theme_parse_prepare_file ( " ../ " , NULL ) ;
ck_assert_ptr_nonnull ( f ) ;
ck_assert_int_eq ( * f , ' / ' ) ;
ck_assert_str_ne ( f , current_dir ) ;
ck_assert ( g_str_has_prefix ( current_dir , f ) = = TRUE ) ;
g_free ( f ) ;
f = rofi_theme_parse_prepare_file ( " ../ " , " /tmp/ " ) ;
ck_assert_ptr_nonnull ( f ) ;
ck_assert_str_eq ( f , " / " ) ;
g_free ( f ) ;
f = rofi_theme_parse_prepare_file ( " /tmp/test.rasi " , " /random/ " ) ;
ck_assert_ptr_nonnull ( f ) ;
ck_assert_str_eq ( f , " /tmp/test.rasi " ) ;
g_free ( f ) ;
g_free ( current_dir ) ;
}
END_TEST
2017-08-17 13:04:01 -04:00
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
2017-05-04 08:53:35 -04:00
static Suite * theme_parser_suite ( void )
2017-04-30 11:44:53 -04:00
{
Suite * s ;
TCase * tc_core ;
s = suite_create ( " Theme " ) ;
/* Core test case */
2017-04-26 01:46:01 -04:00
{
2017-04-30 11:44:53 -04:00
tc_core = tcase_create ( " Core " ) ;
tcase_add_checked_fixture ( tc_core , theme_parser_setup , theme_parser_teardown ) ;
2017-08-17 13:04:01 -04:00
tcase_add_test ( tc_core , test_properties_types_names ) ;
2017-04-30 11:44:53 -04:00
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 ) ;
tcase_add_test ( tc_core , test_core_error_root ) ;
tcase_add_test ( tc_core , test_core_comments ) ;
2017-04-30 14:15:49 -04:00
tcase_add_test ( tc_core , test_core_newline ) ;
2017-05-11 12:23:36 -04:00
tcase_add_test ( tc_core , test_core_properties_error ) ;
2017-04-30 11:44:53 -04:00
suite_add_tcase ( s , tc_core ) ;
2017-04-26 12:43:49 -04:00
}
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_bool = tcase_create ( " PropertiesBoolean " ) ;
tcase_add_checked_fixture ( tc_prop_bool , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_bool , test_properties_boolean ) ;
tcase_add_test ( tc_prop_bool , test_properties_boolean_reference ) ;
suite_add_tcase ( s , tc_prop_bool ) ;
2017-04-26 12:43:49 -04:00
}
2017-04-26 16:45:14 -04:00
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_distance = tcase_create ( " PropertiesDistance " ) ;
tcase_add_checked_fixture ( tc_prop_distance , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_distance , test_properties_distance_em ) ;
tcase_add_test ( tc_prop_distance , test_properties_distance_px ) ;
tcase_add_test ( tc_prop_distance , test_properties_distance_percent ) ;
tcase_add_test ( tc_prop_distance , test_properties_distance_em_linestyle ) ;
tcase_add_test ( tc_prop_distance , test_properties_distance_px_linestyle ) ;
tcase_add_test ( tc_prop_distance , test_properties_distance_percent_linestyle ) ;
suite_add_tcase ( s , tc_prop_distance ) ;
2017-04-26 16:45:14 -04:00
}
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_position = tcase_create ( " PropertiesPosition " ) ;
tcase_add_checked_fixture ( tc_prop_position , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_position , test_properties_position ) ;
suite_add_tcase ( s , tc_prop_position ) ;
2017-04-26 16:45:14 -04:00
}
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_style = tcase_create ( " PropertiesStyle " ) ;
tcase_add_checked_fixture ( tc_prop_style , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_style , test_properties_style ) ;
tcase_add_test ( tc_prop_style , test_properties_style2 ) ;
tcase_add_test ( tc_prop_style , test_properties_style_color ) ;
suite_add_tcase ( s , tc_prop_style ) ;
2017-04-26 16:45:14 -04:00
}
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_color = tcase_create ( " PropertiesColor " ) ;
tcase_add_checked_fixture ( tc_prop_color , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_color , test_properties_color_h3 ) ;
2017-05-16 15:55:52 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_h4 ) ;
2017-04-30 11:44:53 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_h6 ) ;
tcase_add_test ( tc_prop_color , test_properties_color_h8 ) ;
tcase_add_test ( tc_prop_color , test_properties_color_rgb ) ;
tcase_add_test ( tc_prop_color , test_properties_color_rgba ) ;
2017-05-10 14:54:16 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_rgba_percent ) ;
2017-05-17 02:24:28 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_rgb_p ) ;
tcase_add_test ( tc_prop_color , test_properties_color_rgba_p ) ;
tcase_add_test ( tc_prop_color , test_properties_color_rgba_percent_p ) ;
2017-04-30 11:44:53 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_argb ) ;
2017-05-10 14:54:16 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_hsl ) ;
2017-05-15 03:10:02 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_hsla ) ;
2017-05-21 07:34:58 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_hsl_ws ) ;
tcase_add_test ( tc_prop_color , test_properties_color_hsla_ws ) ;
2017-05-13 16:51:10 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_hwb ) ;
2017-05-15 09:05:40 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_hwb_ws ) ;
2017-05-10 14:54:16 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_cmyk ) ;
2017-05-15 09:05:40 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_cmyk_ws ) ;
2017-05-15 16:46:33 -04:00
tcase_add_test ( tc_prop_color , test_properties_color_names ) ;
tcase_add_test ( tc_prop_color , test_properties_color_names_alpha ) ;
2017-04-30 11:44:53 -04:00
suite_add_tcase ( s , tc_prop_color ) ;
2017-04-26 16:45:14 -04:00
}
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_padding = tcase_create ( " PropertiesPadding " ) ;
tcase_add_checked_fixture ( tc_prop_padding , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_padding , test_properties_padding_2 ) ;
tcase_add_test ( tc_prop_padding , test_properties_padding_3 ) ;
tcase_add_test ( tc_prop_padding , test_properties_padding_4 ) ;
suite_add_tcase ( s , tc_prop_padding ) ;
2017-04-26 16:45:14 -04:00
}
2017-04-26 17:24:14 -04:00
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_string = tcase_create ( " PropertiesString " ) ;
tcase_add_checked_fixture ( tc_prop_string , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_string , test_properties_string ) ;
2017-06-26 17:00:41 -04:00
tcase_add_test ( tc_prop_string , test_properties_string_escape ) ;
2017-04-30 11:44:53 -04:00
suite_add_tcase ( s , tc_prop_string ) ;
2017-04-26 17:24:14 -04:00
}
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_double = tcase_create ( " PropertiesDouble " ) ;
tcase_add_checked_fixture ( tc_prop_double , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_double , test_properties_double ) ;
suite_add_tcase ( s , tc_prop_double ) ;
2017-04-26 17:24:14 -04:00
}
2017-04-26 17:47:58 -04:00
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_integer = tcase_create ( " PropertiesInteger " ) ;
tcase_add_checked_fixture ( tc_prop_integer , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_integer , test_properties_integer ) ;
suite_add_tcase ( s , tc_prop_integer ) ;
2017-04-26 17:47:58 -04:00
}
2017-06-02 16:12:00 -04:00
{
TCase * tc_prop_orientation = tcase_create ( " Propertiesorientation " ) ;
tcase_add_checked_fixture ( tc_prop_orientation , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_orientation , test_properties_orientation ) ;
tcase_add_test ( tc_prop_orientation , test_properties_orientation_case ) ;
suite_add_tcase ( s , tc_prop_orientation ) ;
}
2017-06-14 02:18:59 -04:00
{
TCase * tc_prop_list = tcase_create ( " Propertieslist " ) ;
tcase_add_checked_fixture ( tc_prop_list , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_list , test_properties_list ) ;
suite_add_tcase ( s , tc_prop_list ) ;
}
2017-04-25 17:34:48 -04:00
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_configuration = tcase_create ( " Configuration " ) ;
tcase_add_checked_fixture ( tc_prop_configuration , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_configuration , test_configuration ) ;
suite_add_tcase ( s , tc_prop_configuration ) ;
2017-04-25 17:34:48 -04:00
}
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_parse_file = tcase_create ( " ParseFile " ) ;
tcase_add_checked_fixture ( tc_prop_parse_file , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_parse_file , test_parse_file_empty ) ;
tcase_add_test ( tc_prop_parse_file , test_parse_file_not_existing ) ;
suite_add_tcase ( s , tc_prop_parse_file ) ;
2017-04-25 17:34:48 -04:00
}
{
2017-04-30 11:44:53 -04:00
TCase * tc_prop_import = tcase_create ( " Import " ) ;
tcase_add_checked_fixture ( tc_prop_import , theme_parser_setup , theme_parser_teardown ) ;
tcase_add_test ( tc_prop_import , test_import_empty ) ;
2017-05-14 11:21:34 -04:00
tcase_add_test ( tc_prop_import , test_import_error ) ;
2017-04-30 11:44:53 -04:00
suite_add_tcase ( s , tc_prop_import ) ;
}
2017-06-14 10:19:17 -04:00
{
TCase * tc_prepare_path = tcase_create ( " prepare_path " ) ;
tcase_add_test ( tc_prepare_path , test_prepare_path ) ;
suite_add_tcase ( s , tc_prepare_path ) ;
}
2017-04-30 11:44:53 -04:00
return s ;
}
2017-04-25 17:34:48 -04:00
2017-04-30 11:44:53 -04:00
int main ( int argc , char * * argv )
{
cmd_set_arguments ( argc , argv ) ;
2017-04-25 17:34:48 -04:00
2017-05-30 07:30:01 -04:00
if ( setlocale ( LC_ALL , " C " ) = = NULL ) {
2017-04-30 11:44:53 -04:00
fprintf ( stderr , " Failed to set locale. \n " ) ;
return EXIT_FAILURE ;
2017-04-25 17:34:48 -04:00
}
2017-04-30 11:44:53 -04:00
2017-05-10 14:54:16 -04:00
2017-04-30 11:44:53 -04:00
Suite * s ;
SRunner * sr ;
s = theme_parser_suite ( ) ;
sr = srunner_create ( s ) ;
srunner_run_all ( sr , CK_NORMAL ) ;
int number_failed = srunner_ntests_failed ( sr ) ;
srunner_free ( sr ) ;
return ( number_failed = = 0 ) ? EXIT_SUCCESS : EXIT_FAILURE ;
2017-04-04 02:56:19 -04:00
}