public void OverloadedToString_ReturnsCorrectValue()
        {
            TextUnit unit = new TextUnit("key", twoCultureTexts);

            Assert.IsTrue(unit.ToString(CultureInfo.InvariantCulture) == HelloWorld);
            Assert.IsTrue(unit.ToString(frFR) == HelloWorldFr);
        }
        public void OverloadedToString_NotSupportedCulture_ThrowsKeyNotFoundException()
        {
            TextUnit unit = new TextUnit("key", invariantCultureTexts);

            CultureInfo impossibleCultureInfo = CultureInfo.GetCultureInfo("sq"); // Albanian !

            unit.ToString(impossibleCultureInfo);
        }
Esempio n. 3
0
        internal static int Win32CountTextUnit(TextUnit textUnit, TextPatternRange rangeToCount)
        {
            AutomationElement element    = null;
            string            actualText = "";

            ValidateArgumentNonNull(rangeToCount, "rangeToCount argument cannot be null");  // Sanity check

            // Get text
            try
            {
                actualText = rangeToCount.GetText(-1);
                element    = rangeToCount.GetEnclosingElement();
                if (element == null)
                {
                    throw new InvalidOperationException("Null automation element incorrectly returned by TextPatternRange.GetEnclosingElement() in Win32CountTextUnit()");
                }
            }
            catch (Exception exception)
            {
                if (IsCriticalException(exception))
                {
                    throw;
                }

                throw new InvalidOperationException("Unable to call TextPatternRange.GetText() in Win32CountTextUnit()", exception);
            }

            // Count text units and assign to array element
            switch (textUnit)
            {
            case TextUnit.Character:
                return(actualText.Length);

            case TextUnit.Format:
                return(CountTextUnit(TextUnit.Format, rangeToCount));

            case TextUnit.Word:
                return(CountTextUnit(TextUnit.Word, rangeToCount));

            case TextUnit.Line:
                return(Win32CountLines(element));

            case TextUnit.Paragraph:
                return(CountParagraphs(actualText));

            case TextUnit.Page:
                return(1);

            case TextUnit.Document:
                return(1);

            default:
                throw new ArgumentException("CountTextUnits() does not support " + textUnit.ToString());
            }
        }
        //---------------------------------------------------------------------------
        // Calls move N+1 times and validates results
        // First N times should equal expected result
        // N+1'th time should return 0
        // Unit is the actual unit we're going to call move with.
        //---------------------------------------------------------------------------
        internal void TS_MoveNTimes(TextUnit unit, int[] numberOfTextUnits, TextPatternRange range, int moveCount, int expectedResult, CheckType checkType)
        {
            int count = 0;
            int countOffset = 0;
            int actualResult = 0;
            bool isRichEdit = TextLibrary.IsRichEdit(m_le);
            string msg = "Move(" + unit.ToString() + ", " + moveCount + ")";
            TextPatternRange callingRange = null;

            // Get document range and clone calling range
            Range_Clone(range, ref callingRange, null, checkType);

            // Get count of type
            count = numberOfTextUnits[(int)unit];

            if (isRichEdit == true)    // Bug 1059357 or 1134056 (take your pick)
            {
                if (unit == TextUnit.Character)
                {
                    countOffset = _trailingCRLFCount;
                    count += countOffset;
                    Comment("Depricating expected count of chracters by " + countOffset + " for textunit " + ParseType(TextUnit.Character));
                }
                else if (unit == TextUnit.Word)
                {
                    count--;
                    Comment("Depricating expected count of words by -1 for textunit " + ParseType(TextUnit.Word));
                }
            }

            // First N times, the return value of Move should equal result
            for (int i = 0; i < count; i++)
            {
                Range_Move(callingRange, unit, moveCount, ref actualResult, null, checkType);

                if (actualResult != expectedResult)
                {
                    ThrowMe(checkType, msg + " returned " + actualResult + ", expected = " + expectedResult);
                }
            }
            Comment(msg + " called " + count + " times successfully");


            // Now move N+1'th time, should always return 0
            moveCount = 0;
            Range_Move(callingRange, unit, moveCount, ref actualResult, null, checkType);

            if (actualResult != 0)
                ThrowMe(checkType, msg + " returned " + actualResult + ", expected = 0");
            else
                Comment(msg + " returned 0 as expected");

            m_TestStep++;
        }
