banshee r3630 - in trunk/banshee: . src/Libraries/Hyena/Hyena.Query tests tests/Hyena



Author: gburt
Date: Tue Apr  1 00:26:52 2008
New Revision: 3630
URL: http://svn.gnome.org/viewvc/banshee?rev=3630&view=rev

Log:
2008-03-31  Gabriel Burt  <gabriel burt gmail com>

	* src/Libraries/Hyena/Hyena.Query/DateQueryValue.cs:
	* src/Libraries/Hyena/Hyena.Query/IntegerQueryValue.cs:
	* src/Libraries/Hyena/Hyena.Query/RelativeTimeSpanQueryValue.cs:
	* src/Libraries/Hyena/Hyena.Query/TimeSpanQueryValue.cs: Pass
	InvariantCulture in ToString calls, though probably not too necessary for
	ints and strings.

	* tests/Makefile.am:
	* tests/Hyena/QueryTests.cs: New tests for query parsing etc.
	Currently failing to round trip a couple user queries.


Added:
   trunk/banshee/tests/Hyena/QueryTests.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Libraries/Hyena/Hyena.Query/DateQueryValue.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Query/IntegerQueryValue.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Query/RelativeTimeSpanQueryValue.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Query/TimeSpanQueryValue.cs
   trunk/banshee/tests/Makefile.am

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Query/DateQueryValue.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Query/DateQueryValue.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Query/DateQueryValue.cs	Tue Apr  1 00:26:52 2008
@@ -108,7 +108,7 @@
 
         public override string ToSql ()
         {
-            return DateTimeUtil.FromDateTime (value).ToString ();
+            return DateTimeUtil.FromDateTime (value).ToString (System.Globalization.CultureInfo.InvariantCulture);
         }
 
         public DateTime DateTime {

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Query/IntegerQueryValue.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Query/IntegerQueryValue.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Query/IntegerQueryValue.cs	Tue Apr  1 00:26:52 2008
@@ -97,7 +97,7 @@
 
         public override string ToSql ()
         {
-            return Convert.ToString (value);
+            return Convert.ToString (value, System.Globalization.CultureInfo.InvariantCulture);
         }
     }
 }

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Query/RelativeTimeSpanQueryValue.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Query/RelativeTimeSpanQueryValue.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Query/RelativeTimeSpanQueryValue.cs	Tue Apr  1 00:26:52 2008
@@ -72,7 +72,7 @@
 
         public override string ToSql ()
         {
-            return DateTimeUtil.FromDateTime (DateTime.Now + TimeSpan.FromSeconds ((double) offset)).ToString ();
+            return DateTimeUtil.FromDateTime (DateTime.Now + TimeSpan.FromSeconds ((double) offset)).ToString (System.Globalization.CultureInfo.InvariantCulture);
         }
 
         protected override string FactorString (TimeFactor factor, int count)

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Query/TimeSpanQueryValue.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Query/TimeSpanQueryValue.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Query/TimeSpanQueryValue.cs	Tue Apr  1 00:26:52 2008
@@ -150,7 +150,7 @@
 
         public override string ToSql ()
         {
-            return Convert.ToString (offset * 1000);
+            return Convert.ToString (offset * 1000, System.Globalization.CultureInfo.InvariantCulture);
         }
 
         protected virtual string FactorString (TimeFactor factor, int count)

