Verified Commit 0731d48d authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Adapt autotests, CMake

parent e656592a
......@@ -4,7 +4,7 @@ find_package(Qt5Test CONFIG REQUIRED)
set(kgapitest_SRCS
fakeaccountstorage.cpp
fakeauthwidget.cpp
fakeauthbrowser.cpp
fakenetworkreply.cpp
fakenetworkaccessmanager.cpp
fakenetworkaccessmanagerfactory.cpp
......@@ -24,17 +24,18 @@ set_source_files_properties(
endif()
add_library(kgapitest STATIC ${kgapitest_SRCS})
target_link_libraries(kgapitest Qt5::Core Qt5::Network Qt5::Test KPimGAPICore)
target_link_libraries(kgapitest Qt5::Core Qt5::Network Qt5::Gui Qt5::Test KPimGAPICore)
macro(add_libkgapi2_test _module _testname)
set(_extraLibs ${ARGN})
set(testSources ${_module}/${_testname}.cpp)
string(SUBSTRING ${_module} 0 1 moduleFirst)
string(SUBSTRING ${_module} 1 -1 moduleLast)
string(TOUPPER ${moduleFirst} moduleFirst)
string(CONCAT moduleName ${moduleFirst} ${moduleLast})
set(extraLibs "KPimGAPI${moduleName}")
set(extraLibs "${_extraLibs};KPimGAPI${moduleName}")
set(utilsFile ${CMAKE_CURRENT_SOURCE_DIR}/${_module}/${_module}testutils.cpp)
if (EXISTS ${utilsFile})
list(APPEND testSources ${utilsFile})
......@@ -85,8 +86,8 @@ add_libkgapi2_test(tasks tasklistmodifyjobtest)
add_libkgapi2_test(drive aboutfetchjobtest)
add_libkgapi2_test(drive changefetchjobtest)
add_libkgapi2_test(drive filecopyjobtest)
add_libkgapi2_test(drive filecreatejobtest)
add_libkgapi2_test(drive filecopyjobtest Qt5::Gui)
add_libkgapi2_test(drive filecreatejobtest Qt5::Gui)
add_libkgapi2_test(drive filesearchquerytest)
add_libkgapi2_test(drive drivescreatejobtest)
add_libkgapi2_test(drive drivesdeletejobtest)
......
......@@ -11,7 +11,7 @@
#include <QList>
#include "fakeaccountstorage.h"
#include "fakeauthwidget.h"
#include "fakeauthbrowser.h"
#include "fakenetworkaccessmanagerfactory.h"
#include "fakenetworkaccessmanager.h"
#include "fakenetworkreply.h"
......@@ -68,7 +68,7 @@ private Q_SLOTS:
void testGetNewAccount()
{
FakeAuthWidgetFactory authFactory;
FakeAuthBrowser authBrowser;
FakeNetworkAccessManagerFactory::get()->setScenarios(
{ scenarioFromFile(QFINDTESTDATA("data/accountmanager_part1_request.txt"),
QFINDTESTDATA("data/accountmanager_part1_response.txt"),
......@@ -116,7 +116,7 @@ private Q_SLOTS:
void testMergeAccountScopes()
{
FakeAuthWidgetFactory authFactory;
FakeAuthBrowser authBrowser;
FakeNetworkAccessManagerFactory::get()->setScenarios(
{ scenarioFromFile(QFINDTESTDATA("data/accountmanager_part1_request.txt"),
QFINDTESTDATA("data/accountmanager_part1_response.txt"),
......@@ -211,7 +211,7 @@ private Q_SLOTS:
void testRefreshTokens()
{
FakeAuthWidgetFactory authFactory;
FakeAuthBrowser authBrowser;
FakeNetworkAccessManagerFactory::get()->setScenarios(
{ scenarioFromFile(QFINDTESTDATA("data/accountmanager_refresh_request.txt"),
QFINDTESTDATA("data/accountmanager_refresh_response.txt"),
......
......@@ -93,7 +93,7 @@ private Q_SLOTS:
}
};
QTEST_GUILESS_MAIN(FileCopyJobTest)
QTEST_MAIN(FileCopyJobTest)
#include "filecopyjobtest.moc"
......
......@@ -97,7 +97,7 @@ private Q_SLOTS:
}
};
QTEST_GUILESS_MAIN(FileCreateJobTest)
QTEST_MAIN(FileCreateJobTest)
#include "filecreatejobtest.moc"
......
......@@ -4,43 +4,27 @@
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "fakeauthwidget.h"
#include "ui/authwidget_p.h"
#include "fakeauthbrowser.h"
#include <QObject>
#include <QDesktopServices>
#include <QTimer>
#include <QTcpSocket>
#include <QHostAddress>
FakeAuthWidgetFactory::FakeAuthWidgetFactory()
{
sFactory = this;
}
FakeAuthWidgetFactory::~FakeAuthWidgetFactory()
{
sFactory = nullptr;
}
KGAPI2::AuthWidget * FakeAuthWidgetFactory::create(QWidget* parent)
{
return new FakeAuthWidget(parent);
}
extern uint16_t kgapiTcpAuthServerPort; // defined in authjob.cpp
class FakeAuthWidgetPrivate : public KGAPI2::AuthWidgetPrivate
class FakeAuthBrowser::Private : public QObject
{
Q_OBJECT
public:
FakeAuthWidgetPrivate(FakeAuthWidget *parent)
: KGAPI2::AuthWidgetPrivate(parent)
explicit Private()
{
serverPort = 42413; // random port, but must be stable
kgapiTcpAuthServerPort = 42413;
}
~FakeAuthWidgetPrivate() override
{}
void setUrl(const QUrl &url) override
public Q_SLOTS:
void openUrl(const QUrl &url)
{
Q_UNUSED(url);
......@@ -50,32 +34,27 @@ public:
QTimer::singleShot(0, this, [=]() {
QTcpSocket socket;
socket.connectToHost(QHostAddress::LocalHost, serverPort);
socket.connectToHost(QHostAddress::LocalHost, kgapiTcpAuthServerPort);
if (!socket.waitForConnected()) {
qWarning() << "Failed to connect to internal TCP server!";
return;
}
socket.write("GET http://127.0.0.1:42431?code=TheCakeIsALie HTTP/1.1");
socket.write("GET http://127.0.0.1:42413?code=TheCakeIsALie HTTP/1.1");
socket.waitForBytesWritten();
socket.close();
});
}
void setupUi() override
{
// do nothing
}
void setVisible(bool) override
{
// do nothing
}
};
FakeAuthBrowser::FakeAuthBrowser()
: d(new FakeAuthBrowser::Private)
{
QDesktopServices::setUrlHandler(QStringLiteral("https"), d.get(), "openUrl");
}
FakeAuthWidget::FakeAuthWidget(QWidget *parent)
: KGAPI2::AuthWidget(new FakeAuthWidgetPrivate(this), parent)
FakeAuthBrowser::~FakeAuthBrowser()
{
QDesktopServices::unsetUrlHandler(QStringLiteral("https"));
}
#include "fakeauthwidget.moc"
#include "fakeauthbrowser.moc"
......@@ -4,26 +4,21 @@
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef KGAPI_FAKEAUTHWIDGET_H_
#define KGAPI_FAKEAUTHWIDGET_H_
#ifndef KGAPI_FAKEAUTHBROWSER_H_
#define KGAPI_FAKEAUTHBROWSER_H_
#include "ui/authwidgetfactory_p.h"
#include "ui/authwidget.h"
#include <QScopedPointer>
class FakeAuthWidgetFactory : public KGAPI2::AuthWidgetFactory
class FakeAuthBrowser
{
public:
FakeAuthWidgetFactory();
~FakeAuthWidgetFactory() override;
explicit FakeAuthBrowser();
~FakeAuthBrowser();
KGAPI2::AuthWidget *create(QWidget *parent) override;
};
class FakeAuthWidget : public KGAPI2::AuthWidget
{
Q_OBJECT
public:
explicit FakeAuthWidget(QWidget *parent);
private:
class Private;
QScopedPointer<Private> const d;
friend class Private;
};
#endif
......
......@@ -52,6 +52,7 @@ target_link_libraries(KPimGAPICalendar
PUBLIC
KPim::GAPICore
KF5::CalendarCore
Qt5::Gui
PRIVATE
Qt5::Network
)
......
......@@ -47,6 +47,7 @@ target_link_libraries(KPimGAPIContacts
PUBLIC
KPim::GAPICore
KF5::Contacts
Qt5::Gui
PRIVATE
Qt5::Xml
Qt5::Network
......
......@@ -84,7 +84,6 @@ public:
account->setScopes(currentScopes);
}
AuthJob *job = new AuthJob(account, apiKey, apiSecret);
job->setUsername(account->accountName());
connect(job, &AuthJob::finished,
[=]() {
if (job->error() != KGAPI2::NoError) {
......
......@@ -17,6 +17,7 @@
using namespace KGAPI2;
// Used by fakeauthbrowser in tests
KGAPICORE_EXPORT uint16_t kgapiTcpAuthServerPort = 0;
class Q_DECL_HIDDEN AuthJob::Private
......
......@@ -134,6 +134,7 @@ target_include_directories(KPimGAPIDrive INTERFACE "$<INSTALL_INTERFACE:${KDE_IN
target_link_libraries(KPimGAPIDrive
PUBLIC
KPim::GAPICore
Qt5::Gui
PRIVATE
Qt5::Network
)
......
......@@ -32,6 +32,7 @@ target_link_libraries(KPimGAPIMaps
PUBLIC
KPim::GAPICore
KF5::Contacts
Qt5::Gui
PRIVATE
Qt5::Network
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment