You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2010/11/26 11:17:50 UTC

svn commit: r1039299 [3/3] - in /thrift/trunk: ./ lib/c_glib/ lib/c_glib/src/ lib/c_glib/src/processor/ lib/c_glib/src/protocol/ lib/c_glib/src/server/ lib/c_glib/src/transport/ lib/c_glib/test/

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_socket.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_socket.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_socket.c (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_socket.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include <errno.h>
 #include <netdb.h>
 #include <stdlib.h>
@@ -19,156 +38,7 @@ enum _ThriftSocketProperties
 /* for errors coming from socket() and connect() */
 extern int errno;
 
-/* forward declarations */
-static void thrift_socket_instance_init (ThriftSocket *self);
-static void thrift_socket_class_init (ThriftSocketClass *cls);
-
-gboolean thrift_socket_is_open (ThriftTransport *transport);
-gboolean thrift_socket_open (ThriftTransport *transport, GError **error);
-gboolean thrift_socket_close (ThriftTransport *transport, GError **error);
-gint32 thrift_socket_read (ThriftTransport *transport, gpointer buf,
-                           guint32 len, GError **error);
-gboolean thrift_socket_read_end (ThriftTransport *transport, GError **error);
-gboolean thrift_socket_write (ThriftTransport *transport, const gpointer buf,
-                              const guint32 len, GError **error);
-gboolean thrift_socket_write_end (ThriftTransport *transport, GError **error);
-gboolean thrift_socket_flush (ThriftTransport *transport, GError **error);
-
-GType
-thrift_socket_get_type (void)
-{
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo info =
-    {
-      sizeof (ThriftSocketClass),
-      NULL, /* base_init */
-      NULL, /* base_finalize */
-      (GClassInitFunc) thrift_socket_class_init,
-      NULL, /* class finalize */
-      NULL, /* class data */
-      sizeof (ThriftSocket),
-      0, /* n_preallocs */
-      (GInstanceInitFunc) thrift_socket_instance_init,
-      NULL, /* value_table */
-    };
-
-    type = g_type_register_static (THRIFT_TYPE_TRANSPORT,
-                                   "ThriftSocket", &info, 0);
-  }
-
-  return type;
-}
-
-/* initializes the instance */
-static void
-thrift_socket_instance_init (ThriftSocket *socket)
-{
-  socket->sd = 0;
-}
-
-/* destructor */
-static void
-thrift_socket_finalize (GObject *object)
-{
-  ThriftSocket *socket = THRIFT_SOCKET (object);
-
-  if (socket->hostname != NULL)
-  {
-    g_free (socket->hostname);
-  }
-  socket->hostname = NULL;
-
-  if (socket->sd != 0)
-  {
-    close (socket->sd);
-  }
-  socket->sd = 0;
-}
-
-/* property accessor */
-void
-thrift_socket_get_property (GObject *object, guint property_id,
-                            GValue *value, GParamSpec *pspec)
-{
-  THRIFT_UNUSED_VAR (pspec);
-  ThriftSocket *socket = THRIFT_SOCKET (object);
-
-  switch (property_id)
-  {
-    case PROP_THRIFT_SOCKET_HOSTNAME:
-      g_value_set_string (value, socket->hostname);
-      break;
-    case PROP_THRIFT_SOCKET_PORT:
-      g_value_set_uint (value, socket->port);
-      break;
-  }
-}
-
-/* property mutator */
-void
-thrift_socket_set_property (GObject *object, guint property_id,
-                            const GValue *value, GParamSpec *pspec)
-{
-  THRIFT_UNUSED_VAR (pspec);
-  ThriftSocket *socket = THRIFT_SOCKET (object);
-
-  switch (property_id)
-  {
-    case PROP_THRIFT_SOCKET_HOSTNAME:
-      socket->hostname = g_strdup (g_value_get_string (value));
-      break;
-    case PROP_THRIFT_SOCKET_PORT:
-      socket->port = g_value_get_uint (value);
-      break;
-  }
-}
-
-/* initializes the class */
-static void
-thrift_socket_class_init (ThriftSocketClass *cls)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
-  GParamSpec *param_spec = NULL;
-
-  /* setup accessors and mutators */
-  gobject_class->get_property = thrift_socket_get_property;
-  gobject_class->set_property = thrift_socket_set_property;
-
-  param_spec = g_param_spec_string ("hostname",
-                                    "hostname (construct)",
-                                    "Set the hostname of the remote host",
-                                    "localhost", /* default value */
-                                    G_PARAM_CONSTRUCT_ONLY |
-                                    G_PARAM_READWRITE);
-  g_object_class_install_property (gobject_class, PROP_THRIFT_SOCKET_HOSTNAME, 
-                                   param_spec);
-
-  param_spec = g_param_spec_uint ("port",
-                                  "port (construct)",
-                                  "Set the port of the remote host",
-                                  0, /* min */
-                                  65534, /* max */
-                                  9090, /* default by convention */
-                                  G_PARAM_CONSTRUCT_ONLY |
-                                  G_PARAM_READWRITE);
-  g_object_class_install_property (gobject_class, PROP_THRIFT_SOCKET_PORT, 
-                                   param_spec);
-
-  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
-
-  gobject_class->finalize = thrift_socket_finalize;
-  ttc->is_open = thrift_socket_is_open;
-  ttc->open = thrift_socket_open;
-  ttc->close = thrift_socket_close;
-  ttc->read = thrift_socket_read;
-  ttc->read_end = thrift_socket_read_end;
-  ttc->write = thrift_socket_write;
-  ttc->write_end = thrift_socket_write_end;
-  ttc->flush = thrift_socket_flush;
-}
+G_DEFINE_TYPE(ThriftSocket, thrift_socket, THRIFT_TYPE_TRANSPORT)
 
 /* implements thrift_transport_is_open */
 gboolean
@@ -331,4 +201,110 @@ thrift_socket_flush (ThriftTransport *tr
   return TRUE;
 }
 
