[f-spot] Modernize unit tests.



commit 143d3399bb2bd990a3504705dedbbd2ce33d12bb
Author: Ruben Vermeersch <ruben savanne be>
Date:   Thu Jun 3 20:15:54 2010 +0200

    Modernize unit tests.

 Makefile.am                                        |    6 +-
 build/build.environment.mk                         |    4 -
 configure.ac                                       |   37 +------
 src/BlockProcessor.cs                              |   34 ------
 src/Imaging/JpegHeader.cs                          |  124 --------------------
 src/Imaging/PnmFile.cs                             |    4 -
 src/Query/Makefile.am                              |    3 +-
 .../Query/Tests/LogicalTermTests.cs                |    2 +-
 src/Utils/Makefile.am                              |    3 +-
 .../Utils/Tests/SafeUriTests.cs                    |    6 +-
 tests/Makefile.am                                  |   32 +++++-
 tests/src/.gitignore                               |    5 -
 tests/src/Cms/Cms.cs                               |   59 ---------
 tests/src/Makefile.am                              |   18 ---
 14 files changed, 40 insertions(+), 297 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 1550316..6f09bac 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,9 +49,7 @@ run:
 	popd;
 
 
-if ENABLE_TESTS
 test:
-	@pushd tests/src/; \
-	make test; \
+	@pushd tests; \
+	make test \
 	popd;
