[libgda] Unit tests for GdaData.DbTable/Table
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Unit tests for GdaData.DbTable/Table
- Date: Fri, 17 Feb 2012 20:45:10 +0000 (UTC)
commit 699628c6603ae7bcc26e0288c0b29e1bd18fc6e0
Author: Daniel Espinosa <despinosa src gnome org>
Date: Wed Feb 15 19:07:14 2012 -0600
Unit tests for GdaData.DbTable/Table
libgda/data/DbTable.vala | 2 +-
libgda/data/Table.vala | 3 +-
tests/vala/CheckTable.vala | 121 ++++++++++++++++++++++++++++++++++++++++++++
tests/vala/Makefile.am | 25 +++++++++-
4 files changed, 148 insertions(+), 3 deletions(-)
---
diff --git a/libgda/data/DbTable.vala b/libgda/data/DbTable.vala
index 05dffe8..5e2175f 100644
--- a/libgda/data/DbTable.vala
+++ b/libgda/data/DbTable.vala
@@ -22,7 +22,7 @@ using Gda;
namespace GdaData
{
- public interface DbTable : DbObject, DbNamedObject
+ public interface DbTable : Object, DbObject, DbNamedObject
{
public abstract DbCatalog catalog { get; set; }
public abstract DbSchema schema { get; set; }
diff --git a/libgda/data/Table.vala b/libgda/data/Table.vala
index dfb7d6f..5d27edb 100644
--- a/libgda/data/Table.vala
+++ b/libgda/data/Table.vala
@@ -163,7 +163,8 @@ namespace GdaData
var pk = new Gee.HashMap<string,DbFieldInfo> ();
foreach (DbFieldInfo f in fields)
{
- if (DbFieldInfo.Attribute.PRIMARY_KEY in f.attributes)
+ if (DbFieldInfo.Attribute.PRIMARY_KEY in f.attributes
+ || DbFieldInfo.Attribute.UNIQUE in f.attributes)
{
pk.set (f.name, f);
}
diff --git a/tests/vala/CheckTable.vala b/tests/vala/CheckTable.vala
new file mode 100644
index 0000000..8709a0a
--- /dev/null
+++ b/tests/vala/CheckTable.vala
@@ -0,0 +1,121 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata Unit Tests
+ * Copyright (C) Daniel Espinosa Ortiz 2011 <esodan gmail com>
+ *
+ * libgda is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libgda is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gda;
+using GdaData;
+using Gee;
+
+namespace Check {
+ class Tests : GLib.Object {
+ public Gda.Connection connection { get; set; }
+ public DbTable table;
+
+ Tests()
+ {
+ try {
+ GLib.FileUtils.unlink("table.db");
+ stdout.printf("Creating Database...\n");
+ this.connection = Connection.open_from_string("SQLite", "DB_DIR=.;DB_NAME=dataobject", null, Gda.ConnectionOptions.NONE);
+ stdout.printf("Creating table 'user'...\n");
+ this.connection.execute_non_select_command("CREATE TABLE user (id integer PRIMARY KEY AUTOINCREMENT, name string UNIQUE, city string)");
+ this.connection.execute_non_select_command("INSERT INTO user (id, name, city) VALUES (1, \"Daniel\", \"Mexico\")");
+ this.connection.execute_non_select_command("INSERT INTO user (id, name, city) VALUES (2, \"Jhon\", \"USA\")");
+
+ stdout.printf("Creating table 'company'...\n");
+ this.connection.execute_non_select_command("CREATE TABLE company (id int PRIMARY KEY, name string, responsability string)");
+ this.connection.execute_non_select_command("INSERT INTO company (id, name, responsability) VALUES (1, \"Telcsa\", \"Programing\")");
+ this.connection.execute_non_select_command("INSERT INTO company (id, name, responsability) VALUES (2, \"Viasa\", \"Accessories\")");
+ this.connection.update_meta_store(null);
+ }
+ catch (Error e) {
+ stdout.printf ("Couln't create temporary database...\nERROR: %s\n", e.message);
+ }
+ }
+
+ public int update ()
+ throws Error
+ {
+ stdout.printf(">>> NEW TEST: GdaData.DbTable -- Update\n");
+ int fails = 0;
+ stdout.printf("Creating new table\n");
+ table = new Table ();
+ stdout.printf("Setting connection\n");
+ t.connection = this.connection;
+ stdout.printf("Setting name\n");
+ t.name = "user";
+ stdout.printf(">>> Updating meta information\n");
+ t.update ();
+ return fails;
+ }
+
+ public int fields ()
+ throws Error
+ {
+ stdout.printf(">>> NEW TEST: Gda.DbTable - Fields...\n");
+ int fails = 0;
+ var f = new Gee.HashSet<string> ();
+ f.add ("id");
+ f.add ("name");
+ f.add ("city");
+ foreach (DbFieldInfo fi in table.fields)
+ {
+ if (! f.contains (fi.name))
+ {
+ fails++;
+ break;
+ }
+ }
+ var f2 = new Gee.HashSet<string> ();
+ f2.add ("id");
+ f2.add ("name");
+ foreach (DbFieldInfo fi2 in table.primary_keys)
+ {
+ if (! f2.contains (fi2.name))
+ {
+ fails++;
+ break;
+ }
+ }
+
+ //FIXME: Add test for default values
+
+ return fails;
+ }
+
+ public static int main (string[] args) {
+ stdout.printf ("Checking GdaData.DbRecord implementation...\n");
+ int failures = 0;
+ var app = new Tests ();
+ try {
+ failures += app.update ();
+ failures += app.fields ();
+ //failures += app.records ();
+ //failures += app.depends ();
+ //failures += app.references ();
+ //failures += app.check_expression ();
+ }
+ catch (Error e)
+ {
+ stdout.printf ("ERROR: " + e.message);
+ return 1;
+ }
+ return failures != 0 ? 1 : 0;
+ }
+ }
+}
diff --git a/tests/vala/Makefile.am b/tests/vala/Makefile.am
index a185ed4..10df461 100644
--- a/tests/vala/Makefile.am
+++ b/tests/vala/Makefile.am
@@ -12,17 +12,19 @@ AM_CPPFLAGS = \
-DROOT_DIR=\""$(top_srcdir)"\"
TESTS_ENVIRONMENT =
-TESTS = check_dataobject check_datamodeliterator
+TESTS = check_dataobject check_datamodeliterator check_table
check_PROGRAMS = check_dataobject check_datamodeliterator
BUILT_SOURCES = \
check_dataobject.vala.stamp \
check_datamodeliterator.vala.stamp \
+ check_table.vala.stamp \
$(NULL)
CLEANFILES = \
check_dataobject.vala.stamp \
check_datamodeliterator.vala.stamp \
+ check_table.vala.stamp \
$(NULL)
VALAFLAGS = \
@@ -44,6 +46,10 @@ check_datamodeliterator_VALASOURCES = \
CheckDataModelIterator.vala \
$(NULL)
+check_table_VALASOURCES = \
+ CheckTable.vala \
+ $(NULL)
+
check_dataobject.vala.stamp: $(check_dataobject_VALASOURCES)
$(VALA_COMPILER) $(VALAFLAGS) -C -H check_dataobject.h $^
@touch $@
@@ -52,6 +58,10 @@ check_datamodeliterator.vala.stamp: $(check_datamodeliterator_VALASOURCES)
$(VALA_COMPILER) $(VALAFLAGS) -C -H check_datamodeliterator.h $^
@touch $@
+check_table.vala.stamp: $(check_datamodeliterator_VALASOURCES)
+ $(VALA_COMPILER) $(VALAFLAGS) -C -H check_datamodeliterator.h $^
+ @touch $@
+
check_dataobject_SOURCES = $(check_dataobject_VALASOURCES:.vala=.c) check_dataobject.h
check_dataobject_CFLAGS= \
-I$(top_builddir) \
@@ -74,6 +84,18 @@ check_datamodeliterator_LDADD = \
$(COREDEPS_LIBS) \
$(GEE_LIBS)
+
+check_table_SOURCES = $(check_datamodeliterator_VALASOURCES:.vala=.c) check_datamodeliterator.h
+check_table_CFLAGS= \
+ -I$(top_builddir) \
+ -I$(top_builddir)/libgda/data \
+ $(NULL)
+check_table_LDADD = \
+ $(top_builddir)/libgda/libgda-5.0.la \
+ $(top_builddir)/libgda/data/libgdadata-5.0.la \
+ $(COREDEPS_LIBS) \
+ $(GEE_LIBS)
+
CLEANFILES += \
$(check_dataobject_VALASOURCES:.vala=.c) \
check_dataobject.h \
@@ -81,6 +103,7 @@ CLEANFILES += \
check_datamodeliterator.h \
dataobject.db \
datamodeliterator.db \
+ table.db \
$(NULL)
EXTRA_DIST =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]