outputparser_test.cpp 5.54 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
8
9
10
11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
30
31
32
33
34
**
**************************************************************************/

#include "outputparser_test.h"

35
36
#if defined(WITH_TESTS)

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <QtTest>

using namespace ProjectExplorer;

OutputParserTester::OutputParserTester() :
        m_debug(false)
{
}

OutputParserTester::~OutputParserTester()
{
    if (childParser())
        childParser()->takeOutputParserChain();
}

// test methods:
void OutputParserTester::testParsing(const QString &lines,
                                     Channel inputChannel,
55
                                     QList<Task> tasks,
56
57
58
59
60
61
62
63
64
65
                                     const QString &childStdOutLines,
                                     const QString &childStdErrLines,
                                     const QString &outputLines)
{
    reset();
    Q_ASSERT(childParser());

    QStringList inputLines = lines.split(QChar('\n'));
    foreach (const QString &input, inputLines) {
        if (inputChannel == STDOUT)
66
            childParser()->stdOutput(input + QLatin1Char('\n'));
67
        else
68
            childParser()->stdError(input + QLatin1Char('\n'));
69
    }
70
71
     // first disconnect ourselves from the end of the parser chain again
    IOutputParser * parser = this;
72
    while ( (parser = parser->childParser()) ) {
73
74
75
76
77
78
79
80
81
82
        if (parser->childParser() == this) {
            childParser()->takeOutputParserChain();
            break;
        }
    }
    parser = 0;
    emit aboutToDeleteParser();

    // then delete the parser(s) to test
    setChildParser(0);
83
84
85
86
87
88
89
90
91
92
93

    QCOMPARE(m_receivedOutput, outputLines);
    QCOMPARE(m_receivedStdErrChildLine, childStdErrLines);
    QCOMPARE(m_receivedStdOutChildLine, childStdOutLines);
    QCOMPARE(m_receivedTasks.size(), tasks.size());
    if (m_receivedTasks.size() == tasks.size()) {
        for(int i = 0; i < tasks.size(); ++i) {
            QCOMPARE(m_receivedTasks.at(i).category, tasks.at(i).category);
            QCOMPARE(m_receivedTasks.at(i).description, tasks.at(i).description);
            QCOMPARE(m_receivedTasks.at(i).file, tasks.at(i).file);
            QCOMPARE(m_receivedTasks.at(i).line, tasks.at(i).line);
94
            QCOMPARE(static_cast<int>(m_receivedTasks.at(i).type), static_cast<int>(tasks.at(i).type));
95
96
97
98
        }
    }
}

99
100
void OutputParserTester::testTaskMangling(const Task input,
                                          const Task output)
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{
    reset();
    childParser()->taskAdded(input);

    QVERIFY(m_receivedOutput.isNull());
    QVERIFY(m_receivedStdErrChildLine.isNull());
    QVERIFY(m_receivedStdOutChildLine.isNull());
    QVERIFY(m_receivedTasks.size() == 1);
    if (m_receivedTasks.size() == 1) {
        QCOMPARE(m_receivedTasks.at(0).category, output.category);
        QCOMPARE(m_receivedTasks.at(0).description, output.description);
        QCOMPARE(m_receivedTasks.at(0).file, output.file);
        QCOMPARE(m_receivedTasks.at(0).line, output.line);
        QCOMPARE(m_receivedTasks.at(0).type, output.type);
    }
}

void OutputParserTester::testOutputMangling(const QString &input,
                                            const QString &output)
{
    reset();

123
    childParser()->outputAdded(input, BuildStep::NormalOutput);
124
125
126
127
128
129
130
131
132
133
134
135
136
137

    QCOMPARE(m_receivedOutput, output);
    QVERIFY(m_receivedStdErrChildLine.isNull());
    QVERIFY(m_receivedStdOutChildLine.isNull());
    QVERIFY(m_receivedTasks.isEmpty());
}

void OutputParserTester::setDebugEnabled(bool debug)
{
    m_debug = debug;
}

void OutputParserTester::stdOutput(const QString &line)
{
138
    QVERIFY(line.endsWith(QLatin1Char('\n')));
139
140
141
142
143
    m_receivedStdOutChildLine.append(line);
}

void OutputParserTester::stdError(const QString &line)
{
144
    QVERIFY(line.endsWith(QLatin1Char('\n')));
145
146
147
148
149
150
151
152
153
154
155
    m_receivedStdErrChildLine.append(line);
}

void OutputParserTester::appendOutputParser(IOutputParser *parser)
{
    Q_ASSERT(!childParser());

    IOutputParser::appendOutputParser(parser);
    parser->appendOutputParser(this);
}

156
void OutputParserTester::outputAdded(const QString &line, ProjectExplorer::BuildStep::OutputFormat format)
157
{
158
    Q_UNUSED(format);
159
160
161
162
163
    if (!m_receivedOutput.isEmpty())
        m_receivedOutput.append(QChar('\n'));
    m_receivedOutput.append(line);
}

164
void OutputParserTester::taskAdded(const ProjectExplorer::Task &task)
165
166
167
168
169
170
{
    m_receivedTasks.append(task);
}

void OutputParserTester::reset()
{
171
172
    m_receivedStdErrChildLine.clear();
    m_receivedStdOutChildLine.clear();
173
    m_receivedTasks.clear();
174
    m_receivedOutput.clear();
175
}
176
177

#endif