|
Packit |
8b6d7a |
/*
|
|
Packit |
8b6d7a |
* Copyright 2008-2011 Novell, Inc.
|
|
Packit |
8b6d7a |
*
|
|
Packit |
8b6d7a |
* This library is free software; you can redistribute it and/or
|
|
Packit |
8b6d7a |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
8b6d7a |
* License as published by the Free Software Foundation; either
|
|
Packit |
8b6d7a |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
8b6d7a |
*
|
|
Packit |
8b6d7a |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
8b6d7a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8b6d7a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
8b6d7a |
* Library General Public License for more details.
|
|
Packit |
8b6d7a |
*
|
|
Packit |
8b6d7a |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
8b6d7a |
* License along with this library; if not, write to the
|
|
Packit |
8b6d7a |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Packit |
8b6d7a |
* Boston, MA 02111-1307, USA.
|
|
Packit |
8b6d7a |
*/
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
#include <stdio.h>
|
|
Packit |
8b6d7a |
#include <glib.h>
|
|
Packit |
8b6d7a |
#include <string.h>
|
|
Packit |
8b6d7a |
#include <dbind/dbind.h>
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
/* Wow! dbus is unpleasant to use */
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
#define DESKICE_PATH "/Novell/ICEDesktop/Daemon"
|
|
Packit |
8b6d7a |
#define DESKICE_NAMESPACE "Novell.ICEDesktop.Daemon"
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void marshal (DBusMessage *msg, char *type, void *ptr)
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
DBusMessageIter iter;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbus_message_iter_init_append (msg, &iter);
|
|
Packit |
8b6d7a |
dbind_any_marshal (&iter, &type, &ptr);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void demarshal (DBusMessage *msg, char *type, void *ptr)
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
DBusMessageIter iter;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
if (!dbus_message_iter_init (msg, &iter))
|
|
Packit |
8b6d7a |
fprintf (stderr, "no data in msg\n");
|
|
Packit |
8b6d7a |
else
|
|
Packit |
8b6d7a |
dbind_any_demarshal (&iter, &type, &ptr);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
#if 0
|
|
Packit |
8b6d7a |
dbus_bool_t dbus_message_marshal (DBusMessage *msg,
|
|
Packit |
8b6d7a |
char **marshalled_data_p,
|
|
Packit |
8b6d7a |
int *len_p);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void dump_msg (DBusMessage *msg)
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
char *data = NULL;
|
|
Packit |
8b6d7a |
int len, i, j;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbus_message_marshal (msg, &data, &len;;
|
|
Packit |
8b6d7a |
for (i = 0; i < (len+15)/16; i++) {
|
|
Packit |
8b6d7a |
fprintf (stderr, "%4.d | ", i * 16);
|
|
Packit |
8b6d7a |
for (j = 0; j < 16; j++) {
|
|
Packit |
8b6d7a |
unsigned char c = (i*16+j <= len) ? data[i*16+j] : 0;
|
|
Packit |
8b6d7a |
fprintf (stderr, "0x%.2x ", c);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
fprintf (stderr, " | ");
|
|
Packit |
8b6d7a |
for (j = 0; j < 16; j++) {
|
|
Packit |
8b6d7a |
char c = (i*16+j <= len) ? data[i*16+j] : '\0';
|
|
Packit |
8b6d7a |
fprintf (stderr, "%c", g_ascii_isprint (c) ? c : '.');
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
#endif
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void test_simple ()
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
dbus_int32_t v1, v2;
|
|
Packit |
8b6d7a |
DBusMessage *msg;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
msg = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
Packit |
8b6d7a |
v1 = 42;
|
|
Packit |
8b6d7a |
marshal (msg, "i", &v1;;
|
|
Packit |
8b6d7a |
demarshal (msg, "i", &v2;;
|
|
Packit |
8b6d7a |
g_assert (v2 == 42);
|
|
Packit |
8b6d7a |
g_assert (v1 == v2);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbind_any_free ("i", &v2;; /* nop */
|
|
Packit |
8b6d7a |
dbus_message_unref (msg);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
fprintf (stderr, "simple ok\n");
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void test_array ()
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
GArray *a1, *a2;
|
|
Packit |
8b6d7a |
DBusMessage *msg;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
/* pod types */
|
|
Packit |
8b6d7a |
a1 = g_array_new (FALSE, FALSE, sizeof (dbus_int32_t));
|
|
Packit |
8b6d7a |
g_array_set_size (a1, 4);
|
|
Packit |
8b6d7a |
g_array_index (a1, dbus_int32_t, 0) = 42;
|
|
Packit |
8b6d7a |
g_array_index (a1, dbus_int32_t, 1) = 17;
|
|
Packit |
8b6d7a |
g_array_index (a1, dbus_int32_t, 2) = 26;
|
|
Packit |
8b6d7a |
g_array_index (a1, dbus_int32_t, 3) = 38;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
msg = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
Packit |
8b6d7a |
marshal (msg, "ai", &a1;;
|
|
Packit |
8b6d7a |
demarshal (msg, "ai", &a2;;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
g_assert (a2 != NULL);
|
|
Packit |
8b6d7a |
g_assert (a2->len == 4);
|
|
Packit |
8b6d7a |
g_assert (g_array_index (a2, dbus_int32_t, 0) == 42);
|
|
Packit |
8b6d7a |
g_assert (g_array_index (a2, dbus_int32_t, 1) == 17);
|
|
Packit |
8b6d7a |
g_assert (g_array_index (a2, dbus_int32_t, 2) == 26);
|
|
Packit |
8b6d7a |
g_assert (g_array_index (a2, dbus_int32_t, 3) == 38);
|
|
Packit |
8b6d7a |
g_array_free (a1, TRUE);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbind_any_free ("ai", &a2;;
|
|
Packit |
8b6d7a |
dbus_message_unref (msg);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
fprintf (stderr, "array ok\n");
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
/* this taught me that the struct type is a mis-nomer,
|
|
Packit |
8b6d7a |
it is generated by brackets */
|
|
Packit |
8b6d7a |
void test_struct_native ()
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
DBusMessage *msg;
|
|
Packit |
8b6d7a |
DBusMessageIter iter, arr, str;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
/* manually create ar(ss) */
|
|
Packit |
8b6d7a |
msg = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbus_message_iter_init_append (msg, &iter);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(ss)", &arr;;
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
char *foo;
|
|
Packit |
8b6d7a |
dbus_message_iter_open_container (&arr, DBUS_TYPE_STRUCT, NULL, &str);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
foo = "foo";
|
|
Packit |
8b6d7a |
dbus_message_iter_append_basic (&str, DBUS_TYPE_STRING, &foo;;
|
|
Packit |
8b6d7a |
foo = "baa";
|
|
Packit |
8b6d7a |
dbus_message_iter_append_basic (&str, DBUS_TYPE_STRING, &foo;;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbus_message_iter_close_container (&arr, &str);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
dbus_message_iter_close_container (&iter, &arr;;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
fprintf (stderr, "native struct marshalling ok\n");
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbus_message_unref (msg);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void test_struct_simple ()
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
typedef struct {
|
|
Packit |
8b6d7a |
char *foo;
|
|
Packit |
8b6d7a |
char *baa;
|
|
Packit |
8b6d7a |
char *baz;
|
|
Packit |
8b6d7a |
} FooBaa;
|
|
Packit |
8b6d7a |
GArray *a1 = NULL, *a2 = NULL;
|
|
Packit |
8b6d7a |
DBusMessage *msg;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
a1 = g_array_new (FALSE, FALSE, sizeof (FooBaa));
|
|
Packit |
8b6d7a |
g_array_set_size (a1, 2);
|
|
Packit |
8b6d7a |
g_array_index (a1, FooBaa, 0).foo = "foo";
|
|
Packit |
8b6d7a |
g_array_index (a1, FooBaa, 0).baa = "baa";
|
|
Packit |
8b6d7a |
g_array_index (a1, FooBaa, 0).baz = "baz";
|
|
Packit |
8b6d7a |
g_array_index (a1, FooBaa, 1).foo = "Foo";
|
|
Packit |
8b6d7a |
g_array_index (a1, FooBaa, 1).baa = "baA";
|
|
Packit |
8b6d7a |
g_array_index (a1, FooBaa, 1).baz = "BaZ";
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
msg = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
Packit |
8b6d7a |
marshal (msg, "a(sss)", &a1;;
|
|
Packit |
8b6d7a |
demarshal (msg, "a(sss)", &a2;;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
g_assert (a2 != NULL);
|
|
Packit |
8b6d7a |
g_assert (a2 != a1);
|
|
Packit |
8b6d7a |
g_assert (a2->len == 2);
|
|
Packit |
8b6d7a |
g_assert (!strcmp (g_array_index (a2, FooBaa, 0).foo, "foo"));
|
|
Packit |
8b6d7a |
g_assert (!strcmp (g_array_index (a2, FooBaa, 0).baa, "baa"));
|
|
Packit |
8b6d7a |
g_assert (!strcmp (g_array_index (a2, FooBaa, 0).baz, "baz"));
|
|
Packit |
8b6d7a |
g_assert (!strcmp (g_array_index (a2, FooBaa, 1).foo, "Foo"));
|
|
Packit |
8b6d7a |
g_assert (!strcmp (g_array_index (a2, FooBaa, 1).baa, "baA"));
|
|
Packit |
8b6d7a |
g_assert (!strcmp (g_array_index (a2, FooBaa, 1).baz, "BaZ"));
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
fprintf (stderr, "simple struct ok\n");
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbind_any_free ("a(sss)", &a2;;
|
|
Packit |
8b6d7a |
dbus_message_unref (msg);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void test_struct_complex ()
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
typedef struct {
|
|
Packit |
8b6d7a |
dbus_int32_t x, y;
|
|
Packit |
8b6d7a |
} Point;
|
|
Packit |
8b6d7a |
typedef struct {
|
|
Packit |
8b6d7a |
unsigned char pad1;
|
|
Packit |
8b6d7a |
double val;
|
|
Packit |
8b6d7a |
Point tl, br;
|
|
Packit |
8b6d7a |
char pad2;
|
|
Packit |
8b6d7a |
char *name;
|
|
Packit |
8b6d7a |
} Complex;
|
|
Packit |
8b6d7a |
#define TYPEOF_POINT \
|
|
Packit |
8b6d7a |
DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_TYPE_INT32_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_TYPE_INT32_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_STRUCT_END_CHAR_AS_STRING
|
|
Packit |
8b6d7a |
#define TYPEOF_COMPLEX \
|
|
Packit |
8b6d7a |
DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_TYPE_BYTE_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_TYPE_DOUBLE_AS_STRING \
|
|
Packit |
8b6d7a |
TYPEOF_POINT \
|
|
Packit |
8b6d7a |
TYPEOF_POINT \
|
|
Packit |
8b6d7a |
DBUS_TYPE_BYTE_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_TYPE_STRING_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_STRUCT_END_CHAR_AS_STRING
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
DBusMessage *msg;
|
|
Packit |
8b6d7a |
Complex c1, c2;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
memset (&c1, 0, sizeof (c1));
|
|
Packit |
8b6d7a |
memset (&c2, 0, sizeof (c2));
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
c1.pad1 = 2;
|
|
Packit |
8b6d7a |
c1.val = 0.1327569;
|
|
Packit |
8b6d7a |
c1.tl.x = 1;
|
|
Packit |
8b6d7a |
c1.tl.y = 17;
|
|
Packit |
8b6d7a |
c1.br.x = 2587;
|
|
Packit |
8b6d7a |
c1.br.y = -1;
|
|
Packit |
8b6d7a |
c1.pad2 = 1;
|
|
Packit |
8b6d7a |
c1.name = "stroustrup";
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
msg = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
Packit |
8b6d7a |
marshal (msg, TYPEOF_COMPLEX, &c1;;
|
|
Packit |
8b6d7a |
demarshal (msg, TYPEOF_COMPLEX, &c2;;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
g_assert (c2.pad1 == 2);
|
|
Packit |
8b6d7a |
g_assert (c2.val == c1.val);
|
|
Packit |
8b6d7a |
g_assert (c2.val != 0);
|
|
Packit |
8b6d7a |
g_assert (c2.tl.x == 1);
|
|
Packit |
8b6d7a |
g_assert (c2.tl.y == 17);
|
|
Packit |
8b6d7a |
g_assert (c2.br.x == 2587);
|
|
Packit |
8b6d7a |
g_assert (c2.br.y == -1);
|
|
Packit |
8b6d7a |
g_assert (c2.pad2 == 1);
|
|
Packit |
8b6d7a |
g_assert (!strcmp (c1.name, "stroustrup"));
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
fprintf (stderr, "complex struct ok\n");
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbind_any_free (TYPEOF_COMPLEX, &c2;;
|
|
Packit |
8b6d7a |
dbus_message_unref (msg);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void test_struct_with_array ()
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
typedef struct {
|
|
Packit |
8b6d7a |
GArray *vals;
|
|
Packit |
8b6d7a |
unsigned char pad1;
|
|
Packit |
8b6d7a |
} ArrayStruct;
|
|
Packit |
8b6d7a |
#define TYPEOF_ARRAYSTRUCT \
|
|
Packit |
8b6d7a |
DBUS_TYPE_ARRAY_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_TYPE_ARRAY_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_TYPE_UINT32_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_TYPE_BYTE_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_STRUCT_END_CHAR_AS_STRING
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
DBusMessage *msg;
|
|
Packit |
8b6d7a |
GArray *a1, *a2;
|
|
Packit |
8b6d7a |
ArrayStruct *p, *q;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
a1 = g_array_new (FALSE, FALSE, sizeof (ArrayStruct));
|
|
Packit |
8b6d7a |
g_array_set_size (a1, 2);
|
|
Packit |
8b6d7a |
p = &g_array_index (a1, ArrayStruct, 0);
|
|
Packit |
8b6d7a |
p[0].vals = g_array_new (FALSE, FALSE, sizeof (dbus_uint32_t));
|
|
Packit |
8b6d7a |
g_array_set_size (p[0].vals, 2);
|
|
Packit |
8b6d7a |
g_array_index (p[0].vals, dbus_uint32_t, 0) = 1;
|
|
Packit |
8b6d7a |
g_array_index (p[0].vals, dbus_uint32_t, 1) = 1000;
|
|
Packit |
8b6d7a |
p[0].pad1 = 2;
|
|
Packit |
8b6d7a |
p[1].vals = g_array_new (FALSE, FALSE, sizeof (dbus_uint32_t));
|
|
Packit |
8b6d7a |
g_array_set_size (p[1].vals, 2);
|
|
Packit |
8b6d7a |
g_array_index (p[1].vals, dbus_uint32_t, 0) = 1000000;
|
|
Packit |
8b6d7a |
g_array_index (p[1].vals, dbus_uint32_t, 1) = 1000000000;
|
|
Packit |
8b6d7a |
p[1].pad1 = 8;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
msg = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
Packit |
8b6d7a |
marshal (msg, TYPEOF_ARRAYSTRUCT, &a1;;
|
|
Packit |
8b6d7a |
demarshal (msg, TYPEOF_ARRAYSTRUCT, &a2;;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
q = &g_array_index (a2, ArrayStruct, 0);
|
|
Packit |
8b6d7a |
g_assert (p[0].pad1 == 2);
|
|
Packit |
8b6d7a |
g_assert (g_array_index (p[1].vals, dbus_uint32_t, 1) == 1000000000);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
fprintf (stderr, "struct with array ok\n");
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbind_any_free (TYPEOF_ARRAYSTRUCT, &a2;;
|
|
Packit |
8b6d7a |
dbus_message_unref (msg);
|
|
Packit |
8b6d7a |
g_array_free (p[0].vals, TRUE);
|
|
Packit |
8b6d7a |
g_array_free (p[1].vals, TRUE);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void test_twovals ()
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
typedef struct {
|
|
Packit |
8b6d7a |
dbus_int32_t v1;
|
|
Packit |
8b6d7a |
dbus_int32_t v2;
|
|
Packit |
8b6d7a |
} TwoVal;
|
|
Packit |
8b6d7a |
#define TYPEOF_TWOVAL \
|
|
Packit |
8b6d7a |
DBUS_TYPE_INT32_AS_STRING \
|
|
Packit |
8b6d7a |
DBUS_TYPE_INT32_AS_STRING \
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
DBusMessage *msg;
|
|
Packit |
8b6d7a |
DBusMessageIter iter;
|
|
Packit |
8b6d7a |
TwoVal i, o;
|
|
Packit |
8b6d7a |
char *type_twoval = TYPEOF_TWOVAL;
|
|
Packit |
8b6d7a |
char *type;
|
|
Packit |
8b6d7a |
void *ptr;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
msg = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
Packit |
8b6d7a |
i.v1 = 42;
|
|
Packit |
8b6d7a |
i.v2 = 1764;
|
|
Packit |
8b6d7a |
dbus_message_iter_init_append (msg, &iter);
|
|
Packit |
8b6d7a |
type = type_twoval;
|
|
Packit |
8b6d7a |
ptr = &i;
|
|
Packit |
8b6d7a |
dbind_any_marshal (&iter, &type, &ptr);
|
|
Packit |
8b6d7a |
dbind_any_marshal (&iter, &type, &ptr);
|
|
Packit |
8b6d7a |
dbus_message_iter_init (msg, &iter);
|
|
Packit |
8b6d7a |
type = type_twoval;
|
|
Packit |
8b6d7a |
ptr = &o;
|
|
Packit |
8b6d7a |
dbind_any_demarshal (&iter, &type, &ptr);
|
|
Packit |
8b6d7a |
dbind_any_demarshal (&iter, &type, &ptr);
|
|
Packit |
8b6d7a |
g_assert (o.v1 == 42);
|
|
Packit |
8b6d7a |
g_assert (o.v2 == 1764);
|
|
Packit |
8b6d7a |
g_assert (i.v1 == o.v1);
|
|
Packit |
8b6d7a |
g_assert (i.v2 == o.v2);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbind_any_free ("ii", &o); /* nop */
|
|
Packit |
8b6d7a |
dbus_message_unref (msg);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
fprintf (stderr, "two-val ok\n");
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void test_marshalling ()
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
test_simple ();
|
|
Packit |
8b6d7a |
test_array ();
|
|
Packit |
8b6d7a |
test_struct_native ();
|
|
Packit |
8b6d7a |
test_struct_simple ();
|
|
Packit |
8b6d7a |
test_struct_complex ();
|
|
Packit |
8b6d7a |
test_struct_with_array ();
|
|
Packit |
8b6d7a |
test_twovals ();
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
fprintf (stderr, "Marshalling ok\n");
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void test_teamspaces (DBusConnection *bus)
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
GArray *spaces;
|
|
Packit |
8b6d7a |
DBusError error;
|
|
Packit |
8b6d7a |
int i;
|
|
Packit |
8b6d7a |
typedef struct {
|
|
Packit |
8b6d7a |
char *name;
|
|
Packit |
8b6d7a |
char *id;
|
|
Packit |
8b6d7a |
char *url;
|
|
Packit |
8b6d7a |
} TeamSpace;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbus_error_init (&error);
|
|
Packit |
8b6d7a |
if (!dbind_method_call_reentrant (bus,
|
|
Packit |
8b6d7a |
NULL,
|
|
Packit |
8b6d7a |
DESKICE_PATH,
|
|
Packit |
8b6d7a |
DESKICE_NAMESPACE,
|
|
Packit |
8b6d7a |
"GetTeamList",
|
|
Packit |
8b6d7a |
&error,
|
|
Packit |
8b6d7a |
"=>a(sss)",
|
|
Packit |
8b6d7a |
&spaces)) {
|
|
Packit |
8b6d7a |
fprintf (stderr, "Error getting team spaces %s: %s\n",
|
|
Packit |
8b6d7a |
error.name, error.message);
|
|
Packit |
8b6d7a |
dbus_error_free (&error);
|
|
Packit |
8b6d7a |
return;
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
if (!spaces) {
|
|
Packit |
8b6d7a |
fprintf (stderr, "no teamspaces\n");
|
|
Packit |
8b6d7a |
return;
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
fprintf (stderr, "%d teamspace(s)\n", spaces->len);
|
|
Packit |
8b6d7a |
for (i = 0; i < spaces->len; i++) {
|
|
Packit |
8b6d7a |
TeamSpace *space = &g_array_index (spaces, TeamSpace, i);
|
|
Packit |
8b6d7a |
fprintf (stderr, "\t%d: %s, %s, %s\n", i, space->name, space->id, space->url);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
dbind_any_free_ptr ("a(sss)", spaces);
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
void test_helpers ()
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
dbind_find_c_alignment ("(sss)");
|
|
Packit |
8b6d7a |
dbind_find_c_alignment ("a(sss)");
|
|
Packit |
8b6d7a |
dbind_find_c_alignment ("(s(s)yd(d)s)");
|
|
Packit |
8b6d7a |
dbind_find_c_alignment ("a{ss}");
|
|
Packit |
8b6d7a |
fprintf (stderr, "helpers passed\n");
|
|
Packit |
8b6d7a |
}
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
int main (int argc, char **argv)
|
|
Packit |
8b6d7a |
{
|
|
Packit |
8b6d7a |
DBusConnection *bus;
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
bus = dbus_bus_get (DBUS_BUS_SESSION, NULL);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
test_helpers ();
|
|
Packit |
8b6d7a |
test_marshalling ();
|
|
Packit |
8b6d7a |
test_teamspaces (bus);
|
|
Packit |
8b6d7a |
|
|
Packit |
8b6d7a |
return 0;
|
|
Packit |
8b6d7a |
}
|