[f-spot] Fix extension detection for files without extension.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot] Fix extension detection for files without extension.
- Date: Sat, 29 May 2010 12:43:00 +0000 (UTC)
commit 5a5310884097c9541dafa25606a1d0e3dca6a5bc
Author: Ruben Vermeersch <ruben savanne be>
Date: Sat May 29 14:39:21 2010 +0200
Fix extension detection for files without extension.
Also added a unit test to test these scenarios.
https://bugzilla.gnome.org/show_bug.cgi?id=619968
src/Core/SafeUriExtensions.cs | 4 ++-
tests/src/Makefile.am | 1 +
tests/src/SafeUriTest.cs | 75 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 79 insertions(+), 1 deletions(-)
---
diff --git a/src/Core/SafeUriExtensions.cs b/src/Core/SafeUriExtensions.cs
index 5d382b3..bdc27cb 100644
--- a/src/Core/SafeUriExtensions.cs
+++ b/src/Core/SafeUriExtensions.cs
@@ -1,4 +1,5 @@
using Hyena;
+using System;
namespace FSpot
{
@@ -24,7 +25,8 @@ namespace FSpot
public static string GetExtension (this SafeUri uri)
{
var abs_uri = uri.AbsoluteUri;
- return abs_uri.Substring (abs_uri.LastIndexOf ('.'));
+ var index = abs_uri.LastIndexOf ('.');
+ return index == -1 ? String.Empty : abs_uri.Substring (index);
}
public static string GetFilenameWithoutExtension (this SafeUri uri)
diff --git a/tests/src/Makefile.am b/tests/src/Makefile.am
index 257803f..9097c5e 100644
--- a/tests/src/Makefile.am
+++ b/tests/src/Makefile.am
@@ -1,6 +1,7 @@
include $(top_srcdir)/Makefile.include
SOURCES = \
+ $(srcdir)/SafeUriTest.cs \
$(srcdir)/ImageTest.cs \
$(srcdir)/Query/LogicalTerm.cs \
$(srcdir)/Cms/Cms.cs
diff --git a/tests/src/SafeUriTest.cs b/tests/src/SafeUriTest.cs
new file mode 100644
index 0000000..3abf656
--- /dev/null
+++ b/tests/src/SafeUriTest.cs
@@ -0,0 +1,75 @@
+using NUnit.Framework;
+using System;
+using Hyena;
+using FSpot;
+
+namespace FSpot.Tests
+{
+ [TestFixture]
+ public class SafeUriTests
+ {
+ static SafeUriTest[] tests = new SafeUriTest[] {
+ new SafeUriTest () {
+ Uri = "https://bugzilla.gnome.org/process_bug.cgi",
+ IsURI = true,
+ AbsoluteUri = "https://bugzilla.gnome.org/process_bug.cgi",
+ Extension = ".cgi",
+ BaseUri = "https://bugzilla.gnome.org",
+ Filename = "process_bug.cgi",
+ FilenameWithoutExtension = "process_bug"
+
+ },
+ new SafeUriTest () {
+ Uri = "file:///home/ruben/Desktop/F-Spot Vision.pdf",
+ IsURI = true,
+ AbsoluteUri = "file:///home/ruben/Desktop/F-Spot Vision.pdf",
+ Extension = ".pdf",
+ BaseUri = "file:///home/ruben/Desktop",
+ Filename = "F-Spot Vision.pdf",
+ FilenameWithoutExtension = "F-Spot Vision"
+ },
+ new SafeUriTest () {
+ Uri = "/home/ruben/Projects/f-spot/",
+ IsURI = false,
+ AbsoluteUri = "file:///home/ruben/Projects/f-spot/",
+ Extension = "",
+ BaseUri = "file:///home/ruben/Projects/f-spot",
+ Filename = "",
+ FilenameWithoutExtension = ""
+ },
+ new SafeUriTest () {
+ Uri = "/home/ruben/Projects/f-spot/README",
+ IsURI = false,
+ AbsoluteUri = "file:///home/ruben/Projects/f-spot/README",
+ Extension = "",
+ BaseUri = "file:///home/ruben/Projects/f-spot",
+ Filename = "README",
+ FilenameWithoutExtension = "README"
+ }
+ };
+
+ [Test]
+ public void TestFileUris ()
+ {
+ foreach (var test in tests) {
+ var suri = new SafeUri (test.Uri, test.IsURI);
+ Assert.AreEqual (suri.AbsoluteUri, test.AbsoluteUri, String.Format("AbsoluteUri for {0}", test.Uri));
+ Assert.AreEqual (suri.GetExtension (), test.Extension, String.Format("Extension for {0}", test.Uri));
+ Assert.AreEqual (suri.GetBaseUri ().ToString (), test.BaseUri, String.Format("BaseUri for {0}", test.Uri));
+ Assert.AreEqual (suri.GetFilename (), test.Filename, String.Format("Filename for {0}", test.Uri));
+ Assert.AreEqual (suri.GetFilenameWithoutExtension (), test.FilenameWithoutExtension, String.Format("FilenameWithoutExtension for {0}", test.Uri));
+ }
+ }
+ }
+
+ internal class SafeUriTest
+ {
+ public string Uri { get; set; }
+ public bool IsURI { get; set; }
+ public string AbsoluteUri { get; set; }
+ public string Extension { get; set; }
+ public string BaseUri { get; set; }
+ public string Filename { get; set; }
+ public string FilenameWithoutExtension { get; set; }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]