2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-11-30 11:27:06 +01:00
|
|
|
#include "googletest.h"
|
|
|
|
|
|
2020-05-27 23:48:03 +02:00
|
|
|
#include <sqlitedatabase.h>
|
2021-05-07 09:19:39 +02:00
|
|
|
#include <sqlitelibraryinitializer.h>
|
|
|
|
|
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <sqliteglobal.h>
|
2022-01-06 10:40:58 +01:00
|
|
|
#include <utils/launcherinterface.h>
|
2021-12-17 19:54:37 +01:00
|
|
|
#include <utils/singleton.h>
|
2022-01-06 10:40:58 +01:00
|
|
|
#include <utils/temporarydirectory.h>
|
2017-01-30 10:05:42 +01:00
|
|
|
|
2021-01-13 13:23:46 +01:00
|
|
|
#include <QGuiApplication>
|
2015-09-30 14:21:34 +02:00
|
|
|
#include <QLoggingCategory>
|
2022-01-06 10:40:58 +01:00
|
|
|
#include <QScopeGuard>
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-02-16 16:04:54 +01:00
|
|
|
#ifdef WITH_BENCHMARKS
|
2017-10-24 19:38:47 +02:00
|
|
|
#include <benchmark/benchmark.h>
|
2016-02-16 16:04:54 +01:00
|
|
|
#endif
|
|
|
|
|
|
2020-11-10 12:12:15 +01:00
|
|
|
class Environment : public testing::Environment
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
void SetUp() override
|
|
|
|
|
{
|
|
|
|
|
const QString temporayDirectoryPath = QDir::tempPath() + "/QtCreator-UnitTests-XXXXXX";
|
|
|
|
|
Utils::TemporaryDirectory::setMasterTemporaryDirectory(temporayDirectoryPath);
|
|
|
|
|
qputenv("TMPDIR", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
|
|
|
|
|
qputenv("TEMP", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TearDown() override {}
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2021-05-07 09:19:39 +02:00
|
|
|
Sqlite::LibraryInitializer::initialize();
|
2020-05-27 23:48:03 +02:00
|
|
|
Sqlite::Database::activateLogging();
|
2017-02-20 17:14:17 +01:00
|
|
|
|
2021-01-13 13:23:46 +01:00
|
|
|
QGuiApplication application(argc, argv);
|
2022-01-06 10:40:58 +01:00
|
|
|
Utils::LauncherInterface::setPathToLauncher(qApp->applicationDirPath() + '/'
|
|
|
|
|
+ QLatin1String(TEST_RELATIVE_LIBEXEC_PATH));
|
2016-02-16 16:04:54 +01:00
|
|
|
testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
#ifdef WITH_BENCHMARKS
|
|
|
|
|
benchmark::Initialize(&argc, argv);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-10 15:39:36 +01:00
|
|
|
auto environment = std::make_unique<Environment>();
|
|
|
|
|
testing::AddGlobalTestEnvironment(environment.release());
|
2020-11-10 12:12:15 +01:00
|
|
|
|
2016-02-16 16:04:54 +01:00
|
|
|
int testsHaveErrors = RUN_ALL_TESTS();
|
|
|
|
|
|
2021-09-17 16:32:50 +02:00
|
|
|
Utils::Singleton::deleteAll();
|
2016-02-16 16:04:54 +01:00
|
|
|
#ifdef WITH_BENCHMARKS
|
|
|
|
|
if (testsHaveErrors == 0 && application.arguments().contains(QStringLiteral("--with-benchmarks")))
|
|
|
|
|
benchmark::RunSpecifiedBenchmarks();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return testsHaveErrors;
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|