+/* initializes the instance */
+static void
+thrift_socket_init (ThriftSocket *socket)
+{
+  socket->sd = 0;
+}
+
+/* destructor */
+static void
+thrift_socket_finalize (GObject *object)
+{
+  ThriftSocket *socket = THRIFT_SOCKET (object);
+
+  if (socket->hostname != NULL)
+  {
+    g_free (socket->hostname);
+  }
+  socket->hostname = NULL;
 
+  if (socket->sd != 0)
+  {
+    close (socket->sd);
+  }
+  socket->sd = 0;
+}
+
+/* property accessor */
+void
+thrift_socket_get_property (GObject *object, guint property_id,
+                            GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftSocket *socket = THRIFT_SOCKET (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_SOCKET_HOSTNAME:
+      g_value_set_string (value, socket->hostname);
+      break;
+    case PROP_THRIFT_SOCKET_PORT:
+      g_value_set_uint (value, socket->port);
+      break;
+  }
+}
+
+/* property mutator */
+void
+thrift_socket_set_property (GObject *object, guint property_id,
+                            const GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftSocket *socket = THRIFT_SOCKET (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_SOCKET_HOSTNAME:
+      socket->hostname = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_THRIFT_SOCKET_PORT:
+      socket->port = g_value_get_uint (value);
+      break;
+  }
+}
+
+/* initializes the class */
+static void
+thrift_socket_class_init (ThriftSocketClass *cls)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
+  GParamSpec *param_spec = NULL;
+
+  /* setup accessors and mutators */
+  gobject_class->get_property = thrift_socket_get_property;
+  gobject_class->set_property = thrift_socket_set_property;
+
+  param_spec = g_param_spec_string ("hostname",
+                                    "hostname (construct)",
+                                    "Set the hostname of the remote host",
+                                    "localhost", /* default value */
+                                    G_PARAM_CONSTRUCT_ONLY |
+                                    G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class, PROP_THRIFT_SOCKET_HOSTNAME,
+                                   param_spec);
+
+  param_spec = g_param_spec_uint ("port",
+                                  "port (construct)",
+                                  "Set the port of the remote host",
+                                  0, /* min */
+                                  65534, /* max */
+                                  9090, /* default by convention */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class, PROP_THRIFT_SOCKET_PORT,
+                                   param_spec);
+
+  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
+
+  gobject_class->finalize = thrift_socket_finalize;
+  ttc->is_open = thrift_socket_is_open;
+  ttc->open = thrift_socket_open;
+  ttc->close = thrift_socket_close;
+  ttc->read = thrift_socket_read;
+  ttc->read_end = thrift_socket_read_end;
+  ttc->write = thrift_socket_write;
+  ttc->write_end = thrift_socket_write_end;
+  ttc->flush = thrift_socket_flush;
+}

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_socket.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_socket.h?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_socket.h (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_socket.h Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #ifndef _THRIFT_SOCKET_H
 #define _THRIFT_SOCKET_H
 
@@ -5,6 +24,8 @@
 
 #include "transport/thrift_transport.h"
 
+G_BEGIN_DECLS
+
 /*! \file thrift_socket.h
  *  \brief Socket implementation of a Thrift transport.  Subclasses the
  *         ThriftTransport class.
@@ -12,17 +33,11 @@
 
 /* type macros */
 #define THRIFT_TYPE_SOCKET (thrift_socket_get_type ())
-#define THRIFT_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                THRIFT_TYPE_SOCKET, ThriftSocket))
-#define THRIFT_IS_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                   THRIFT_TYPE_SOCKET))
-#define THRIFT_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                    THRIFT_TYPE_SOCKET, ThriftSocketClass))
-#define THRIFT_IS_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                       THRIFT_TYPE_SOCKET))
-#define THRIFT_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-                                          THRIFT_TYPE_SOCKET, \
-                                          ThriftSocketClass))
+#define THRIFT_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SOCKET, ThriftSocket))
+#define THRIFT_IS_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SOCKET))
+#define THRIFT_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_SOCKET, ThriftSocketClass))
+#define THRIFT_IS_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SOCKET))
+#define THRIFT_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SOCKET, ThriftSocketClass))
 
 /*!
  * Thrift Socket instance.
@@ -53,4 +68,6 @@ typedef struct _ThriftSocketClass Thrift
 /* used by THRIFT_TYPE_SOCKET */
 GType thrift_socket_get_type (void);
 
+G_END_DECLS
+
 #endif

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_transport.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_transport.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_transport.c (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_transport.c Fri Nov 26 10:17:48 2010
@@ -1,55 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include "thrift.h"
 #include "transport/thrift_transport.h"
 
 /* define the GError domain string */
 #define THRIFT_TRANSPORT_ERROR_DOMAIN "thrift-transport-error-quark"
 
-/* forward declarations */
-static void thrift_transport_class_init (ThriftTransportClass *cls);
-
-/* define ThriftTransportInterface's type */
-GType
-thrift_transport_get_type (void)
-{
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo info =
-    {
-      sizeof (ThriftTransportClass),
-      NULL, /* base_init */
-      NULL, /* base_finalize */
-      (GClassInitFunc) thrift_transport_class_init,
-      NULL, /* class_finalize */
-      NULL, /* class_data */
-      sizeof (ThriftTransport),
-      0, /* n_preallocs */
-      NULL, /* instance_init */
-      NULL, /* value_table */
-    };
-
-    type = g_type_register_static (G_TYPE_OBJECT, "ThriftTransport",
-                                   &info, G_TYPE_FLAG_ABSTRACT);
-  }
-
-  return type;
-}
-
-/* class initializer for ThriftTransport */
-static void
-thrift_transport_class_init (ThriftTransportClass *cls)
-{
-  /* set these as virtual methods to be implemented by a subclass */
-  cls->is_open = thrift_transport_is_open;
-  cls->open = thrift_transport_open;
-  cls->close = thrift_transport_close;
-  cls->read = thrift_transport_read;
-  cls->read_end = thrift_transport_read_end;
-  cls->write = thrift_transport_write;
-  cls->write_end = thrift_transport_write_end;
-  cls->flush = thrift_transport_flush;
-}
+G_DEFINE_ABSTRACT_TYPE(ThriftTransport, thrift_transport, G_TYPE_OBJECT)
 
 gboolean 
 thrift_transport_is_open (ThriftTransport *transport)
@@ -112,3 +86,23 @@ thrift_transport_error_quark (void)
   return g_quark_from_static_string (THRIFT_TRANSPORT_ERROR_DOMAIN);
 }
 
+/* class initializer for ThriftTransport */
+static void
+thrift_transport_class_init (ThriftTransportClass *cls)
+{
+  /* set these as virtual methods to be implemented by a subclass */
+  cls->is_open = thrift_transport_is_open;
+  cls->open = thrift_transport_open;
+  cls->close = thrift_transport_close;
+  cls->read = thrift_transport_read;
+  cls->read_end = thrift_transport_read_end;
+  cls->write = thrift_transport_write;
+  cls->write_end = thrift_transport_write_end;
+  cls->flush = thrift_transport_flush;
+}
+
+static void
+thrift_transport_init (ThriftTransport *transport)
+{
+  THRIFT_UNUSED_VAR (transport);
+}

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_transport.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_transport.h?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_transport.h (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_transport.h Fri Nov 26 10:17:48 2010
@@ -1,8 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #ifndef _THRIFT_TRANSPORT_H
 #define _THRIFT_TRANSPORT_H
 
 #include <glib-object.h>
 
+G_BEGIN_DECLS
+
 /*! \file thrift_transport.h
  *  \brief Abstract class for Thrift transports.
  *
@@ -13,20 +34,13 @@
  *    is necessary.
  */
 
-/* type macros */	
+/* type macros */
 #define THRIFT_TYPE_TRANSPORT (thrift_transport_get_type ())
-#define THRIFT_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                   THRIFT_TYPE_TRANSPORT, ThriftTransport))
-#define THRIFT_IS_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                      THRIFT_TYPE_TRANSPORT))
-#define THRIFT_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                       THRIFT_TYPE_TRANSPORT, \
-                                       ThriftTransportClass))
-#define THRIFT_IS_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                          THRIFT_TYPE_TRANSPORT))
-#define THRIFT_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-                                             THRIFT_TYPE_TRANSPORT, \
-                                             ThriftTransportClass))
+#define THRIFT_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_TRANSPORT, ThriftTransport))
+#define THRIFT_IS_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_TRANSPORT))
+#define THRIFT_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_TRANSPORT, ThriftTransportClass))
+#define THRIFT_IS_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_TRANSPORT))
+#define THRIFT_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_TRANSPORT, ThriftTransportClass))
 
 /*!
  * Thrift Protocol object
@@ -45,7 +59,7 @@ struct _ThriftTransportClass
   GObjectClass parent;
 
   /* vtable */
