示例#1
0
        /// @tests java.text.CollationKey#toByteArray()
        // FIXME This test fails on Harmony ClassLibrary
        public void Failing_test_toByteArray()
        {
            // Test for method byte [] java.text.CollationKey.toByteArray()
            Collator collator = ILOG.J2CsMapping.Text.Collator.GetInstance();

            collator.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY);
            CollationKey key1 = collator.GetCollationKey("abc");

            byte[] bytes = key1.ToByteArray();
            NUnit.Framework.Assert.IsTrue(bytes.Length >= 3, "Not enough bytes");

            try {
                collator = new RuleBasedCollator("= 1 , 2 ; 3 , 4 < 5 ; 6 , 7");
            } catch (ParseException e) {
                NUnit.Framework.Assert.Fail("ParseException");
                return;
            }
            bytes = collator.GetCollationKey("1234567").ToByteArray();

            /*
             * CollationElementIterator it =
             * ((RuleBasedCollator)collator).getCollationElementIterator("1234567");
             * int order; while ((order = it.next()) !=
             * CollationElementIterator.NULLORDER) {
             * System.out.println(Integer.toHexString(order)); } for (int i=0;
             * i<bytes.length; i+=2) {
             * System.out.print(Integer.toHexString(bytes[i]) +
             * Integer.toHexString(bytes[i+1]) + " "); } System.out.println();
             */
            byte[] result = new byte[] { 0, 2, 0, 2, 0, 2, 0, 0, 0, 3, 0, 3, 0, 1,
                                         0, 2, 0, 2, 0, 0, 0, 4, 0, 4, 0, 1, 0, 1, 0, 2 };
            // Failed in java too : NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(bytes,result),"Wrong bytes");
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testInitVars() throws Exception
        public virtual void testInitVars()
        {
            CollationKey sortKey = collator.getCollationKey(firstRangeBeginningOriginal);

            sbyte[]  data = sortKey.toByteArray();
            BytesRef r    = new BytesRef(data);
        }
示例#3
0
        public void Test_hashCode()
        {
            Collator collator = ILOG.J2CsMapping.Text.Collator.GetInstance();

            collator.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY);
            CollationKey key1 = collator.GetCollationKey("abc");
            CollationKey key2 = collator.GetCollationKey("ABC");

            NUnit.Framework.Assert.IsTrue(key1.GetHashCode() == key2.GetHashCode(), "Should be equal");
        }
示例#4
0
        public void Test_compareToLjava_text_CollationKey()
        {
            Collator collator = ILOG.J2CsMapping.Text.Collator.GetInstance();

            collator.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY);
            CollationKey key1 = collator.GetCollationKey("abc");
            CollationKey key2 = collator.GetCollationKey("ABC");

            NUnit.Framework.Assert.AreEqual(0, key1.CompareTo(key2), "Should be equal");
        }
示例#5
0
        public void Test_equalsLjava_lang_Object()
        {
            Collator collator = ILOG.J2CsMapping.Text.Collator.GetInstance();

            collator.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY);
            CollationKey key1 = collator.GetCollationKey("abc");
            CollationKey key2 = collator.GetCollationKey("ABC");

            NUnit.Framework.Assert.IsTrue(key1.Equals(key2), "Should be equal");
        }
示例#6
0
 private void Report(String localeName, String string1, CollationKey k1, CollationKey k2)
 {
     if (!k1.Equals(k2))
     {
         StringBuilder msg = new StringBuilder();
         msg.Append("With ").Append(localeName).Append(" collator\n and input string: ").Append(string1).Append('\n');
         msg.Append(" failed to produce identical keys on both collators\n");
         msg.Append("  localeCollator key: ").Append(CollationTest.Prettify(k1)).Append('\n');
         msg.Append("  ruleCollator   key: ").Append(CollationTest.Prettify(k2)).Append('\n');
         Errln(msg.ToString());
     }
 }
