Exemple #1
0
void QTestLogger::stopLogging()
{
    QTestElement *iterator = listOfTestcases;

    if(format == TLF_XunitXml ){
        char buf[10];

        currentLogElement = new QTestElement(QTest::LET_TestSuite);
        currentLogElement->addAttribute(QTest::AI_Name, QTestResult::currentTestObjectName());

        QTest::qt_snprintf(buf, sizeof(buf), "%i", testCounter);
        currentLogElement->addAttribute(QTest::AI_Tests, buf);

        QTest::qt_snprintf(buf, sizeof(buf), "%i", failureCounter);
        currentLogElement->addAttribute(QTest::AI_Failures, buf);

        QTest::qt_snprintf(buf, sizeof(buf), "%i", errorCounter);
        currentLogElement->addAttribute(QTest::AI_Errors, buf);

        QTestElement *property;
        QTestElement *properties = new QTestElement(QTest::LET_Properties);

        property = new QTestElement(QTest::LET_Property);
        property->addAttribute(QTest::AI_Name, "QTestVersion");
        property->addAttribute(QTest::AI_PropertyValue, QTEST_VERSION_STR);
        properties->addLogElement(property);

        property = new QTestElement(QTest::LET_Property);
        property->addAttribute(QTest::AI_Name, "QtVersion");
        property->addAttribute(QTest::AI_PropertyValue, qVersion());
        properties->addLogElement(property);

        currentLogElement->addLogElement(properties);

        currentLogElement->addLogElement(iterator);

        /* For correct indenting, make sure every testcase knows its parent */
        QTestElement* testcase = iterator;
        while (testcase) {
            testcase->setParent(currentLogElement);
            testcase = testcase->nextElement();
        }

        currentLogElement->addLogElement(errorLogElement);

        QTestElement *it = currentLogElement;
        logFormatter->output(it);
    }else{
        logFormatter->output(iterator);
    }

    logFormatter->stopStreaming();
}
Exemple #2
0
void QXunitTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
{
    QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark);

    benchmarkElement->addAttribute(
        QTest::AI_Metric,
        QTest::benchmarkMetricName(QBenchmarkTestMethodData::current->result.metric));
    benchmarkElement->addAttribute(QTest::AI_Tag, result.context.tag.toUtf8().data());
    benchmarkElement->addAttribute(QTest::AI_Value, QByteArray::number(result.value).constData());

    char buf[100];
    qsnprintf(buf, sizeof(buf), "%i", result.iterations);
    benchmarkElement->addAttribute(QTest::AI_Iterations, buf);
    currentLogElement->addLogElement(benchmarkElement);
}
Exemple #3
0
void QXunitTestLogger::addMessage(MessageTypes type, const char *message, const char *file, int line)
{
    QTestElement *errorElement = new QTestElement(QTest::LET_Error);
    const char *typeBuf = 0;

    switch (type) {
    case QAbstractTestLogger::Warn:
        typeBuf = "warn";
        break;
    case QAbstractTestLogger::QSystem:
        typeBuf = "system";
        break;
    case QAbstractTestLogger::QDebug:
        typeBuf = "qdebug";
        break;
    case QAbstractTestLogger::QWarning:
        typeBuf = "qwarn";
        break;
    case QAbstractTestLogger::QFatal:
        typeBuf = "qfatal";
        break;
    case QAbstractTestLogger::Skip:
        typeBuf = "skip";
        break;
    case QAbstractTestLogger::Info:
        typeBuf = "info";
        break;
    default:
        typeBuf = "??????";
        break;
    }

    errorElement->addAttribute(QTest::AI_Type, typeBuf);
    errorElement->addAttribute(QTest::AI_Description, message);
    addTag(errorElement);

    if (file)
        errorElement->addAttribute(QTest::AI_File, file);
    else
        errorElement->addAttribute(QTest::AI_File, "");

    char buf[100];
    qsnprintf(buf, sizeof(buf), "%i", line);
    errorElement->addAttribute(QTest::AI_Line, buf);

    currentLogElement->addLogElement(errorElement);
    ++errorCounter;

    // Also add the message to the system error log (i.e. stderr), if one exists
    if (errorLogElement) {
        QTestElement *systemErrorElement = new QTestElement(QTest::LET_Error);
        systemErrorElement->addAttribute(QTest::AI_Description, message);
        errorLogElement->addLogElement(systemErrorElement);
    }
}
void QTestLogger::addIncident(IncidentTypes type, const char *description,
                     const char *file, int line)
{
    const char *typeBuf = 0;
    char buf[100];

    switch (type) {
    case QAbstractTestLogger::XPass:
        ++failureCounter;
        typeBuf = "xpass";
        break;
    case QAbstractTestLogger::Pass:
        ++passCounter;
        typeBuf = "pass";
        break;
    case QAbstractTestLogger::XFail:
        ++passCounter;
        typeBuf = "xfail";
        break;
    case QAbstractTestLogger::Fail:
        ++failureCounter;
        typeBuf = "fail";
        break;
    default:
        typeBuf = "??????";
        break;
    }

    if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XPass
            || ((format != TLF_XunitXml) && (type == QAbstractTestLogger::XFail))) {
        QTestElement *failureElement = new QTestElement(QTest::LET_Failure);
        failureElement->addAttribute(QTest::AI_Result, typeBuf);
        if(file)
            failureElement->addAttribute(QTest::AI_File, file);
        else
            failureElement->addAttribute(QTest::AI_File, "");
        QTest::qt_snprintf(buf, sizeof(buf), "%i", line);
        failureElement->addAttribute(QTest::AI_Line, buf);
        failureElement->addAttribute(QTest::AI_Description, description);
        addTag(failureElement);
        currentLogElement->addLogElement(failureElement);
    }

    /*
        Only one result can be shown for the whole testfunction.
        Check if we currently have a result, and if so, overwrite it
        iff the new result is worse.
    */
    QTestElementAttribute* resultAttr =
        const_cast<QTestElementAttribute*>(currentLogElement->attribute(QTest::AI_Result));
    if (resultAttr) {
        const char* oldResult = resultAttr->value();
        bool overwrite = false;
        if (!strcmp(oldResult, "pass")) {
            overwrite = true;
        }
        else if (!strcmp(oldResult, "xfail")) {
            overwrite = (type == QAbstractTestLogger::XPass || type == QAbstractTestLogger::Fail);
        }
        else if (!strcmp(oldResult, "xpass")) {
            overwrite = (type == QAbstractTestLogger::Fail);
        }
        if (overwrite) {
            resultAttr->setPair(QTest::AI_Result, typeBuf);
        }
    }
    else {
        currentLogElement->addAttribute(QTest::AI_Result, typeBuf);
    }

    if(file)
        currentLogElement->addAttribute(QTest::AI_File, file);
    else
        currentLogElement->addAttribute(QTest::AI_File, "");

    QTest::qt_snprintf(buf, sizeof(buf), "%i", line);
    currentLogElement->addAttribute(QTest::AI_Line, buf);

    /*
        Since XFAIL does not add a failure to the testlog in xunitxml, add a message, so we still
        have some information about the expected failure.
    */
    if (format == TLF_XunitXml && type == QAbstractTestLogger::XFail) {
        QTestLogger::addMessage(QAbstractTestLogger::Info, description, file, line);
    }
}