-endif
diff --git a/build/build.environment.mk b/build/build.environment.mk
index 65d0df3..893b06e 100644
--- a/build/build.environment.mk
+++ b/build/build.environment.mk
@@ -131,10 +131,6 @@ REF_FSPOT = $(LINK_FSPOT_WIDGETS_DEPS) $(LINK_FSPOT_PLATFORM_DEPS) $(LINK_FSPOT_
 LINK_FSPOT = -r:$(DIR_BIN)/f-spot.exe
 LINK_FSPOT_DEPS = $(REF_FSPOT) $(LINK_FSPOT)
 
-# FSpot.Tests
-REF_FSPOT_TESTS = $(LINK_FSPOT_DEPS)
-
-
 # Extensions
 REF_FSPOT_EXTENSION_BLACKOUTEDITOR = $(LINK_FSPOT_DEPS)
 REF_FSPOT_EXTENSION_BWEDITOR = $(LINK_FSPOT_DEPS) $(LINK_MONO_SIMD)
diff --git a/configure.ac b/configure.ac
index 04583d9..78d2e79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,7 +80,7 @@ SHAMROCK_CHECK_MONO_2_0_GAC_ASSEMBLIES([
 FSPOT_CHECK_GTK_SHARP
 FSPOT_CHECK_GNOME_KEYRING_SHARP
 FSPOT_CHECK_FLICKRNET
-
+SHAMROCK_CHECK_NUNIT
 
 
 
@@ -206,40 +206,6 @@ dnl -- dbus-sharp
 PKG_CHECK_MODULES(NDESK_DBUS, ndesk-dbus-1.0 >= $NDESK_DBUS_REQUIRED ndesk-dbus-glib-1.0 >= $NDESK_DBUS_GLIB_REQUIRED)
 AC_SUBST(NDESK_DBUS_LIBS)
 
-AC_ARG_ENABLE(tests,
-	AC_HELP_STRING([--enable-tests],
-		[Enable NUnit tests]))
-
-AM_CONDITIONAL(ENABLE_TESTS, test "x$enable_tests" != "xno")
-
-if test "x$enable_tests" != "xno"; then
-	dnl -- nunit
-	PKG_CHECK_MODULES(NUNIT, nunit >= $NUNIT_REQUIRED,
-		do_tests="yes", do_tests="no")
-
-	AC_SUBST(NUNIT_LIBS)
-	AM_CONDITIONAL(ENABLE_TESTS, test "x$do_tests" = "xyes")
-
-	if test "x$do_tests" = "xno"; then
-		PKG_CHECK_MODULES(NUNIT, mono-nunit >= 2.0,
-			do_tests="yes", do_tests="no")
-
-		AC_SUBST(NUNIT_LIBS)
-		AM_CONDITIONAL(ENABLE_TESTS, test "x$do_tests" = "xyes")
-
-		if test "x$do_tests" = "xno"; then
-			NUNIT_DEFINES=''
-			AC_MSG_WARN([Could not find nunit: tests will not be available.])
-		else
-			NUNIT_DEFINES='-d:ENABLE_NUNIT'
-		fi
-		AC_SUBST(NUNIT_DEFINES)
-	fi
-else
-	do_tests="no"
-fi
-
-
 dnl --- GConf
 
 AC_PATH_PROG(GCONFTOOL, gconftool-2, no)
@@ -421,7 +387,6 @@ extensions/Tools/ScreensaverConfig/Makefile
 extensions/Transitions/Makefile
 extensions/Transitions/CoverTransition/Makefile
 tests/Makefile
-tests/src/Makefile
 )
 
 cat <<EOF
diff --git a/src/BlockProcessor.cs b/src/BlockProcessor.cs
index 8f60cf8..0371e4c 100644
--- a/src/BlockProcessor.cs
+++ b/src/BlockProcessor.cs
@@ -11,10 +11,6 @@
 using Gdk;
 using System;
 
-#if ENABLE_NUNIT
-using NUnit.Framework;
-#endif
-
 namespace FSpot {
 	public class BlockProcessor {
 		Rectangle rect;
@@ -40,34 +36,4 @@ namespace FSpot {
 		}
 
 	}
-
-#if ENABLE_NUNIT
-	[TestFixture]
-	public class BlockProcessorTests 
-	{
-		[Test]
-		public void Contained ()
-		{
-			BlockProcessor proc = new BlockProcessor (new Rectangle (0, 0, 10, 10), 1000);
-			Rectangle step;
-
-			Assert.IsTrue (proc.Step (out step));
-			Assert.AreEqual (step, new Rectangle (0, 0, 10, 10));
-			Assert.IsFalse (proc.Step (out step));
-		}
-
-		[Test]
-		public void Step ()
-		{
-			BlockProcessor proc = new BlockProcessor (new Rectangle (10, 100, 25, 15), 20);
-			Rectangle step;
-
-			Assert.AreEqual (proc.Step (out step), true);
-			Assert.AreEqual (step, new Rectangle (10, 100, 20, 15));
-			Assert.AreEqual (proc.Step (out step), true);
-			Assert.AreEqual (step, new Rectangle (30, 100, 5, 15));
-			Assert.AreEqual (proc.Step (out step), false);
-		}
-	}
-#endif
 }
diff --git a/src/Imaging/JpegHeader.cs b/src/Imaging/JpegHeader.cs
index 5db2a95..422603c 100644
--- a/src/Imaging/JpegHeader.cs
+++ b/src/Imaging/JpegHeader.cs
@@ -651,128 +651,4 @@ public class JpegHeader : SemWeb.StatementSource {
 			return image_data;
 		}
 	}
-
-#if ENABLE_NUNIT
-	[TestFixture]
-	public class Tests {
-		int quality =  75;
-
-		public string CreateFile ()
-		{
-			Gdk.Pixbuf test = new Gdk.Pixbuf (null, "f-spot-32.png");
-			string path = FSpot.ImageFile.TempPath ("joe.jpg");
-			string desc = "\x00a9 Novell Inc.";
-			PixbufOrientation orient = PixbufOrientation.TopRight;
-
-			PixbufUtils.SaveJpeg (test, path, quality, new Exif.ExifData ());
-			FSpot.JpegFile jimg = new FSpot.JpegFile (new SafeUri (path));
-			jimg.SetDescription (desc);
-			jimg.SetOrientation (orient);
-			jimg.SaveMetaData (path);
-			
-			return path;
-		}
-
-		[Test]
-		public void Load ()
-		{
-			string path = CreateFile ();
-
-			using (Stream stream = File.OpenRead (path)) {
-				JpegHeader jhead = new JpegHeader (stream);
-
-				Assert.AreEqual (((Marker)jhead.Markers [0]).Type, JpegMarker.Soi);
-				Assert.AreEqual (((Marker)jhead.Markers [1]).GetName (), "JFIF");
-				Assert.AreEqual (((Marker)jhead.Markers [1]).Type, JpegMarker.App0);
-				Assert.AreEqual (((Marker)jhead.Markers [2]).GetName (), "Exif");
-				Assert.AreEqual (((Marker)jhead.Markers [2]).Type, JpegMarker.App1);
-
-				// NOTE the currently we don't store the Eoi as the last marker
-				Assert.AreEqual (((Marker)jhead.Markers [jhead.Markers.Count -1]).Type, JpegMarker.Sos);
-
-				// NOTE this is kind of sill but it might help
-				Assert.IsTrue (Math.Abs (jhead.GuessQuality () - quality) <= 1);
-
-				Assert.IsNotNull (jhead.GetExifHeader ());
-			}
-
-			File.Delete (path);
-		}
-
-		[Test]
-		public void Save ()
-		{
-			string in_path = CreateFile ();
-			string out_path = ImageFile.TempPath ("output.jpg");
-			JpegHeader source;
-			JpegHeader dest;
-
-			using (Stream orig = File.OpenRead (in_path)) {
-				source = new JpegHeader (orig);
-				
-				using (Stream output = File.OpenWrite (out_path)) {
-					source.Save (output);
-				}
-
-				using (Stream result = File.OpenRead (out_path)) {
-					dest = new JpegHeader (result);
-					
-					Assert.AreEqual (source.Markers.Count, dest.Markers.Count);
-					Assert.AreEqual (source.GuessQuality (), dest.GuessQuality ());
-					Assert.AreEqual (orig.Length, result.Length);
-					for (int i = 0; i < source.Markers.Count; i++) {
-						Marker d = (Marker) dest.Markers [i];
-						Marker s = (Marker) source.Markers [i];
-
-						Assert.AreEqual (d.Type, s.Type);
-						Assert.AreEqual (d.GetName (), s.GetName ());
-
-						if (d.Data != null) {
-							Assert.AreEqual (d.Data.Length, s.Data.Length);
-						
-							for (int j = 0; j < d.Data.Length; j++) {
-								Assert.AreEqual (d.Data [j], s.Data [j]);
-							}
-						} else {
-							Assert.AreEqual (d.Data, s.Data);
-						}
-					}
-				}
-			}
-
-			File.Delete (in_path);
-			File.Delete (out_path);
-		}
-	}
-#endif
-
-#if false
-	public static int Main (string [] args)
-	{
-		JpegHeader data = new JpegHeader (args [0]);
-		byte [] value = data.GetRawXmp ();
-
-		if (value != null) {
-			string xml = System.Text.Encoding.UTF8.GetString (value, 29, value.Length - 29);
-			Log.Debug (xml);
-		}
-		
-		value = data.GetRaw ("ICC_PROFILE");
-		if (value != null) {
-			System.IO.FileStream stream = new System.IO.FileStream ("profile.icc", System.IO.FileMode.Create);
-			stream.Write (value, 12, value.Length - 12);
-			stream.Close ();
-		}
-
-		value = data.GetRawExif ();
-		
-		
-		//System.IO.Stream ostream = System.IO.File.Open ("/home/lewing/test.jpg", System.IO.FileMode.OpenOrCreate);
-		//data.Save (ostream);
-		//ostream.Position = 0;
-		//data = new JpegHeader (ostream);
-
-		return 0;
-	}
-#endif
 }
