1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[UnitTest] Add more tests for environment parsing.

This commit is contained in:
Dave Davenport 2023-03-26 21:52:50 +02:00
parent 40ecbe018e
commit e6af09a52c

View file

@ -1643,6 +1643,90 @@ START_TEST(test_prepare_default) {
ck_assert_ptr_nonnull(rofi_theme);
}
END_TEST
START_TEST(test_prepare_environment_nf) {
widget wid;
wid.name = "window";
wid.state = "";
rofi_theme_parse_string("window { width: env(QER_TEST,128); }");
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");
RofiDistance l = rofi_theme_get_distance(&wid, "width", 0);
int dist = distance_get_pixel(l, ROFI_ORIENTATION_HORIZONTAL);
ck_assert_int_eq(dist, 128);
}
END_TEST
START_TEST(test_prepare_environment_f) {
widget wid;
wid.name = "window";
wid.state = "";
setenv("QER_TEST", "64", 1);
rofi_theme_parse_string("window { width: env(QER_TEST,128); }");
unsetenv("QER_TEST");
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");
RofiDistance l = rofi_theme_get_distance(&wid, "width", 0);
int dist = distance_get_pixel(l, ROFI_ORIENTATION_HORIZONTAL);
ck_assert_int_eq(dist, 64);
}
END_TEST
START_TEST(test_prepare_environment_old_style) {
widget wid;
wid.name = "window";
wid.state = "";
setenv("QER_TEST", "64", 1);
rofi_theme_parse_string("window { width: ${QER_TEST}; }");
rofi_theme_parse_process_conditionals();
unsetenv("QER_TEST");
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");
RofiDistance l = rofi_theme_get_distance(&wid, "width", 0);
int dist = distance_get_pixel(l, ROFI_ORIENTATION_HORIZONTAL);
ck_assert_int_eq(dist, 64);
}
END_TEST
START_TEST(test_prepare_environment_media_f) {
widget wid;
wid.name = "window";
wid.state = "";
setenv("QER_TEST", "true", 1);
rofi_theme_parse_string("window { width: 32; } @media( enabled: env(QER_TEST,false)){ window {width:64; }}");
rofi_theme_parse_process_conditionals();
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");
unsetenv("QER_TEST");
RofiDistance l = rofi_theme_get_distance(&wid, "width", 0);
int dist = distance_get_pixel(l, ROFI_ORIENTATION_HORIZONTAL);
ck_assert_int_eq(dist, 64);
}
END_TEST
START_TEST(test_prepare_environment_media_nf) {
widget wid;
wid.name = "window";
wid.state = "";
rofi_theme_parse_string("window { width: 32; } @media( enabled: env(QER_TEST,false)){ window {width:64; }}");
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");
RofiDistance l = rofi_theme_get_distance(&wid, "width", 0);
int dist = distance_get_pixel(l, ROFI_ORIENTATION_HORIZONTAL);
ck_assert_int_eq(dist, 32);
}
END_TEST
START_TEST(test_prepare_path) {
char *current_dir = g_get_current_dir();
@ -1887,6 +1971,15 @@ static Suite *theme_parser_suite(void) {
tcase_add_test(tc_prepare_math, test_prepare_math_failure9);
suite_add_tcase(s, tc_prepare_math);
}
{
TCase *tc_prepare_default = tcase_create("environment");
tcase_add_test(tc_prepare_default, test_prepare_environment_nf);
tcase_add_test(tc_prepare_default, test_prepare_environment_f);
tcase_add_test(tc_prepare_default, test_prepare_environment_old_style);
tcase_add_test(tc_prepare_default, test_prepare_environment_media_f);
tcase_add_test(tc_prepare_default, test_prepare_environment_media_nf);
suite_add_tcase(s, tc_prepare_default);
}
return s;
}