removed warnings; code cleaned up

master
Marc Wäckerlin 6 years ago
parent 7c7786eb04
commit a1c721f45d
  1. 97
      src/commands.hxx
  2. 8
      src/editor.hxx
  3. 8
      src/exceptions.hxx
  4. 4
      src/networkaccessmanager.hxx
  5. 4
      src/scriptfile.hxx
  6. 36
      src/testgui.hxx
  7. 20
      src/webpage.hxx
  8. 4
      src/webrunner.cxx

@ -105,7 +105,7 @@ class Logger {
}; };
class Command: public QObject { class Command: public QObject {
Q_OBJECT; Q_OBJECT
public: public:
Command(): _log(true), _line(-1), _indent(0) {} Command(): _log(true), _line(-1), _indent(0) {}
virtual ~Command() {} virtual ~Command() {}
@ -119,7 +119,7 @@ class Command: public QObject {
log(QString(" FAILED[")+demangle(typeid(e).name())+"]: "+e.what()); log(QString(" FAILED[")+demangle(typeid(e).name())+"]: "+e.what());
throw e; throw e;
} }
virtual int steps(Script* parent) { virtual int steps(Script*) {
return 1; return 1;
} }
void line(int linenr) { void line(int linenr) {
@ -198,10 +198,11 @@ class Command: public QObject {
QStringList args = QStringList()); QStringList args = QStringList());
QStringList subCommandBlock(QStringList& in) { QStringList subCommandBlock(QStringList& in) {
QStringList commands; QStringList commands;
int pos(-1); std::string::size_type pos(std::string::npos);
while (in.size() && in[0].size() && in[0][0]==' ' while (in.size() && in[0].size() && in[0][0]==' '
&& pos<=(signed)in[0].toStdString().find_first_not_of(' ')) { && (pos==std::string::npos ||
if (pos<0) pos=in[0].toStdString().find_first_not_of(' '); pos<=in[0].toStdString().find_first_not_of(' '))) {
if (pos==std::string::npos) pos=in[0].toStdString().find_first_not_of(' ');
commands += in.takeFirst().mid(pos); commands += in.takeFirst().mid(pos);
} }
return commands; return commands;
@ -252,7 +253,7 @@ class Command: public QObject {
for (int i=0; i<repeat; ++i) { for (int i=0; i<repeat; ++i) {
element = frame->findFirstElement(selector); element = frame->findFirstElement(selector);
if (!element.isNull()) return element; if (!element.isNull()) return element;
Q_FOREACH(QWebFrame* childFrame, frame->childFrames()) { for (QWebFrame* childFrame: frame->childFrames()) {
element = find1(childFrame, selector, 1, 0); element = find1(childFrame, selector, 1, 0);
if (!element.isNull()) return element; if (!element.isNull()) return element;
} }
@ -403,7 +404,7 @@ class Screenshot: public Command {
}; };
class RunDownload: public QObject { class RunDownload: public QObject {
Q_OBJECT; Q_OBJECT
public: public:
RunDownload(QNetworkReply* reply, QString filename): RunDownload(QNetworkReply* reply, QString filename):
_reply(reply), _file(filename) { _reply(reply), _file(filename) {
@ -445,7 +446,7 @@ class RunDownload: public QObject {
-# test scripts, see @ref testscript. */ -# test scripts, see @ref testscript. */
class Script: public QObject { class Script: public QObject {
Q_OBJECT; Q_OBJECT
Q_SIGNALS: Q_SIGNALS:
void logging(QString); void logging(QString);
void progress(QString, int, int); void progress(QString, int, int);
@ -486,17 +487,17 @@ class Script: public QObject {
} }
public: public:
Script(): Script():
_step(0), _clicktype(JAVASCRIPT_CLICK), _command(0), _step(0), _clicktype(JAVASCRIPT_CLICK),
_screenshots(true), _defaultTimeout(20) { _screenshots(true), _command(0), _defaultTimeout(20) {
initPrototypes(); initPrototypes();
} }
Script(const Script& o): Script(const Script& o):
QObject(), QObject(),
_step(0),
_prototypes(o._prototypes), _prototypes(o._prototypes),
_step(0),
_script(o._script), _script(o._script),
_command(0), _screenshots(true),
_screenshots(true) { _command(0) {
set(o); set(o);
} }
QString syntax() const { QString syntax() const {
@ -861,7 +862,7 @@ class Script: public QObject {
void ignore(QStringList sigs = QStringList()) { void ignore(QStringList sigs = QStringList()) {
if (sigs.empty()) if (sigs.empty())
sigs<<"loadFinished"<<"loadStarted"<<"frameChanged"<<"titleChanged"<<"urlChanged"; sigs<<"loadFinished"<<"loadStarted"<<"frameChanged"<<"titleChanged"<<"urlChanged";
Q_FOREACH(const QString& sig, sigs) { for (const QString& sig: sigs) {
log("start ignoring: '"+sig+"'"); log("start ignoring: '"+sig+"'");
_ignore<<sig; _ignore<<sig;
} }
@ -869,7 +870,7 @@ class Script: public QObject {
void unignore(QStringList sigs = QStringList()) { void unignore(QStringList sigs = QStringList()) {
if (sigs.empty()) if (sigs.empty())
sigs<<"loadFinished"<<"loadStarted"<<"frameChanged"<<"titleChanged"<<"urlChanged"; sigs<<"loadFinished"<<"loadStarted"<<"frameChanged"<<"titleChanged"<<"urlChanged";
Q_FOREACH(const QString& sig, sigs) { for (const QString& sig: sigs) {
if (_ignore.contains(sig)) { if (_ignore.contains(sig)) {
log("stop ignoring: '"+sig+"'"); log("stop ignoring: '"+sig+"'");
_ignore.erase(_ignore.find(sig)); _ignore.erase(_ignore.find(sig));
@ -1190,7 +1191,7 @@ class CommandContainer: public Command {
return countSteps(parent); return countSteps(parent);
} }
protected: protected:
virtual int countSteps(Script* parent) const { virtual int countSteps(Script*) const {
return _script->countSteps()+1; return _script->countSteps()+1;
} }
std::shared_ptr<Script> _script; std::shared_ptr<Script> _script;
@ -1580,7 +1581,7 @@ class Exists: public Command {
QString text(script->replacevars(_text)); QString text(script->replacevars(_text));
QStringList notfound; QStringList notfound;
QWebElement firstelement(find(frame, selector, script->timeout()-1)); QWebElement firstelement(find(frame, selector, script->timeout()-1));
Q_FOREACH(QWebElement element, frame->findAllElements(selector)) { for (QWebElement element: frame->findAllElements(selector)) {
if (text.isEmpty()) return true; // just find element if (text.isEmpty()) return true; // just find element
if (element.toOuterXml().indexOf(text)!=-1) return true; if (element.toOuterXml().indexOf(text)!=-1) return true;
if (element.toPlainText().indexOf(text)!=-1) return true; if (element.toPlainText().indexOf(text)!=-1) return true;
@ -1636,7 +1637,7 @@ class Not: public Command {
QString text(script->replacevars(_text)); QString text(script->replacevars(_text));
QWebElement firstelement(find(frame, selector, QWebElement firstelement(find(frame, selector,
mrw::max(mrw::min(script->timeout()/3, 10), 2))); mrw::max(mrw::min(script->timeout()/3, 10), 2)));
Q_FOREACH(QWebElement element, frame->findAllElements(selector)) { for (QWebElement element: frame->findAllElements(selector)) {
if (text.isEmpty()) if (text.isEmpty())
error(log, AssertionFailed("element must not exists: "+selector)); error(log, AssertionFailed("element must not exists: "+selector));
if (element.toOuterXml().indexOf(text)!=-1) if (element.toOuterXml().indexOf(text)!=-1)
@ -1685,7 +1686,7 @@ class Execute: public Command {
QString command(script->replacevars(_command)); QString command(script->replacevars(_command));
QStringList args; QStringList args;
QString scripttxt(script->replacevars(_script.join("\n"))); QString scripttxt(script->replacevars(_script.join("\n")));
Q_FOREACH(QString arg, _args) args.push_back(script->replacevars(arg)); for (QString arg: _args) args.push_back(script->replacevars(arg));
QProcess exec; QProcess exec;
exec.setProcessChannelMode(QProcess::MergedChannels); exec.setProcessChannelMode(QProcess::MergedChannels);
exec.start(command, args); exec.start(command, args);
@ -1699,14 +1700,14 @@ class Execute: public Command {
exec.closeWriteChannel(); exec.closeWriteChannel();
if (!exec.waitForFinished(60000) && exec.state()!=QProcess::NotRunning) if (!exec.waitForFinished(60000) && exec.state()!=QProcess::NotRunning)
error(log, ScriptNotFinished(command, args, scripttxt)); error(log, ScriptNotFinished(command, args, scripttxt));
QString stdout(exec.readAllStandardOutput()); QString sout(exec.readAllStandardOutput());
QString stderr(exec.readAllStandardError()); QString serr(exec.readAllStandardError());
_result = stdout; _result = sout;
log("result: "+(_result.size()?_result:"(void)")); log("result: "+(_result.size()?_result:"(void)"));
script->log(stdout); script->log(sout);
if (exec.exitCode()!=0 || exec.exitStatus()!=QProcess::NormalExit) if (exec.exitCode()!=0 || exec.exitStatus()!=QProcess::NormalExit)
error(log, ScriptExecutionFailed(command, args, scripttxt, error(log, ScriptExecutionFailed(command, args, scripttxt,
exec.exitCode(), stdout, stderr)); exec.exitCode(), sout, serr));
return true; return true;
} }
private: private:
@ -1716,7 +1717,7 @@ class Execute: public Command {
}; };
class Download: public Command { class Download: public Command {
Q_OBJECT; Q_OBJECT
public: public:
QString tag() const { QString tag() const {
return "download"; return "download";
@ -2158,7 +2159,7 @@ class SetValue: public Command {
if (element.tagName()=="SELECT") { if (element.tagName()=="SELECT") {
// value is a comma seperated list of option values // value is a comma seperated list of option values
QStringList values(commaSeparatedList(value)); QStringList values(commaSeparatedList(value));
Q_FOREACH(QWebElement option, element.findAll("option")) { for (QWebElement option: element.findAll("option")) {
QString name(option.evaluateJavaScript("this.value").toString()); QString name(option.evaluateJavaScript("this.value").toString());
option.evaluateJavaScript option.evaluateJavaScript
("this.selected="+QString(values.contains(name)?"true;":"false;")); ("this.selected="+QString(values.contains(name)?"true;":"false;"));
@ -2224,6 +2225,7 @@ class Function: public CommandContainer {
return runScript(log, parentCommand, _script, script, frame, _vars, args); return runScript(log, parentCommand, _script, script, frame, _vars, args);
} catch (const Exception& x) { } catch (const Exception& x) {
error(log, FunctionCallFailed(_name, _vars, args, x)); error(log, FunctionCallFailed(_name, _vars, args, x));
return false; // never reached due to exception above
} }
} }
private: private:
@ -2342,7 +2344,7 @@ class If: public CommandContainer {
if (_cmp=="->") { if (_cmp=="->") {
QWebElement firstelement(find(frame, selector, QWebElement firstelement(find(frame, selector,
mrw::max(mrw::min(script->timeout()/3, 10), 2))); mrw::max(mrw::min(script->timeout()/3, 10), 2)));
Q_FOREACH(QWebElement element, frame->findAllElements(selector)) { for (QWebElement element: frame->findAllElements(selector)) {
if (value.isEmpty() || // just find element if (value.isEmpty() || // just find element
element.toOuterXml().indexOf(value)!=-1 || element.toOuterXml().indexOf(value)!=-1 ||
element.toPlainText().indexOf(value)!=-1) { element.toPlainText().indexOf(value)!=-1) {
@ -2449,7 +2451,7 @@ class While: public CommandContainer {
check = false; check = false;
QWebElement firstelement(find(frame, selector, QWebElement firstelement(find(frame, selector,
mrw::max(mrw::min(script->timeout()/3, 10), 2))); mrw::max(mrw::min(script->timeout()/3, 10), 2)));
Q_FOREACH(QWebElement element, frame->findAllElements(selector)) { for (QWebElement element: frame->findAllElements(selector)) {
if (value.isEmpty() || // just find element if (value.isEmpty() || // just find element
element.toOuterXml().indexOf(value)!=-1 || element.toOuterXml().indexOf(value)!=-1 ||
element.toPlainText().indexOf(value)!=-1) { element.toPlainText().indexOf(value)!=-1) {
@ -2511,7 +2513,7 @@ class TestSuite: public Command {
cmd->_name = args; cmd->_name = args;
return cmd; return cmd;
} }
bool execute(Script* script, QWebFrame* frame) { bool execute(Script* script, QWebFrame*) {
Logger log(this, script); Logger log(this, script);
script->testsuite(script->replacevars(_name)); script->testsuite(script->replacevars(_name));
return true; return true;
@ -2540,7 +2542,7 @@ class TestCase: public Command {
cmd->_name = args; cmd->_name = args;
return cmd; return cmd;
} }
bool execute(Script* script, QWebFrame* frame) { bool execute(Script* script, QWebFrame*) {
Logger log(this, script); Logger log(this, script);
script->testclass(script->replacevars(_name)); script->testclass(script->replacevars(_name));
return true; return true;
@ -2648,7 +2650,7 @@ class For: public CommandContainer {
" in the loop.\n\n" " in the loop.\n\n"
"Without values, if there is a global variable with the same name as the" "Without values, if there is a global variable with the same name as the"
" local variable the global variable is parsed as if it were the line after" " local variable the global variable is parsed as if it were the line after"
" the dash (->).\n\n"; " the dash (->).\n\n"
"If you quote the values, then quote all values with the same" "If you quote the values, then quote all values with the same"
" quotes. If you need a comma within a value, you must quote."; " quotes. If you need a comma within a value, you must quote.";
} }
@ -2667,7 +2669,7 @@ class For: public CommandContainer {
} }
bool execute(Script* script, QWebFrame* frame) { bool execute(Script* script, QWebFrame* frame) {
Logger log(this, script); Logger log(this, script);
Q_FOREACH(QString i, _vals.size()?_vals:commaSeparatedList(script->variable(_variable))) { for (QString i: _vals.size()?_vals:commaSeparatedList(script->variable(_variable))) {
if (!runScript(log, this, _script, script, frame, QStringList()<<_variable, QStringList()<<i)) if (!runScript(log, this, _script, script, frame, QStringList()<<_variable, QStringList()<<i))
return false; return false;
} }
@ -2706,7 +2708,7 @@ class Echo: public Command {
cmd->_text = args; cmd->_text = args;
return cmd; return cmd;
} }
bool execute(Script* script, QWebFrame* frame) { bool execute(Script* script, QWebFrame*) {
Logger log(this, script); Logger log(this, script);
log(script->replacevars(_text)); log(script->replacevars(_text));
return true; return true;
@ -2774,7 +2776,7 @@ class ClearCookies: public Command {
QString url(_url); QString url(_url);
if (url.isEmpty()) url = frame->url().toString(); if (url.isEmpty()) url = frame->url().toString();
QNetworkCookieJar* cookies = frame->page()->networkAccessManager()->cookieJar(); QNetworkCookieJar* cookies = frame->page()->networkAccessManager()->cookieJar();
Q_FOREACH(QNetworkCookie cookie, cookies->cookiesForUrl(url)) { for (QNetworkCookie cookie: cookies->cookiesForUrl(url)) {
log("delete cookie "+cookie.name()); log("delete cookie "+cookie.name());
cookies->deleteCookie(cookie); cookies->deleteCookie(cookie);
} }
@ -2810,7 +2812,7 @@ class Include: public CommandContainer {
} catch (Exception& e) { } catch (Exception& e) {
throw ParseIncludeFailed(cmd->_filename, e.what()); throw ParseIncludeFailed(cmd->_filename, e.what());
} }
Q_FOREACH(QString key, cmd->_script->functions()) // copy new functions to parent for (QString key: cmd->_script->functions()) // copy new functions to parent
script->function(key, cmd->_script->function(key)); script->function(key, cmd->_script->function(key));
return cmd; return cmd;
} }
@ -2820,6 +2822,7 @@ class Include: public CommandContainer {
return runScript(log, this, _script, script, frame); return runScript(log, this, _script, script, frame);
} catch (Exception& e) { } catch (Exception& e) {
error(log, ExecuteIncludeFailed(_filename, e.what())); error(log, ExecuteIncludeFailed(_filename, e.what()));
return false; // never reached due to exception above
} }
} }
private: private:
@ -2837,7 +2840,7 @@ class Case: public Command {
" <cmp1> <value1>\n" " <cmp1> <value1>\n"
" <command>\n" " <command>\n"
" <command>\n" " <command>\n"
" <cmp1> <value2>\n" " <cmp2> <value2>\n"
" <command>\n" " <command>\n"
" <command>\n" " <command>\n"
" <...>\n" " <...>\n"
@ -2873,7 +2876,7 @@ class Case: public Command {
} }
QString command() const { QString command() const {
QString body; QString body;
Q_FOREACH(Condition condition, _conditions) { for (Condition condition: _conditions) {
body += "\n "+condition.cmp+" "+condition.value+"\n " body += "\n "+condition.cmp+" "+condition.value+"\n "
+condition.script->print().join("\n "); +condition.script->print().join("\n ");
} }
@ -2886,6 +2889,7 @@ class Case: public Command {
if (!args.size()) throw BadArgument(tag()+" requires a <variable> or <selector>"); if (!args.size()) throw BadArgument(tag()+" requires a <variable> or <selector>");
cmd->_variable = args; cmd->_variable = args;
QStringList body(subCommandBlock(in)); QStringList body(subCommandBlock(in));
if (!body.size()) throw BadArgument(tag()+" requires a body");
while (body.size()) { while (body.size()) {
++line; ++line;
QStringList parts(body.takeFirst().split(' ')); QStringList parts(body.takeFirst().split(' '));
@ -2902,7 +2906,7 @@ class Case: public Command {
bool execute(Script* script, QWebFrame* frame) { bool execute(Script* script, QWebFrame* frame) {
Logger log(this, script, false); Logger log(this, script, false);
QString selector(script->replacevars(_variable)); QString selector(script->replacevars(_variable));
Q_FOREACH(Condition condition, _conditions) { for (Condition condition: _conditions) {
QString value(script->replacevars(condition.value)); QString value(script->replacevars(condition.value));
bool check(false); bool check(false);
if (condition.cmp=="default") { if (condition.cmp=="default") {
@ -2911,7 +2915,7 @@ class Case: public Command {
} else if (condition.cmp=="->") { } else if (condition.cmp=="->") {
QWebElement firstelement(find(frame, selector, QWebElement firstelement(find(frame, selector,
mrw::max(mrw::min(script->timeout()/3, 10), 2))); mrw::max(mrw::min(script->timeout()/3, 10), 2)));
Q_FOREACH(QWebElement element, frame->findAllElements(selector)) { for (QWebElement element: frame->findAllElements(selector)) {
if (value.isEmpty() || // just find element if (value.isEmpty() || // just find element
element.toOuterXml().indexOf(value)!=-1 || element.toOuterXml().indexOf(value)!=-1 ||
element.toPlainText().indexOf(value)!=-1) { element.toPlainText().indexOf(value)!=-1) {
@ -2948,7 +2952,7 @@ class Case: public Command {
return true; return true;
} }
private: private:
int countSteps(Script* parent) { int countSteps(Script*) {
int res1(0); int res1(0);
for (auto condition: _conditions) { for (auto condition: _conditions) {
int res2(condition.script->countSteps()+1); int res2(condition.script->countSteps()+1);
@ -3031,7 +3035,7 @@ class Auth: public Command {
} }
return cmd; return cmd;
} }
bool execute(Script* script, QWebFrame* frame) { bool execute(Script* script, QWebFrame*) {
Logger log(this, script); Logger log(this, script);
script->auth(_realm, _username, _password); script->auth(_realm, _username, _password);
return true; return true;
@ -3065,7 +3069,7 @@ class Ignore: public Command {
cmd->_signals = args.split(' ', QString::SkipEmptyParts); cmd->_signals = args.split(' ', QString::SkipEmptyParts);
return cmd; return cmd;
} }
bool execute(Script* script, QWebFrame* frame) { bool execute(Script* script, QWebFrame*) {
Logger log(this, script); Logger log(this, script);
script->ignore(_signals); script->ignore(_signals);
return true; return true;
@ -3097,7 +3101,7 @@ class UnIgnore: public Command {
cmd->_signals = args.split(' ', QString::SkipEmptyParts); cmd->_signals = args.split(' ', QString::SkipEmptyParts);
return cmd; return cmd;
} }
bool execute(Script* script, QWebFrame* frame) { bool execute(Script* script, QWebFrame*) {
Logger log(this, script); Logger log(this, script);
script->unignore(_signals); script->unignore(_signals);
return true; return true;
@ -3151,11 +3155,12 @@ inline Logger::Logger(Command* command, Script* script, bool showLines):
if (command) { if (command) {
_previous = _script->command(); _previous = _script->command();
_script->command(command); _script->command(command);
if (_command->log()) if (_command->log()) {
if (showLines) if (showLines)
_script->log("\\ "+_command->command(), _command); _script->log("\\ "+_command->command(), _command);
else else
_script->log("\\ "+_command->command().split('\n').first(), _command); _script->log("\\ "+_command->command().split('\n').first(), _command);
}
} }
} }
inline void Logger::operator()(QString txt) { inline void Logger::operator()(QString txt) {
@ -3182,7 +3187,7 @@ inline std::shared_ptr<Script> Command::subParser(Script* parent, const QStringL
const QString& file, const QString& file,
int line, int indent) { int line, int indent) {
std::shared_ptr<Script> res(new Script); std::shared_ptr<Script> res(new Script);
Q_FOREACH(QString key, parent->functions()) // copy functions from parent for (QString key: parent->functions()) // copy functions from parent
res->function(key, parent->function(key)); res->function(key, parent->function(key));
res->parse(in, file, line+1, indent+1); res->parse(in, file, line+1, indent+1);
return res; return res;
@ -3216,7 +3221,7 @@ inline bool Command::runScript(Logger& log, Command* parentCommand,
disconnect(&scriptCopy, SIGNAL(logging(QString)), disconnect(&scriptCopy, SIGNAL(logging(QString)),
parent, SLOT(parentlog(QString))); parent, SLOT(parentlog(QString)));
parentCommand->_result = scriptCopy.result(); parentCommand->_result = scriptCopy.result();
Q_FOREACH(QString key, scriptCopy.variables()) // copy new variables to parent for (QString key: scriptCopy.variables()) // copy new variables to parent
if (!vars.contains(key)) parent->set(key, scriptCopy.variable(key)); if (!vars.contains(key)) parent->set(key, scriptCopy.variable(key));
parent->ignore(scriptCopy); // copy ignore list parent->ignore(scriptCopy); // copy ignore list
if (parentCommand->_result.size()) if (parentCommand->_result.size())

@ -14,7 +14,7 @@
#include <iostream> #include <iostream>
class Highlighter: public QSyntaxHighlighter { class Highlighter: public QSyntaxHighlighter {
Q_OBJECT; Q_OBJECT
Q_SIGNALS: Q_SIGNALS:
void include(QString); void include(QString);
public: public:
@ -40,9 +40,9 @@ class Highlighter: public QSyntaxHighlighter {
include(m.captured(1)); include(m.captured(1));
} }
for (auto e: _expressions) { for (auto e: _expressions) {
auto m(e.re.match(text)); auto m2(e.re.match(text));
for (int i(0); i<=m.lastCapturedIndex(); ++i) { for (int i(0); i<=m2.lastCapturedIndex(); ++i) {
setFormat(m.capturedStart(i), m.capturedLength(i), e.fmt); setFormat(m2.capturedStart(i), m2.capturedLength(i), e.fmt);
} }
} }
} }

@ -224,10 +224,10 @@ class ScriptNotFinished: public ScriptFailed {
class ScriptExecutionFailed: public ScriptFailed { class ScriptExecutionFailed: public ScriptFailed {
public: public:
ScriptExecutionFailed(QString command, QStringList args, QString script, ScriptExecutionFailed(QString command, QStringList args, QString script,
int code, QString stdout, QString stderr): int code, QString sout, QString serr):
ScriptFailed("failed with exit code "+QString::number(code) ScriptFailed("failed with exit code "+QString::number(code)
+(stdout.size()?"; stdout=\""+stdout+"\"":"") +(sout.size()?"; sout=\""+sout+"\"":"")
+(stderr.size()?"; stderr=\""+stderr+"\"":""), +(serr.size()?"; serr=\""+serr+"\"":""),
command, args, script) { command, args, script) {
} }
}; };
@ -269,7 +269,7 @@ class CheckFailed: public TestFailed {
public: public:
CheckFailed(QString value1, char cmp, QString value2): CheckFailed(QString value1, char cmp, QString value2):
TestFailed(QString("check failed: %1 %2 %3") TestFailed(QString("check failed: %1 %2 %3")
.arg(value1).arg(cmp).arg(value1)) { .arg(value1).arg(cmp).arg(value2)) {
} }
}; };

@ -13,7 +13,7 @@
#include <QNetworkProxy> #include <QNetworkProxy>
class NetworkAccessManager: public QNetworkAccessManager { class NetworkAccessManager: public QNetworkAccessManager {
Q_OBJECT; Q_OBJECT
public: public:
NetworkAccessManager(QObject* parent = 0): QNetworkAccessManager(parent) { NetworkAccessManager(QObject* parent = 0): QNetworkAccessManager(parent) {
//log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
@ -224,7 +224,7 @@ class NetworkAccessManager: public QNetworkAccessManager {
//log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
} }
void sslErrorsLog(const QList<QSslError>& errors) { void sslErrorsLog(const QList<QSslError>& errors) {
Q_FOREACH(const QSslError& error, errors) { for (const QSslError& error: errors) {
log("**** SSL-Error: "+error.errorString()); log("**** SSL-Error: "+error.errorString());
} }
QNetworkReply* reply(dynamic_cast<QNetworkReply*>(QObject::sender())); QNetworkReply* reply(dynamic_cast<QNetworkReply*>(QObject::sender()));

@ -5,7 +5,7 @@
#include <cassert> #include <cassert>
class ScriptFile: public QDockWidget, protected Ui::ScriptFile { class ScriptFile: public QDockWidget, protected Ui::ScriptFile {
Q_OBJECT; Q_OBJECT
Q_SIGNALS: Q_SIGNALS:
void link(QString); void link(QString);
void include(QString); void include(QString);
@ -31,7 +31,7 @@ class ScriptFile: public QDockWidget, protected Ui::ScriptFile {
setWindowModified(false); setWindowModified(false);
} }
protected: protected:
void closeEvent (QCloseEvent *event) { void closeEvent (QCloseEvent*) {
close(this); close(this);
} }
private: private:

@ -28,7 +28,7 @@
#include <mrw/stdext.hxx> #include <mrw/stdext.hxx>
class TestGUI: public QMainWindow, protected Ui::TestGUI { class TestGUI: public QMainWindow, protected Ui::TestGUI {
Q_OBJECT; Q_OBJECT
public: public:
explicit TestGUI(QWidget *parent = 0, explicit TestGUI(QWidget *parent = 0,
QString url = QString(), QString url = QString(),
@ -59,15 +59,15 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
if (!url.isEmpty()) { if (!url.isEmpty()) {
storeUrl(url); storeUrl(url);
} }
TestWebPage* page(new TestWebPage(_web)); TestWebPage* pg(new TestWebPage(_web));
_web->setPage(page); _web->setPage(pg);
_web->installEventFilter(this); // track mouse and keyboard _web->installEventFilter(this); // track mouse and keyboard
page->setForwardUnsupportedContent(true); pg->setForwardUnsupportedContent(true);
_commands->setText(Script().commands(Script::HTML)); _commands->setText(Script().commands(Script::HTML));
assert(connect(page, SIGNAL(uploadFile(QString)), SLOT(uploadFile(QString)))); assert(connect(pg, SIGNAL(uploadFile(QString)), SLOT(uploadFile(QString))));
assert(connect(page, SIGNAL(unsupportedContent(QNetworkReply*)), assert(connect(pg, SIGNAL(unsupportedContent(QNetworkReply*)),
SLOT(unsupportedContent(QNetworkReply*)))); SLOT(unsupportedContent(QNetworkReply*))));
assert(connect(page, SIGNAL(downloadRequested(const QNetworkRequest&)), assert(connect(pg, SIGNAL(downloadRequested(const QNetworkRequest&)),
SLOT(downloadRequested(const QNetworkRequest&)))); SLOT(downloadRequested(const QNetworkRequest&))));
//assert(connect(_testscript, SIGNAL(include(QString)), SLOT(include(QString)))); //assert(connect(_testscript, SIGNAL(include(QString)), SLOT(include(QString))));
assert(connect(_testscript, SIGNAL(link(QString)), SLOT(include(QString)))); assert(connect(_testscript, SIGNAL(link(QString)), SLOT(include(QString))));
@ -270,12 +270,12 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
_setupscriptstatus->setText(trUtf8("?")); _setupscriptstatus->setText(trUtf8("?"));
std::shared_ptr<xml::Node> testsuites(new xml::Node("testsuite")); std::shared_ptr<xml::Node> testsuites(new xml::Node("testsuite"));
Script script; Script script;
TestWebPage page(0, true); TestWebPage pg(0, true);
script.parse(_setupscript->toPlainText().split('\n'), "setup"); script.parse(_setupscript->toPlainText().split('\n'), "setup");
script.run(page.mainFrame(), testsuites, QString(), false); script.run(pg.mainFrame(), testsuites, QString(), false);
_setupScript.cleanup(); _setupScript.cleanup();
_setupScript.parse(_setupscript->toPlainText().split('\n'), "setup"); _setupScript.parse(_setupscript->toPlainText().split('\n'), "setup");
_setupScript.run(page.mainFrame(), testsuites, QString(), false); _setupScript.run(pg.mainFrame(), testsuites, QString(), false);
_setupscriptstatus->setText(trUtf8("")); _setupscriptstatus->setText(trUtf8(""));
_setupscriptactive->setEnabled(true); _setupscriptactive->setEnabled(true);
} catch (std::exception &x) { } catch (std::exception &x) {
@ -425,16 +425,15 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
// click on a select results in a value change // click on a select results in a value change
// find all selected options ... // find all selected options ...
QStringList v; QStringList v;
Q_FOREACH(QWebElement option, for (QWebElement option: _lastFocused.findAll("option")) {
_lastFocused.findAll("option")) {
//! @bug QT does not support selected //! @bug QT does not support selected
if (option.evaluateJavaScript("this.selected").toBool()) if (option.evaluateJavaScript("this.selected").toBool())
v += value(option); v += value(option);
} }
setValue(selected, v); setValue(selected, v);
} else if (_lastFocused.tagName()=="TEXTAREA" || } else if (_lastFocused.tagName()=="TEXTAREA" ||
_lastFocused.tagName()=="INPUT" && (_lastFocused.tagName()=="INPUT" &&
_lastFocused.attribute("type")=="text") { _lastFocused.attribute("type")=="text")) {
// user clickt in a text edit field, so not the klick // user clickt in a text edit field, so not the klick
// is important, but the text that will be typed // is important, but the text that will be typed
_typing = true; _typing = true;
@ -543,8 +542,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
"selection.setBaseAndExtent(this, 0, this, 1);"); "selection.setBaseAndExtent(this, 0, this, 1);");
} }
QWebElement focused(QMouseEvent* event = 0) { QWebElement focused(QMouseEvent* event = 0) {
Q_FOREACH(QWebElement element, for (QWebElement element: _web->page()->currentFrame()->findAllElements("*")) {
_web->page()->currentFrame()->findAllElements("*")) {
if (element.hasFocus()) { if (element.hasFocus()) {
return element; return element;
} }
@ -579,11 +577,11 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
+"[name="+quote(element.attribute("name"))+"]"; +"[name="+quote(element.attribute("name"))+"]";
} else { } else {
QString res; QString res;
Q_FOREACH(QString attr, element.attributeNames()) { for (QString attr: element.attributeNames()) {
if (attr=="id") if (attr=="id")
res = "#"+element.attribute("id")+res; res = "#"+element.attribute("id")+res;
else if (attr=="class") else if (attr=="class")
Q_FOREACH(QString c, element.attribute(attr).split(' ')) { for (QString c: element.attribute(attr).split(' ')) {
if (!c.isEmpty()) res = '.'+c+res; if (!c.isEmpty()) res = '.'+c+res;
} }
else if (element.attribute(attr).isEmpty()) else if (element.attribute(attr).isEmpty())
@ -736,7 +734,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
QWebElementCollection forms(_web->page()->mainFrame()->documentElement() QWebElementCollection forms(_web->page()->mainFrame()->documentElement()
.findAll("form")); .findAll("form"));
_forms->clear(); _forms->clear();
Q_FOREACH(const QWebElement &form, forms) { for (const QWebElement &form: forms) {
addDomElement(form, _forms->invisibleRootItem()); addDomElement(form, _forms->invisibleRootItem());
} }

@ -26,7 +26,7 @@ inline std::ostream& operator<<(std::ostream& o, const QString& s) {
#endif #endif
class TestWebPage: public QWebPage { class TestWebPage: public QWebPage {
Q_OBJECT; Q_OBJECT
public: public:
TestWebPage(QObject* parent = 0, bool unattended = false): TestWebPage(QObject* parent = 0, bool unattended = false):
QWebPage(parent), QWebPage(parent),
@ -38,10 +38,16 @@ class TestWebPage: public QWebPage {
//settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true); //settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
settings()->setAttribute(QWebSettings::LocalStorageEnabled, true); settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
} }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wterminate"
virtual ~TestWebPage() { virtual ~TestWebPage() {
if (!_nextFile.isEmpty() && !std::uncaught_exception()) if (!_nextFile.isEmpty() && !std::uncaught_exception())
// will not call terminate(), because I check std::uncaught_exception()
throw LastFileNotUploaded(_nextFile); throw LastFileNotUploaded(_nextFile);
} }
#pragma GCC diagnostic pop
void setNextUploadFile(QString nextFile) { void setNextUploadFile(QString nextFile) {
if (!_unattended) throw NotUnattended(); if (!_unattended) throw NotUnattended();
if (!_nextFile.isEmpty()) throw LastFileNotUploaded(_nextFile); if (!_nextFile.isEmpty()) throw LastFileNotUploaded(_nextFile);
@ -73,8 +79,7 @@ class TestWebPage: public QWebPage {
if (_unattended) { if (_unattended) {
return; return;
} else { } else {
return; return QWebPage::javaScriptAlert(frame, msg);
//return QWebPage::javaScriptAlert(frame, msg);
} }
} }
virtual bool javaScriptConfirm(QWebFrame* frame, const QString& msg) { virtual bool javaScriptConfirm(QWebFrame* frame, const QString& msg) {
@ -82,8 +87,7 @@ class TestWebPage: public QWebPage {
if (_unattended) { if (_unattended) {
return true; return true;
} else { } else {
return true; return QWebPage::javaScriptConfirm(frame, msg);
//return QWebPage::javaScriptConfirm(frame, msg);
} }
} }
virtual void javaScriptConsoleMessage(const QString& msg, virtual void javaScriptConsoleMessage(const QString& msg,
@ -92,8 +96,7 @@ class TestWebPage: public QWebPage {
if (_unattended) { if (_unattended) {
return; return;
} else { } else {
return; return QWebPage::javaScriptConsoleMessage(msg, line, src);
//return QWebPage::javaScriptConsoleMessage(msg, line, src);
} }
} }
virtual bool javaScriptPrompt(QWebFrame* frame, const QString& msg, virtual bool javaScriptPrompt(QWebFrame* frame, const QString& msg,
@ -102,8 +105,7 @@ class TestWebPage: public QWebPage {
if (_unattended) { if (_unattended) {
return true; return true;
} else { } else {
return true; return QWebPage::javaScriptPrompt(frame, msg, defaultValue, result);
//return QWebPage::javaScriptPrompt(frame, msg, defaultValue, result);
} }
} }
private: private:

@ -56,7 +56,7 @@ QString format(QString txt, int indent = 2, int cpl = 80) {
QStringList res; QStringList res;
QStringList lines(txt.split('\n')); QStringList lines(txt.split('\n'));
QString ind(indent, ' '); QString ind(indent, ' ');
Q_FOREACH(QString line, lines) { for (QString line: lines) {
line.insert(0, ind); line.insert(0, ind);
for (int pos(indent); line.size()-pos>cpl; ++pos) { for (int pos(indent); line.size()-pos>cpl; ++pos) {
int pos2=line.lastIndexOf(' ', pos+cpl); int pos2=line.lastIndexOf(' ', pos+cpl);
@ -152,7 +152,7 @@ int main(int argc, char *argv[]) try {
QString target(parser.value("target-path")); QString target(parser.value("target-path"));
p.resize(width, height); p.resize(width, height);
std::shared_ptr<xml::Node> testsuites(new xml::Node("testsuites")); std::shared_ptr<xml::Node> testsuites(new xml::Node("testsuites"));
Q_FOREACH(QString file, parser.positionalArguments()) { for (QString file: parser.positionalArguments()) {
int expectedtestcases(-1); int expectedtestcases(-1);
xml::Node testsuite("testsuite"); xml::Node testsuite("testsuite");
testsuite.attr("name") = QFileInfo(file).baseName().toStdString(); testsuite.attr("name") = QFileInfo(file).baseName().toStdString();

Loading…
Cancel
Save