示例#7
0
        public void Test_compareToLjava_lang_Object()
        {
            // Test for method int
            // java.text.CollationKey.compareTo(java.lang.Object)
            Collator collator = ILOG.J2CsMapping.Text.Collator.GetInstance();

            collator.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY);
            CollationKey key1 = collator.GetCollationKey("abc");
            CollationKey key2 = collator.GetCollationKey("ABC");

            NUnit.Framework.Assert.AreEqual(0, key1.CompareTo(key2), "Should be equal");
        }
        public void TestCollationKey()
        {
            Collator     coll = ILOG.J2CsMapping.Text.Collator.GetInstance(Locale.US);
            String       text = "abc";
            CollationKey key  = coll.GetCollationKey(text);

            key.GetHashCode();

            CollationKey key2 = coll.GetCollationKey("abc");

            NUnit.Framework.Assert.AreEqual(0, key.CompareTo(key2));
        }
        /// <summary>
        /// Compare this RuleBasedCollationKey to target. The collation rules of the
        /// Collator object which created these keys are applied. <strong>Note:</strong>
        /// RuleBasedCollationKeys created by different Collators can not be compared. </summary>
        /// <param name="target"> target RuleBasedCollationKey </param>
        /// <returns> Returns an integer value. Value is less than zero if this is less
        /// than target, value is zero if this and target are equal and value is greater than
        /// zero if this is greater than target. </returns>
        /// <seealso cref= java.text.Collator#compare </seealso>
        public override int CompareTo(CollationKey target)
        {
            int result = Key.CompareTo(((RuleBasedCollationKey)(target)).Key);

            if (result <= Collator.LESS)
            {
                return(Collator.LESS);
            }
            else if (result >= Collator.GREATER)
            {
                return(Collator.GREATER);
            }
            return(Collator.EQUAL);
        }
        public void TestGetCollationKey()
        {
            RuleBasedCollator coll = (RuleBasedCollator)ILOG.J2CsMapping.Text.Collator
                                     .GetInstance(Locale.GERMAN);
            String       source = "abc";
            CollationKey key1   = coll.GetCollationKey(source);

            NUnit.Framework.Assert.AreEqual(source, key1.GetSourceString());
            String       source2 = "abb";
            CollationKey key2    = coll.GetCollationKey(source2);

            NUnit.Framework.Assert.AreEqual(source2, key2.GetSourceString());
            NUnit.Framework.Assert.IsTrue(key1.CompareTo(key2) > 0);
            NUnit.Framework.Assert.IsTrue(coll.Compare(source, source2) > 0);
        }
        public void Test_getCollationKeyLjava_lang_String()
        {
            // Regression test for HARMONY-28
            String            source = null;
            RuleBasedCollator rbc    = null;

            try
            {
                String Simple = "< a< b< c< d";
                rbc = new RuleBasedCollator(Simple);
            }
            catch (ParseException e)
            {
                NUnit.Framework.Assert.Fail("Assert 0: Unexpected format exception " + e);
            }
            CollationKey ck = rbc.GetCollationKey(source);

            NUnit.Framework.Assert.IsNull(ck, "Assert 1: getCollationKey (null) does not return null");
        }
示例#12
0
        public void TestContinuationReordering()
        {
            String rule = "&0x2f00 << 0x2f01";

            try
            {
                RuleBasedCollator collator = new RuleBasedCollator(rule);
                collator.IsFrenchCollation = (true);
                CollationKey key1
                    = collator.GetCollationKey("a\u0325\u2f00\u2f01b\u0325");
                CollationKey key2
                    = collator.GetCollationKey("a\u0325\u2f01\u2f01b\u0325");
                if (key1.CompareTo(key2) >= 0)
                {
                    Errln("Error comparing continuation strings");
                }
            }
            catch (Exception e)
            {
                Errln(e.ToString());
            }
        }
