diff options
author | Robert Löhning <robert.loehning@qt.io> | 2023-12-04 19:12:39 +0100 |
---|---|---|
committer | Robert Löhning <robert.loehning@qt.io> | 2024-01-12 16:46:58 +0000 |
commit | f9a0d18ddcaea037c24e145f694a969fc2f0dfd9 (patch) | |
tree | 7910912eaf973221e7e65509fedf41c7e0ddb1a8 | |
parent | 6dee879e48ca8430a3d0734dea3ddb7a6e329c6a (diff) |
Squish: Add test for files created by project wizards
Change-Id: I6a639cffc150188710187155f4d06ac6914dd93b
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r-- | Tests/system/Readme.txt | 2 | ||||
-rw-r--r-- | Tests/system/suite_configuration/shared/scripts/names.py | 11 | ||||
-rw-r--r-- | Tests/system/suite_configuration/suite.conf | 2 | ||||
-rw-r--r-- | Tests/system/suite_configuration/tst_new_project_file_creation/test.py | 111 |
4 files changed, 125 insertions, 1 deletions
diff --git a/Tests/system/Readme.txt b/Tests/system/Readme.txt index 596d423b..a9490b49 100644 --- a/Tests/system/Readme.txt +++ b/Tests/system/Readme.txt @@ -21,3 +21,5 @@ SQUISH_VSTOOLS_VERSION: The expected version of Qt VS Tools SQUISH_VSTOOLS_QTDIRS: A list of Qt installations to be used by the tests, i.e. the paths to the parent directories of the respective Qt versions' bin-directories, separated by semicola. +SQUISH_VSTOOLS_WORKDIR: A directory in which the tests may create projects. + Please note: The tests may remove contents from this directory. diff --git a/Tests/system/suite_configuration/shared/scripts/names.py b/Tests/system/suite_configuration/shared/scripts/names.py index 18bc4b7c..8759686d 100644 --- a/Tests/system/suite_configuration/shared/scripts/names.py +++ b/Tests/system/suite_configuration/shared/scripts/names.py @@ -45,3 +45,14 @@ no_Qt_version_Label = {"container": qt_Wizard_Window, "id": "ErrorMsg", "type": qt_Wizard_Finish_Button = {"container": qt_Wizard_Window, "text": "Finish", "type": "Button"} lower_case_file_names_CheckBox = {"container": qt_Wizard_Window, "text": "Lower case file names", "type": "CheckBox"} +file_Close_Solution_MenuItem = {"container": globalnames.file_MenuItem, "text": "Close Solution", + "type": "MenuItem"} +microsoft_Visual_Studio_Create_a_new_project_Label = {"container": + globalnames.microsoft_Visual_Studio_Window, + "text": "Create a _new project", + "type": "Label"} +qt_Microsoft_Visual_Studio_cpp_TabItem = {"container":globalnames.microsoft_Visual_Studio_Window, + "text": RegularExpression(".*Qt.*\.cpp$|^main\.(cpp|qml)$"), + "type": "TabItem"} +qt_cpp_Label = {"container": qt_Microsoft_Visual_Studio_cpp_TabItem, + "text": RegularExpression(".+\.(cpp|qml)$"), "type": "Label"} diff --git a/Tests/system/suite_configuration/suite.conf b/Tests/system/suite_configuration/suite.conf index f2197549..f8bc6333 100644 --- a/Tests/system/suite_configuration/suite.conf +++ b/Tests/system/suite_configuration/suite.conf @@ -3,6 +3,6 @@ ENVVARS=envvars IMPLICITAUTSTART=0 LANGUAGE=Python OBJECTMAPSTYLE=script -TEST_CASES=tst_add_remove_qt_versions tst_new_project_defaults tst_new_project_edit tst_new_project_no_qt +TEST_CASES=tst_add_remove_qt_versions tst_new_project_defaults tst_new_project_edit tst_new_project_file_creation tst_new_project_no_qt VERSION=3 WRAPPERS=Windows diff --git a/Tests/system/suite_configuration/tst_new_project_file_creation/test.py b/Tests/system/suite_configuration/tst_new_project_file_creation/test.py new file mode 100644 index 00000000..36fae76b --- /dev/null +++ b/Tests/system/suite_configuration/tst_new_project_file_creation/test.py @@ -0,0 +1,111 @@ +#################################################################################################### +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#################################################################################################### + +# -*- coding: utf-8 -*- + +source("../shared/scripts/config_utils.py") + +import os +import re +import shutil + +from newprojectdialog import NewProjectDialog +import names + + +def fixAppContext(): + waitFor("len(applicationContextList()) > 1", 10000) + appContexts = applicationContextList() + if len(appContexts) == 1: # Might have changed after waitFor() + if appContexts[0].name != "devenv": + test.fatal("The only application context is " + appContexts[0].name) + else: + for ctxt in appContexts: + if ctxt.name == "devenv": + setApplicationContext(ctxt) + return + test.fatal("There's no devenv application context, only: " + appContexts) + + +def testCompareRegex(text, pattern, message): + regex = re.compile(pattern) + test.verify(regex.match(text), '%s ("%s"/"%s")' % (message, text, pattern)) + + +workDir = os.getenv("SQUISH_VSTOOLS_WORKDIR") +createdProjects = set() + + +def main(): + qtDirs = readQtDirs() + if not qtDirs: + test.fatal("No Qt versions known", "Did you set SQUISH_VSTOOLS_QTDIRS correctly?") + return + if not workDir: + test.fatal("No directory for creating projects known", + "Did you set SQUISH_VSTOOLS_WORKDIR correctly?") + return + version = startAppGetVersion() + if not version: + return + if not configureQtVersions(version, qtDirs): + closeMainWindow() + return + + with NewProjectDialog() as dialog: + dialog.filterForQtProjects() + listedTemplates = list(dialog.getListedTemplates()) + + expectedFiles = {"Qt Designer Custom Widget": "^QtDesigner.*\.cpp$", + "Qt Console Application": "^main\.cpp$", + "Qt ActiveQt Server": "^ActiveQtServer\d*\.cpp$", + "Qt Quick Application": "^main\.qml$", + "Qt Empty Application": None, + "Qt Class Library": "^QtClassLibrary\d*\.cpp$", + "Qt Widgets Application": "^QtWidgets.*\.cpp$"} + + with NewProjectDialog() as dialog: + for listItem, templateName in listedTemplates: + with TestSection(templateName): + if not templateName in expectedFiles: + test.warning("Template %s is not supported, skipping..." % templateName) + continue + mouseClick(waitForObject(listItem)) + clickButton(waitForObject(names.microsoft_Visual_Studio_Next_Button)) + type(waitForObject(names.comboBox_Edit), workDir) + waitFor("waitForObject(names.comboBox_Edit).text == workDir") + createdProjects.add(waitForObjectExists(names.microsoft_Visual_Studio_Project_name_Edit).text) + clickButton(waitForObject(names.microsoft_Visual_Studio_Create_Button)) + fixAppContext() + clickButton(waitForObject(names.qt_Wizard_Next_Button)) + if templateName in ["Qt ActiveQt Server", + "Qt Class Library", + "Qt Designer Custom Widget", + "Qt Widgets Application"]: + clickButton(waitForObject(names.qt_Wizard_Next_Button)) + clickButton(waitForObject(names.qt_Wizard_Finish_Button)) + fixAppContext() + if expectedFiles[templateName]: + try: + testCompareRegex(waitForObjectExists(names.qt_cpp_Label).text, + expectedFiles[templateName], + "Was a file with an expected name opened?") + except: + test.fail("There was no expected file opened for %s" % templateName) + else: + test.exception("waitForObjectExists(names.qt_cpp_Label)", + "No file should be opened for %s" % templateName) + mouseClick(waitForObject(globalnames.file_MenuItem)) + mouseClick(waitForObject(names.file_Close_Solution_MenuItem)) + # reopens the "New Project" dialog + mouseClick(waitForObject(names.microsoft_Visual_Studio_Create_a_new_project_Label)) + clearQtVersions(version) + closeMainWindow() + + +def cleanup(): + if workDir: + for project in createdProjects: + shutil.rmtree(os.path.join(workDir, project)) |