[libgda/libgda-vala] GdaDataObject basic API and unit test fixed to build



commit e07195c138d8a6ec1eaee657049e301c57dc5a8e
Author: Daniel Espinosa <despinosa src gnome org>
Date:   Tue Nov 29 16:33:01 2011 -0600

    GdaDataObject basic API and unit test fixed to build

 libgda/data/DataObject.vala     |    3 +-
 libgda/data/Makefile.am         |   18 ++++----
 tests/vala/CheckDataObject.vala |  101 ++++++++++++++++++++++++++++++++-------
 tests/vala/Makefile.am          |   13 ++++-
 4 files changed, 105 insertions(+), 30 deletions(-)
---
diff --git a/libgda/data/DataObject.vala b/libgda/data/DataObject.vala
index 6e25ca1..f8d03dc 100644
--- a/libgda/data/DataObject.vala
+++ b/libgda/data/DataObject.vala
@@ -24,10 +24,10 @@ namespace GdaData {
 
     public abstract class Object : GLib.Object {
         
-        private DataModel? _model;
         private string? _field_id;
         private Value? _id_value;
         
+        protected DataModel? _model;
         protected string? _table;
         
         public Connection connection { get; set; }
@@ -94,6 +94,7 @@ namespace GdaData {
 			var e_id = q.add_expr_value (null, this._id_value);
 			var c_id = q.add_cond (SqlOperatorType.EQ, f_id, e_id, 0);
 			q.set_where (c_id);
+			q.select_add_field ("*", null, null);
 			return q;			
         }
     }
diff --git a/libgda/data/Makefile.am b/libgda/data/Makefile.am
index 0cd8a22..4facbfa 100644
--- a/libgda/data/Makefile.am
+++ b/libgda/data/Makefile.am
@@ -20,7 +20,7 @@ AM_CFLAGS =\
     $(VALA_CFLAGS) \
     $(NULL)
 
-lib_LTLIBRARIES = libgdadata.la
+lib_LTLIBRARIES = libgdadata-1.0.la
 
 VALAFLAGS = \
     --vapidir=$(top_srcdir)/libgda \
@@ -29,25 +29,25 @@ VALAFLAGS = \
     --pkg libgda-5.0 \
     $(NULL)
 
-libgdadata_la_VALASOURCES = \
+libgdadata_1_0_la_VALASOURCES = \
 	DataObject.vala \
 	SelectQuery.vala \
 	$(NULL)
 
-libgdadata_la_SOURCES = \
+libgdadata_1_0_la_SOURCES = \
 	gdadata.vala.stamp \
-	$(libgdadata_la_VALASOURCES:.vala=.c) \
+	$(libgdadata_1_0_la_VALASOURCES:.vala=.c) \
 	$(NULL)	
 
-gdadata-1.0.vapi gdadata.vala.stamp GdaData-1.0.gir: $(libgdadata_la_VALASOURCES)
+gdadata-1.0.vapi gdadata.vala.stamp GdaData-1.0.gir: $(libgdadata_1_0_la_VALASOURCES)
 	$(VALA_COMPILER) $(VALAFLAGS) -C -H libgdadata.h --gir=GdaData-1.0.gir --library gdadata-1.0 $^
 	@touch $@
 
 CLEANFILES+= gdadata-1.0.vapi GdaData-1.0.gir
 
-libgdadata_la_LDFLAGS = 
+libgdadata_1_0_la_LDFLAGS = 
 
-libgdadata_la_LIBADD = \
+libgdadata_1_0_la_LIBADD = \
     $(top_builddir)/libgda/libgda-5.0.la \
 	$(LIBGDA_LIBS) \
 	$(GEE_LIBS) \
@@ -88,11 +88,11 @@ typelibs_DATA = GdaData-1.0.typelib
 vapidir = $(VALA_VAPIDIR)
 vapi_DATA = gdadata-1.0.vapi
 
-CLEANFILES += $(INTROSPECTION_GIRS) $(typelibs_DATA) gdadata-1.0.vapi 
+CLEANFILES += $(INTROSPECTION_GIRS) $(typelibs_DATA) gdadata-1.0.vapi $(libgdadata_1_0_la_VALASOURCES:.vala=.c)
 
 EXTRA_DIST = \
 	libgdadata-1.0.pc.in \
-	$(libgdadata_la_VALASOURCES:.vala=.c) \
+	$(libgdadata_1_0_la_VALASOURCES:.vala=.c) \
 	$(vapi_DATA) \
 	$(INTROSPECTION_GIRS) \
 	$(typelibs_DATA) \
diff --git a/tests/vala/CheckDataObject.vala b/tests/vala/CheckDataObject.vala
index ffc4008..af6a2e7 100644
--- a/tests/vala/CheckDataObject.vala
+++ b/tests/vala/CheckDataObject.vala
@@ -22,47 +22,114 @@ using GdaData;
 
 namespace Check {
 	class Tests : GdaData.Object {
+		private int fails;
+		
 		Tests()
 		{
 			try {
-				this.connection = Connection.open_sqlite(null, "check_dataobject", true);
-				this.connection.execute_non_select_command("CREATE TABLE user (int id, string name, string city)");
+				GLib.FileUtils.unlink("dataobject.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 int PRIMARY KEY, name string, 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\")");
-			
-				this.connection.execute_non_select_command("CREATE TABLE company (int id, string name, string responsability)");
-				this.connection.execute_non_select_command("INSERT INTO company (id, name, city) VALUES (1, \"Telcsa\", \"Programing\")");
-				this.connection.execute_non_select_command("INSERT INTO company (id, name, city) VALUES (2, \"Viasa\", \"Accessories\")");
+				
+				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...\n");
+				stdout.printf ("Couln't create temporary database...\nERROR: %s\n", e.message);
 			}
 		}
 		
 		public int t1()
 			throws Error
 		{
+			stdout.printf(">>> NEW TEST: Gda.DataObject API tests\n");
 			int fails = 0;
 			this._table = "user";
 			Value v = 1;
-			this.set_id ("id", v);
-			var f = this.get_field_id();
-			if ( f != "id")
+			stdout.printf("Setting ID to %i\n", (int) v);
+			try {
+				this.set_id ("id", v);
+				var f = this.get_field_id();
+				if ( f != "id") {
+					fails++;
+					stdout.printf("FAILS: %i\n", fails);
+				}
+			}
+			catch (Error e) {
+				fails++;
+				stdout.printf ("Couln't set ID...\nFAILS: %i\nERROR: %s\n", fails, e.message);
+			}
+			
+			stdout.printf("DataObject points to, in table '%s':\n", this._table);
+			stdout.printf("%s\n", this._model.dump_as_string());
+			
+			stdout.printf("Getting ID value...\n");
+			var i = (int) this.get_value_id();
+			if (i != 1 ){
+				fails++;
+				stdout.printf("FAILS: %i\n", fails);
+			}
+			
+			stdout.printf("Getting value at 'name'...\n");
+			var vdb = (string) this.get_value ("name");
+			if (vdb == null ){
+				fails++;
+				stdout.printf("FAILS: %i\n", fails);
+			}
+			else
+				if ( (string)vdb != "Daniel"){
+					fails++;
+					stdout.printf("FAILS: %i\n", fails);
+				}
+			
+			stdout.printf("Setting value at 'name'...\n");
+			Value n = "Daniel Espinosa";
+			this.set_value ("name", n);
+			stdout.printf("DataObject points to in memory modified value, in table '%s':\n", this._table);
+			stdout.printf("%s\n", this._model.dump_as_string());
+			
+			stdout.printf("Saving changes...\n");
+			try {
+				this.save();
+				stdout.printf("DataObject points to modified value, in table '%s':\n", this._table);
+				stdout.printf("%s\n", this._model.dump_as_string());
+			}
+			catch (Error e) {
 				fails++;
+				stdout.printf ("Couln't SAVE...\nFAILS: %i\nERROR: %s\n", fails, e.message);
+			}
 			
-			var i = this.get_value_id();
-			if (i != 1 )
-			    fails++;
-			    
-			var vdb = this.get_value ("name");
-			if ( vdb != "Daniel")
+			try {
+				this.connection.execute_non_select_command("UPDATE user SET name = \"Jhon Strauss\", city =\"New Jersey\"");
+			}
+			catch (Error e) {
 				fails++;
+				stdout.printf ("Couln't manual update table '%s'...\nFAILS: %i\nERROR: %s\n", this._table, fails, e.message);
+			}
+			
+			stdout.printf("Updating values from database...\n");
+			try {
+				this.update();
+				stdout.printf("DataObject points to actual stored values, in table '%s':\n", this._table);
+				stdout.printf("%s\n", this._model.dump_as_string());
+			}
+			catch (Error e) {
+				fails++;
+				stdout.printf ("Couln't UPDATE...\nFAILS: %i\nERROR: %s\n", fails, e.message);
+			}
 			
 			return fails;
 		}
 		
 		public static int main (string[] args) {
-			stdout.printf ("Checking Gda.DataObject implementation\n");
+			stdout.printf ("Checking Gda.DataObject implementation...\n");
 			int failures = 0;
 			var app = new Tests ();
 			failures += app.t1 ();
diff --git a/tests/vala/Makefile.am b/tests/vala/Makefile.am
index 189189e..da7b37e 100644
--- a/tests/vala/Makefile.am
+++ b/tests/vala/Makefile.am
@@ -28,10 +28,17 @@ VALAFLAGS = \
     $(NULL)
 
 check_dataobject_VALASOURCES = \
-	CheckDataObject.vala
+	CheckDataObject.vala \
+	$(NULL)
 
-check_dataobject check_dataobject.vala.stamp: $(check_dataobject_VALASOURCES)
-	$(VALA_COMPILER) $(VALAFLAGS) -o check_dataobject $^
+check_dataobject.vala.stamp: $(check_dataobject_VALASOURCES)
+	$(VALA_COMPILER) $(VALAFLAGS) -C -H check_dataobject.h $^
 	@touch $@
 
+check_dataobject_SOURCES = $(check_dataobject_VALASOURCES:.vala=.c) check_dataobject.h
+check_dataobject_LDADD = \
+    $(top_builddir)/libgda/libgda-5.0.la \
+	$(top_builddir)/libgda/data/libgdadata-1.0.la \
+	$(COREDEPS_LIBS)
+
 EXTRA_DIST = 



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