main.cpp 5.73 KB
Newer Older
1
2
3
4

#include "gdbmi.h"

#include <QtCore/QObject>
hjk's avatar
hjk committed
5
6
#include <QtCore/QProcess>
#include <QtCore/QFileInfo>
7
#include <QtTest/QtTest>
hjk's avatar
hjk committed
8
//#include <QtTest/qtest_gui.h>
9
10
11
12
13

using namespace Debugger;
using namespace Debugger::Internal;

static const char test1[] =
hjk's avatar
hjk committed
14
    "[frame={level=\"0\",addr=\"0x00000000004061ca\","
15
16
17
18
    "func=\"main\",file=\"test1.cpp\","
    "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]";

static const char test2[] =
hjk's avatar
hjk committed
19
    "[frame={level=\"0\",addr=\"0x00002ac058675840\","
20
21
22
    "func=\"QApplication\",file=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\","
    "fullname=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\",line=\"592\"},"
    "frame={level=\"1\",addr=\"0x00000000004061e0\",func=\"main\",file=\"test1.cpp\","
hjk's avatar
hjk committed
23
    "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]";
24
25

static const char test3[] =
hjk's avatar
hjk committed
26
    "[stack={frame={level=\"0\",addr=\"0x00000000004061ca\","
27
    "func=\"main\",file=\"test1.cpp\","
hjk's avatar
hjk committed
28
    "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}}]";
29
30

static const char test4[] =
hjk's avatar
hjk committed
31
    "&\"source /home/apoenitz/dev/ide/main/bin/gdb/qt4macros\\n\""
32
33
34
    "4^done\n";

static const char test5[] =
hjk's avatar
hjk committed
35
    "[reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"1\","
36
37
38
    "frame={addr=\"0x0000000000405738\",func=\"main\","
    "args=[{name=\"argc\",value=\"1\"},{name=\"argv\",value=\"0x7fff1ac78f28\"}],"
    "file=\"test1.cpp\",fullname=\"/home/apoenitz/work/test1/test1.cpp\","
hjk's avatar
hjk committed
39
    "line=\"209\"}]";
40
41

static const char test8[] =
hjk's avatar
hjk committed
42
    "[data={locals={{name=\"a\"},{name=\"w\"}}}]";
43
44

static const char test9[] =
hjk's avatar
hjk committed
45
    "[data={locals=[name=\"baz\",name=\"urgs\",name=\"purgs\"]}]";
46
47

static const char test10[] =
hjk's avatar
hjk committed
48
    "[name=\"urgs\",numchild=\"1\",type=\"Urgs\"]";
49
50
51
52
53
54

static const char test11[] =
    "[{name=\"size\",value=\"1\",type=\"size_t\",readonly=\"true\"},"
     "{name=\"0\",value=\"one\",type=\"QByteArray\"}]";

static const char test12[] =
hjk's avatar
hjk committed
55
56
    "[{iname=\"local.hallo\",value=\"\\\"\\\"\",type=\"QByteArray\","
     "numchild=\"0\"}]";
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

class tst_Debugger : public QObject
{
    Q_OBJECT

public:
    tst_Debugger() {}

    void testMi(const char* input)
    {
        QCOMPARE('\n' + QString::fromLatin1(GdbMi(input).toString(false)),
            '\n' + QString(input));
    }

private slots:
    void mi1()  { testMi(test1);  }
    void mi2()  { testMi(test2);  }
    void mi3()  { testMi(test3);  }
hjk's avatar
hjk committed
75
    //void mi4()  { testMi(test4);  }
76
77
78
79
80
81
    void mi5()  { testMi(test5);  }
    void mi8()  { testMi(test8);  }
    void mi9()  { testMi(test9);  }
    void mi10() { testMi(test10); }
    void mi11() { testMi(test11); }
    void mi12() { testMi(test12); }
82
83
84

    void infoBreak();

hjk's avatar
hjk committed
85
    void runQtc();
hjk's avatar
hjk committed
86
87
88
89
90
91

public slots:
    void readStandardOutput();
    void readStandardError();

private:
hjk's avatar
hjk committed
92
    QProcess m_proc; // the Qt Creator process
93
94
};

