2016-01-15 14:55:33 +01:00
|
|
|
############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
# Contact: https://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 https://www.qt.io/terms-conditions. For further
|
|
|
|
|
# information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
#
|
|
|
|
|
# GNU General Public License Usage
|
|
|
|
|
# Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
# General Public License version 3 as published by the Free Software
|
|
|
|
|
# Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
# included in the packaging of this file. Please review the following
|
|
|
|
|
# information to ensure the GNU General Public License requirements will
|
|
|
|
|
# be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
#
|
|
|
|
|
############################################################################
|
2013-05-15 13:17:33 +02:00
|
|
|
|
2012-03-29 12:13:53 +02:00
|
|
|
source("../../shared/qtcreator.py")
|
|
|
|
|
|
|
|
|
|
# entry of test
|
|
|
|
|
def main():
|
2015-07-30 13:12:16 +02:00
|
|
|
clangLoaded = startCreatorTryingClang()
|
2013-02-22 14:31:39 +01:00
|
|
|
if not startedWithoutPluginError():
|
|
|
|
|
return
|
2012-03-29 12:13:53 +02:00
|
|
|
# create qt quick application
|
|
|
|
|
# Step 1: Open test .pro project.
|
|
|
|
|
createNewQtQuickApplication(tempDir(), "SampleApp")
|
2015-12-01 14:05:49 +01:00
|
|
|
for useClang in set([False, clangLoaded]):
|
|
|
|
|
selectClangCodeModel(clangLoaded, useClang)
|
2012-03-29 12:13:53 +02:00
|
|
|
# Step 2: Open .cpp file in Edit mode.
|
2015-07-30 13:12:16 +02:00
|
|
|
if not openDocument("SampleApp.Sources.main\\.cpp"):
|
|
|
|
|
test.fatal("Could not open main.cpp")
|
|
|
|
|
invokeMenuItem("File", "Exit")
|
|
|
|
|
return
|
|
|
|
|
test.verify(checkIfObjectExists(":Qt Creator_CppEditor::Internal::CPPEditorWidget"),
|
|
|
|
|
"Step 2: Verifying if: .cpp file is opened in Edit mode.")
|
2012-03-29 12:13:53 +02:00
|
|
|
# Steps 3&4: Insert text "class" to new line in Editor mode and press Ctrl+Space.
|
|
|
|
|
# Focus "class derived from QObject" in the list and press Tab or Enter to complete the code.
|
2015-07-30 13:12:16 +02:00
|
|
|
editorWidget = findObject(":Qt Creator_CppEditor::Internal::CPPEditorWidget")
|
|
|
|
|
mouseClick(editorWidget, 5, 5, 0, Qt.LeftButton)
|
|
|
|
|
type(editorWidget, "<Return>")
|
|
|
|
|
type(editorWidget, "<Up>")
|
|
|
|
|
type(editorWidget, "class")
|
|
|
|
|
if platform.system() == "Darwin":
|
|
|
|
|
type(editorWidget, "<Meta+Space>")
|
|
|
|
|
else:
|
|
|
|
|
type(editorWidget, "<Ctrl+Space>")
|
|
|
|
|
listView = waitForObject(":popupFrame_Proposal_QListView")
|
2015-08-06 18:14:56 +02:00
|
|
|
shownProposals = dumpItems(listView.model())
|
|
|
|
|
usedProposal = "class derived from QObject"
|
|
|
|
|
expectedProposals = ["class", "class ", "class template",
|
|
|
|
|
usedProposal, "class derived from QWidget"]
|
|
|
|
|
test.compare(len(shownProposals), len(expectedProposals), "Number of proposed templates")
|
|
|
|
|
test.compare(set(shownProposals), set(expectedProposals),
|
|
|
|
|
"Expected proposals shown, ignoring order?")
|
|
|
|
|
doubleClickItem(listView, usedProposal, 5, 5, 0, Qt.LeftButton)
|
|
|
|
|
pattern = ("(?<=class)\s+name\s*:\s*public\s+QObject\s*\{\s*Q_OBJECT\s+"
|
|
|
|
|
"public:\s+name\(\)\s*\{\}\s+virtual\s+~name\(\)\s*\{\}\s+\};")
|
|
|
|
|
test.verify(re.search(pattern, str(editorWidget.plainText)),
|
|
|
|
|
"Code with several variables is inserted?")
|
2012-03-29 12:13:53 +02:00
|
|
|
# Step 5: Press Tab to move between the variables and specify values for them. For example write "Myname" for variable "name".
|
2015-07-30 13:12:16 +02:00
|
|
|
type(editorWidget, "<Tab>")
|
|
|
|
|
type(editorWidget, "<Tab>")
|
|
|
|
|
type(editorWidget, "<Tab>")
|
|
|
|
|
type(editorWidget, "Myname")
|
2015-08-06 18:14:56 +02:00
|
|
|
result = re.search(pattern.replace("name", "Myname"), str(editorWidget.plainText))
|
2015-07-30 13:12:16 +02:00
|
|
|
if result:
|
|
|
|
|
test.passes("Step 5: Verifying if: A value for a variable is inserted and all "
|
|
|
|
|
"instances of the variable within the snippet are renamed.")
|
|
|
|
|
else:
|
|
|
|
|
test.fail("Step 5: Seems that not all instances of variable had been renamed "
|
|
|
|
|
"- Content of editor:\n%s" % editorWidget.plainText)
|
|
|
|
|
invokeMenuItem('File', 'Revert "main.cpp" to Saved')
|
|
|
|
|
clickButton(waitForObject(":Revert to Saved.Proceed_QPushButton"))
|
|
|
|
|
snooze(1) # 'Close "main.cpp"' might still be disabled
|
|
|
|
|
# editor must be closed to get the second code model applied on re-opening the file
|
|
|
|
|
invokeMenuItem('File', 'Close "main.cpp"')
|
2012-03-29 12:13:53 +02:00
|
|
|
# exit qt creator
|
|
|
|
|
invokeMenuItem("File", "Exit")
|