示例#13
0
        private void ReportCResult(String source, String target, CollationKey sourceKey, CollationKey targetKey,
                                   int compareResult, int keyResult, int incResult, int expectedResult)
        {
            if (expectedResult < -1 || expectedResult > 1)
            {
                Errln("***** invalid call to reportCResult ****");
                return;
            }

            bool ok1 = (compareResult == expectedResult);
            bool ok2 = (keyResult == expectedResult);
            bool ok3 = (incResult == expectedResult);

            if (ok1 && ok2 && ok3 && !IsVerbose())
            {
                return;
            }
            else
            {
                String msg1 = ok1 ? "Ok: compare(\"" : "FAIL: compare(\"";
                String msg2 = "\", \"";
                String msg3 = "\") returned ";
                String msg4 = "; expected ";

                String sExpect = "";
                String sResult = "";
                sResult = CollationTest.AppendCompareResult(compareResult, sResult);
                sExpect = CollationTest.AppendCompareResult(expectedResult, sExpect);
                if (ok1)
                {
                    Logln(msg1 + source + msg2 + target + msg3 + sResult);
                }
                else
                {
                    Errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
                }

                msg1    = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
                msg2    = "\").compareTo(key(\"";
                msg3    = "\")) returned ";
                sResult = CollationTest.AppendCompareResult(keyResult, sResult);
                if (ok2)
                {
                    Logln(msg1 + source + msg2 + target + msg3 + sResult);
                }
                else
                {
                    Errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
                    msg1 = "  ";
                    msg2 = " vs. ";
                    Errln(msg1 + CollationTest.Prettify(sourceKey) + msg2 + CollationTest.Prettify(targetKey));
                }

                msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
                msg2 = "\", \"";
                msg3 = "\") returned ";

                sResult = CollationTest.AppendCompareResult(incResult, sResult);

                if (ok3)
                {
                    Logln(msg1 + source + msg2 + target + msg3 + sResult);
                }
                else
                {
                    Errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
                }
            }
        }
示例#14
0
        public void TestVariableTop()
        {
            /*
             * Starting with ICU 53, setting the variable top via a pseudo relation string
             * is not supported any more.
             * It was replaced by the [maxVariable symbol] setting.
             * See ICU tickets #9958 and #8032.
             */
            if (!SUPPORT_VARIABLE_TOP_RELATION)
            {
                return;
            }
            String   rule = "&z = [variable top]";
            Collator myColl;
            Collator enColl;

            char[] source = new char[1];
            char   ch;

            int[] expected = { 0 };

            try
            {
                enColl = Collator.GetInstance(new CultureInfo("en") /* Locale.ENGLISH */);
            }
            catch (Exception e)
            {
                Errln("ERROR: Failed to create the collator for ENGLISH");
                return;
            }

            try
            {
                myColl = new RuleBasedCollator(rule);
            }
            catch (Exception e)
            {
                Errln("Fail to create RuleBasedCollator with rules:" + rule);
                return;
            }
            enColl.Strength = (Collator.PRIMARY);
            myColl.Strength = (Collator.PRIMARY);

            ((RuleBasedCollator)enColl).IsAlternateHandlingShifted = (true);
            ((RuleBasedCollator)myColl).IsAlternateHandlingShifted = (true);

            if (((RuleBasedCollator)enColl).IsAlternateHandlingShifted != true)
            {
                Errln("ERROR: ALTERNATE_HANDLING value can not be set to SHIFTED\n");
            }

            // space is supposed to be a variable
            CollationKey key = enColl.GetCollationKey(" ");

            byte[] result = key.ToByteArray();

            for (int i = 0; i < result.Length; i++)
            {
                if (result[i] != expected[i])
                {
                    Errln("ERROR: SHIFTED alternate does not return 0 for primary of space\n");
                    break;
                }
            }

            ch = 'a';
            while (ch < 'z')
            {
                source[0] = ch;
                key       = myColl.GetCollationKey(new String(source));
                result    = key.ToByteArray();

                for (int i = 0; i < result.Length; i++)
                {
                    if (result[i] != expected[i])
                    {
                        Errln("ERROR: SHIFTED alternate does not return 0 for primary of space\n");
                        break;
                    }
                }
                ch++;
            }
        }
