[Goodies-commits] r5292 - in xfbib/branches/gobject: src tests

David Gustafsson tssj at xfce.org
Sat Aug 23 16:54:14 CEST 2008


Author: tssj
Date: 2008-08-23 14:54:14 +0000 (Sat, 23 Aug 2008)
New Revision: 5292

Added:
   xfbib/branches/gobject/src/xfbib-value.c
   xfbib/branches/gobject/src/xfbib-value.h
   xfbib/branches/gobject/tests/test-xfbib-value.c
Modified:
   xfbib/branches/gobject/src/Makefile.am
   xfbib/branches/gobject/tests/Makefile.am
   xfbib/branches/gobject/tests/test-xfbib-elements.c
Log:
Initial work on the parser.


Modified: xfbib/branches/gobject/src/Makefile.am
===================================================================
--- xfbib/branches/gobject/src/Makefile.am	2008-08-23 10:50:41 UTC (rev 5291)
+++ xfbib/branches/gobject/src/Makefile.am	2008-08-23 14:54:14 UTC (rev 5292)
@@ -34,6 +34,8 @@
 	xfbib-toolbar.h \
 	xfbib-tree-view.c \
 	xfbib-tree-view.h \
+	xfbib-value.c \
+	xfbib-value.h \
 	xfbib-window.c \
 	xfbib-window.h
 

Added: xfbib/branches/gobject/src/xfbib-value.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-value.c	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-value.c	2008-08-23 14:54:14 UTC (rev 5292)
@@ -0,0 +1,63 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <gtk/gtk.h>
+
+#include "xfbib-value.h"
+
+struct _XfbibValue
+{
+	GObject parent;
+};
+
+typedef struct _XfbibValueClass
+{
+	GObjectClass parent;
+} XfbibValueClass;
+
+static void xfbib_value_class_init(XfbibValueClass *klass);
+
+static void xfbib_value_init(XfbibValue *instance);
+static void xfbib_value_finalize(GObject *obj);
+
+G_DEFINE_TYPE(XfbibValue, xfbib_value, G_TYPE_OBJECT)
+
+static void
+xfbib_value_class_init(XfbibValueClass *klass)
+{
+	GObjectClass *object_class = (GObjectClass *)klass;
+	object_class->finalize = xfbib_value_finalize;
+}
+
+static void
+xfbib_value_init(XfbibValue *instance)
+{
+}
+
+static void
+xfbib_value_finalize(GObject *obj)
+{
+	G_OBJECT_CLASS(xfbib_value_parent_class)->finalize(obj);
+}
+
+XfbibValue *
+xfbib_value_new()
+{
+	XfbibValue *value;
+	value = g_object_new(XFBIB_TYPE_VALUE, NULL);
+	return value;
+}
+
+gboolean
+xfbib_value_parse(XfbibValue *value, const gchar *str)
+{
+
+	return FALSE;
+}
+
+
+gchar *
+xfbib_value_get_str(XfbibValue *value)
+{
+	return "";
+}

Added: xfbib/branches/gobject/src/xfbib-value.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-value.h	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-value.h	2008-08-23 14:54:14 UTC (rev 5292)
@@ -0,0 +1,26 @@
+#ifndef __XFBIB_VALUE_H
+#define __XFBIB_VALUE_H
+
+#include <glib-object.h>
+
+#define XFBIB_TYPE_VALUE             (xfbib_value_get_type())
+#define XFBIB_VALUE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_VALUE, XfbibValue))
+#define XFBIB_IS_VALUE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFBIB_TYPE_VALUE))
+#define XFBIB_VALUE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), XFBIB_TYPE_VALUE, XfbibValueClass))
+#define XFBIB_IS_VALUE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), XFBIB_TYPE_VALUE))
+#define XFBIB_VALUE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), XFBIB_TYPE_VALUE, XfbibValueClass))
+
+G_BEGIN_DECLS
+
+typedef struct _XfbibValue         XfbibValue;
+
+GType xfbib_value_get_type() G_GNUC_CONST;
+
+XfbibValue *xfbib_value_new();
+
+gboolean xfbib_value_parse(XfbibValue *, const gchar *);
+gchar *xfbib_value_get_str(XfbibValue *);
+G_END_DECLS
+
+#endif //__XFBIB_VALUE_H
+

Modified: xfbib/branches/gobject/tests/Makefile.am
===================================================================
--- xfbib/branches/gobject/tests/Makefile.am	2008-08-23 10:50:41 UTC (rev 5291)
+++ xfbib/branches/gobject/tests/Makefile.am	2008-08-23 14:54:14 UTC (rev 5292)
@@ -16,6 +16,7 @@
 	test-xfbib-entry \
 	test-xfbib-field \
 	test-xfbib-preamble \
+	test-xfbib-value \
 	test-xfbib-strbuf \
 	test-xfbib-string
 
@@ -92,6 +93,19 @@
 	$(test_xfbib_preamble_DEPENDENCIES)
 
 ###
