diff options
Diffstat (limited to 'tests/test-command.c')
-rw-r--r-- | tests/test-command.c | 80 |
1 files changed, 67 insertions, 13 deletions
diff --git a/tests/test-command.c b/tests/test-command.c index 0f0f3c1..2d91b64 100644 --- a/tests/test-command.c +++ b/tests/test-command.c @@ -25,6 +25,7 @@ #include <src/uzbl-core.h> #include <src/config.h> #include <src/type.h> +#include <src/variables.h> extern UzblCore uzbl; @@ -163,17 +164,14 @@ test_set_variable (struct EventFixture *ef, const void *data) { /* set a float */ /* we have to be careful about locales here */ - GString *cmd, *ev; + GString *cmd; cmd = g_string_new("set zoom_level = "); g_string_append_printf(cmd, "%f", 0.25); parse_cmd_line(g_string_free(cmd, FALSE), NULL); - ev = g_string_new("EVENT [" INSTANCE_NAME "] VARIABLE_SET zoom_level float "); - g_string_append_printf(ev, "%.2f\n", 0.25); - read_event(ef); - g_assert_cmpstr(g_string_free(ev, FALSE), ==, ef->event_buffer); + ASSERT_EVENT(ef, "VARIABLE_SET zoom_level float 0.25"); - g_assert_cmpfloat(0.25, ==, uzbl.behave.zoom_level); + g_assert_cmpfloat(0.25, ==, get_var_value_float("zoom_level")); /* set a constant int (nothing should happen) */ int old_major = uzbl.info.webkit_major; @@ -191,13 +189,13 @@ test_set_variable (struct EventFixture *ef, const void *data) { parse_cmd_line("set nonexistant_variable = Some Value", NULL); ASSERT_EVENT(ef, "VARIABLE_SET nonexistant_variable str 'Some Value'"); uzbl_cmdprop *c = g_hash_table_lookup(uzbl.behave.proto_var, "nonexistant_variable"); - g_assert_cmpstr("Some Value", ==, *c->ptr.s); + g_assert_cmpstr("Some Value", ==, *(c->ptr.s)); /* set a custom variable with expansion */ parse_cmd_line("set an_expanded_variable = Test @(echo expansion)@", NULL); ASSERT_EVENT(ef, "VARIABLE_SET an_expanded_variable str 'Test expansion'"); c = g_hash_table_lookup(uzbl.behave.proto_var, "an_expanded_variable"); - g_assert_cmpstr("Test expansion", ==, *c->ptr.s); + g_assert_cmpstr("Test expansion", ==, *(c->ptr.s)); } void @@ -251,15 +249,16 @@ test_scroll (void) { void test_toggle_status (void) { - g_assert(!uzbl.behave.show_status); + /* status bar is not shown (for whatever reason) */ + g_assert(!get_show_status()); /* status bar can be toggled on */ - parse_cmd_line("toggle_status", NULL); - g_assert(uzbl.behave.show_status); + parse_cmd_line("toggle show_status", NULL); + g_assert(get_show_status()); /* status bar can be toggled back off */ - parse_cmd_line("toggle_status", NULL); - g_assert(!uzbl.behave.show_status); + parse_cmd_line("toggle show_status", NULL); + g_assert(!get_show_status()); } void @@ -309,6 +308,57 @@ test_no_such_command (void) { /* if we didn't crash then we're ok! */ } +// TODO: test toggling emits an event +void +test_toggle_int (void) { + g_assert_cmpint(0, ==, uzbl.behave.forward_keys); + + parse_cmd_line("toggle forward_keys", NULL); + g_assert_cmpint(1, ==, uzbl.behave.forward_keys); + + parse_cmd_line("toggle forward_keys", NULL); + g_assert_cmpint(0, ==, uzbl.behave.forward_keys); + + // if cycle values are specified it should use those + parse_cmd_line("toggle forward_keys 1 2", NULL); + g_assert_cmpint(1, ==, uzbl.behave.forward_keys); + + parse_cmd_line("toggle forward_keys 1 2", NULL); + g_assert_cmpint(2, ==, uzbl.behave.forward_keys); + + // and wrap to the first value when it reaches the end. + parse_cmd_line("toggle forward_keys 1 2", NULL); + g_assert_cmpint(1, ==, uzbl.behave.forward_keys); +} + +void +test_toggle_string (void) { + parse_cmd_line("set useragent = something interesting", NULL); + g_assert_cmpstr("something interesting", ==, uzbl.net.useragent); + + // when something was set, it gets reset + parse_cmd_line("toggle useragent", NULL); + g_assert_cmpstr("", ==, uzbl.net.useragent); + + // if cycle values are specified it should use those + parse_cmd_line("set useragent = something interesting", NULL); + parse_cmd_line("toggle useragent 'x' 'y'", NULL); + g_assert_cmpstr("x", ==, uzbl.net.useragent); + + parse_cmd_line("toggle useragent 'x' 'y'", NULL); + g_assert_cmpstr("y", ==, uzbl.net.useragent); + + // and wrap to the first value when it reaches the end. + parse_cmd_line("toggle useragent 'x' 'y'", NULL); + g_assert_cmpstr("x", ==, uzbl.net.useragent); + + // user-defined variables can be toggled too. + parse_cmd_line("toggle new_variable 'x' 'y'", NULL); + gchar *value = get_var_value_string("new_variable"); + g_assert_cmpstr("x", ==, value); + g_free(value); +} + int main (int argc, char *argv[]) { /* set up tests */ @@ -330,6 +380,10 @@ main (int argc, char *argv[]) { g_test_add_func("/test-command/no-such-command", test_no_such_command); + g_test_add_func("/test-command/toggle-int", test_toggle_int); + // we should probably test toggle float, but meh. + g_test_add_func("/test-command/toggle-string", test_toggle_string); + /* set up uzbl */ initialize(argc, argv); |