[libgda] GdaData.Table pass Unit Test for tables depends and table referenced by



commit ce105d0960010b76c5d7b93548b83f18900005cc
Author: Daniel Espinosa <despinosa src gnome org>
Date:   Tue Feb 21 00:21:36 2012 -0600

    GdaData.Table pass Unit Test for tables depends and table referenced by

 libgda/data/Table.vala     |   10 ++-----
 tests/vala/CheckTable.vala |   54 +++++++++++++++++++++++++++++++-------------
 2 files changed, 41 insertions(+), 23 deletions(-)
---
diff --git a/libgda/data/Table.vala b/libgda/data/Table.vala
index aca2f74..1cf3852 100644
--- a/libgda/data/Table.vala
+++ b/libgda/data/Table.vala
@@ -120,7 +120,6 @@ namespace GdaData
 				_fields.set (fi.name, fi);
 			}
 			// Constraints
-			stdout.printf ("Cheking FiledInfo Constraints ...\n");
 			ctx.set_table ("_table_constraints");
 			connection.update_meta_store (ctx);
 			ctx.set_table ("_key_column_usage");
@@ -128,7 +127,6 @@ namespace GdaData
 			var mc = store.extract ("SELECT * FROM _table_constraints"+
 			                        " WHERE table_name  = ##name::string" + cond,
 									vals);
