1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# Copyright (C) 2016 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
source("../../shared/qtcreator.py")
class ExpectedResult:
def __init__(self, file, lineNumber, lineContent):
self.file = file
self.lineNumber = lineNumber
self.lineContent = lineContent
# check if usage in code (expectedText) is found in resultsView
def checkUsages(resultsView, expectedResults, directory):
# wait for results
resultsModel = resultsView.model()
waitFor("resultsModel.rowCount() > 0", 5000)
expectedResultIndex = 0
for index in dumpIndices(resultsModel):
# enum Roles { ResultItemRole = Qt::UserRole, ResultLineRole, ResultLineNumberRole, ResultIconRole,
# SearchTermStartRole, SearchTermLengthRole, IsGeneratedRole };
# get only filename not full path
fullPath = str(index.data(Qt.UserRole + 1).toString())
if not fullPath.startswith(directory):
test.warning("Skipping '%s' due to known issue (QTCREATORBUG-11984)" % fullPath)
continue
resultFile = fullPath.replace("\\", "/").split('/')[-1]
for chIndex in dumpIndices(resultsModel, index):
resultLine = str(chIndex.data(Qt.UserRole + 1).toString()).strip()
resultLineNumber = chIndex.data(Qt.UserRole + 2).toInt()
# verify if we don't get more results
if expectedResultIndex >= len(expectedResults):
test.log("More results than expected")
return False
# check expected text
if (not test.compare(expectedResults[expectedResultIndex].file, resultFile, "Result file comparison") or
not test.compare(expectedResults[expectedResultIndex].lineNumber, resultLineNumber, "Result line number comparison") or
not test.compare(expectedResults[expectedResultIndex].lineContent, resultLine, "Result line content comparison")):
return False
expectedResultIndex += 1
# verify if we get all results
if expectedResultIndex < len(expectedResults):
test.log("Less results than expected")
return False
return True
def main():
# prepare example project
sourceExample = os.path.join(QtPath.examplesPath(Targets.DESKTOP_5_14_1_DEFAULT),
"quick", "animation")
proFile = "animation.pro"
if not neededFilePresent(os.path.join(sourceExample, proFile)):
return
# copy example project to temp directory
templateDir = prepareTemplate(sourceExample)
examplePath = os.path.join(templateDir, proFile)
templateDir = os.path.join(templateDir, "basics") # only check subproject
startQC()
if not startedWithoutPluginError():
return
# open example project
openQmakeProject(examplePath, [Targets.DESKTOP_5_14_1_DEFAULT])
# open qml file
openDocument("animation.Resources.animation\\.qrc./animation.basics.color-animation\\.qml")
# get editor
editorArea = waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget")
# 1. check usages using context menu
# place cursor to component
if not placeCursorToLine(editorArea, "Rectangle {"):
invokeMenuItem("File", "Exit")
return
for _ in range(5):
type(editorArea, "<Left>")
invokeContextMenuItem(editorArea, "Find References to Symbol Under Cursor")
# check if usage was properly found
expectedResults = [ExpectedResult("color-animation.qml", 59, "Rectangle {"),
ExpectedResult("color-animation.qml", 119, "Rectangle {"),
ExpectedResult("property-animation.qml", 58, "Rectangle {"),
ExpectedResult("property-animation.qml", 67, "Rectangle {")]
resultsView = waitForObject(":Qt Creator_Find::Internal::SearchResultTreeView")
test.verify(checkUsages(resultsView, expectedResults, templateDir),
"Verifying if usages were properly found using context menu.")
# clear previous results & prepare for next search
clickButton(waitForObject(":*Qt Creator.Clear_QToolButton"))
mouseClick(editorArea)
# 2. check usages using menu
# place cursor to component
if not placeCursorToLine(editorArea, "anchors { left: parent.left; top: parent.top; right: parent.right; bottom: parent.verticalCenter }"):
invokeMenuItem("File", "Exit")
return
for _ in range(87):
type(editorArea, "<Left>")
invokeMenuItem("Tools", "QML/JS", "Find References to Symbol Under Cursor")
# check if usage was properly found
expectedResults = [ExpectedResult("color-animation.qml", 60, "anchors { left: parent.left; top: parent.top; right: parent.right; bottom: parent.verticalCenter }"),
ExpectedResult("color-animation.qml", 120, "anchors { left: parent.left; top: parent.verticalCenter; right: parent.right; bottom: parent.bottom }"),
ExpectedResult("property-animation.qml", 59, "anchors { left: parent.left; top: parent.top; right: parent.right; bottom: parent.verticalCenter }"),
ExpectedResult("property-animation.qml", 68, "anchors { left: parent.left; top: parent.verticalCenter; right: parent.right; bottom: parent.bottom }")]
resultsView = waitForObject(":Qt Creator_Find::Internal::SearchResultTreeView")
test.verify(checkUsages(resultsView, expectedResults, templateDir),
"Verifying if usages were properly found using main menu.")
# clear previous results & prepare for next search
clickButton(waitForObject(":*Qt Creator.Clear_QToolButton"))
mouseClick(editorArea)
# 3. check usages using keyboard shortcut
# place cursor to component
if not placeCursorToLine(editorArea, "SequentialAnimation on opacity {"):
invokeMenuItem("File", "Exit")
return
for _ in range(5):
type(editorArea, "<Left>")
type(editorArea, "<Ctrl+Shift+u>")
# check if usage was properly found
expectedResults = [ExpectedResult("color-animation.qml", 103, "SequentialAnimation on opacity {")]
resultsView = waitForObject(":Qt Creator_Find::Internal::SearchResultTreeView")
test.verify(checkUsages(resultsView, expectedResults, templateDir),
"Verifying if usages were properly found using shortcut.")
#save and exit
invokeMenuItem("File", "Exit")
|