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