[gxml] * make tests use data files from test/ directory as defined by -D



commit 04baf4014f265ba2e8854f30e8b7c708f998a821
Author: Richard Schwarting <aquarichy gmail com>
Date:   Wed Aug 22 20:05:52 2012 -0400

    * make tests use data files from test/ directory as defined by -D

 test/DocumentTest.vala      |   12 +++---
 test/GXmlTest.vala          |   12 +++++-
 test/SerializationTest.vala |   83 ++++++++++++++++++++++---------------------
 3 files changed, 58 insertions(+), 49 deletions(-)
---
diff --git a/test/DocumentTest.vala b/test/DocumentTest.vala
index bbb0956..8c1cc94 100644
--- a/test/DocumentTest.vala
+++ b/test/DocumentTest.vala
@@ -56,7 +56,7 @@ class DocumentTest : GXmlTest {
 			});
 		Test.add_func ("/gxml/document/construct_from_stream", () => {
 				try {
-					File fin = File.new_for_path ("test.xml");
+					File fin = File.new_for_path (GXmlTest.get_test_dir () + "/test.xml");
 					InputStream instream = fin.read (null);
 					// TODO use cancellable
 
@@ -87,9 +87,9 @@ class DocumentTest : GXmlTest {
 				try {
 					Document doc = get_doc ();
 					int exit_status;
-					doc.save_to_path ("test_out_path.xml");
+					doc.save_to_path (GLib.Environment.get_tmp_dir () + "/test_out_path.xml"); // TODO: /tmp because of 'make distcheck' being readonly, want to use GXmlTest.get_test_dir () if readable, though
 
-					Process.spawn_sync (null,  { "/usr/bin/diff", "test_out_path.xml", "test_out_path_expected.xml" }, null, 0, null, null /* stdout */, null /* stderr */, out exit_status);
+					Process.spawn_sync (null,  { "/usr/bin/diff", GLib.Environment.get_tmp_dir () + "/test_out_path.xml", GXmlTest.get_test_dir () + "/test_out_path_expected.xml" }, null, 0, null, null /* stdout */, null /* stderr */, out exit_status);
 					assert (exit_status == 0);
 				} catch (GLib.Error e) {
 					GLib.warning ("%s", e.message);
@@ -98,10 +98,10 @@ class DocumentTest : GXmlTest {
 			});
 		Test.add_func ("/gxml/document/save_to_stream", () => {
 				try {
-					File fin = File.new_for_path ("test.xml");
+					File fin = File.new_for_path (GXmlTest.get_test_dir () + "/test.xml");
 					InputStream instream = fin.read (null);
 
-					File fout = File.new_for_path ("test_out_stream.xml");
+					File fout = File.new_for_path (GLib.Environment.get_tmp_dir () + "/test_out_stream.xml");
 					// OutputStream outstream = fout.create (FileCreateFlags.REPLACE_DESTINATION, null); // REPLACE_DESTINATION doesn't work like I thought it would?
 					OutputStream outstream = fout.replace (null, true, FileCreateFlags.REPLACE_DESTINATION, null);
 
@@ -110,7 +110,7 @@ class DocumentTest : GXmlTest {
 
 					doc.save_to_stream (outstream);
 
-					Process.spawn_sync (null,  { "/usr/bin/diff", "test_out_stream.xml", "test_out_stream_expected.xml" }, null, 0, null, null /* stdout */, null /* stderr */, out exit_status);
+					Process.spawn_sync (null,  { "/usr/bin/diff", GLib.Environment.get_tmp_dir () + "/test_out_stream.xml", GXmlTest.get_test_dir () + "/test_out_stream_expected.xml" }, null, 0, null, null /* stdout */, null /* stderr */, out exit_status);
 					assert (exit_status == 0);
 				} catch (GLib.Error e) {
 					GLib.warning ("%s", e.message);
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index 3f0daed..f52ce67 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -20,18 +20,26 @@ class GXmlTest {
 
 		Test.run ();
 
-		return 1;
+		return 0;
 	}
 
 	internal static Document get_doc () throws DomError {
 		Document doc = null;
 		try {
-			doc = new Document.from_path ("test.xml");
+			doc = new Document.from_path (get_test_dir () + "/test.xml");
 		} catch (DomError e) {
 		}
 		return doc;
 	}
 
+	internal static string get_test_dir () {
+		if (TEST_DIR == null || TEST_DIR == "") {
+			return ".";
+		} else {
+			return TEST_DIR;
+		}
+	}
+
 	// internal static Attr get_attr_new_doc (string name, string value) throws DomError {
 	// 	return get_attr (name, value, get_doc ());
 	// }
diff --git a/test/SerializationTest.vala b/test/SerializationTest.vala
index 77ef4bc..d5ac5d9 100644
--- a/test/SerializationTest.vala
+++ b/test/SerializationTest.vala
@@ -387,47 +387,6 @@ class SerializationTest : GXmlTest {
 				SimpleProperties obj = new SimpleProperties (3, 4.2, "catfish", true, 0); // set private arg just to 0
 				test_serialization_deserialization (obj, "simple_properties", (GLib.EqualFunc)SimpleProperties.equals, (StringifyFunc)SimpleProperties.to_string);
 			});
-		Test.add_func ("/gxml/serialization/collection_properties", () => {
-				// TODO: want a test with more complex data than strings
-
-				CollectionProperties obj;
-				GLib.List<string> list;
-				GLib.HashTable<string,string> table;
-
-				list = new GLib.List<string> ();
-				list.append ("a");
-				list.append ("b");
-				list.append ("c");
-
-				table = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
-				table.set ("aa", "AA");
-				table.set ("bb", "BB");
-				table.set ("cc", "CC");
-
-				obj = new CollectionProperties (list, table);
-
-				test_serialization_deserialization (obj, "collection_properties", (GLib.EqualFunc)CollectionProperties.equals, (StringifyFunc)CollectionProperties.to_string);
-			});
-		Test.add_func ("/gxml/serialization/gee_collection_properties", () => {
-				GeeCollectionProperties obj;
-
-				Gee.List<string> list = new Gee.ArrayList<string> ();
-				Gee.HashSet<string> hashset = new Gee.HashSet<string> ();
-				Gee.Set<string> tset = new Gee.TreeSet<string> ();
-				Gee.HashMap<string,string> map = new Gee.HashMap<string,string> ();
-				Gee.Collection<string> col = new Gee.LinkedList<string> ();
-
-				foreach (string str in new string[] { "a", "b", "c" }) {
-					list.add (str);
-					hashset.add (str);
-					tset.add (str);
-					map.set (str + str, str + str + str);
-					col.add (str);
-				}
-
-				obj = new GeeCollectionProperties (list, hashset, tset, map, col);
-				test_serialization_deserialization (obj, "gee_collection_properties", (GLib.EqualFunc)GeeCollectionProperties.equals, (StringifyFunc)GeeCollectionProperties.to_string);
-			});
 		Test.add_func ("/gxml/serialization/complex_simple_properties", () => {
 				SimpleProperties simple_properties;
 				ComplexSimpleProperties obj;
@@ -486,6 +445,48 @@ class SerializationTest : GXmlTest {
 				      "GXmlSerializable and overriding its view of its properties " +
 				      "for GXmlSerialization.");
 
+			Test.add_func ("/gxml/serialization/collection_properties", () => {
+					// TODO: want a test with more complex data than strings
+
+					CollectionProperties obj;
+					GLib.List<string> list;
+					GLib.HashTable<string,string> table;
+
+					list = new GLib.List<string> ();
+					list.append ("a");
+					list.append ("b");
+					list.append ("c");
+
+					table = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
+					table.set ("aa", "AA");
+					table.set ("bb", "BB");
+					table.set ("cc", "CC");
+
+					obj = new CollectionProperties (list, table);
+
+					test_serialization_deserialization (obj, "collection_properties", (GLib.EqualFunc)CollectionProperties.equals, (StringifyFunc)CollectionProperties.to_string);
+				});
+			Test.add_func ("/gxml/serialization/gee_collection_properties", () => {
+					GeeCollectionProperties obj;
+
+					Gee.List<string> list = new Gee.ArrayList<string> ();
+					Gee.HashSet<string> hashset = new Gee.HashSet<string> ();
+					Gee.Set<string> tset = new Gee.TreeSet<string> ();
+					Gee.HashMap<string,string> map = new Gee.HashMap<string,string> ();
+					Gee.Collection<string> col = new Gee.LinkedList<string> ();
+
+					foreach (string str in new string[] { "a", "b", "c" }) {
+						list.add (str);
+						hashset.add (str);
+						tset.add (str);
+						map.set (str + str, str + str + str);
+						col.add (str);
+					}
+
+					obj = new GeeCollectionProperties (list, hashset, tset, map, col);
+					test_serialization_deserialization (obj, "gee_collection_properties", (GLib.EqualFunc)GeeCollectionProperties.equals, (StringifyFunc)GeeCollectionProperties.to_string);
+				});
+
 			Test.add_func ("/gxml/serialization/xml_automatically_serialize_fields", () => {
 					/* NOTE: We expect this one to fail right now */
 



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