src/testlib/qtestlogger.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
   209         else
   209         else
   210             failureElement->addAttribute(QTest::AI_File, "");
   210             failureElement->addAttribute(QTest::AI_File, "");
   211         QTest::qt_snprintf(buf, sizeof(buf), "%i", line);
   211         QTest::qt_snprintf(buf, sizeof(buf), "%i", line);
   212         failureElement->addAttribute(QTest::AI_Line, buf);
   212         failureElement->addAttribute(QTest::AI_Line, buf);
   213         failureElement->addAttribute(QTest::AI_Description, description);
   213         failureElement->addAttribute(QTest::AI_Description, description);
   214         const char* tag = QTestResult::currentDataTag();
   214         addTag(failureElement);
   215         if (tag) {
       
   216             failureElement->addAttribute(QTest::AI_Tag, tag);
       
   217         }
       
   218         currentLogElement->addLogElement(failureElement);
   215         currentLogElement->addLogElement(failureElement);
   219     }
   216     }
   220 
   217 
   221     /*
   218     /*
   222         Only one result can be shown for the whole testfunction.
   219         Only one result can be shown for the whole testfunction.
   265 void QTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
   262 void QTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
   266 {
   263 {
   267     QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark);
   264     QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark);
   268 //    printf("element %i", benchmarkElement->elementType());
   265 //    printf("element %i", benchmarkElement->elementType());
   269 
   266 
   270     benchmarkElement->addAttribute(QTest::AI_Metric, QBenchmarkGlobalData::current->measurer->metricText().toAscii().data());
   267     benchmarkElement->addAttribute(
       
   268         QTest::AI_Metric,
       
   269         QTest::benchmarkMetricName(QBenchmarkTestMethodData::current->result.metric));
   271     benchmarkElement->addAttribute(QTest::AI_Tag, result.context.tag.toAscii().data());
   270     benchmarkElement->addAttribute(QTest::AI_Tag, result.context.tag.toAscii().data());
   272     benchmarkElement->addAttribute(QTest::AI_Value, QByteArray::number(result.value).constData());
   271     benchmarkElement->addAttribute(QTest::AI_Value, QByteArray::number(result.value).constData());
   273 
   272 
   274     char buf[100];
   273     char buf[100];
   275     QTest::qt_snprintf(buf, sizeof(buf), "%i", result.iterations);
   274     QTest::qt_snprintf(buf, sizeof(buf), "%i", result.iterations);
   276     benchmarkElement->addAttribute(QTest::AI_Iterations, buf);
   275     benchmarkElement->addAttribute(QTest::AI_Iterations, buf);
   277     currentLogElement->addLogElement(benchmarkElement);
   276     currentLogElement->addLogElement(benchmarkElement);
   278 }
   277 }
   279 
   278 
       
   279 void QTestLogger::addTag(QTestElement* element)
       
   280 {
       
   281     const char *tag = QTestResult::currentDataTag();
       
   282     const char *gtag = QTestResult::currentGlobalDataTag();
       
   283     const char *filler = (tag && gtag) ? ":" : "";
       
   284     if ((!tag || !tag[0]) && (!gtag || !gtag[0])) {
       
   285         return;
       
   286     }
       
   287 
       
   288     if (!tag) {
       
   289         tag = "";
       
   290     }
       
   291     if (!gtag) {
       
   292         gtag = "";
       
   293     }
       
   294 
       
   295     QTestCharBuffer buf;
       
   296     QTest::qt_asprintf(&buf, "%s%s%s", gtag, filler, tag);
       
   297     element->addAttribute(QTest::AI_Tag, buf.constData());
       
   298 }
       
   299 
   280 void QTestLogger::addMessage(MessageTypes type, const char *message, const char *file, int line)
   300 void QTestLogger::addMessage(MessageTypes type, const char *message, const char *file, int line)
   281 {
   301 {
   282     QTestElement *errorElement = new QTestElement(QTest::LET_Error);
   302     QTestElement *errorElement = new QTestElement(QTest::LET_Error);
   283     const char *typeBuf = 0;
   303     const char *typeBuf = 0;
   284 
   304 
   295         ++qdebugCounter;
   315         ++qdebugCounter;
   296         typeBuf = "qdebug";
   316         typeBuf = "qdebug";
   297         break;
   317         break;
   298     case QAbstractTestLogger::QWarning:
   318     case QAbstractTestLogger::QWarning:
   299         ++qwarnCounter;
   319         ++qwarnCounter;
   300         typeBuf = "qwarning";
   320         typeBuf = "qwarn";
   301         break;
   321         break;
   302     case QAbstractTestLogger::QFatal:
   322     case QAbstractTestLogger::QFatal:
   303         ++qfatalCounter;
   323         ++qfatalCounter;
   304         typeBuf = "qfatal";
   324         typeBuf = "qfatal";
   305         break;
   325         break;
   316         break;
   336         break;
   317     }
   337     }
   318 
   338 
   319     errorElement->addAttribute(QTest::AI_Type, typeBuf);
   339     errorElement->addAttribute(QTest::AI_Type, typeBuf);
   320     errorElement->addAttribute(QTest::AI_Description, message);
   340     errorElement->addAttribute(QTest::AI_Description, message);
       
   341     addTag(errorElement);
   321 
   342 
   322     if(file)
   343     if(file)
   323         errorElement->addAttribute(QTest::AI_File, file);
   344         errorElement->addAttribute(QTest::AI_File, file);
   324     else
   345     else
   325         errorElement->addAttribute(QTest::AI_File, "");
   346         errorElement->addAttribute(QTest::AI_File, "");