[libgda/libgda-vala] Added initial tests cases for GdaDataObject for make check



commit bb632feebe2be3d85c1d08ca218c6e9f3d5000bc
Author: Daniel Espinosa <despinosa src gnome org>
Date:   Mon Nov 14 10:26:14 2011 -0600

    Added initial tests cases for GdaDataObject for make check

 libgda/vala/DataObject.vala     |   18 ++++++++++--
 tests/vala/CheckDataObject.vala |   57 +++++++++++++++++++++++++++++++++++++++
 tests/vala/Makefile.am          |   35 ++++++++++++++++++++++++
 3 files changed, 107 insertions(+), 3 deletions(-)
---
diff --git a/libgda/vala/DataObject.vala b/libgda/vala/DataObject.vala
index d63d461..2427d55 100644
--- a/libgda/vala/DataObject.vala
+++ b/libgda/vala/DataObject.vala
@@ -17,8 +17,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-using Gda;
-
 namespace Gda {
     public abstract class DataObject : Object {
         
@@ -27,7 +25,8 @@ namespace Gda {
         private Value _id_value;
         
         protected _table;
-        protected Connection _cnn;
+        
+        public Connection _cnn { get; set; };
         
         public SqlBuilder sql {
             get {
@@ -50,11 +49,13 @@ namespace Gda {
         }
         
         public void set_id (string field, Value cond)
+        	throws Error
         {
         	this._field_id = field;
         	this._id_value = cond;
         	var q = this.sql;
         	var m = this._cnn.statement_execute_select(q.get_statement(), null);
+        	((DataSelect) m).compute_modification_statements();
         	this._model = new DataProxy(m);
         }
         
@@ -62,5 +63,16 @@ namespace Gda {
         {
         	return this._model.get_value_at(this._model.get_column_index(field), 0);
         }
+        
+        public void set_value (string field, Value v)
+        {
+        	this._model.set_value_at(this._model.get_column_index(field), 0);
+        }
+        
+        public void save ()
+        	throws Error
+        {
+        	((DataProxy) this._model).apply_all_changes();
+        }
     }
 }
diff --git a/tests/vala/CheckDataObject.vala b/tests/vala/CheckDataObject.vala
new file mode 100644
index 0000000..052c9ab
--- /dev/null
+++ b/tests/vala/CheckDataObject.vala
@@ -0,0 +1,57 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgda
+ * Copyright (C) Daniel Espinosa Ortiz 2008 <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/>.
+ */
+ 
+namespace Check {
+	class Tests : DataObject {
+		Tests()
+		{
+			this._cnn = Connection.open_sqlite(null, "check_dataobject", true);
+			this._cnn.execute_non_select_command("CREATE TABLE user (int id, string name, string city)");
+			this._cnn.execute_non_select_command("INSERT INTO user (id, name, city) VALUES (1, \"Daniel\", \"Mexico\")");
+			this._cnn.execute_non_select_command("INSERT INTO user (id, name, city) VALUES (2, \"Jhon\", \"USA\")");
+			
+			this._cnn.execute_non_select_command("CREATE TABLE company (int id, string name, string responsability)");
+			this._cnn.execute_non_select_command("INSERT INTO company (id, name, city) VALUES (1, \"Telcsa\", \"Programing\")");
+			this._cnn.execute_non_select_command("INSERT INTO company (id, name, city) VALUES (2, \"Viasa\", \"Accessories\")");
+		}
+		
+		public int t1()
+		{
+			this._table = "user";
+			Value v = 1;
+			this.set_id ("id", v);
+			var f = this.get_field_id();
+			if ( f == "id")
+				return 0;
+			else
+				return 1;
+			
+			var i = this.get_value_id();
+			if ( )
+		}
+		
+		public static int main (string[] args) {
+			stdout.printf ("Checking Gda.DataObject implementation\n");
+			int failures = 0;
+			failures += t1 ();
+			failures += t2 ();
+			return failures != 0 ? 1 : 0;
+		}
+	}
+}
diff --git a/tests/vala/Makefile.am b/tests/vala/Makefile.am
new file mode 100644
index 0000000..f132806
--- /dev/null
+++ b/tests/vala/Makefile.am
@@ -0,0 +1,35 @@
+AM_CPPFLAGS = \
+	-I$(top_srcdir) \
+	-I$(top_srcdir)/libgda \
+	-I$(top_builddir) \
+	$(COREDEPS_CFLAGS) \
+	$(COREDEPS_WFLAGS) \
+	$(JSON_GLIB_CFLAGS) \
+	-DROOT_DIR=\""$(top_srcdir)"\"
+
+TESTS_ENVIRONMENT = GDA_TOP_SRC_DIR="$(abs_top_srcdir)" GDA_TOP_BUILD_DIR="$(abs_top_builddir)"
+TESTS = check_dataobject
+check_PROGRAMS = check_dataobject
+
+common_sources = common.c common.h
+
+BUILT_SOURCES = check_dataobject.vala.stamp
+CLEANFILES = check_dataobject.vala.stamp
+
+VALAFLAGS = \
+    --pkg gee-1.0 \
+    --pkg gobject-2.0 \
+    $(GDA_TOP_SRC_DIR)/libgda-5.0.vapi
+
+check_dataobject_VALASOURCES = \
+	CheckDataObject.vala
+	
+check_holder_SOURCES = \
+	check_dataobject.vala.stamp \
+	$(check_dataobject_VALASOURCES:.vala=.c)
+
+check_holder_LDADD = \
+	$(top_builddir)/libgda/libgda-5.0.la \
+	$(COREDEPS_LIBS)
+
+EXTRA_DIST = 



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