mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-11 21:04:07 -07:00
QTTesting
Took 1 hour 28 minutes Took 4 seconds Took 28 minutes Took 8 minutes
This commit is contained in:
parent
7c7755b61d
commit
db0a642880
6 changed files with 166 additions and 9 deletions
|
|
@ -38,6 +38,10 @@
|
|||
#include "../interface/widgets/tabs/tab_supervisor.h"
|
||||
#include "../main.h"
|
||||
#include "logger.h"
|
||||
#include "pqEventObserver.h"
|
||||
#include "pqEventSource.h"
|
||||
#include "pqEventTypes.h"
|
||||
#include "pqTestUtility.h"
|
||||
#include "version_string.h"
|
||||
#include "widgets/utility/get_text_with_max.h"
|
||||
|
||||
|
|
@ -833,6 +837,137 @@ void MainWindow::createMenus()
|
|||
helpMenu->addAction(aOpenSettingsFolder);
|
||||
}
|
||||
|
||||
class XMLEventObserver : public pqEventObserver
|
||||
{
|
||||
QXmlStreamWriter *XMLStream;
|
||||
QString XMLString;
|
||||
|
||||
public:
|
||||
XMLEventObserver(QObject *p) : pqEventObserver(p)
|
||||
{
|
||||
this->XMLStream = NULL;
|
||||
}
|
||||
|
||||
~XMLEventObserver() override
|
||||
{
|
||||
delete this->XMLStream;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setStream(QTextStream *stream) override
|
||||
{
|
||||
if (this->XMLStream) {
|
||||
this->XMLStream->writeEndElement();
|
||||
this->XMLStream->writeEndDocument();
|
||||
delete this->XMLStream;
|
||||
this->XMLStream = NULL;
|
||||
}
|
||||
if (this->Stream) {
|
||||
*this->Stream << this->XMLString;
|
||||
}
|
||||
this->XMLString = QString();
|
||||
pqEventObserver::setStream(stream);
|
||||
if (this->Stream) {
|
||||
this->XMLStream = new QXmlStreamWriter(&this->XMLString);
|
||||
this->XMLStream->setAutoFormatting(true);
|
||||
this->XMLStream->writeStartDocument();
|
||||
this->XMLStream->writeStartElement("events");
|
||||
}
|
||||
}
|
||||
|
||||
void onRecordEvent(const QString &widget,
|
||||
const QString &command,
|
||||
const QString &arguments,
|
||||
const int &eventType) override
|
||||
{
|
||||
if (this->XMLStream) {
|
||||
this->XMLStream->writeStartElement("event");
|
||||
this->XMLStream->writeAttribute("widget", widget);
|
||||
if (eventType == pqEventTypes::ACTION_EVENT) {
|
||||
this->XMLStream->writeAttribute("command", command);
|
||||
} else // if(eventType == pqEventTypes::CHECK_EVENT)
|
||||
{
|
||||
this->XMLStream->writeAttribute("property", command);
|
||||
}
|
||||
this->XMLStream->writeAttribute("arguments", arguments);
|
||||
this->XMLStream->writeEndElement();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class XMLEventSource : public pqEventSource
|
||||
{
|
||||
typedef pqEventSource Superclass;
|
||||
QXmlStreamReader *XMLStream;
|
||||
|
||||
public:
|
||||
XMLEventSource(QObject *p) : Superclass(p)
|
||||
{
|
||||
this->XMLStream = NULL;
|
||||
}
|
||||
~XMLEventSource() override
|
||||
{
|
||||
delete this->XMLStream;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setContent(const QString &xmlfilename) override
|
||||
{
|
||||
delete this->XMLStream;
|
||||
this->XMLStream = NULL;
|
||||
|
||||
QFile xml(xmlfilename);
|
||||
if (!xml.open(QIODevice::ReadOnly)) {
|
||||
qDebug() << "Failed to load " << xmlfilename;
|
||||
return;
|
||||
}
|
||||
QByteArray data = xml.readAll();
|
||||
this->XMLStream = new QXmlStreamReader(data);
|
||||
/* This checked for valid event objects, but also caused the first event
|
||||
* to get dropped. Commenting this out in the example. If you wish to report
|
||||
* empty XML test files a flag indicating whether valid events were found is
|
||||
* probably the best way to go.
|
||||
while (!this->XMLStream->atEnd())
|
||||
{
|
||||
QXmlStreamReader::TokenType token = this->XMLStream->readNext();
|
||||
if (token == QXmlStreamReader::StartElement)
|
||||
{
|
||||
if (this->XMLStream->name() == "event")
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
} */
|
||||
if (this->XMLStream->atEnd()) {
|
||||
qDebug() << "Invalid xml";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int getNextEvent(QString &widget, QString &command, QString &arguments, int &eventType) override
|
||||
{
|
||||
if (this->XMLStream->atEnd()) {
|
||||
return DONE;
|
||||
}
|
||||
while (!this->XMLStream->atEnd()) {
|
||||
QXmlStreamReader::TokenType token = this->XMLStream->readNext();
|
||||
if (token == QXmlStreamReader::StartElement) {
|
||||
if (this->XMLStream->name() == "event") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this->XMLStream->atEnd()) {
|
||||
return DONE;
|
||||
}
|
||||
eventType = pqEventTypes::ACTION_EVENT;
|
||||
widget = this->XMLStream->attributes().value("widget").toString();
|
||||
command = this->XMLStream->attributes().value("command").toString();
|
||||
arguments = this->XMLStream->attributes().value("arguments").toString();
|
||||
return SUCCESS;
|
||||
}
|
||||
};
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), localServer(nullptr), bHasActivated(false), askedForDbUpdater(false),
|
||||
cardUpdateProcess(nullptr), logviewDialog(nullptr)
|
||||
|
|
@ -908,6 +1043,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
// run startup check async
|
||||
QTimer::singleShot(0, this, &MainWindow::startupConfigCheck);
|
||||
|
||||
this->TestUtility = new pqTestUtility(this);
|
||||
this->TestUtility->addEventObserver("xml", new XMLEventObserver(this));
|
||||
this->TestUtility->addEventSource("xml", new XMLEventSource(this));
|
||||
}
|
||||
|
||||
void MainWindow::startupConfigCheck()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue