From 58e4a5fb5ebbdd041ce7c1389df5442891a936a3 Mon Sep 17 00:00:00 2001
From: Robert Loehning <robert.loehning@digia.com>
Date: Wed, 30 Jan 2013 18:15:38 +0100
Subject: [PATCH] Squish: Fixed opening of files

Change-Id: Ia96a4a000cac1dde0f660e5f58141a73c7625a1e
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
---
 tests/system/shared/editor_utils.py        | 12 ++++++++++--
 tests/system/suite_CCOM/tst_CCOM02/test.py |  2 +-
 tests/system/suite_CSUP/tst_CSUP01/test.py |  2 +-
 tests/system/suite_CSUP/tst_CSUP02/test.py |  2 +-
 tests/system/suite_CSUP/tst_CSUP04/test.py |  4 ++--
 tests/system/suite_CSUP/tst_CSUP05/test.py |  2 +-
 tests/system/suite_QMLS/shared/qmls.py     |  7 +++++--
 tests/system/suite_QMLS/tst_QMLS03/test.py |  2 +-
 tests/system/suite_SCOM/tst_SCOM02/test.py |  2 +-
 tests/system/suite_SCOM/tst_SCOM04/test.py |  2 +-
 10 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/tests/system/shared/editor_utils.py b/tests/system/shared/editor_utils.py
index c438804429c..558eef273d5 100644
--- a/tests/system/shared/editor_utils.py
+++ b/tests/system/shared/editor_utils.py
@@ -287,14 +287,22 @@ def invokeFindUsage(editor, line, typeOperation, n=1):
     invokeContextMenuItem(editor, "Find Usages")
     return True
 
+def addBranchWildcardToRoot(rootNode):
+    pos = rootNode.find(".")
+    return rootNode[:pos] + " (*)" + rootNode[pos:]
+
 def openDocument(treeElement):
     try:
         selectFromCombo(":Qt Creator_Core::Internal::NavComboBox", "Open Documents")
         navigator = waitForObject(":Qt Creator_Utils::NavigationTreeView")
-        fileName = waitForObjectItem(navigator, treeElement).text
+        try:
+            item = waitForObjectItem(navigator, treeElement, 3000)
+        except:
+            treeElement = addBranchWildcardToRoot(treeElement)
+            item = waitForObjectItem(navigator, treeElement)
         doubleClickItem(navigator, treeElement, 5, 5, 0, Qt.LeftButton)
         mainWindow = waitForObject(":Qt Creator_Core::Internal::MainWindow")
-        waitFor("fileName in str(mainWindow.windowTitle)")
+        waitFor("item.text in str(mainWindow.windowTitle)")
         return True
     except:
         return False
diff --git a/tests/system/suite_CCOM/tst_CCOM02/test.py b/tests/system/suite_CCOM/tst_CCOM02/test.py
index a687649f8cc..02b3e93df3c 100755
--- a/tests/system/suite_CCOM/tst_CCOM02/test.py
+++ b/tests/system/suite_CCOM/tst_CCOM02/test.py
@@ -15,7 +15,7 @@ def main():
     # open example project
     openQmakeProject(examplePath)
     # create syntax error
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.QML.qml.property-animation\\.qml", 5, 5, 0, Qt.LeftButton)
+    openDocument("propertyanimation.QML.qml.property-animation\\.qml")
     if not appendToLine(waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget"), "Image {", "SyntaxError"):
         invokeMenuItem("File", "Exit")
         return
diff --git a/tests/system/suite_CSUP/tst_CSUP01/test.py b/tests/system/suite_CSUP/tst_CSUP01/test.py
index 10b4f3ffa6b..78962ce23a9 100644
--- a/tests/system/suite_CSUP/tst_CSUP01/test.py
+++ b/tests/system/suite_CSUP/tst_CSUP01/test.py
@@ -11,7 +11,7 @@ def main():
     test.verify(waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp"),
                 "Step 1: Verifying if: Project is opened.")
 # Step 2: Open .cpp file in Edit mode.
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton)
+    openDocument("SampleApp.Sources.main\\.cpp")
     test.verify(checkIfObjectExists(":Qt Creator_CppEditor::Internal::CPPEditorWidget"),
                 "Step 2: Verifying if: .cpp file is opened in Edit mode.")
 # Step 3: Insert text "re" to new line in Editor mode and press Ctrl+Space.
diff --git a/tests/system/suite_CSUP/tst_CSUP02/test.py b/tests/system/suite_CSUP/tst_CSUP02/test.py
index ec8313a9fe9..804ea8caeaa 100644
--- a/tests/system/suite_CSUP/tst_CSUP02/test.py
+++ b/tests/system/suite_CSUP/tst_CSUP02/test.py
@@ -11,7 +11,7 @@ def main():
     test.verify(waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp"),
                 "Step 1: Verifying if: Project is opened.")
 # Step 2: Open .cpp file in Edit mode.
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton)
+    openDocument("SampleApp.Sources.main\\.cpp")
     test.verify(checkIfObjectExists(":Qt Creator_CppEditor::Internal::CPPEditorWidget"),
                 "Step 2: Verifying if: .cpp file is opened in Edit mode.")
 # Steps 3&4: Insert text "class" to new line in Editor mode and press Ctrl+Space.
