void TestCaseView::displayBaseLines(const TestCase *const tc)
{
    clearTabWidget(baselinesTabs);
    Q_ASSERT(tc);
    const TestBaseLine::List bs(tc->baseLines());
    const TestBaseLine::List::const_iterator end(bs.constEnd());
    TestBaseLine::List::const_iterator it(bs.constBegin());

    for(; it != end; ++it)
    {
        const TestBaseLine *const bl = *it;
        Q_ASSERT(bl);
        const TestBaseLine::Type t = bl->type();

        QString title(TestBaseLine::displayName(t));
        const QString details(bl->details());

        QWidget *const currPage = new QWidget();
        Ui::BaseLinePage setupPage;
        setupPage.setupUi(currPage);

        /* Make this title a bit better: "ExpectedError: XPTY0004", for example. */
        switch(t)
        {
            case TestBaseLine::ExpectedError:
            {
                title += (QLatin1String(": ") + details);
                /* Fallthrough. */
            }
            case TestBaseLine::Ignore:
            {
                setupPage.contentEdit->setEnabled(false);
                break;
            }
            default:
            {
                setupPage.contentEdit->setPlainText(details);
                break;
            }
        }

        baselinesTabs->addTab(currPage, title);
    }

    int tabIndex = baselinesTabs->count(); /* The tab we're about to add. */
    baselinesTabs->addTab(new QWidget(), QLatin1String("AST Baseline"));
    baselinesTabs->setTabToolTip(tabIndex,
                                 QLatin1String("Expected AST baselines are not yet implemented."));
    baselinesTabs->setTabEnabled(tabIndex, false);

    ++tabIndex; /* Again, the tab we're about to add. */
    baselinesTabs->addTab(new QWidget(), QLatin1String("Message Baseline"));
    baselinesTabs->setTabToolTip(tabIndex,
                                 QLatin1String("Expected Message baselines are not yet implemented."));
    baselinesTabs->setTabEnabled(tabIndex, false);

    baselinesTabs->setCurrentIndex(0);
}
예제 #2
0
TestResult::Status TestBaseLine::scanErrors(const ErrorHandler::Message::List &errors,
                                            const TestBaseLine::List &lines)
{
    pDebug() << "TestBaseLine::scanErrors()";

    /* 1. Find the first error in @p errors that's a Patternist
     * error(not warning and not from Qt) and extract the error code. */
    QString errorCode;

    const ErrorHandler::Message::List::const_iterator end(errors.constEnd());
    ErrorHandler::Message::List::const_iterator it(errors.constBegin());
    for(; it != end; ++it)
    {
        if((*it).type() != QtFatalMsg)
            continue;

        errorCode = QUrl((*it).identifier()).fragment();

        pDebug() << "ERR:" << (*it).description();
        /* This is hackish. We have no way of determining whether a Message
         * is actually issued from Patternist, so we try to narrow it down like this. */
        if(errorRegExp()->exactMatch(errorCode))
            break; /* It's an error code. */
        else
            errorCode.clear();
    }

    pDebug() << "Got error code: " << errorCode;
    /* 2. Loop through @p lines, and for the first base line
     * which is of type ExpectedError and which matches @p errorCode
     * return Pass, otherwise Fail. */
    const TestBaseLine::List::const_iterator blend(lines.constEnd());
    TestBaseLine::List::const_iterator blit(lines.constBegin());
    for(; blit != blend; ++blit)
    {
        const Type t = (*blit)->type();

        if(t == TestBaseLine::ExpectedError)
        {
            const QString d((*blit)->details());
            if(d == errorCode || d == QChar::fromLatin1('*'))
                return TestResult::Pass;
        }
    }

    return TestResult::Fail;
}
예제 #3
0
TestResult::Status TestBaseLine::scan(const QString &serialized,
                                      const TestBaseLine::List &lines)
{
    Q_ASSERT_X(lines.count() >= 1, Q_FUNC_INFO,
               "At least one base line must be passed, otherwise there's nothing "
               "to compare to.");

    const TestBaseLine::List::const_iterator end(lines.constEnd());
    TestBaseLine::List::const_iterator it(lines.constBegin());
    for(; it != end; ++it)
    {
        const TestResult::Status retval((*it)->verify(serialized));

        if(retval == TestResult::Pass || retval == TestResult::NotTested)
            return retval;
    }

    return TestResult::Fail;
}