diff options
author | Dan Winship <danw@gnome.org> | 2009-08-02 11:35:01 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2009-08-09 10:33:46 -0400 |
commit | 005bf1a75397d66028454e58e4aa1d95ac88569d (patch) | |
tree | cecf2325d39fe994e1ca1efd28c0d054849398b8 /tests/sniffing-test.c | |
parent | 280dc8568d9ebe9fb16fb13b2272169e968b3e49 (diff) | |
download | libsoup-005bf1a75397d66028454e58e4aa1d95ac88569d.tar.gz |
Add soup_message_disable_feature()
This allows you to disable specific SoupSessionFeatures for particular
messages.
Also update tests/sniffing-test to test it out.
http://bugzilla.gnome.org/show_bug.cgi?id=574773
Diffstat (limited to 'tests/sniffing-test.c')
-rw-r--r-- | tests/sniffing-test.c | 61 |
1 files changed, 52 insertions, 9 deletions
diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c index a5c95872..561d2eea 100644 --- a/tests/sniffing-test.c +++ b/tests/sniffing-test.c @@ -343,29 +343,62 @@ do_signals_test (gboolean should_content_sniff, } static void -sniffing_content_sniffed (SoupMessage *msg, char *content_type, GHashTable *params, gpointer data) +sniffing_content_sniffed (SoupMessage *msg, const char *content_type, + GHashTable *params, gpointer data) { - char *expected_type = (char*)data; + char **sniffed_type = (char **)data; - if (strcmp (content_type, expected_type)) { + *sniffed_type = g_strdup (content_type); +} + +static void +test_sniffing (const char *path, const char *expected_type) +{ + SoupURI *uri = soup_uri_new_with_base (base_uri, path); + SoupMessage *msg = soup_message_new_from_uri ("GET", uri); + GMainLoop *loop = g_main_loop_new (NULL, TRUE); + char *sniffed_type = NULL; + + debug_printf (1, "test_sniffing(\"%s\", \"%s\")\n", path, expected_type); + + g_signal_connect (msg, "content-sniffed", + G_CALLBACK (sniffing_content_sniffed), &sniffed_type); + + g_object_ref (msg); + + soup_session_queue_message (session, msg, finished, loop); + + g_main_loop_run (loop); + + if (!sniffed_type) { + debug_printf (1, " message was not sniffed!\n"); + errors++; + } else if (strcmp (sniffed_type, expected_type) != 0) { debug_printf (1, " sniffing failed! expected %s, got %s\n", - expected_type, content_type); + expected_type, sniffed_type); errors++; } + g_free (sniffed_type); + + soup_uri_free (uri); + g_object_unref (msg); + g_main_loop_unref (loop); } static void -test_sniffing (const char *path, const char *expected_type) +test_disabled (const char *path) { SoupURI *uri = soup_uri_new_with_base (base_uri, path); SoupMessage *msg = soup_message_new_from_uri ("GET", uri); GMainLoop *loop = g_main_loop_new (NULL, TRUE); + char *sniffed_type = NULL; - debug_printf (1, "test_sniffing(\"%s\", \"%s\")\n", path, expected_type); + soup_message_disable_feature (msg, SOUP_TYPE_CONTENT_SNIFFER); - g_object_connect (msg, - "signal::content_sniffed", sniffing_content_sniffed, expected_type, - NULL); + debug_printf (1, "test_disabled(\"%s\")\n", path); + + g_signal_connect (msg, "content-sniffed", + G_CALLBACK (sniffing_content_sniffed), &sniffed_type); g_object_ref (msg); @@ -373,6 +406,12 @@ test_sniffing (const char *path, const char *expected_type) g_main_loop_run (loop); + if (sniffed_type) { + debug_printf (1, " message was sniffed!\n"); + errors++; + g_free (sniffed_type); + } + soup_uri_free (uri); g_object_unref (msg); g_main_loop_unref (loop); @@ -474,6 +513,10 @@ main (int argc, char **argv) test_sniffing ("/multiple_headers/home.gif", "image/gif"); + /* Test that disabling the sniffer works correctly */ + + test_disabled ("/text_or_binary/home.gif"); + soup_uri_free (base_uri); test_cleanup (); |