[longomatch] Port more tests



commit 736f4506610111907c395463391899d7be326aaf
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Mar 4 17:18:49 2015 +0100

    Port more tests

 LongoMatch.Core/Config.cs                       |    8 +-
 LongoMatch.Core/Store/Templates/Dashboard.cs    |   10 ++-
 LongoMatch.Core/Store/Templates/TeamTemplate.cs |   15 +++-
 Tests/Core/TestPlayer.cs                        |   11 +--
 Tests/Core/TestPlaysFilter.cs                   |   99 +++++++++++++----------
 Tests/Makefile.am                               |    2 +
 Tests/Tests.csproj                              |    2 +
 7 files changed, 86 insertions(+), 61 deletions(-)
---
diff --git a/LongoMatch.Core/Config.cs b/LongoMatch.Core/Config.cs
index 2043d8a..b34b8d1 100644
--- a/LongoMatch.Core/Config.cs
+++ b/LongoMatch.Core/Config.cs
@@ -31,10 +31,10 @@ namespace LongoMatch
 {
        public class Config
        {
-               public static string homeDirectory;
-               public static string baseDirectory;
-               public static string configDirectory;
-               public static string dataDir;
+               public static string homeDirectory = ".";
+               public static string baseDirectory = ".";
+               public static string configDirectory = ".";
+               public static string dataDir = ".";
                
                /* State */
                public static IGUIToolkit GUIToolkit;
diff --git a/LongoMatch.Core/Store/Templates/Dashboard.cs b/LongoMatch.Core/Store/Templates/Dashboard.cs
index cbb944f..f48bf2b 100644
--- a/LongoMatch.Core/Store/Templates/Dashboard.cs
+++ b/LongoMatch.Core/Store/Templates/Dashboard.cs
@@ -53,9 +53,13 @@ namespace LongoMatch.Core.Store.Templates
                /// Creates a new template
                /// </summary>
                public Dashboard() {
-                       FieldBackground = Config.FieldBackground;
-                       HalfFieldBackground = Config.HalfFieldBackground;
-                       GoalBackground = Config.GoalBackground;
+                       try {
+                               FieldBackground = Config.FieldBackground;
+                               HalfFieldBackground = Config.HalfFieldBackground;
+                               GoalBackground = Config.GoalBackground;
+                       } catch {
+                               /* Ingore for unit tests */
+                       }
                        ID = Guid.NewGuid ();
                        List = new List<DashboardButton>();
                }
diff --git a/LongoMatch.Core/Store/Templates/TeamTemplate.cs b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
index a2333c1..1c3cec6 100644
--- a/LongoMatch.Core/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
@@ -34,15 +34,20 @@ namespace LongoMatch.Core.Store.Templates
                private const int MAX_WIDTH=100;
                private const int MAX_HEIGHT=100;
                
-               public TeamTemplate () {
-                       TeamName = Catalog.GetString("Team");
+               public TeamTemplate ()
+               {
+                       TeamName = Catalog.GetString ("Team");
                        if (Formation == null) {
                                FormationStr = "1-4-3-3";
                        }
-                       ID = Guid.NewGuid();
-                       List = new List<Player>();
+                       ID = Guid.NewGuid ();
+                       List = new List<Player> ();
                        string path = Path.Combine (Config.IconsDir, StyleConf.DefaultShield);
-                       Shield = Image.LoadFromFile (path);
+                       try {
+                               Shield = Image.LoadFromFile (path);
+                       } catch {
+                               /* Ignore for unit tests */
+                       }
                        ActiveColor = 0;
                        Colors = new Color [2];
                        Colors[0] = Color.Blue1;
diff --git a/Tests/Core/TestPlayer.cs b/Tests/Core/TestPlayer.cs
index 55f07db..51e9c11 100644
--- a/Tests/Core/TestPlayer.cs
+++ b/Tests/Core/TestPlayer.cs
@@ -32,7 +32,7 @@ namespace Tests.Core
                        Player player = new Player {Name="andoni", Position="runner",
                                Number = 5, Birthday = new DateTime (1984, 6, 11),
                                Nationality = "spanish", Height = 1.73f, Weight = 70,
-                               Playing = true};
+                               Playing = true, Mail = "test test"};
                                
                        Utils.CheckSerialization (player);
                        
@@ -45,6 +45,7 @@ namespace Tests.Core
                        Assert.AreEqual (player.Height, newPlayer.Height);
                        Assert.AreEqual (player.Weight, newPlayer.Weight);
                        Assert.AreEqual (player.Playing, newPlayer.Playing);
+                       Assert.AreEqual (player.Mail, newPlayer.Mail);
                }
                
                [Test()]
@@ -54,12 +55,10 @@ namespace Tests.Core
                                Number = 5, Birthday = new DateTime (1984, 6, 11),
                                Nationality = "spanish", Height = 1.73f, Weight = 70,
                                Playing = true};
-                               
-                       player.Photo = null;
-                       Assert.AreEqual (player.Photo, null);
-                       /* FIXME: test with real image */
-                       player.Photo = null;
+                       player.Photo = Utils.LoadImageFromFile();
                        Utils.CheckSerialization (player);
+                       Assert.AreEqual (player.Photo.Width, 16);
+                       Assert.AreEqual (player.Photo.Height, 16);
                }
        }
 }
diff --git a/Tests/Core/TestPlaysFilter.cs b/Tests/Core/TestPlaysFilter.cs
index a987056..13e71ea 100644
--- a/Tests/Core/TestPlaysFilter.cs
+++ b/Tests/Core/TestPlaysFilter.cs
@@ -36,19 +36,25 @@ namespace Tests.Core
                        MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
                                                      "aac", 320, 240, 1.3, null);
                        ProjectDescription pd = new ProjectDescription ();
-                       pd.File = mf;
+                       pd.FileSet = new MediaFileSet ();
+                       pd.FileSet.SetAngle (MediaFileAngle.Angle1, mf);
                        p.Description = pd;
+                       p.UpdateEventTypesAndTimers ();
+                       
+                       AnalysisEventButton b = p.Dashboard.List[0] as AnalysisEventButton;
                        
                        /* No tags, no players */
-                       pl = new TimelineEvent {EventType = p.Dashboard.CategoriesList[0]};
+                       pl = new TimelineEvent {EventType = b.EventType};
                        p.Timeline.Add (pl);
                        /* tags, but no players */
-                       pl = new TimelineEvent {EventType = p.Dashboard.CategoriesList[1]};
-                       pl.Tags.Add (p.Dashboard.CategoriesList[1].Tags[0]);
+                       b = p.Dashboard.List[1] as AnalysisEventButton;
+                       pl = new TimelineEvent {EventType = b.EventType};
+                       pl.Tags.Add (b.AnalysisEventType.Tags[0]);
                        p.Timeline.Add (pl);
                        /* tags and players */
-                       pl = new TimelineEvent {EventType = p.Dashboard.CategoriesList[2]};
-                       pl.Tags.Add (p.Dashboard.CategoriesList[2].Tags[1]);
+                       b = p.Dashboard.List[2] as AnalysisEventButton;
+                       pl = new TimelineEvent {EventType = b.EventType};
+                       pl.Tags.Add (b.AnalysisEventType.Tags[1]);
                        pl.Players.Add (p.LocalTeamTemplate.List[0]);
                        p.Timeline.Add (pl);
                        return p;
@@ -60,7 +66,7 @@ namespace Tests.Core
                        Project p = CreateProject ();
                        EventsFilter filter = new EventsFilter (p);
                        
-                       Assert.AreEqual (17, filter.VisibleCategories.Count);
+                       Assert.AreEqual (13, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (10, filter.VisiblePlayers.Count);
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
                }
@@ -71,32 +77,32 @@ namespace Tests.Core
                        Project p = CreateProject ();
                        EventsFilter filter = new EventsFilter (p);
                        
-                       filter.FilterEventType (p.Dashboard.CategoriesList[0], true);
-                       Assert.AreEqual (1, filter.VisibleCategories.Count);
+                       filter.FilterEventType (p.EventTypes[0], true);
+                       Assert.AreEqual (1, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (1, filter.VisiblePlays.Count);
                        
-                       filter.FilterEventType (p.Dashboard.CategoriesList[1], true);
-                       Assert.AreEqual (2, filter.VisibleCategories.Count);
+                       filter.FilterEventType (p.EventTypes[1], true);
+                       Assert.AreEqual (2, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (2, filter.VisiblePlays.Count);
 
-                       filter.FilterEventType (p.Dashboard.CategoriesList[2], true);
-                       Assert.AreEqual (3, filter.VisibleCategories.Count);
+                       filter.FilterEventType (p.EventTypes[2], true);
+                       Assert.AreEqual (3, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
                        
-                       filter.FilterEventType (p.Dashboard.CategoriesList[0], true);
-                       Assert.AreEqual (3, filter.VisibleCategories.Count);
+                       filter.FilterEventType (p.EventTypes[0], true);
+                       Assert.AreEqual (3, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
                        
-                       filter.FilterEventType (p.Dashboard.CategoriesList[0], false);
-                       Assert.AreEqual (2, filter.VisibleCategories.Count);
+                       filter.FilterEventType (p.EventTypes[0], false);
+                       Assert.AreEqual (2, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (2, filter.VisiblePlays.Count);
 
-                       filter.FilterEventType (p.Dashboard.CategoriesList[1], false);
-                       Assert.AreEqual (1, filter.VisibleCategories.Count);
+                       filter.FilterEventType (p.EventTypes[1], false);
+                       Assert.AreEqual (1, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (1, filter.VisiblePlays.Count);
                        
-                       filter.FilterEventType (p.Dashboard.CategoriesList[2], false);
-                       Assert.AreEqual (17, filter.VisibleCategories.Count);
+                       filter.FilterEventType (p.EventTypes[2], false);
+                       Assert.AreEqual (13, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
                }
                
@@ -105,44 +111,51 @@ namespace Tests.Core
                {
                        Project p = CreateProject ();
                        EventsFilter filter = new EventsFilter (p);
+                       AnalysisEventType a;
                        
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
                        
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[0], 
p.Dashboard.CategoriesList[0].Tags[0], true);
-                       Assert.AreEqual (1, filter.VisibleCategories.Count);
+                       a = p.EventTypes[0] as AnalysisEventType;
+                       filter.FilterEventTag (a, a.Tags[0], true);
+                       Assert.AreEqual (1, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (0, filter.VisiblePlays.Count);
 
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[1], 
p.Dashboard.CategoriesList[1].Tags[0], true);
-                       Assert.AreEqual (2, filter.VisibleCategories.Count);
+                       a = p.EventTypes[1] as AnalysisEventType;
+                       filter.FilterEventTag (a, a.Tags[0], true);
+                       Assert.AreEqual (2, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (1, filter.VisiblePlays.Count);
                        
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[2], 
p.Dashboard.CategoriesList[2].Tags[0], true);
-                       Assert.AreEqual (3, filter.VisibleCategories.Count);
+                       a = p.EventTypes[2] as AnalysisEventType;
+                       filter.FilterEventTag (a, a.Tags[0], true);
+                       Assert.AreEqual (3, filter.VisibleEventTypes.Count);
                        Assert.AreEqual (1, filter.VisiblePlays.Count);
 
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[2], 
p.Dashboard.CategoriesList[2].Tags[1], true);
+                       filter.FilterEventTag (a, a.Tags[1], true);
                        Assert.AreEqual (2, filter.VisiblePlays.Count);
                        
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[0], 
p.Dashboard.CategoriesList[0].Tags[0], false);
+                       a = p.EventTypes[0] as AnalysisEventType;
+                       filter.FilterEventTag (a, a.Tags[0], false);
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
                        
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[1], 
p.Dashboard.CategoriesList[1].Tags[0], false);
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[1], 
p.Dashboard.CategoriesList[1].Tags[1], true);
+                       a = p.EventTypes[1] as AnalysisEventType;
+                       filter.FilterEventTag (a, a.Tags[0], false);
+                       filter.FilterEventTag (a, a.Tags[1], true);
                        Assert.AreEqual (2, filter.VisiblePlays.Count);
                        Assert.AreEqual (p.Timeline[0], filter.VisiblePlays[0]);
                        Assert.AreEqual (p.Timeline[2], filter.VisiblePlays[1]);
                        
                        /* One tag filtered now, but not the one of this play */
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[2], 
p.Dashboard.CategoriesList[2].Tags[1], false);
+                       a = p.EventTypes[2] as AnalysisEventType;
+                       filter.FilterEventTag (a, a.Tags[1], false);
                        Assert.AreEqual (1, filter.VisiblePlays.Count);
                        Assert.AreEqual (p.Timeline[0], filter.VisiblePlays[0]);
                        /* No more tags filtered, if the category matches we are ok */
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[2], 
p.Dashboard.CategoriesList[2].Tags[0], false);
+                       filter.FilterEventTag (a, a.Tags[0], false);
                        Assert.AreEqual (2, filter.VisiblePlays.Count);
                        Assert.AreEqual (p.Timeline[0], filter.VisiblePlays[0]);
                        Assert.AreEqual (p.Timeline[2], filter.VisiblePlays[1]);
 