-  gboolean (*is_open) (ThriftTransport *transport); 
+  gboolean (*is_open) (ThriftTransport *transport);
   gboolean (*open) (ThriftTransport *transport, GError **error);
   gboolean (*close) (ThriftTransport *transport, GError **error);
   gint32 (*read) (ThriftTransport *transport, gpointer buf,
@@ -59,7 +73,7 @@ struct _ThriftTransportClass
 typedef struct _ThriftTransportClass ThriftTransportClass;
 
 /* used by THRIFT_TYPE_TRANSPORT */
-GType thrift_transport_get_type (void); 
+GType thrift_transport_get_type (void);
 
 /* virtual public methods */
 
@@ -67,7 +81,7 @@ GType thrift_transport_get_type (void); 
  * Checks if this transport is opened.
  * \public \memberof ThriftTransportInterface
  */
-gboolean thrift_transport_is_open (ThriftTransport *transport); 
+gboolean thrift_transport_is_open (ThriftTransport *transport);
 
 /*!
  * Open the transport for reading and writing.
@@ -105,7 +119,7 @@ gboolean thrift_transport_write (ThriftT
  * Called when write is completed.
  * \public \memberof ThriftTransportInterface
  */
-gboolean thrift_transport_write_end (ThriftTransport *transport, 
+gboolean thrift_transport_write_end (ThriftTransport *transport,
                                      GError **error);
 
 /*!
@@ -131,5 +145,6 @@ typedef enum
 GQuark thrift_transport_error_quark (void);
 #define THRIFT_TRANSPORT_ERROR (thrift_transport_error_quark ())
 
+G_END_DECLS
 
 #endif /* _THRIFT_TRANSPORT_H */

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_transport_factory.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_transport_factory.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_transport_factory.c (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_transport_factory.c Fri Nov 26 10:17:48 2010
@@ -1,35 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include "thrift.h"
 #include "transport/thrift_transport_factory.h"
 
-/* forward declaration s*/
-static void thrift_transport_factory_class_init (ThriftTransportFactoryClass *cls);
-ThriftTransport *thrift_transport_factory_get_transport (ThriftTransportFactory *factory, ThriftTransport *transport);
+G_DEFINE_TYPE(ThriftTransportFactory, thrift_transport_factory, G_TYPE_OBJECT)
 
-GType
-thrift_transport_factory_get_type (void)
+/* builds a transport from the base transport. */
+ThriftTransport *
+thrift_transport_factory_get_transport (ThriftTransportFactory *factory,
+                                        ThriftTransport *transport)
 {
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo info = {
-      sizeof (ThriftTransportFactoryClass),
-      NULL, /* base_init */
-      NULL, /* base_finalize */
-      (GClassInitFunc) thrift_transport_factory_class_init,
-      NULL, /* class_finalize */
-      NULL, /* class_data */
-      sizeof (ThriftTransportFactory),
-      0, /* n_preallocs */
-      NULL, /* instance_init */
-      NULL, /* value_table */
-    };
-
-    type = g_type_register_static (G_TYPE_OBJECT, "ThriftTransportFactory",
-                                   &info, 0);
-  }
-
-  return type;
+  THRIFT_UNUSED_VAR (factory);
+  return transport;
 }
 
 static void
@@ -38,14 +37,8 @@ thrift_transport_factory_class_init (Thr
   cls->get_transport = thrift_transport_factory_get_transport;
 }
 
-/* builds a transport from the base transport. */
-ThriftTransport *
-thrift_transport_factory_get_transport (ThriftTransportFactory *factory,
-                                        ThriftTransport *transport)
+static void
+thrift_transport_factory_init (ThriftTransportFactory *factory)
 {
   THRIFT_UNUSED_VAR (factory);
-  return transport;
 }
-
-
-

Modified: thrift/trunk/lib/c_glib/src/transport/thrift_transport_factory.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/src/transport/thrift_transport_factory.h?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/src/transport/thrift_transport_factory.h (original)
+++ thrift/trunk/lib/c_glib/src/transport/thrift_transport_factory.h Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #ifndef _THRIFT_TRANSPORT_FACTORY_H
 #define _THRIFT_TRANSPORT_FACTORY_H
 
@@ -5,6 +24,8 @@
 
 #include "thrift_transport.h"
 
+G_BEGIN_DECLS
+
 /*! \file thrift_transport_factory.h
  *  \brief Base class for Thrift Transport Factories.  Used by Thrift Servers
  *         to obtain a client transport from an existing transport.  The default
@@ -13,19 +34,11 @@
 
 /* type macros */
 #define THRIFT_TYPE_TRANSPORT_FACTORY (thrift_transport_factory_get_type ())
-#define THRIFT_TRANSPORT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                           THRIFT_TYPE_TRANSPORT_FACTORY, \
-                                           ThriftTransportFactory))
-#define THRIFT_IS_TRANSPORT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                           THRIFT_TYPE_TRANSPORT_FACTORY))
-#define THRIFT_TRANSPORT_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                               THRIFT_TYPE_TRANSPORT_FACTORY, \
-                                               ThriftTransportFactoryClass))
-#define THRIFT_IS_TRANSPORT_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                                  THRIFT_TYPE_TRANSPORT_FACTORY))
-#define THRIFT_TRANSPORT_FACTORY_GET_CLASS(obj) \
-            (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_TRANSPORT_FACTORY, \
-                                        ThriftTransportFactoryClass))
+#define THRIFT_TRANSPORT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_TRANSPORT_FACTORY, ThriftTransportFactory))
+#define THRIFT_IS_TRANSPORT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_TRANSPORT_FACTORY))
+#define THRIFT_TRANSPORT_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_TRANSPORT_FACTORY, ThriftTransportFactoryClass))
+#define THRIFT_IS_TRANSPORT_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_TRANSPORT_FACTORY))
+#define THRIFT_TRANSPORT_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_TRANSPORT_FACTORY, ThriftTransportFactoryClass))
 
 /* Thrift Transport Factory instance */
 struct _ThriftTransportFactory
@@ -51,5 +64,6 @@ GType thrift_transport_factory_get_type 
 /* virtual public methods */
 ThriftTransport *thrift_transport_factory_get_transport (ThriftTransportFactory *factory, ThriftTransport *transport);
 
+G_END_DECLS
 
 #endif /* _THRIFT_TRANSPORT_FACTORY_H */

Propchange: thrift/trunk/lib/c_glib/test/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Nov 26 10:17:48 2010
@@ -20,3 +20,4 @@ testframedtransport
 testbufferedtransport
 testprotocolbinary
 testdebugproto
+testbinaryprotocol

