[Goodies-commits] r5304 - in xfbib/branches/gobject: . src tests
David Gustafsson
tssj at xfce.org
Mon Aug 25 22:09:34 CEST 2008
Author: tssj
Date: 2008-08-25 20:09:34 +0000 (Mon, 25 Aug 2008)
New Revision: 5304
Added:
xfbib/branches/gobject/src/xfbib-integer.c
xfbib/branches/gobject/src/xfbib-integer.h
xfbib/branches/gobject/tests/test-xfbib-integer.c
Modified:
xfbib/branches/gobject/TODO
xfbib/branches/gobject/src/Makefile.am
xfbib/branches/gobject/src/xfbib-preamble.c
xfbib/branches/gobject/src/xfbib-preamble.h
xfbib/branches/gobject/src/xfbib-string.c
xfbib/branches/gobject/src/xfbib-string.h
xfbib/branches/gobject/src/xfbib-value.c
xfbib/branches/gobject/src/xfbib-value.h
xfbib/branches/gobject/tests/Makefile.am
xfbib/branches/gobject/tests/test-xfbib-preamble.c
xfbib/branches/gobject/tests/test-xfbib-string.c
xfbib/branches/gobject/tests/test-xfbib-value.c
Log:
Started filling in the gaps in the parser.
Modified: xfbib/branches/gobject/TODO
===================================================================
--- xfbib/branches/gobject/TODO 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/TODO 2008-08-25 20:09:34 UTC (rev 5304)
@@ -5,6 +5,7 @@
* Update the icons.
* Fix the native language support.
* Support for non volatile configuration.
- * Update the README file
- * Make the entries editable
-
+ * Update the README file.
+ * Make the entries editable.
+ * Add funtionality so that bibtex files can be merged.
+ * Make the list sortable.
Modified: xfbib/branches/gobject/src/Makefile.am
===================================================================
--- xfbib/branches/gobject/src/Makefile.am 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/src/Makefile.am 2008-08-25 20:09:34 UTC (rev 5304)
@@ -14,6 +14,8 @@
xfbib-field.h \
xfbib-input-dialog.c \
xfbib-input-dialog.h \
+ xfbib-integer.c \
+ xfbib-integer.h \
xfbib-list-store.c \
xfbib-list-store.h \
xfbib-menu-bar.c \
Added: xfbib/branches/gobject/src/xfbib-integer.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-integer.c (rev 0)
+++ xfbib/branches/gobject/src/xfbib-integer.c 2008-08-25 20:09:34 UTC (rev 5304)
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <gtk/gtk.h>
+
+#include "xfbib-integer.h"
+#include "xfbib-strbuf.h"
+
+struct _XfbibInteger
+{
+ GObject parent;
+ XfbibStrbuf *str;
+};
+
+typedef struct _XfbibIntegerClass
+{
+ GObjectClass parent;
+} XfbibIntegerClass;
+
+static void xfbib_integer_class_init(XfbibIntegerClass *klass);
+
+static void xfbib_integer_init(XfbibInteger *instance);
+static void xfbib_integer_finalize(GObject *obj);
+
+G_DEFINE_TYPE(XfbibInteger, xfbib_integer, G_TYPE_OBJECT)
+
+static void
+xfbib_integer_class_init(XfbibIntegerClass *klass)
+{
+ GObjectClass *object_class = (GObjectClass *)klass;
+ object_class->finalize = xfbib_integer_finalize;
+}
+
+static void
+xfbib_integer_init(XfbibInteger *instance)
+{
+ instance->str = xfbib_strbuf_new();
+}
+
+static void
+xfbib_integer_finalize(GObject *obj)
+{
+ G_OBJECT_CLASS(xfbib_integer_parent_class)->finalize(obj);
+}
+
+
+const gchar *
+xfbib_integer_get(XfbibInteger *integer)
+{
+ return xfbib_strbuf_get_str(integer->str);
+}
+
+void
+xfbib_integer_set(XfbibInteger *integer, const gchar *str)
+{
+ xfbib_strbuf_wipe(integer->str);
+ xfbib_strbuf_append(integer->str, str);
+}
+
+XfbibInteger *
+xfbib_integer_new()
+{
+ XfbibInteger *integer;
+ integer = g_object_new(XFBIB_TYPE_INTEGER, NULL);
+ return integer;
+}
+
Added: xfbib/branches/gobject/src/xfbib-integer.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-integer.h (rev 0)
+++ xfbib/branches/gobject/src/xfbib-integer.h 2008-08-25 20:09:34 UTC (rev 5304)
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+#ifndef __XFBIB_INTEGER_H
+#define __XFBIB_INTEGER_H
+
+#include <glib-object.h>
+
+#define XFBIB_TYPE_INTEGER (xfbib_integer_get_type())
+#define XFBIB_INTEGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_INTEGER, XfbibInteger))
+#define XFBIB_IS_INTEGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFBIB_TYPE_INTEGER))
+#define XFBIB_INTEGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XFBIB_TYPE_INTEGER, XfbibIntegerClass))
+#define XFBIB_IS_INTEGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), XFBIB_TYPE_INTEGER))
+#define XFBIB_INTEGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XFBIB_TYPE_INTEGER, XfbibIntegerClass))
+
+G_BEGIN_DECLS
+
+typedef struct _XfbibInteger XfbibInteger;
+
+GType xfbib_integer_get_type() G_GNUC_CONST;
+
+const gchar *xfbib_integer_get(XfbibInteger *);
+void xfbib_integer_set(XfbibInteger *, const gchar *);
+XfbibInteger *xfbib_integer_new();
+
+G_END_DECLS
+
+#endif //__XFBIB_INTEGER_H
+
Modified: xfbib/branches/gobject/src/xfbib-preamble.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-preamble.c 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/src/xfbib-preamble.c 2008-08-25 20:09:34 UTC (rev 5304)
@@ -23,10 +23,13 @@
#include <gtk/gtk.h>
#include "xfbib-preamble.h"
+#include "xfbib-value.h"
struct _XfbibPreamble
{
GObject parent;
+ gchar separator;
+ XfbibValue *value;
};
typedef struct _XfbibPreambleClass
@@ -51,6 +54,7 @@
static void
xfbib_preamble_init(XfbibPreamble *instance)
{
+ instance->value = xfbib_value_new();
}
static void
@@ -66,3 +70,30 @@
preamble = g_object_new(XFBIB_TYPE_PREAMBLE, NULL);
return preamble;
}
+
+gboolean
+xfbib_preamble_parse(XfbibPreamble *preamble, const gchar *s)
+{
+ gchar *str, *tmp;
+
+ str = g_strdup(s + 9);
+ g_strstrip(str);
+ preamble->separator = str[0];
+
+ tmp = g_strndup(str + 1, strlen(str) - 2);
+
+ if (!xfbib_value_parse(preamble->value, tmp)) {
+ free(tmp);
+ free(str);
+ return FALSE;
+ }
+ free(tmp);
+ free(str);
+ return TRUE;
+}
+
+const gchar *
+xfbib_preamble_get_value(XfbibPreamble *preamble)
+{
+ return xfbib_value_get_str(preamble->value);
+}
Modified: xfbib/branches/gobject/src/xfbib-preamble.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-preamble.h 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/src/xfbib-preamble.h 2008-08-25 20:09:34 UTC (rev 5304)
@@ -36,6 +36,8 @@
GType xfbib_preamble_get_type() G_GNUC_CONST;
XfbibPreamble *xfbib_preamble_new();
+gboolean xfbib_preamble_parse(XfbibPreamble *, const gchar *);
+const gchar *xfbib_preamble_get_value(XfbibPreamble *);
G_END_DECLS
Modified: xfbib/branches/gobject/src/xfbib-string.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-string.c 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/src/xfbib-string.c 2008-08-25 20:09:34 UTC (rev 5304)
@@ -25,12 +25,13 @@
#include "xfbib-string.h"
#include "xfbib-strbuf.h"
+#include "xfbib-value.h"
struct _XfbibString
{
GObject parent;
XfbibStrbuf *variable;
- XfbibStrbuf *value;
+ XfbibValue *value;
};
typedef struct _XfbibStringClass
@@ -69,69 +70,54 @@
return xfbib_strbuf_get_str(string->variable);
}
+void
+xfbib_string_set_variable(XfbibString *string, const gchar *variable)
+{
+ xfbib_strbuf_wipe(string->variable);
+ xfbib_strbuf_append(string->variable, variable);
+}
+
const gchar *
xfbib_string_get_value(XfbibString *string)
{
- return xfbib_strbuf_get_str(string->value);
+ return xfbib_value_get_str(string->value);
}
gboolean
-xfbib_string_parse(XfbibString *string, const gchar *s)
+xfbib_string_parse(XfbibString *string, const gchar *str)
{
- gint i = 0;
- gchar *str, *equal, *variable, *value;
+ gint i;
+ gchar **split = NULL, *tmp;
+
+ split = g_strsplit(str, "=", 2);
- str = g_strdup(s);
-
- if ((equal = strchr(str, '=')) == NULL) {
- /* Equal sign missing */
- g_warning("No equal sign found in definition of String: %s\n", str);
- g_free(str);
- return FALSE;
- }
-
- /* The variable starts after @string{ or @string( */
- variable = str + 8;
- value = equal + 1;
- equal[0] = '\0';
-
-
- /* Trim spaces and tabs from the beginning */
- while (variable != NULL && (variable[0] == ' ' || variable[0] == '\t'))
- variable++;
-
- /* Trim spaces and tabs from the end */
- for (i = strlen(variable) - 1; i > 0 && (variable[i] == ' ' || variable[i] == '\t'); i--)
- variable[i] = '\0';
-
- xfbib_strbuf_wipe(string->variable);
- xfbib_strbuf_append(string->variable, variable);
- /*
- * Value can be a variable or a "real" value.
- * A variable does not have quotes but a value do.
- */
- xfbib_strbuf_wipe(string->value);
- for (i = 0; i < strlen(value); i++) {
- if (value[i] = '"') {
- /* "Real" value */
- for (i++; i < strlen(value) || value[i] != '"'; i++) {
- xfbib_strbuf_append_char(string->value, value[i]);
- }
-
- if (value[i] != '"') {
- g_warning("Did not find a matching end quote for value in the string: %s\n", s);
- g_free(str);
+ for (i = 0; split[i] != NULL; i++) {
+ g_strstrip(split[i]);
+ if (strncasecmp(split[i], "@string", 7) == 0) {
+ /* Variable */
+ xfbib_strbuf_wipe(string->variable);
+ g_strstrip(split[i] + 7);
+ xfbib_strbuf_append(string->variable, split[i] + 8);
+ } else {
+ /* Value */
+ tmp = g_strndup(split[i], strlen(split[i]) - 1);
+ if (!xfbib_value_parse(string->value, tmp)) {
+ free(tmp);
+ g_strfreev(split);
return FALSE;
}
-// for (i++; i < strlen(value); i++) {
-// if (
-// }
- } else {
- /* Variable */
+ free(tmp);
}
}
- g_free(str);
+ if (split[1] == NULL) {
+ /* Equal sign missing */
+ g_warning("No equal sign found in definition of String\n");
+ g_strfreev(split);
+ return FALSE;
+ }
+
+ g_strfreev(split);
return TRUE;
}
@@ -142,7 +128,7 @@
string = g_object_new(XFBIB_TYPE_STRING, NULL);
string->variable = xfbib_strbuf_new();
- string->value = xfbib_strbuf_new();
+ string->value = xfbib_value_new();
return string;
}
Modified: xfbib/branches/gobject/src/xfbib-string.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-string.h 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/src/xfbib-string.h 2008-08-25 20:09:34 UTC (rev 5304)
@@ -36,6 +36,7 @@
GType xfbib_string_get_type() G_GNUC_CONST;
const gchar *xfbib_string_get_variable(XfbibString *);
+void xfbib_string_set_variable(XfbibString *, const gchar *);
const gchar *xfbib_string_get_value(XfbibString *);
gboolean xfbib_string_parse(XfbibString *, const gchar *);
XfbibString *xfbib_string_new();
Modified: xfbib/branches/gobject/src/xfbib-value.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-value.c 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/src/xfbib-value.c 2008-08-25 20:09:34 UTC (rev 5304)
@@ -6,12 +6,14 @@
#include "xfbib-value.h"
#include "xfbib-strbuf.h"
+#include "xfbib-string.h"
+#include "xfbib-integer.h"
+
struct _XfbibValue
{
GObject parent;
- XfbibStrbuf *str;
- XfbibValue *next;
+ GList *list;
};
typedef struct _XfbibValueClass
@@ -36,6 +38,7 @@
static void
xfbib_value_init(XfbibValue *instance)
{
+ instance->list = NULL;
}
static void
@@ -50,57 +53,134 @@
XfbibValue *value;
value = g_object_new(XFBIB_TYPE_VALUE, NULL);
- value->str = xfbib_strbuf_new();
- value->next = NULL;
-
return value;
}
gboolean
-xfbib_value_wipe(XfbibValue *value)
+xfbib_value_parse(XfbibValue *value, const gchar *str)
{
- if (value->next != NULL)
- {
- xfbib_value_wipe(value->next);
- value->next = NULL;
- }
- xfbib_strbuf_wipe(value->str);
- return TRUE;
-}
+ gint i, j, len, braces;
+ GList *list;
+ gchar **split = NULL;
+ GObject *obj;
-gboolean
-xfbib_value_parse(XfbibValue *value, const gchar *str)
-{
- int n;
- gchar *lcb;
- for (n = 0; n < strlen(str); n++)
- {
- switch (str[n])
- {
- case '#':
- value->next = xfbib_value_new();
- xfbib_value_parse(value->next, &str[n+1]);
- n=strlen(str);
- break;
- default:
- xfbib_strbuf_append_char(value->str, str[n]);
+ /* TODO: Free all elements of the list */
+ value->list = NULL;
+
+ split = g_strsplit(str, "#", 0);
+
+ for (i = 0; split[i] != NULL; i++) {
+ /*
+ * Check the type of the string to parse.
+ *
+ * If the string starts with " or { it is a string,
+ * if the string starts with a alphabetic character
+ * it is a variable or if it contains all numbers it
+ * is an integer.
+ */
+ g_strstrip(split[i]);
+ if (split[i][0] == '"' || split[i][0] == '{') {
+ /* String */
+
+ len = strlen(split[i]);
+
+ if (split[i][0] == '"' && split[i][len - 1] != '"')
+ return FALSE;
+ else if (split[i][0] == '{' && split[i][len - 1] != '}')
+ return FALSE;
+
+ if (split[i][0] == '{' && strchr(split[i], '@') != NULL) {
+ /* Braced string contains @ */
+ g_warning("Braced string contains @: %s\n", split[i]);
+ return FALSE;
+ }
+
+ braces = 0;
+ len = strlen(split[i]) - 1;
+ for (j = 1; j < len; j++) {
+ /* Check if the braces are balanced and quotes are inside braces*/
+ if (split[i][j] == '{')
+ braces++;
+ else if (split[i][j] == '}')
+ braces--;
+ else if (split[i][0] == '"' && split[i][j] == '"' && braces == 0) {
+ g_warning("Quote not inside braces in string: %s\n", split[i]);
+ return FALSE;
+ }
+ }
+
+ if (braces != 0) {
+ /* Braces was not balanced */
+ g_warning("Braces not balanced in field string: %s\n", split[i]);
+ return FALSE;
+ }
+
+ obj = G_OBJECT(xfbib_strbuf_new());
+ xfbib_strbuf_append(XFBIB_STRBUF(obj), split[i]);
+ value->list = g_list_prepend(value->list, obj);
+ } else if(g_ascii_isalpha(split[i][0])) {
+ /* Variable */
+
+ if (strstr(split[i], "\"") != NULL) {
+ g_warning("Variable contains double quote\n");
+ return FALSE;
+ }
+
+ obj = G_OBJECT(xfbib_string_new());
+ xfbib_string_set_variable(XFBIB_STRING(obj), split[i]);
+ value->list = g_list_prepend(value->list, obj);
+ } else {
+ len = strlen(split[i]);
+ for (j = 0; j < len; j++) {
+ if (!g_ascii_isdigit(split[i][j])) {
+ /* Character was not a number between 0 and 9 */
+ g_warning("TODO: Add a character in number warning\n");
+ return FALSE;
+ }
+ }
+ /* Integer */
+ obj = G_OBJECT(xfbib_integer_new());
+ xfbib_integer_set(XFBIB_INTEGER(obj), split[i]);
+ value->list = g_list_prepend(value->list, obj);
}
}
+
+ g_strfreev(split);
+
+
+ value->list = g_list_reverse(value->list);
return TRUE;
}
const gchar *
xfbib_value_get_str(XfbibValue *value)
{
- XfbibStrbuf *tmp;
- tmp = xfbib_strbuf_new();
+ XfbibStrbuf *buf;
+ int i, len;
+ GObject *obj;
+
+ if ((obj = g_list_nth_data(value->list, 0)) == NULL)
+ return "";
- xfbib_strbuf_append(tmp, xfbib_strbuf_get_str(value->str));
- if (value->next != NULL)
- {
- xfbib_strbuf_append_char(tmp, '#');
- xfbib_strbuf_append(tmp, xfbib_value_get_str(value->next));
+ buf = xfbib_strbuf_new();
+ if (XFBIB_IS_STRBUF(obj))
+ xfbib_strbuf_append(buf, xfbib_strbuf_get_str(XFBIB_STRBUF(obj)));
+ else if (XFBIB_IS_STRING(obj))
+ xfbib_strbuf_append(buf, xfbib_string_get_variable(XFBIB_STRING(obj)));
+ else if (XFBIB_IS_INTEGER(obj))
+ xfbib_strbuf_append(buf, xfbib_integer_get(XFBIB_INTEGER(obj)));
+
+ len = g_list_length(value->list);
+ for (i = 1; i < len; i++) {
+ xfbib_strbuf_append(buf, " # ");
+
+ obj = g_list_nth_data(value->list, i);
+ if (XFBIB_IS_STRBUF(obj))
+ xfbib_strbuf_append(buf, xfbib_strbuf_get_str(XFBIB_STRBUF(obj)));
+ else if (XFBIB_IS_STRING(obj))
+ xfbib_strbuf_append(buf, xfbib_string_get_variable(XFBIB_STRING(obj)));
+ else if (XFBIB_IS_INTEGER(obj))
+ xfbib_strbuf_append(buf, xfbib_integer_get(XFBIB_INTEGER(obj)));
}
-
- return xfbib_strbuf_get_str(tmp);
+ return xfbib_strbuf_get_str(buf);
}
Modified: xfbib/branches/gobject/src/xfbib-value.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-value.h 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/src/xfbib-value.h 2008-08-25 20:09:34 UTC (rev 5304)
@@ -18,8 +18,6 @@
XfbibValue *xfbib_value_new();
-
-gboolean xfbib_value_wipe(XfbibValue *value);
gboolean xfbib_value_parse(XfbibValue *, const gchar *);
const gchar *xfbib_value_get_str(XfbibValue *);
G_END_DECLS
Modified: xfbib/branches/gobject/tests/Makefile.am
===================================================================
--- xfbib/branches/gobject/tests/Makefile.am 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/tests/Makefile.am 2008-08-25 20:09:34 UTC (rev 5304)
@@ -15,6 +15,7 @@
test-xfbib-comment \
test-xfbib-entry \
test-xfbib-field \
+ test-xfbib-integer \
test-xfbib-preamble \
test-xfbib-value \
test-xfbib-strbuf \
@@ -80,12 +81,29 @@
$(test_xfbib_field_DEPENDENCIES)
###
+# Test xfbib-integer.c
+###
+test_xfbib_integer_SOURCES = \
+ test-xfbib-integer.c
+
+test_xfbib_integer_DEPENDENCIES = \
+ $(top_builddir)/src/xfbib-xfbib-integer.o \
+ $(top_builddir)/src/xfbib-xfbib-strbuf.o
+
+test_xfbib_integer_LDADD = \
+ $(LDADD) \
+ $(test_xfbib_integer_DEPENDENCIES)
+###
# Test xfbib-preamble.c
###
test_xfbib_preamble_SOURCES = \
test-xfbib-preamble.c
test_xfbib_preamble_DEPENDENCIES = \
+ $(top_builddir)/src/xfbib-xfbib-integer.o \
+ $(top_builddir)/src/xfbib-xfbib-string.o \
+ $(top_builddir)/src/xfbib-xfbib-strbuf.o \
+ $(top_builddir)/src/xfbib-xfbib-value.o \
$(top_builddir)/src/xfbib-xfbib-preamble.o
test_xfbib_preamble_LDADD = \
@@ -99,6 +117,8 @@
test-xfbib-value.c
test_xfbib_value_DEPENDENCIES = \
+ $(top_builddir)/src/xfbib-xfbib-integer.o \
+ $(top_builddir)/src/xfbib-xfbib-string.o \
$(top_builddir)/src/xfbib-xfbib-strbuf.o \
$(top_builddir)/src/xfbib-xfbib-value.o
@@ -127,6 +147,8 @@
test_xfbib_string_DEPENDENCIES = \
$(top_builddir)/src/xfbib-xfbib-string.o \
+ $(top_builddir)/src/xfbib-xfbib-integer.o \
+ $(top_builddir)/src/xfbib-xfbib-value.o \
$(top_builddir)/src/xfbib-xfbib-strbuf.o
test_xfbib_string_LDADD = \
Added: xfbib/branches/gobject/tests/test-xfbib-integer.c
===================================================================
--- xfbib/branches/gobject/tests/test-xfbib-integer.c (rev 0)
+++ xfbib/branches/gobject/tests/test-xfbib-integer.c 2008-08-25 20:09:34 UTC (rev 5304)
@@ -0,0 +1,38 @@
+/*
+ * 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-integer.h"
+
+int main(int argc, char **argv)
+{
+ XfbibInteger *integer;
+ gtk_init(&argc, &argv);
+
+ integer = xfbib_integer_new();
+
+ xfbib_integer_set(integer, "1234");
+ g_assert(strcmp(xfbib_integer_get(integer), "1234") == 0);
+
+ g_object_unref(integer);
+
+ return EXIT_SUCCESS;
+}
Modified: xfbib/branches/gobject/tests/test-xfbib-preamble.c
===================================================================
--- xfbib/branches/gobject/tests/test-xfbib-preamble.c 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/tests/test-xfbib-preamble.c 2008-08-25 20:09:34 UTC (rev 5304)
@@ -29,6 +29,17 @@
preamble = xfbib_preamble_new();
+ g_assert(xfbib_preamble_parse(preamble, "@preamble {\"This bibliography was generated on \\today\"}"));
+ g_assert(strcmp(xfbib_preamble_get_value(preamble), "\"This bibliography was generated on \\today\"") == 0);
+
+ g_assert(xfbib_preamble_parse(preamble, "@preamble (\"This bibliography was generated on \\today\")"));
+ g_assert(strcmp(xfbib_preamble_get_value(preamble), "\"This bibliography was generated on \\today\"") == 0);
+
+ g_assert(xfbib_preamble_parse(preamble, "@preamble { \"Maintained by \" # maintainer }"));
+ g_assert(strcmp(xfbib_preamble_get_value(preamble), "\"Maintained by \" # maintainer") == 0);
+
+
+
g_object_unref(preamble);
return EXIT_SUCCESS;
Modified: xfbib/branches/gobject/tests/test-xfbib-string.c
===================================================================
--- xfbib/branches/gobject/tests/test-xfbib-string.c 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/tests/test-xfbib-string.c 2008-08-25 20:09:34 UTC (rev 5304)
@@ -31,20 +31,24 @@
g_assert(xfbib_string_parse(string, "@String(mar = \"march\")"));
g_assert(strcmp(xfbib_string_get_variable(string), "mar") == 0);
-// g_assert(strcmp(xfbib_string_get_value(string), "march") == 0);
+ g_assert(strcmp(xfbib_string_get_value(string), "\"march\"") == 0);
+
g_assert(xfbib_string_parse(string, "@String{mar = \"march\"}"));
g_assert(strcmp(xfbib_string_get_variable(string), "mar") == 0);
-// g_assert(strcmp(xfbib_string_get_value(string), "march") == 0);
+ g_assert(strcmp(xfbib_string_get_value(string), "\"march\"") == 0);
+
g_assert(!xfbib_string_parse(string, "@String{mar \"march\"}"));
-// g_assert(!xfbib_string_parse(string, "@String(mar = \"march\",\n"
-// " apr = \"april\")"));
-// g_assert(!xfbib_string_parse(string, "@String(mar = \"march)"));
-// g_assert(!xfbib_string_parse(string, "@String(mar = march\")"));
-// g_assert(xfbib_string_parse(string, "@String {email = firstname # \".\" # lastname # \"@imag.fr\"}"));
-// g_assert(strcmp(xfbib_string_get_variable(string), "email") == 0);
-// g_assert(strcmp(xfbib_string_get_value(string), "firstname # . # lastname # @imag.fr") == 0);
-
+ g_assert(!xfbib_string_parse(string, "@String(mar = \"march\",\n"
+ " apr = \"april\")"));
+ g_assert(!xfbib_string_parse(string, "@String(mar = \"march)"));
+
+ g_assert(!xfbib_string_parse(string, "@String(mar = march\")"));
+
+ g_assert(xfbib_string_parse(string, "@String {email = firstname # \".\" # lastname # \"@imag.fr\"}"));
+ g_assert(strcmp(xfbib_string_get_variable(string), "email") == 0);
+ g_assert(strcmp(xfbib_string_get_value(string), "firstname # \".\" # lastname # \"@imag.fr\"") == 0);
+
g_object_unref(string);
return EXIT_SUCCESS;
Modified: xfbib/branches/gobject/tests/test-xfbib-value.c
===================================================================
--- xfbib/branches/gobject/tests/test-xfbib-value.c 2008-08-25 19:54:55 UTC (rev 5303)
+++ xfbib/branches/gobject/tests/test-xfbib-value.c 2008-08-25 20:09:34 UTC (rev 5304)
@@ -39,50 +39,30 @@
g_assert(xfbib_value_parse(value, "\"Maintained by \" # maintainer"));
g_assert(strcmp(xfbib_value_get_str(value), "\"Maintained by \" # maintainer") == 0);
- xfbib_value_wipe(value);
-
g_assert(xfbib_value_parse(value, "1921"));
g_assert(strcmp(xfbib_value_get_str(value), "1921") == 0);
- xfbib_value_wipe(value);
-
g_assert(xfbib_value_parse(value, "\"april\""));
g_assert(strcmp(xfbib_value_get_str(value), "\"april\"") == 0);
- xfbib_value_wipe(value);
-
g_assert(xfbib_value_parse(value, "firstname # \".\" # lastname # \"@imag.fr\""));
g_assert(strcmp(xfbib_value_get_str(value), "firstname # \".\" # lastname # \"@imag.fr\"") == 0);
- xfbib_value_wipe(value);
-
g_assert(xfbib_value_parse(value, "\"The history of @ sign\""));
g_assert(strcmp(xfbib_value_get_str(value), "\"The history of @ sign\"") == 0);
- xfbib_value_wipe(value);
-
g_assert(xfbib_value_parse(value, "\"Simon {\"}the {saint\"} Templar\""));
g_assert(strcmp(xfbib_value_get_str(value), "\"Simon {\"}the {saint\"} Templar\"") == 0);
- xfbib_value_wipe(value);
-
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);
- xfbib_value_wipe(value);
-
g_assert(!xfbib_value_parse(value, "{ The history of @ sign }"));
- xfbib_value_wipe(value);
-
g_assert(!xfbib_value_parse(value, "\"Simon \\\"the saint\\\" Templar\""));
- xfbib_value_wipe(value);
-
g_assert(!xfbib_value_parse(value, "\"The lonely { brace\""));
- xfbib_value_wipe(value);
-
g_object_unref(value);
return EXIT_SUCCESS;
More information about the Goodies-commits
mailing list