示例#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");
        }
示例#2
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++;
            }
        }