Esempio n. 5
0
 //-------------------------------------------------------------------
 // Identify supported TextUnits in WPF
 //-------------------------------------------------------------------
 internal static TextUnit wpf_IdentifySupportedTextUnits(AutomationElement element, TextUnit targetUnit)
 {
     switch (targetUnit)
     {
         case TextUnit.Character: return TextUnit.Character;
         case TextUnit.Format: return TextUnit.Format;
         case TextUnit.Word: return TextUnit.Word;
         case TextUnit.Line: return TextUnit.Line;
         case TextUnit.Paragraph: return TextUnit.Paragraph;
         case TextUnit.Page:                                 // Maps to Document for everything but MS Word
         case TextUnit.Document: return TextUnit.Document;
         default:
             throw new NotImplementedException("IdentifySupportedTextUnits() does not support " + targetUnit.ToString());
     }
 }
Esempio n. 6
0
        //-------------------------------------------------------------------
        // Identify supported TextUnits in Win32
        //-------------------------------------------------------------------
        internal static TextUnit win32_IdentifySupportedTextUnits(AutomationElement element, TextUnit targetUnit)
        {
            string className = GetClassName(element);

            if (className.IndexOf(RichEditClassName) > -1)
            {
                switch (targetUnit)
                {
                    case TextUnit.Character: return TextUnit.Character;
                    case TextUnit.Format: return TextUnit.Format;
                    case TextUnit.Word: return TextUnit.Word;
                    case TextUnit.Line: return TextUnit.Line;
                    case TextUnit.Paragraph: return TextUnit.Paragraph;
                    case TextUnit.Page:                                 // Maps to Document for everything but MS Word
                    case TextUnit.Document: return TextUnit.Document;
                    default:
                        throw new NotImplementedException("IdentifySupportedTextUnits() does not support " + targetUnit.ToString());
                }
            }
            else if (className.IndexOf(EditClassName) > -1)
            {
                switch (targetUnit)
                {
                    case TextUnit.Character: return TextUnit.Character;
                    case TextUnit.Word: return TextUnit.Word;
                    case TextUnit.Line: return TextUnit.Line;
                    case TextUnit.Paragraph: return TextUnit.Paragraph;
                    case TextUnit.Format:                               // No support for Format in Win32 Edit
                    case TextUnit.Page:                                 // Maps to Document for everything but MS Word
                    case TextUnit.Document: return TextUnit.Document;
                    default:
                        throw new NotImplementedException("IdentifySupportedTextUnits() does not support " + targetUnit.ToString());
                }
            }

            throw new NotImplementedException("IdentifySupportedTextUnits() cannot determine supported text units for class " + className);
        }
Esempio n. 7
0
        internal static int Win32CountTextUnit(TextUnit textUnit, TextPatternRange rangeToCount)
        {
            AutomationElement element = null;
            string actualText = "";

            ValidateArgumentNonNull(rangeToCount, "rangeToCount argument cannot be null");  // Sanity check

            // Get text
            try
            {
                actualText = rangeToCount.GetText(-1);
                element = rangeToCount.GetEnclosingElement();
                if (element == null)
                    throw new InvalidOperationException("Null automation element incorrectly returned by TextPatternRange.GetEnclosingElement() in Win32CountTextUnit()");
            }
            catch (Exception exception)
            {
                if (IsCriticalException(exception))
                    throw;

                throw new InvalidOperationException("Unable to call TextPatternRange.GetText() in Win32CountTextUnit()", exception);
            }

            // Count text units and assign to array element
            switch (textUnit)
            {
                case TextUnit.Character:
                    return actualText.Length;
                case TextUnit.Format:
                    return CountTextUnit(TextUnit.Format, rangeToCount);
                case TextUnit.Word:
                    return CountTextUnit(TextUnit.Word, rangeToCount);
                case TextUnit.Line:
                    return Win32CountLines(element);
                case TextUnit.Paragraph:
                    return CountParagraphs(actualText);
                case TextUnit.Page:
                    return 1;
                case TextUnit.Document:
                    return 1;
                default:
                    throw new ArgumentException("CountTextUnits() does not support " + textUnit.ToString());
            }
        }
