soylent r161 - in trunk/libsoylent: . test



Author: svenp
Date: Sat Jun 14 16:04:57 2008
New Revision: 161
URL: http://svn.gnome.org/viewvc/soylent?rev=161&view=rev

Log:
refactored code with prefix sl instead of soylent and in GNU style

Added:
   trunk/libsoylent/sl-entity.c
      - copied, changed from r160, /trunk/libsoylent/soylent-entity.c
   trunk/libsoylent/sl-entity.h
      - copied, changed from r159, /trunk/libsoylent/soylent-entity.h
   trunk/libsoylent/sl-person.c
      - copied, changed from r159, /trunk/libsoylent/soylent-person.c
   trunk/libsoylent/sl-person.h
      - copied, changed from r159, /trunk/libsoylent/soylent-person.h
Removed:
   trunk/libsoylent/soylent-entity.c
   trunk/libsoylent/soylent-entity.h
   trunk/libsoylent/soylent-person.c
   trunk/libsoylent/soylent-person.h
Modified:
   trunk/libsoylent/Makefile.am
   trunk/libsoylent/sl-book.c
   trunk/libsoylent/sl-book.h
   trunk/libsoylent/soylent.c
   trunk/libsoylent/soylent.h
   trunk/libsoylent/test/init.c
   trunk/libsoylent/test/playground.c
   trunk/libsoylent/test/test.c
   trunk/libsoylent/test/test.h

Modified: trunk/libsoylent/Makefile.am
==============================================================================
--- trunk/libsoylent/Makefile.am	(original)
+++ trunk/libsoylent/Makefile.am	Sat Jun 14 16:04:57 2008
@@ -6,13 +6,13 @@
 
 libsoylent_la_SOURCES = \
 	soylent.h \
-	soylent-entity.h \
+	sl-entity.h \
 	sl-book.h \
-	soylent-person.h \
+	sl-person.h \
 	soylent.c \
-	soylent-entity.c \
+	sl-entity.c \
 	sl-book.c \
-	soylent-person.c
+	sl-person.c
 
 libsoylent_la_CFLAGS = $(LIBSOYLENT_CFLAGS) $(WARN_CFLAGS)
 libsoylent_la_LIBADD = $(LIBSOYLENT_LIBS)

Modified: trunk/libsoylent/sl-book.c
==============================================================================
--- trunk/libsoylent/sl-book.c	(original)
+++ trunk/libsoylent/sl-book.c	Sat Jun 14 16:04:57 2008
@@ -149,7 +149,7 @@
   return self;
 }
 
