[longomatch] Add more unit tests



commit 09b2908a88d6da21a381137c6788e57084d8ae5a
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Mar 4 14:42:14 2015 +0100

    Add more unit tests

 Tests/Core/TestCategory.cs     |   85 ----------------------------
 Tests/Core/TestEventType.cs    |  121 ++++++++++++++++++++++++++++++++++++++++
 Tests/Core/TestHotkey.cs       |   68 ++++++++++++++++++++++
 Tests/Core/TestMediaFile.cs    |   22 ++++++-
 Tests/Core/TestMediaFileSet.cs |   84 +++++++++++++++++++++++++++
 Tests/Core/TestPenaltyCard.cs  |   45 +++++++++++++++
 Tests/Core/TestScore.cs        |   45 +++++++++++++++
 Tests/Makefile.am              |    7 ++
 Tests/Tests.csproj             |    7 ++
 build/build.environment.mk     |    1 +
 10 files changed, 397 insertions(+), 88 deletions(-)
---
diff --git a/Tests/Core/TestEventType.cs b/Tests/Core/TestEventType.cs
new file mode 100644
index 0000000..4c3c3fc
--- /dev/null
+++ b/Tests/Core/TestEventType.cs
@@ -0,0 +1,121 @@
+//
+//  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 System.IO;
+using LongoMatch.Core.Common;
+using LongoMatch.Core.Store;
+using NUnit.Framework;
+using Newtonsoft.Json;
+
+namespace Tests.Core
+{
+       [TestFixture()]
+       public class TestEventType
+       {
+               [Test()]
+               public void TestEvntType ()
+               {
+                       string jsonString;
+                       EventType evType;
+                       MemoryStream stream;
+                       StreamReader reader;
+                       
+                       evType = new EventType();
+                       evType.Color = new Color (255, 0, 0);
+                       evType.Name = "test";
+                       evType.SortMethod = SortMethodType.SortByDuration;
+                       evType.TagFieldPosition = true;
+                       evType.TagGoalPosition = true;
+                       evType.TagHalfFieldPosition = true;
+                       evType.FieldPositionIsDistance = true;
+                       evType.HalfFieldPositionIsDistance = false;
+                       
+                       Utils.CheckSerialization (evType);
+                       
+                       stream = new MemoryStream ();
+                       Serializer.Save (evType, stream, SerializationType.Json);
+                       stream.Seek (0, SeekOrigin.Begin);
+                       reader = new StreamReader (stream);
+                       jsonString = reader.ReadToEnd();
+                       Assert.IsFalse (jsonString.Contains ("SortMethodString"));
+                       stream.Seek (0, SeekOrigin.Begin);
+                       EventType newEventType = Serializer.Load<EventType> (stream, SerializationType.Json);
+                       
+                       Assert.AreEqual (evType.ID, newEventType.ID);
+                       Assert.AreEqual (evType.Name, newEventType.Name);
+                       Assert.AreEqual (evType.SortMethod, newEventType.SortMethod);
+                       Assert.AreEqual (evType.TagFieldPosition, newEventType.TagFieldPosition);
+                       Assert.AreEqual (evType.TagGoalPosition, newEventType.TagGoalPosition);
+                       Assert.AreEqual (evType.TagHalfFieldPosition, newEventType.TagHalfFieldPosition);
+                       Assert.AreEqual (evType.FieldPositionIsDistance, 
newEventType.FieldPositionIsDistance);
+                       Assert.AreEqual (evType.HalfFieldPositionIsDistance, 
newEventType.HalfFieldPositionIsDistance);
+                       Assert.AreEqual (255, newEventType.Color.R);
+                       Assert.AreEqual (0, newEventType.Color.G);
+                       Assert.AreEqual (0, newEventType.Color.B);
+               }
+               
+               [Test()]
+               public void TestAnalysisEventType ()
+               {
+                       AnalysisEventType at = new AnalysisEventType ();
+                       Utils.CheckSerialization (at);
+                       
+                       Assert.IsNotNull (at.Tags);
+                       Assert.AreEqual (at.TagsByGroup.Count, 0); 
+                       at.Tags.Add (new Tag ("test1", "grp1"));
+                       at.Tags.Add (new Tag ("test2", "grp1"));
+                       at.Tags.Add (new Tag ("test3", "grp2"));
+                       
+                       var tbg = at.TagsByGroup;
+                       Assert.AreEqual (tbg.Count, 2);
+                       Assert.AreEqual (tbg["grp1"].Count, 2);
+                       Assert.AreEqual (tbg["grp2"].Count, 1);
+               }
+               
+               [Test()]
+               public void TestPenaltyCardEventType ()
+               {
+                       PenaltyCardEventType pc = new PenaltyCardEventType ();
+                       Utils.CheckSerialization (pc);
+                       
+                       Assert.AreEqual (pc.ID, Constants.PenaltyCardID);
+                       Assert.AreEqual (pc, new PenaltyCardEventType ());
+               }
+               
+               [Test()]
+               public void TestScoreEventType ()
+               {
+                       ScoreEventType score = new ScoreEventType ();
+                       Utils.CheckSerialization (score);
+                       
+                       Assert.AreEqual (score.ID, Constants.ScoreID);
+                       Assert.AreEqual (score, new ScoreEventType ());
+               }
+               
+               [Test()]
+               public void TestSubstitutionEventType ()
+               {
+                       SubstitutionEventType sub = new SubstitutionEventType ();
+                       Utils.CheckSerialization (sub);
+                       
+                       Assert.AreEqual (sub.ID, Constants.SubsID);
+                       Assert.AreEqual (sub, new SubstitutionEventType ());
+               }
+       }
+}
diff --git a/Tests/Core/TestHotkey.cs b/Tests/Core/TestHotkey.cs
new file mode 100644
index 0000000..417a158
--- /dev/null
+++ b/Tests/Core/TestHotkey.cs
@@ -0,0 +1,68 @@
+//
+//  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 NUnit.Framework;
+using System;
+using LongoMatch.Core.Store;
+
+namespace Tests.Core
+{
+       [TestFixture()]
+       public class TestHotKey
+       {
+               [Test()]
+               public void TestSerialization ()
+               {
+                       HotKey hk = new HotKey ();
+                       hk.Key = 2;
+                       hk.Modifier = 3;
+                       
+                       Utils.CheckSerialization (hk);
+                       
+                       HotKey hk2 = Utils.SerializeDeserialize (hk);
+                       Assert.AreEqual (hk.Key, hk2.Key);
+                       Assert.AreEqual (hk.Modifier, hk2.Modifier);
+               }
+               
+               [Test()]
+               public void TestDefined ()
+               {
+                       HotKey hk = new HotKey ();
+                       Assert.IsFalse (hk.Defined);
+                       hk.Key = 2;
+                       Assert.IsTrue (hk.Defined);
+                       hk.Key = -1;
+                       hk.Modifier = 1;
+                       Assert.IsFalse (hk.Defined);
+               }
+               
+               [Test()]
+               public void TestEquality ()
+               {
+                       HotKey k1 = new HotKey {Key = 1, Modifier = 2};
+                       HotKey k2 = new HotKey {Key = 1, Modifier = 3};
+                       Assert.AreNotEqual (k1, k2);
+                       Assert.IsTrue (k1 != k2);
+                       Assert.IsFalse (k1 == k2);
+                       k2.Modifier = 2;
+                       Assert.AreEqual (k1, k2);
+                       Assert.IsFalse (k1 != k2);
+                       Assert.IsTrue (k1 == k2);
+               }
+       }
+}
+
diff --git a/Tests/Core/TestMediaFile.cs b/Tests/Core/TestMediaFile.cs
index 45af205..b103513 100644
--- a/Tests/Core/TestMediaFile.cs
+++ b/Tests/Core/TestMediaFile.cs
@@ -16,6 +16,7 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
+using System.IO;
 using NUnit.Framework;
 using LongoMatch.Core.Common;
 using LongoMatch.Core.Store;