Esempio n. 8
0
        //-------------------------------------------------------------------
        // Identify supported TextUnits in WPF
        //-------------------------------------------------------------------
        internal static TextUnit wpf_IdentifySupportedTextUnits(AutomationElement element, TextUnit targetUnit)
        {
            switch (targetUnit)
            {
            case TextUnit.Character: return(TextUnit.Character);

            case TextUnit.Format: return(TextUnit.Format);

            case TextUnit.Word: return(TextUnit.Word);

            case TextUnit.Line: return(TextUnit.Line);

            case TextUnit.Paragraph: return(TextUnit.Paragraph);

            case TextUnit.Page:                                     // Maps to Document for everything but MS Word
            case TextUnit.Document: return(TextUnit.Document);

            default:
                throw new NotImplementedException("IdentifySupportedTextUnits() does not support " + targetUnit.ToString());
            }
        }
Esempio n. 9
0
        //-------------------------------------------------------------------
        // Identify supported TextUnits in Win32
        //-------------------------------------------------------------------
        internal static TextUnit win32_IdentifySupportedTextUnits(AutomationElement element, TextUnit targetUnit)
        {
            string className = GetClassName(element);

            if (className.IndexOf(RichEditClassName) > -1)
            {
                switch (targetUnit)
                {
                case TextUnit.Character: return(TextUnit.Character);

                case TextUnit.Format: return(TextUnit.Format);

                case TextUnit.Word: return(TextUnit.Word);

                case TextUnit.Line: return(TextUnit.Line);

                case TextUnit.Paragraph: return(TextUnit.Paragraph);

                case TextUnit.Page:                                     // Maps to Document for everything but MS Word
                case TextUnit.Document: return(TextUnit.Document);

                default:
                    throw new NotImplementedException("IdentifySupportedTextUnits() does not support " + targetUnit.ToString());
                }
            }
            else if (className.IndexOf(EditClassName) > -1)
            {
                switch (targetUnit)
                {
                case TextUnit.Character: return(TextUnit.Character);

                case TextUnit.Word: return(TextUnit.Word);

                case TextUnit.Line: return(TextUnit.Line);

                case TextUnit.Paragraph: return(TextUnit.Paragraph);

                case TextUnit.Format:                                   // No support for Format in Win32 Edit
                case TextUnit.Page:                                     // Maps to Document for everything but MS Word
                case TextUnit.Document: return(TextUnit.Document);

                default:
                    throw new NotImplementedException("IdentifySupportedTextUnits() does not support " + targetUnit.ToString());
                }
            }

            throw new NotImplementedException("IdentifySupportedTextUnits() cannot determine supported text units for class " + className);
        }
Esempio n. 10
0
 /// ---------------------------------------------------------------------------
 /// <summary>Parses values for enum</summary>
 /// ---------------------------------------------------------------------------
 static public string ParseType(TextUnit value)
 {
     return ParseType(value.GetType().ToString(), value.ToString());
 }
        public void ToString_ReturnsDefaultValue()
        {
            TextUnit unit = new TextUnit("key", invariantCultureTexts);

            Assert.IsTrue(unit.ToString() == HelloWorld);
        }