[banshee] Add unit tests for the text displayed by TrackInfoDisplay



commit e74b72693aa0069a9368c3e7786d874fc4f07a04
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Sun Apr 1 15:34:20 2012 +0200

    Add unit tests for the text displayed by TrackInfoDisplay
    
    The construction of the text displayed in TrackInfoDisplay and its
    subclasses is quite tricky and needs some refactoring, but first let's
    add some unit tests to try to avoid regressions.

 .../Tests/TrackInfoDisplayTests.cs                 |  221 ++++++++++++++++++++
 .../Banshee.ThickClient/Banshee.ThickClient.csproj |    4 +
 src/Core/Banshee.ThickClient/Makefile.am           |    1 +
 tests/Makefile.am                                  |    1 +
 4 files changed, 227 insertions(+), 0 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/Tests/TrackInfoDisplayTests.cs b/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/Tests/TrackInfoDisplayTests.cs
new file mode 100644
index 0000000..c339cea
--- /dev/null
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/Tests/TrackInfoDisplayTests.cs
@@ -0,0 +1,221 @@
+//
+// TrackInfoDisplayTests.cs
+//
+// Author:
+//   Bertrand Lorentz <bertrand lorentz gmail com>
+//
+// Copyright 2012 Bertrand Lorentz
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#if ENABLE_TESTS
+
+using System;
+
+using Cairo;
+using Mono.Unix;
+using NUnit.Framework;
+
+using Hyena;
+using Hyena.Tests;
+
+using Banshee.Collection;
+using Banshee.Gui.Widgets;
+
+namespace Banshee.Gui.Widgets.Tests
+{
+    public class TextTrackInfoDisplay : TrackInfoDisplay
+    {
+        protected override void RenderTrackInfo (Context cr, TrackInfo track, bool render_track, bool render_artist_album)
+        {
+        }
+
+        public string GetFirstLine (TrackInfo track)
+        {
+            return GetFirstLineText (track);
+        }
+
+        public string GetSecondLine (TrackInfo track)
+        {
+            return GetSecondLineText (track);
+        }
+    }
+
+    [TestFixture]
+    public class TrackInfoDisplayTests : TestBase
+    {
+        private TextTrackInfoDisplay display;
+
+        [TestFixtureSetUp]
+        public void Init ()
+        {
+            // TrackInfoDisplay is a widget, so we need to initialize GTK
+            Gtk.Application.Init ();
+            display = new TextTrackInfoDisplay ();
+        }
+
+        [Test]
+        public void TestEmptyTrack ()
+        {
+            var track = new TrackInfo ();
+
+            TestFirstLine (track, TrackInfo.UnknownTitle);
+            TestSecondLine (track,
+                            "<span color=\"#000000\"><span color=\"#000000\" size=\"small\">by</span> {0}</span>",
+                            ArtistInfo.UnknownArtistName);
+        }
+
+        [Test]
+        public void TestTrackArtist ()
+        {
+            var track = new TrackInfo ();
+            track.TrackTitle = "The Title";
+            track.ArtistName = "The Artist";
+
+            TestFirstLine (track, track.TrackTitle);
+            TestSecondLine (track,
+                            "<span color=\"#000000\"><span color=\"#000000\" size=\"small\">by</span> {0}</span>",
+                            track.ArtistName);
+        }
+
+        [Test]
+        public void TestTrackAlbum ()
+        {
+            var track = new TrackInfo ();
+            track.TrackTitle = "The Title";
+            track.AlbumTitle = "The Album Title";
+
+            TestFirstLine (track, track.TrackTitle);
+            TestSecondLine (track,
+                            "<span color=\"#000000\"><span color=\"#000000\" size=\"small\">from</span> {0}</span>",
+                            track.AlbumTitle);
+        }
+
+        [Test]
+        public void TestTrackFull ()
+        {
+            var track = new TrackInfo ();
+            track.TrackTitle = "The Title";
+            track.AlbumTitle = "The Album Title";
+            track.ArtistName = "The Artist";
+
+            TestFirstLine (track, track.TrackTitle);
+            TestSecondLine (track,
+                            "<span color=\"#000000\"><span color=\"#000000\" size=\"small\">by</span> {0} " +
+                            "<span color=\"#000000\" size=\"small\">from</span> {1}</span>",
+                            track.ArtistName, track.AlbumTitle);
+        }
+
+        [Test]
+        public void TestPodcastTrack ()
+        {
+            var track = new TrackInfo ();
+            track.TrackTitle = "The Title";
+            track.AlbumTitle = "The Album Title";
+            track.ArtistName = "The Artist";
+            track.MediaAttributes |= TrackMediaAttributes.Podcast;
+            track.ReleaseDate = new DateTime (2012, 02, 29);
+
+            TestFirstLine (track, track.TrackTitle);
+            TestSecondLine (track,
+                            "<span color=\"#000000\"><span color=\"#000000\" size=\"small\">from</span> {0} " +
+                            "<span color=\"#000000\" size=\"small\">published</span> {1}</span>",
+                            track.AlbumTitle, track.ReleaseDate.ToShortDateString ());
+        }
+
+        [Test]
+        public void TestRadioTrackEmpty ()
+        {
+            var station = new TrackInfo ();
+
+            var track = new Banshee.Streaming.RadioTrackInfo (station);
+
+            TestFirstLine (track, TrackInfo.UnknownTitle);
+            TestSecondLine (track,
+                            "<span color=\"#000000\">{0}</span>",
+                            Banshee.Streaming.RadioTrackInfo.UnknownStream);
+        }
+
+        [Test]
+        public void TestRadioTrackStationOnly ()
+        {
+            var station = new TrackInfo ();
+            station.TrackTitle = "Station Title";
+            station.AlbumTitle = "Station Album Title";
+            station.ArtistName = "Station Artist";
+
+            var track = new Banshee.Streaming.RadioTrackInfo (station);
+
+            TestFirstLine (track, station.TrackTitle);
+            TestSecondLine (track,
+                            "<span color=\"#000000\">{0}</span>",
+                            track.ParentTrack.ArtistName);
+        }
+
+        [Test]
+        public void TestRadioTrackPartial ()
+        {
+            var station = new TrackInfo ();
+            station.TrackTitle = "Station Title";
+
+            var track = new Banshee.Streaming.RadioTrackInfo (station);
+            track.TrackTitle = "The Title";
+            track.ArtistName = "The Artist";
+
+            TestFirstLine (track, track.TrackTitle);
+            TestSecondLine (track,
+                            "<span color=\"#000000\"><span color=\"#000000\" size=\"small\">by</span> {0} " +
+                            "<span color=\"#000000\" size=\"small\">on</span> {1}</span>",
+                            track.ArtistName, track.ParentTrack.TrackTitle);
+        }
+
+        [Test]
+        public void TestRadioTrackFull ()
+        {
+            var station = new TrackInfo ();
+            station.TrackTitle = "Station Title";
+            station.AlbumTitle = "Station Album Title";
+            station.ArtistName = "Station Artist";
+
+            var track = new Banshee.Streaming.RadioTrackInfo (station);
+            track.TrackTitle = "The Title";
+            track.AlbumTitle = "The Album Title";
+            track.ArtistName = "The Artist";
+
+            TestFirstLine (track, track.TrackTitle);
+            TestSecondLine (track,
+                            "<span color=\"#000000\"><span color=\"#000000\" size=\"small\">by</span> {0} " +
+                            "<span color=\"#000000\" size=\"small\">from</span> {1} " +
+                            "<span color=\"#000000\" size=\"small\">on</span> {2}</span>",
+                            track.ArtistName, track.AlbumTitle, track.ParentTrack.TrackTitle);
+        }
+
+        private void TestFirstLine (TrackInfo track, string content)
+        {
+            Assert.AreEqual (String.Format ("<b>{0}</b>", content), display.GetFirstLine (track));
+        }
+
+        private void TestSecondLine (TrackInfo track, string format, params object [] args)
+        {
+            Assert.AreEqual (String.Format (format, args), display.GetSecondLine (track));
+        }
+    }
+}
+
+#endif
diff --git a/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj b/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
index 7df1fd9..ec6ccfc 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
+++ b/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
@@ -307,6 +307,7 @@
     <Compile Include="Banshee.Gui\IGlobalUIActions.cs" />
     <Compile Include="Banshee.Gui\PlaybackSubtitleActions.cs" />
     <Compile Include="Banshee.Collection.Gui\YearListView.cs" />
+    <Compile Include="Banshee.Gui.Widgets\Tests\TrackInfoDisplayTests.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ProjectExtensions>
@@ -325,4 +326,7 @@
       </Properties>
     </MonoDevelop>
   </ProjectExtensions>
+  <ItemGroup>
+    <Folder Include="Banshee.Gui.Widgets\Tests\" />
+  </ItemGroup>
 </Project>
diff --git a/src/Core/Banshee.ThickClient/Makefile.am b/src/Core/Banshee.ThickClient/Makefile.am
index 8e56ea8..7e56a78 100644
--- a/src/Core/Banshee.ThickClient/Makefile.am
+++ b/src/Core/Banshee.ThickClient/Makefile.am
@@ -95,6 +95,7 @@ SOURCES =  \
 	Banshee.Gui.Widgets/PlaylistMenuItem.cs \
 	Banshee.Gui.Widgets/RepeatActionButton.cs \
 	Banshee.Gui.Widgets/TaskStatusIcon.cs \
+	Banshee.Gui.Widgets/Tests/TrackInfoDisplayTests.cs \
 	Banshee.Gui.Widgets/TitledList.cs \
 	Banshee.Gui.Widgets/TrackInfoDisplay.cs \
 	Banshee.Gui.Widgets/UserJobTile.cs \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 980ce9f..ad3cd33 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ TEST_ASSEMBLIES = \
 	Banshee.Core.dll \
 	Banshee.Gnome.dll \
 	Banshee.Services.dll \
+	Banshee.ThickClient.dll \
 	Banshee.Fixup.dll \
 	Banshee.AmazonMp3.exe \
 	Banshee.Dap.Mtp.dll



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