Commit 4e0421ed authored by Christian Stenger's avatar Christian Stenger
Browse files

Squish: Add hovering test



Change-Id: I78a8e855a3b276c1549b57002ced88af3245ccdd
Reviewed-by: default avatarBill King <bill.king@nokia.com>
parent 5c56953a
......@@ -15,8 +15,10 @@
:New.templatesView_QListView {name='templatesView' type='QListView' visible='1' window=':New_Core::Internal::NewDialog'}
:New_Core::Internal::NewDialog {name='Core__Internal__NewDialog' type='Core::Internal::NewDialog' visible='1' windowTitle='New'}
:Next_QPushButton {text~='(Next.*|Continue)' type='QPushButton' visible='1'}
:Options.OK_QPushButton {text='OK' type='QPushButton' unnamed='1' visible='1' window=':Options_Core::Internal::SettingsDialog'}
:Options.qt_tabwidget_tabbar_QTabBar {name='qt_tabwidget_tabbar' type='QTabBar' visible='1' window=':Options_Core::Internal::SettingsDialog'}
:Options_Core::Internal::SettingsDialog {type='Core::Internal::SettingsDialog' unnamed='1' visible='1' windowTitle~='(Options|Preferences)'}
:Options_QListView {type='QListView' unnamed='1' visible='1' window=':Options_Core::Internal::SettingsDialog'}
:Project Setup.scrollArea_QScrollArea {name='scrollArea' type='QScrollArea' visible='1' window=':Project Setup_Qt4ProjectManager::Internal::ProjectLoadWizard'}
:Project Setup_Qt4ProjectManager::Internal::ProjectLoadWizard {type='Qt4ProjectManager::Internal::ProjectLoadWizard' unnamed='1' visible='1' windowTitle='Project Setup'}
:Qt Creator.QtCreator.MenuBar_QMenuBar {name='QtCreator.MenuBar' type='QMenuBar' visible='1' window=':Qt Creator_Core::Internal::MainWindow'}
......
......@@ -73,3 +73,117 @@ def typeLines(editor, lines):
type(editor, "<Enter>")
else:
test.warning("Illegal parameter passed to typeLines()")
# function to verify hoverings on e.g. code inside of the given editor
# param editor the editor object
# param lines a list/tuple of regex that indicates which lines should be verified
# param additionalKeyPresses an array holding the additional typings to do (special chars for cursor movement)
# to get to the location (inside line) where to trigger the hovering (must be the same for all lines)
# param expectedTypes list/tuple holding the type of the (tool)tips that should occur (for each line)
# param expectedValues list/tuple of dict or list/tuple of strings regarding the types that have been used
# if it's a dict it indicates a property value pair, if it's a string it is type specific (e.g. color value for ColorTip)
# param alternativeValues same as expectedValues, but here you can submit alternatives - this is for example
# necessary if you do not add the correct documentation (from where the tip gets its content)
def verifyHoveringOnEditor(editor, lines, additionalKeyPresses, expectedTypes, expectedValues, alternativeValues=None):
counter = 0
for line in lines:
expectedVals = expectedValues[counter]
expectedType = expectedTypes[counter]
altVal = None
if isinstance(alternativeValues, (list, tuple)):
altVal = alternativeValues[counter]
counter += 1
placeCursorToLine(editor, line, True)
for ty in additionalKeyPresses:
type(editor, ty)
rect = editor.cursorRect(editor.textCursor())
sendEvent("QMouseEvent", editor, QEvent.MouseMove, rect.x+rect.width/2, rect.y+rect.height/2, Qt.NoButton, 0)
try:
tip = waitForObject("{type='%s' visible='1'}" % expectedType)
except:
tip = None
if tip == None:
test.warning("Could not get %s for line containing pattern '%s'" % (expectedType,line))
else:
if expectedType == "ColorTip":
__handleColorTips__(tip, expectedVals)
elif expectedType == "TextTip":
__handleTextTips__(tip, expectedVals, altVal)
elif expectedType == "WidgetTip":
test.warning("Sorry - WidgetTip checks aren't implemented yet.")
sendEvent("QMouseEvent", editor, QEvent.MouseMove, 0, -50, Qt.NoButton, 0)
waitFor("isNull(tip)")
# helper function that handles verification of TextTip hoverings
# param textTip the TextTip object
# param expectedVals a dict holding property value pairs that must match
def __handleTextTips__(textTip, expectedVals, alternativeVals):
props = object.properties(textTip)
expFail = altFail = False
eResult = verifyProperties(props, expectedVals)
for val in eResult.itervalues():
if not val:
expFail = True
break
if expFail and alternativeVals != None:
aResult = verifyProperties(props, alternativeVals)
else:
altFail = True
aResult = None
if not expFail:
test.passes("TextTip verified")
else:
for key,val in eResult.iteritems():
if val == False:
if aResult and aResult.get(key):
test.passes("Property '%s' does not match expected, but alternative value" % key)
else:
aVal = None
if alternativeVals:
aVal = alternativeVals.get(key, None)
if aVal:
test.fail("Property '%s' does not match - expected '%s' or '%s', got '%s'" % (key, expectedVals.get(key), aVal, props.get(key)))
else:
test.fail("Property '%s' does not match - expected '%s', got '%s" % (key, expectedVals.get(key), props.get(key)))
else:
test.fail("Property '%s' could not be found inside properties" % key)
# helper function that handles verification of ColorTip hoverings
# param colTip the ColorTip object
# param expectedColor a single string holding the color the ColorTip should have
# Attention: because of being a non-standard Qt object it's not possible to
# verify colors which are (semi-)transparent!
def __handleColorTips__(colTip, expectedColor):
cmp = QColor()
cmp.setNamedColor(expectedColor)
if cmp.alpha() != 255:
test.warning("Cannot handle transparent colors - cancelling this verification")
return
dPM = QPixmap.grabWidget(colTip, 1, 1, colTip.width-2, colTip.height-2)
img = dPM.toImage()
rgb = img.pixel(1, 1)
rgb = QColor(rgb)
if rgb.rgba() == cmp.rgba():
test.passes("ColorTip verified")
else:
test.fail("ColorTip does not match - expected color '%s' got '%s'" % (rgb.rgb(), cmp.rgb()))
# function that checks whether all expected properties (including their values)
# match the given properties
# param properties a dict holding the properties to check
# param expectedProps a dict holding the key value pairs that must be found inside properties
# this function returns a dict holding the keys of the expectedProps - the value of each key
# is a boolean that indicates whether this key could have been found inside properties and
# the values matched or None if the key could not be found
def verifyProperties(properties, expectedProps):
if not isinstance(properties, dict) or not isinstance(expectedProps, dict):
test.warning("Wrong usage - both parameter must be of type dict")
return {}
result = {}
for key,val in expectedProps.iteritems():
foundVal = properties.get(key, None)
if foundVal != None:
result[key] = val == foundVal
else:
result[key] = None
return result
......@@ -183,3 +183,34 @@ def getOutputFromCmdline(cmdline):
result = versCall.communicate()[0]
versCall.stdout.close()
return result
# add qt.qch from SDK path
def addHelpDocumentationFromSDK():
global sdkPath
doc = "%s/Documentation/qt.qch" % sdkPath
invokeMenuItem("Tools", "Options...")
waitForObjectItem(":Options_QListView", "Help")
clickItem(":Options_QListView", "Help", 14, 15, 0, Qt.LeftButton)
waitForObject("{container=':Options.qt_tabwidget_tabbar_QTabBar' type='TabItem' text='Documentation'}")
clickTab(waitForObject(":Options.qt_tabwidget_tabbar_QTabBar"), "Documentation")
# get rid of all docs already registered
listWidget = waitForObject("{type='QListWidget' name='docsListWidget' visible='1'}")
for i in range(listWidget.count):
rect = listWidget.visualItemRect(listWidget.item(0))
mouseClick(listWidget, rect.x+5, rect.y+5, 0, Qt.LeftButton)
mouseClick(waitForObject("{type='QPushButton' name='removeButton' visible='1'}"), 5, 5, 0, Qt.LeftButton)
clickButton(waitForObject("{type='QPushButton' name='addButton' visible='1' text='Add...'}"))
if platform.system() == "Darwin":
snooze(1)
nativeType("<Command+Shift+g>")
snooze(1)
nativeType(doc)
snooze(1)
nativeType("<Return>")
snooze(2)
nativeType("<Return>")
else:
pathLine = waitForObject("{name='fileNameEdit' type='QLineEdit' visible='1'}")
replaceEditorContent(pathLine, os.path.abspath(doc))
type(pathLine, "<Return>")
clickButton(waitForObject(":Options.OK_QPushButton"))
......@@ -9,6 +9,8 @@ def main():
if not neededFilePresent(sourceExample):
return
startApplication("qtcreator" + SettingsPath)
# add docs to have the correct tool tips
addHelpDocumentationFromSDK()
# using a temporary directory won't mess up an eventually exisiting
workingDir = tempDir()
prepareTemplate(sourceExample)
......@@ -18,6 +20,7 @@ def main():
waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)")
testRenameId()
testFindUsages()
testHovering()
invokeMenuItem("File", "Exit")
def prepareTemplate(sourceExample):
......@@ -78,14 +81,14 @@ def testRenameId():
test.compare(originalText,formerTxt, "Comparing %s" % file.replace("Core.","").replace("\\",""))
invokeMenuItem("File","Save All")
def __invokeFindUsage__(treeView, filename, line, typings, expectedCount):
def __invokeFindUsage__(treeView, filename, line, additionalKeyPresses, expectedCount):
doubleClickFile(treeView, filename)
editor = waitForObject("{type='QmlJSEditor::QmlJSTextEditorWidget' unnamed='1' visible='1' "
"window=':Qt Creator_Core::Internal::MainWindow'}", 20000)
if not placeCursorToLine(editor, line, True):
test.fatal("File seems to have changed... Canceling current test")
return
for ty in typings:
for ty in additionalKeyPresses:
type(editor, ty)
openContextMenuOnTextCursorPosition(editor)
ctxtMenu = waitForObject("{type='QMenu' visible='1' unnamed='1'}")
......@@ -128,6 +131,68 @@ def validateSearchResult(expectedCount):
line = lineUnderCursor(editor)
test.compare(line, text)
def testHovering():
navTree = waitForObject("{type='Utils::NavigationTreeView' unnamed='1' visible='1' "
"window=':Qt Creator_Core::Internal::MainWindow'}", 20000)
test.log("Testing hovering elements")
doubleClickFile(navTree, "focus\\.qml")
editor = waitForObject("{type='QmlJSEditor::QmlJSTextEditorWidget' unnamed='1' visible='1' "
"window=':Qt Creator_Core::Internal::MainWindow'}", 20000)
lines=["FocusScope\s*\{", "Rectangle\s*\{"]
if platform.system() == "Darwin":
home = "<Ctrl+Left>"
else:
home = "<Home>"
additionalKeyPresses = [home, "<Right>"]
expectedTypes = ["TextTip", "TextTip"]
expectedValues = [
{'text':'<table><tr><td valign=middle>FocusScope\n<p>The FocusScope object explicitly '
'creates a focus scope.</p></td><td>&nbsp;&nbsp;<img src=":/cppeditor/images/f1.png"></td></tr></table>'},
{'text':'<table><tr><td valign=middle>Rectangle\n<p>The Rectangle item provides a filled rectangle with an '
'optional border.</p></td><td>&nbsp;&nbsp;<img src=":/cppeditor/images/f1.png"></td></tr></table>'}
]
alternativeValues = [{"text":"FocusScope"}, {"text":"Rectangle"}]
verifyHoveringOnEditor(editor, lines, additionalKeyPresses, expectedTypes, expectedValues, alternativeValues)
test.log("Testing hovering properties")
doubleClickFile(navTree, "focus\\.qml")
editor = waitForObject("{type='QmlJSEditor::QmlJSTextEditorWidget' unnamed='1' visible='1' "
"window=':Qt Creator_Core::Internal::MainWindow'}", 20000)
lines = ['focus:\s*true', 'color:\s*"black"', 'states:\s*State\s*\{', 'transitions:\s*Transition\s*\{']
additionalKeyPresses = [home, "<Right>"]
expectedTypes = ["TextTip", "TextTip", "TextTip", "TextTip"]
expectedValues = [
{'text':'<table><tr><td valign=middle>boolean<p>This property indicates whether the item has focus '
'within the enclosing focus scope. If true, this item will gain active focus when the enclosing '
'focus scope gains active focus. In the following example, <tt>input</tt> will be given active focus '
'when <tt>scope</tt> gains active focus.</p></td><td>&nbsp;&nbsp;<img src=":/cppeditor/images/f1.png"'
'></td></tr></table>'},
{'text':'<table><tr><td valign=middle>string<p>This property holds the color used to fill the rectangle.'
'</p></td><td>&nbsp;&nbsp;<img src=":/cppeditor/images/f1.png"></td></tr></table>'},
{'text':'<table><tr><td valign=middle>State<p>This property holds a list of states defined by the item.'
'</p></td><td>&nbsp;&nbsp;<img src=":/cppeditor/images/f1.png"></td></tr></table>'},
{'text':'<table><tr><td valign=middle>Transition<p>This property holds a list of transitions defined by '
'the item.</p></td><td>&nbsp;&nbsp;<img src=":/cppeditor/images/f1.png"></td></tr></table>'}
]
alternativeValues = [{"text":"boolean"}, {"text":"string"}, {"text":"State"}, {"text":"Transition"}]
verifyHoveringOnEditor(editor, lines, additionalKeyPresses, expectedTypes, expectedValues, alternativeValues)
test.log("Testing hovering expressions")
doubleClickFile(navTree, "focus\\.qml")
editor = waitForObject("{type='QmlJSEditor::QmlJSTextEditorWidget' unnamed='1' visible='1' "
"window=':Qt Creator_Core::Internal::MainWindow'}", 20000)
lines=['color:\s*"black"', 'color:\s*"#3E606F"']
expectedValues = ["black", "#3E606F"]
expectedTypes = ["ColorTip", "ColorTip"]
additionalKeyPresses = ["<Left>"]
verifyHoveringOnEditor(editor, lines, additionalKeyPresses, expectedTypes, expectedValues)
doubleClickFile(navTree, "Core.ListMenu\\.qml")
editor = waitForObject("{type='QmlJSEditor::QmlJSTextEditorWidget' unnamed='1' visible='1' "
"window=':Qt Creator_Core::Internal::MainWindow'}", 20000)
lines=['Rectangle\s*\{.*color:\s*"#D1DBBD"', 'NumberAnimation\s*\{\s*.*Easing.OutQuint\s*\}']
additionalKeyPresses = ["<Left>", "<Left>", "<Left>", "<Left>"]
expectedTypes = ["ColorTip", "TextTip"]
expectedValues = ["#D1DBBD", {"text":"number"}]
verifyHoveringOnEditor(editor, lines, additionalKeyPresses, expectedTypes, expectedValues)
def doubleClickFile(navTree, file):
global templateDir
treeElement = ("untitled.QML.%s/qml.%s" %
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment