From ea63b86e49d2f15eb2aff1548aae1fce1af70090 Mon Sep 17 00:00:00 2001 From: Robert Loehning Date: Fri, 25 May 2012 11:52:01 +0200 Subject: [PATCH] Squish: Replaced function moveTextCursor Change-Id: Ie4cccd0de668690a3d66baf422bcfff7acae7345 Reviewed-by: Christian Stenger --- tests/system/shared/editor_utils.py | 15 -------------- tests/system/suite_QMLS/tst_QMLS02/test.py | 5 +++-- tests/system/suite_QMLS/tst_QMLS03/test.py | 9 +++++--- tests/system/suite_QMLS/tst_QMLS04/test.py | 3 ++- tests/system/suite_QMLS/tst_QMLS05/test.py | 24 ++++++++++------------ 5 files changed, 22 insertions(+), 34 deletions(-) diff --git a/tests/system/shared/editor_utils.py b/tests/system/shared/editor_utils.py index ae5fc8cfde6..8f7b74026f4 100644 --- a/tests/system/shared/editor_utils.py +++ b/tests/system/shared/editor_utils.py @@ -30,21 +30,6 @@ def placeCursorToLine(editor, line, isRegex=False): editor.setTextCursor(cursor) return True -# this function moves the text cursor of an editor by using Qt internal functions -# this is more reliable (especially on Mac) than the type() approach -# param editor an editor object -# param moveOperation a value of enum MoveOperation (of QTextCursor) -# param moveAnchor a value of enum MoveMode (of QTextCursor) -# param n how often repeat the move operation? -def moveTextCursor(editor, moveOperation, moveAnchor, n=1): - if not editor or isinstance(editor, (str,unicode)): - test.fatal("Either got a NoneType or a string instead of an editor object") - return False - textCursor = editor.textCursor() - result = textCursor.movePosition(moveOperation, moveAnchor, n) - editor.setTextCursor(textCursor) - return result - # this function returns True if a QMenu is # popped up above the given editor # param editor is the editor where the menu should appear diff --git a/tests/system/suite_QMLS/tst_QMLS02/test.py b/tests/system/suite_QMLS/tst_QMLS02/test.py index 3c65ac020f4..7f29524b83c 100644 --- a/tests/system/suite_QMLS/tst_QMLS02/test.py +++ b/tests/system/suite_QMLS/tst_QMLS02/test.py @@ -16,8 +16,9 @@ def main(): "Verifying if error is properly reported") # repair error - go to written line placeCursorToLine(editorArea, testingCodeLine) - moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 14) - moveTextCursor(editorArea, QTextCursor.Right, QTextCursor.KeepAnchor, 1) + for i in range(14): + type(editorArea, "") + type(editorArea, "") type(editorArea, "c") # invoke QML parsing invokeMenuItem("Tools", "QML/JS", "Run Checks") diff --git a/tests/system/suite_QMLS/tst_QMLS03/test.py b/tests/system/suite_QMLS/tst_QMLS03/test.py index c492a4d2684..bbd4facd237 100644 --- a/tests/system/suite_QMLS/tst_QMLS03/test.py +++ b/tests/system/suite_QMLS/tst_QMLS03/test.py @@ -59,7 +59,8 @@ def main(): if not placeCursorToLine(editorArea, "Rectangle {"): invokeMenuItem("File", "Exit") return - moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 5) + for i in range(5): + type(editorArea, "") ctxtMenu = openContextMenuOnTextCursorPosition(editorArea) activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Find Usages")) # check if usage was properly found @@ -77,7 +78,8 @@ def main(): if not placeCursorToLine(editorArea, "anchors { left: parent.left; top: parent.top; right: parent.right; bottom: parent.verticalCenter }"): invokeMenuItem("File", "Exit") return - moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 87) + for i in range(87): + type(editorArea, "") invokeMenuItem("Tools", "QML/JS", "Find Usages") # check if usage was properly found expectedResults = [ExpectedResult("color-animation.qml", 50, "anchors { left: parent.left; top: parent.top; right: parent.right; bottom: parent.verticalCenter }"), @@ -94,7 +96,8 @@ def main(): if not placeCursorToLine(editorArea, "SequentialAnimation on opacity {"): invokeMenuItem("File", "Exit") return - moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 5) + for i in range(5): + type(editorArea, "") type(editorArea, "") # check if usage was properly found expectedResults = [ExpectedResult("color-animation.qml", 87, "SequentialAnimation on opacity {")] diff --git a/tests/system/suite_QMLS/tst_QMLS04/test.py b/tests/system/suite_QMLS/tst_QMLS04/test.py index e62b72dc6ae..e14f79804a4 100644 --- a/tests/system/suite_QMLS/tst_QMLS04/test.py +++ b/tests/system/suite_QMLS/tst_QMLS04/test.py @@ -5,7 +5,8 @@ def main(): editorArea = startQtCreatorWithNewAppAtQMLEditor(projectDir, "SampleApp", "Text {") if not editorArea: return - moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 5) + for i in range(5): + type(editorArea, "") # invoke Refactoring - Move Component into separate file ctxtMenu = openContextMenuOnTextCursorPosition(editorArea) activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Refactoring")) diff --git a/tests/system/suite_QMLS/tst_QMLS05/test.py b/tests/system/suite_QMLS/tst_QMLS05/test.py index 694460eea32..f2e0fb50720 100644 --- a/tests/system/suite_QMLS/tst_QMLS05/test.py +++ b/tests/system/suite_QMLS/tst_QMLS05/test.py @@ -4,12 +4,17 @@ def main(): editorArea = startQtCreatorWithNewAppAtQMLEditor(tempDir(), "SampleApp", "Text {") if not editorArea: return - moveTextCursor(editorArea, QTextCursor.StartOfLine, QTextCursor.MoveAnchor) + homeKey = "" + if platform.system() == "Darwin": + homeKey = "" + for i in range(2): + type(editorArea, homeKey) type(editorArea, "") - moveTextCursor(editorArea, QTextCursor.Up, QTextCursor.MoveAnchor) + type(editorArea, "") type(editorArea, "") type(editorArea, "Item { x: 10; y: 20; width: 10 }") - moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 30) + for i in range(30): + type(editorArea, "") invokeMenuItem("File", "Save All") # activate menu and apply 'Refactoring - Split initializer' numLinesExpected = len(str(editorArea.plainText).splitlines()) + 4 @@ -20,16 +25,9 @@ def main(): waitFor("len(str(editorArea.plainText).splitlines()) == numLinesExpected", 5000) # verify if refactoring was properly applied - each part on separate line verifyMessage = "Verifying split initializer functionality at element line." - verifyCurrentLine(editorArea, "Item {", verifyMessage) - moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1) - verifyCurrentLine(editorArea, "x: 10;", verifyMessage) - moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1) - verifyCurrentLine(editorArea, "y: 20;", verifyMessage) - moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1) - verifyCurrentLine(editorArea, "width: 10", verifyMessage) - moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1) - verifyCurrentLine(editorArea, "}", verifyMessage) - moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1) + for line in ["Item {", "x: 10;", "y: 20;", "width: 10", "}"]: + verifyCurrentLine(editorArea, line, verifyMessage) + type(editorArea, "") #save and exit invokeMenuItem("File", "Save All") invokeMenuItem("File", "Exit")