[longomatch] Port more unit tests



commit d0e7d634b12b45fccd093f0d7daf1548305cdbdd
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Feb 27 15:34:26 2015 +0100

    Port more unit tests

 Tests/Core/TestColor.cs         |   63 ++++++++++++++++++++++++-
 Tests/Core/TestImage.cs         |  101 ++++++++++++++++++++++++++++++++++++++-
 Tests/Core/TestTime.cs          |    2 +-
 Tests/Core/TestTimeNode.cs      |    2 +-
 Tests/Core/TestTimelineEvent.cs |    4 +-
 Tests/Makefile.am               |    6 ++-
 Tests/Tests.csproj              |    7 +++
 7 files changed, 177 insertions(+), 8 deletions(-)
---
diff --git a/Tests/Core/TestColor.cs b/Tests/Core/TestColor.cs
index 5ab2c04..f5a65ca 100644
--- a/Tests/Core/TestColor.cs
+++ b/Tests/Core/TestColor.cs
@@ -16,8 +16,8 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
-using NUnit.Framework;
 using LongoMatch.Core.Common;
+using NUnit.Framework;
 
 namespace Tests.Core
 {
@@ -32,6 +32,67 @@ namespace Tests.Core
                        Utils.CheckSerialization (c);
                        Color c1 = Utils.SerializeDeserialize (c);
                        Assert.AreEqual (c, c1);
+                       
+                       YCbCrColor yc = new YCbCrColor (2, 3, 4);
+                       Utils.CheckSerialization (yc);
+               }
+               
+               [Test()]
+               public void TestParse ()
+               {
+                       Color c;
+                       
+                       Assert.IsNull (Color.Parse ("232424"));
+                       Assert.IsNull (Color.Parse ("#abc"));
+                       Assert.IsNull (Color.Parse ("#2324"));
+                       Assert.IsNull (Color.Parse ("#2324242434"));
+                       Assert.IsNull (Color.Parse ("#1020AZ"));
+                       
+                       c = Color.Parse ("#af1023");
+                       Assert.AreEqual (c.R, 175);
+                       Assert.AreEqual (c.G, 16);
+                       Assert.AreEqual (c.B, 35);
+                       Assert.AreEqual (c.A, Byte.MaxValue);
+                       
+                       c = Color.Parse ("#af1023aa");
+                       Assert.AreEqual (c.R, 175);
+                       Assert.AreEqual (c.G, 16);
+                       Assert.AreEqual (c.B, 35);
+                       Assert.AreEqual (c.A, 170);
+               }
+               
+               [Test()]
+               public void TestCopy ()
+               {
+                       Color c1 = new Color (100, 200, 240);
+                       Color c2 = c1.Copy ();
+                       Assert.IsFalse (Object.ReferenceEquals (c1, c2));
+                       Assert.AreEqual (c1, c2);
+               }
+
+               [Test()]
+               public void TestEquals ()
+               {
+                       Color c1 = new Color (100, 200, 240);
+                       Color c2 = new Color (100, 200, 240);
+                       Assert.AreEqual (c1, c2);
+               }
+               
+               [Test()]
+               public void TestYCbCr ()
+               {
+                       Color c1 = new Color (100, 100, 100);
+                       YCbCrColor yc = YCbCrColor.YCbCrFromColor (c1);
+                       Assert.AreEqual (yc.Y, 101);
+                       Assert.AreEqual (yc.Cb, 128);
+                       Assert.AreEqual (yc.Cr, 125);
+                       Color c2 = yc.RGBColor ();
+                       /* Conversions is not 1-1 */
+                       Assert.AreNotEqual (c1, c2);
+                       Assert.AreEqual (c2.R, 94);
+                       Assert.AreEqual (c2.G, 101);
+                       Assert.AreEqual (c2.B, 98);
+                       
                }
        }
 }
diff --git a/Tests/Core/TestImage.cs b/Tests/Core/TestImage.cs
index 0fdcac9..1e50f07 100644
--- a/Tests/Core/TestImage.cs
+++ b/Tests/Core/TestImage.cs
@@ -15,17 +15,116 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
-using NUnit.Framework;
 using System;