+# Test xfbib-value.c
+###
+test_xfbib_value_SOURCES = \
+	test-xfbib-value.c
+
+test_xfbib_value_DEPENDENCIES = \
+	$(top_builddir)/src/xfbib-xfbib-value.o
+
+test_xfbib_value_LDADD = \
+	$(LDADD) \
+	$(test_xfbib_value_DEPENDENCIES)
+
+###
 # Test xfbib-strbuf.c
 ###
 test_xfbib_strbuf_SOURCES = \

Modified: xfbib/branches/gobject/tests/test-xfbib-elements.c
===================================================================
--- xfbib/branches/gobject/tests/test-xfbib-elements.c	2008-08-23 10:50:41 UTC (rev 5291)
+++ xfbib/branches/gobject/tests/test-xfbib-elements.c	2008-08-23 14:54:14 UTC (rev 5292)
@@ -67,18 +67,18 @@
 
 	object = g_list_nth_data(list, 0);
 	g_assert(XFBIB_IS_ENTRY(object));
-	g_assert(strcmp(xfbib_entry_get_bibtype(entry), "@misc") == 0);
-	g_assert(strcmp(xfbib_entry_get_key(entry), "patashnik-bibtexing") == 0);
+	g_assert(strcmp(xfbib_entry_get_bibtype(XFBIB_ENTRY(object)), "@misc") == 0);
+	g_assert(strcmp(xfbib_entry_get_key(XFBIB_ENTRY(object)), "patashnik-bibtexing") == 0);
 	
 	object = g_list_nth_data(list, 1);
 	g_assert(XFBIB_IS_ENTRY(object));
-	g_assert(strcmp(xfbib_entry_get_bibtype(entry), "@Article") == 0);
-	g_assert(strcmp(xfbib_entry_get_key(entry), "py03") == 0);
+	g_assert(strcmp(xfbib_entry_get_bibtype(XFBIB_ENTRY(object)), "@Article") == 0);
+	g_assert(strcmp(xfbib_entry_get_key(XFBIB_ENTRY(object)), "py03") == 0);
 	
 	object = g_list_nth_data(list, 2);
 	g_assert(XFBIB_IS_ENTRY(object));
-	g_assert(strcmp(xfbib_entry_get_bibtype(entry), "@Book") == 0);
-	g_assert(strcmp(xfbib_entry_get_key(entry), "steward03") == 0);
+	g_assert(strcmp(xfbib_entry_get_bibtype(XFBIB_ENTRY(object)), "@Book") == 0);
+	g_assert(strcmp(xfbib_entry_get_key(XFBIB_ENTRY(object)), "steward03") == 0);
 	
 
 	g_object_unref(elements);

Added: xfbib/branches/gobject/tests/test-xfbib-value.c
===================================================================
--- xfbib/branches/gobject/tests/test-xfbib-value.c	                        (rev 0)
+++ xfbib/branches/gobject/tests/test-xfbib-value.c	2008-08-23 14:54:14 UTC (rev 5292)
@@ -0,0 +1,68 @@
+/* 
+ * Copyright (c) 2008 Jesper Karlsson & David Gustafsson
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <gtk/gtk.h>
+
+#include "xfbib-value.h"
+
+/*
+ * TODO:
+ * Implement a getter method that returns a list of objects.
+ * Check that the returned list contains the right objects
+ */
+
+int main(int argc, char **argv)
+{
+	XfbibValue *value;
+	gtk_init(&argc, &argv);
+	
+	value = xfbib_value_new();
+
+	g_assert(xfbib_value_parse(value, "\"Maintained by \" # maintainer"));
+	g_assert(strcmp(xfbib_value_get_str(value), "\"Maintained by \" # maintainer") == 0);
+
+	g_assert(xfbib_value_parse(value, "1921"));
+	g_assert(strcmp(xfbib_value_get_str(value), "1921") == 0);
+
+	g_assert(xfbib_value_parse(value, "\"april\""));
+	g_assert(strcmp(xfbib_value_get_str(value), "\"april\"") == 0);
+	
+	g_assert(xfbib_value_parse(value, "firstname # \".\" # lastname # \"@imag.fr\""));
+	g_assert(strcmp(xfbib_value_get_str(value), "firstname # \".\" # lastname # \"@imag.fr\"") == 0);
+	
+	g_assert(xfbib_value_parse(value, "\"The history of @ sign\""));
+	g_assert(strcmp(xfbib_value_get_str(value), "\"The history of @ sign\"") == 0);
+	
+	g_assert(xfbib_value_parse(value, "\"Simon {\"}the {saint\"} Templar\""));
+	g_assert(strcmp(xfbib_value_get_str(value), "\"Simon {\"}the {saint\"} Templar\"") == 0);
+	
+	g_assert(xfbib_value_parse(value, "\"A {bunch {of} braces {in}} title\""));
+	g_assert(strcmp(xfbib_value_get_str(value), "\"A {bunch {of} braces {in}} title\"") == 0);
+	
+	g_assert(!xfbib_value_parse(value, "{ The history of @ sign }"));
+	
+	g_assert(!xfbib_value_parse(value, "\"Simon \\\"the saint\\\" Templar\""));
+	
+	g_assert(!xfbib_value_parse(value, "\"The lonely { brace\""));
+	
+	g_object_unref(value);
+
+	return EXIT_SUCCESS;
+}




More information about the Goodies-commits mailing list