diff --git a/tests/system/suite_CSUP/tst_CSUP04/test.py b/tests/system/suite_CSUP/tst_CSUP04/test.py
index 28d4ac145b8..c591a3425b2 100644
--- a/tests/system/suite_CSUP/tst_CSUP04/test.py
+++ b/tests/system/suite_CSUP/tst_CSUP04/test.py
@@ -22,7 +22,7 @@ def main():
     test.verify(waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation"),
                 "Verifying if: Project is opened.")
     # open .cpp file in editor
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton)
+    openDocument("propertyanimation.Sources.main\\.cpp")
     test.verify(checkIfObjectExists(":Qt Creator_CppEditor::Internal::CPPEditorWidget"),
                 "Verifying if: .cpp file is opened in Edit mode.")
     # place cursor on line "QmlApplicationViewer viewer;"
@@ -39,7 +39,7 @@ def main():
     test.verify(result, "Verifying if: The list of all usages of the selected text is displayed in Search Results. "
                 "File with used text is opened.")
     # move cursor to the other word and test Find Usages function by pressing Ctrl+Shift+U.
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton)
+    openDocument("propertyanimation.Sources.main\\.cpp")
     if not placeCursorToLine(editorWidget, "viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);"):
         return
     for i in range(4):
diff --git a/tests/system/suite_CSUP/tst_CSUP05/test.py b/tests/system/suite_CSUP/tst_CSUP05/test.py
index f3d065ed0ef..4a947079d47 100644
--- a/tests/system/suite_CSUP/tst_CSUP05/test.py
+++ b/tests/system/suite_CSUP/tst_CSUP05/test.py
@@ -19,7 +19,7 @@ def main():
     test.verify(waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation"),
                 "Verifying if: Project is opened.")
     # open .cpp file in editor
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton)
+    openDocument("propertyanimation.Sources.main\\.cpp")
     test.verify(checkIfObjectExists(":Qt Creator_CppEditor::Internal::CPPEditorWidget"),
                 "Verifying if: .cpp file is opened in Edit mode.")
     # select some word for example "viewer" and press Ctrl+F.
diff --git a/tests/system/suite_QMLS/shared/qmls.py b/tests/system/suite_QMLS/shared/qmls.py
index 37bcdcb6222..1792c98ff44 100644
--- a/tests/system/suite_QMLS/shared/qmls.py
+++ b/tests/system/suite_QMLS/shared/qmls.py
@@ -6,8 +6,11 @@ def startQtCreatorWithNewAppAtQMLEditor(projectDir, projectName, line = None):
     # create qt quick application
     createNewQtQuickApplication(projectDir, projectName)
     # open qml file
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", projectName + ".QML.qml/" +
-                    projectName + ".main\\.qml", 5, 5, 0, Qt.LeftButton)
+    qmlFile = projectName + ".QML.qml/" + projectName + ".main\\.qml"
+    if not openDocument(qmlFile):
+        test.fatal("Could not open %s" % qmlFile)
+        invokeMenuItem("File", "Exit")
+        return None
     # get editor
     editorArea = waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget")
     # place to line if needed
diff --git a/tests/system/suite_QMLS/tst_QMLS03/test.py b/tests/system/suite_QMLS/tst_QMLS03/test.py
index 4340260f656..abb3ab3a5a8 100644
--- a/tests/system/suite_QMLS/tst_QMLS03/test.py
+++ b/tests/system/suite_QMLS/tst_QMLS03/test.py
@@ -50,7 +50,7 @@ def main():
     # open example project
     openQmakeProject(examplePath)
     # open qml file
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.QML.qml.color-animation\\.qml", 5, 5, 0, Qt.LeftButton)
+    openDocument("propertyanimation.QML.qml.color-animation\\.qml")
     # get editor
     editorArea = waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget")
     # 1. check usages using context menu
diff --git a/tests/system/suite_SCOM/tst_SCOM02/test.py b/tests/system/suite_SCOM/tst_SCOM02/test.py
index 67e8fca6ab2..517217dabdd 100644
--- a/tests/system/suite_SCOM/tst_SCOM02/test.py
+++ b/tests/system/suite_SCOM/tst_SCOM02/test.py
@@ -7,7 +7,7 @@ def main():
     # create qt quick application
     createNewQtQuickApplication(tempDir(), "SampleApp")
     # create syntax error in qml file
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp.QML.qml/SampleApp.main\\.qml", 5, 5, 0, Qt.LeftButton)
+    openDocument("SampleApp.QML.qml/SampleApp.main\\.qml")
     if not appendToLine(waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget"), "Text {", "SyntaxError"):
         invokeMenuItem("File", "Exit")
         return
diff --git a/tests/system/suite_SCOM/tst_SCOM04/test.py b/tests/system/suite_SCOM/tst_SCOM04/test.py
index 254fea1060e..be20b1fd368 100644
--- a/tests/system/suite_SCOM/tst_SCOM04/test.py
+++ b/tests/system/suite_SCOM/tst_SCOM04/test.py
@@ -10,7 +10,7 @@ def main():
     # create qt quick application
     checkedTargets, projectName = createNewQtQuickApplication(tempDir(), "SampleApp")
     # create syntax error in cpp file
-    doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton)
+    openDocument("SampleApp.Sources.main\\.cpp")
     if not appendToLine(waitForObject(":Qt Creator_CppEditor::Internal::CPPEditorWidget"), "viewer.showExpanded();", "SyntaxError"):
         invokeMenuItem("File", "Exit")
         return
-- 
GitLab