[tracker] functional-tests: collation tests



commit 542d9239438bdb4c44cfb4581d7051e7010a9993
Author: Ivan Frade <ivan frade nokia com>
Date:   Thu Sep 23 16:55:18 2010 +0300

    functional-tests: collation tests

 tests/functional-tests/16-collation.py |  120 ++++++++++++++++++++++++++++++++
 tests/functional-tests/Makefile.am     |    1 +
 2 files changed, 121 insertions(+), 0 deletions(-)
---
diff --git a/tests/functional-tests/16-collation.py b/tests/functional-tests/16-collation.py
new file mode 100755
index 0000000..900c0f9
--- /dev/null
+++ b/tests/functional-tests/16-collation.py
@@ -0,0 +1,120 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+#
+# Copyright (C) 2010, Nokia <ivan frade nokia com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+
+"""
+Stand-alone tests cases for the store, checking the collation is working
+"""
+import time
+import random
+
+from common.utils import configuration as cfg
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+
+class TrackerStoreCollationTests (CommonTrackerStoreTest):
+    """
+    Insert few instances with a text field containing collation-problematic words.
+    Ask for those instances order by the field and check the results.
+    """
+    def setUp (self):
+        """
+        Each test append to this list the used URIS, so they can be removed
+        in the tearDown
+        """
+        self.clean_up_instances = []
+
+    def tearDown (self):
+        for uri in self.clean_up_instances:
+            self.tracker.update ("DELETE { <%s> a rdfs:Resource. }" % (uri))
+        self.clean_up_instances = []
+        time.sleep (1)
+
+    def __insert_text (self, text):
+        uri = "test://collation-01-%d" % (random.randint (1, 1000))
+        self.clean_up_instances.append (uri)
+        
+        self.tracker.update ("""
+        INSERT {
+            <%s> a nie:InformationElement ;
+                nie:title "%s" ;
+                nie:description "tracker-collation-test-instance" .
+        }
+         """ % (uri, text))
+
+    def __get_text_sorted_by_collation (self):
+        return self.tracker.query ("""
+         SELECT ?title WHERE {
+            ?u a nie:InformationElement ;
+               nie:title ?title ;
+               nie:description 'tracker-collation-test-instance' .
+         } ORDER BY ?title
+        """)
+
+    def __collation_test (self, input_list, expected_list):
+
+        for i in input_list:
+            self.__insert_text (i)
+
+        results = [unicode(r[0]) for r in self.__get_text_sorted_by_collation ()]
+        self.assertEquals (len (results), len (expected_list))
+        
+        for r in range (0, len (results)):
+            self.assertEquals (results[r], expected_list [r],
+                               "Error:\nExpected : *** %s\nResult   : *** %s" % (expected_list, results))
+
+    def test_collation_01 (self):
+        """
+        Behaves as case-insensitive
+        """
+        input_dt = ["abb", "bb",  "Abc", "Ba"]
+        expected = ["abb", "Abc", "Ba",  "bb"]
+        self.__collation_test (input_dt, expected)
+
+    def test_collation_02 (self):
+        """
+        In conflict, Capital letters go *after* small letters
+        """
+        input_dt = ["Bb", "bb", "aa", "Aa"]
+        expected = ["aa", "Aa", "bb", "Bb"]
+        self.__collation_test (input_dt, expected)
+
+    def test_collation_03 (self):
+        """
+        Example from the unicode spec
+        http://www.unicode.org/reports/tr10/#Main_Algorithm
+        """
+        input_dt = ["Cab", "cab", "dab", "cáb"]
+        expected = ["cab", "Cab", u"cáb", "dab"]
+        self.__collation_test (input_dt, expected)
+
+    def test_collation_04 (self):
+        """
+        Spanish test in english locale
+        """
+        input_dt = ["ä", "ö", "a", "e", "i", "o", "u"]
+        expected = ["a", "ä", "e", "i", "o", "u", "ü"]
+        self.__collation_test (input_dt, expected)
+
+if __name__ == "__main__":
+    ut.main ()
+
+    
diff --git a/tests/functional-tests/Makefile.am b/tests/functional-tests/Makefile.am
index a44a4be..4c9d371 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -37,6 +37,7 @@ standard_tests +=			\
 	09-concurrent-query.py		\
 	14-signals.py			\
 	15-statistics.py		\
+	16-collation.py			\
 	200-backup-restore.py		\
 	300-miner-basic-ops.py
 if HAVE_TRACKER_FTS



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