-			stdout.printf ("table REF_CONST: \n"+mc.dump_as_string ());
 			for (r = 0; r < mc.get_n_rows (); r++) 
 			{
 				string ct = (string) mc.get_value_at (mc.get_column_index ("constraint_type"), r);
@@ -140,7 +138,6 @@ namespace GdaData
 				var colname = (string) mpk.get_value_at (mpk.get_column_index ("column_name"), 0);
 				var f = _fields.get (colname);
 				f.attributes = f.attributes | DbFieldInfo.attribute_from_string (ct);
-				stdout.printf("Conts type: " + ct + " : Getted Field: " + f.name + ": Attrib= " + ((int)f.attributes).to_string () + "\n");
 				
 				if (DbFieldInfo.Attribute.FOREIGN_KEY in f.attributes) 
 				{
@@ -149,7 +146,6 @@ namespace GdaData
 					var mfk = store.extract ("SELECT * FROM _referential_constraints"+
 					                         " WHERE table_name  = ##name::string "+
 					                         "AND constraint_name = ##constraint_name::string" + cond, vals);
-					stdout.printf ("REF_CONST: \n"+mfk.dump_as_string ());
 					f.fkey = new DbFieldInfo.ForeignKey ();
 					f.fkey.name = cn;
 					f.fkey.refname = (string) mfk.get_value_at (mfk.get_column_index ("ref_constraint_name"), 0);
@@ -185,9 +181,9 @@ namespace GdaData
 			}
 			// Table referencing this
 			var mtr = store.extract ("SELECT * FROM "+
-			                     	 "_detailed_fk WHERE fk_table_name  = ##name::string"+
-			                         " AND fk_table_catalog = ##catalog::string"+
-			                         " AND fk_table_schema = ##schema::string", vals);
+			                     	 "_detailed_fk WHERE ref_table_name  = ##name::string"+
+			                         " AND ref_table_catalog = ##catalog::string"+
+			                         " AND ref_table_schema = ##schema::string", vals);
 			for (r = 0; r < mtr.get_n_rows (); r++) {
 				var tn = (string) mtr.get_value_at (mtr.get_column_index ("fk_table_name"), r);
 				var tr = new Table ();
diff --git a/tests/vala/CheckTable.vala b/tests/vala/CheckTable.vala
index 0a321fb..73ef32c 100644
--- a/tests/vala/CheckTable.vala
+++ b/tests/vala/CheckTable.vala
@@ -32,22 +32,25 @@ namespace Check {
 				GLib.FileUtils.unlink("table.db");
 				stdout.printf("Creating Database...\n");
 				this.connection = Connection.open_from_string("SQLite", "DB_DIR=.;DB_NAME=table", 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 DEFAULT \"New Yield\","+
-				                                           " company integer REFERENCES company (id) ON DELETE SET NULL ON UPDATE CASCADE)");
-				this.connection.execute_non_select_command("INSERT INTO user (id, name, city, company) VALUES (1, \"Daniel\", \"Mexico\", 1)");
-				this.connection.execute_non_select_command("INSERT INTO user (id, name, city) VALUES (2, \"Jhon\", \"USA\", 2)");
-				
 				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\")");
+				
+				stdout.printf("Creating table 'customer'...\n");
+				this.connection.execute_non_select_command("CREATE TABLE customer (id integer PRIMARY KEY AUTOINCREMENT, name string UNIQUE,"+
+				                                           " city string DEFAULT \"New Yield\","+
+				                                           " company integer REFERENCES company (id) ON DELETE SET NULL ON UPDATE CASCADE)");
+				this.connection.execute_non_select_command("INSERT INTO customer (id, name, city, company) VALUES (1, \"Daniel\", \"Mexico\", 1)");
+				this.connection.execute_non_select_command("INSERT INTO customer (id, name, city) VALUES (2, \"Jhon\", \"USA\")");
+				this.connection.execute_non_select_command("INSERT INTO customer (id, name) VALUES (3, \"Jack\")");
+				stdout.printf("Creating table 'salary'...\n");
 				this.connection.execute_non_select_command("CREATE TABLE salary (id integer PRIMARY KEY AUTOINCREMENT,"+
-				                                           " user integer REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,"+
+				                                           " customer integer REFERENCES customer (id) ON DELETE CASCADE ON UPDATE CASCADE,"+
 				                                           " income float DEFAULT 10.0)");
-				this.connection.execute_non_select_command("INSERT INTO salary (id, user, income) VALUES (1,1,55.0)");
-				this.connection.execute_non_select_command("INSERT INTO salary (id, user, income) VALUES (2,2,65.0)");
+				this.connection.execute_non_select_command("INSERT INTO salary (id, customer, income) VALUES (1,1,55.0)");
+				this.connection.execute_non_select_command("INSERT INTO salary (id, customer, income) VALUES (2,2,65.0)");
+				this.connection.execute_non_select_command("INSERT INTO salary (customer) VALUES (3)");
 			}
 			catch (Error e) {
 				stdout.printf ("Couln't create temporary database...\nERROR: %s\n", e.message);
@@ -62,22 +65,26 @@ namespace Check {
 			stdout.printf("Setting connection\n");
 			table.connection = this.connection;
 			stdout.printf("Setting name\n");
-			table.name = "user";
+			table.name = "customer";
 		}
 		public int update ()
 			throws Error
 		{
-			stdout.printf(">>> NEW TEST: GdaData.DbTable -- Update\n");
+			stdout.printf("\n\n\n>>>>>>>>>>>>>>> NEW TEST: GdaData.DbTable -- Update\n");
 			int fails = 0;
-			stdout.printf(">>> Updating meta information\n");
+			stdout.printf(">>>>>> Updating meta information\n");
 			table.update ();
+			if (fails > 0)
+				stdout.printf (">>>>>>>> FAIL <<<<<<<<<<<\n");
+			else
+				stdout.printf (">>>>>>>> TEST PASS <<<<<<<<<<<\n");
 			return fails;
 		}
 		
 		public int fields ()
 			throws Error
 		{
-			stdout.printf(">>> NEW TEST: Gda.DbTable - Fields...\n");
+			stdout.printf("\n\n\n>>>>>>>>>>>>>>> NEW TEST: Gda.DbTable - Fields...\n");
 			int fails = 0;
 			var f = new Gee.HashMap<string,int> ();
 			f.set ("id", 0);
@@ -89,6 +96,7 @@ namespace Check {
 				if (! f.keys.contains (fi.name))
 				{
 					fails++;
+					stdout.printf (">>>>>>>> Check Fields names:  FAIL\n");
 					break;
 				}
 			}
@@ -99,6 +107,7 @@ namespace Check {
 			{
 				if (! f2.keys.contains (fi2.name))
 				{
+					stdout.printf (">>>>>>>> Check Primary Keys Fields:  FAIL\n");
 					fails++;
 					break;
 				}
@@ -110,6 +119,7 @@ namespace Check {
 			{
 				if (! f3.keys.contains (t.name))
 				{
+					stdout.printf (">>>>>>>> Check Table Depends:  FAIL\n");
 					fails++;
 					break;
 				}
@@ -121,6 +131,7 @@ namespace Check {
 			{
 				if (! f4.keys.contains (t2.name))
 				{
+					stdout.printf (">>>>>>>> Check Table Referenced by:  FAIL\n");
 					fails++;
 					break;
 				}
@@ -132,17 +143,28 @@ namespace Check {
 				if (DbFieldInfo.Attribute.HAVE_DEFAULT in fi3.attributes
 						&& fi3.name == "city") {
 					found++;
+					if (GLib.strcmp ((string)fi3.default_value,"\"New Yield\"") != 0) {
+						fails++;
+						stdout.printf (">>>>>>>> Default Value No Match. Holded \'"+
+						               (string) fi3.default_value + "\' But Expected \"New Yield\" : FAIL\n");
+					}
+					break;
 				}
 			}
+			
 			if (found == 0) {
-				stdout.printf ("Check Default Values: FAIL\n");
+				stdout.printf (">>>>>>>> Check Default Values: FAIL\n");
 				fails++;
 			}
+			if (fails > 0)
+				stdout.printf (">>>>>>>> FAIL <<<<<<<<<<<\n");
+			else
+				stdout.printf (">>>>>>>> TEST PASS <<<<<<<<<<<\n");
 			return fails;
 		}
 		
 		public static int main (string[] args) {
-			stdout.printf ("Checking GdaData.DbRecord implementation...\n");
+			stdout.printf ("\n\n\n>>>>>>>>>>>>>>>> NEW TEST: Checking GdaData.DbRecord implementation... <<<<<<<<<< \n");
 			int failures = 0;
 			var app = new Tests ();
 			try {



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