[cogl/wip/cogl-sharp: 15/42] cogl-sharp: Add a unit tests infrastructure



commit d142395fe8a3258a0d1687e19230d7efb55f0be8
Author: Damien Lespiau <damien lespiau intel com>
Date:   Sat Sep 29 22:29:23 2012 +0100

    cogl-sharp: Add a unit tests infrastructure
    
    And test Color.

 .gitignore                    |    1 +
 cogl-sharp/CoglTests.rsp      |    2 +
 cogl-sharp/Color.cs           |    2 +-
 cogl-sharp/Makefile.am        |   19 +++++++++++++-
 cogl-sharp/launch-tests       |    2 +
 cogl-sharp/tests/TestColor.cs |   56 +++++++++++++++++++++++++++++++++++++++++
 configure.ac                  |    7 ++++-
 7 files changed, 86 insertions(+), 3 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index e0c8a27..8072e51 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,6 +32,7 @@ stamp-marshal
 *.typelib
 /cogl-pango/cogl-pango.rc
 /cogl-sharp/AssemblyInfo.cs
+/cogl-sharp/TestResult.xml
 /cogl/cogl.rc
 /cogl/cogl-defines.h
 /cogl/cogl-defines.h.win32
diff --git a/cogl-sharp/CoglTests.rsp b/cogl-sharp/CoglTests.rsp
new file mode 100644
index 0000000..f9a6814
--- /dev/null
+++ b/cogl-sharp/CoglTests.rsp
@@ -0,0 +1,2 @@
+/target:library
+/out:CoglTests.dll
diff --git a/cogl-sharp/Color.cs b/cogl-sharp/Color.cs
index 3b98517..54336db 100644
--- a/cogl-sharp/Color.cs
+++ b/cogl-sharp/Color.cs
@@ -55,7 +55,7 @@ namespace Cogl
         [DllImport("cogl2.dll")]
         private static extern void cogl_color_premultiply(ref Color color);
 
-        public void Premuliply()
+        public void Premultiply()
         {
             cogl_color_premultiply(ref this);
         }
diff --git a/cogl-sharp/Makefile.am b/cogl-sharp/Makefile.am
index a4066d7..3cb9380 100644
--- a/cogl-sharp/Makefile.am
+++ b/cogl-sharp/Makefile.am
@@ -1,4 +1,3 @@
-
 assemblydir = $(libdir)/cogl
 assembly_DATA = cogl2-sharp.dll cogl2-sharp.dll.config cogl2-sharp.dll.mdb
 
@@ -29,3 +28,21 @@ CLEANFILES =			\
 DISTCLEANFILES =		\
 	AssemblyInfo.cs		\
 	$(NULL)
+
+if BUILD_NUNIT_TESTS
+noinst_DATA = CoglTests.dll
+
+TESTS = launch-tests
+
+launch-tests: CoglTests.dll
+
+tests_sources =			\
+	tests/TestColor.cs	\
+	$(NULL)
+
+CoglTests.dll: $(tests_sources)
+	$(MCS) $(CSFLAGS) @$(srcdir)/CoglTests.rsp -lib:$(top_builddir)/cogl-sharp -r:cogl2-sharp.dll $(MONO_NUNIT_LIBS) $(tests_sources)
+
+EXTRA_DIST += $(tests_sources)
+CLEANFILES += CoglTests.dll
+endif
diff --git a/cogl-sharp/launch-tests b/cogl-sharp/launch-tests
new file mode 100755
index 0000000..92bddbb
--- /dev/null
+++ b/cogl-sharp/launch-tests
@@ -0,0 +1,2 @@
+#!/bin/sh
+nunit-console CoglTests.dll
diff --git a/cogl-sharp/tests/TestColor.cs b/cogl-sharp/tests/TestColor.cs
new file mode 100644
index 0000000..89fde99
--- /dev/null
+++ b/cogl-sharp/tests/TestColor.cs
@@ -0,0 +1,56 @@
+using Cogl;
+using NUnit.Framework;
+
+namespace Cogl.Test
+{
+    [TestFixture]
+    public class TestColor : AssertionHelper
+    {
+
+        [SetUp]
+        public void Init()
+        {
+            GlobalSettings.DefaultFloatingPointTolerance = 1e-6;
+        }
+
+        [Test]
+        public void FloatConstructor()
+        {
+            Color color = new Color(0.1f, 0.2f, 0.3f, 0.4f);
+
+            Expect(color.red, EqualTo(0.1f));
+            Expect(color.green, EqualTo(0.2f));
+            Expect(color.blue, EqualTo(0.3f));
+            Expect(color.alpha, EqualTo(0.4f));
+        }
+
+        [Test]
+        public void ByteConstructor()
+        {
+            Color color = new Color(10, 20, 30, 40);
+
+            Expect(color.red, EqualTo(10.0f / 255.0f));
+            Expect(color.green, EqualTo(20.0f / 255.0f));
+            Expect(color.blue, EqualTo(30.0f / 255.0f));
+            Expect(color.alpha, EqualTo(40.0f / 255.0f));
+        }
+
+        [Test]
+        public void Premultiply()
+        {
+            Color color = new Color(1.0f, 1.0f, 1.0f, 0.5f);
+
+            color.Premultiply();
+            Expect(color.red, EqualTo(0.5f));
+            Expect(color.green, EqualTo(0.5f));
+            Expect(color.blue, EqualTo(0.5f));
+            Expect(color.alpha, EqualTo(0.5f));
+
+            color.UnPremultiply();
+            Expect(color.red, EqualTo(1.0f));
+            Expect(color.green, EqualTo(1.0f));
+            Expect(color.blue, EqualTo(1.0f));
+            Expect(color.alpha, EqualTo(0.5f));
+        }
+    }
+}
diff --git a/configure.ac b/configure.ac
index 60dd0f6..ece3ae2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1207,6 +1207,11 @@ AS_IF([test "x$enable_cogl_sharp" = "xyes" -a "x$have_mcs" != "xyes"],
 AM_CONDITIONAL(BUILD_COGL_SHARP, [test "$enable_cogl_sharp" = "yes"])
 AC_SUBST(MCS)
 
+PKG_CHECK_MODULES(MONO_NUNIT, [mono-nunit], [have_nunit=yes], [have_nunit=no])
+AS_IF([test "$enable_cogl_sharp" = "yes" -a "$have_nunit" = "yes"],
+      [enable_nunit=yes], [enable_nunit=no])
+AM_CONDITIONAL(BUILD_NUNIT_TESTS, [test "$enable_nunit" = "yes"])
+
 dnl ================================================================
 dnl What needs to be substituted in other files
 dnl ================================================================
@@ -1339,7 +1344,7 @@ echo " â Extra:"
 echo "        Build API reference: ${enable_gtk_doc}"
 echo "        Build introspection data: ${enable_introspection}"
 echo "        Enable internationalization: ${USE_NLS}"
-echo "        Build C# binding: ${enable_cogl_sharp}"
+echo "        Build C# binding: ${enable_cogl_sharp} (unit tests: ${enable_nunit})"
 
 echo ""
 



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