Modified: thrift/trunk/lib/c_glib/test/Makefile.am
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/Makefile.am?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/Makefile.am (original)
+++ thrift/trunk/lib/c_glib/test/Makefile.am Fri Nov 26 10:17:48 2010
@@ -6,25 +6,9 @@ AM_LDFLAGS = $(GLIB_LIBS) $(GOBJECT_LIBS
 CFLAGS = @GCOV_CFLAGS@
 CXXFLAGS = -g
 
-check_SCRIPTS = \
-  testwrapper-testtransportsocket \
-  testwrapper-testprotocolbinary \
-  testwrapper-testbufferedtransport \
-  testwrapper-testframedtransport \
-  testwrapper-testmemorybuffer \
-  testwrapper-teststruct \
-  testwrapper-testsimpleserver \
-  testwrapper-testdebugproto \
-  testwrapper-testoptionalrequired \
-  testwrapper-testthrifttest
-
-if WITH_CPP
-  check_SCRIPTS += testwrapper-testthrifttestclient
-endif
-
 check_PROGRAMS = \
   testtransportsocket \
-  testprotocolbinary \
+  testbinaryprotocol \
   testbufferedtransport \
   testframedtransport \
   testmemorybuffer \
@@ -44,8 +28,8 @@ testtransportsocket_LDADD = \
     ../libthrift_c_glib_la-thrift_server_transport.o \
     ../libthrift_c_glib_la-thrift_server_socket.o
 
-testprotocolbinary_SOURCES = testprotocolbinary.c
-testprotocolbinary_LDADD = \
+testbinaryprotocol_SOURCES = testbinaryprotocol.c
+testbinaryprotocol_LDADD = \
     ../libthrift_c_glib_la-thrift_protocol.o \
     ../libthrift_c_glib_la-thrift_transport.o \
     ../libthrift_c_glib_la-thrift_socket.o \
@@ -158,9 +142,7 @@ gen-c_glib/t_test_second_service.c gen-c
 gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest.h: ../../../test/ThriftTest.thrift
 	$(THRIFT) --gen cpp $<
 
-
 TESTS = \
-  $(testwrapper-%) \
   $(check_PROGRAMS) \
   $(check_SCRIPTS)
 
@@ -212,18 +194,13 @@ leakcheck-%: %
 	    ${VALGRIND_LEAK_OPTS}                                       \
 	    ${$<_VALGRIND_LEAK_OPTS}  ./$<
 
-testwrapper-%: % test-wrapper.sh
-	@ln -sf test-wrapper.sh $@
-
 clean-local:
 	$(RM) -r gen-c_glib gen-cpp
 
 CLEANFILES =                            \
-    testwrapper-*                       \
     *.bb                                \
     *.bbg                               \
     *.da                                \
     *.gcno                              \
     *.gcda                              \
-    *.gcov                              \
-    test-wrapper.sh
+    *.gcov

Added: thrift/trunk/lib/c_glib/test/testbinaryprotocol.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testbinaryprotocol.c?rev=1039299&view=auto
==============================================================================
--- thrift/trunk/lib/c_glib/test/testbinaryprotocol.c (added)
+++ thrift/trunk/lib/c_glib/test/testbinaryprotocol.c Fri Nov 26 10:17:48 2010
@@ -0,0 +1,672 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <netdb.h>
+#include <string.h>
+
+#include "protocol/thrift_protocol.h"
+#include "transport/thrift_socket.h"
+#include "transport/thrift_server_socket.h"
+
+#define TEST_BOOL TRUE
+#define TEST_BYTE 123
+#define TEST_I16 12345
+#define TEST_I32 1234567890
+#define TEST_I64 123456789012345LL
+#define TEST_DOUBLE 1234567890.123
+#define TEST_STRING "this is a test string 1234567890!@#$%^&*()"
+#define TEST_PORT 51199
+
+static int transport_read_count = 0;
+static int transport_read_error = 0;
+static int transport_read_error_at = -1;
+gint32
+my_thrift_transport_read (ThriftTransport *transport, gpointer buf,
+                          guint32 len, GError **error)
+{
+  if (transport_read_count != transport_read_error_at
+      && transport_read_error == 0)
+  {
+    transport_read_count++;
+    return thrift_transport_read (transport, buf, len, error);
+  }
+  return -1;
+}
+
+static int transport_write_count = 0;
+static int transport_write_error = 0;
+static int transport_write_error_at = -1;
+gboolean
+my_thrift_transport_write (ThriftTransport *transport, const gpointer buf,
+                           const guint32 len, GError **error)
+{
+  if (transport_write_count != transport_write_error_at
+      && transport_write_error == 0)
+  {
+    transport_write_count++;
+    return thrift_transport_write (transport, buf, len, error);
+  }
+  return FALSE;
+}
+
+#define thrift_transport_read my_thrift_transport_read
+#define thrift_transport_write my_thrift_transport_write
+#include "../src/protocol/thrift_binary_protocol.c"
+#undef thrift_transport_read
+#undef thrift_transport_write
+
+static void thrift_server_primitives (const int port);
+static void thrift_server_complex_types (const int port);
+
+static void
+test_create_and_destroy(void)
+{
+  GObject *object = NULL;
+
+  /* create an object and then destroy it */
+  object = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, NULL);
+  assert (object != NULL);
+  g_object_unref (object);
+}
+
+static void
+test_initialize(void)
+{
+  ThriftSocket *tsocket = NULL;
+  ThriftBinaryProtocol *protocol = NULL;
+  ThriftSocket *temp = NULL;
+
+  /* create a ThriftTransport */
+  tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
+                          "port", 51188, NULL);
+  assert (tsocket != NULL);
+  /* create a ThriftBinaryProtocol using the Transport */
+  protocol = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
+                           tsocket, NULL);
+  assert (protocol != NULL);
+  /* fetch the properties */
+  g_object_get (G_OBJECT(protocol), "transport", &temp, NULL);
+  g_object_unref (temp);
+
+  /* clean up memory */
+  g_object_unref (protocol);
+  g_object_unref (tsocket);
+}
+
+static void
+test_read_and_write_primitives(void)
+{
+  int status;
+  pid_t pid;
+  ThriftSocket *tsocket = NULL;
+  ThriftTransport *transport = NULL;
+  ThriftBinaryProtocol *tb = NULL;
+  ThriftProtocol *protocol = NULL;
+  gpointer binary = (gpointer *) TEST_STRING;
+  guint32 len = strlen (TEST_STRING);
+  int port = TEST_PORT;
+
+  /* fork a server from the client */
+  pid = fork ();
+  assert (pid >= 0);
+
+  if (pid == 0)
+  {
+    /* child listens */
+    thrift_server_primitives (port);
+    exit (0);
+  } else {
+    /* parent.  wait a bit for the socket to be created. */
+    sleep (1);
+
+    /* create a ThriftSocket */
+    tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
+                            "port", port, NULL);
+    transport = THRIFT_TRANSPORT (tsocket);
+    thrift_transport_open (transport, NULL);
+    assert (thrift_transport_is_open (transport));
+
+    /* create a ThriftBinaryTransport */
+    tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
+                       tsocket, NULL);
+    protocol = THRIFT_PROTOCOL (tb);
+    assert (protocol != NULL);
+
+    /* write a bunch of primitives */
+    assert (thrift_binary_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
+    assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, NULL) > 0);
+    assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) > 0);
+    assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) > 0);
+    assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) > 0);
+    assert (thrift_binary_protocol_write_double (protocol, 
+                                                 TEST_DOUBLE, NULL) > 0);
+    assert (thrift_binary_protocol_write_string (protocol,
+                                                 TEST_STRING, NULL) > 0);
+    assert (thrift_binary_protocol_write_binary (protocol, binary, 
+                                                 len, NULL) > 0);
+    assert (thrift_binary_protocol_write_binary (protocol, NULL, 0, NULL) > 0);
+    assert (thrift_binary_protocol_write_binary (protocol, binary,
+                                                 len, NULL) > 0);
+
+    /* test write errors */
+    transport_write_error = 1;
+    assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, 
+                                               NULL) == -1);
+    assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) == -1);
+    assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) == -1);
+    assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) == -1);
+    assert (thrift_binary_protocol_write_double (protocol, TEST_DOUBLE,
+                                                 NULL) == -1);
+    assert (thrift_binary_protocol_write_binary (protocol, binary, len,
+                                                 NULL) == -1);
+    transport_write_error = 0;
+
+    /* test binary partial failure */
+    transport_write_count = 0;
+    transport_write_error_at = 1;
+    assert (thrift_binary_protocol_write_binary (protocol, binary,
+                                                 len, NULL) == -1);
+    transport_write_error_at = -1;
+
+    /* clean up */
+    thrift_transport_close (transport, NULL);
+    g_object_unref (tsocket);
+    g_object_unref (protocol);
+    assert (wait (&status) == pid);
+    assert (status == 0);
+  }
+}
+
+static void
+test_read_and_write_complex_types (void)
+{
+  int status;
+  pid_t pid;
+  ThriftSocket *tsocket = NULL;
+  ThriftTransport *transport = NULL;
+  ThriftBinaryProtocol *tb = NULL;
+  ThriftProtocol *protocol = NULL;
+  int port = TEST_PORT;
+
+  /* fork a server from the client */
+  pid = fork ();
+  assert (pid >= 0);
+
+  if (pid == 0)
+  {
+    /* child listens */
+    thrift_server_complex_types (port);
+    exit (0);
+  } else {
+    /* parent.  wait a bit for the socket to be created. */
+    sleep (1);
+
+    /* create a ThriftSocket */
+    tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
+                            "port", port, NULL);
+    transport = THRIFT_TRANSPORT (tsocket);
+    thrift_transport_open (transport, NULL);
+    assert (thrift_transport_is_open (transport));
+
+    /* create a ThriftBinaryTransport */
+    tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
+                       tsocket, NULL);
+    protocol = THRIFT_PROTOCOL (tb);
+    assert (protocol != NULL);
+
+    /* test structures */
+    assert (thrift_binary_protocol_write_struct_begin (protocol, 
+                                                       NULL, NULL) == 0);
+    assert (thrift_binary_protocol_write_struct_end (protocol, NULL) == 0);
+
+    assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
+                                                      1, NULL) > 0);
+    assert (thrift_binary_protocol_write_field_end (protocol, NULL) == 0);
+
+    /* test write error */
+    transport_write_error = 1;
+    assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID, 
+                                                      1, NULL) == -1);
+    transport_write_error = 0;
+
+    /* test 2nd write error */
+    transport_write_count = 0;
+    transport_write_error_at = 1;
+    assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
+                                                      1, NULL) == -1);
+    transport_write_error_at = -1;
+
+    /* test 2nd read failure on a field */
+    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
+
+    /* test write_field_stop */
+    assert (thrift_binary_protocol_write_field_stop (protocol, NULL) > 0);
+
+    /* write a map */
+    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
+                                                    1, NULL) > 0);
+    assert (thrift_binary_protocol_write_map_end (protocol, NULL) == 0);
+
+    /* test 2nd read failure on a map */
+    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
+
+    /* test 3rd read failure on a map */
+    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
+    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
+
+    /* test 1st write failure on a map */
+    transport_write_error = 1;
+    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
+                                                    1, NULL) == -1);
+    transport_write_error = 0;
+
+    /* test 2nd write failure on a map */
+    transport_write_count = 0;
+    transport_write_error_at = 1;
+    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
+                                                    1, NULL) == -1);
+    transport_write_error_at = -1;
+
+    /* test 3rd write failure on a map */
+    transport_write_count = 0;
+    transport_write_error_at = 2;
+    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
+                                                    1, NULL) == -1);
+    transport_write_error_at = -1;
+
+    /* test negative map size */
+    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
+    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
+    thrift_binary_protocol_write_i32 (protocol, -10, NULL);
+
+    /* test list operations */
+    assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
+                                                     1, NULL) > 0);
+    assert (thrift_binary_protocol_write_list_end (protocol, NULL) == 0);
+
+    /* test 2nd read failure on a list */
+    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
+
+    /* test negative list size */
+    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
+    thrift_binary_protocol_write_i32 (protocol, -10, NULL);
+
+    /* test first write error on a list */
+    transport_write_error = 1;
+    assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
+                                                     1, NULL) == -1);
+    transport_write_error = 0;
+
+    /* test 2nd write error on a list */
+    transport_write_count = 0;
+    transport_write_error_at = 1;
+    assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
+                                                     1, NULL) == -1);
+    transport_write_error_at = -1;
+
+    /* test set operation s*/
+    assert (thrift_binary_protocol_write_set_begin (protocol, T_VOID,
+                                                    1, NULL) > 0);
+    assert (thrift_binary_protocol_write_set_end (protocol, NULL) == 0);
+
+    /* invalid version */
+    assert (thrift_binary_protocol_write_i32 (protocol, -1, NULL) > 0);
+
+    /* sz > 0 for a message */
+    assert (thrift_binary_protocol_write_i32 (protocol, 1, NULL) > 0);
+
+    /* send a valid message */
+    thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
+    thrift_binary_protocol_write_string (protocol, "test", NULL);
+    thrift_binary_protocol_write_i32 (protocol, 1, NULL);
+
+    /* broken 2nd read */
+    thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
+
+    /* send a broken 3rd read */
+    thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
+    thrift_binary_protocol_write_string (protocol, "test", NULL);
+
+    /* send a valid message */
+    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
+                                                        T_CALL, 1, NULL) > 0);
+
+    assert (thrift_binary_protocol_write_message_end (protocol, NULL) == 0);
+
+    /* send broken writes */
+    transport_write_error = 1;
+    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
+                                                        T_CALL, 1, NULL) == -1);
+    transport_write_error = 0;
+
+    transport_write_count = 0;
+    transport_write_error_at = 2;
+    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
+                                                        T_CALL, 1, NULL) == -1);
+    transport_write_error_at = -1;
+
+    transport_write_count = 0;
+    transport_write_error_at = 3;
+    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
+                                                        T_CALL, 1, NULL) == -1);
+    transport_write_error_at = -1;
+
+    /* clean up */
+    thrift_transport_close (transport, NULL);
+    g_object_unref (tsocket);
+    g_object_unref (protocol);
+    assert (wait (&status) == pid);
+    assert (status == 0);
+  }
+}
+
+
+static void
+thrift_server_primitives (const int port)
+{
+  ThriftServerTransport *transport = NULL;
+  ThriftTransport *client = NULL;
+  ThriftBinaryProtocol *tbp = NULL;
+  ThriftProtocol *protocol = NULL;
+  gboolean value_boolean = FALSE;
+  gint8 value_byte = 0;
+  gint16 value_16 = 0;
+  gint32 value_32 = 0;
+  gint64 value_64 = 0;
+  gdouble value_double = 0;
+  gchar *string = NULL;
+  gpointer binary = NULL;
+  guint32 len = 0;
+  void *comparator = (void *) TEST_STRING;
+
+  ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
+                                              "port", port, NULL);
+  transport = THRIFT_SERVER_TRANSPORT (tsocket);
+  thrift_server_transport_listen (transport, NULL);
+  client = thrift_server_transport_accept (transport, NULL);
+  assert (client != NULL);
+
+  tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
+                      client, NULL);
+  protocol = THRIFT_PROTOCOL (tbp);
+
+  assert (thrift_binary_protocol_read_bool (protocol,
+                                            &value_boolean, NULL) > 0);
+  assert (thrift_binary_protocol_read_byte (protocol, &value_byte, NULL) > 0);
+  assert (thrift_binary_protocol_read_i16 (protocol, &value_16, NULL) > 0);
+  assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) > 0);
+  assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) > 0);
+  assert (thrift_binary_protocol_read_double (protocol,
+                                              &value_double, NULL) > 0);
+  assert (thrift_binary_protocol_read_string (protocol, &string, NULL) > 0);
+  assert (thrift_binary_protocol_read_binary (protocol, &binary,
+                                              &len, NULL) > 0);
+
+  assert (value_boolean == TEST_BOOL);
+  assert (value_byte = TEST_BYTE);
+  assert (value_16 = TEST_I16);
+  assert (value_32 = TEST_I32);
+  assert (value_64 = TEST_I64);
+  assert (value_double = TEST_DOUBLE);
+  assert (strcmp (TEST_STRING, string) == 0);
+  assert (memcmp (comparator, binary, len) == 0);
+
+  g_free (string);
+  g_free (binary);
+
+  thrift_binary_protocol_read_binary (protocol, &binary, &len, NULL);
+  g_free (binary);
+
+  transport_read_count = 0;
+  transport_read_error_at = 0;
+  assert (thrift_binary_protocol_read_binary (protocol, &binary,
+                                              &len, NULL) == -1);
+  transport_read_error_at = -1;
+
+  transport_read_count = 0;
+  transport_read_error_at = 1;
+  assert (thrift_binary_protocol_read_binary (protocol, &binary,
+                                              &len, NULL) == -1);
+  transport_read_error_at = -1;
+
+  transport_read_error = 1;
+  assert (thrift_binary_protocol_read_bool (protocol,
+                                            &value_boolean, NULL) == -1);
+  assert (thrift_binary_protocol_read_byte (protocol,
+                                            &value_byte, NULL) == -1);
+  assert (thrift_binary_protocol_read_i16 (protocol,
+                                           &value_16, NULL) == -1);
+  assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) == -1);
+  assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) == -1);
+  assert (thrift_binary_protocol_read_double (protocol,
+                                              &value_double, NULL) == -1);
+  transport_read_error = 0;
+
+  /* test partial write failure */
+  thrift_protocol_read_i32 (protocol, &value_32, NULL);
+
+  thrift_transport_read_end (client, NULL);
+  thrift_transport_close (client, NULL);
+
+  g_object_unref (tbp);
+  g_object_unref (client);
+  g_object_unref (tsocket);
+}
+
+static void
+thrift_server_complex_types (const int port)
+{
+  ThriftServerTransport *transport = NULL;
+  ThriftTransport *client = NULL;
+  ThriftBinaryProtocol *tbp = NULL;
+  ThriftProtocol *protocol = NULL;
+  gchar *struct_name = NULL;
+  gchar *field_name = NULL;
+  gchar *message_name = NULL;
+  ThriftType element_type, key_type, value_type, field_type;
+  ThriftMessageType message_type;
+  gint8 value = 0;
+  gint16 field_id = 0;
+  guint32 size = 0;
+  gint32 seqid = 0;
+  gint32 version = 0;
+
+  ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
+                                              "port", port, NULL);
+  transport = THRIFT_SERVER_TRANSPORT (tsocket);
+  thrift_server_transport_listen (transport, NULL);
+  client = thrift_server_transport_accept (transport, NULL);
+  assert (client != NULL);
+
+  tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
+                      client, NULL);
+  protocol = THRIFT_PROTOCOL (tbp);
+
+  thrift_binary_protocol_read_struct_begin (protocol, &struct_name, NULL);
+  thrift_binary_protocol_read_struct_end (protocol, NULL);
+
+  thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type,
+                                           &field_id, NULL);
+  thrift_binary_protocol_read_field_end (protocol, NULL);
+
+  /* test first read error on a field */
+  transport_read_error = 1;
+  assert (thrift_binary_protocol_read_field_begin (protocol,
+                                                   &field_name, &field_type,
+                                                   &field_id, NULL) == -1);
+  transport_read_error = 0;
+
+  /* test 2nd write failure */
+  thrift_binary_protocol_read_byte (protocol, &value, NULL);
+
+  /* test 2nd read failure on a field */
+  transport_read_count = 0;
+  transport_read_error_at = 1;
+  assert (thrift_binary_protocol_read_field_begin (protocol,
+                                                   &field_name, &field_type,
+                                                   &field_id, NULL) == -1);
+  transport_read_error_at = -1;
+
+  /* test field stop */
+  thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type,
+                                           &field_id, NULL);
+
+  thrift_binary_protocol_read_map_begin (protocol, &key_type, &value_type,
+                                         &size, NULL);
+  thrift_binary_protocol_read_map_end (protocol, NULL);
+
+  /* test read failure on a map */
+  transport_read_count = 0;
+  transport_read_error_at = 0;
+  assert (thrift_binary_protocol_read_map_begin (protocol,
+                                                 &key_type, &value_type,
+                                                 &size, NULL) == -1);
+  transport_read_error_at = -1;
+
+  /* test 2nd read failure on a map */
+  transport_read_count = 0;
+  transport_read_error_at = 1;
+  assert (thrift_binary_protocol_read_map_begin (protocol,
+                                                 &key_type, &value_type,
+                                                 &size, NULL) == -1);
+  transport_read_error_at = -1;
+
+  /* test 3rd read failure on a map */
+  transport_read_count = 0;
+  transport_read_error_at = 2;
+  assert (thrift_binary_protocol_read_map_begin (protocol,
+                                                 &key_type, &value_type,
+                                                 &size, NULL) == -1);
+  transport_read_error_at = -1;
+
+  /* test 2nd write failure */
+  thrift_binary_protocol_read_byte (protocol, &value, NULL);
+
+  /* test 3rd write failure */
+  thrift_binary_protocol_read_byte (protocol, &value, NULL);
+  thrift_binary_protocol_read_byte (protocol, &value, NULL);
+
+  /* test negative map size */
+  assert (thrift_binary_protocol_read_map_begin (protocol,
+                                                 &key_type, &value_type,
+                                                 &size, NULL) == -1);
+
+  /* test list operations */
+  thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
+  thrift_binary_protocol_read_list_end (protocol, NULL);
+
+  /* test read failure */
+  transport_read_error = 1;
+  assert (thrift_binary_protocol_read_list_begin (protocol, &element_type,
+                                                  &size, NULL) == -1);
+  transport_read_error = 0;
+
+  /* test 2nd read failure */
+  transport_read_count = 0;
+  transport_read_error_at = 1;
+  thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
+  transport_read_error_at = -1;
+
+  /* test negative list size failure */
+  thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
+
+  /* test 2nd write failure */
+  thrift_binary_protocol_read_byte (protocol, &value, NULL);
+
+  /* test set operations */
+  thrift_binary_protocol_read_set_begin (protocol, &element_type, &size, NULL);
+  thrift_binary_protocol_read_set_end (protocol, NULL);
+
+  /* broken read */
+  transport_read_error = 1;
+  assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
+                                                     &message_type, &seqid,
+                                                     NULL) == -1);
+  transport_read_error = 0;
+
+  /* invalid protocol version */
+  assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
+                                                     &message_type, &seqid,
+                                                     NULL) == -1);
+
+  /* sz > 0 */
+  assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
+                                                     &message_type, &seqid,
+                                                     NULL) > 0);
+
+  /* read a valid message */
+  assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
+                                                     &message_type, &seqid,
+                                                     NULL) > 0);
+  g_free (message_name);
+
+  /* broken 2nd read on a message */
+  transport_read_count = 0;
+  transport_read_error_at = 1;
+  assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
+                                                     &message_type, &seqid,
+                                                     NULL) == -1);
+  transport_read_error_at = -1;
+
+  /* broken 3rd read on a message */
+  transport_read_count = 0;
+  transport_read_error_at = 3; /* read_string does two reads */
+  assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
+                                                     &message_type, &seqid,
+                                                     NULL) == -1);
+  g_free (message_name);
+  transport_read_error_at = -1;
+
+  /* read a valid message */
+  assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
+                                                     &message_type, &seqid, 
+                                                     NULL) > 0);
+  g_free (message_name);
+
+  assert (thrift_binary_protocol_read_message_end (protocol, NULL) == 0);
+
+  /* handle 2nd write failure on a message */
+  thrift_binary_protocol_read_i32 (protocol, &version, NULL);
+
+  /* handle 2nd write failure on a message */
+  thrift_binary_protocol_read_i32 (protocol, &version, NULL);
+  thrift_binary_protocol_read_string (protocol, &message_name, NULL);
+
+  g_object_unref (client);
+  // TODO: investigate g_object_unref (tbp);
+  g_object_unref (tsocket);
+}
+
+int
+main(int argc, char *argv[])
+{
+  g_type_init();
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/testmemorybuffer/CreateAndDestroy", test_create_and_destroy);
+  g_test_add_func ("/testmemorybuffer/Initialize", test_initialize);
+  g_test_add_func ("/testmemorybuffer/ReadAndWritePrimitives", test_read_and_write_primitives);
+  g_test_add_func ("/testmemorybuffer/ReadAndWriteComplexTypes", test_read_and_write_complex_types);
+
+  return g_test_run ();
+}

Modified: thrift/trunk/lib/c_glib/test/testbufferedtransport.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testbufferedtransport.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/testbufferedtransport.c (original)
+++ thrift/trunk/lib/c_glib/test/testbufferedtransport.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include <assert.h>
 #include <netdb.h>
 
@@ -176,13 +195,15 @@ thrift_server (const int port)
 }
 
 int
-main(void)
+main(int argc, char *argv[])
 {
   g_type_init();
-  test_create_and_destroy();
-  test_open_and_close();
-  test_read_and_write();
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/testbufferedtransport/CreateAndDestroy", test_create_and_destroy);
+  g_test_add_func ("/testbufferedtransport/OpenAndClose", test_open_and_close);
+  g_test_add_func ("/testbufferedtransport/ReadAndWrite", test_read_and_write);
 
-  return 0;
+  return g_test_run ();
 }
 

Modified: thrift/trunk/lib/c_glib/test/testdebugproto.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testdebugproto.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/testdebugproto.c (original)
+++ thrift/trunk/lib/c_glib/test/testdebugproto.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include <math.h>
 #include <glib-object.h>
 
@@ -7,12 +26,9 @@
 
 #include "gen-c_glib/t_test_debug_proto_test_types.h"
 
-
-int
-main(void)
+static void
+test_debug_proto(void)
 {
-  g_type_init ();
-
   TTestOneOfEach *ooe = NULL;
   TTestNesting *n = NULL;
   TTestHolyMoley *hm = NULL;
@@ -62,3 +78,15 @@ main(void)
   return 0;
 }
 
