aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Brendan Taylor <whateley@gmail.com>2009-10-25 13:59:28 -0600
committerGravatar Brendan Taylor <whateley@gmail.com>2009-10-25 13:59:28 -0600
commit7ca43bde2de171f4378049dff54691542bf3b1e6 (patch)
tree27ac4ade8aae10acc47af7d5739d87cf9db70649 /tests
parent4d8df4fd7b595b3d3506d8b2c35febb9d1104bb0 (diff)
expand arguments given to "set *_handler"
Diffstat (limited to 'tests')
-rw-r--r--tests/test-command.c73
1 files changed, 71 insertions, 2 deletions
diff --git a/tests/test-command.c b/tests/test-command.c
index e37fb57..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);
@@ -267,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
@@ -285,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 */
@@ -301,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";