From 73005e6bcadce4e1d2bc417f745bfaddba7f0396 Mon Sep 17 00:00:00 2001
From: Robert Loehning <robert.loehning@nokia.com>
Date: Tue, 17 Jan 2012 13:47:47 +0100
Subject: [PATCH] Squish: Added functions for switching build configurations

Change-Id: I03eb8987ec28bac7db99395ed91952d8a3a0d038
Reviewed-by: Bill King <bill.king@nokia.com>
Reviewed-by: Christian Stenger <christian.stenger@nokia.com>
---
 tests/system/objects.map                      |  2 +
 tests/system/shared/build_utils.py            | 30 ++++++++++++++
 tests/system/shared/utils.py                  |  6 ++-
 .../tst_build_speedcrunch/test.py             | 40 ++++++-------------
 4 files changed, 50 insertions(+), 28 deletions(-)

diff --git a/tests/system/objects.map b/tests/system/objects.map
index b33ccf42d83..bb758419ecb 100644
--- a/tests/system/objects.map
+++ b/tests/system/objects.map
@@ -48,6 +48,8 @@
 :scrollArea.Create Build Configurations:_QComboBox_2	{container=':Qt Gui Application.scrollArea_QScrollArea' leftWidget=':scrollArea.Create Build Configurations:_QLabel_2' type='QComboBox' unnamed='1' visible='1'}
 :scrollArea.Create Build Configurations:_QLabel	{container=':Project Setup.scrollArea_QScrollArea' text='Create Build Configurations:' type='QLabel' unnamed='1' visible='1'}
 :scrollArea.Create Build Configurations:_QLabel_2	{container=':Qt Gui Application.scrollArea_QScrollArea' text='Create Build Configurations:' type='QLabel' unnamed='1' visible='1'}
+:scrollArea.Edit build configuration:_QComboBox	{container=':Qt Creator.scrollArea_QScrollArea' leftWidget=':scrollArea.Edit build configuration:_QLabel' type='QComboBox' unnamed='1' visible='1'}
+:scrollArea.Edit build configuration:_QLabel	{container=':Qt Creator.scrollArea_QScrollArea' text='Edit build configuration:' type='QLabel' unnamed='1' visible='1'}
 :scrollArea.Qt 4 for Desktop - (Qt SDK) debug_QCheckBox	{container=':Qt Gui Application.scrollArea_QScrollArea' text?='*Qt 4.* for *(Qt SDK) debug' type='QCheckBox' unnamed='1' visible='1'}
 :scrollArea.Qt 4 for Desktop - (Qt SDK) release_QCheckBox	{container=':Qt Gui Application.scrollArea_QScrollArea' text?='*Qt 4.* for *(Qt SDK) release' type='QCheckBox' unnamed='1' visible='1'}
 :scrollArea.Qt Version:_QComboBox	{aboveWidget=':scrollArea.Use Shadow Building_QCheckBox' container=':Qt Gui Application.scrollArea_QScrollArea' leftWidget=':scrollArea.Qt Version:_QLabel' type='QComboBox' unnamed='1' visible='1'}
diff --git a/tests/system/shared/build_utils.py b/tests/system/shared/build_utils.py
index 131e6ed556c..c371e9df1ee 100644
--- a/tests/system/shared/build_utils.py
+++ b/tests/system/shared/build_utils.py
@@ -1,3 +1,5 @@
+import re;
+
 # dictionary to hold a list of all installed handler functions for all object-signalSignature pairs
 installedSignalHandlers = {}
 # flag to indicate whether overrideInstallLazySignalHandler() has been called already
@@ -134,3 +136,31 @@ def createTasksFile(list):
     file.close()
     test.log("Written tasks file %s" % outfile)
 
+# returns a list of the build configurations for a target
+# param targetCount specifies the number of targets currently defined (must be correct!)
+# param currentTarget specifies the target for which to switch into the specified settings (zero based index)
+# param filter is a regular expression to filter the configuration by their name
+def iterateBuildConfigs(targetCount, currentTarget, filter = ""):
+    switchViewTo(ViewConstants.PROJECTS)
+    switchToBuildOrRunSettingsFor(targetCount, currentTarget, ProjectSettings.BUILD)
+    configs = []
+    model = waitForObject(":scrollArea.Edit build configuration:_QComboBox", 20000).model()
+    prog = re.compile(filter)
+    for row in range(model.rowCount()):
+        configName = str(model.index(row, 0).data())
+        if prog.match(configName):
+            configs += [configName]
+    switchViewTo(ViewConstants.EDIT)
+    return configs
+
+# selects a build configuration for building the current project
+# param targetCount specifies the number of targets currently defined (must be correct!)
+# param currentTarget specifies the target for which to switch into the specified settings (zero based index)
+# param configName is the name of the configuration that should be selected
+def selectBuildConfig(targetCount, currentTarget, configName):
+    switchViewTo(ViewConstants.PROJECTS)
+    switchToBuildOrRunSettingsFor(targetCount, currentTarget, ProjectSettings.BUILD)
+    if selectFromCombo(":scrollArea.Edit build configuration:_QComboBox", configName):
+        waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}",
+                      "sourceFilesRefreshed(QStringList)")
+    switchViewTo(ViewConstants.EDIT)
diff --git a/tests/system/shared/utils.py b/tests/system/shared/utils.py
index 7d0168178bc..34c8a443138 100644
--- a/tests/system/shared/utils.py
+++ b/tests/system/shared/utils.py
@@ -52,12 +52,16 @@ def verifyEnabled(objectSpec, expectedState = True):
 # param objectSpec  specifies the combo box. It can either be a string determining an object
 #                   or the object itself. If it is an object, it must exist already.
 # param itemName is the item to be selected in the combo box