diff --git a/src/Imaging/PnmFile.cs b/src/Imaging/PnmFile.cs
index 0d3ae16..7b367c0 100644
--- a/src/Imaging/PnmFile.cs
+++ b/src/Imaging/PnmFile.cs
@@ -4,10 +4,6 @@ using System;
 using System.IO;
 using Hyena;
 
-#if ENABLE_NUNIT
-using NUnit.Framework;
-#endif
-
 namespace FSpot.Pnm {
 	public class PnmFile : ImageFile, StatementSource {
 
diff --git a/src/Query/Makefile.am b/src/Query/Makefile.am
index 7149ef4..d81fedb 100644
--- a/src/Query/Makefile.am
+++ b/src/Query/Makefile.am
@@ -12,7 +12,8 @@ SOURCES = \
 	RatingRange.cs \
 	RollSet.cs \
 	TagConditionWrapper.cs \
-	UntaggedCondition.cs
+	UntaggedCondition.cs \
+	Tests/LogicalTermTests.cs
 
 RESOURCES =
 
diff --git a/tests/src/Query/LogicalTerm.cs b/src/Query/Tests/LogicalTermTests.cs
similarity index 98%
rename from tests/src/Query/LogicalTerm.cs
rename to src/Query/Tests/LogicalTermTests.cs
index fd9898e..6911b24 100644
--- a/tests/src/Query/LogicalTerm.cs
+++ b/src/Query/Tests/LogicalTermTests.cs
@@ -1,4 +1,4 @@
-#if ENABLE_NUNIT
+#if ENABLE_TESTS
 using NUnit.Framework;
 
 namespace FSpot.Query.Tests
diff --git a/src/Utils/Makefile.am b/src/Utils/Makefile.am
index 4d07e43..ce7ba7c 100644
--- a/src/Utils/Makefile.am
+++ b/src/Utils/Makefile.am
@@ -18,7 +18,8 @@ SOURCES = \
 	Unix.cs \
 	UriExtensions.cs \
 	UriUtils.cs \
-	XdgThumbnailSpec.cs
+	XdgThumbnailSpec.cs \
+	Tests/SafeUriTests.cs
 
 RESOURCES =
 
diff --git a/tests/src/SafeUriTest.cs b/src/Utils/Tests/SafeUriTests.cs
similarity index 97%
rename from tests/src/SafeUriTest.cs
rename to src/Utils/Tests/SafeUriTests.cs
index 3abf656..08c80b9 100644
--- a/tests/src/SafeUriTest.cs
+++ b/src/Utils/Tests/SafeUriTests.cs
@@ -1,11 +1,12 @@
+#if ENABLE_TESTS
 using NUnit.Framework;
 using System;
 using Hyena;
 using FSpot;
 
-namespace FSpot.Tests
+namespace FSpot.Utils.Tests
 {
-	[TestFixture]
+    [TestFixture]
     public class SafeUriTests
     {
         static SafeUriTest[] tests = new SafeUriTest[] {
@@ -73,3 +74,4 @@ namespace FSpot.Tests
         public string FilenameWithoutExtension { get; set; }
     }
 }
+#endif
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 92ea75a..f3c4001 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,29 @@
-SUBDIRS = \
-	src
+include $(top_srcdir)/build/build.environment.mk
+
+if ENABLE_TESTS
+
+TEST_ASSEMBLIES = \
+	FSpot.Query.dll \
+	FSpot.Utils.dll
+
+ENV_OPTIONS = TZ=America/Chicago LC_ALL=it_IT LANG=it_IT
+NUNIT_CONSOLE = $$(echo $$(which nunit-console2 || which nunit-console))
+RUNNER = for asm in $${TEST_ASSEMBLIES}; do echo -e "\033[1mRunning tests on $${asm}...\033[0m"; $(ENV_OPTIONS) $(NUNIT_CONSOLE) -nologo -noshadow $$asm; done
+
+test:
+	@pushd $(DIR_BIN) &>/dev/null; \
+	export TEST_ASSEMBLIES="$(TEST_ASSEMBLIES)"; $(RUNNER); \
+	popd &>/dev/null;
+
+%:
+	@pushd $(DIR_BIN) &>/dev/null; \
+	for i in *.dll; do \
+		if [[ $$(echo "$$i" | tr "[:upper:]" "[:lower:]") = "$$(echo "$@" | tr "[:upper:]" "[:lower:]").dll" ]]; then \
+			export TEST_ASSEMBLIES="$$i"; $(RUNNER); \
+		fi; \
+	done;
+
+endif
+
+MAINTAINERCLEANFILES = Makefile.in
 
-MAINTAINERCLEANFILES = \
-	Makefile.in



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