@@ -44,14 +45,29 @@ namespace Tests.Core
                        Assert.AreEqual (mf.VideoWidth, newmf.VideoWidth);
                        Assert.AreEqual (mf.VideoHeight, newmf.VideoHeight);
                        Assert.AreEqual (mf.Par, newmf.Par);
+                       Assert.AreEqual (mf.Offset, new Time (0));
                                
                }
                
                [Test()]
-               public void TestGetFrames ()
+               public void TestShortDescription ()
                {
-                       MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
-                                                     "aac", 320, 240, 1.3, null);
+                       MediaFile mf = new MediaFile {VideoWidth = 320, VideoHeight = 240, Fps = 25};
+                       Assert.AreEqual (mf.ShortDescription, "320x240 25fps");
+               }
+               
+               [Test()]
+               public void TestExists ()
+               {
+                       string path = Path.GetTempFileName ();
+                       MediaFile mf = new MediaFile ();
+                       try {
+                               Assert.IsFalse (mf.Exists ());
+                               mf.FilePath = path;
+                               Assert.IsTrue (mf.Exists ());
+                       } finally {
+                               File.Delete (path);
+                       }
                }
        }
 }
diff --git a/Tests/Core/TestMediaFileSet.cs b/Tests/Core/TestMediaFileSet.cs
new file mode 100644
index 0000000..b39be9d
--- /dev/null
+++ b/Tests/Core/TestMediaFileSet.cs
@@ -0,0 +1,84 @@
+//
+//  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;
+using System.IO;
+
+namespace Tests.Core
+{
+       [TestFixture()]
+       public class TestMediaFileSet
+       {
+               [Test()]
+               public void TestSerialization ()
+               {
+                       MediaFileSet mf = new MediaFileSet ();
+                       Utils.CheckSerialization (mf);
+               }
+               
+               [Test()]
+               public void TestPreview ()
+               {
+                       MediaFileSet mf = new MediaFileSet ();
+                       Assert.IsNull (mf.Preview);
+                       mf.SetAngle (MediaFileAngle.Angle1,
+                                    new MediaFile {Preview = Utils.LoadImageFromFile ()});
+                       Assert.IsNotNull (mf.Preview);
+               }
+               
+               [Test()]
+               public void TestDuration ()
+               {
+                       MediaFileSet mf = new MediaFileSet ();
+                       Assert.AreEqual (mf.Duration.MSeconds, 0);
+                       mf.SetAngle (MediaFileAngle.Angle1, new MediaFile {Duration = new Time (2000)});
+                       Assert.AreEqual (mf.Duration.MSeconds, 2000); 
+                       mf.SetAngle (MediaFileAngle.Angle1, new MediaFile {Duration = new Time (2001)});
+                       Assert.AreEqual (mf.Duration.MSeconds, 2001); 
+               }
+               
+               [Test()]
+               public void TestCheckFiles ()
+               {
+                       string path = Path.GetTempFileName ();
+                       MediaFileSet mf = new MediaFileSet ();
+                       Assert.IsFalse (mf.CheckFiles());
+                       mf.SetAngle (MediaFileAngle.Angle1, new MediaFile {FilePath = path});
+                       try {
+                               Assert.IsTrue (mf.CheckFiles ());
+                       } finally {
+                               File.Delete (path);
+                       }
+               }
+               
+               [Test()]
+               public void TestGetSetAngles ()
+               {
+                       MediaFileSet mfs = new MediaFileSet ();
+                       MediaFile mf = new MediaFile ();
+                       Assert.IsNull (mfs.GetAngle (MediaFileAngle.Angle1));
+                       mfs.SetAngle (MediaFileAngle.Angle1, mf);
+                       Assert.AreEqual (mfs.GetAngle (MediaFileAngle.Angle1), mf);
+                       mfs.SetAngle (MediaFileAngle.Angle2, mf);
+                       Assert.AreEqual (mfs.GetAngle (MediaFileAngle.Angle2), mf);
+               }
+       }
+}
+
diff --git a/Tests/Core/TestPenaltyCard.cs b/Tests/Core/TestPenaltyCard.cs
new file mode 100644
index 0000000..84684db
--- /dev/null
+++ b/Tests/Core/TestPenaltyCard.cs
@@ -0,0 +1,45 @@
+//
+//  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 LongoMatch.Core.Common;
+using NUnit.Framework;
+
+namespace Tests.Core
+{
+       [TestFixture()]
+       public class TestPenaltyCard
+       {
+               [Test()]
+               public void TestSerialization ()
+               {
+                       PenaltyCard pc = new PenaltyCard ();
+                       pc.Color = Color.Red;
+                       pc.Name = "test";
+                       pc.Shape = CardShape.Circle;
+                       
+                       Utils.CheckSerialization (pc);
+                       
+                       PenaltyCard pc2 = Utils.SerializeDeserialize (pc);
+                       Assert.AreEqual (pc.Name, pc2.Name);
+                       Assert.AreEqual (pc.Color, pc2.Color);
+                       Assert.AreEqual (pc.Shape, pc2.Shape);
+               }
+       }
+}
+
diff --git a/Tests/Core/TestScore.cs b/Tests/Core/TestScore.cs
new file mode 100644
index 0000000..24b7dc9
--- /dev/null
+++ b/Tests/Core/TestScore.cs
@@ -0,0 +1,45 @@
+//
+//  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.Common;
+using LongoMatch.Core.Store;
+using NUnit.Framework;
+
+namespace Tests.Core
+{
+       [TestFixture()]
+       public class TestScore
+       {
+               [Test()]
+               public void TestSerialization ()
+               {
+                       Score s = new Score ();
+                       s.Color = Color.Red;
+                       s.Name = "test";
+                       s.Points = 2;
+                       
+                       Utils.CheckSerialization (s);
+                       
+                       Score s2 = Utils.SerializeDeserialize (s);
+                       Assert.AreEqual (s.Color, s2.Color);
+                       Assert.AreEqual (s.Name, s2.Name);
+                       Assert.AreEqual (s.Points, s2.Points);
+               }
+       }
+}
+
diff --git a/Tests/Makefile.am b/Tests/Makefile.am
index 2eaf4ae..2df3cfc 100644
--- a/Tests/Makefile.am
+++ b/Tests/Makefile.am
@@ -6,8 +6,15 @@ LINK = $(REF_DEP_TESTS)
 SOURCES = Core/TestColor.cs \
        Core/TestCoordinates.cs \
        Core/TestDashboardButton.cs \