Added: trunk/banshee/tests/Hyena/QueryTests.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/tests/Hyena/QueryTests.cs	Tue Apr  1 00:26:52 2008
@@ -0,0 +1,97 @@
+using System;
+using System.Reflection;
+using NUnit.Framework;
+
+using Hyena.Query;
+using Banshee.Query;
+
+[TestFixture]
+public class QueryTests
+{
+    [Test]
+    public void TestQueryValueSql ()
+    {
+        QueryValue qv;
+        
+        qv = new DateQueryValue (); qv.ParseUserQuery ("2007-03-9");
+        Assert.AreEqual (new DateTime (2007, 3, 9), qv.Value);
+        Assert.AreEqual ("2007-03-09", qv.ToUserQuery ());
+        Assert.AreEqual ("1173420000", qv.ToSql ());
+
+        qv = new StringQueryValue (); qv.ParseUserQuery ("foo 'bar'");
+        Assert.AreEqual ("foo 'bar'", qv.Value);
+        Assert.AreEqual ("foo 'bar'", qv.ToUserQuery ());
+        Assert.AreEqual ("foo ''bar''", qv.ToSql ());
+
+        qv = new IntegerQueryValue (); qv.ParseUserQuery ("22");
+        Assert.AreEqual (22, qv.Value);
+        Assert.AreEqual ("22", qv.ToUserQuery ());
+        Assert.AreEqual ("22", qv.ToSql ());
+
+        qv = new FileSizeQueryValue (); qv.ParseUserQuery ("2048 KB");
+        Assert.AreEqual (2097152, qv.Value);
+        Assert.AreEqual ("2048 KB", qv.ToUserQuery ());
+        Assert.AreEqual ("2097152", qv.ToSql ());
+
+        // TODO this will break once an it_IT translation for "days ago" etc is committed
+        qv = new RelativeTimeSpanQueryValue (); qv.ParseUserQuery ("2 days ago");
+        Assert.AreEqual (-172800, qv.Value);
+        Assert.AreEqual ("2 days ago", qv.ToUserQuery ());
+
+        // TODO this will break once an it_IT translation for "minutes" etc is committed
+        qv = new TimeSpanQueryValue (); qv.ParseUserQuery ("4 minutes");
+        Assert.AreEqual (240, qv.Value);
+        Assert.AreEqual ("4 minutes", qv.ToUserQuery ());
+        Assert.AreEqual ("240000", qv.ToSql ());
+    }
+
+    [Test]
+    public void TestQueryParsing ()
+    {
+        string [] tests = new string [] {
+            "foo",
+            "foo bar",
+            "foo -bar",
+            "-foo -bar",
+            "-(foo bar)",
+            "-(foo or bar)",
+            "-(foo (-bar or baz))",
+            "-(foo (-bar or -baz))",
+            "artist:foo",
+            "-artist:foo",
+            "-artist!=foo",
+            "duration>\"2 minutes\"",
+            "rating>3",
+            "-rating>3",
+            "artist:baz -album:bar",
+            "artist:baz -album:bar",
+            "artist:baz (rating>3 or rating<2)",
+        };
+
+        AssertForEach<string> (tests, UserQueryParsesAndGenerates);
+    }
+
+    public delegate void TestRunner<T> (T item);
+    public static void AssertForEach<T> (System.Collections.Generic.IEnumerable<T> objects, TestRunner<T> runner)
+    {
+        System.Text.StringBuilder sb = new System.Text.StringBuilder ();
+        foreach (T o in objects) {
+            try { runner (o); }
+            catch (Exception e) { sb.AppendFormat ("{0}\n", e.Message); }
+        }
+
+        if (sb.Length > 0)
+            Assert.Fail (sb.ToString ());
+    }
+
+    private static void UserQueryParsesAndGenerates (string query)
+    {
+        QueryNode node = UserQueryParser.Parse (query, BansheeQuery.FieldSet);
+        if (query == null || query.Trim () == String.Empty) {
+            Assert.AreEqual (node, null); 
+            return;
+        }
+
+        Assert.AreEqual (query, node.ToUserQuery ());
+    }
+}

Modified: trunk/banshee/tests/Makefile.am
==============================================================================
--- trunk/banshee/tests/Makefile.am	(original)
+++ trunk/banshee/tests/Makefile.am	Tue Apr  1 00:26:52 2008
@@ -9,7 +9,8 @@
 	$(srcdir)/Hyena/CryptoUtilTests.cs \
 	$(srcdir)/Hyena/RangeCollectionTests.cs \
 	$(srcdir)/Hyena/StringUtilTests.cs \
-	$(srcdir)/Hyena/SqliteCommandTests.cs
+	$(srcdir)/Hyena/SqliteCommandTests.cs \
+	$(srcdir)/Hyena/QueryTests.cs
 
 #	Banshee.Core/KernelTests.cs
 #	Banshee.Core/FileNamePatternTests.cs
@@ -23,7 +24,7 @@
 	ConsoleUi.cs
 
 $(ASSEMBLY): $(ASSEMBLY_CSFILES)
-	$(MCS) $(MCS_FLAGS) $(NUNIT_FLAGS) -out:$@ -target:library -r:System.Xml $(LINK_HYENA_DEPS) $(ASSEMBLY_CSFILES)
+	$(MCS) $(MCS_FLAGS) $(NUNIT_FLAGS) -out:$@ -target:library -r:System.Xml $(LINK_HYENA_DEPS) $(LINK_BANSHEE_THICKCLIENT_DEPS) $(ASSEMBLY_CSFILES)
 
 $(NUNIT_TESTER): $(NUNIT_TESTER_CSFILES)
 	$(MCS) $(MCS_FLAGS) -out:$@ $(NUNIT_FLAGS) $(NUNIT_TESTER_CSFILES)



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