diff options
author | Rob Staudinger <robsta@linux.intel.com> | 2011-10-12 11:08:20 +0200 |
---|---|---|
committer | Rob Staudinger <robsta@linux.intel.com> | 2011-10-12 11:08:20 +0200 |
commit | f83891afa03af2e77b2bbd8ec08865bde9158274 (patch) | |
tree | 9ef4ff3b83e8f500cdd5760cf29d61fdef3808f9 | |
parent | e5f10568cef6adc2f0357f20305c36eedee18ee4 (diff) |
message-send.c: Port to new low-level API.
Used MetadataService before, which is no longer.
Tags: testmessage-send.c: Port to new low-level API.
Used MetadataService before, which is no longer.
Tags: tests
-rw-r--r-- | tests/Makefile.am | 5 | ||||
-rw-r--r-- | tests/local-connection.c | 1 | ||||
-rw-r--r-- | tests/message-send.c | 48 | ||||
-rw-r--r-- | tests/metadata-service.c | 102 |
4 files changed, 30 insertions, 126 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 226a5fa..4bf77e5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ -TESTS = message status metadata-service local-connection message-send status-set +TESTS = message status local-connection message-send status-set AM_CPPFLAGS = \ -I$(top_srcdir) \ @@ -19,9 +19,6 @@ message_LDADD = $(YTS_LIBS) status_SOURCES = status.c status_LDADD = $(YTS_LIBS) -metadata_service_SOURCES = metadata-service.c -metadata_service_LDADD = $(YTS_LIBS) - local_connection_SOURCES = local-connection.c local_connection_LDADD = $(YTS_LIBS) diff --git a/tests/local-connection.c b/tests/local-connection.c index d1763dc..73699d5 100644 --- a/tests/local-connection.c +++ b/tests/local-connection.c @@ -19,6 +19,7 @@ */ #include <ytstenut/ytstenut.h> +#include "ytstenut/yts-message.h" #define TEST_LENGTH 5 diff --git a/tests/message-send.c b/tests/message-send.c index 51cefea..0f1fc16 100644 --- a/tests/message-send.c +++ b/tests/message-send.c @@ -20,6 +20,7 @@ #include <string.h> #include <ytstenut/ytstenut.h> +#include "ytstenut/yts-message.h" #define TEST_LENGTH 10 @@ -49,31 +50,43 @@ authenticated_cb (YtsClient *client, gpointer data) } static void -message_cb (YtsClient *client, YtsMessage *msg, gpointer data) +_dictionary_message (YtsClient *client, + char const *const *dictionary, + gpointer data) { - YtsMetadata *md = (YtsMetadata*)msg; + unsigned length; + unsigned i; + char const *a1 = NULL; + char const *a2 = NULL; - g_assert (YTS_IS_MESSAGE (msg)); + length = g_strv_length ((char **) dictionary); - g_assert_cmpstr ("v1", ==, yts_metadata_get_attribute (md, "a1")); - g_assert_cmpstr ("v2", ==, yts_metadata_get_attribute (md, "a2")); + g_assert (length == 4); + + for (i = 0; i < length && !(a1 && a2); i++) { + if (0 == g_strcmp0 ("a1", dictionary[2*i])) { + a1 = dictionary[2*i + 1]; + } else if (0 == g_strcmp0 ("a2", dictionary[2*i])) { + a2 = dictionary[2*i + 1]; + } + } + + g_assert_cmpstr ("v1", ==, a1); + g_assert_cmpstr ("v2", ==, a2); retval = 0; g_main_loop_quit (loop); } static void -service_added_cb (YtsRoster *roster, YtsService *service, gpointer data) +service_added_cb (YtsRoster *roster, YtsService *service, YtsClient *client) { - YtsClient *client = yts_roster_get_client (roster); - YtsContact *contact = yts_service_get_contact (service); - const char *jid = yts_contact_get_id (contact); const char *sid = yts_service_get_service_id (service); gboolean our = FALSE; static YtsService *service2 = NULL; - g_debug ("Service %s:%s", jid, sid); + g_debug ("Service %s", sid); if (client == client1 && strstr (sid, "org.freedesktop.ytstenut.SendMessageTest2")) { @@ -87,7 +100,8 @@ service_added_cb (YtsRoster *roster, YtsService *service, gpointer data) ready2 = TRUE; our = TRUE; - g_signal_connect (client, "message", G_CALLBACK (message_cb), NULL); + g_signal_connect (client, "dictionary-message", + G_CALLBACK (_dictionary_message), NULL); } /* @@ -96,7 +110,6 @@ service_added_cb (YtsRoster *roster, YtsService *service, gpointer data) if (our && ready1 && ready2) { YtsError e; - YtsMetadata *metadata; const char *attributes[] = { "a1", "v1", @@ -104,14 +117,9 @@ service_added_cb (YtsRoster *roster, YtsService *service, gpointer data) NULL }; - metadata = (YtsMetadata*)yts_message_new ((const char**)&attributes); - g_debug ("Both test services are ready, sending message"); - e = yts_metadata_service_send_metadata ((YtsMetadataService *)service2, - metadata); - - g_assert (yts_error_get_code (e) == YTS_ERROR_PENDING); + yts_service_send_dictionary (service2, attributes, -1); } } @@ -131,7 +139,7 @@ main (int argc, char **argv) G_CALLBACK (authenticated_cb), NULL); roster1 = yts_client_get_roster (client1); g_signal_connect (roster1, "service-added", - G_CALLBACK (service_added_cb), NULL); + G_CALLBACK (service_added_cb), client1); yts_client_connect (client1); client2 = yts_client_new (YTS_PROTOCOL_LOCAL_XMPP, @@ -140,7 +148,7 @@ main (int argc, char **argv) G_CALLBACK (authenticated_cb), NULL); roster2 = yts_client_get_roster (client2); g_signal_connect (roster2, "service-added", - G_CALLBACK (service_added_cb), NULL); + G_CALLBACK (service_added_cb), client2); yts_client_connect (client2); g_timeout_add_seconds (TEST_LENGTH, timeout_test_cb, loop); diff --git a/tests/metadata-service.c b/tests/metadata-service.c deleted file mode 100644 index 4516f72..0000000 --- a/tests/metadata-service.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2011 Intel Corp. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * <http://www.gnu.org/licenses/>. - * - * Authored by: Tomas Frydrych <tf@linux.intel.com> - */ - -#include <ytstenut/ytstenut.h> -#include "ytstenut/yts-metadata-internal.h" -#include "ytstenut/yts-metadata-service-internal.h" - -#define MYUID "org.freedesktop.ytstenut.TestService" -#define STATUS_XML "<status a1='v1' a2='v2'></status>" -#define MESSAGE_XML "<message a1='v1' a2='v2'></message>" - -static gboolean got_status_signal = FALSE; -static gboolean got_message_signal = FALSE; - -static void -status_cb (YtsMetadataService *service, YtsStatus *status, gpointer data) -{ - YtsStatus *s2 = data; - - got_status_signal = TRUE; - - g_assert (yts_metadata_is_equal ((YtsMetadata*)status, (YtsMetadata*)s2)); -} - -static void -message_cb (YtsMetadataService *service, YtsMessage *message, gpointer data) -{ - YtsMessage *m2 = data; - - got_message_signal = TRUE; - - g_assert (yts_metadata_is_equal ((YtsMetadata*)message, (YtsMetadata*)m2)); -} - -int -main (int argc, char **argv) -{ - YtsService *service; - YtsStatus *status; - YtsMessage *message; - const char *uid; - - g_thread_init (NULL); - g_type_init (); - - /* - * The metadata-serivice-test property allows for partial construction of - * the object, so we can run some rudimentary tests. - */ - service = g_object_new (YTS_TYPE_METADATA_SERVICE, - "metadata-service-test", TRUE, - "uid", MYUID, - "type", "application", - NULL); - - g_assert (service); - - uid = yts_service_get_service_id (service); - - g_assert_cmpstr (MYUID, ==, uid); - - status = (YtsStatus*)yts_metadata_new_from_xml (STATUS_XML); - g_assert (YTS_IS_STATUS (status)); - - g_signal_connect (service, "status", - G_CALLBACK (status_cb), status); - - yts_metadata_service_received_status ((YtsMetadataService*)service, - STATUS_XML); - - g_assert (got_status_signal); - - message = (YtsMessage*)yts_metadata_new_from_xml (MESSAGE_XML); - g_assert (YTS_IS_MESSAGE (message)); - - g_signal_connect (service, "message", - G_CALLBACK (message_cb), message); - - yts_metadata_service_received_message ((YtsMetadataService*)service, - MESSAGE_XML); - - g_assert (got_message_signal); - - return 0; -} |