test.py 6.61 KB
Newer Older
1 2
#############################################################################
##
3
## Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
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
## Contact: http://www.qt-project.org/legal
##
## 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 Digia.  For licensing terms and
## conditions see http://qt.digia.com/licensing.  For further information
## use the contact form at http://qt.digia.com/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 as published by the Free Software
## Foundation and appearing in the file LICENSE.LGPL included in the
## packaging of this file.  Please review the following information to
## ensure the GNU Lesser General Public License version 2.1 requirements
## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## In addition, as a special exception, Digia gives you certain additional
## rights.  These rights are described in the Digia Qt LGPL Exception
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
#############################################################################

30 31 32 33 34
source("../../shared/qtcreator.py")

project = "untitled"

def main():
35 36 37
    if platform.system() == "Darwin" and JIRA.isBugStillOpen(6853, JIRA.Bug.CREATOR):
        test.xverify(False, "This test is unstable on Mac, see QTCREATORBUG-6853.")
        return
38 39 40 41
    outputQDebug = "Output from qDebug()."
    outputStdOut = "Output from std::cout."
    outputStdErr = "Output from std::cerr."
    startApplication("qtcreator" + SettingsPath)
42 43
    if not startedWithoutPluginError():
        return
44
    checkedTargets = createProject_Qt_Console(tempDir(), project)
45 46 47 48 49 50 51 52 53 54 55 56

    mainEditor = waitForObject(":Qt Creator_CppEditor::Internal::CPPEditorWidget")
    replaceEditorContent(mainEditor, "")
    typeLines(mainEditor, ["#include <QDebug>",
                           "#include <iostream>",
                           "int main(int, char *argv[])",
                           "{",
                           '    std::cout << \"' + outputStdOut + '\" << std::endl;',
                           '    std::cerr << \"' + outputStdErr + '\" << std::endl;',
                           '    qDebug() << \"' + outputQDebug + '\";'])
    # Rely on code completion for closing bracket
    invokeMenuItem("File", "Save All")
57
    openDocument(project + "." + project + "\\.pro")
58
    proEditor = waitForObject(":Qt Creator_TextEditor::TextEditorWidget")
59 60
    test.verify("CONFIG   += console" in str(proEditor.plainText), "Verifying that program is configured with console")

61
    availableConfigs = iterateBuildConfigs(len(checkedTargets))
62 63
    if not availableConfigs:
        test.fatal("Haven't found a suitable Qt version - leaving without building.")
64
    for kit, config in availableConfigs:
65
        selectBuildConfig(len(checkedTargets), kit, config)
66 67 68
        test.log("Testing build configuration: " + config)

        test.log("Running application")
69
        setRunInTerminal(len(checkedTargets), kit, False)
70
        clickButton(waitForObject(":*Qt Creator.Run_Core::Internal::FancyToolButton"))
71 72 73 74 75
        outputButton = waitForObject(":Qt Creator_AppOutput_Core::Internal::OutputPaneToggleButton")
        waitFor("outputButton.checked", 20000) # Not ensureChecked(), avoid race condition
        outputWindow = waitForObject(":Qt Creator_Core::OutputWindow")
        waitFor("'exited with code' in str(outputWindow.plainText) or \
                'The program has unexpectedly finished' in str(outputWindow.plainText)", 20000)
76
        try:
77
            appOutput = str(waitForObject(":Qt Creator_Core::OutputWindow").plainText)
78 79 80 81 82 83 84
            verifyOutput(appOutput, outputStdOut, "std::cout", "Application Output")
            verifyOutput(appOutput, outputStdErr, "std::cerr", "Application Output")
            verifyOutput(appOutput, outputQDebug, "qDebug()", "Application Output")
            clickButton(waitForObject(":Qt Creator_CloseButton"))
        except:
            test.fatal("Could not find Application Output Window",
                       "Did the application run at all?")
85 86

        test.log("Debugging application")
87
        isMsvc = isMsvcConfig(len(checkedTargets), kit)
88
        invokeMenuItem("Debug", "Start Debugging", "Start Debugging")
89
        JIRA.performWorkaroundForBug(6853, JIRA.Bug.CREATOR, config)
90
        handleDebuggerWarnings(config, isMsvc)
91 92 93
        ensureChecked(":Qt Creator_AppOutput_Core::Internal::OutputPaneToggleButton")
        outputWindow = waitForObject(":Qt Creator_Core::OutputWindow")
        waitFor("'Debugging has finished' in str(outputWindow.plainText)", 20000)
94 95
        try:
            debuggerLog = takeDebuggerLog()
96
            if not isMsvc:
97 98 99 100 101 102 103 104 105 106 107 108 109
                # cout works with MSVC, too, but we don't check it since it's not supported
                verifyOutput(debuggerLog, outputStdOut, "std::cout", "Debugger Log")
                verifyOutput(debuggerLog, outputStdErr, "std::cerr", "Debugger Log")
                verifyOutput(debuggerLog, outputQDebug, "qDebug()", "Debugger Log")
        except LookupError:
            # takeDebuggerLog() expects the debugger log to not be visible.
            # If debugger log showed up automatically, previous call to takeDebuggerLog() has closed it.
            debuggerLog = takeDebuggerLog()
            if "lib\qtcreatorcdbext64\qtcreatorcdbext.dll cannot be found." in debuggerLog:
                test.fatal("qtcreatorcdbext.dll is missing in lib\qtcreatorcdbext64")
            else:
                test.fatal("Debugger log did not behave as expected. Please check manually.")
        switchViewTo(ViewConstants.EDIT)
110 111
        ensureChecked(":Qt Creator_AppOutput_Core::Internal::OutputPaneToggleButton")
        try:
112
            appOutput = str(waitForObject(":Qt Creator_Core::OutputWindow").plainText)
113 114 115 116 117 118 119 120
            if not isMsvc:
                verifyOutput(appOutput, outputStdOut, "std::cout", "Application Output")
                verifyOutput(appOutput, outputStdErr, "std::cerr", "Application Output")
                verifyOutput(appOutput, outputQDebug, "qDebug()", "Application Output")
            clickButton(waitForObject(":Qt Creator_CloseButton"))
        except:
            test.fatal("Could not find Application Output Window",
                       "Did the application run at all?")
121
        progressBarWait(10000, False)   # wait for "Build" progressbar to disappear
122 123

    invokeMenuItem("File", "Exit")