forked from qt-creator/qt-creator
Squish: Add test for creating new C++ class
Task-number: QTCREATORBUG-14949 Change-Id: Ie42471f174eaacab2810eec12c2af4201a9374fe Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -127,6 +127,7 @@
|
||||
:QmlJSTools::Internal::QmlConsoleEdit {columnIndex='0' container=':DebugModeWidget_QmlJSTools::Internal::QmlConsoleView' rowIndex='0' type='QmlJSTools::Internal::QmlConsoleEdit' unnamed='1' visible='1'}
|
||||
:Qt Creator.Add Bookmark_QToolButton {text='Add Bookmark' type='QToolButton' unnamed='1' visible='1' window=':Qt Creator_Core::Internal::MainWindow'}
|
||||
:Qt Creator.Analyzer Toolbar_QDockWidget {name='Analyzer Toolbar' type='QDockWidget' visible='1' window=':Qt Creator_Core::Internal::MainWindow' windowTitle='Analyzer Toolbar'}
|
||||
:Qt Creator.CloseDoc_QToolButton {toolTip?='Close Document *' type='QToolButton' unnamed='1' visible='1' window=':Qt Creator_Core::Internal::MainWindow'}
|
||||
:Qt Creator.CloseFind_QToolButton {name='close' type='QToolButton' visible='1' window=':Qt Creator_Core::Internal::MainWindow'}
|
||||
:Qt Creator.Compile Output_Core::OutputWindow {type='Core::OutputWindow' unnamed='1' visible='1' window=':Qt Creator_Core::Internal::MainWindow' windowTitle='Compile Output'}
|
||||
:Qt Creator.DebugModeWidget_QSplitter {name='DebugModeWidget' type='QSplitter' visible='1' window=':Qt Creator_Core::Internal::MainWindow'}
|
||||
|
@@ -174,8 +174,8 @@ def __selectQtVersionDesktop__(checks, available=None):
|
||||
clickButton(waitForObject(":Next_QPushButton"))
|
||||
return checkedTargets
|
||||
|
||||
def __createProjectHandleLastPage__(expectedFiles = None, addToVersionControl = "<None>", addToProject = None):
|
||||
if expectedFiles != None:
|
||||
def __createProjectHandleLastPage__(expectedFiles=[], addToVersionControl="<None>", addToProject=None):
|
||||
if len(expectedFiles):
|
||||
summary = waitForObject("{name='filesLabel' text?='<qt>Files to be added in<pre>*</pre>' "
|
||||
"type='QLabel' visible='1'}").text
|
||||
verifyItemOrder(expectedFiles, summary)
|
||||
@@ -241,7 +241,7 @@ def createProject_Qt_GUI(path, projectName, checks = True, addToVersionControl =
|
||||
|
||||
clickButton(waitForObject(":Next_QPushButton"))
|
||||
|
||||
expectedFiles = None
|
||||
expectedFiles = []
|
||||
if checks:
|
||||
if platform.system() in ('Windows', 'Microsoft'):
|
||||
path = os.path.abspath(path)
|
||||
@@ -264,7 +264,7 @@ def createProject_Qt_Console(path, projectName, checks = True):
|
||||
__createProjectSetNameAndPath__(path, projectName, checks)
|
||||
checkedTargets = __selectQtVersionDesktop__(checks, available)
|
||||
|
||||
expectedFiles = None
|
||||
expectedFiles = []
|
||||
if checks:
|
||||
if platform.system() in ('Windows', 'Microsoft'):
|
||||
path = os.path.abspath(path)
|
||||
@@ -734,20 +734,47 @@ def compareProjectTree(rootObject, dataset):
|
||||
return
|
||||
test.passes("No errors found in project tree")
|
||||
|
||||
def addCPlusPlusFileToCurrentProject(name, template, forceOverwrite=False, addToVCS = "<None>"):
|
||||
# creates C++ file(s) and adds them to the current project if one is open
|
||||
# name name of the created object: filename for files, classname for classes
|
||||
# template "C++ Class", "C++ Header File" or "C++ Source File"
|
||||
# forceOverwrite bool: force overwriting existing files?
|
||||
# addToVCS name of VCS to add the file(s) to
|
||||
# newBasePath path to create the file(s) at
|
||||
# expectedSourceName expected name of created source file
|
||||
# expectedHeaderName expected name of created header file
|
||||
def addCPlusPlusFileToCurrentProject(name, template, forceOverwrite=False, addToVCS="<None>",
|
||||
newBasePath=None, expectedSourceName=None, expectedHeaderName=None):
|
||||
if name == None:
|
||||
test.fatal("File must have a name - got None.")
|
||||
return
|
||||
__createProjectOrFileSelectType__(" C++", template, isProject=False)
|
||||
window = "{type='ProjectExplorer::JsonWizard' unnamed='1' visible='1'}"
|
||||
basePath = str(waitForObject("{type='Utils::FancyLineEdit' unnamed='1' visible='1' "
|
||||
"window=%s}" % window).text)
|
||||
lineEdit = waitForObject("{name='nameLineEdit' type='Utils::FileNameValidatingLineEdit' "
|
||||
"visible='1' window=%s}" % window)
|
||||
basePathEdit = waitForObject("{type='Utils::FancyLineEdit' unnamed='1' visible='1' "
|
||||
"window=%s}" % window)
|
||||
if newBasePath:
|
||||
replaceEditorContent(basePathEdit, newBasePath)
|
||||
basePath = str(basePathEdit.text)
|
||||
lineEdit = None
|
||||
if template == "C++ Class":
|
||||
lineEdit = waitForObject("{name='Class' type='QLineEdit' visible='1'}")
|
||||
else:
|
||||
lineEdit = waitForObject("{name='nameLineEdit' type='Utils::FileNameValidatingLineEdit' "
|
||||
"visible='1' window=%s}" % window)
|
||||
replaceEditorContent(lineEdit, name)
|
||||
expectedFiles = []
|
||||
if expectedSourceName:
|
||||
expectedFiles += [expectedSourceName]
|
||||
if template == "C++ Class":
|
||||
test.compare(str(waitForObject("{name='SrcFileName' type='QLineEdit' visible='1'}").text),
|
||||
expectedSourceName)
|
||||
if expectedHeaderName:
|
||||
expectedFiles += [expectedHeaderName]
|
||||
if template == "C++ Class":
|
||||
test.compare(str(waitForObject("{name='HdrFileName' type='QLineEdit' visible='1'}").text),
|
||||
expectedHeaderName)
|
||||
clickButton(waitForObject(":Next_QPushButton"))
|
||||
fileExistedBefore = os.path.exists(os.path.join(basePath, name))
|
||||
__createProjectHandleLastPage__(addToVersionControl = addToVCS)
|
||||
__createProjectHandleLastPage__(expectedFiles, addToVersionControl=addToVCS)
|
||||
if (fileExistedBefore):
|
||||
overwriteDialog = "{type='Core::Internal::PromptOverwriteDialog' unnamed='1' visible='1'}"
|
||||
waitForObject(overwriteDialog)
|
||||
|
@@ -7,6 +7,6 @@ HOOK_SUB_PROCESSES=false
|
||||
IMPLICITAUTSTART=0
|
||||
LANGUAGE=Python
|
||||
OBJECTMAP=../objects.map
|
||||
TEST_CASES=tst_build_speedcrunch tst_cmake_speedcrunch tst_create_proj_wizard tst_default_settings tst_installed_languages tst_opencreator_qbs tst_openqt_creator tst_rename_file tst_save_before_build tst_session_handling tst_tasks_handling
|
||||
TEST_CASES=tst_build_speedcrunch tst_cmake_speedcrunch tst_create_proj_wizard tst_default_settings tst_installed_languages tst_new_class tst_opencreator_qbs tst_openqt_creator tst_rename_file tst_save_before_build tst_session_handling tst_tasks_handling
|
||||
VERSION=2
|
||||
WRAPPERS=Qt
|
||||
|
73
tests/system/suite_general/tst_new_class/test.py
Normal file
73
tests/system/suite_general/tst_new_class/test.py
Normal file
@@ -0,0 +1,73 @@
|
||||
#############################################################################
|
||||
##
|
||||
## Copyright (C) 2015 The Qt Company Ltd.
|
||||
## Contact: http://www.qt.io/licensing
|
||||
##
|
||||
## This file is part of Qt Creator.
|
||||
##
|
||||
## Commercial License Usage
|
||||
## Licensees holding valid commercial Qt licenses may use this file in
|
||||
## accordance with the commercial license agreement provided with the
|
||||
## Software or, alternatively, in accordance with the terms contained in
|
||||
## a written agreement between you and The Qt Company. For licensing terms and
|
||||
## conditions see http://www.qt.io/terms-conditions. For further information
|
||||
## use the contact form at http://www.qt.io/contact-us.
|
||||
##
|
||||
## GNU Lesser General Public License Usage
|
||||
## Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
## General Public License version 2.1 or version 3 as published by the Free
|
||||
## Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
## LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
## following information to ensure the GNU Lesser General Public License
|
||||
## requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
##
|
||||
## In addition, as a special exception, The Qt Company gives you certain additional
|
||||
## rights. These rights are described in The Qt Company LGPL Exception
|
||||
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
##
|
||||
#############################################################################
|
||||
|
||||
source("../../shared/qtcreator.py")
|
||||
|
||||
def main():
|
||||
newClassName = "MyNewClass"
|
||||
headerFileName = newClassName.lower() + ".h"
|
||||
sourceFileName = newClassName.lower() + ".cpp"
|
||||
startApplication("qtcreator" + SettingsPath)
|
||||
if not startedWithoutPluginError():
|
||||
return
|
||||
addCPlusPlusFileToCurrentProject(newClassName, "C++ Class", newBasePath=tempDir(),
|
||||
expectedSourceName=sourceFileName,
|
||||
expectedHeaderName=headerFileName)
|
||||
|
||||
mainWindow = waitForObject(":Qt Creator_Core::Internal::MainWindow")
|
||||
if test.verify(waitFor("sourceFileName in str(mainWindow.windowTitle)", 1000),
|
||||
"Source file was opened on time?"):
|
||||
editor = waitForObject(":Qt Creator_CppEditor::Internal::CPPEditorWidget")
|
||||
editorText = str(editor.plainText)
|
||||
mouseClick(editor) # enable menu items for file
|
||||
test.verify('#include "%s"' % headerFileName in editorText,
|
||||
"Header included in source file?")
|
||||
test.verify(newClassName + "::" + newClassName + "()" in editorText,
|
||||
"Ctor implementation in source file?")
|
||||
clickButton(waitForObject(":Qt Creator.CloseDoc_QToolButton"))
|
||||
if test.verify(waitFor("headerFileName in str(mainWindow.windowTitle)", 1000),
|
||||
"Header file was shown after closing source?"):
|
||||
editor = waitForObject(":Qt Creator_CppEditor::Internal::CPPEditorWidget")
|
||||
editorText = str(editor.plainText)
|
||||
includeGuard = newClassName.upper().replace(".", "_")
|
||||
test.verify("#ifndef " + includeGuard in editorText,
|
||||
"Include guard check in header file?")
|
||||
test.verify("#define " + includeGuard in editorText,
|
||||
"Include guard definition in header file?")
|
||||
test.verify("class " + newClassName in editorText,
|
||||
"Class definition in header file?")
|
||||
test.verify(" " + newClassName + "();" in editorText,
|
||||
"Ctor declaration in header file?")
|
||||
test.verify("signals" not in editorText, # QTCREATORBUG-14949
|
||||
"No signals in non-Qt header file?")
|
||||
test.verify("slots" not in editorText, # QTCREATORBUG-14949
|
||||
"No slots in non-Qt header file?")
|
||||
invokeMenuItem("File", "Exit")
|
||||
return
|
Reference in New Issue
Block a user