+int
+main(int argc, char *argv[])
+{
+  g_type_init();
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/testdebugproto/DebugProto", test_debug_proto);
+
+  return g_test_run ();
+}
+
+

Modified: thrift/trunk/lib/c_glib/test/testframedtransport.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testframedtransport.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/testframedtransport.c (original)
+++ thrift/trunk/lib/c_glib/test/testframedtransport.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include <assert.h>
 #include <netdb.h>
 
@@ -164,13 +183,14 @@ thrift_server (const int port)
 }
 
 int
-main(void)
+main(int argc, char *argv[])
 {
   g_type_init();
-  test_create_and_destroy();
-  test_open_and_close();
-  test_read_and_write();
+  g_test_init (&argc, &argv, NULL);
 
-  return 0;
-}
+  g_test_add_func ("/testframedtransport/CreateAndDestroy", test_create_and_destroy);
+  g_test_add_func ("/testframedtransport/OpenAndClose", test_open_and_close);
+  g_test_add_func ("/testframedtransport/ReadAndWrite", test_read_and_write);
 
+  return g_test_run ();
+}

Modified: thrift/trunk/lib/c_glib/test/testmemorybuffer.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testmemorybuffer.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/testmemorybuffer.c (original)
+++ thrift/trunk/lib/c_glib/test/testmemorybuffer.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include <assert.h>
 #include <netdb.h>
 
