1############################################################################
2#
3# Copyright (C) 2016 The Qt Company Ltd.
4# Contact: https://www.qt.io/licensing/
5#
6# This file is part of Qt Creator.
7#
8# Commercial License Usage
9# Licensees holding valid commercial Qt licenses may use this file in
10# accordance with the commercial license agreement provided with the
11# Software or, alternatively, in accordance with the terms contained in
12# a written agreement between you and The Qt Company. For licensing terms
13# and conditions see https://www.qt.io/terms-conditions. For further
14# information use the contact form at https://www.qt.io/contact-us.
15#
16# GNU General Public License Usage
17# Alternatively, this file may be used under the terms of the GNU
18# General Public License version 3 as published by the Free Software
19# Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20# included in the packaging of this file. Please review the following
21# information to ensure the GNU General Public License requirements will
22# be met: https://www.gnu.org/licenses/gpl-3.0.html.
23#
24############################################################################
25
26# appends to line, by typing <typeWhat> after <insertAfterLine> text into <codeArea> widget
27def appendToLine(codeArea, insertAfterLine, typeWhat):
28    if not placeCursorToLine(codeArea, insertAfterLine):
29        return False
30    type(codeArea, typeWhat)
31    return True
32
33# checks if error is properly reported, returns True if succeeded and False if not.
34# Current implementation is focused on allowing different compilers, and it is enough if one of the expected messages
35# is found in issues view. warnIfMoreIssues should warn if there are more than one issue, no matter how many
36# expected texts are in array (because they are alternatives).
37def checkSyntaxError(issuesView, expectedTextsArray, warnIfMoreIssues = True):
38    issuesModel = issuesView.model()
39    # wait for issues
40    waitFor("issuesModel.rowCount() > 0", 5000)
41    # warn if more issues reported
42    if(warnIfMoreIssues and issuesModel.rowCount() > 1):
43        test.warning("More than one expected issues reported")
44    # iterate issues and check if there exists "Unexpected token" message
45    for description, type in zip(dumpItems(issuesModel, role=Qt.UserRole + 3),
46                                 dumpItems(issuesModel, role=Qt.UserRole + 5)):
47        # enum Roles { File = Qt::UserRole, Line, MovedLine, Description, FileNotFound, Type, Category, Icon, Task_t };
48        # check if at least one of expected texts found in issue text
49        for expectedText in expectedTextsArray:
50            if expectedText in description:
51                # check if it is error and warn if not - returns False which leads to fail
52                if type is not "1":
53                    test.warning("Expected error text found, but is not of type: 'error'")
54                    return False
55                else:
56                    test.log("Found expected error (%s)" % expectedText)
57                    return True
58    return False
59
60# change autocomplete options to manual
61def changeAutocompleteToManual(toManual=True):
62    invokeMenuItem("Tools", "Options...")
63    mouseClick(waitForObjectItem(":Options_QListView", "Text Editor"))
64    clickOnTab(":Options.qt_tabwidget_tabbar_QTabBar", "Completion")
65    ensureChecked(waitForObject(":Behavior.Autocomplete common prefix_QCheckBox"), not toManual)
66    activateCompletion = "Always"
67    if toManual:
68        activateCompletion = "Manually"
69    selectFromCombo(":Behavior.completionTrigger_QComboBox", activateCompletion)
70    verifyEnabled(":Options.OK_QPushButton")
71    clickButton(waitForObject(":Options.OK_QPushButton"))
72
73# wait and verify if object item exists/not exists
74def checkIfObjectItemExists(object, item, timeout = 3000):
75    try:
76        waitForObjectItem(object, item, timeout)
77        return True
78    except:
79        return False
80