[longomatch] Unit Test for UpdatesNotifier and fix Version Comparison bug.
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Unit Test for UpdatesNotifier and fix Version Comparison bug.
- Date: Thu, 23 Apr 2015 15:19:12 +0000 (UTC)
commit dcf4b8ff905b2aed8281a34e21ca3ce7d292de03
Author: Xavi Artigas <xartigas fluendo com>
Date: Thu Apr 16 16:28:42 2015 +0200
Unit Test for UpdatesNotifier and fix Version Comparison bug.
LongoMatch.Services/UpdatesNotifier.cs | 12 ++-----
Tests/Makefile.am | 4 ++-
Tests/Services/TestUpdatesNotifier.cs | 59 ++++++++++++++++++++++++++++++++
Tests/Services/latest-test.json | 5 +++
Tests/Tests.csproj | 1 +
5 files changed, 71 insertions(+), 10 deletions(-)
---
diff --git a/LongoMatch.Services/UpdatesNotifier.cs b/LongoMatch.Services/UpdatesNotifier.cs
index 65187d7..80f1563 100644
--- a/LongoMatch.Services/UpdatesNotifier.cs
+++ b/LongoMatch.Services/UpdatesNotifier.cs
@@ -57,18 +57,12 @@ namespace LongoMatch.Services
return true;
}
- static bool IsOutDated (Version currentVersion, Version latestVersion)
+ static public bool IsOutDated (Version currentVersion, Version latestVersion)
{
- if (latestVersion.Major > currentVersion.Major)
- return true;
- if (latestVersion.Minor > currentVersion.Minor)
- return true;
- if (latestVersion.Build > currentVersion.Build)
- return true;
- return false;
+ return latestVersion > currentVersion;
}
- static void CheckForUpdates ()
+ static public void CheckForUpdates ()
{
string tempFile = Path.Combine (Config.HomeDir, "latest.json");
if (!FetchNewVersion (Config.LatestVersionURL, tempFile))
diff --git a/Tests/Makefile.am b/Tests/Makefile.am
index 2c4455d..f9717cb 100644
--- a/Tests/Makefile.am
+++ b/Tests/Makefile.am
@@ -45,9 +45,11 @@ SOURCES = Core/Common/TestColor.cs \
Services/TestRenderingJobsManager.cs \
Services/TestServices.cs \
Services/TestTemplatesService.cs \
+ Services/TestUpdatesNotifier.cs \
Utils.cs
-RESOURCES = Core/dibujo.svg
+RESOURCES = Core/dibujo.svg \
+ Services/latest-test.json
include $(top_srcdir)/build/build.mk
diff --git a/Tests/Services/TestUpdatesNotifier.cs b/Tests/Services/TestUpdatesNotifier.cs
new file mode 100644
index 0000000..039b34a
--- /dev/null
+++ b/Tests/Services/TestUpdatesNotifier.cs
@@ -0,0 +1,59 @@
+//
+// Copyright (C) 2015 Fluendo S.A.
+//
+using System;
+using System.IO;
+using System.Reflection;
+using NUnit.Framework;
+using LongoMatch.Services;
+
+namespace Tests.Services
+{
+ [TestFixture()]
+ public class TestUpdatesNotifier
+ {
+ [Test()]
+ public void TestParser ()
+ {
+ // Extract the file from the resources
+ string tmpFile = Path.GetTempFileName ();
+ using (Stream resource = Assembly.GetExecutingAssembly ().GetManifestResourceStream
("latest-test.json")) {
+ using (Stream output = File.OpenWrite (tmpFile)) {
+ resource.CopyTo (output);
+ }
+ }
+
+ // Parse the file and check that the content is correct
+ Version latestVersion;
+ string downloadUrl;
+ string changeLog;
+ UpdatesNotifier.ParseNewVersion (tmpFile, out latestVersion, out downloadUrl, out
changeLog);
+ Assert.AreEqual (latestVersion.Major, 9);
+ Assert.AreEqual (latestVersion.Minor, 8);
+ Assert.AreEqual (latestVersion.Build, 7);
+ Assert.AreEqual (downloadUrl, "test-url.com");
+ Assert.AreEqual (changeLog, "none");
+ }
+
+ [Test()]
+ public void TestIsOutDated ()
+ {
+ Assert.IsTrue (UpdatesNotifier.IsOutDated (new Version ("1.0.2"), new Version
("1.0.3")));
+ Assert.IsTrue (UpdatesNotifier.IsOutDated (new Version ("1.0.2"), new Version
("1.1.1")));
+ Assert.IsTrue (UpdatesNotifier.IsOutDated (new Version ("1.9.2"), new Version
("2.0.1")));
+ Assert.IsTrue (UpdatesNotifier.IsOutDated (new Version ("1.0.2"), new Version
("1.1")));
+ Assert.IsTrue (UpdatesNotifier.IsOutDated (new Version ("1.0.2"), new Version
("3.0")));
+ Assert.IsTrue (UpdatesNotifier.IsOutDated (new Version ("2.1"), new Version
("3.0")));
+ Assert.IsTrue (UpdatesNotifier.IsOutDated (new Version ("1.1"), new Version
("1.2")));
+
+ Assert.IsFalse (UpdatesNotifier.IsOutDated (new Version ("1.0.3"), new Version
("1.0.2")));
+ Assert.IsFalse (UpdatesNotifier.IsOutDated (new Version ("1.1.1"), new Version
("1.0.2")));
+ Assert.IsFalse (UpdatesNotifier.IsOutDated (new Version ("2.0.1"), new Version
("1.9.2")));
+ Assert.IsFalse (UpdatesNotifier.IsOutDated (new Version ("1.1"), new Version
("1.0.2")));
+ Assert.IsFalse (UpdatesNotifier.IsOutDated (new Version ("3.0"), new Version
("1.0.2")));
+ Assert.IsFalse (UpdatesNotifier.IsOutDated (new Version ("3.0"), new Version
("2.1") ));
+ Assert.IsFalse (UpdatesNotifier.IsOutDated (new Version ("1.2"), new Version
("1.1") ));
+ }
+ }
+}
+
diff --git a/Tests/Services/latest-test.json b/Tests/Services/latest-test.json
new file mode 100644
index 0000000..598e20e
--- /dev/null
+++ b/Tests/Services/latest-test.json
@@ -0,0 +1,5 @@
+{
+ "version": "9.8.7",
+ "url": "test-url.com",
+ "changes": "none"
+}
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 0037f2e..c4adb0a 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -86,6 +86,7 @@
<Compile Include="Core\Store\TestActionLink.cs" />
<Compile Include="Core\Store\Templates\TestDashboard.cs" />
<Compile Include="Services\TestServices.cs" />
+ <Compile Include="Services\TestUpdatesNotifier.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LongoMatch.Core\LongoMatch.Core.csproj">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]