1/* 2 * Copyright (C) 2009 Gustavo Noronha Silva 3 * Copyright (C) 2009 Collabora Ltd. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21#include <errno.h> 22#include <unistd.h> 23#include <glib.h> 24#include <glib/gstdio.h> 25#include <gtk/gtk.h> 26#include <stdlib.h> 27#include <webkit/webkit.h> 28 29#if GTK_CHECK_VERSION(2, 14, 0) 30 31static void test_network_response_create_destroy() 32{ 33 WebKitNetworkResponse* response; 34 SoupMessage* message; 35 36 /* Test creation with URI */ 37 response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "uri", "http://debian.org/", NULL)); 38 g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); 39 message = webkit_network_response_get_message(response); 40 g_assert(!message); 41 g_object_unref(response); 42 43 /* Test creation with SoupMessage */ 44 message = soup_message_new("GET", "http://debian.org/"); 45 response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", message, NULL)); 46 g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); 47 g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2); 48 g_object_unref(response); 49 g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1); 50 g_object_unref(message); 51 52 /* Test creation with both SoupMessage and URI */ 53 message = soup_message_new("GET", "http://debian.org/"); 54 response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", message, "uri", "http://gnome.org/", NULL)); 55 g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); 56 g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2); 57 g_assert_cmpstr(webkit_network_response_get_uri(response), ==, "http://gnome.org/"); 58 g_object_unref(response); 59 g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1); 60 g_object_unref(message); 61} 62 63static void test_network_response_properties() 64{ 65 WebKitNetworkResponse* response; 66 SoupMessage* message; 67 gchar* soupURI; 68 69 /* Test URI is set correctly when creating with URI */ 70 response = webkit_network_response_new("http://debian.org/"); 71 g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); 72 g_assert_cmpstr(webkit_network_response_get_uri(response), ==, "http://debian.org/"); 73 g_object_unref(response); 74 75 /* Test URI is set correctly when creating with Message */ 76 message = soup_message_new("GET", "http://debian.org/"); 77 response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", message, NULL)); 78 g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); 79 g_object_unref(message); 80 81 message = webkit_network_response_get_message(response); 82 soupURI = soup_uri_to_string(soup_message_get_uri(message), FALSE); 83 g_assert_cmpstr(soupURI, ==, "http://debian.org/"); 84 g_free(soupURI); 85 86 g_assert_cmpstr(webkit_network_response_get_uri(response), ==, "http://debian.org/"); 87 g_object_unref(response); 88} 89 90int main(int argc, char** argv) 91{ 92 g_thread_init(NULL); 93 gtk_test_init(&argc, &argv, NULL); 94 95 g_test_bug_base("https://bugs.webkit.org/"); 96 g_test_add_func("/webkit/networkresponse/createdestroy", test_network_response_create_destroy); 97 g_test_add_func("/webkit/networkresponse/properties", test_network_response_properties); 98 return g_test_run (); 99} 100 101#else 102int main(int argc, char** argv) 103{ 104 g_critical("You will need gtk-2.14.0 to run the unit tests. Doing nothing now."); 105 return 0; 106} 107 108#endif 109