示例#15
0
        public void TestSurrogates()
        {
            String rules = "&z<'\ud800\udc00'<'\ud800\udc0a\u0308'<A";

            String[] source = { "z",
                                "\uD800\uDC00",
                                "\ud800\udc0a\u0308",
                                "\ud800\udc02" };

            String[] target = { "\uD800\uDC00",
                                "\ud800\udc0a\u0308",
                                "A",
                                "\ud800\udc03" };

            // this test is to verify the supplementary sort key order in the english
            // collator
            Collator enCollation;

            try
            {
                enCollation = Collator.GetInstance(new CultureInfo("en") /* Locale.ENGLISH */);
            }
            catch (Exception e)
            {
                Errln("ERROR: Failed to create the collator for ENGLISH");
                return;
            }

            myCollation.Strength = (Collator.TERTIARY);
            int count = 0;

            // logln("start of english collation supplementary characters test\n");
            while (count < 2)
            {
                DoTest(enCollation, source[count], target[count], -1);
                count++;
            }
            DoTest(enCollation, source[count], target[count], 1);

            // logln("start of tailored collation supplementary characters test\n");
            count = 0;
            Collator newCollation;

            try
            {
                newCollation = new RuleBasedCollator(rules);
            }
            catch (Exception e)
            {
                Errln("ERROR: Failed to create the collator for rules");
                return;
            }

            // tests getting collation elements for surrogates for tailored rules
            while (count < 4)
            {
                DoTest(newCollation, source[count], target[count], -1);
                count++;
            }

            // tests that \uD801\uDC01 still has the same value, not changed
            CollationKey enKey     = enCollation.GetCollationKey(source[3]);
            CollationKey newKey    = newCollation.GetCollationKey(source[3]);
            int          keyResult = enKey.CompareTo(newKey);

            if (keyResult != 0)
            {
                Errln("Failed : non-tailored supplementary characters should have the same value\n");
            }
        }
