GetText() public method

public GetText ( int maxLength ) : string
maxLength int
return string
Ejemplo n.º 1
0
        public static int CountTrailingCRLF(AutomationElement autoElement, TextPatternRange callingRange)
        {
            // Bug: 1134056: Resolve RichEdit control inconsistencies / unexpected behavior
            int offset = 0;

            Library.ValidateArgumentNonNull(autoElement, "AutomationElement cannot be null");
            Library.ValidateArgumentNonNull(callingRange, "callingRange cannot be null");

            if (IsRichEdit(autoElement) == true)
            {
                string text = callingRange.GetText(-1);

                offset = GetTrailingCRLFOffset(text);
            }
            return offset;
        }
Ejemplo n.º 2
0
        public static void TrimRangeCRLF(AutomationElement autoElement, TextPatternRange callingRange)
        {
            Library.ValidateArgumentNonNull(autoElement, "AutomationElement cannot be null");
            Library.ValidateArgumentNonNull(autoElement, "callingRange cannot be null");

            if (IsRichEdit(autoElement) == true)
            {
                int actualOffset = 0; // Actual   offset of \r, \n or \r\n
                int expectedOffset = 0; // Expected offset of \r, \n or \r\n
                string text = callingRange.GetText(-1);

                expectedOffset = GetTrailingCRLFOffset(text);

                // Now... move the endpoint
                actualOffset = callingRange.MoveEndpointByUnit(TextPatternRangeEndpoint.End, TextUnit.Character, expectedOffset);

                if (actualOffset != expectedOffset)
                    throw new InvalidOperationException("Unable to move endpoint back by " + expectedOffset + " characters. Actual = " + actualOffset);
                else
                    /* changing to new flexible logging */
                    //Logger.LogComment("Adjusted size of range for RichEdit control by omitting last " + expectedOffset + " characters");
                    UIVerifyLogger.LogComment("Adjusted size of range for RichEdit control by omitting last " + expectedOffset + " characters");
            }
        }
Ejemplo n.º 3
0
        /// --------------------------------------------------------------------
        /// <summary>
        ///     The delegate for the target text selection changed event.
        /// </summary>
        /// <param name="arg">null argument</param>
        /// <returns>A null object.</returns>
        /// --------------------------------------------------------------------
        private void NotifySelectionChanged()
        {
            // Get the array of disjoint selections.
            var selectionRanges =
                _targetTextPattern.GetSelection();
            // Update the current search range.
            // For the purposes of this sample only the first selection
            // range will be echoed in the client.
            _searchRange = selectionRanges[0];
            // For performance and security reasons we'll limit 
            // the length of the string retrieved to 100 characters.
            // Alternatively, GetText(-1) will retrieve all selected text.
            var selectedText = _searchRange.GetText(100);
            _targetSelectionLabel.Content =
                "Currently selected (100 character maximum): " +
                selectedText.Length + " characters.";

            // Report target selection details.
            DisplaySelectedTextWithAttributes(selectedText);
        }
Ejemplo n.º 4
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());
            }
        }
Ejemplo n.º 5
0
        public static int CountTextUnit(TextUnit tu, TextPatternRange rangeToCount)
        {
            ValidateArgumentNonNull(rangeToCount, "rangeToCount argument cannot be null");  // Sanity check

            TextPatternRange clone = rangeToCount.Clone();

            int count = clone.MoveEndpointByUnit(TextPatternRangeEndpoint.Start, tu, Int32.MaxValue);
        
            // Provider / Text Unit specific offsets    
            switch(typeOfProvider)
            {
            case "win32":
            case "winform":
                {
                    // This is to correct the fact that our line count will skip the last line if it 
                    // DOES NOT have a trailing \r, \n or \r\n
                    if( tu == TextUnit.Line ) 
                    {
                        string text = rangeToCount.GetText(-1);
                        AutomationElement element = rangeToCount.GetEnclosingElement();
                        if( IsTrailingCRLF(element, text) == 0 )
                            count++;
                    }
                }
                break;
            case "wpf":
                break;
            } 
            
            return count;
        }
Ejemplo n.º 6
0
        //---------------------------------------------------------------------------
        // Wrapper for TextPatternRange.GetText Method 
        // that "eats" InavlidOperationException's when raised
        // THis is so we can get all the text of a control without 1456324 causing
        // unexpected side-effects of the test infrastructure / tests whose scenarios 
        // may not obviously define them as having 1456324 as a "known issue"
        //---------------------------------------------------------------------------
        internal string Range_GetText(TextPatternRange callingRange)
        {
            string text = "";
            string call = "TextPatternRange.GetText(-1)";
            Comment("---Calling " + call);

            if (callingRange == null)
                throw new ArgumentNullException(call + " requires non-NULL TextPatterncallingRange");

            try
            {
                text = callingRange.GetText(-1);
            }
            catch (InvalidOperationException)
            {
                Comment("SOFT ERROR:  GetText(-1) raised InvalidOperationException. This is a known bug.");
                Comment("             1456324: BVT BLOCKER: GetText(-1) throws InvalidOperationException");
                ThrowMe(CheckType.IncorrectElementConfiguration, "Unable to continue with test due to known bug/side-effect");
            }
            return text;
        }
Ejemplo n.º 7
0
        //---------------------------------------------------------------------------
        // Wrapper for TextPatternRange.GetText Method
        //---------------------------------------------------------------------------
        internal void Range_GetText(TextPatternRange callingRange, ref string text, int maxLength, Type expectedException, CheckType checkType)
        {
            string call = "TextPatternRange.GetText(" + maxLength + ")";
            Comment("---Calling " + call);

            if (callingRange == null)
                throw new ArgumentNullException(call + " requires non-NULL TextPatterncallingRange");

            try
            {
                text = callingRange.GetText(maxLength);
            }
            catch (Exception actualException)
            {
                if (Library.IsCriticalException(actualException))
                    throw;

                //                     // Can't use BugIssues.PS1456324 here becasue 
                //                     // coneivably MOST of the 300 TextPattern tests could hit this
                //if (maxLength == -1) // Can't use TS_FilterOnException because of this special case
                //    ThrowMe(CheckType.KnownProductIssue, "Bug hit 1456324");

                TestException(expectedException, actualException, call, checkType);
                return;
            }
            TestNoExceptionQuiet(expectedException, call, checkType);
        }