[longomatch] Port and add more unit tests



commit df536db16289878d9d566869d99e0aab19def0d5
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Mar 2 14:41:53 2015 +0100

    Port and add more unit tests

 LongoMatch.Multimedia/Makefile.am |    2 +-
 Tests/Core/TestDashboardButton.cs |  130 +++++++++++++++++++++++++++++++++++++
 Tests/Core/TestDrawing.cs         |   32 ---------
 Tests/Core/TestFrameDrawing.cs    |   52 +++++++++++++++
 Tests/Core/TestImage.cs           |   33 ++--------
 Tests/Makefile.am                 |    5 +-
 Tests/Tests.csproj                |    3 +
 Tests/Utils.cs                    |   25 +++++++
 8 files changed, 220 insertions(+), 62 deletions(-)
---
diff --git a/LongoMatch.Multimedia/Makefile.am b/LongoMatch.Multimedia/Makefile.am
index b22f1ca..310c58b 100644
--- a/LongoMatch.Multimedia/Makefile.am
+++ b/LongoMatch.Multimedia/Makefile.am
@@ -18,12 +18,12 @@ SOURCES = Capturer/FakeCapturer.cs \
        Player/ObjectManager.cs \
        Remuxer/GstRemuxer.cs \
        Remuxer/ObjectManager.cs \
+       Utils/Devices.cs \
        Utils/GStreamer.cs \
        Utils/GstDiscoverer.cs \
        Utils/MultimediaFactory.cs \
        Utils/Seeker.cs \
        Utils/TimeString.cs \
-       Utils/Devices.cs \
        Utils/WindowHandle.cs
 
 DLLCONFIG = LongoMatch.Multimedia.dll.config