+using System.IO;
+using LongoMatch.Core.Common;
+using NUnit.Framework;
 
 namespace Tests.Core
 {
        [TestFixture()]
        public class TestImage
        {
+               Image img;
+               
+               Image LoadFromFile (bool scaled = false)
+               {
+                       Image img = null;
+                       string tmpFile = Path.GetTempFileName ();
+
+                       using (Stream resource = GetType().Assembly.GetManifestResourceStream("dibujo.svg")) {
+                               using (Stream output = File.OpenWrite(tmpFile)) {
+                                       resource.CopyTo (output);
+                               }
+                       }
+                       try {
+                               if (!scaled) {
+                                       img = Image.LoadFromFile (tmpFile);
+                               } else {
+                                       img = Image.LoadFromFile (tmpFile, 20, 20);
+                               }
+                       } catch (Exception ex) {
+                               Assert.Fail (ex.Message);
+                       } finally {
+                               File.Delete (tmpFile);
+                       }
+                       return img;
+               }
+
+               [SetUp()]
+               public void LoadFromFile ()
+               {
+                       img = LoadFromFile (false);
+               }
+
                [Test()]
                public void TestSerialization ()
                {
+                       string dir = Environment.CurrentDirectory;
+                       Utils.CheckSerialization (img);
+               }
+               
+               [Test()]
+               public void TestLoadFromFile ()
+               {
+                       Assert.AreEqual (img.Width, 16);
+                       Assert.AreEqual (img.Height, 16);
+                       img = LoadFromFile (true);
+                       Assert.AreEqual (img.Width, 20);
+                       Assert.AreEqual (img.Height, 20);
+               }
+               
+               [Test()]
+               public void TestSerialize ()
+               {
+                       byte[] buf = img.Serialize ();
+                       Assert.AreEqual (buf.Length, 102);
+                       img = Image.Deserialize (buf);
+                       Assert.AreEqual (img.Width, 16);
+                       Assert.AreEqual (img.Height, 16);
+               }
+               
+               [Test()]
+               public void TestScale ()
+               {
+                       Image img2 = img.Scale (20, 20);
+                       Assert.AreNotSame (img, img2); 
+                       Assert.AreEqual (img2.Width, 20);
+                       Assert.AreEqual (img2.Height, 20);
+                       
+                       img = img.Scale (20, 30);
+                       Assert.AreEqual (img.Width, 20);
+                       Assert.AreEqual (img.Height, 20);
+                       img = img.Scale (25, 20);
+                       Assert.AreEqual (img.Width, 20);
+                       Assert.AreEqual (img.Height, 20);
+                       
+                       img.ScaleInplace ();
+                       Assert.AreEqual (img.Width, Constants.MAX_THUMBNAIL_SIZE);
+                       Assert.AreEqual (img.Height, Constants.MAX_THUMBNAIL_SIZE);
+               }
+               
+               [Test()]
+               public void TestSave ()
+               {
+                       string tmpFile = Path.GetTempFileName ();
+                       try {
+                               img.Save (tmpFile);
+                               Image img2 = Image.LoadFromFile (tmpFile);
+                               Assert.AreEqual (img2.Width, 16);
+                               Assert.AreEqual (img2.Height, 16);
+                       } finally {
+                               File.Delete (tmpFile);
+                       }
+               }
+               
+               [Test()]
+               public void TestComposite ()
+               {
+                       Image img2 = LoadFromFile (true);
+                       Image img3 = Image.Composite (img2, img);
+                       Assert.AreEqual (img3.Width, 20);
+                       Assert.AreEqual (img3.Height, 20);
                        
                }
        }
diff --git a/Tests/Core/TestTime.cs b/Tests/Core/TestTime.cs
index 08ea689..633ea32 100644
--- a/Tests/Core/TestTime.cs
+++ b/Tests/Core/TestTime.cs
@@ -15,9 +15,9 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
-using NUnit.Framework;
 using System;
 using LongoMatch.Core.Store;
+using NUnit.Framework;
 
 namespace Tests.Core
 {
diff --git a/Tests/Core/TestTimeNode.cs b/Tests/Core/TestTimeNode.cs
index bff8254..db76c82 100644
--- a/Tests/Core/TestTimeNode.cs
+++ b/Tests/Core/TestTimeNode.cs
@@ -16,8 +16,8 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
-using NUnit.Framework;
 using LongoMatch.Core.Store;
+using NUnit.Framework;
 
 namespace Tests.Core
 {
diff --git a/Tests/Core/TestTimelineEvent.cs b/Tests/Core/TestTimelineEvent.cs
index d8030cb..2a2367b 100644
--- a/Tests/Core/TestTimelineEvent.cs
+++ b/Tests/Core/TestTimelineEvent.cs
@@ -16,10 +16,10 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
-using NUnit.Framework;
+using System.Collections.Generic;
 using LongoMatch.Core.Common;
 using LongoMatch.Core.Store;
-using System.Collections.Generic;
+using NUnit.Framework;
 
 namespace Tests.Core
 {
diff --git a/Tests/Makefile.am b/Tests/Makefile.am
index 51dc108..69b4014 100644
--- a/Tests/Makefile.am
+++ b/Tests/Makefile.am
@@ -3,12 +3,14 @@ TARGET = library
 
 LINK = $(REF_DEP_TESTS)
 
-SOURCES = Core/TestTime.cs \
+SOURCES = Core/TestColor.cs \
+       Core/TestImage.cs \
+       Core/TestTime.cs \
        Core/TestTimeNode.cs \
        Core/TestTimelineEvent.cs \
        Utils.cs
 
-RESOURCES = 
+RESOURCES = Core/dibujo.svg
 
 include $(top_srcdir)/build/build.mk
 
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index d73fa3d..10fd6ba 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -44,6 +44,8 @@
     <Compile Include="Core\TestTimelineEvent.cs" />
     <Compile Include="Core\TestTimeNode.cs" />
     <Compile Include="Core\TestTime.cs" />
+    <Compile Include="Core\TestColor.cs" />
+    <Compile Include="Core\TestImage.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\LongoMatch.Core\LongoMatch.Core.csproj">
@@ -55,4 +57,9 @@
       <Name>LongoMatch.Services</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="Core\dibujo.svg">
+      <LogicalName>dibujo.svg</LogicalName>
+    </EmbeddedResource>
+  </ItemGroup>
 </Project>
\ No newline at end of file


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