+# returns True if selection was changed or False if the wanted value was already selected
 def selectFromCombo(objectSpec, itemName):
     object = verifyEnabled(objectSpec)
-    if itemName != str(object.currentText):
+    if itemName == str(object.currentText):
+        return False
+    else:
         mouseClick(object, 5, 5, 0, Qt.LeftButton)
         mouseClick(waitForObjectItem(object, itemName.replace(".", "\\.")), 5, 5, 0, Qt.LeftButton)
         waitFor("str(object.currentText)==itemName", 5000)
+        return True
 
 def selectFromLocator(filter, itemName = None):
     if itemName == None:
diff --git a/tests/system/suite_general/tst_build_speedcrunch/test.py b/tests/system/suite_general/tst_build_speedcrunch/test.py
index 819c79a451e..705d3290736 100644
--- a/tests/system/suite_general/tst_build_speedcrunch/test.py
+++ b/tests/system/suite_general/tst_build_speedcrunch/test.py
@@ -1,5 +1,4 @@
 source("../../shared/qtcreator.py")
-import re;
 
 SpeedCrunchPath = ""
 
@@ -25,33 +24,20 @@ def main():
         test.compare(waitForObject(node).text, value)
 
     fancyToolButton = waitForObject(":*Qt Creator_Core::Internal::FancyToolButton")
-    clickButton(fancyToolButton)
-    listWidget = waitForObject("{occurrence='2' type='ProjectExplorer::Internal::GenericListWidget' unnamed='1' visible='0' "
-                               "window=':QtCreator.MenuBar_ProjectExplorer::Internal::MiniProjectTargetSelector'}")
-    mouseClick(waitForObject(":QtCreator.MenuBar_ProjectExplorer::Internal::MiniProjectTargetSelector"), -5, 5, 0, Qt.LeftButton)
 
-    prog = re.compile("(Desktop )?Qt.*Release")
-    for row in range(listWidget.count):
-        currentItem = listWidget.item(row)
-        if prog.match(str(currentItem.text())):
-            clickButton(fancyToolButton)
-            itemText = currentItem.text()
-            test.log("Testing build configuration: "+str(itemText))
-            if listWidget.currentRow != row:
-                rect = listWidget.visualItemRect(currentItem)
-                mouseClick(listWidget, rect.x+5, rect.y+5, 0, Qt.LeftButton)
-                waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)")
-            mouseClick(waitForObject(":QtCreator.MenuBar_ProjectExplorer::Internal::MiniProjectTargetSelector"), -45, 64, 0, Qt.LeftButton)
-            buildConfig = buildConfigFromFancyToolButtton(fancyToolButton)
-            if buildConfig != currentItem.text():
-                test.fatal("Build configuration %s is selected instead of %s" % (buildConfig, currentItem.text()))
-                continue
-            invokeMenuItem("Build", "Run qmake")
-            waitForSignal("{type='ProjectExplorer::BuildManager' unnamed='1'}", "buildQueueFinished(bool)")
-            invokeMenuItem("Build", "Rebuild All")
-            waitForSignal("{type='ProjectExplorer::BuildManager' unnamed='1'}", "buildQueueFinished(bool)", 300000)
-            checkCompile()
-            checkLastBuild()
+    for config in iterateBuildConfigs(1, 0, "(Desktop )?Qt.*Release"):
+        selectBuildConfig(1, 0, config)
+        buildConfig = buildConfigFromFancyToolButtton(fancyToolButton)
+        if buildConfig != config:
+            test.fatal("Build configuration %s is selected instead of %s" % (buildConfig, config))
+            continue
+        test.log("Testing build configuration: " + config)
+        invokeMenuItem("Build", "Run qmake")
+        waitForSignal("{type='ProjectExplorer::BuildManager' unnamed='1'}", "buildQueueFinished(bool)")
+        invokeMenuItem("Build", "Rebuild All")
+        waitForSignal("{type='ProjectExplorer::BuildManager' unnamed='1'}", "buildQueueFinished(bool)", 300000)
+        checkCompile()
+        checkLastBuild()
 
     # Add a new run configuration
 
-- 
GitLab