diff options
author | Robert Manea <gotmor@gmail.com> | 2009-10-25 23:09:38 +0100 |
---|---|---|
committer | Robert Manea <gotmor@gmail.com> | 2009-10-25 23:09:38 +0100 |
commit | 4f177df009acadaeadfb273c411c4d78dc46128a (patch) | |
tree | fdd08e96ea0de3228a406407e1cc51ed7b125fb6 | |
parent | ff952dd40fc7cef8e2c31f08b4a6ff56589fe999 (diff) | |
parent | 1c28354f0e6e54395f494a79b4a43285f0dfa71f (diff) |
Merge branch 'master' of git://github.com/bct/uzbl into experimental
-rw-r--r-- | callbacks.c | 26 | ||||
-rw-r--r-- | callbacks.h | 6 | ||||
-rw-r--r-- | examples/config/uzbl/config | 2 | ||||
-rw-r--r-- | tests/test-command.c | 89 | ||||
-rw-r--r-- | uzbl-core.c | 11 |
5 files changed, 94 insertions, 40 deletions
diff --git a/callbacks.c b/callbacks.c index 175f4a3..b986172 100644 --- a/callbacks.c +++ b/callbacks.c @@ -231,32 +231,6 @@ cmd_caret_browsing() { } void -cmd_cookie_handler() { - gchar **split = g_strsplit(uzbl.behave.cookie_handler, " ", 2); - /* pitfall: doesn't handle chain actions; must the sync_ action manually */ - if ((g_strcmp0(split[0], "sh") == 0) || - (g_strcmp0(split[0], "spawn") == 0)) { - g_free (uzbl.behave.cookie_handler); - uzbl.behave.cookie_handler = - g_strdup_printf("sync_%s %s", split[0], split[1]); - } - g_strfreev (split); -} - -void -cmd_scheme_handler() { - gchar **split = g_strsplit(uzbl.behave.scheme_handler, " ", 2); - /* pitfall: doesn't handle chain actions; must the sync_ action manually */ - if ((g_strcmp0(split[0], "sh") == 0) || - (g_strcmp0(split[0], "spawn") == 0)) { - g_free (uzbl.behave.scheme_handler); - uzbl.behave.scheme_handler = - g_strdup_printf("sync_%s %s", split[0], split[1]); - } - g_strfreev (split); -} - -void cmd_fifo_dir() { uzbl.behave.fifo_dir = init_fifo(uzbl.behave.fifo_dir); } diff --git a/callbacks.h b/callbacks.h index 72361ba..05dc618 100644 --- a/callbacks.h +++ b/callbacks.h @@ -16,12 +16,6 @@ void set_icon(); void -cmd_cookie_handler(); - -void -cmd_scheme_handler(); - -void move_statusbar(); void diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config index 07bf69a..d72be2c 100644 --- a/examples/config/uzbl/config +++ b/examples/config/uzbl/config @@ -28,7 +28,7 @@ set scripts_dir = $XDG_DATA_HOME/uzbl:/usr/local/share/uzbl/examples/data/uzb set download_handler = spawn @scripts_dir/download.sh set cookie_handler = talk_to_socket $XDG_CACHE_HOME/uzbl/cookie_daemon_socket -set scheme_handler = spawn @scripts_dir/scheme.py +set scheme_handler = sync_spawn @scripts_dir/scheme.py # New window handler options #set new_window = sh 'echo uri "$8" > $4' # open in same window diff --git a/tests/test-command.c b/tests/test-command.c index 239803c..9275d68 100644 --- a/tests/test-command.c +++ b/tests/test-command.c @@ -29,6 +29,33 @@ extern UzblCore uzbl; #define INSTANCE_NAME "testing" +gchar* +assert_str_beginswith(GString *expected, gchar *actual) { + gchar *actual_beginning = g_strndup(actual, expected->len); + g_assert_cmpstr(expected->str, ==, actual_beginning); + g_free(actual_beginning); + + /* return the part of the actual string that hasn't been compared yet */ + return &actual[expected->len]; +} + +/* compare the contents of uzbl.comm.sync_stdout to the standard arguments that + * should have been passed. This is meant to be called after something like "sync echo". */ +gchar* +assert_sync_beginswith_stdarg() { + GString *stdargs = g_string_new(""); + + g_string_append_printf(stdargs, "%s %d %d ", uzbl.state.config_file, getpid(), (int)uzbl.xwin); + g_string_append_printf(stdargs, "%s %s ", uzbl.comm.fifo_path, uzbl.comm.socket_path); + g_string_append_printf(stdargs, "%s %s ", uzbl.state.uri, uzbl.gui.main_title); + + gchar *rest = assert_str_beginswith(stdargs, uzbl.comm.sync_stdout); + + g_string_free(stdargs, TRUE); + + return rest; +} + #define ASSERT_EVENT(EF, STR) { read_event(ef); \ g_assert_cmpstr("EVENT [" INSTANCE_NAME "] " STR "\n", ==, ef->event_buffer); } @@ -96,8 +123,6 @@ event_fixture_setup(struct EventFixture *ef, const void* data) ef->test_sock = socks[1]; /* attach uzbl_sock to uzbl's event dispatcher. */ - uzbl.comm.socket_path = "/tmp/some-nonexistant-socket"; - GIOChannel *iochan = g_io_channel_unix_new(ef->uzbl_sock); g_io_channel_set_encoding(iochan, NULL, NULL); @@ -163,8 +188,17 @@ test_set_variable (struct EventFixture *ef, const void *data) { g_assert_cmpint(0, ==, uzbl.behave.forward_keys); /* set a float */ - parse_cmd_line("set zoom_level = 0.25", NULL); - ASSERT_EVENT(ef, "VARIABLE_SET zoom_level float 0.250000"); + /* we have to be careful about locales here */ + GString *cmd, *ev; + 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, "%f\n", 0.25); + read_event(ef); + g_assert_cmpstr(g_string_free(ev, FALSE), ==, ef->event_buffer); + g_assert_cmpfloat(0.25, ==, uzbl.behave.zoom_level); /* set a constant int (nothing should happen) */ @@ -209,6 +243,9 @@ test_print (void) { void test_scroll (void) { + uzbl.gui.scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL); + uzbl.gui.bar_v = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_v); + gtk_adjustment_set_lower(uzbl.gui.bar_v, 0); gtk_adjustment_set_upper(uzbl.gui.bar_v, 100); gtk_adjustment_set_page_size(uzbl.gui.bar_v, 5); @@ -255,6 +292,9 @@ void test_sync_sh (void) { parse_cmd_line("sync_sh 'echo Test echo.'", NULL); g_assert_cmpstr("Test echo.\n", ==, uzbl.comm.sync_stdout); + + /* clean up after ourselves */ + uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); } void @@ -273,6 +313,36 @@ test_js (void) { g_string_free(result, TRUE); } +void +test_run_handler_arg_order (void) { + run_handler("sync_spawn echo uvw xyz", "abc def"); + + assert(uzbl.comm.sync_stdout); + + /* the result should begin with the standard handler arguments */ + gchar *rest = assert_sync_beginswith_stdarg(); + + /* the rest of the result should be the arguments passed to run_handler. */ + /* the arguments in the second argument to run_handler should be placed before any + * included in the first argument to run handler. */ + g_assert_cmpstr("abc def uvw xyz\n", ==, rest); +} + +void +test_run_handler_expand (void) { + uzbl.gui.sbar.msg = "Test message"; + run_handler("sync_spawn echo @status_message", "result:"); + + assert(uzbl.comm.sync_stdout); + + /* the result should begin with the standard handler arguments */ + gchar *rest = assert_sync_beginswith_stdarg(); + + /* the rest of the result should be the arguments passed to run_handler. */ + /* the user-specified arguments to the handler should have been expanded */ + g_assert_cmpstr("result: Test message\n", ==, rest); +} + int main (int argc, char *argv[]) { /* set up tests */ @@ -289,9 +359,20 @@ main (int argc, char *argv[]) { g_test_add_func("/test-command/js", test_js); + /* the following aren't really "command" tests, but they're not worth + * splitting into a separate file yet */ + g_test_add_func("/test-command/run_handler/arg-order", test_run_handler_arg_order); + g_test_add_func("/test-command/run_handler/expand", test_run_handler_expand); + /* set up uzbl */ initialize(argc, argv); + uzbl.state.config_file = "/tmp/uzbl-config"; + uzbl.comm.fifo_path = "/tmp/some-nonexistant-fifo"; + uzbl.comm.socket_path = "/tmp/some-nonexistant-socket"; + uzbl.state.uri = "http://example.org/"; + uzbl.gui.main_title = "Example.Org"; + uzbl.state.instance_name = INSTANCE_NAME; uzbl.behave.shell_cmd = "sh -c"; diff --git a/uzbl-core.c b/uzbl-core.c index c17c792..f278a1f 100644 --- a/uzbl-core.c +++ b/uzbl-core.c @@ -103,9 +103,9 @@ const struct var_name_to_ptr_t { { "load_start_handler", PTR_V_STR(uzbl.behave.load_start_handler, 1, NULL)}, { "load_commit_handler", PTR_V_STR(uzbl.behave.load_commit_handler, 1, NULL)}, { "download_handler", PTR_V_STR(uzbl.behave.download_handler, 1, NULL)}, - { "cookie_handler", PTR_V_STR(uzbl.behave.cookie_handler, 1, cmd_cookie_handler)}, + { "cookie_handler", PTR_V_STR(uzbl.behave.cookie_handler, 1, NULL)}, { "new_window", PTR_V_STR(uzbl.behave.new_window, 1, NULL)}, - { "scheme_handler", PTR_V_STR(uzbl.behave.scheme_handler, 1, cmd_scheme_handler)}, + { "scheme_handler", PTR_V_STR(uzbl.behave.scheme_handler, 1, NULL)}, { "fifo_dir", PTR_V_STR(uzbl.behave.fifo_dir, 1, cmd_fifo_dir)}, { "socket_dir", PTR_V_STR(uzbl.behave.socket_dir, 1, cmd_socket_dir)}, { "http_debug", PTR_V_INT(uzbl.behave.http_debug, 1, cmd_http_debug)}, @@ -2058,10 +2058,15 @@ run_handler (const gchar *act, const gchar *args) { g_strfreev(chainparts); } else { - gchar **inparts = inject_handler_args(parts[0], parts[1], args); + /* expand the user-specified arguments */ + gchar* expanded = expand(parts[1], 0); + gchar **inparts = inject_handler_args(parts[0], expanded, args); + parse_command(inparts[0], inparts[1], NULL); + g_free(inparts[0]); g_free(inparts[1]); + g_free(expanded); } g_strfreev(parts); } |