From d0aa102cb7510a98de4b5f59f0b24ab7effbf3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Gl=C3=A4=C3=9Fle?= Date: Mon, 6 Jul 2015 18:07:37 +0200 Subject: [PATCH] Add test for binary input string --- src/tests/helper.c | 14 ++++++++++++++ src/tests/test.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/tests/helper.c b/src/tests/helper.c index 087ba30..0efe520 100644 --- a/src/tests/helper.c +++ b/src/tests/helper.c @@ -102,6 +102,20 @@ main (int argc, char *argv[]) } break; + case 8: + /* read from stdin.. echo back the hex codes */ + { + gint c; + + g_print ("Woah, you said `"); + while ((c = fgetc (stdin)) != EOF) { + g_print ("%02x", c); + } + g_print ("', partner!\n"); + ret = 0; + } + break; + default: g_assert_not_reached (); break; diff --git a/src/tests/test.c b/src/tests/test.c index 9d8b26b..b303e75 100644 --- a/src/tests/test.c +++ b/src/tests/test.c @@ -378,12 +378,49 @@ test_spawned_job_input_string (void) { UDisksSpawnedJob *job; gchar *s; + GString *input; + input = g_string_new ("foobar"); s = g_strdup_printf (UDISKS_TEST_DIR "/udisks-test-helper 7"); - job = udisks_spawned_job_new (s, "foobar", getuid (), geteuid (), NULL, NULL); + job = udisks_spawned_job_new (s, input, getuid (), geteuid (), NULL, NULL); _g_assert_signal_received (job, "spawned-job-completed", G_CALLBACK (input_string_on_spawned_job_completed), NULL); g_object_unref (job); g_free (s); + g_string_free (input, TRUE); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static gboolean +binary_input_string_on_spawned_job_completed (UDisksSpawnedJob *job, + GError *error, + gint status, + GString *standard_output, + GString *standard_error, + gpointer user_data) +{ + g_assert_no_error (error); + g_assert_cmpstr (standard_error->str, ==, ""); + g_assert (WIFEXITED (status)); + g_assert (WEXITSTATUS (status) == 0); + g_assert_cmpstr (standard_output->str, ==, "Woah, you said `affe00affe', partner!\n"); + return FALSE; +} + +static void +test_spawned_job_binary_input_string (void) +{ + UDisksSpawnedJob *job; + gchar *s; + GString *input; + + input = g_string_new_len("\xaf\xfe\0\xaf\xfe", 5); + s = g_strdup_printf (UDISKS_TEST_DIR "/udisks-test-helper 8"); + job = udisks_spawned_job_new (s, input, getuid (), geteuid (), NULL, NULL); + _g_assert_signal_received (job, "spawned-job-completed", G_CALLBACK (binary_input_string_on_spawned_job_completed), NULL); + g_object_unref (job); + g_free (s); + g_string_free (input, TRUE); } /* ---------------------------------------------------------------------------------------------------- */ @@ -559,6 +596,7 @@ main (int argc, g_test_add_func ("/udisks/daemon/spawned_job/abnormal_termination", test_spawned_job_abnormal_termination); g_test_add_func ("/udisks/daemon/spawned_job/binary_output", test_spawned_job_binary_output); g_test_add_func ("/udisks/daemon/spawned_job/input_string", test_spawned_job_input_string); + g_test_add_func ("/udisks/daemon/spawned_job/binary_input_string", test_spawned_job_binary_input_string); g_test_add_func ("/udisks/daemon/threaded_job/successful", test_threaded_job_successful); g_test_add_func ("/udisks/daemon/threaded_job/failure", test_threaded_job_failure); g_test_add_func ("/udisks/daemon/threaded_job/cancelled_at_start", test_threaded_job_cancelled_at_start); -- 2.10.2