示例#16
0
        public void TestCurrency()
        {
            // All the currency symbols, in collation order
            char[][] currency =
            {
                new char[] { (char)0x00A4 },    /*00A4; L; [14 36, 03, 03]    # [082B.0020.0002] # CURRENCY SIGN*/
                new char[] { (char)0x00A2 },    /*00A2; L; [14 38, 03, 03]    # [082C.0020.0002] # CENT SIGN*/
                new char[] { (char)0xFFE0 },    /*FFE0; L; [14 38, 03, 05]    # [082C.0020.0003] # FULLWIDTH CENT SIGN*/
                new char[] { (char)0x0024 },    /*0024; L; [14 3A, 03, 03]    # [082D.0020.0002] # DOLLAR SIGN*/
                new char[] { (char)0xFF04 },    /*FF04; L; [14 3A, 03, 05]    # [082D.0020.0003] # FULLWIDTH DOLLAR SIGN*/
                new char[] { (char)0xFE69 },    /*FE69; L; [14 3A, 03, 1D]    # [082D.0020.000F] # SMALL DOLLAR SIGN*/
                new char[] { (char)0x00A3 },    /*00A3; L; [14 3C, 03, 03]    # [082E.0020.0002] # POUND SIGN*/
                new char[] { (char)0xFFE1 },    /*FFE1; L; [14 3C, 03, 05]    # [082E.0020.0003] # FULLWIDTH POUND SIGN*/
                new char[] { (char)0x00A5 },    /*00A5; L; [14 3E, 03, 03]    # [082F.0020.0002] # YEN SIGN*/
                new char[] { (char)0xFFE5 },    /*FFE5; L; [14 3E, 03, 05]    # [082F.0020.0003] # FULLWIDTH YEN SIGN*/
                new char[] { (char)0x09F2 },    /*09F2; L; [14 40, 03, 03]    # [0830.0020.0002] # BENGALI RUPEE MARK*/
                new char[] { (char)0x09F3 },    /*09F3; L; [14 42, 03, 03]    # [0831.0020.0002] # BENGALI RUPEE SIGN*/
                new char[] { (char)0x0E3F },    /*0E3F; L; [14 44, 03, 03]    # [0832.0020.0002] # THAI CURRENCY SYMBOL BAHT*/
                new char[] { (char)0x17DB },    /*17DB; L; [14 46, 03, 03]    # [0833.0020.0002] # KHMER CURRENCY SYMBOL RIEL*/
                new char[] { (char)0x20A0 },    /*20A0; L; [14 48, 03, 03]    # [0834.0020.0002] # EURO-CURRENCY SIGN*/
                new char[] { (char)0x20A1 },    /*20A1; L; [14 4A, 03, 03]    # [0835.0020.0002] # COLON SIGN*/
                new char[] { (char)0x20A2 },    /*20A2; L; [14 4C, 03, 03]    # [0836.0020.0002] # CRUZEIRO SIGN*/
                new char[] { (char)0x20A3 },    /*20A3; L; [14 4E, 03, 03]    # [0837.0020.0002] # FRENCH FRANC SIGN*/
                new char[] { (char)0x20A4 },    /*20A4; L; [14 50, 03, 03]    # [0838.0020.0002] # LIRA SIGN*/
                new char[] { (char)0x20A5 },    /*20A5; L; [14 52, 03, 03]    # [0839.0020.0002] # MILL SIGN*/
                new char[] { (char)0x20A6 },    /*20A6; L; [14 54, 03, 03]    # [083A.0020.0002] # NAIRA SIGN*/
                new char[] { (char)0x20A7 },    /*20A7; L; [14 56, 03, 03]    # [083B.0020.0002] # PESETA SIGN*/
                new char[] { (char)0x20A9 },    /*20A9; L; [14 58, 03, 03]    # [083C.0020.0002] # WON SIGN*/
                new char[] { (char)0xFFE6 },    /*FFE6; L; [14 58, 03, 05]    # [083C.0020.0003] # FULLWIDTH WON SIGN*/
                new char[] { (char)0x20AA },    /*20AA; L; [14 5A, 03, 03]    # [083D.0020.0002] # NEW SHEQEL SIGN*/
                new char[] { (char)0x20AB },    /*20AB; L; [14 5C, 03, 03]    # [083E.0020.0002] # DONG SIGN*/
                new char[] { (char)0x20AC },    /*20AC; L; [14 5E, 03, 03]    # [083F.0020.0002] # EURO SIGN*/
                new char[] { (char)0x20AD },    /*20AD; L; [14 60, 03, 03]    # [0840.0020.0002] # KIP SIGN*/
                new char[] { (char)0x20AE },    /*20AE; L; [14 62, 03, 03]    # [0841.0020.0002] # TUGRIK SIGN*/
                new char[] { (char)0x20AF }     /*20AF; L; [14 64, 03, 03]    # [0842.0020.0002] # DRACHMA SIGN*/
            };

            int i, j;
            int expectedResult  = 0;
            RuleBasedCollator c = (RuleBasedCollator)Collator.GetInstance(new CultureInfo("en") /*Locale.ENGLISH*/);

            // Compare each currency symbol against all the
            // currency symbols, including itself
            String source;
            String target;

            for (i = 0; i < currency.Length; i += 1)
            {
                for (j = 0; j < currency.Length; j += 1)
                {
                    source = new String(currency[i]);
                    target = new String(currency[j]);

                    if (i < j)
                    {
                        expectedResult = -1;
                    }
                    else if (i == j)
                    {
                        expectedResult = 0;
                    }
                    else
                    {
                        expectedResult = 1;
                    }

                    int          compareResult = c.Compare(source, target);
                    CollationKey sourceKey     = null;

                    sourceKey = c.GetCollationKey(source);

                    if (sourceKey == null)
                    {
                        Errln("Couldn't get collationKey for source");
                        continue;
                    }

                    CollationKey targetKey = null;
                    targetKey = c.GetCollationKey(target);
                    if (targetKey == null)
                    {
                        Errln("Couldn't get collationKey for source");
                        continue;
                    }

                    int keyResult = sourceKey.CompareTo(targetKey);

                    ReportCResult(source, target, sourceKey, targetKey, compareResult, keyResult, compareResult, expectedResult);
                }
            }
        }