summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/mainwindow.cpp
blob: 49614ecbc6aeef670867f63e3d148de48e1c0249 (plain)
1
2
3
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "mainwindow.h"
#include <QMessageBox>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent), testIdx(-1)
{
    createMenus();
    view = new QDeclarativeView(this);
    setCentralWidget(view);
    view->setResizeMode(QDeclarativeView::SizeViewToRootObject);
    curTest = new TestModel(this);
    connect(curTest, SIGNAL(moveOn()),
            this, SLOT(runTests()));

    view->engine()->rootContext()->setContextProperty("test", curTest);
    view->setSource(QUrl("qrc:qml/Comparison.qml"));
}

void MainWindow::runAllTests()
{
    tests.clear();
    testIdx = 0;

    QString visualTest = "./tst_qmlvisual";//TODO: Crossplatform

    QProcess p;//TODO: Error checking here
    p.setProcessChannelMode(QProcess::MergedChannels);
    p.start(visualTest, QStringList());
    p.waitForFinished(-1);//Can't time out, because it takes an indeterminate and long time

    QString output = QString(p.readAllStandardOutput());
    QRegExp re("QDeclarativeTester\\( \"([^\"]*)\" \\)");
    int offset=0;
    while((offset = re.indexIn(output, offset)) != -1){
        tests << re.cap(1);
        offset++;
    }

    if(tests.count())
        QMessageBox::information(this, "Test Results", QString("Tests completed. %1 test failures occurred.").arg(tests.count()));
    else
        QMessageBox::information(this, "Test Results", "Tests completed. All tests passed!");

    runTests();
}

void MainWindow::runTests()
{
    if(testIdx >= tests.size())
        testIdx = -1;
    if(testIdx == -1)
        return;
    showFixScreen(tests[testIdx++]);
}

void MainWindow::showFixScreen(const QString &path)
{
    if(curTest->setTest(path)){
        view->engine()->rootContext()->setContextProperty("test", curTest); //signal connects to runTests
    }else{
        QMessageBox::critical(this, "Test Error", QString("Cannot find test %1.").arg(path));
        runTests();
    }
}

void MainWindow::createMenus()
{
    QMenu *tests = this->menuBar()->addMenu("Tests");
    tests->addAction("Run All", this, SLOT(runAllTests()));
    tests->addSeparator();
    tests->addAction("About Qt...", qApp, SLOT(aboutQt()));
    tests->addAction("Quit", qApp, SLOT(quit()));
}