diff options
author | David Zeuthen <davidz@redhat.com> | 2008-12-10 21:01:11 -0500 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2008-12-10 21:01:11 -0500 |
commit | 5292e4068869da4cdaa4431cb50242265286e352 (patch) | |
tree | 7e8b6c4557c427ce5927884a28701ad8d9a60b08 | |
parent | 429c7633738d9982f21b89b6db79134bb7ffaf39 (diff) |
move interface implementations to separate files in the test suite
-rw-r--r-- | src/tests/Makefile.am | 3 | ||||
-rw-r--r-- | src/tests/testfrobimpl.c | 574 | ||||
-rw-r--r-- | src/tests/testfrobimpl.h | 56 | ||||
-rw-r--r-- | src/tests/testserver.c | 1041 | ||||
-rw-r--r-- | src/tests/testtweakimpl.c | 359 | ||||
-rw-r--r-- | src/tests/testtweakimpl.h | 54 | ||||
-rw-r--r-- | src/tests/testtwiddleimpl.c | 149 | ||||
-rw-r--r-- | src/tests/testtwiddleimpl.h | 54 |
8 files changed, 1253 insertions, 1037 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 7db2634..58dceb8 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -105,6 +105,9 @@ noinst_PROGRAMS += testserver testserver_SOURCES = \ testserver.c \ testtypes.h \ + testfrobimpl.h testfrobimpl.c \ + testtweakimpl.h testtweakimpl.c \ + testtwiddleimpl.h testtwiddleimpl.c \ $(NULL) testserver_CFLAGS = \ diff --git a/src/tests/testfrobimpl.c b/src/tests/testfrobimpl.c new file mode 100644 index 0000000..f14c49e --- /dev/null +++ b/src/tests/testfrobimpl.c @@ -0,0 +1,574 @@ +/* + * Copyright (C) 2008 Red Hat, Inc. + * + * 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, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#include "config.h" +#include <string.h> +#include "testfrobimpl.h" +#include "testbindings.h" + +enum +{ + PROP_0, + + /* Properties from the TestFrob interface */ + PROP_Y, + PROP_B, + PROP_N, + PROP_Q, + PROP_I, + PROP_U, + PROP_X, + PROP_T, + PROP_D, + PROP_S, + PROP_O, + PROP_G, + PROP_AY, + PROP_AB, + PROP_AN, + PROP_AQ, + PROP_AI, + PROP_AU, + PROP_AX, + PROP_AT, + PROP_AD, + PROP_AS, + PROP_AO, + PROP_AG, + PROP_FOO, +}; + +static void test_frob_impl_frob_iface_init (TestFrobIface *iface); + +G_DEFINE_TYPE_WITH_CODE (TestFrobImpl, test_frob_impl, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (TEST_TYPE_FROB, + test_frob_impl_frob_iface_init) + ); + +static void +test_frob_impl_init (TestFrobImpl *frob_impl) +{ +} + +static void +test_frob_impl_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + TestFrobImpl *frob_impl; + + frob_impl = TEST_FROB_IMPL (object); + + switch (prop_id) + { + case PROP_Y: + g_value_set_uchar (value, 1); + break; + + case PROP_B: + g_value_set_boolean (value, TRUE); + break; + + case PROP_N: + egg_dbus_value_set_int16 (value, 2); + break; + + case PROP_Q: + egg_dbus_value_set_uint16 (value, 3); + break; + + case PROP_I: + g_value_set_int (value, 4); + break; + + case PROP_U: + g_value_set_uint (value, 5); + break; + + case PROP_X: + g_value_set_int64 (value, 6); + break; + + case PROP_T: + g_value_set_uint64 (value, 7); + break; + + case PROP_D: + g_value_set_double (value, 7.5); + break; + + case PROP_S: + g_value_set_string (value, "a string"); + break; + + case PROP_O: + g_value_set_boxed (value, "/some/path"); + break; + + case PROP_G: + g_value_set_boxed (value, "(sig)"); + break; + + case PROP_AY: + { + GArray *array_byte; + guchar byte_val; + array_byte = g_array_new (FALSE, FALSE, sizeof (guchar)); + egg_dbus_array_set_elem_signature (array_byte, "y"); + byte_val = 1; g_array_append_val (array_byte, byte_val); + byte_val = 11; g_array_append_val (array_byte, byte_val); + g_value_take_boxed (value, array_byte); + } + break; + + case PROP_AB: + { + GArray *array_bool; + gboolean bool_val; + array_bool = g_array_new (FALSE, FALSE, sizeof (gboolean)); + egg_dbus_array_set_elem_signature (array_bool, "b"); + bool_val = TRUE; g_array_append_val (array_bool, bool_val); + bool_val = FALSE; g_array_append_val (array_bool, bool_val); + g_value_take_boxed (value, array_bool); + } + break; + + case PROP_AN: + { + GArray *array_int16; + gint16 int16_val; + array_int16 = g_array_new (FALSE, FALSE, sizeof (gint16)); + egg_dbus_array_set_elem_signature (array_int16, "n"); + int16_val = 2; g_array_append_val (array_int16, int16_val); + int16_val = 12; g_array_append_val (array_int16, int16_val); + g_value_take_boxed (value, array_int16); + } + break; + + case PROP_AQ: + { + GArray *array_uint16; + guint16 uint16_val; + array_uint16 = g_array_new (FALSE, FALSE, sizeof (guint16)); + egg_dbus_array_set_elem_signature (array_uint16, "q"); + uint16_val = 3; g_array_append_val (array_uint16, uint16_val); + uint16_val = 13; g_array_append_val (array_uint16, uint16_val); + g_value_take_boxed (value, array_uint16); + } + break; + + case PROP_AI: + { + GArray *array_int32; + gint32 int32_val; + array_int32 = g_array_new (FALSE, FALSE, sizeof (gint32)); + egg_dbus_array_set_elem_signature (array_int32, "i"); + int32_val = 4; g_array_append_val (array_int32, int32_val); + int32_val = 14; g_array_append_val (array_int32, int32_val); + g_value_take_boxed (value, array_int32); + } + break; + + case PROP_AU: + { + GArray *array_uint32; + guint32 uint32_val; + array_uint32 = g_array_new (FALSE, FALSE, sizeof (guint32)); + egg_dbus_array_set_elem_signature (array_uint32, "u"); + uint32_val = 5; g_array_append_val (array_uint32, uint32_val); + uint32_val = 15; g_array_append_val (array_uint32, uint32_val); + g_value_take_boxed (value, array_uint32); + } + break; + + case PROP_AX: + { + GArray *array_int64; + gint64 int64_val; + array_int64 = g_array_new (FALSE, FALSE, sizeof (gint64)); + egg_dbus_array_set_elem_signature (array_int64, "x"); + int64_val = 6; g_array_append_val (array_int64, int64_val); + int64_val = 16; g_array_append_val (array_int64, int64_val); + g_value_take_boxed (value, array_int64); + } + break; + + case PROP_AT: + { + GArray *array_uint64; + guint64 uint64_val; + array_uint64 = g_array_new (FALSE, FALSE, sizeof (guint64)); + egg_dbus_array_set_elem_signature (array_uint64, "t"); + uint64_val = 7; g_array_append_val (array_uint64, uint64_val); + uint64_val = 17; g_array_append_val (array_uint64, uint64_val); + g_value_take_boxed (value, array_uint64); + } + break; + + case PROP_AD: + { + GArray *array_double; + gdouble double_val; + array_double = g_array_new (FALSE, FALSE, sizeof (gdouble)); + egg_dbus_array_set_elem_signature (array_double, "d"); + double_val = 7.5; g_array_append_val (array_double, double_val); + double_val = 17.5; g_array_append_val (array_double, double_val); + g_value_take_boxed (value, array_double); + } + break; + + case PROP_AS: + { + const gchar *strs[] = {"a string", "another string", NULL}; + g_value_set_boxed (value, strs); + } + break; + + case PROP_AO: + { + const gchar *strs[] = {"/some/path", "/another/path", NULL}; + g_value_set_boxed (value, strs); + } + break; + + case PROP_AG: + { + const gchar *strs[] = {"(sig)", "((sig))", NULL}; + g_value_set_boxed (value, strs); + } + break; + + case PROP_FOO: + g_value_set_string (value, "a frobbed string"); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +test_frob_impl_class_init (TestFrobImplClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->get_property = test_frob_impl_get_property; + + g_assert (test_frob_override_properties (gobject_class, PROP_Y) == PROP_FOO); +} + +TestFrobImpl * +test_frob_impl_new (void) +{ + return TEST_FROB_IMPL (g_object_new (TEST_TYPE_FROB_IMPL, NULL)); +} + +static void +frob_iface_handle_hello_world (TestFrob *instance, + const gchar *hello_message, + EggDBusMethodInvocation *method_invocation) +{ + if (strcmp (hello_message, "Yo") == 0) + { + egg_dbus_method_invocation_return_error_literal (method_invocation, + TEST_ERROR, + TEST_ERROR_FLUX_CAPACITOR_FAILURE, + "Yo is not a proper greeting"); + } + else + { + gchar *ret; + + ret = g_strdup_printf ("You greeted me with '%s'. Thanks!", hello_message); + + test_frob_handle_hello_world_finish (method_invocation, + ret); + + g_free (ret); + } +} + +static void +frob_iface_handle_emit_test_signals (TestFrob *instance, + EggDBusMethodInvocation *method_invocation) +{ + const gchar *str_array[3]; + const gchar *objpath_array[4]; + const gchar *sig_array[4]; + GArray *array_int32; + gint32 int32_val; + GArray *array_byte; + guchar byte_val; + TestPoint *point; + TestDescribedPoint *dpoint; + TestPoint *point_in_dpoint; + GHashTable *hash_string_to_string; + GHashTable *hash_string_to_point; + + /* --- */ + + test_frob_emit_signal_signal_with_primitive_types (instance, + NULL, + 0xfe, + TRUE, + 2, + 3, + 4, + 5, + 6, + 7, + 1.2, + "a string", + "/objpath", + "(ss)"); + + /* --- */ + + str_array[0] = "signalfoo"; + str_array[1] = "signalbar"; + str_array[2] = NULL; + + objpath_array[0] = "/signal/foo"; + objpath_array[1] = "/signal/bar"; + objpath_array[2] = "/signal/baz"; + objpath_array[3] = NULL; + + sig_array[0] = "s"; + sig_array[1] = "(ss)"; + sig_array[2] = "(sig)"; + sig_array[3] = NULL; + + array_byte = g_array_new (FALSE, FALSE, sizeof (guchar)); + egg_dbus_array_set_elem_signature (array_byte, "y"); + byte_val = 1; g_array_append_val (array_byte, byte_val); + byte_val = 11; g_array_append_val (array_byte, byte_val); + + array_int32 = g_array_new (FALSE, FALSE, sizeof (gint32)); + egg_dbus_array_set_elem_signature (array_int32, "i"); + int32_val = 4; g_array_append_val (array_int32, int32_val); + int32_val = 14; g_array_append_val (array_int32, int32_val); + + test_frob_emit_signal_signal_with_array_of_primitive_types (instance, + NULL, + array_byte, + array_int32, + (gchar **) str_array, + (gchar **) objpath_array, + (gchar **) sig_array); + + g_array_free (array_byte, TRUE); + g_array_free (array_int32, TRUE); + + /* --- */ + + point = test_point_new (40, 41); + + point_in_dpoint = test_point_new (42, 43); + dpoint = test_described_point_new ("xmas", point_in_dpoint); + g_object_unref (point_in_dpoint); + + hash_string_to_string = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); + g_hash_table_insert (hash_string_to_string, "secret", "emerald"); + g_hash_table_insert (hash_string_to_string, "top-secret", "stuff"); + g_hash_table_insert (hash_string_to_string, "ultra-top-secret", "Rupert"); + + hash_string_to_point = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_object_unref); + g_hash_table_insert (hash_string_to_point, "site59", test_point_new (20, 21)); + g_hash_table_insert (hash_string_to_point, "site60", test_point_new (22, 23)); + + test_frob_emit_signal_signal_with_structure_and_hash (instance, + NULL, + point, + dpoint, + hash_string_to_string, + hash_string_to_point); + g_object_unref (point); + g_object_unref (dpoint); + egg_dbus_hash_table_unref (hash_string_to_string); + egg_dbus_hash_table_unref (hash_string_to_point); + + test_frob_handle_emit_test_signals_finish (method_invocation); + +} + +static void +frob_iface_handle_test_primitive_types (TestFrob *instance, + guint8 val_byte, + gboolean val_boolean, + gint16 val_int16, + guint16 val_uint16, + gint val_int32, + guint val_uint32, + gint64 val_int64, + guint64 val_uint64, + double val_double, + const gchar *val_string, + const gchar *val_objpath, + const gchar *val_sig, + EggDBusMethodInvocation *method_invocation) +{ + gchar *str; + gchar *objpath; + gchar *sig; + + str = g_strdup_printf ("%s%s", val_string, val_string); + objpath = g_strdup_printf ("%s/modified", val_objpath); + sig = g_strdup_printf ("(%s)", val_sig); + + test_frob_handle_test_primitive_types_finish (method_invocation, + val_byte + 1, + ! val_boolean, + val_int16 + 1, + val_uint16 + 1, + val_int32 + 1, + val_uint32 + 1, + val_int64 + 1, + val_uint64 + 1, + -val_double, + str, + objpath, + sig); + + g_free (str); + g_free (objpath); + g_free (sig); +} + +static void +frob_iface_handle_test_array_of_primitive_types (TestFrob *instance, + GArray *val_byte, + GArray *val_boolean, + GArray *val_int16, + GArray *val_uint16, + GArray *val_int32, + GArray *val_uint32, + GArray *val_int64, + GArray *val_uint64, + GArray *val_double, + gchar **val_string, + gchar **val_objpath, + gchar **val_sig, + EggDBusMethodInvocation *method_invocation) +{ + GArray *ret_array_byte; + GArray *ret_array_boolean; + GArray *ret_array_int16; + GArray *ret_array_uint16; + GArray *ret_array_int32; + GArray *ret_array_uint32; + GArray *ret_array_int64; + GArray *ret_array_uint64; + GArray *ret_array_double; + gchar **ret_array_string; + gchar **ret_array_objpath; + gchar **ret_array_sig; + guint n; + guint len; + + ret_array_byte = g_array_new (FALSE, FALSE, sizeof (guint8)); + g_array_append_vals (ret_array_byte, val_byte->data, val_byte->len); + g_array_append_vals (ret_array_byte, val_byte->data, val_byte->len); + + ret_array_boolean = g_array_new (FALSE, FALSE, sizeof (gboolean)); + g_array_append_vals (ret_array_boolean, val_boolean->data, val_boolean->len); + g_array_append_vals (ret_array_boolean, val_boolean->data, val_boolean->len); + + ret_array_int16 = g_array_new (FALSE, FALSE, sizeof (gint16)); + g_array_append_vals (ret_array_int16, val_int16->data, val_int16->len); + g_array_append_vals (ret_array_int16, val_int16->data, val_int16->len); + + ret_array_uint16 = g_array_new (FALSE, FALSE, sizeof (guint16)); + g_array_append_vals (ret_array_uint16, val_uint16->data, val_uint16->len); + g_array_append_vals (ret_array_uint16, val_uint16->data, val_uint16->len); + + ret_array_int32 = g_array_new (FALSE, FALSE, sizeof (gint32)); + g_array_append_vals (ret_array_int32, val_int32->data, val_int32->len); + g_array_append_vals (ret_array_int32, val_int32->data, val_int32->len); + + ret_array_uint32 = g_array_new (FALSE, FALSE, sizeof (guint32)); + g_array_append_vals (ret_array_uint32, val_uint32->data, val_uint32->len); + g_array_append_vals (ret_array_uint32, val_uint32->data, val_uint32->len); + + ret_array_int64 = g_array_new (FALSE, FALSE, sizeof (gint64)); + g_array_append_vals (ret_array_int64, val_int64->data, val_int64->len); + g_array_append_vals (ret_array_int64, val_int64->data, val_int64->len); + + ret_array_uint64 = g_array_new (FALSE, FALSE, sizeof (guint64)); + g_array_append_vals (ret_array_uint64, val_uint64->data, val_uint64->len); + g_array_append_vals (ret_array_uint64, val_uint64->data, val_uint64->len); + + ret_array_double = g_array_new (FALSE, FALSE, sizeof (gdouble)); + g_array_append_vals (ret_array_double, val_double->data, val_double->len); + g_array_append_vals (ret_array_double, val_double->data, val_double->len); + + len = g_strv_length (val_string); + ret_array_string = g_new0 (gchar *, len * 2 + 1); + for (n = 0; n < len; n++) + ret_array_string[n] = ret_array_string[len + n] = val_string[n]; + + len = g_strv_length (val_string); + ret_array_objpath = g_new0 (gchar *, len * 2 + 1); + for (n = 0; n < len; n++) + ret_array_objpath[n] = ret_array_objpath[len + n] = val_objpath[n]; + + len = g_strv_length (val_string); + ret_array_sig = g_new0 (gchar *, len * 2 + 1); + for (n = 0; n < len; n++) + ret_array_sig[n] = ret_array_sig[len + n] = val_sig[n]; + + test_frob_handle_test_array_of_primitive_types_finish (method_invocation, + ret_array_byte, + ret_array_boolean, + ret_array_int16, + ret_array_uint16, + ret_array_int32, + ret_array_uint32, + ret_array_int64, + ret_array_uint64, + ret_array_double, + ret_array_string, + ret_array_objpath, + ret_array_sig); + + g_array_free (ret_array_byte, TRUE); + g_array_free (ret_array_boolean, TRUE); + g_array_free (ret_array_int16, TRUE); + g_array_free (ret_array_uint16, TRUE); + g_array_free (ret_array_int32, TRUE); + g_array_free (ret_array_uint32, TRUE); + g_array_free (ret_array_int64, TRUE); + g_array_free (ret_array_uint64, TRUE); + g_array_free (ret_array_double, TRUE); + g_free (ret_array_string); + g_free (ret_array_objpath); + g_free (ret_array_sig); +} + +static void +test_frob_impl_frob_iface_init (TestFrobIface *iface) +{ + iface->handle_hello_world = frob_iface_handle_hello_world; + iface->handle_test_primitive_types = frob_iface_handle_test_primitive_types; + iface->handle_test_array_of_primitive_types = frob_iface_handle_test_array_of_primitive_types; + iface->handle_emit_test_signals = frob_iface_handle_emit_test_signals; +} diff --git a/src/tests/testfrobimpl.h b/src/tests/testfrobimpl.h new file mode 100644 index 0000000..6727b74 --- /dev/null +++ b/src/tests/testfrobimpl.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2008 Red Hat, Inc. + * + * 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, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#ifndef __TEST_FROB_IMPL_H +#define __TEST_FROB_IMPL_H + +#include <eggdbus/eggdbus.h> + +G_BEGIN_DECLS + +#define TEST_TYPE_FROB_IMPL (test_frob_impl_get_type()) +#define TEST_FROB_IMPL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TEST_TYPE_FROB_IMPL, TestFrobImpl)) +#define TEST_FROB_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TEST_TYPE_FROB_IMPL, TestFrobImplClass)) +#define TEST_FROB_IMPL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TEST_TYPE_FROB_IMPL, TestFrobImplClass)) +#define TEST_IS_FROB_IMPL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TEST_TYPE_FROB_IMPL)) +#define TEST_IS_FROB_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TEST_TYPE_FROB_IMPL)) + + +typedef struct _TestFrobImpl TestFrobImpl; +typedef struct _TestFrobImplClass TestFrobImplClass; + +struct _TestFrobImpl +{ + GObject parent_instance; +}; + +struct _TestFrobImplClass +{ + GObjectClass parent_class; +}; + +GType test_frob_impl_get_type (void) G_GNUC_CONST; +TestFrobImpl *test_frob_impl_new (void); + + +G_END_DECLS + +#endif /* __TEST_FROB_IMPL_H */ diff --git a/src/tests/testserver.c b/src/tests/testserver.c index ac57ae7..b825fb1 100644 --- a/src/tests/testserver.c +++ b/src/tests/testserver.c @@ -19,1049 +19,16 @@ * Author: David Zeuthen <davidz@redhat.com> */ +#include "config.h" #include <unistd.h> #include <sys/types.h> #include <stdlib.h> #include <string.h> #include "testbindings.h" -/* ---------------------------------------------------------------------------------------------------- */ - -#define TEST_TYPE_FROB_IMPL (test_frob_impl_get_type()) -#define TEST_FROB_IMPL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TEST_TYPE_FROB_IMPL, TestFrobImpl)) -#define TEST_FROB_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TEST_TYPE_FROB_IMPL, TestFrobImplClass)) -#define TEST_FROB_IMPL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TEST_TYPE_FROB_IMPL, TestFrobImplClass)) -#define TEST_IS_FROB_IMPL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TEST_TYPE_FROB_IMPL)) -#define TEST_IS_FROB_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TEST_TYPE_FROB_IMPL)) - -GType test_frob_impl_get_type (void); - -typedef struct _TestFrobImpl TestFrobImpl; -typedef struct _TestFrobImplClass TestFrobImplClass; - -struct _TestFrobImpl -{ - GObject parent_instance; -}; - -struct _TestFrobImplClass -{ - GObjectClass parent_class; -}; - -enum -{ - PROP_TEST_FROB_IMPL_0, - - /* Properties from the TestFrob interface */ - PROP_TEST_FROB_Y, - PROP_TEST_FROB_B, - PROP_TEST_FROB_N, - PROP_TEST_FROB_Q, - PROP_TEST_FROB_I, - PROP_TEST_FROB_U, - PROP_TEST_FROB_X, - PROP_TEST_FROB_T, - PROP_TEST_FROB_D, - PROP_TEST_FROB_S, - PROP_TEST_FROB_O, - PROP_TEST_FROB_G, - PROP_TEST_FROB_AY, - PROP_TEST_FROB_AB, - PROP_TEST_FROB_AN, - PROP_TEST_FROB_AQ, - PROP_TEST_FROB_AI, - PROP_TEST_FROB_AU, - PROP_TEST_FROB_AX, - PROP_TEST_FROB_AT, - PROP_TEST_FROB_AD, - PROP_TEST_FROB_AS, - PROP_TEST_FROB_AO, - PROP_TEST_FROB_AG, - PROP_TEST_FROB_FOO, -}; - -static void test_frob_impl_frob_iface_init (TestFrobIface *iface); - -G_DEFINE_TYPE_WITH_CODE (TestFrobImpl, test_frob_impl, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TEST_TYPE_FROB, - test_frob_impl_frob_iface_init) - ); - -static void -test_frob_impl_init (TestFrobImpl *frob_impl) -{ -} - -static void -test_frob_impl_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - TestFrobImpl *frob_impl; - - frob_impl = TEST_FROB_IMPL (object); - - switch (prop_id) - { - case PROP_TEST_FROB_Y: - g_value_set_uchar (value, 1); - break; - - case PROP_TEST_FROB_B: - g_value_set_boolean (value, TRUE); - break; - - case PROP_TEST_FROB_N: - egg_dbus_value_set_int16 (value, 2); - break; - - case PROP_TEST_FROB_Q: - egg_dbus_value_set_uint16 (value, 3); - break; - - case PROP_TEST_FROB_I: - g_value_set_int (value, 4); - break; - - case PROP_TEST_FROB_U: - g_value_set_uint (value, 5); - break; - - case PROP_TEST_FROB_X: - g_value_set_int64 (value, 6); - break; - - case PROP_TEST_FROB_T: - g_value_set_uint64 (value, 7); - break; - - case PROP_TEST_FROB_D: - g_value_set_double (value, 7.5); - break; - - case PROP_TEST_FROB_S: - g_value_set_string (value, "a string"); - break; - - case PROP_TEST_FROB_O: - g_value_set_boxed (value, "/some/path"); - break; - - case PROP_TEST_FROB_G: - g_value_set_boxed (value, "(sig)"); - break; - - case PROP_TEST_FROB_AY: - { - GArray *array_byte; - guchar byte_val; - array_byte = g_array_new (FALSE, FALSE, sizeof (guchar)); - egg_dbus_array_set_elem_signature (array_byte, "y"); - byte_val = 1; g_array_append_val (array_byte, byte_val); - byte_val = 11; g_array_append_val (array_byte, byte_val); - g_value_take_boxed (value, array_byte); - } - break; - - case PROP_TEST_FROB_AB: - { - GArray *array_bool; - gboolean bool_val; - array_bool = g_array_new (FALSE, FALSE, sizeof (gboolean)); - egg_dbus_array_set_elem_signature (array_bool, "b"); - bool_val = TRUE; g_array_append_val (array_bool, bool_val); - bool_val = FALSE; g_array_append_val (array_bool, bool_val); - g_value_take_boxed (value, array_bool); - } - break; - - case PROP_TEST_FROB_AN: - { - GArray *array_int16; - gint16 int16_val; - array_int16 = g_array_new (FALSE, FALSE, sizeof (gint16)); - egg_dbus_array_set_elem_signature (array_int16, "n"); - int16_val = 2; g_array_append_val (array_int16, int16_val); - int16_val = 12; g_array_append_val (array_int16, int16_val); - g_value_take_boxed (value, array_int16); - } - break; - - case PROP_TEST_FROB_AQ: - { - GArray *array_uint16; - guint16 uint16_val; - array_uint16 = g_array_new (FALSE, FALSE, sizeof (guint16)); - egg_dbus_array_set_elem_signature (array_uint16, "q"); - uint16_val = 3; g_array_append_val (array_uint16, uint16_val); - uint16_val = 13; g_array_append_val (array_uint16, uint16_val); - g_value_take_boxed (value, array_uint16); - } - break; - - case PROP_TEST_FROB_AI: - { - GArray *array_int32; - gint32 int32_val; - array_int32 = g_array_new (FALSE, FALSE, sizeof (gint32)); - egg_dbus_array_set_elem_signature (array_int32, "i"); - int32_val = 4; g_array_append_val (array_int32, int32_val); - int32_val = 14; g_array_append_val (array_int32, int32_val); - g_value_take_boxed (value, array_int32); - } - break; - - case PROP_TEST_FROB_AU: - { - GArray *array_uint32; - guint32 uint32_val; - array_uint32 = g_array_new (FALSE, FALSE, sizeof (guint32)); - egg_dbus_array_set_elem_signature (array_uint32, "u"); - uint32_val = 5; g_array_append_val (array_uint32, uint32_val); - uint32_val = 15; g_array_append_val (array_uint32, uint32_val); - g_value_take_boxed (value, array_uint32); - } - break; - - case PROP_TEST_FROB_AX: - { - GArray *array_int64; - gint64 int64_val; - array_int64 = g_array_new (FALSE, FALSE, sizeof (gint64)); - egg_dbus_array_set_elem_signature (array_int64, "x"); - int64_val = 6; g_array_append_val (array_int64, int64_val); - int64_val = 16; g_array_append_val (array_int64, int64_val); - g_value_take_boxed (value, array_int64); - } - break; - - case PROP_TEST_FROB_AT: - { - GArray *array_uint64; - guint64 uint64_val; - array_uint64 = g_array_new (FALSE, FALSE, sizeof (guint64)); - egg_dbus_array_set_elem_signature (array_uint64, "t"); - uint64_val = 7; g_array_append_val (array_uint64, uint64_val); - uint64_val = 17; g_array_append_val (array_uint64, uint64_val); - g_value_take_boxed (value, array_uint64); - } - break; - - case PROP_TEST_FROB_AD: - { - GArray *array_double; - gdouble double_val; - array_double = g_array_new (FALSE, FALSE, sizeof (gdouble)); - egg_dbus_array_set_elem_signature (array_double, "d"); - double_val = 7.5; g_array_append_val (array_double, double_val); - double_val = 17.5; g_array_append_val (array_double, double_val); - g_value_take_boxed (value, array_double); - } - break; - - case PROP_TEST_FROB_AS: - { - const gchar *strs[] = {"a string", "another string", NULL}; - g_value_set_boxed (value, strs); - } - break; - - case PROP_TEST_FROB_AO: - { - const gchar *strs[] = {"/some/path", "/another/path", NULL}; - g_value_set_boxed (value, strs); - } - break; - - case PROP_TEST_FROB_AG: - { - const gchar *strs[] = {"(sig)", "((sig))", NULL}; - g_value_set_boxed (value, strs); - } - break; - - case PROP_TEST_FROB_FOO: - g_value_set_string (value, "a frobbed string"); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -test_frob_impl_class_init (TestFrobImplClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->get_property = test_frob_impl_get_property; - - g_assert (test_frob_override_properties (gobject_class, PROP_TEST_FROB_Y) == PROP_TEST_FROB_FOO); -} - -static TestFrobImpl * -test_frob_impl_new (void) -{ - return TEST_FROB_IMPL (g_object_new (TEST_TYPE_FROB_IMPL, NULL)); -} - -static void -frob_iface_handle_hello_world (TestFrob *instance, - const gchar *hello_message, - EggDBusMethodInvocation *method_invocation) -{ - if (strcmp (hello_message, "Yo") == 0) - { - egg_dbus_method_invocation_return_error_literal (method_invocation, - TEST_ERROR, - TEST_ERROR_FLUX_CAPACITOR_FAILURE, - "Yo is not a proper greeting"); - } - else - { - gchar *ret; - - ret = g_strdup_printf ("You greeted me with '%s'. Thanks!", hello_message); - - test_frob_handle_hello_world_finish (method_invocation, - ret); - - g_free (ret); - } -} - -static void -frob_iface_handle_emit_test_signals (TestFrob *instance, - EggDBusMethodInvocation *method_invocation) -{ - const gchar *str_array[3]; - const gchar *objpath_array[4]; - const gchar *sig_array[4]; - GArray *array_int32; - gint32 int32_val; - GArray *array_byte; - guchar byte_val; - TestPoint *point; - TestDescribedPoint *dpoint; - TestPoint *point_in_dpoint; - GHashTable *hash_string_to_string; - GHashTable *hash_string_to_point; - - /* --- */ - - test_frob_emit_signal_signal_with_primitive_types (instance, - NULL, - 0xfe, - TRUE, - 2, - 3, - 4, - 5, - 6, - 7, - 1.2, - "a string", - "/objpath", - "(ss)"); - - /* --- */ - - str_array[0] = "signalfoo"; - str_array[1] = "signalbar"; - str_array[2] = NULL; - - objpath_array[0] = "/signal/foo"; - objpath_array[1] = "/signal/bar"; - objpath_array[2] = "/signal/baz"; - objpath_array[3] = NULL; - - sig_array[0] = "s"; - sig_array[1] = "(ss)"; - sig_array[2] = "(sig)"; - sig_array[3] = NULL; - - array_byte = g_array_new (FALSE, FALSE, sizeof (guchar)); - egg_dbus_array_set_elem_signature (array_byte, "y"); - byte_val = 1; g_array_append_val (array_byte, byte_val); - byte_val = 11; g_array_append_val (array_byte, byte_val); - - array_int32 = g_array_new (FALSE, FALSE, sizeof (gint32)); - egg_dbus_array_set_elem_signature (array_int32, "i"); - int32_val = 4; g_array_append_val (array_int32, int32_val); - int32_val = 14; g_array_append_val (array_int32, int32_val); - - test_frob_emit_signal_signal_with_array_of_primitive_types (instance, - NULL, - array_byte, - array_int32, - (gchar **) str_array, - (gchar **) objpath_array, - (gchar **) sig_array); - - g_array_free (array_byte, TRUE); - g_array_free (array_int32, TRUE); - - /* --- */ - - point = test_point_new (40, 41); - - point_in_dpoint = test_point_new (42, 43); - dpoint = test_described_point_new ("xmas", point_in_dpoint); - g_object_unref (point_in_dpoint); - - hash_string_to_string = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); - g_hash_table_insert (hash_string_to_string, "secret", "emerald"); - g_hash_table_insert (hash_string_to_string, "top-secret", "stuff"); - g_hash_table_insert (hash_string_to_string, "ultra-top-secret", "Rupert"); - - hash_string_to_point = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_object_unref); - g_hash_table_insert (hash_string_to_point, "site59", test_point_new (20, 21)); - g_hash_table_insert (hash_string_to_point, "site60", test_point_new (22, 23)); - - test_frob_emit_signal_signal_with_structure_and_hash (instance, - NULL, - point, - dpoint, - hash_string_to_string, - hash_string_to_point); - g_object_unref (point); - g_object_unref (dpoint); - egg_dbus_hash_table_unref (hash_string_to_string); - egg_dbus_hash_table_unref (hash_string_to_point); - - test_frob_handle_emit_test_signals_finish (method_invocation); - -} - -static void -frob_iface_handle_test_primitive_types (TestFrob *instance, - guint8 val_byte, - gboolean val_boolean, - gint16 val_int16, - guint16 val_uint16, - gint val_int32, - guint val_uint32, - gint64 val_int64, - guint64 val_uint64, - double val_double, - const gchar *val_string, - const gchar *val_objpath, - const gchar *val_sig, - EggDBusMethodInvocation *method_invocation) -{ - gchar *str; - gchar *objpath; - gchar *sig; - - str = g_strdup_printf ("%s%s", val_string, val_string); - objpath = g_strdup_printf ("%s/modified", val_objpath); - sig = g_strdup_printf ("(%s)", val_sig); - - test_frob_handle_test_primitive_types_finish (method_invocation, - val_byte + 1, - ! val_boolean, - val_int16 + 1, - val_uint16 + 1, - val_int32 + 1, - val_uint32 + 1, - val_int64 + 1, - val_uint64 + 1, - -val_double, - str, - objpath, - sig); - - g_free (str); - g_free (objpath); - g_free (sig); -} - -static void -frob_iface_handle_test_array_of_primitive_types (TestFrob *instance, - GArray *val_byte, - GArray *val_boolean, - GArray *val_int16, - GArray *val_uint16, - GArray *val_int32, - GArray *val_uint32, - GArray *val_int64, - GArray *val_uint64, - GArray *val_double, - gchar **val_string, - gchar **val_objpath, - gchar **val_sig, - EggDBusMethodInvocation *method_invocation) -{ - GArray *ret_array_byte; - GArray *ret_array_boolean; - GArray *ret_array_int16; - GArray *ret_array_uint16; - GArray *ret_array_int32; - GArray *ret_array_uint32; - GArray *ret_array_int64; - GArray *ret_array_uint64; - GArray *ret_array_double; - gchar **ret_array_string; - gchar **ret_array_objpath; - gchar **ret_array_sig; - guint n; - guint len; - - ret_array_byte = g_array_new (FALSE, FALSE, sizeof (guint8)); - g_array_append_vals (ret_array_byte, val_byte->data, val_byte->len); - g_array_append_vals (ret_array_byte, val_byte->data, val_byte->len); - - ret_array_boolean = g_array_new (FALSE, FALSE, sizeof (gboolean)); - g_array_append_vals (ret_array_boolean, val_boolean->data, val_boolean->len); - g_array_append_vals (ret_array_boolean, val_boolean->data, val_boolean->len); - - ret_array_int16 = g_array_new (FALSE, FALSE, sizeof (gint16)); - g_array_append_vals (ret_array_int16, val_int16->data, val_int16->len); - g_array_append_vals (ret_array_int16, val_int16->data, val_int16->len); - - ret_array_uint16 = g_array_new (FALSE, FALSE, sizeof (guint16)); - g_array_append_vals (ret_array_uint16, val_uint16->data, val_uint16->len); - g_array_append_vals (ret_array_uint16, val_uint16->data, val_uint16->len); - - ret_array_int32 = g_array_new (FALSE, FALSE, sizeof (gint32)); - g_array_append_vals (ret_array_int32, val_int32->data, val_int32->len); - g_array_append_vals (ret_array_int32, val_int32->data, val_int32->len); - - ret_array_uint32 = g_array_new (FALSE, FALSE, sizeof (guint32)); - g_array_append_vals (ret_array_uint32, val_uint32->data, val_uint32->len); - g_array_append_vals (ret_array_uint32, val_uint32->data, val_uint32->len); - - ret_array_int64 = g_array_new (FALSE, FALSE, sizeof (gint64)); - g_array_append_vals (ret_array_int64, val_int64->data, val_int64->len); - g_array_append_vals (ret_array_int64, val_int64->data, val_int64->len); - - ret_array_uint64 = g_array_new (FALSE, FALSE, sizeof (guint64)); - g_array_append_vals (ret_array_uint64, val_uint64->data, val_uint64->len); - g_array_append_vals (ret_array_uint64, val_uint64->data, val_uint64->len); - - ret_array_double = g_array_new (FALSE, FALSE, sizeof (gdouble)); - g_array_append_vals (ret_array_double, val_double->data, val_double->len); - g_array_append_vals (ret_array_double, val_double->data, val_double->len); - - len = g_strv_length (val_string); - ret_array_string = g_new0 (gchar *, len * 2 + 1); - for (n = 0; n < len; n++) - ret_array_string[n] = ret_array_string[len + n] = val_string[n]; - - len = g_strv_length (val_string); - ret_array_objpath = g_new0 (gchar *, len * 2 + 1); - for (n = 0; n < len; n++) - ret_array_objpath[n] = ret_array_objpath[len + n] = val_objpath[n]; - - len = g_strv_length (val_string); - ret_array_sig = g_new0 (gchar *, len * 2 + 1); - for (n = 0; n < len; n++) - ret_array_sig[n] = ret_array_sig[len + n] = val_sig[n]; - - test_frob_handle_test_array_of_primitive_types_finish (method_invocation, - ret_array_byte, - ret_array_boolean, - ret_array_int16, - ret_array_uint16, - ret_array_int32, - ret_array_uint32, - ret_array_int64, - ret_array_uint64, - ret_array_double, - ret_array_string, - ret_array_objpath, - ret_array_sig); - - g_array_free (ret_array_byte, TRUE); - g_array_free (ret_array_boolean, TRUE); - g_array_free (ret_array_int16, TRUE); - g_array_free (ret_array_uint16, TRUE); - g_array_free (ret_array_int32, TRUE); - g_array_free (ret_array_uint32, TRUE); - g_array_free (ret_array_int64, TRUE); - g_array_free (ret_array_uint64, TRUE); - g_array_free (ret_array_double, TRUE); - g_free (ret_array_string); - g_free (ret_array_objpath); - g_free (ret_array_sig); -} - -static void -test_frob_impl_frob_iface_init (TestFrobIface *iface) -{ - iface->handle_hello_world = frob_iface_handle_hello_world; - iface->handle_test_primitive_types = frob_iface_handle_test_primitive_types; - iface->handle_test_array_of_primitive_types = frob_iface_handle_test_array_of_primitive_types; - iface->handle_emit_test_signals = frob_iface_handle_emit_test_signals; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -#define TEST_TYPE_TWEAK_IMPL (test_tweak_impl_get_type()) -#define TEST_TWEAK_IMPL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TEST_TYPE_TWEAK_IMPL, TestTweakImpl)) -#define TEST_TWEAK_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TEST_TYPE_TWEAK_IMPL, TestTweakImplClass)) -#define TEST_TWEAK_IMPL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TEST_TYPE_TWEAK_IMPL, TestTweakImplClass)) -#define TEST_IS_TWEAK_IMPL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TEST_TYPE_TWEAK_IMPL)) -#define TEST_IS_TWEAK_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TEST_TYPE_TWEAK_IMPL)) - -GType test_tweak_impl_get_type (void); - -typedef struct _TestTweakImpl TestTweakImpl; -typedef struct _TestTweakImplClass TestTweakImplClass; - -struct _TestTweakImpl -{ - GObject parent_instance; - - gchar *some_read_write_property; - gchar *new_foo; - - TestSomeExampleCType property_with_ctype; -}; - -struct _TestTweakImplClass -{ - GObjectClass parent_class; -}; - -enum -{ - PROP_TEST_TWEAK_IMPL_0, - - /* Properties from the TestTweak interface */ - PROP_TEST_TWEAK_FOO, - PROP_TEST_TWEAK_BAR, - PROP_TEST_TWEAK_BAZ, - PROP_TEST_TWEAK_BAZ_FORCED_TO_USE_PAIR, - PROP_TEST_TWEAK_SOME_READ_WRITE_PROPERTY, - PROP_TEST_TWEAK_PROPERTY_WITH_CTYPE, -}; - -static void test_tweak_impl_tweak_iface_init (TestTweakIface *iface); - -G_DEFINE_TYPE_WITH_CODE (TestTweakImpl, test_tweak_impl, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TEST_TYPE_TWEAK, - test_tweak_impl_tweak_iface_init) - ); - -static void -test_tweak_impl_init (TestTweakImpl *tweak_impl) -{ - tweak_impl->some_read_write_property = g_strdup ("Some initial property value"); -} - -static void -test_tweak_impl_finalize (GObject *object) -{ - TestTweakImpl *tweak_impl; - - tweak_impl = TEST_TWEAK_IMPL (object); - - g_free (tweak_impl->some_read_write_property); - g_free (tweak_impl->new_foo); -} - -static void -test_tweak_impl_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - TestTweakImpl *tweak_impl; - - tweak_impl = TEST_TWEAK_IMPL (object); - - switch (prop_id) - { - case PROP_TEST_TWEAK_SOME_READ_WRITE_PROPERTY: - tweak_impl->some_read_write_property = g_value_dup_string (value); - break; - - case PROP_TEST_TWEAK_PROPERTY_WITH_CTYPE: - tweak_impl->property_with_ctype = (TestSomeExampleCType) g_value_get_int (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -test_tweak_impl_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - TestTweakImpl *tweak_impl; - - tweak_impl = TEST_TWEAK_IMPL (object); - - switch (prop_id) - { - case PROP_TEST_TWEAK_FOO: - if (tweak_impl->new_foo != NULL) - g_value_set_string (value, tweak_impl->new_foo); - else - g_value_set_string (value, "a tweaked string"); - break; - - case PROP_TEST_TWEAK_BAR: - { - GArray *array_int32; - guint32 int32_val; - array_int32 = g_array_new (FALSE, FALSE, sizeof (gint32)); - egg_dbus_array_set_elem_signature (array_int32, "i"); - int32_val = 1; g_array_append_val (array_int32, int32_val); - int32_val = 2; g_array_append_val (array_int32, int32_val); - g_value_take_boxed (value, array_int32); - } - break; - - case PROP_TEST_TWEAK_BAZ: - { - TestPoint *point; - point = test_point_new (3, 4); - g_value_take_object (value, point); - } - break; - - case PROP_TEST_TWEAK_BAZ_FORCED_TO_USE_PAIR: - { - TestPair *pair; - pair = test_pair_new (30, 40); - g_value_take_object (value, pair); - } - break; - - case PROP_TEST_TWEAK_SOME_READ_WRITE_PROPERTY: - g_value_set_string (value, tweak_impl->some_read_write_property); - break; - - case PROP_TEST_TWEAK_PROPERTY_WITH_CTYPE: - g_value_set_int (value, (gint) tweak_impl->property_with_ctype); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -test_tweak_impl_class_init (TestTweakImplClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = test_tweak_impl_finalize; - gobject_class->set_property = test_tweak_impl_set_property; - gobject_class->get_property = test_tweak_impl_get_property; - - g_assert (test_tweak_override_properties (gobject_class, PROP_TEST_TWEAK_FOO) == PROP_TEST_TWEAK_PROPERTY_WITH_CTYPE); -} - -static TestTweakImpl * -test_tweak_impl_new (void) -{ - return TEST_TWEAK_IMPL (g_object_new (TEST_TYPE_TWEAK_IMPL, NULL)); -} - -static void -tweak_iface_handle_i_can_haz_greetingz (TestTweak *instance, - const gchar *greetz, - EggDBusMethodInvocation *method_invocation) -{ - gchar *word; - - word = g_strdup_printf ("Word. You haz greetz '%s'. KTHXBYE!", greetz); - - test_tweak_handle_i_can_haz_greetingz_finish (method_invocation, - word); - - g_free (word); -} - -static void -tweak_iface_handle_get_server_unique_name (TestTweak *instance, - EggDBusMethodInvocation *method_invocation) -{ - EggDBusConnection *connection; - const gchar *unique_name; - - connection = egg_dbus_method_invocation_get_connection (method_invocation); - unique_name = egg_dbus_connection_get_unique_name (connection); - - test_tweak_handle_get_server_unique_name_finish (method_invocation, - unique_name); -} - -static void -tweak_iface_handle_broadcastz_newz (TestTweak *instance, - const gchar *newz, - EggDBusMethodInvocation *method_invocation) -{ - gchar *s; - - s = g_strdup_printf ("Word. Broadcastz '%s'. KTHXBYE!", newz); - test_tweak_emit_signal_newz_notifz (instance, - NULL, - s); - - test_tweak_handle_broadcastz_newz_finish (method_invocation); - - g_free (s); -} - -static void -rw_property_changed (TestTweak *instance, - GParamSpec *pspec, - gpointer user_data) -{ - EggDBusMethodInvocation *method_invocation = EGG_DBUS_METHOD_INVOCATION (user_data); - - g_signal_handlers_disconnect_by_func (instance, - (GCallback) rw_property_changed, - method_invocation); - - test_tweak_handle_block_until_rw_property_changes_finish (method_invocation, - TEST_TWEAK_IMPL (instance)->some_read_write_property); -} - -static void -tweak_iface_handle_block_until_rw_property_changes (TestTweak *instance, - EggDBusMethodInvocation *method_invocation) -{ - g_signal_connect (instance, - "notify::some-read-write-property", - (GCallback) rw_property_changed, - method_invocation); -} - -static void -tweak_iface_handle_change_readable_property (TestTweak *instance, - const gchar *new_value, - EggDBusMethodInvocation *method_invocation) -{ - TestTweakImpl *tweak_impl; - - tweak_impl = TEST_TWEAK_IMPL (instance); - - tweak_impl->new_foo = g_strdup (new_value); - g_object_notify (G_OBJECT (tweak_impl), "foo"); - - test_tweak_handle_change_readable_property_finish (method_invocation); -} - -typedef struct { - TestTweak *instance; - EggDBusMethodInvocation *method_invocation; -} LongRunningData; - -static gboolean -long_running_method_timeout_cb (gpointer user_data) -{ - LongRunningData *data = user_data; - - test_tweak_handle_long_running_method_finish (data->method_invocation); - - g_object_unref (data->instance); - g_free (data); - - return FALSE; -} - -static void -tweak_iface_handle_long_running_method (TestTweak *instance, - gint msec_to_run, - EggDBusMethodInvocation *method_invocation) -{ - LongRunningData *data; - - /* TODO: Hmm, would be useful to get the instance from method_invocation */ - data = g_new0 (LongRunningData, 1); - data->instance = g_object_ref (instance); - data->method_invocation = method_invocation; - - g_timeout_add (msec_to_run, - long_running_method_timeout_cb, - data); -} - -static void -tweak_iface_handle_return_gerror (TestTweak *instance, - const gchar *error_domain, - gint error_code, - EggDBusMethodInvocation *method_invocation) -{ - egg_dbus_method_invocation_return_error (method_invocation, - g_quark_from_string (error_domain), - error_code, - "This is the error you requested (domain='%s', error_code=%d).", - error_domain, - error_code); -} - -static void -tweak_iface_handle_method_with_ctypes (TestTweak *instance, - TestSomeExampleCType value, - EggDBusMethodInvocation *method_invocation) -{ - test_tweak_emit_signal_signal_with_ctype (instance, - NULL, - value + 1); - - test_tweak_handle_method_with_ctypes_finish (method_invocation, - value + 1); -} - -static void -test_tweak_impl_tweak_iface_init (TestTweakIface *iface) -{ - iface->handle_i_can_haz_greetingz = tweak_iface_handle_i_can_haz_greetingz; - iface->handle_get_server_unique_name = tweak_iface_handle_get_server_unique_name; - iface->handle_broadcastz_newz = tweak_iface_handle_broadcastz_newz; - iface->handle_block_until_rw_property_changes = tweak_iface_handle_block_until_rw_property_changes; - iface->handle_change_readable_property = tweak_iface_handle_change_readable_property; - iface->handle_long_running_method = tweak_iface_handle_long_running_method; - iface->handle_return_gerror = tweak_iface_handle_return_gerror; - iface->handle_method_with_ctypes = tweak_iface_handle_method_with_ctypes; -} - -/* ---------------------------------------------------------------------------------------------------- */ - - -#define TEST_TYPE_TWIDDLE_IMPL (test_twiddle_impl_get_type()) -#define TEST_TWIDDLE_IMPL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TEST_TYPE_TWIDDLE_IMPL, TestTwiddleImpl)) -#define TEST_TWIDDLE_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TEST_TYPE_TWIDDLE_IMPL, TestTwiddleImplClass)) -#define TEST_TWIDDLE_IMPL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TEST_TYPE_TWIDDLE_IMPL, TestTwiddleImplClass)) -#define TEST_IS_TWIDDLE_IMPL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TEST_TYPE_TWIDDLE_IMPL)) -#define TEST_IS_TWIDDLE_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TEST_TYPE_TWIDDLE_IMPL)) - -GType test_twiddle_impl_get_type (void); - -typedef struct _TestTwiddleImpl TestTwiddleImpl; -typedef struct _TestTwiddleImplClass TestTwiddleImplClass; - -struct _TestTwiddleImpl -{ - GObject parent_instance; - - TestSubject *six; - TestSubject *david; - TestSubject *divad; - TestSubject *god; -}; - -struct _TestTwiddleImplClass -{ - GObjectClass parent_class; -}; - -static void test_twiddle_impl_twiddle_iface_init (TestTwiddleIface *iface); - -G_DEFINE_TYPE_WITH_CODE (TestTwiddleImpl, test_twiddle_impl, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TEST_TYPE_TWIDDLE, - test_twiddle_impl_twiddle_iface_init) - ); - -static void -test_twiddle_impl_init (TestTwiddleImpl *twiddle_impl) -{ - twiddle_impl->god = test_subject_new (TEST_SUBJECT_KIND_DEITY, "God", "deity-snacks", "infrared"); - twiddle_impl->david = test_subject_new (TEST_SUBJECT_KIND_HUMAN, "David", "buffalo chicken pizza", "blue"); - twiddle_impl->six = test_subject_new (TEST_SUBJECT_KIND_CYLON, "Caprica-Six", "baltar-snacks", "red"); - twiddle_impl->divad = test_subject_new (TEST_SUBJECT_KIND_HUMAN, "Divad", "oysters", "black"); -} - -static void -test_twiddle_impl_finalize (GObject *object) -{ - TestTwiddleImpl *twiddle_impl; - - twiddle_impl = TEST_TWIDDLE_IMPL (object); - - g_object_unref (twiddle_impl->god); - g_object_unref (twiddle_impl->david); - g_object_unref (twiddle_impl->six); - g_object_unref (twiddle_impl->divad); -} - -static void -test_twiddle_impl_class_init (TestTwiddleImplClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = test_twiddle_impl_finalize; -} - -static TestTwiddleImpl * -test_twiddle_impl_new (void) -{ - return TEST_TWIDDLE_IMPL (g_object_new (TEST_TYPE_TWIDDLE_IMPL, NULL)); -} - -static void -twiddle_iface_handle_broadcastz_newz (TestTwiddle *instance, - const gchar *newz, - EggDBusMethodInvocation *method_invocation) -{ - gchar *s; - - s = g_strdup_printf ("Sez '%s'. KTHXBYE!", newz); - test_twiddle_emit_signal_newz_notifz (instance, - NULL, - s); - - test_twiddle_handle_broadcastz_newz_finish (method_invocation); - - g_free (s); -} - -static void -twiddle_iface_handle_get_most_powerful_subject (TestTwiddle *instance, - EggDBusMethodInvocation *method_invocation) -{ - TestTwiddleImpl *twiddle_impl; - - twiddle_impl = TEST_TWIDDLE_IMPL (instance); - - test_twiddle_handle_get_most_powerful_subject_finish (method_invocation, - twiddle_impl->god); -} - -static void -twiddle_iface_handle_get_all_subjects (TestTwiddle *instance, - EggDBusMethodInvocation *method_invocation) -{ - GList *l; - TestTwiddleImpl *twiddle_impl; - - twiddle_impl = TEST_TWIDDLE_IMPL (instance); - - l = NULL; - l = g_list_prepend (l, twiddle_impl->divad); - l = g_list_prepend (l, twiddle_impl->six); - l = g_list_prepend (l, twiddle_impl->david); - l = g_list_prepend (l, twiddle_impl->god); - - test_twiddle_handle_get_all_subjects_finish (method_invocation, - l); - - g_list_free (l); -} - -static void -test_twiddle_impl_twiddle_iface_init (TestTwiddleIface *iface) -{ - iface->handle_broadcastz_newz = twiddle_iface_handle_broadcastz_newz; - iface->handle_get_most_powerful_subject = twiddle_iface_handle_get_most_powerful_subject; - iface->handle_get_all_subjects = twiddle_iface_handle_get_all_subjects; -} - -/* ---------------------------------------------------------------------------------------------------- */ +#include "testfrobimpl.h" +#include "testtweakimpl.h" +#include "testtwiddleimpl.h" int main (int argc, char *argv[]) diff --git a/src/tests/testtweakimpl.c b/src/tests/testtweakimpl.c new file mode 100644 index 0000000..3137717 --- /dev/null +++ b/src/tests/testtweakimpl.c @@ -0,0 +1,359 @@ +/* + * Copyright (C) 2008 Red Hat, Inc. + * + * 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, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#include "config.h" +#include <string.h> +#include "testtweakimpl.h" +#include "testbindings.h" +#include "testtypes.h" + +typedef struct +{ + gchar *some_read_write_property; + gchar *new_foo; + + TestSomeExampleCType property_with_ctype; +} TestTweakImplPrivate; + +#define TEST_TWEAK_IMPL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_TYPE_TWEAK_IMPL, TestTweakImplPrivate)) + +enum +{ + PROP_0, + + /* Properties from the TestTweak interface */ + PROP_FOO, + PROP_BAR, + PROP_BAZ, + PROP_BAZ_FORCED_TO_USE_PAIR, + PROP_SOME_READ_WRITE_PROPERTY, + PROP_PROPERTY_WITH_CTYPE, +}; + +static void test_tweak_impl_tweak_iface_init (TestTweakIface *iface); + +G_DEFINE_TYPE_WITH_CODE (TestTweakImpl, test_tweak_impl, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (TEST_TYPE_TWEAK, + test_tweak_impl_tweak_iface_init) + ); + +static void +test_tweak_impl_init (TestTweakImpl *tweak_impl) +{ + TestTweakImplPrivate *priv; + + priv = TEST_TWEAK_IMPL_GET_PRIVATE (tweak_impl); + + priv->some_read_write_property = g_strdup ("Some initial property value"); +} + +static void +test_tweak_impl_finalize (GObject *object) +{ + TestTweakImpl *tweak_impl; + TestTweakImplPrivate *priv; + + tweak_impl = TEST_TWEAK_IMPL (object); + priv = TEST_TWEAK_IMPL_GET_PRIVATE (tweak_impl); + + g_free (priv->some_read_write_property); + g_free (priv->new_foo); +} + +static void +test_tweak_impl_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + TestTweakImpl *tweak_impl; + TestTweakImplPrivate *priv; + + tweak_impl = TEST_TWEAK_IMPL (object); + priv = TEST_TWEAK_IMPL_GET_PRIVATE (tweak_impl); + + switch (prop_id) + { + case PROP_SOME_READ_WRITE_PROPERTY: + priv->some_read_write_property = g_value_dup_string (value); + break; + + case PROP_PROPERTY_WITH_CTYPE: + priv->property_with_ctype = (TestSomeExampleCType) g_value_get_int (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +test_tweak_impl_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + TestTweakImpl *tweak_impl; + TestTweakImplPrivate *priv; + + tweak_impl = TEST_TWEAK_IMPL (object); + priv = TEST_TWEAK_IMPL_GET_PRIVATE (tweak_impl); + + switch (prop_id) + { + case PROP_FOO: + if (priv->new_foo != NULL) + g_value_set_string (value, priv->new_foo); + else + g_value_set_string (value, "a tweaked string"); + break; + + case PROP_BAR: + { + GArray *array_int32; + guint32 int32_val; + array_int32 = g_array_new (FALSE, FALSE, sizeof (gint32)); + egg_dbus_array_set_elem_signature (array_int32, "i"); + int32_val = 1; g_array_append_val (array_int32, int32_val); + int32_val = 2; g_array_append_val (array_int32, int32_val); + g_value_take_boxed (value, array_int32); + } + break; + + case PROP_BAZ: + { + TestPoint *point; + point = test_point_new (3, 4); + g_value_take_object (value, point); + } + break; + + case PROP_BAZ_FORCED_TO_USE_PAIR: + { + TestPair *pair; + pair = test_pair_new (30, 40); + g_value_take_object (value, pair); + } + break; + + case PROP_SOME_READ_WRITE_PROPERTY: + g_value_set_string (value, priv->some_read_write_property); + break; + + case PROP_PROPERTY_WITH_CTYPE: + g_value_set_int (value, (gint) priv->property_with_ctype); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +test_tweak_impl_class_init (TestTweakImplClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = test_tweak_impl_finalize; + gobject_class->set_property = test_tweak_impl_set_property; + gobject_class->get_property = test_tweak_impl_get_property; + + g_assert (test_tweak_override_properties (gobject_class, PROP_FOO) == PROP_PROPERTY_WITH_CTYPE); + + g_type_class_add_private (klass, sizeof (TestTweakImplPrivate)); +} + +TestTweakImpl * +test_tweak_impl_new (void) +{ + return TEST_TWEAK_IMPL (g_object_new (TEST_TYPE_TWEAK_IMPL, NULL)); +} + +static void +tweak_iface_handle_i_can_haz_greetingz (TestTweak *instance, + const gchar *greetz, + EggDBusMethodInvocation *method_invocation) +{ + gchar *word; + + word = g_strdup_printf ("Word. You haz greetz '%s'. KTHXBYE!", greetz); + + test_tweak_handle_i_can_haz_greetingz_finish (method_invocation, + word); + + g_free (word); +} + +static void +tweak_iface_handle_get_server_unique_name (TestTweak *instance, + EggDBusMethodInvocation *method_invocation) +{ + EggDBusConnection *connection; + const gchar *unique_name; + + connection = egg_dbus_method_invocation_get_connection (method_invocation); + unique_name = egg_dbus_connection_get_unique_name (connection); + + test_tweak_handle_get_server_unique_name_finish (method_invocation, + unique_name); +} + +static void +tweak_iface_handle_broadcastz_newz (TestTweak *instance, + const gchar *newz, + EggDBusMethodInvocation *method_invocation) +{ + gchar *s; + + s = g_strdup_printf ("Word. Broadcastz '%s'. KTHXBYE!", newz); + test_tweak_emit_signal_newz_notifz (instance, + NULL, + s); + + test_tweak_handle_broadcastz_newz_finish (method_invocation); + + g_free (s); +} + +static void +rw_property_changed (TestTweak *instance, + GParamSpec *pspec, + gpointer user_data) +{ + TestTweakImpl *tweak_impl; + TestTweakImplPrivate *priv; + EggDBusMethodInvocation *method_invocation; + + tweak_impl = TEST_TWEAK_IMPL (instance); + priv = TEST_TWEAK_IMPL_GET_PRIVATE (tweak_impl); + method_invocation = EGG_DBUS_METHOD_INVOCATION (user_data); + + g_signal_handlers_disconnect_by_func (instance, + (GCallback) rw_property_changed, + method_invocation); + + test_tweak_handle_block_until_rw_property_changes_finish (method_invocation, + priv->some_read_write_property); +} + +static void +tweak_iface_handle_block_until_rw_property_changes (TestTweak *instance, + EggDBusMethodInvocation *method_invocation) +{ + g_signal_connect (instance, + "notify::some-read-write-property", + (GCallback) rw_property_changed, + method_invocation); +} + +static void +tweak_iface_handle_change_readable_property (TestTweak *instance, + const gchar *new_value, + EggDBusMethodInvocation *method_invocation) +{ + TestTweakImpl *tweak_impl; + TestTweakImplPrivate *priv; + + tweak_impl = TEST_TWEAK_IMPL (instance); + priv = TEST_TWEAK_IMPL_GET_PRIVATE (tweak_impl); + + priv->new_foo = g_strdup (new_value); + g_object_notify (G_OBJECT (tweak_impl), "foo"); + + test_tweak_handle_change_readable_property_finish (method_invocation); +} + +typedef struct { + TestTweak *instance; + EggDBusMethodInvocation *method_invocation; +} LongRunningData; + +static gboolean +long_running_method_timeout_cb (gpointer user_data) +{ + LongRunningData *data = user_data; + + test_tweak_handle_long_running_method_finish (data->method_invocation); + + g_object_unref (data->instance); + g_free (data); + + return FALSE; +} + +static void +tweak_iface_handle_long_running_method (TestTweak *instance, + gint msec_to_run, + EggDBusMethodInvocation *method_invocation) +{ + LongRunningData *data; + + /* TODO: Hmm, would be useful to get the instance from method_invocation */ + data = g_new0 (LongRunningData, 1); + data->instance = g_object_ref (instance); + data->method_invocation = method_invocation; + + g_timeout_add (msec_to_run, + long_running_method_timeout_cb, + data); +} + +static void +tweak_iface_handle_return_gerror (TestTweak *instance, + const gchar *error_domain, + gint error_code, + EggDBusMethodInvocation *method_invocation) +{ + egg_dbus_method_invocation_return_error (method_invocation, + g_quark_from_string (error_domain), + error_code, + "This is the error you requested (domain='%s', error_code=%d).", + error_domain, + error_code); +} + +static void +tweak_iface_handle_method_with_ctypes (TestTweak *instance, + TestSomeExampleCType value, + EggDBusMethodInvocation *method_invocation) +{ + test_tweak_emit_signal_signal_with_ctype (instance, + NULL, + value + 1); + + test_tweak_handle_method_with_ctypes_finish (method_invocation, + value + 1); +} + +static void +test_tweak_impl_tweak_iface_init (TestTweakIface *iface) +{ + iface->handle_i_can_haz_greetingz = tweak_iface_handle_i_can_haz_greetingz; + iface->handle_get_server_unique_name = tweak_iface_handle_get_server_unique_name; + iface->handle_broadcastz_newz = tweak_iface_handle_broadcastz_newz; + iface->handle_block_until_rw_property_changes = tweak_iface_handle_block_until_rw_property_changes; + iface->handle_change_readable_property = tweak_iface_handle_change_readable_property; + iface->handle_long_running_method = tweak_iface_handle_long_running_method; + iface->handle_return_gerror = tweak_iface_handle_return_gerror; + iface->handle_method_with_ctypes = tweak_iface_handle_method_with_ctypes; +} diff --git a/src/tests/testtweakimpl.h b/src/tests/testtweakimpl.h new file mode 100644 index 0000000..8202f9b --- /dev/null +++ b/src/tests/testtweakimpl.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2008 Red Hat, Inc. + * + * 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, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#ifndef __TEST_TWEAK_IMPL_H +#define __TEST_TWEAK_IMPL_H + +#include <eggdbus/eggdbus.h> + +G_BEGIN_DECLS + +#define TEST_TYPE_TWEAK_IMPL (test_tweak_impl_get_type()) +#define TEST_TWEAK_IMPL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TEST_TYPE_TWEAK_IMPL, TestTweakImpl)) +#define TEST_TWEAK_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TEST_TYPE_TWEAK_IMPL, TestTweakImplClass)) +#define TEST_TWEAK_IMPL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TEST_TYPE_TWEAK_IMPL, TestTweakImplClass)) +#define TEST_IS_TWEAK_IMPL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TEST_TYPE_TWEAK_IMPL)) +#define TEST_IS_TWEAK_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TEST_TYPE_TWEAK_IMPL)) + +typedef struct _TestTweakImpl TestTweakImpl; +typedef struct _TestTweakImplClass TestTweakImplClass; + +struct _TestTweakImpl +{ + GObject parent_instance; +}; + +struct _TestTweakImplClass +{ + GObjectClass parent_class; +}; + +GType test_tweak_impl_get_type (void) G_GNUC_CONST; +TestTweakImpl *test_tweak_impl_new (void); + +G_END_DECLS + +#endif /* __TEST_TWEAK_IMPL_H */ diff --git a/src/tests/testtwiddleimpl.c b/src/tests/testtwiddleimpl.c new file mode 100644 index 0000000..d96e08a --- /dev/null +++ b/src/tests/testtwiddleimpl.c @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2008 Red Hat, Inc. + * + * 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, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#include "config.h" +#include <string.h> +#include "testtwiddleimpl.h" +#include "testbindings.h" +#include "testsubject.h" + +typedef struct +{ + TestSubject *six; + TestSubject *david; + TestSubject *divad; + TestSubject *god; +} TestTwiddleImplPrivate; + +#define TEST_TWIDDLE_IMPL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_TYPE_TWIDDLE_IMPL, TestTwiddleImplPrivate)) + +static void test_twiddle_impl_twiddle_iface_init (TestTwiddleIface *iface); + +G_DEFINE_TYPE_WITH_CODE (TestTwiddleImpl, test_twiddle_impl, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (TEST_TYPE_TWIDDLE, + test_twiddle_impl_twiddle_iface_init) + ); + +static void +test_twiddle_impl_init (TestTwiddleImpl *twiddle_impl) +{ + TestTwiddleImplPrivate *priv; + + priv = TEST_TWIDDLE_IMPL_GET_PRIVATE (twiddle_impl); + + priv->god = test_subject_new (TEST_SUBJECT_KIND_DEITY, "God", "deity-snacks", "infrared"); + priv->david = test_subject_new (TEST_SUBJECT_KIND_HUMAN, "David", "buffalo chicken pizza", "blue"); + priv->six = test_subject_new (TEST_SUBJECT_KIND_CYLON, "Caprica-Six", "baltar-snacks", "red"); + priv->divad = test_subject_new (TEST_SUBJECT_KIND_HUMAN, "Divad", "oysters", "black"); +} + +static void +test_twiddle_impl_finalize (GObject *object) +{ + TestTwiddleImpl *twiddle_impl; + TestTwiddleImplPrivate *priv; + + twiddle_impl = TEST_TWIDDLE_IMPL (object); + priv = TEST_TWIDDLE_IMPL_GET_PRIVATE (twiddle_impl); + + g_object_unref (priv->god); + g_object_unref (priv->david); + g_object_unref (priv->six); + g_object_unref (priv->divad); +} + +static void +test_twiddle_impl_class_init (TestTwiddleImplClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = test_twiddle_impl_finalize; + + g_type_class_add_private (klass, sizeof (TestTwiddleImplPrivate)); +} + +TestTwiddleImpl * +test_twiddle_impl_new (void) +{ + return TEST_TWIDDLE_IMPL (g_object_new (TEST_TYPE_TWIDDLE_IMPL, NULL)); +} + +static void +twiddle_iface_handle_broadcastz_newz (TestTwiddle *instance, + const gchar *newz, + EggDBusMethodInvocation *method_invocation) +{ + gchar *s; + + s = g_strdup_printf ("Sez '%s'. KTHXBYE!", newz); + test_twiddle_emit_signal_newz_notifz (instance, + NULL, + s); + + test_twiddle_handle_broadcastz_newz_finish (method_invocation); + + g_free (s); +} + +static void +twiddle_iface_handle_get_most_powerful_subject (TestTwiddle *instance, + EggDBusMethodInvocation *method_invocation) +{ + TestTwiddleImpl *twiddle_impl; + TestTwiddleImplPrivate *priv; + + twiddle_impl = TEST_TWIDDLE_IMPL (instance); + priv = TEST_TWIDDLE_IMPL_GET_PRIVATE (twiddle_impl); + + test_twiddle_handle_get_most_powerful_subject_finish (method_invocation, + priv->god); +} + +static void +twiddle_iface_handle_get_all_subjects (TestTwiddle *instance, + EggDBusMethodInvocation *method_invocation) +{ + GList *l; + TestTwiddleImpl *twiddle_impl; + TestTwiddleImplPrivate *priv; + + twiddle_impl = TEST_TWIDDLE_IMPL (instance); + priv = TEST_TWIDDLE_IMPL_GET_PRIVATE (twiddle_impl); + + l = NULL; + l = g_list_prepend (l, priv->divad); + l = g_list_prepend (l, priv->six); + l = g_list_prepend (l, priv->david); + l = g_list_prepend (l, priv->god); + + test_twiddle_handle_get_all_subjects_finish (method_invocation, + l); + + g_list_free (l); +} + +static void +test_twiddle_impl_twiddle_iface_init (TestTwiddleIface *iface) +{ + iface->handle_broadcastz_newz = twiddle_iface_handle_broadcastz_newz; + iface->handle_get_most_powerful_subject = twiddle_iface_handle_get_most_powerful_subject; + iface->handle_get_all_subjects = twiddle_iface_handle_get_all_subjects; +} diff --git a/src/tests/testtwiddleimpl.h b/src/tests/testtwiddleimpl.h new file mode 100644 index 0000000..2d76dc0 --- /dev/null +++ b/src/tests/testtwiddleimpl.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2008 Red Hat, Inc. + * + * 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, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#ifndef __TEST_TWIDDLE_IMPL_H +#define __TEST_TWIDDLE_IMPL_H + +#include <eggdbus/eggdbus.h> + +G_BEGIN_DECLS + +#define TEST_TYPE_TWIDDLE_IMPL (test_twiddle_impl_get_type()) +#define TEST_TWIDDLE_IMPL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TEST_TYPE_TWIDDLE_IMPL, TestTwiddleImpl)) +#define TEST_TWIDDLE_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TEST_TYPE_TWIDDLE_IMPL, TestTwiddleImplClass)) +#define TEST_TWIDDLE_IMPL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TEST_TYPE_TWIDDLE_IMPL, TestTwiddleImplClass)) +#define TEST_IS_TWIDDLE_IMPL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TEST_TYPE_TWIDDLE_IMPL)) +#define TEST_IS_TWIDDLE_IMPL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TEST_TYPE_TWIDDLE_IMPL)) + +typedef struct _TestTwiddleImpl TestTwiddleImpl; +typedef struct _TestTwiddleImplClass TestTwiddleImplClass; + +struct _TestTwiddleImpl +{ + GObject parent_instance; +}; + +struct _TestTwiddleImplClass +{ + GObjectClass parent_class; +}; + +GType test_twiddle_impl_get_type (void) G_GNUC_CONST; +TestTwiddleImpl *test_twiddle_impl_new (void); + +G_END_DECLS + +#endif /* __TEST_TWIDDLE_IMPL_H */ |