Ejemplo n.º 1
0
        public void TestPreviousNext()
        {
            // src and expect strings
            char[] src =
            {
                UTF16.GetLeadSurrogate(0x2f999), UTF16.GetTrailSurrogate(0x2f999),
                UTF16.GetLeadSurrogate(0x1d15f), UTF16.GetTrailSurrogate(0x1d15f),
                (char)0xc4,
                (char)0x1ed0
            };
            // iterators
            UCharacterIterator iter1 = UCharacterIterator.GetInstance(new ReplaceableString(new String(src)));
            UCharacterIterator iter2 = UCharacterIterator.GetInstance(src /*char array*/);
            UCharacterIterator iter3 = UCharacterIterator.GetInstance(new StringCharacterIterator(new String(src)));
            UCharacterIterator iter4 = UCharacterIterator.GetInstance(new StringBuffer(new String(src)));

            previousNext(iter1);
            previousNext(iter2);
            previousNext(iter3);
            previousNext(iter4);
            getText(iter1, new String(src));
            getText(iter2, new String(src));
            getText(iter3, new String(src));
            /* getCharacterIterator */
            CharacterIterator citer1 = iter1.GetCharacterIterator();
            CharacterIterator citer2 = iter2.GetCharacterIterator();
            CharacterIterator citer3 = iter3.GetCharacterIterator();

            if (citer1.First() != iter1.Current)
            {
                Errln("getCharacterIterator for iter1 failed");
            }
            if (citer2.First() != iter2.Current)
            {
                Errln("getCharacterIterator for iter2 failed");
            }
            if (citer3.First() != iter3.Current)
            {
                Errln("getCharacterIterator for iter3 failed");
            }
            /* Test clone()  && moveIndex()*/
            try
            {
                UCharacterIterator clone1 = (UCharacterIterator)iter1.Clone();
                UCharacterIterator clone2 = (UCharacterIterator)iter2.Clone();
                UCharacterIterator clone3 = (UCharacterIterator)iter3.Clone();
                if (clone1.MoveIndex(3) != iter1.MoveIndex(3))
                {
                    Errln("moveIndex for iter1 failed");
                }
                if (clone2.MoveIndex(3) != iter2.MoveIndex(3))
                {
                    Errln("moveIndex for iter2 failed");
                }
                if (clone3.MoveIndex(3) != iter3.MoveIndex(3))
                {
                    Errln("moveIndex for iter1 failed");
                }
            }
            catch (Exception e)
            {
                Errln("could not clone the iterator");
            }
        }