+       Core/TestEventType.cs \
        Core/TestFrameDrawing.cs \
+       Core/TestHotkey.cs \
        Core/TestImage.cs \
+       Core/TestMediaFile.cs \
+       Core/TestMediaFileSet.cs \
+       Core/TestPenaltyCard.cs \
+       Core/TestPoint.cs \
+       Core/TestScore.cs \
        Core/TestTime.cs \
        Core/TestTimeNode.cs \
        Core/TestTimelineEvent.cs \
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 8445f27..7b1277e 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -49,6 +49,13 @@
     <Compile Include="Core\TestCoordinates.cs" />
     <Compile Include="Core\TestDashboardButton.cs" />
     <Compile Include="Core\TestFrameDrawing.cs" />
+    <Compile Include="Core\TestEventType.cs" />
+    <Compile Include="Core\TestHotkey.cs" />
+    <Compile Include="Core\TestMediaFile.cs" />
+    <Compile Include="Core\TestMediaFileSet.cs" />
+    <Compile Include="Core\TestPenaltyCard.cs" />
+    <Compile Include="Core\TestScore.cs" />
+    <Compile Include="Core\TestPoint.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\LongoMatch.Core\LongoMatch.Core.csproj">
diff --git a/build/build.environment.mk b/build/build.environment.mk
index 870aeaa..8a43747 100644
--- a/build/build.environment.mk
+++ b/build/build.environment.mk
@@ -170,6 +170,7 @@ REF_DEP_LONGOMATCH_PLUGINS_STATS = \
 REF_DEP_TESTS = \
                      $(LINK_LONGOMATCH_CORE) \
                      $(LINK_LONGOMATCH_SERVICES) \
+                     $(LINK_JSON) \
                      $(LINK_NUNIT)
 
 DIR_BIN = $(top_builddir)/bin


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