diff --git a/Tests/Core/TestDashboardButton.cs b/Tests/Core/TestDashboardButton.cs
new file mode 100644
index 0000000..20f7422
--- /dev/null
+++ b/Tests/Core/TestDashboardButton.cs
@@ -0,0 +1,130 @@
+//
+//  Copyright (C) 2015 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Core.Store;
+using NUnit.Framework;
+using LongoMatch.Core.Common;
+
+namespace Tests.Core
+{
+       [TestFixture()]
+       public class TestDashboardButton
+       {
+               [Test()]
+               public void TestSerialization ()
+               {
+                       DashboardButton db = new DashboardButton ();
+                       Utils.CheckSerialization (db);
+                       db = new TimedDashboardButton ();
+                       Utils.CheckSerialization (db);
+                       db = new TagButton ();
+                       Utils.CheckSerialization (db);
+                       db = new TimerButton ();
+                       Utils.CheckSerialization (db);
+                       db = new EventButton ();
+                       Utils.CheckSerialization (db);
+                       db = new AnalysisEventButton ();
+                       Utils.CheckSerialization (db);
+                       db = new PenaltyCardButton ();
+                       Utils.CheckSerialization (db);
+                       db = new PenaltyCardButton ();
+                       Utils.CheckSerialization (db);
+                       db = new ScoreButton ();
+                       Utils.CheckSerialization (db);
+               }
+               
+               [Test()]
+               public void TestTimedDashboardButton ()
+               {
+                       TimedDashboardButton db = new TimedDashboardButton ();
+                       Assert.IsNotNull (db.Start);
+                       Assert.IsNotNull (db.Stop);
+               }
+               
+               [Test()]
+               public void TestTagButton ()
+               {
+                       TagButton db = new TagButton ();
+                       Assert.IsNull (db.Name);
+                       Assert.IsNull (db.HotKey);
+                       db.Tag = new Tag ("test");
+                       Assert.AreEqual (db.Name, "test");
+                       db.Name = "test2";
+                       Assert.AreEqual (db.Tag.Value, "test2");
+               }
+               
+               [Test()]
+               public void TestTimerButton ()
+               {
+                       TimerButton tm = new TimerButton ();
+                       Assert.IsNull (tm.Name);
+                       tm.Timer = new Timer {Name = "test"};
+                       Assert.AreEqual (tm.Name, "test");
+                       tm.Name = "test2";
+                       Assert.AreEqual (tm.Timer.Name, "test2");
+               }
+               
+               [Test()]
+               public void TestEventButton ()
+               {
+                       EventButton eb = new EventButton ();
+                       Assert.IsNull (eb.Name);
+                       Assert.IsNull (eb.BackgroundColor);
+                       eb.EventType = new EventType {Name = "test", Color = Color.Red};
+                       Assert.AreEqual (eb.Name, "test");
+                       Assert.AreEqual (eb.BackgroundColor, Color.Red);
+                       eb.Name = "test2";
+                       eb.BackgroundColor = Color.Blue;
+                       Assert.AreEqual (eb.EventType.Name, "test2");
+                       Assert.AreEqual (eb.EventType.Color, Color.Blue);
+               }
+               
+               [Test()]
+               public void TestAnalysisEventButton ()
+               {
+                       AnalysisEventButton ab = new AnalysisEventButton ();
+                       ab.EventType = new AnalysisEventType ();
+                       Assert.AreEqual (ab.EventType, ab.AnalysisEventType);
+               }
+               
+               [Test()]
+               public void TestPenaltyCardButton ()
+               {
+                       PenaltyCardButton pb = new PenaltyCardButton ();
+                       Assert.IsNull (pb.BackgroundColor);
+                       Assert.IsNull (pb.Name);
+                       pb.PenaltyCard = new PenaltyCard ("test", Color.Red, CardShape.Circle);
+                       Assert.AreEqual (pb.Name, "test");
+                       Assert.AreEqual (pb.BackgroundColor, Color.Red);
+                       Assert.AreEqual (pb.PenaltyCardEventType, pb.EventType);
+               }
+               
+               [Test()]
+               public void TestScoreButton ()
+               {
+                       ScoreButton sb = new ScoreButton ();
+                       Assert.IsNull (sb.BackgroundColor);
+                       Assert.IsNull (sb.Name);
+                       sb.Score = new Score ("test", 2);
+                       Assert.AreEqual (sb.Name, "test");
+                       Assert.AreEqual (sb.BackgroundColor, sb.Score.Color);
+                       Assert.AreEqual (sb.ScoreEventType, sb.EventType);
+               }
+       }
+}
+
diff --git a/Tests/Core/TestFrameDrawing.cs b/Tests/Core/TestFrameDrawing.cs
new file mode 100644
index 0000000..9d4f214
--- /dev/null
+++ b/Tests/Core/TestFrameDrawing.cs
@@ -0,0 +1,52 @@
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Collections.Generic;
+using LongoMatch.Core.Common;
+using LongoMatch.Core.Store;
+using LongoMatch.Core.Store.Drawables;
+using NUnit.Framework;
+
+namespace Tests.Core
+{
+       [TestFixture()]
+       public class TestFrameDrawing
+       {
+               [Test()]
+               public void TestSerialization ()
+               {
+                       FrameDrawing d = new FrameDrawing ();
+                       d.Miniature = Utils.LoadImageFromFile ();
+                       d.Freehand = Utils.LoadImageFromFile ();
+                       d.Drawables = new List<Drawable> {new Line (), new Rectangle()};
+                       d.Angle = MediaFileAngle.Angle2;
+                       d.Render = new Time (1000);
+                       d.Pause = new Time (2000);
+                       Utils.CheckSerialization (d);
+                       
+                       FrameDrawing d2 = Utils.SerializeDeserialize (d);
+                       Assert.AreEqual (d.Render, d2.Render);
+                       Assert.AreEqual (d.Pause, d2.Pause);
+                       Assert.AreEqual (d.Angle, d2.Angle);
+                       Assert.AreEqual (d2.Drawables.Count, d.Drawables.Count);
+                       Assert.IsNotNull (d2.Freehand);
+                       Assert.IsNotNull (d2.Miniature);
+               }
+       }
+}
+
diff --git a/Tests/Core/TestImage.cs b/Tests/Core/TestImage.cs
index 1e50f07..361faca 100644
--- a/Tests/Core/TestImage.cs
+++ b/Tests/Core/TestImage.cs
@@ -27,34 +27,11 @@ namespace Tests.Core
        {
                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 ()
+               public void LoadImageFromFile ()
                {
-                       img = LoadFromFile (false);
+                       img = Utils.LoadImageFromFile (false);
                }
 
                [Test()]
@@ -69,7 +46,7 @@ namespace Tests.Core
                {
                        Assert.AreEqual (img.Width, 16);
                        Assert.AreEqual (img.Height, 16);
-                       img = LoadFromFile (true);
+                       img = Utils.LoadImageFromFile (true);
                        Assert.AreEqual (img.Width, 20);
                        Assert.AreEqual (img.Height, 20);
                }
@@ -121,7 +98,7 @@ namespace Tests.Core
                [Test()]
                public void TestComposite ()
                {
-                       Image img2 = LoadFromFile (true);
+                       Image img2 = Utils.LoadImageFromFile (true);
                        Image img3 = Image.Composite (img2, img);
                        Assert.AreEqual (img3.Width, 20);
                        Assert.AreEqual (img3.Height, 20);
diff --git a/Tests/Makefile.am b/Tests/Makefile.am
index 69b4014..36cc6c0 100644
--- a/Tests/Makefile.am
+++ b/Tests/Makefile.am
@@ -4,6 +4,9 @@ TARGET = library
 LINK = $(REF_DEP_TESTS)
 
 SOURCES = Core/TestColor.cs \
+       Core/TestCoordinates.cs \
+       Core/TestDashboardButton.cs \
+       Core/TestFrameDrawing.cs \
        Core/TestImage.cs \
        Core/TestTime.cs \
        Core/TestTimeNode.cs \
@@ -15,4 +18,4 @@ RESOURCES = Core/dibujo.svg
 include $(top_srcdir)/build/build.mk
 
 check:
-               nunit-console $(ASSEMBLY_FILE) --result=$(ASSEMBLY)-test-results.xml
+       nunit-console $(ASSEMBLY_FILE) --result=$(ASSEMBLY)-test-results.xml
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 10fd6ba..bc066fc 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -46,6 +46,9 @@
     <Compile Include="Core\TestTime.cs" />
     <Compile Include="Core\TestColor.cs" />
     <Compile Include="Core\TestImage.cs" />
+    <Compile Include="Core\TestCoordinates.cs" />
+    <Compile Include="Core\TestDashboardButton.cs" />
+    <Compile Include="Core\TestFrameDrawing.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\LongoMatch.Core\LongoMatch.Core.csproj">
diff --git a/Tests/Utils.cs b/Tests/Utils.cs
index 9b55c72..290c924 100644
--- a/Tests/Utils.cs
+++ b/Tests/Utils.cs
@@ -19,6 +19,7 @@ using System;
 using System.IO;
 using LongoMatch.Core.Common;
 using NUnit.Framework;
+using System.Reflection;
 
 namespace Tests
 {
@@ -66,6 +67,30 @@ namespace Tests
                        }
                        Assert.AreEqual (jsonString, newJsonString);
                }
+               
+               public static Image LoadImageFromFile (bool scaled = false)
+               {
+                       Image img = null;
+                       string tmpFile = Path.GetTempFileName ();
+
+                       using (Stream resource = 
Assembly.GetExecutingAssembly().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;
+               }
        }
 }
 


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