-                       filter.ClearCategoriesFilter ();
+                       filter.ClearAll ();
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
                }
                
@@ -172,7 +185,7 @@ namespace Tests.Core
                }
                
                [Test()]
-               public void TestClearFilters ()
+               public void TestClearAll ()
                {
                        Project p = CreateProject ();
                        EventsFilter filter = new EventsFilter (p);
@@ -180,23 +193,23 @@ namespace Tests.Core
                        filter.FilterPlayer (p.LocalTeamTemplate.List[0], true);
                        Assert.AreEqual (1, filter.VisiblePlays.Count);
                        Assert.AreEqual (1, filter.VisiblePlayers.Count);
-                       filter.ClearPlayersFilter();
+                       filter.ClearAll();
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
                        Assert.AreEqual (10, filter.VisiblePlayers.Count);
                        
-                       filter.FilterEventType (p.Dashboard.CategoriesList[0], true);
+                       filter.FilterEventType (p.EventTypes[0], true);
                        Assert.AreEqual (1, filter.VisiblePlays.Count);
-                       Assert.AreEqual (1, filter.VisibleCategories.Count);
-                       filter.ClearCategoriesFilter ();
+                       Assert.AreEqual (1, filter.VisibleEventTypes.Count);
+                       filter.ClearAll ();
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
-                       Assert.AreEqual (17, filter.VisibleCategories.Count);
+                       Assert.AreEqual (13, filter.VisibleEventTypes.Count);
                        
-                       filter.FilterEventTag (p.Dashboard.CategoriesList[0], 
p.Dashboard.CategoriesList[0].Tags[0], true);
+                       filter.FilterEventTag (p.EventTypes[0], (p.EventTypes[0] as 
AnalysisEventType).Tags[0], true);
                        Assert.AreEqual (0, filter.VisiblePlays.Count);
-                       Assert.AreEqual (1, filter.VisibleCategories.Count);
+                       Assert.AreEqual (1, filter.VisibleEventTypes.Count);
                        filter.ClearAll ();
                        Assert.AreEqual (3, filter.VisiblePlays.Count);
-                       Assert.AreEqual (17, filter.VisibleCategories.Count);
+                       Assert.AreEqual (13, filter.VisibleEventTypes.Count);
                }
        }
 }
diff --git a/Tests/Makefile.am b/Tests/Makefile.am
index 4a0ba28..b1da77e 100644
--- a/Tests/Makefile.am
+++ b/Tests/Makefile.am
@@ -22,6 +22,8 @@ SOURCES = Core/Drawables/TestAngle.cs \
        Core/TestMediaFile.cs \
        Core/TestMediaFileSet.cs \
        Core/TestPenaltyCard.cs \
+       Core/TestPlayer.cs \
+       Core/TestPlaysFilter.cs \
        Core/TestPoint.cs \
        Core/TestScore.cs \
        Core/TestTime.cs \
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index b273a77..163a1e5 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -65,6 +65,8 @@
     <Compile Include="Core\Drawables\TestQuadrilateral.cs" />
     <Compile Include="Core\Drawables\TestRectangle.cs" />
     <Compile Include="Core\Drawables\TestText.cs" />
+    <Compile Include="Core\TestPlayer.cs" />
+    <Compile Include="Core\TestPlaysFilter.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\LongoMatch.Core\LongoMatch.Core.csproj">


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