2011-09-27 11:39:01 +02:00
|
|
|
import tempfile
|
2011-08-25 10:05:28 +02:00
|
|
|
|
2011-09-27 11:04:12 +02:00
|
|
|
def neededFilePresent(path):
|
|
|
|
found = os.path.exists(path)
|
|
|
|
if not found:
|
|
|
|
test.fatal("Missing file or directory: " + path)
|
|
|
|
return found
|
|
|
|
|
2011-08-25 10:05:28 +02:00
|
|
|
def tempDir():
|
2011-09-21 11:29:21 +02:00
|
|
|
Result = os.path.abspath(os.getcwd()+"/../../testing")
|
|
|
|
if not os.path.exists(Result):
|
|
|
|
os.mkdir(Result)
|
|
|
|
return tempfile.mkdtemp(prefix="qtcreator_", dir=Result)
|
2011-08-25 10:05:28 +02:00
|
|
|
|
|
|
|
def deleteDirIfExists(path):
|
|
|
|
shutil.rmtree(path, True)
|
|
|
|
|
|
|
|
def verifyChecked(objectName):
|
|
|
|
object = waitForObject(objectName, 20000)
|
|
|
|
test.compare(object.checked, True)
|
|
|
|
return object
|
|
|
|
|
2011-10-05 13:18:42 +02:00
|
|
|
def verifyEnabled(objectName, expectedState = True):
|
|
|
|
waitFor("object.exists('" + objectName + "')", 20000)
|
|
|
|
object = findObject(objectName)
|
|
|
|
test.compare(object.enabled, expectedState)
|
2011-08-25 10:05:28 +02:00
|
|
|
return object
|
|
|
|
|
|
|
|
def selectFromCombo(objectName, itemName):
|
|
|
|
object = verifyEnabled(objectName)
|
2011-08-31 13:51:32 +02:00
|
|
|
mouseClick(object, 5, 5, 0, Qt.LeftButton)
|
|
|
|
mouseClick(waitForObjectItem(object, itemName), 5, 5, 0, Qt.LeftButton)
|
2011-08-25 10:05:28 +02:00
|
|
|
|
|
|
|
def wordUnderCursor(window):
|
|
|
|
cursor = window.textCursor()
|
|
|
|
oldposition = cursor.position()
|
|
|
|
cursor.movePosition(QTextCursor.StartOfWord)
|
|
|
|
cursor.movePosition(QTextCursor.EndOfWord, QTextCursor.KeepAnchor)
|
|
|
|
returnValue = cursor.selectedText()
|
|
|
|
cursor.setPosition(oldposition)
|
|
|
|
return returnValue
|
|
|
|
|
|
|
|
def lineUnderCursor(window):
|
|
|
|
cursor = window.textCursor()
|
|
|
|
oldposition = cursor.position()
|
|
|
|
cursor.movePosition(QTextCursor.StartOfLine)
|
|
|
|
cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)
|
|
|
|
returnValue = cursor.selectedText()
|
|
|
|
cursor.setPosition(oldposition)
|
|
|
|
return returnValue
|
|
|
|
|
|
|
|
def which(program):
|
|
|
|
def is_exe(fpath):
|
|
|
|
return os.path.exists(fpath) and os.access(fpath, os.X_OK)
|
|
|
|
|
|
|
|
fpath, fname = os.path.split(program)
|
|
|
|
if fpath:
|
|
|
|
if is_exe(program):
|
|
|
|
return program
|
|
|
|
if platform.system() in ('Windows', 'Microsoft'):
|
|
|
|
if is_exe(program + ".exe"):
|
|
|
|
return program + ".exe"
|
|
|
|
|
|
|
|
else:
|
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
|
|
exe_file = os.path.join(path, program)
|
|
|
|
if is_exe(exe_file):
|
|
|
|
return exe_file
|
|
|
|
if platform.system() in ('Windows', 'Microsoft'):
|
|
|
|
if is_exe(exe_file + ".exe"):
|
|
|
|
return exe_file + ".exe"
|
|
|
|
|
|
|
|
return None
|
2011-08-26 11:14:39 +02:00
|
|
|
|
2011-09-12 10:29:08 +02:00
|
|
|
signalObjects = {}
|
|
|
|
|
2011-10-05 14:59:12 +02:00
|
|
|
# do not call this function directly - it's only a helper
|
2011-09-21 17:29:18 +02:00
|
|
|
def __callbackFunction__(object, *args):
|
2011-09-12 10:29:08 +02:00
|
|
|
global signalObjects
|
2011-09-21 17:29:18 +02:00
|
|
|
# test.log("__callbackFunction__: "+objectMap.realName(object))
|
2011-09-12 10:29:08 +02:00
|
|
|
signalObjects[objectMap.realName(object)] += 1
|
|
|
|
|
|
|
|
def waitForSignal(object, signal, timeout=30000):
|
2011-09-21 17:29:18 +02:00
|
|
|
global signalObjects
|
|
|
|
realName = prepareForSignal(object, signal)
|
|
|
|
beforeCount = signalObjects[realName]
|
|
|
|
waitFor("signalObjects[realName] > beforeCount", timeout)
|
|
|
|
|
|
|
|
def prepareForSignal(object, signal):
|
2011-09-12 10:29:08 +02:00
|
|
|
global signalObjects
|
|
|
|
overrideInstallLazySignalHandler()
|
|
|
|
realName = objectMap.realName(object)
|
|
|
|
# test.log("waitForSignal: "+realName)
|
|
|
|
if not (realName in signalObjects):
|
|
|
|
signalObjects[realName] = 0
|
2011-09-21 17:29:18 +02:00
|
|
|
installLazySignalHandler(object, signal, "__callbackFunction__")
|
|
|
|
return realName
|
2011-09-12 11:07:54 +02:00
|
|
|
|
2011-09-27 11:39:01 +02:00
|
|
|
# this function removes the user files of given pro file(s)
|
|
|
|
# can be called with a single string object or a list of strings holding path(s) to
|
|
|
|
# the pro file(s) returns False if it could not remove all user files or has been
|
|
|
|
# called with an unsupported object
|
|
|
|
def cleanUpUserFiles(pathsToProFiles=None):
|
|
|
|
if pathsToProFiles==None:
|
|
|
|
return False
|
2011-10-17 19:09:51 +02:00
|
|
|
if isinstance(pathsToProFiles, (str, unicode)):
|
2011-09-27 11:39:01 +02:00
|
|
|
filelist = glob.glob(pathsToProFiles+".user*")
|
2011-10-17 19:09:51 +02:00
|
|
|
elif isinstance(pathsToProFiles, (list, tuple)):
|
2011-09-27 11:39:01 +02:00
|
|
|
filelist = []
|
|
|
|
for p in pathsToProFiles:
|
|
|
|
filelist.extend(glob.glob(p+".user*"))
|
|
|
|
else:
|
|
|
|
test.fatal("Got an unsupported object.")
|
|
|
|
return False
|
|
|
|
doneWithoutErrors = True
|
|
|
|
for file in filelist:
|
|
|
|
try:
|
|
|
|
file = os.path.abspath(file)
|
|
|
|
os.remove(file)
|
|
|
|
except:
|
|
|
|
doneWithoutErrors = False
|
|
|
|
return doneWithoutErrors
|
|
|
|
|
2011-10-06 20:16:15 +02:00
|
|
|
def invokeMenuItem(menu, item):
|
|
|
|
menuObject = waitForObjectItem("{type='QMenuBar' visible='true'}", menu)
|
|
|
|
activateItem(menuObject)
|
|
|
|
activateItem(waitForObjectItem(objectMap.realName(menuObject), item))
|
|
|
|
|
|
|
|
def logApplicationOutput():
|
|
|
|
# make sure application output is shown
|
|
|
|
toggleAppOutput = waitForObject("{type='Core::Internal::OutputPaneToggleButton' unnamed='1' visible='1' "
|
|
|
|
"window=':Qt Creator_Core::Internal::MainWindow' occurrence='3'}", 20000)
|
|
|
|
if not toggleAppOutput.checked:
|
|
|
|
clickButton(toggleAppOutput)
|
|
|
|
output = waitForObject("{type='Core::OutputWindow' visible='1' windowTitle='Application Output Window'}", 20000)
|
|
|
|
test.log("Application Output:\n%s" % output.plainText)
|