diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:18:55 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:18:55 (GMT) |
commit | e5fcad302d86d316390c6b0f62759a067313e8a9 (patch) | |
tree | c2afbf6f1066b6ce261f14341cf6d310e5595bc1 /tests/arthur/htmlgenerator | |
download | Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.zip Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.bz2 |
Long live Qt 4.5!
Diffstat (limited to 'tests/arthur/htmlgenerator')
-rw-r--r-- | tests/arthur/htmlgenerator/htmlgenerator.cpp | 518 | ||||
-rw-r--r-- | tests/arthur/htmlgenerator/htmlgenerator.h | 126 | ||||
-rw-r--r-- | tests/arthur/htmlgenerator/htmlgenerator.pro | 18 | ||||
-rw-r--r-- | tests/arthur/htmlgenerator/main.cpp | 54 |
4 files changed, 716 insertions, 0 deletions
diff --git a/tests/arthur/htmlgenerator/htmlgenerator.cpp b/tests/arthur/htmlgenerator/htmlgenerator.cpp new file mode 100644 index 0000000..5928dc7 --- /dev/null +++ b/tests/arthur/htmlgenerator/htmlgenerator.cpp @@ -0,0 +1,518 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "htmlgenerator.h" + +#include "xmldata.h" + +#include <QtXml> + +#include <QFile> +#include <QStringList> +#include <QDateTime> +#include <QtDebug> + +#include <iostream> + +static void generateIndex(QTextStream &out) +{ + out <<"\ +<html>\n\ + <head><title>SVG rendering comparison</title></head>\n\ + <body bgcolor=\"white\">\n\ + <h1>QSvg testing framework</h1>\n\ + <table border=\"1\">\n\ + <tr><td>Testing suite</td><td>History</td></tr>\n\ + <tr>\n\ + <td><a href=\"test1.1-full.html\">1.1</a></td>\n\ + <td><a href=\"test1.1-history.html\">1.1 history</a></td>\n\ + </tr>\n\ + <tr>\n\ + <td><a href=\"test1.2-full.html\">1.2 testing suite</a></td>\n\ + <td><a href=\"test1.2-history.html\">1.2 QSvg history</a></td>\n\ + </tr>\n\ + <tr>\n\ + <td><a href=\"testrandom-full.html\">Random testing suite</a></td>\n\ + <td><a href=\"testrandom-history.html\">Random tests QSvg history</a></td>\n\ + </tr>\n\ + </body>\n\ +</html>\n"; +} + + +static void usage(const char *progname) +{ + std::cerr << "Couldn't find 'framework.ini' " + << "file and no output has been specified."<<std::endl; + std::cerr << "Usage: "<<progname + << " -framework <framework.ini>" + << " dirname\n" + << std::endl; +} + + +HTMLGenerator::HTMLGenerator() + : settings(0) +{ + if (QFile::exists("framework.ini")) { + settings = new QSettings("framework.ini", QSettings::IniFormat); + } +} + +void HTMLGenerator::generateIndex(const QString &) +{ + +} + +void HTMLGenerator::generatePages() +{ + foreach(HTMLSuite *suite, suites) { + generateSuite(*suite); + } +} + +struct HTMLPage +{ + QString pageName; + QStringList headings; + QList<HTMLRow> rows; +}; +void HTMLGenerator::generateSuite(const HTMLSuite &suite) +{ + generateReferencePage(suite); + generateHistoryPages(suite); + generateQtComparisonPage(suite); +} + +void HTMLGenerator::generateReferencePage(const HTMLSuite &suite) +{ + + bool generateReference = false; + QStringList generators; + foreach(HTMLRow *row, suite.rows) { + foreach(HTMLImage refs, row->referenceImages) { + generators += refs.generatorName; + foreach(HTMLImage img, row->images) { + if ((img.flags & Default)) { + generators += img.generatorName; + break; + } + } + foreach(HTMLImage img, row->foreignImages) { + generators += img.generatorName; + } + generateReference = true; + break; + } + if (generateReference) + break; + } + + if (!generateReference) + return; + + QFile file(QString("test-%1-reference.html").arg(suite.name)); + if (!file.open(QFile::WriteOnly | QFile::Truncate)) { + return; + } + + QTextStream out(&file); + generateHeader(out, "Reference Page", generators); + + foreach(HTMLRow *row, suite.rows) { + bool referenceRow = false; + QList<HTMLImage> images; + foreach(HTMLImage refs, row->referenceImages) { + startGenerateRow(out, row->testcase); + referenceRow = true; + images.append(refs); + break; + } + if (referenceRow) { + foreach(HTMLImage img, row->images) { + if ((img.flags & Default)) { + images.append(img); + break; + } + } + images << row->foreignImages; + + generateImages(out, images); + finishGenerateRow(out, row->testcase); + } + } + + generateFooter(out); +} + +void HTMLGenerator::generateHistoryPages(const HTMLSuite &suite) +{ + QStringList lst; + foreach(XMLEngine *engine, engines) { + generateHistoryForEngine(suite, engine->name); + } +} + +void HTMLGenerator::generateHistoryForEngine(const HTMLSuite &suite, const QString &engine) +{ + QFile file(QString("test-%1-%2-history.html").arg(suite.name).arg(engine)); + if (!file.open(QFile::WriteOnly | QFile::Truncate)) { + return; + } + + QTextStream out(&file); + + QStringList generators; + foreach(HTMLRow *row, suite.rows) { + foreach(HTMLImage refs, row->referenceImages) { + generators += refs.generatorName; + generators += "Today"; + generators += "Yesterday"; + generators += "Last Week"; + break; + } + if (!generators.isEmpty()) + break; + } + if (generators.isEmpty()) { + generators += "Today"; + generators += "Yesterday"; + generators += "Last Week"; + } + generateHeader(out, QString("History for %1 engine").arg(engine), generators); + + foreach(HTMLRow *row, suite.rows) { + QList<HTMLImage> images; + QStringList generators; + foreach(HTMLImage refs, row->referenceImages) { + generators += refs.generatorName; + images.append(refs); + break; + } + + startGenerateRow(out, row->testcase); + foreach(HTMLImage img, row->images) { + if (img.generatorName == engine) { + images << img; + } + } + + generateHistoryImages(out, images); + finishGenerateRow(out, row->testcase); + } + + generateFooter(out); +} + + +void HTMLGenerator::generateQtComparisonPage(const HTMLSuite &suite) +{ + QFile file(QString("test-%1-comparison.html").arg(suite.name)); + if (!file.open(QFile::WriteOnly | QFile::Truncate)) { + return; + } + + QTextStream out(&file); + + QStringList lst; + foreach(XMLEngine *engine, engines) { + if (!engine->foreignEngine && !engine->referenceEngine) + lst += engine->name; + } + + generateHeader(out, QString("Qt Engine Comparison"), lst); + foreach(HTMLRow *row, suite.rows) { + QList<HTMLImage> images; + + startGenerateRow(out, row->testcase); + foreach(HTMLImage img, row->images) { + images.append(img); + } + generateImages(out, images); + finishGenerateRow(out, row->testcase); + } + + generateFooter(out); +} + + +void HTMLGenerator::generateHeader(QTextStream &out, const QString &name, + const QStringList &generators) +{ + out << "<html>\n" + << "<head><title>"<<name<<"</title></head>\n" + << "<body bgcolor=\"white\">\n" + << "<a href=\"index.html\">Click here to go back to main page</a>\n" + << "<p><center><h2> Generated: "<<QDateTime::currentDateTime().toString() + <<"</h2></center></p>\n" + << "<table border=\"1\">\n"; + + out << "<tr>"; + foreach(QString generator, generators) { + out <<"<td><b>"<<generator<<"</b></td>\n"; + } + out<<"</tr>\n"; + +} + +void HTMLGenerator::startGenerateRow(QTextStream &out, const QString &name) +{ + Q_UNUSED(name); + out <<" <tr>\n"; +} + +void HTMLGenerator::generateImages(QTextStream &out, + const QList<HTMLImage> &images) +{ + out <<" <tr>\n"; + foreach(HTMLImage image, images) { + out <<" <td valign=top><img src=\""<< image.file <<"\"></td>\n"; + } + out <<" </tr>\n"; + out <<" <tr>\n"; + foreach(HTMLImage image, images) { + out <<" <td><center>" + << image.generatorName << ": " + << image.details <<" ms </center></td>\n"; + } +} + +void HTMLGenerator::generateHistoryImages(QTextStream &out, + const QList<HTMLImage> &images) +{ + foreach(HTMLImage image, images) { + if ((image.flags & Reference)) { + out <<" <td><img src=\""<< image.file + <<"\" width=480 height=360></td>\n"; + } else { + QString genName = image.generatorName; + QString file = image.file.replace(image.generatorName, ""); + out <<" <td><img src=\""<<image.generatorName + << file <<"\"></td>\n" + <<" <td><img src=\""<<image.generatorName + <<".yesterday"<< file <<"\"></td>\n" + <<" <td><img src=\""<<image.generatorName + <<".lastweek"<< file <<"\"></td>\n"; + } + } +} + + +void HTMLGenerator::finishGenerateRow(QTextStream &out, const QString &name) +{ + out <<" </tr>\n" + <<" <tr><td colspan=5 bgcolor=yellow><center>" + <<name<<"</center></td>\n"; +} + +void HTMLGenerator::generateFooter(QTextStream &out) +{ + out << "</table>\n" + << "</body>\n" + << "</html>\n"; +} + +void HTMLGenerator::run(int argc, char **argv) +{ + processArguments(argc, argv); + + QDir dir; + dir.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot); + QFileInfoList list = dir.entryInfoList(); + for (int i = 0; i < list.size(); ++i) { + QFileInfo fileInfo = list.at(i); + + QString dataFile = QString("%1/data.xml") + .arg(fileInfo.absoluteFilePath()); + if (QFile::exists(dataFile)) { + XMLReader handler; + QXmlSimpleReader reader; + reader.setContentHandler(&handler); + reader.setErrorHandler(&handler); + + QFile file(dataFile); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + qWarning("Cannot open file '%s', because: %s", + qPrintable(dataFile), qPrintable(file.errorString())); + continue; + } + + QXmlInputSource xmlInputSource(&file); + if (reader.parse(xmlInputSource)) { + XMLEngine *engine = handler.xmlEngine(); + engines.insert(engine->name, engine); + } + } + } + + if (engines.isEmpty()) { + usage(argv[0]); + return; + } + + convertToHtml(); + generatePages(); +} + +void HTMLGenerator::processArguments(int argc, char **argv) +{ + QString frameworkFile; + for (int i=1; i < argc; ++i) { + QString opt(argv[i]); + if (opt == "-framework") { + frameworkFile = QString(argv[++i]); + } else { + outputDirName = opt; + } + } + + if (!frameworkFile.isEmpty() && QFile::exists(frameworkFile)) { + delete settings; + baseDataDir = QFileInfo(frameworkFile).absoluteDir().absolutePath(); + settings = new QSettings(frameworkFile, QSettings::IniFormat); + } + + if (!outputDirName.isEmpty()) { + QDir::setCurrent(outputDirName); + } + htmlOutputDir = QString("html"); + QDir dir; + dir.mkpath(htmlOutputDir); +} + +void HTMLGenerator::convertToHtml() +{ + foreach(XMLEngine *engine, engines) { + foreach(XMLSuite *suite, engine->suites) { + QString refUrl; + QString refPrefix; + if (settings) { + settings->beginGroup(suite->name); + refUrl = settings->value("reference").toString(); + refPrefix = settings->value("referencePrefix").toString(); + if (refUrl.endsWith('/')) + refUrl.chop(1); + settings->endGroup(); + } + + foreach(XMLFile *file, suite->files) { + HTMLImage image; + image.file = file->output; + image.generatorName = engine->name; + + image.details = file->data.last().iterations == 0 + ? QString::number(-1) + : QString::number(file->data.last().timeToRender + / file->data.last().iterations); + image.flags = Normal; + + if (file->data.last().timeToRender == 0) + image.details = file->data.last().details; + + if (engine->defaultEngine) + image.flags |= Default; + if (engine->foreignEngine) { + image.flags ^= Normal; + image.flags |= Foreign; + } + if (engine->referenceEngine) { + image.flags ^= Normal; + image.flags |= Reference; + } + + if (!outputDirName.isEmpty() && image.file.startsWith(outputDirName)) + image.file.remove(0, outputDirName.length() + 1); // + '/' + HTMLSuite *htmlSuite = suites[suite->name]; + if (!htmlSuite) { + htmlSuite = new HTMLSuite; + htmlSuite->name = suite->name; + suites.insert(suite->name, htmlSuite); + } + HTMLRow *htmlRow = htmlSuite->rows[file->name]; + if (!htmlRow) { + htmlRow = new HTMLRow; + htmlRow->testcase = file->name; + htmlSuite->rows.insert(file->name, htmlRow); + } + + if ((image.flags & Foreign)) + htmlRow->foreignImages.append(image); + else if ((image.flags & Reference)) + htmlRow->referenceImages.append(image); + else { + htmlRow->images.append(image); + } + if (!refUrl.isEmpty()) { + QFileInfo fi(file->output); + HTMLImage image; + image.file = QString("%1/%2%3") + .arg(refUrl) + .arg(refPrefix) + .arg(fi.fileName()); + image.generatorName = QString("Reference"); + image.details = QString("Reference"); + image.flags = Reference; + if (htmlRow) { + htmlRow->referenceImages.append(image); + } + } + } + } + } +} + +void HTMLGenerator::createPerformance() +{ +#if 0 + QFile file(QString("test-performance.html")); + if (!file.open(QFile::WriteOnly | QFile::Truncate)) { + return; + } + + QTextStream out(&file); + foreach(XMLEngine *engine, engines) { + QImage img = createHistoryImage(engine); + QImage ; + + } +#endif +} + + diff --git a/tests/arthur/htmlgenerator/htmlgenerator.h b/tests/arthur/htmlgenerator/htmlgenerator.h new file mode 100644 index 0000000..2a91fe5 --- /dev/null +++ b/tests/arthur/htmlgenerator/htmlgenerator.h @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef HTMLGENERATOR_H +#define HTMLGENERATOR_H + +#include "xmldata.h" + +#include <QTextStream> +#include <QList> +#include <QString> + +QT_FORWARD_DECLARE_CLASS(QStringList) +QT_FORWARD_DECLARE_CLASS(QSettings) + +struct HTMLImage +{ +public: + QString file; + QString generatorName; + GeneratorFlags flags; + QString details; +}; + +struct HTMLRow +{ +public: + QString testcase; + QList<HTMLImage> referenceImages; + QList<HTMLImage> foreignImages; + QList<HTMLImage> images; +}; + +struct HTMLSuite +{ +public: + QString name; + QMap<QString, HTMLRow*> rows; +}; + +class HTMLGenerator +{ +public: + HTMLGenerator(); + + void startSuite(const QString &name); + void startRow(const QString &testcase); + void addImage(const QString &generator, const QString &image, + const QString &details, GeneratorFlags flags); + void endRow(); + void endSuite(); + + void generateIndex(const QString &file); + void generatePages(); + + void run(int argc, char **argv); + +private: + void generateSuite(const HTMLSuite &suite); + + void generateReferencePage(const HTMLSuite &suite); + void generateHistoryPages(const HTMLSuite &suite); + void generateHistoryForEngine(const HTMLSuite &suite, const QString &engine); + void generateQtComparisonPage(const HTMLSuite &suite); + + void generateHeader(QTextStream &out, const QString &name, + const QStringList &generators); + void startGenerateRow(QTextStream &out, const QString &name); + void generateImages(QTextStream &out, + const QList<HTMLImage> &images); + void generateHistoryImages(QTextStream &out, + const QList<HTMLImage> &images); + void finishGenerateRow(QTextStream &out, const QString &name); + void generateFooter(QTextStream &out); + + void processArguments(int argc, char **argv); + void convertToHtml(); + void createPerformance(); +private: + QMap<QString, HTMLSuite*> suites; + QMap<QString, XMLEngine*> engines; + + QSettings *settings; + QString outputDirName; + QString baseDataDir; + QString htmlOutputDir; +}; + +#endif diff --git a/tests/arthur/htmlgenerator/htmlgenerator.pro b/tests/arthur/htmlgenerator/htmlgenerator.pro new file mode 100644 index 0000000..f74c460 --- /dev/null +++ b/tests/arthur/htmlgenerator/htmlgenerator.pro @@ -0,0 +1,18 @@ +# -*- Mode: makefile -*- +COMMON_FOLDER = $$PWD/../common +include(../arthurtester.pri) +TEMPLATE = app +TARGET = htmlgenerator +DEPENDPATH += . +INCLUDEPATH += . +DESTDIR = ../bin + +CONFIG += console + +QT += svg opengl xml qt3support + +# Input +HEADERS += htmlgenerator.h +SOURCES += main.cpp htmlgenerator.cpp + + diff --git a/tests/arthur/htmlgenerator/main.cpp b/tests/arthur/htmlgenerator/main.cpp new file mode 100644 index 0000000..537e570 --- /dev/null +++ b/tests/arthur/htmlgenerator/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QApplication> + +#include "htmlgenerator.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + HTMLGenerator generator; + + generator.run(argc, argv); + + return 0; +} |