-SoylentEntity *
+SlEntity *
 sl_book_get_person(SlBook *self, gchar *attrname, gpointer value)
 {
   g_warning("%s not implemented", __FUNCTION__);

Modified: trunk/libsoylent/sl-book.h
==============================================================================
--- trunk/libsoylent/sl-book.h	(original)
+++ trunk/libsoylent/sl-book.h	Sat Jun 14 16:04:57 2008
@@ -1,9 +1,9 @@
 /**/
 
-#ifndef SOYLENT_BOOK_H
-#define SOYLENT_BOOK_H
+#ifndef SL_BOOK_H
+#define SL_BOOK_H
 
-#include "soylent-entity.h"
+#include "sl-entity.h"
 
 #include <glib.h>
 #include <glib-object.h>
@@ -43,6 +43,6 @@
 GList *sl_book_get_books (void);
 
 SlBook *sl_book_new (void);
-SoylentEntity *sl_book_get_person(SlBook *self, gchar *attrname, gpointer value);
+SlEntity *sl_book_get_person(SlBook *self, gchar *attrname, gpointer value);
 
 #endif

Copied: trunk/libsoylent/sl-entity.c (from r160, /trunk/libsoylent/soylent-entity.c)
==============================================================================
--- /trunk/libsoylent/soylent-entity.c	(original)
+++ trunk/libsoylent/sl-entity.c	Sat Jun 14 16:04:57 2008
@@ -1,92 +1,105 @@
 /**/
 
-#include "soylent-entity.h"
+#include "sl-entity.h"
 
 /* private structs and fields */
 
-struct _SoylentEntityPriv {
+struct _SlEntityPriv
+{
 	gchar *foo;
 };
 
 static GObjectClass *parent_class = NULL;
 
-static void _soylent_entity_class_init(gpointer g_class, gpointer class_data);
-static void _soylent_entity_init(GTypeInstance *instance, gpointer g_class);
-static void _soylent_entity_dispose(GObject *object);
-static void _soylent_entity_set_property(GObject *object, guint property_id,
+static void sl_entity_class_init (gpointer g_class, gpointer class_data);
+static void sl_entity_init (GTypeInstance *instance, gpointer g_class);
+static void sl_entity_dispose (GObject *object);
+static void sl_entity_set_property (GObject *object, guint property_id,
 	const GValue *value, GParamSpec *pspec);
-static void _soylent_entity_get_property(GObject *object, guint property_id,
+static void sl_entity_get_property (GObject *object, guint property_id,
 	GValue *value, GParamSpec *pspec);
 
-GType soylent_entity_get_type(void) {
+GType
+sl_entity_get_type (void)
+{
 	static GType type = 0;
-	static const GTypeInfo info = {
-		sizeof(SoylentEntityClass),
-		NULL,
-		NULL,
-		_soylent_entity_class_init,
-		NULL,
-		NULL,
-		sizeof(SoylentEntity),
-		0,
-		_soylent_entity_init,
-		NULL
-	};
+	static const GTypeInfo info =
+    {
+  		sizeof (SlEntityClass),
+  		NULL,
+  		NULL,
+  		sl_entity_class_init,
+  		NULL,
+  		NULL,
+  		sizeof (SlEntity),
+  		0,
+  		sl_entity_init,
+  		NULL
+	 };
 	
-	if (type == 0) {
-		type = g_type_register_static(G_TYPE_OBJECT, "SoylentEntity", &info, 0);
-	}
+	if (type == 0)
+    {
+		  type = g_type_register_static(G_TYPE_OBJECT, "SlEntity", &info, 0);
+    }
 	return type;
 }
 
-static void _soylent_entity_class_init(gpointer g_class, gpointer class_data) {
-	parent_class = g_type_class_peek(g_type_parent(SOYLENT_ENTITY_TYPE));
-	g_assert(parent_class != NULL);
+static void
+sl_entity_class_init (gpointer g_class, gpointer class_data)
+{
+	parent_class = g_type_class_peek (g_type_parent (SL_ENTITY_TYPE));
+	g_assert (parent_class != NULL);
 	
   GObjectClass *obj_class = G_OBJECT_CLASS (g_class);
-  obj_class->dispose = _soylent_entity_dispose;
-  obj_class->get_property = _soylent_entity_get_property;
-  obj_class->set_property = _soylent_entity_set_property;
+  obj_class->dispose = sl_entity_dispose;
+  obj_class->get_property = sl_entity_get_property;
+  obj_class->set_property = sl_entity_set_property;
 }
 
-static void _soylent_entity_init(GTypeInstance *instance, gpointer g_class) {
-	SoylentEntity *self = SOYLENT_ENTITY(instance);
-	SoylentEntityPriv *priv = g_new(SoylentEntityPriv, 1);
+static void
+sl_entity_init (GTypeInstance *instance, gpointer g_class)
+{
+	SlEntity *self = SL_ENTITY (instance);
+	SlEntityPriv *priv = g_new (SlEntityPriv, 1);
 	self->priv = priv;
 	self->priv->foo = "FOO";
 	self->disposed = FALSE;
 }
 
-static void _soylent_entity_dispose(GObject *object) {
-	SoylentEntity *self = SOYLENT_ENTITY(object);
-	g_return_if_fail(!self->disposed);
+static void
+sl_entity_dispose (GObject *object) {
+	SlEntity *self = SL_ENTITY (object);
+	g_return_if_fail (!self->disposed);
 	
-	g_free(self->priv);
+	g_free (self->priv);
 	self->disposed = TRUE;
   
   parent_class->dispose (object);
 }
 
-static void _soylent_entity_set_property(GObject *object, guint property_id,
-	const GValue *value, GParamSpec *pspec) {
-	g_warning("%s not implemented", __FUNCTION__);
+static void
+sl_entity_set_property (GObject *object, guint property_id, const GValue *value,
+  GParamSpec *pspec)
+{
+	g_warning ("%s not implemented", __FUNCTION__);
 }
 
-static void _soylent_entity_get_property(GObject *object, guint property_id,
-	GValue *value, GParamSpec *pspec) {
+static void
+sl_entity_get_property (GObject *object, guint property_id, GValue *value,
+  GParamSpec *pspec)
+{
 	g_warning("%s not implemented", __FUNCTION__);
 }
 
-SoylentEntity *soylent_entity_new(void) {
-	SoylentEntity *entity = g_object_new(SOYLENT_ENTITY_TYPE, NULL);
+SlEntity *
+sl_entity_new (void)
+{
+	SlEntity *entity = g_object_new (SL_ENTITY_TYPE, NULL);
 	return entity;
 }
 
-gpointer soylent_entity_get(SoylentEntity *self, const gchar *attrname) {
+gpointer
+sl_entity_get (SlEntity *self, const gchar *attrname)
+{
 	return self->priv->foo;
-	
-	/*
-	1) get from cache
-	2) if not present: get from source
-	 */
 }

Copied: trunk/libsoylent/sl-entity.h (from r159, /trunk/libsoylent/soylent-entity.h)
==============================================================================
--- /trunk/libsoylent/soylent-entity.h	(original)
+++ trunk/libsoylent/sl-entity.h	Sat Jun 14 16:04:57 2008
@@ -1,40 +1,41 @@
 /**/
 
-#ifndef SOYLENT_ENTITY_H
-#define SOYLENT_ENTITY_H
+#ifndef SL_ENTITY_H
+#define SL_ENTITY_H
 
 #include <glib.h>
 #include <glib-object.h>
 
-#define SOYLENT_ENTITY_TYPE				(soylent_entity_get_type())
-#define SOYLENT_ENTITY(obj)				(G_TYPE_CHECK_INSTANCE_CAST(obj, \
-	SOYLENT_ENTITY_TYPE, SoylentEntity))
-#define SOYLENT_ENTITY_CLASS(cls)		(G_TYPE_CHECK_CLASS_CAST(cls, \
-	SOYLENT_ENTITY_TYPE, SoylentEntityClass))
-#define SOYLENT_IS_ENTITY(obj)			(G_TYPE_CHECK_INSTANCE_TYPE(obj, \
-	SOYLENT_ENTITY_TYPE))
-#define SOYLENT_IS_ENTITY_CLASS(cls)	(G_TYPE_CHECK_CLASS_TYPE(cls, \
-	SOYLENT_ENTITY_TYPE))
-#define SOYLENT_ENTITY_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS(obj, \
-	SOYLENT_ENTITY_TYPE))
-
-typedef struct _SoylentEntity SoylentEntity;
-typedef struct _SoylentEntityClass SoylentEntityClass;
-typedef struct _SoylentEntityPriv SoylentEntityPriv;
+#define SL_ENTITY_TYPE			 	    (sl_entity_get_type ())
+#define SL_ENTITY(obj)				    (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+	SL_ENTITY_TYPE, SlEntity))
+#define SL_ENTITY_CLASS(cls)		  (G_TYPE_CHECK_CLASS_CAST(cls, \
+	SL_ENTITY_TYPE, SlEntityClass))
+#define SL_IS_ENTITY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE(obj, \
+	SL_ENTITY_TYPE))
+#define SL_IS_ENTITY_CLASS(cls)	  (G_TYPE_CHECK_CLASS_TYPE(cls, SL_ENTITY_TYPE))
+#define SL_ENTITY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS(obj, \
+	SL_ENTITY_TYPE))
+
+typedef struct _SlEntity      SlEntity;
+typedef struct _SlEntityClass SlEntityClass;
+typedef struct _SlEntityPriv  SlEntityPriv;
 
