Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit test crash and adjust 'make check' tests #9

Merged
merged 2 commits into from Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions tests/auto/qsparql.pro
Expand Up @@ -24,10 +24,25 @@ SUBDIRS = \

contains(sparql-plugins, tracker_direct): SUBDIRS += qsparql_benchmark

QSPARQL_TESTS = qsparql qsparqlquery qsparqlbinding qsparql_api qsparql_tracker \
qsparql_tracker_direct qsparql_tracker_direct_sync qsparql_ntriples \
qsparql_tracker_direct_crashes \
qsparqlresultrow qsparql_qmlbindings qsparql_endpoint
QSPARQL_TESTS = \
qsparql \
qsparqlquery \
qsparqlbinding \
qsparql_tracker \
qsparql_ntriples \
qsparqlresultrow \
qsparql_endpoint

# this skipped, needs a setup where connection fails
# qsparql_tracker_direct_crashes \

# can be enabled when qml api is back, but needs also fixing
# qsparql_qmlbindings \

# skipped due to tracker migration as above
# qsparql_api \
# qsparql_tracker_direct \
# qsparql_tracker_direct_sync \

check.CONFIG = recursive
check.recurse = $$QSPARQL_TESTS
Expand Down
19 changes: 11 additions & 8 deletions tests/auto/qsparql_endpoint/EndpointServer.cpp
Expand Up @@ -42,12 +42,13 @@
#include <QTcpSocket>
#include <QStringList>

EndpointServer::EndpointServer(int _port) : port(_port), disabled(true)
EndpointServer::EndpointServer(int _port)
: port(_port), disabled(true)
{
if (!listen(QHostAddress::Any, port)) {
qWarning() << "Can't bind server to port "<< port;
qWarning() << "Can't bind server to port " << port;
} else {
disabled=false;
disabled = false;
//qDebug() << "Starting fake endpoint server";
}
}
Expand All @@ -59,7 +60,7 @@ EndpointServer::~EndpointServer()

void EndpointServer::stop()
{
disabled=true;
disabled = true;
//qDebug() << "Shutting down fake endpoint www server";
close();
}
Expand Down Expand Up @@ -148,17 +149,19 @@ void EndpointServer::readClient()
// server looks if it was a get request and sends a very simple HTML
// document back.
QTcpSocket* socket = (QTcpSocket*)sender();

if (socket->canReadLine()) {
QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
if (tokens[0] == "GET") {

if (tokens.length() >= 2 && tokens[0] == "GET") {
QString url = tokens[1];
QTextStream os(socket);
os.setAutoDetectUnicode(true);
os << sparqlData(url);
socket->close();

if (socket->state() == QTcpSocket::UnconnectedState) {
delete socket;
socket->deleteLater();
}
}
}
Expand All @@ -177,13 +180,13 @@ bool EndpointServer::isRunning() const

void EndpointServer::pause()
{
disabled=true;
disabled = true;
}

bool EndpointServer::resume()
{
if (isListening()) {
disabled=false;
disabled = false;
return true;
} else {
//qDebug() << "Can't resume server as there was problem with binding on port " << port;
Expand Down
5 changes: 5 additions & 0 deletions tests/auto/qsparql_endpoint/EndpointServer.h
Expand Up @@ -51,17 +51,22 @@ class EndpointServer : public QTcpServer
public:
EndpointServer(int port);
~EndpointServer();

bool isRunning() const;
void pause();
bool resume();
void stop();

protected:
void incomingConnection(qintptr socket) override;

private:
QString sparqlData(QString url);

private Q_SLOTS:
void readClient();
void discardClient();

private:
int port;
bool disabled;
Expand Down
4 changes: 3 additions & 1 deletion tests/auto/qsparql_endpoint/EndpointService.cpp
Expand Up @@ -40,7 +40,9 @@
#include "EndpointService.h"
#include <QDebug>

EndpointService::EndpointService(int _port) : port(_port), server(0)
EndpointService::EndpointService(int _port)
: port(_port)
, server(nullptr)
{
}

Expand Down
2 changes: 2 additions & 0 deletions tests/auto/qsparql_endpoint/EndpointService.h
Expand Up @@ -51,11 +51,13 @@ class EndpointService : public QThread
public:
EndpointService(int port);
~EndpointService();

void run();
void stopService(int timeout);
void pause();
bool resume();
bool isRunning();

private:
int port;
EndpointServer *server;
Expand Down
2 changes: 2 additions & 0 deletions tests/auto/qsparql_endpoint/qsparql_endpoint.pro
@@ -1,8 +1,10 @@
include(../sparqltest.pri)
CONFIG += qt warn_on console depend_includepath
QT += testlib xml network

HEADERS += EndpointService.h \
EndpointServer.h

SOURCES += tst_qsparql_endpoint.cpp \
EndpointService.cpp \
EndpointServer.cpp
Expand Down
1 change: 0 additions & 1 deletion tests/auto/qsparql_endpoint/tst_qsparql_endpoint.cpp
Expand Up @@ -149,7 +149,6 @@ void tst_QSparqlEndpoint::ask_query()
delete r;
}


void tst_QSparqlEndpoint::query_with_error()
{
QSparqlConnectionOptions options;
Expand Down