@@ -63,13 +82,14 @@ test_read_and_write(void)
 }
 
 int
-main(void)
+main(int argc, char *argv[])
 {
   g_type_init();
-  test_create_and_destroy();
-  test_open_and_close();
-  test_read_and_write();
+  g_test_init (&argc, &argv, NULL);
 
-  return 0;
-}
+  g_test_add_func ("/testmemorybuffer/CreateAndDestroy", test_create_and_destroy);
+  g_test_add_func ("/testmemorybuffer/OpenAndClose", test_open_and_close);
+  g_test_add_func ("/testmemorybuffer/ReadAndWrite", test_read_and_write);
 
+  return g_test_run ();
+}

Modified: thrift/trunk/lib/c_glib/test/testoptionalrequired.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testoptionalrequired.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/testoptionalrequired.c (original)
+++ thrift/trunk/lib/c_glib/test/testoptionalrequired.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include <assert.h>
 #include <glib.h>
 
@@ -167,16 +186,17 @@ test_tricky4 (void)
 }
 
 int
-main(void)
+main(int argc, char *argv[])
 {
-  g_type_init ();
-  test_old_school1 ();
-  test_simple ();
-  test_tricky1 ();
-  test_tricky2 ();
-  test_tricky3 ();
-  test_tricky4 ();
-  return 0;
-}
+  g_type_init();
+  g_test_init (&argc, &argv, NULL);
 
+  g_test_add_func ("/testoptionalrequired/OldSchool", test_old_school1);
+  g_test_add_func ("/testoptionalrequired/Simple", test_simple);
+  g_test_add_func ("/testoptionalrequired/Tricky1", test_tricky1);
+  g_test_add_func ("/testoptionalrequired/Tricky2", test_tricky2);
+  g_test_add_func ("/testoptionalrequired/Tricky3", test_tricky3);
+  g_test_add_func ("/testoptionalrequired/Tricky4", test_tricky4);
 
+  return g_test_run ();
+}

Modified: thrift/trunk/lib/c_glib/test/testsimpleserver.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testsimpleserver.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/testsimpleserver.c (original)
+++ thrift/trunk/lib/c_glib/test/testsimpleserver.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include <assert.h>
 #include <glib.h>
 #include <stdlib.h>
@@ -5,6 +24,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#include "thrift.h"
 #include "processor/thrift_processor.h"
 #include "transport/thrift_server_socket.h"
 
@@ -27,6 +47,8 @@ struct _TestProcessorClass
 };
 typedef struct _TestProcessorClass TestProcessorClass;
 
+G_DEFINE_TYPE(TestProcessor, test_processor, THRIFT_TYPE_PROCESSOR)
+
 gboolean
 test_processor_process (ThriftProcessor *processor, ThriftProtocol *in,
                         ThriftProtocol *out)
@@ -35,38 +57,15 @@ test_processor_process (ThriftProcessor 
 }
 
 static void
-test_processor_class_init (ThriftProcessorClass *proc)
+test_processor_init (TestProcessor *p)
 {
-  proc->process = test_processor_process;
+  THRIFT_UNUSED_VAR (p);
 }
 
-GType
-test_processor_get_type (void)
+static void
+test_processor_class_init (TestProcessorClass *proc)
 {
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo info =
-    {
-      sizeof (TestProcessorClass),
-      NULL, /* base_init */
-      NULL, /* base_finalize */
-      (GClassInitFunc) test_processor_class_init,
-      NULL, /* class_finalize */
-      NULL, /* class_data */
-      sizeof (TestProcessor),
-      0, /* n_preallocs */
-      NULL, /* instance_init */
-      NULL, /* value_table */
-    };
-
-    type = g_type_register_static (THRIFT_TYPE_PROCESSOR,
-                                   "TestProcessorType",
-                                   &info, 0);
-  }
-
-  return type;
+  (THRIFT_PROCESSOR_CLASS(proc))->process = test_processor_process;
 }
 
 static void
@@ -104,10 +103,12 @@ test_server (void)
 }
 
 int
-main (void)
+main(int argc, char *argv[])
 {
-  g_type_init ();
-  test_server ();
+  g_type_init();
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/testsimpleserver/SimpleServer", test_server);
 
-  return 0;
+  return g_test_run ();
 }

Modified: thrift/trunk/lib/c_glib/test/teststruct.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/teststruct.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/teststruct.c (original)
+++ thrift/trunk/lib/c_glib/test/teststruct.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include <assert.h>
 #include <glib-object.h>
 
@@ -20,67 +39,13 @@ typedef struct _ThriftTestStructClass Th
 GType thrift_test_struct_get_type (void);
 
 #define THRIFT_TYPE_TEST_STRUCT (thrift_test_struct_get_type ())
-#define THRIFT_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                     THRIFT_TYPE_TEST_STRUCT, \
-                                     ThriftTestStruct))
-#define THRIFT_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
-                                         THRIFT_TYPE_TEST_STRUCT, \
-                                         ThriftTestStructClass))
-#define THRIFT_IS_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-                                        THRIFT_TYPE_TEST_STRUCT))
-#define THRIFT_IS_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
-                                            THRIFT_TYPE_TEST_STRUCT))
-#define THRIFT_TEST_STRUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-                                               THRIFT_TYPE_TEST_STRUCT, \
-                                               ThriftTestStructClass))
-
-/* test declarations */
-gint32 thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
-                                GError **error);
-gint32 thrift_test_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
-                                 GError **error);
+#define THRIFT_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_TEST_STRUCT, ThriftTestStruct))
+#define THRIFT_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_TEST_STRUCT, ThriftTestStructClass))
+#define THRIFT_IS_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_TEST_STRUCT))
+#define THRIFT_IS_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_TEST_STRUCT))
+#define THRIFT_TEST_STRUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_TEST_STRUCT, ThriftTestStructClass))
 
-static void
-thrift_test_struct_class_init (ThriftTestStructClass *cls)
-{
-  ThriftStructClass *ts_cls = THRIFT_STRUCT_CLASS (cls);
-  ts_cls->read = thrift_test_struct_read;
-  ts_cls->write = thrift_test_struct_write;
-}
-
-static void
-thrift_test_struct_instance_init (ThriftTestStruct *s)
-{
-  (void) s;
-}
-
-GType
-thrift_test_struct_get_type (void)
-{
-  static GType type = 0;
-
-  if (type == 0)
-  {
-    static const GTypeInfo type_info =
-    {
-      sizeof (ThriftTestStructClass),
-      NULL,
-      NULL,
-      (GClassInitFunc) thrift_test_struct_class_init,
-      NULL,
-      NULL,
-      sizeof (ThriftTestStruct),
-      0,
-      (GInstanceInitFunc) thrift_test_struct_instance_init,
-      NULL, 
-    };
-
-    type = g_type_register_static (THRIFT_TYPE_STRUCT,
-                                   "ThriftTestStructType", &type_info, 0);
-  }
-
-  return type;
-}
+G_DEFINE_TYPE(ThriftTestStruct, thrift_test_struct, THRIFT_TYPE_STRUCT)
 
 gint32
 thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
@@ -96,6 +61,19 @@ thrift_test_struct_write (ThriftStruct *
   return 0;
 }
 
+static void
+thrift_test_struct_class_init (ThriftTestStructClass *cls)
+{
+  ThriftStructClass *ts_cls = THRIFT_STRUCT_CLASS (cls);
+  ts_cls->read = thrift_test_struct_read;
+  ts_cls->write = thrift_test_struct_write;
+}
+
+static void
+thrift_test_struct_init (ThriftTestStruct *s)
+{
+  THRIFT_UNUSED_VAR (s);
+}
 
 static void
 test_initialize_object (void)
@@ -112,10 +90,12 @@ test_initialize_object (void)
 }
 
 int
-main(void)
+main(int argc, char *argv[])
 {
-  g_type_init ();
-  test_initialize_object ();
+  g_type_init();
+  g_test_init (&argc, &argv, NULL);
 
-  return 0;
+  g_test_add_func ("/teststruct/InitializeObject", test_initialize_object);
+
+  return g_test_run ();
 }

Modified: thrift/trunk/lib/c_glib/test/testthrifttest.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testthrifttest.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/testthrifttest.c (original)
+++ thrift/trunk/lib/c_glib/test/testthrifttest.c Fri Nov 26 10:17:48 2010
@@ -7,22 +7,22 @@
 static const char TEST_ADDRESS[] = "localhost";
 static const int TEST_PORT = 64444;
 
-static void thrift_server (const int port);
-
 static void
-thrift_server (const int port)
+test_thrift_server (const int port)
 {
   ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
-                                              "port", port, NULL);
+                                              "port", TEST_PORT, NULL);
 
   g_object_unref (tsocket);
 }
 
 int
-main(void)
+main(int argc, char *argv[])
 {
-  g_type_init ();
-  thrift_server (TEST_PORT);
-  return 0;
-}
+  g_type_init();
+  g_test_init (&argc, &argv, NULL);
 
+  g_test_add_func ("/testthrift/Server", test_thrift_server);
+
+  return g_test_run ();
+}

Modified: thrift/trunk/lib/c_glib/test/testthrifttestclient.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testthrifttestclient.cpp?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/testthrifttestclient.cpp (original)
+++ thrift/trunk/lib/c_glib/test/testthrifttestclient.cpp Fri Nov 26 10:17:48 2010
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 
 /* test a C client with a C++ server */
 

Modified: thrift/trunk/lib/c_glib/test/testtransportsocket.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/test/testtransportsocket.c?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/test/testtransportsocket.c (original)
+++ thrift/trunk/lib/c_glib/test/testtransportsocket.c Fri Nov 26 10:17:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 #include <assert.h>
 #include <netdb.h>
 
@@ -188,13 +207,15 @@ thrift_socket_server (const int port)
 }
 
 int
-main(void)
+main(int argc, char *argv[])
 {
   g_type_init();
-  test_create_and_destroy();
-  test_open_and_close();
-  test_read_and_write();
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/testtransportsocket/CreateAndDestroy", test_create_and_destroy);
+  g_test_add_func ("/testtransportsocket/OpenAndClose", test_open_and_close);
+  g_test_add_func ("/testtransportsocket/ReadAndWrite", test_read_and_write);
 
-  return 0;
+  return g_test_run ();
 }
 

Modified: thrift/trunk/lib/c_glib/thrift_c_glib.pc.in
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/c_glib/thrift_c_glib.pc.in?rev=1039299&r1=1039298&r2=1039299&view=diff
==============================================================================
--- thrift/trunk/lib/c_glib/thrift_c_glib.pc.in (original)
+++ thrift/trunk/lib/c_glib/thrift_c_glib.pc.in Fri Nov 26 10:17:48 2010
@@ -25,5 +25,6 @@ includedir=@includedir@
 Name: Thrift
 Description: Thrift C API
 Version: @VERSION@
+Requires: glib-2.0 gobject-2.0
 Libs: -L${libdir} -lthriftc
 Cflags: -I${includedir}/thrift