OSDN Git Service

42f564413bff9545316f0260996c2d13adddee30
[qt-creator-jp/qt-creator-jp.git] / tests / valgrind / memcheck / parsertests.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator Analyzer Tools
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Author: Frank Osterfeld, KDAB (frank.osterfeld@kdab.com)
8 **
9 ** Contact: Nokia Corporation (qt-info@nokia.com)
10 **
11 ** Commercial Usage
12 **
13 ** Licensees holding valid Qt Commercial licenses may use this file in
14 ** accordance with the Qt Commercial License Agreement provided with the
15 ** Software or, alternatively, in accordance with the terms contained in
16 ** a written agreement between you and Nokia.
17 **
18 ** GNU Lesser General Public License Usage
19 **
20 ** Alternatively, this file may be used under the terms of the GNU Lesser
21 ** General Public License version 2.1 as published by the Free Software
22 ** Foundation and appearing in the file LICENSE.LGPL included in the
23 ** packaging of this file.  Please review the following information to
24 ** ensure the GNU Lesser General Public License version 2.1 requirements
25 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 **
27 ** If you are unsure which license is appropriate for your use, please
28 ** contact the sales department at http://qt.nokia.com/contact.
29 **
30 **************************************************************************/
31
32 #ifndef PARSERTESTS_H
33 #define PARSERTESTS_H
34
35 #include <QtCore/QObject>
36 #include <QtCore/QPair>
37 #include <QtCore/QStringList>
38 #include <QtCore/QVector>
39 #include <QtCore/QDebug>
40
41 #include <valgrind/xmlprotocol/error.h>
42 #include <valgrind/xmlprotocol/status.h>
43 #include <valgrind/xmlprotocol/threadedparser.h>
44 #include <valgrind/xmlprotocol/parser.h>
45 #include <valgrind/memcheck/memcheckrunner.h>
46
47 QT_BEGIN_NAMESPACE
48 class QTcpServer;
49 class QTcpSocket;
50 class QProcess;
51 QT_END_NAMESPACE
52
53 void dumpError(const Valgrind::XmlProtocol::Error &e);
54
55 class Recorder : public QObject
56 {
57     Q_OBJECT
58 public:
59     explicit Recorder(Valgrind::XmlProtocol::Parser *parser, QObject *parent = 0)
60     : QObject(parent)
61     {
62         connect(parser, SIGNAL(error(Valgrind::XmlProtocol::Error)),
63                 this, SLOT(error(Valgrind::XmlProtocol::Error)));
64         connect(parser, SIGNAL(errorCount(qint64, qint64)),
65                 this, SLOT(errorCount(qint64, qint64)));
66         connect(parser, SIGNAL(suppressionCount(QString, qint64)),
67                 this, SLOT(suppressionCount(QString, qint64)));
68     }
69
70     QList<Valgrind::XmlProtocol::Error> errors;
71     QVector<QPair<qint64,qint64> > errorcounts;
72     QVector<QPair<QString,qint64> > suppcounts;
73
74 public Q_SLOTS:
75     void error(const Valgrind::XmlProtocol::Error &err)
76     {
77         errors.append(err);
78     }
79
80     void errorCount(qint64 uniq, qint64 count)
81     {
82         errorcounts.push_back(qMakePair(uniq, count));
83     }
84
85     void suppressionCount(const QString &name, qint64 count)
86     {
87         suppcounts.push_back(qMakePair(name, count));
88     }
89
90 };
91
92 class RunnerDumper : public QObject
93 {
94     Q_OBJECT
95
96 public:
97     explicit RunnerDumper(Valgrind::Memcheck::MemcheckRunner *runner, Valgrind::XmlProtocol::ThreadedParser *parser)
98         : QObject()
99         , m_errorReceived(false)
100     {
101         connect(parser, SIGNAL(error(Valgrind::XmlProtocol::Error)),
102                 this, SLOT(error(Valgrind::XmlProtocol::Error)));
103         connect(parser, SIGNAL(internalError(QString)),
104                 this, SLOT(internalError(QString)));
105         connect(parser, SIGNAL(status(Valgrind::XmlProtocol::Status)),
106                 this, SLOT(status(Valgrind::XmlProtocol::Status)));
107         connect(runner, SIGNAL(standardErrorReceived(QByteArray)),
108                 this, SLOT(standardErrorReceived(QByteArray)));
109         connect(runner, SIGNAL(standardOutputReceived(QByteArray)),
110                 this, SLOT(standardOutputReceived(QByteArray)));
111         connect(runner, SIGNAL(logMessageReceived(QByteArray)),
112                 this, SLOT(logMessageReceived(QByteArray)));
113         connect(runner, SIGNAL(processErrorReceived(QString, QProcess::ProcessError)),
114                 this, SLOT(processErrorReceived(QString)));
115     }
116
117 public slots:
118     void error(const Valgrind::XmlProtocol::Error &e)
119     {
120         qDebug() << "error received";
121         dumpError(e);
122     }
123     void internalError(const QString& error)
124     {
125         qDebug() << "internal error received:" << error;
126     }
127     void standardErrorReceived(const QByteArray &err)
128     {
129         Q_UNUSED(err);
130         // qDebug() << "STDERR received:" << err; // this can be a lot of text
131     }
132     void standardOutputReceived(const QByteArray &out)
133     {
134         qDebug() << "STDOUT received:" << out;
135     }
136     void status(const Valgrind::XmlProtocol::Status &status)
137     {
138         qDebug() << "status received:" << status.state() << status.time();
139     }
140     void logMessageReceived(const QByteArray &log)
141     {
142         qDebug() << "log message received:" << log;
143     }
144     void processErrorReceived(const QString &s)
145     {
146         Q_UNUSED(s);
147         // qDebug() << "error received:" << s; // this can be a lot of text
148         m_errorReceived = true;
149     }
150
151 public:
152     bool m_errorReceived;
153
154 };
155
156 class ParserTests : public QObject
157 {
158     Q_OBJECT
159
160 private Q_SLOTS:
161     void initTestCase();
162     void cleanup();
163
164     void testMemcheckSample1();
165     void testMemcheckSample2();
166     void testMemcheckSample3();
167     void testMemcheckCharm();
168     void testHelgrindSample1();
169
170     void testValgrindCrash();
171     void testValgrindGarbage();
172
173     void testParserStop();
174     void testRealValgrind();
175     void testValgrindStartError_data();
176     void testValgrindStartError();
177
178 private:
179     void initTest(const QLatin1String &testfile, const QStringList &otherArgs = QStringList());
180
181     QTcpServer *m_server;
182     QProcess *m_process;
183     QTcpSocket *m_socket;
184 };
185
186 #endif // PARSERTESTS_H