hjk's avatar
hjk committed
95
96
97
98
99
100
101
102
103
104
105
static QByteArray stripped(QByteArray ba)
{
    for (int i = ba.size(); --i >= 0; ) {
        if (ba.at(i) == '\n' || ba.at(i) == ' ')
            ba.chop(1);
        else
            break;
    }
    return ba;
}

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

void tst_Debugger::infoBreak()
{
    // This tests the regular expression used in GdbEngine::extractDataFromInfoBreak 
    // to discover breakpoints in constructors.

    // Copied from gdbengine.cpp:

    QRegExp re("MULTIPLE.*(0x[0-9a-f]+) in (.*)\\s+at (.*):([\\d]+)([^\\d]|$)");
    re.setMinimal(true);

    QCOMPARE(re.indexIn(
        "2       breakpoint     keep y   <MULTIPLE> 0x0040168e\n"
        "2.1                         y     0x0040168e "
            "in MainWindow::MainWindow(QWidget*) at mainwindow.cpp:7\n"
        "2.2                         y     0x00401792 "
            "in MainWindow::MainWindow(QWidget*) at mainwindow.cpp:7\n"), 33);
    QCOMPARE(re.cap(1), QString("0x0040168e"));
    QCOMPARE(re.cap(2).trimmed(), QString("MainWindow::MainWindow(QWidget*)"));
    QCOMPARE(re.cap(3), QString("mainwindow.cpp"));
    QCOMPARE(re.cap(4), QString("7"));


    QCOMPARE(re.indexIn(
        "Num     Type           Disp Enb Address            What"
        "4       breakpoint     keep y   <MULTIPLE>         0x00000000004066ad"
        "4.1                         y     0x00000000004066ad in CTorTester"
        " at /main/tests/manual/gdbdebugger/simple/app.cpp:124"), 88);

    QCOMPARE(re.cap(1), QString("0x00000000004066ad"));
    QCOMPARE(re.cap(2).trimmed(), QString("CTorTester"));
    QCOMPARE(re.cap(3), QString("/main/tests/manual/gdbdebugger/simple/app.cpp"));
    QCOMPARE(re.cap(4), QString("124"));
}

hjk's avatar
hjk committed
141
142
void tst_Debugger::readStandardOutput()
{
hjk's avatar
hjk committed
143
    qDebug() << "qtcreator-out: " << stripped(m_proc.readAllStandardOutput());
hjk's avatar
hjk committed
144
145
146
147
}

void tst_Debugger::readStandardError()
{
hjk's avatar
hjk committed
148
    qDebug() << "qtcreator-err: " << stripped(m_proc.readAllStandardError());
hjk's avatar
hjk committed
149
150
}

hjk's avatar
hjk committed
151
152
153
154
155
156
157
void tst_Debugger::runQtc()
{
    QString test = QFileInfo(qApp->arguments().at(0)).absoluteFilePath();
    QString qtc = QFileInfo(test).absolutePath() + "/../../../bin/qtcreator.bin";
    qtc = QFileInfo(qtc).absoluteFilePath();
    QStringList env = QProcess::systemEnvironment();
    env.append("QTC_DEBUGGER_TEST=" + test);
hjk's avatar
hjk committed
158
159
160
161
162
163
164
165
166
167
    m_proc.setEnvironment(env);
    connect(&m_proc, SIGNAL(readyReadStandardOutput()),
        this, SLOT(readStandardOutput()));
    connect(&m_proc, SIGNAL(readyReadStandardError()),
        this, SLOT(readStandardError()));
    m_proc.start(qtc);
    m_proc.waitForStarted();
    QCOMPARE(m_proc.state(), QProcess::Running);
    m_proc.waitForFinished();
    QCOMPARE(m_proc.state(), QProcess::NotRunning);
hjk's avatar
hjk committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
}

void runDebuggee()
{
    qDebug() << "RUNNING DEBUGGEE";
}

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    QStringList args = app.arguments();


    if (args.size() == 2 && args.at(1) == "--run-debuggee") {
        runDebuggee();
183
        app.exec();
hjk's avatar
hjk committed
184
185
186
187
188
189
        return 0;
    }

    tst_Debugger test;
    return QTest::qExec(&test, argc, argv);
}
190
191
192

#include "main.moc"