-struct _SoylentEntity {
+struct _SlEntity
+{
 	GObject parent;
 	gboolean disposed;
-	SoylentEntityPriv *priv;
+	SlEntityPriv *priv;
 };
 
-struct _SoylentEntityClass {
+struct _SlEntityClass
+{
 	GObjectClass parent;
 };
 
-GType soylent_entity_get_type(void);
+GType sl_entity_get_type (void);
 
-SoylentEntity *soylent_entity_new(void);
-gpointer soylent_entity_get(SoylentEntity *self, const gchar *attrname);
+SlEntity *sl_entity_new (void);
+gpointer sl_entity_get (SlEntity *self, const gchar *attrname);
 
 #endif

Copied: trunk/libsoylent/sl-person.c (from r159, /trunk/libsoylent/soylent-person.c)
==============================================================================
--- /trunk/libsoylent/soylent-person.c	(original)
+++ trunk/libsoylent/sl-person.c	Sat Jun 14 16:04:57 2008
@@ -1,9 +1,11 @@
 //
 
-#include "soylent-person.h"
+#include "sl-person.h"
 
-gint soylent_person_foo(const gchar *bar) {
-	g_return_val_if_fail(bar != NULL, -1);
+gint
+sl_person_foo (const gchar *bar)
+{
+	g_return_val_if_fail (bar != NULL, -1);
 	
-	return g_str_hash(bar);
+	return g_str_hash (bar);
 }

Copied: trunk/libsoylent/sl-person.h (from r159, /trunk/libsoylent/soylent-person.h)
==============================================================================
--- /trunk/libsoylent/soylent-person.h	(original)
+++ trunk/libsoylent/sl-person.h	Sat Jun 14 16:04:57 2008
@@ -1,11 +1,11 @@
 //
 
-#ifndef SOYLENT_PERSON_H
-#define SOYLENT_PERSON_H
+#ifndef SL_PERSON_H
+#define SL_PERSON_H
 
 #include <glib.h>
 #include <glib-object.h>
 
-gint soylent_person_foo(const gchar *bar);
+gint sl_person_foo (const gchar *bar);
 
 #endif

Modified: trunk/libsoylent/soylent.c
==============================================================================
--- trunk/libsoylent/soylent.c	(original)
+++ trunk/libsoylent/soylent.c	Sat Jun 14 16:04:57 2008
@@ -6,7 +6,7 @@
 #include <glib-object.h>
 
 void
-soylent_init (void)
+sl_init (void)
 {
 	g_type_init ();
 	sl_book_setup ();

Modified: trunk/libsoylent/soylent.h
==============================================================================
--- trunk/libsoylent/soylent.h	(original)
+++ trunk/libsoylent/soylent.h	Sat Jun 14 16:04:57 2008
@@ -3,10 +3,10 @@
 #ifndef SOYLENT_H
 #define SOYLENT_H
 
-#include "soylent-person.h"
-#include "soylent-entity.h"
+#include "sl-entity.h"
+#include "sl-person.h"
 #include "sl-book.h"
 
-void soylent_init(void);
+void sl_init (void);
 
 #endif

Modified: trunk/libsoylent/test/init.c
==============================================================================
--- trunk/libsoylent/test/init.c	(original)
+++ trunk/libsoylent/test/init.c	Sat Jun 14 16:04:57 2008
@@ -4,10 +4,12 @@
 
 #include <libsoylent/soylent.h>
 
-void init(void) {
-	Test *test = test_init("Initialization");
+void
+init (void)
+{
+	Test *test = test_init ("Initialization");
 	
-	soylent_init();
+	sl_init ();
 	
-	test_succeded(test);	
+	test_succeded (test);	
 }

Modified: trunk/libsoylent/test/playground.c
==============================================================================
--- trunk/libsoylent/test/playground.c	(original)
+++ trunk/libsoylent/test/playground.c	Sat Jun 14 16:04:57 2008
@@ -4,11 +4,13 @@
 
 #include <libsoylent/soylent.h>
 
-void playground(void) {
-	Test *test = test_init("Playground");
+void
+playground (void)
+{
+	Test *test = test_init ("Playground");
 	
-	SoylentEntity *entity = soylent_entity_new();
-	g_print("%s\n", (gchar *) soylent_entity_get(entity, "x"));
+	SlEntity *entity = sl_entity_new ();
+	g_print ("%s\n", (gchar *) sl_entity_get (entity, "x"));
 	
-	test_succeded(test);
+	test_succeded (test);
 }

Modified: trunk/libsoylent/test/test.c
==============================================================================
--- trunk/libsoylent/test/test.c	(original)
+++ trunk/libsoylent/test/test.c	Sat Jun 14 16:04:57 2008
@@ -7,60 +7,71 @@
 
 #include <stdlib.h>
 
-int main(int argc, char **argv) {
+/* TODO: split in multiple test binaries */
+
+int
+main (int argc, char **argv)
+{
 	tests = NULL;
 	
 	// TODO: why does this macro not work?
 	//g_print("Welcome to libsoylent Test v%s\n\n", LIBSOYLENT_VERSION);
-	g_print("Welcome to libsoylent Test v0.0.1!\n\n");
+	g_print ("Welcome to libsoylent Test v0.0.1!\n\n");
 	
 	/* --- tests --- */
-	init();
-	playground();
+	init ();
+	playground ();
 	/* insert more tests here... */
 	/* --- */
 	
-	g_print("\n");
-	g_print("Test results:\n");
+	g_print ("\n");
+	g_print ("Test results:\n");
 	
-	int tests_count = g_list_length(tests);
+	int tests_count = g_list_length (tests);
 	int success_count = 0;
 	GList *tests_iter = tests;
-	for(; tests_iter != NULL; tests_iter = tests_iter->next) {
-		Test *test = tests_iter->data;
-		
-		gchar result_char = ' ';
-		if (test->succeded) {
-			result_char = 'X';
-			success_count++;
-		}
-		
-		g_print("  [%c] %s\n", result_char, test->name);
-	}
-	
-	g_print("\n");
-	g_print("%d / %d tests succeded\n", success_count, tests_count);
-	
-	g_list_free(tests);
-	
-	if (success_count != tests_count) {
-		return EXIT_FAILURE;
-	}
+	for (; tests_iter != NULL; tests_iter = tests_iter->next)
+    {
+  		Test *test = tests_iter->data;
+  		
+  		gchar result_char = ' ';
+  		if (test->succeded)
+        {
+  			  result_char = 'X';
+  			  success_count++;
+  		  }
+  		
+  		g_print("  [%c] %s\n", result_char, test->name);
+    }
+	
+	g_print ("\n");
+	g_print ("%d / %d tests succeded\n", success_count, tests_count);
+	
+	g_list_free (tests);
+	
+	if (success_count != tests_count)
+    {
+		  return EXIT_FAILURE;
+	  }
 	
 	return EXIT_SUCCESS;
 }
 
-Test *test_init(const gchar *name) {
-	Test *test = g_new(Test, 1);
+Test
+*test_init (const gchar *name)
+{
+	Test *test = g_new (Test, 1);
 	test->name = (gchar *) name;
 	test->succeded = FALSE;
-	tests = g_list_append(tests, test);
+	tests = g_list_append (tests, test);
 	
-	g_print("Running test %s...\n", name);
+	g_print ("Running test %s...\n", name);
 	
 	return test;
 }
 
-void test_succeded(Test *test) {
+void
+test_succeded (Test *test)
+{
 	test->succeded = TRUE;
 }

Modified: trunk/libsoylent/test/test.h
==============================================================================
--- trunk/libsoylent/test/test.h	(original)
+++ trunk/libsoylent/test/test.h	Sat Jun 14 16:04:57 2008
@@ -1,4 +1,4 @@
-//
+/**/
 
 #ifndef TEST_H
 #define TEST_H
@@ -7,17 +7,18 @@
 
 typedef struct _Test Test;
 
-struct _Test {
+struct _Test
+{
 	gchar *name;
 	gboolean succeded;
 };
 
 GList *tests;
 
-Test *test_init(const gchar *name);
-void test_succeded(Test *test);
+Test *test_init (const gchar *name);
+void test_succeded (Test *test);
 
-void init(void);
-void playground(void);
+void init (void);
+void playground (void);
 
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]