7161e63d4a835a37e7c7d4805622c30049a77844
[profile/ivi/GUPnP.git] / tests / gtest / test-bugs.c
1 /*
2  * Copyright (C) 2013 Intel Corporation.
3  *
4  * Author: Jens Georg <jensg@openismus.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <libgupnp/gupnp.h>
27
28
29 struct _GUPnPServiceAction {
30         volatile gint ref_count;
31
32         GUPnPContext *context;
33
34         char         *name;
35
36         SoupMessage  *msg;
37         gboolean      accept_gzip;
38
39         GUPnPXMLDoc  *doc;
40         xmlNode      *node;
41
42         GString      *response_str;
43
44         guint         argument_count;
45 };
46
47 typedef struct _TestBgo696762Data {
48     GMainLoop *loop;
49     GUPnPServiceProxy *proxy;
50 } TestBgo696762Data;
51
52 static void
53 test_bgo_696762_on_browse_call (G_GNUC_UNUSED GUPnPService *service,
54                                 G_GNUC_UNUSED GUPnPServiceAction *action,
55                                 G_GNUC_UNUSED gpointer user_data)
56 {
57     xmlNode *node = action->node->children;
58     g_assert (node != NULL);
59     g_assert_cmpstr ((const char *) node->name, ==, "ObjectID");
60     node = node->next;
61
62     g_assert (node != NULL);
63     g_assert_cmpstr ((const char *) node->name, ==, "BrowseFlag");
64     node = node->next;
65
66     g_assert (node != NULL);
67     g_assert_cmpstr ((const char *) node->name, ==, "Filter");
68     node = node->next;
69
70     g_assert (node != NULL);
71     g_assert_cmpstr ((const char *) node->name, ==, "StartingIndex");
72     node = node->next;
73
74     g_assert (node != NULL);
75     g_assert_cmpstr ((const char *) node->name, ==, "RequestedCount");
76     node = node->next;
77
78     g_assert (node != NULL);
79     g_assert_cmpstr ((const char *) node->name, ==, "SortCriteria");
80     node = node->next;
81     gupnp_service_action_return (action);
82 }
83
84 static void
85 test_bgo_696762_on_browse (G_GNUC_UNUSED GUPnPServiceProxy       *proxy,
86                            G_GNUC_UNUSED GUPnPServiceProxyAction *action,
87                            gpointer                               user_data)
88 {
89     TestBgo696762Data *data = (TestBgo696762Data *) user_data;
90
91     g_main_loop_quit (data->loop);
92 }
93
94 static void
95 test_bgo_696762_on_sp_available (G_GNUC_UNUSED GUPnPControlPoint *cp,
96                                  GUPnPServiceProxy               *proxy,
97                                  gpointer                         user_data)
98 {
99     TestBgo696762Data *data = (TestBgo696762Data *) user_data;
100
101     data->proxy = g_object_ref (proxy);
102
103     g_main_loop_quit (data->loop);
104 }
105
106 static gboolean
107 test_bgo_696762_on_timeout (G_GNUC_UNUSED gpointer user_data)
108 {
109     g_assert_not_reached ();
110
111     return FALSE;
112 }
113
114 /* Test if a call on a service proxy keeps argument order */
115 static void
116 test_bgo_696762 (void)
117 {
118     GUPnPContext *context = NULL;
119     GError *error = NULL;
120     GUPnPControlPoint *cp = NULL;
121     guint timeout_id = 0;
122     GUPnPRootDevice *rd;
123     TestBgo696762Data data = { NULL, NULL };
124     GUPnPServiceInfo *info = NULL;
125
126     data.loop = g_main_loop_new (NULL, FALSE);
127
128     context = gupnp_context_new (NULL, "lo", 0, &error);
129     g_assert (context != NULL);
130     g_assert (error == NULL);
131
132     cp = gupnp_control_point_new (context,
133                                   "urn:test-gupnp-org:service:bgo696762:1");
134
135     gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
136
137     g_signal_connect (G_OBJECT (cp),
138                       "service-proxy-available",
139                       G_CALLBACK (test_bgo_696762_on_sp_available),
140                       &data);
141
142
143     rd = gupnp_root_device_new (context, "TestBgo696762.xml", DATA_PATH);
144     gupnp_root_device_set_available (rd, TRUE);
145     info = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (rd),
146                                           "urn:test-gupnp-org:service:bgo696762:1");
147     g_signal_connect (G_OBJECT (info),
148                       "action-invoked::Browse",
149                       G_CALLBACK (test_bgo_696762_on_browse_call),
150                       &data);
151
152     timeout_id = g_timeout_add_seconds (2, test_bgo_696762_on_timeout, &(data.loop));
153     g_main_loop_run (data.loop);
154     g_source_remove (timeout_id);
155     g_assert (data.proxy != NULL);
156
157     gupnp_service_proxy_begin_action (data.proxy,
158                                       "Browse",
159                                       test_bgo_696762_on_browse,
160                                       &data,
161                                       "ObjectID", G_TYPE_STRING, "0",
162                                       "BrowseFlag", G_TYPE_STRING, "BrowseDirectChildren",
163                                       "Filter", G_TYPE_STRING, "res,dc:date,res@size",
164                                       "StartingIndex", G_TYPE_UINT, 0,
165                                       "RequestedCount", G_TYPE_UINT, 0,
166                                       "SortCriteria", G_TYPE_STRING, "",
167                                       NULL);
168
169     timeout_id = g_timeout_add_seconds (2, test_bgo_696762_on_timeout, &(data.loop));
170     g_main_loop_run (data.loop);
171     g_source_remove (timeout_id);
172 }
173
174 int
175 main (int argc, char *argv[]) {
176 #if !GLIB_CHECK_VERSION(2,35,0)
177     g_type_init ();
178 #endif
179     g_test_init (&argc, &argv, NULL);
180     g_test_add_func ("/bugs/696762", test_bgo_696762);
181
182     return g_test_run ();
183 }