Use link-time dependency injection to mock external dependencies

parent c42cff3d
......@@ -50,11 +50,13 @@ add_definitions(#-DQT_NO_CAST_TO_ASCII
-DQT_USE_QSTRINGBUILDER
)
find_package(Qt5 5.2.0 REQUIRED CONFIG COMPONENTS Core Test Network Concurrent DBus Widgets)
find_package(LibArchive REQUIRED)
find_package(Sqlite REQUIRED)
find_package(PolkitQt5-1 REQUIRED)
if(BUILD_TESTS)
find_package(GMock REQUIRED)
endif(BUILD_TESTS)
# Define install directories
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/akabei" CACHE "Akabei data installation directory" STRING)
......
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# - Try to find Google Mock
# Once done this will define
# GMOCK_FOUND - System has Google Mock
# GMOCK_INCLUDE_DIRS - The Google Mock include directories
# GMOCK_LIBRARIES - The libraries needed to use Google Mock
# © 2016 Adrián Chaves (Gallaecio) <adriyetichaves@gmail.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
find_package(Threads)
find_path(GMOCK_INCLUDE_DIR gmock/gmock.h)
find_library(GMOCK_LIBRARY NAMES gmock libgmock)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR)
mark_as_advanced(GMOCK_INCLUDE_DIR GMOCK_LIBRARY)
set(GMOCK_LIBRARIES ${GMOCK_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR})
......@@ -90,8 +90,8 @@ bool PolKitArchiveHandler::write(const QString& filename, const QHash<QString, Q
const auto& k = it.key();
map.insert(k, files[k]);
}
QDBusMessage mes = iface.call(QStringLiteral("write"), map);
return !mes.arguments().isEmpty() && mes.arguments().first().toBool();
auto arguments = iface.call(QStringLiteral("write"), map).arguments();
return !arguments.isEmpty() && arguments.first().toBool();
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();//TODO:Error handling
Akabei::ErrorQueue::instance()->appendError(Akabei::Error(Akabei::Error::PermissionError, PolkitQt1::Authority::instance()->errorDetails()));
......@@ -108,10 +108,9 @@ QStringList PolKitArchiveHandler::getEntries() const
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call(QStringLiteral("entries"));
if (!mes.arguments().isEmpty())
return mes.arguments().first().toStringList();
auto arguments = d->iface->call(QStringLiteral("entries")).arguments();
if (!arguments.isEmpty())
return arguments.first().toStringList();
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();
Akabei::ErrorQueue::instance()->appendError(Akabei::Error(Akabei::Error::PermissionError, PolkitQt1::Authority::instance()->errorDetails()));
......@@ -127,10 +126,9 @@ size_t PolKitArchiveHandler::getEntrySize(QString const& fileName) const
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call(QStringLiteral("entrySize"), fileName);
if (!mes.arguments().isEmpty())
return mes.arguments().first().toInt();
auto arguments = d->iface->call(QStringLiteral("entrySize"), fileName).arguments();
if (!arguments.isEmpty())
return arguments.first().toInt();
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();
......@@ -147,10 +145,9 @@ size_t PolKitArchiveHandler::totalEntrySize() const
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call(QStringLiteral("totalEntrySize"));
if (!mes.arguments().isEmpty())
return mes.arguments().first().toInt();
auto arguments = d->iface->call(QStringLiteral("totalEntrySize")).arguments();
if (!arguments.isEmpty())
return arguments.first().toInt();
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();
......@@ -167,10 +164,9 @@ QString PolKitArchiveHandler::readTextFile(const QString &file)
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call(QStringLiteral("readTextFile"), file);
if (!mes.arguments().isEmpty())
return mes.arguments().first().toString();
auto arguments = d->iface->call(QStringLiteral("readTextFile"), file).arguments();
if (!arguments.isEmpty())
return arguments.first().toString();
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();
......@@ -235,10 +231,9 @@ QList<QByteArray> PolKitArchiveHandler::md5(const QStringList& files)
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call(QStringLiteral("md5"), files);
if (!mes.arguments().isEmpty())
return mes.arguments().first().value< QList<QByteArray> >();
auto arguments = d->iface->call(QStringLiteral("md5"), files).arguments();
if (!arguments.isEmpty())
return arguments.first().value< QList<QByteArray> >();
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();
Akabei::ErrorQueue::instance()->appendError(Akabei::Error(Akabei::Error::PermissionError, PolkitQt1::Authority::instance()->errorDetails()));
......@@ -255,10 +250,9 @@ QByteArray PolKitArchiveHandler::md5(const QString &file)
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call(QStringLiteral("md5"), file);
if (!mes.arguments().isEmpty())
return mes.arguments().first().toByteArray();
auto arguments = d->iface->call(QStringLiteral("md5"), file).arguments();
if (!arguments.isEmpty())
return arguments.first().toByteArray();
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();
Akabei::ErrorQueue::instance()->appendError(Akabei::Error(Akabei::Error::PermissionError, PolkitQt1::Authority::instance()->errorDetails()));
......
set(CMAKE_AUTOMOC ON)
set(COMMON_TEST_LIBRARIES akabeicore Qt5::Test)
add_subdirectory(mocks)
#General test
set(akabei_test_SRCS
......@@ -8,9 +11,7 @@ set(akabei_test_SRCS
add_executable(akabei_test ${akabei_test_SRCS} ${akabei_test_MOC_SRCS})
target_link_libraries(akabei_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_test ${COMMON_TEST_LIBRARIES})
add_test(akabei akabei_test)
......@@ -22,9 +23,7 @@ set(akabei_hook_test_SRCS
add_executable(akabei_hook_test ${akabei_hook_test_SRCS} ${akabei_hook_test_MOC_SRCS})
target_link_libraries(akabei_hook_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_hook_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_hook_test akabei_hook_test)
......@@ -36,9 +35,7 @@ set(akabei_group_test_SRCS
add_executable(akabei_group_test ${akabei_group_test_SRCS} ${akabei_group_test_MOC_SRCS})
target_link_libraries(akabei_group_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_group_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_group_test akabei_group_test)
......@@ -50,9 +47,7 @@ set(akabei_error_test_SRCS
add_executable(akabei_error_test ${akabei_error_test_SRCS} ${akabei_error_test_MOC_SRCS})
target_link_libraries(akabei_error_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_error_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_error_test akabei_error_test)
......@@ -64,9 +59,7 @@ set(akabei_md5sum_test_SRCS
add_executable(akabei_md5sum_test ${akabei_md5sum_test_SRCS} ${akabei_md5sum_test_MOC_SRCS})
target_link_libraries(akabei_md5sum_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_md5sum_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_md5sum_test akabei_md5sum_test)
......@@ -80,9 +73,7 @@ add_executable(akabei_sqlite_test ${akabei_sqlite_test_SRCS} ${akabei_sqlite_tes
target_include_directories(akabei_sqlite_test PRIVATE ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/build)
target_link_libraries(akabei_sqlite_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_sqlite_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_sqlite_test akabei_sqlite_test)
......@@ -94,9 +85,7 @@ set(akabei_archive_handler_test_SRCS
add_executable(akabei_archive_handler_test ${akabei_archive_handler_test_SRCS} ${akabei_archive_handler_test_MOC_SRCS})
target_link_libraries(akabei_archive_handler_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_archive_handler_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_archive_handler_test akabei_archive_handler_test)
......@@ -105,9 +94,7 @@ set(akabei_version_test_SRCS akabeiversiontest.cpp)
add_executable(akabei_version_test ${akabei_version_test_SRCS} ${akabei_version_test_MOC_SRCS})
target_link_libraries(akabei_version_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_version_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_version_test akabei_version_test)
......@@ -119,9 +106,8 @@ set(akabei_polkit_archive_handler_test_SRCS
add_executable(akabei_polkit_archive_handler_test ${akabei_polkit_archive_handler_test_SRCS} ${akabei_polkit_archive_handler_test_MOC_SRCS})
target_link_libraries(akabei_polkit_archive_handler_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_polkit_archive_handler_test
dbusmock filesystemmock polkitmock ${COMMON_TEST_LIBRARIES})
add_test(akabei_polkit_archive_handler_test akabei_polkit_archive_handler_test)
......@@ -135,9 +121,7 @@ add_executable(akabei_polkit_sqliteconnection_test ${akabei_polkit_sqliteconnect
target_include_directories(akabei_polkit_sqliteconnection_test PRIVATE ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/build)
target_link_libraries(akabei_polkit_sqliteconnection_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_polkit_sqliteconnection_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_polkit_sqliteconnection_test akabei_polkit_sqliteconnection_test)
......@@ -145,14 +129,6 @@ add_test(akabei_polkit_sqliteconnection_test akabei_polkit_sqliteconnection_test
set(akabei_permissions_test_SRCS
akabeipermissionstest.cpp
)
add_executable(akabei_permissions_test ${akabei_permissions_test_SRCS} ${akabei_permissions_test_MOC_SRCS})
target_link_libraries(akabei_permissions_test akabeicore
Qt5::Gui
Qt5::Test)
target_link_libraries(akabei_permissions_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_permissions_test akabei_permissions_test)
......@@ -17,13 +17,22 @@
#include <akabeihelpers.h>
#include <libarchive++/polkitarchivehandler.h>
AkabeiPolKitArchiveHandlerTest::AkabeiPolKitArchiveHandlerTest(QObject * parent) : QObject(parent)
#include "mocks/dbus.h"
#include "mocks/filesystem.h"
#include "mocks/polkit.h"
using namespace testing;
AkabeiPolKitArchiveHandlerTest::AkabeiPolKitArchiveHandlerTest(
QObject * parent) : QObject(parent)
{
}
void AkabeiPolKitArchiveHandlerTest::test()
{
// Variables
QMap<int, int> map;
map.insert(12312, 23414);
map.insert(12323, 45345);
......@@ -35,44 +44,96 @@ void AkabeiPolKitArchiveHandlerTest::test()
temp.close();
QByteArray originalMd5sum = Akabei::Helpers::md5sumOfFile(temp.fileName());
QFile file(temp.fileName());
file.open(QIODevice::ReadOnly);
QByteArray data = file.readAll();
file.close();
QFile tempFile(temp.fileName());
tempFile.open(QIODevice::ReadOnly);
QByteArray data = tempFile.readAll();
tempFile.close();
QCOMPARE(originalMd5sum, Akabei::Helpers::md5sum(data));
QString entryName("bla");
QHash<QString, QString> archHash;
archHash.insert("bla", temp.fileName());
QString archPath = "/tmp/tmp.tar.xz";
QVERIFY(ArchiveHandler::write(archPath, archHash));
PolKitArchiveHandler handler(archPath);
try {
qDebug() << handler.getEntries();
} catch (std::exception &e) {
qDebug() << e.what();
}
try {
QCOMPARE(originalMd5sum, Akabei::Helpers::md5sum(data));
QCOMPARE(originalMd5sum, handler.md5("bla"));
} catch (ArchiveException &e) {
qDebug() << e.what();
}
try {
QString extractName = "/tmp/blablub";
handler.extract("bla", extractName, true);
QCOMPARE(originalMd5sum, Akabei::Helpers::md5sumOfFile(extractName));
} catch (ArchiveException &e) {
qDebug() << e.what();
}
try {
handler.extractAll("/tmp", true);
QCOMPARE(originalMd5sum, Akabei::Helpers::md5sumOfFile("/tmp/bla"));
} catch (ArchiveException &e) {
qDebug() << e.what();
}
archHash.insert(entryName, temp.fileName());
QTemporaryFile archTemp(this);
QVERIFY(archTemp.open());
archTemp.close();
QVERIFY(ArchiveHandler::write(archTemp.fileName(), archHash));
QTemporaryFile extractTemp(this);
QVERIFY(extractTemp.open());
extractTemp.close();
bool overwrite(true);
QString pathPrefix("/tmp");
// Mocks
QFileInfoMock fileInfoMock;
fileInfoMock.setTrackedFiles({archTemp.fileName()});
EXPECT_CALL(fileInfoMock, isReadable(_))
.Times(AtLeast(1))
.WillRepeatedly(Return(false));
QFileInfoMock::setInstance(&fileInfoMock);
QString read("org.chakraproject.akabeicorehelper.archive.read");
QString extract("org.chakraproject.akabeicorehelper.archive.extract");
PolkitQt1AuthorityMock authorityMock;
PolkitQt1AuthorityMock::setInstance(&authorityMock);
EXPECT_CALL(authorityMock, checkAuthorizationSync(read, _, _))
.Times(2)
.WillRepeatedly(Return(PolkitQt1::Authority::Yes));
EXPECT_CALL(authorityMock, checkAuthorizationSync(extract, _, _))
.Times(2)
.WillRepeatedly(Return(PolkitQt1::Authority::Yes));
QDBusInterfaceMock dbusInterfaceMock;
QDBusInterfaceMock::setInstance(&dbusInterfaceMock);
EXPECT_CALL(dbusInterfaceMock, setProperty(
StrEq("filename"), QVariant::fromValue(archTemp.fileName())))
.Times(4);
EXPECT_CALL(dbusInterfaceMock, call(
QStringLiteral("entries"), QVariant(), QVariant(), QVariant(),
QVariant(), QVariant(), QVariant(), QVariant(), QVariant()))
.Times(1);
EXPECT_CALL(dbusInterfaceMock, call(
QStringLiteral("md5"), QVariant::fromValue(temp.fileName()),
QVariant(), QVariant(), QVariant(), QVariant(), QVariant(),
QVariant(), QVariant()))
.Times(1);
EXPECT_CALL(dbusInterfaceMock, call(
QStringLiteral("extract"), QVariant::fromValue(entryName),
QVariant::fromValue(extractTemp.fileName()),
QVariant::fromValue(overwrite), QVariant(), QVariant(), QVariant(),
QVariant(), QVariant()))
.Times(1);
EXPECT_CALL(dbusInterfaceMock, call(
QStringLiteral("extractAll"), QVariant::fromValue(pathPrefix),
QVariant::fromValue(overwrite), QVariant(), QVariant(), QVariant(),
QVariant(), QVariant(), QVariant()))
.Times(1);
QVariantList getEntriesArguments{
QVariant::fromValue(QStringList{QStringLiteral("bla")})};
auto md5Arguments = QVariantList{
QVariant::fromValue(originalMd5sum)};
QDBusMessageMock dbusMessageMock;
QDBusMessageMock::setInstance(&dbusMessageMock);
EXPECT_CALL(dbusMessageMock, arguments())
.WillOnce(Return(getEntriesArguments))
.WillOnce(Return(md5Arguments));
// Test
PolKitArchiveHandler handler(archTemp.fileName());
QCOMPARE(handler.getEntries(), QStringList{entryName});
QCOMPARE(originalMd5sum, handler.md5(temp.fileName()));
handler.extract(entryName, extractTemp.fileName(), overwrite);
handler.extractAll(pathPrefix, overwrite);
// Verify expectations
QVERIFY(Mock::VerifyAndClearExpectations(&authorityMock));
QVERIFY(Mock::VerifyAndClearExpectations(&dbusInterfaceMock));
QVERIFY(Mock::VerifyAndClearExpectations(&dbusMessageMock));
QVERIFY(Mock::VerifyAndClearExpectations(&fileInfoMock));
}
......
include_directories(${GMOCK_INCLUDE_DIRS})
add_library(dbusmock dbus.cpp)
target_link_libraries(dbusmock Qt5::DBus ${GMOCK_LIBRARIES})
add_library(filesystemmock filesystem.cpp)
target_link_libraries(filesystemmock Qt5::Core ${GMOCK_LIBRARIES})
add_library(polkitmock polkit.cpp)
target_link_libraries(
polkitmock Qt5::Core ${POLKITQT-1_LIBRARIES} ${GMOCK_LIBRARIES})
#include "dbus.h"
#include <QDBusAbstractInterface>
// QDBusMessageMock
QDBusMessageMock* QDBusMessageMock::m_instance = nullptr;
QDBusMessageMock* QDBusMessageMock::instance()
{
return m_instance;
}
void QDBusMessageMock::setInstance(QDBusMessageMock* instance)
{
m_instance = instance;
}
// QDBusInterfaceMock
QDBusInterfaceMock* QDBusInterfaceMock::m_instance = nullptr;
QDBusInterfaceMock* QDBusInterfaceMock::instance()
{
return m_instance;
}
void QDBusInterfaceMock::setInstance(QDBusInterfaceMock* instance)
{
m_instance = instance;
}
// QDBusMessage overrides
QList<QVariant> QDBusMessage::arguments() const
{
return QDBusMessageMock::instance()->arguments();
}
// QDBusAbstractInterface overrides
QDBusMessage QDBusAbstractInterface::call(const QString &method,
const QVariant &arg1,
const QVariant &arg2,
const QVariant &arg3,
const QVariant &arg4,
const QVariant &arg5,
const QVariant &arg6,
const QVariant &arg7,
const QVariant &arg8)
{
return QDBusInterfaceMock::instance()->call(
method, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
}
// QObject overrides
bool QObject::setProperty(const char *name, const QVariant &value)
{
return QDBusInterfaceMock::instance()->setProperty(name, value);
}
#ifndef DBUSMOCK_H
#define DBUSMOCK_H
#include <QDBusMessage>
#include <QVariant>
#include <gmock/gmock.h>
class QDBusMessageMock
{
public:
static QDBusMessageMock* instance();
static void setInstance(QDBusMessageMock* instance);
MOCK_CONST_METHOD0(arguments, QVariantList());
private:
static QDBusMessageMock* m_instance;
};
class QDBusInterfaceMock
{
public:
static QDBusInterfaceMock* instance();
static void setInstance(QDBusInterfaceMock* instance);
MOCK_METHOD9(call, QDBusMessage(const QString &method,
const QVariant &arg1,
const QVariant &arg2,
const QVariant &arg3,
const QVariant &arg4,
const QVariant &arg5,
const QVariant &arg6,
const QVariant &arg7,
const QVariant &arg8));
MOCK_METHOD2(setProperty, bool(const char *name, const QVariant &value));
private:
static QDBusInterfaceMock* m_instance;
};
#endif // DBUSMOCK_H
#include "filesystem.h"
#include <fstream>
#include <QDebug>
#include <QFileInfo>
// QFileInfoMock
QFileInfoMock* QFileInfoMock::m_instance = nullptr;
void QFileInfoMock::setTrackedFiles(QSet<QString> files)
{
trackedFiles = files;
}
bool QFileInfoMock::tracks(QString fileName)
{
return trackedFiles.contains(fileName);
}
QFileInfoMock* QFileInfoMock::instance()
{
return m_instance;
}
void QFileInfoMock::setInstance(QFileInfoMock* instance)
{
m_instance = instance;
}
// QFileInfo overrides
bool QFileInfo::isReadable() const
{
if (QFileInfoMock::instance() != nullptr &&
QFileInfoMock::instance()->tracks(filePath()))
return QFileInfoMock::instance()->isReadable(filePath());
std::ifstream file(filePath().toStdString());
return file.good();
}
#ifndef FILESYSTEMMOCK_H
#define FILESYSTEMMOCK_H
#include <QSet>
#include <QString>
#include <gmock/gmock.h>
class QFileInfoMock
{
public:
static QFileInfoMock* instance();
static void setInstance(QFileInfoMock* instance);
void setTrackedFiles(QSet<QString> trackedFiles);
bool tracks(QString fileName);
MOCK_CONST_METHOD1(isReadable, bool(QString path));
private:
QSet<QString> trackedFiles;
static QFileInfoMock* m_instance;
};
#endif // FILESYSTEMMOCK_H
#include "polkit.h"
// PolkitQt1AuthorityMock
PolkitQt1AuthorityMock* PolkitQt1AuthorityMock::m_instance = nullptr;
PolkitQt1AuthorityMock* PolkitQt1AuthorityMock::instance()
{
return m_instance;
}
void PolkitQt1AuthorityMock::setInstance(PolkitQt1AuthorityMock* instance)
{
m_instance = instance;
}
// Authority overrides
using namespace PolkitQt1;
Authority::Result Authority::checkAuthorizationSync(
const QString &actionId,
const Subject &subject,
Authority::AuthorizationFlags flags) {
return PolkitQt1AuthorityMock::instance()->checkAuthorizationSync(
actionId, subject, flags);
}
#ifndef POLKITMOCK_H
#define POLKITMOCK_H
#include <QString>
#include <PolkitQt1/Authority>
#include <gmock/gmock.h>
class PolkitQt1AuthorityMock
{
public:
static PolkitQt1AuthorityMock* instance();
static void setInstance(PolkitQt1AuthorityMock* instance);
MOCK_METHOD3(checkAuthorizationSync,
PolkitQt1::Authority::Result(
const QString &actionId,
const PolkitQt1::Subject &subject,
PolkitQt1::Authority::AuthorizationFlags flags));
private:
static PolkitQt1AuthorityMock* m_instance;
};
#endif // POLKITMOCK_H
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