test: bring some tests back

Signed-off-by: black-desk <me@black-desk.cn>
This commit is contained in:
black-desk 2024-11-18 14:36:44 +08:00 committed by black_desk
parent 98c38f6f8d
commit e7b72a8d93
19 changed files with 41 additions and 812 deletions

View File

@ -27,6 +27,10 @@ set(ENABLE_LINGLONG_INSTALLER
OFF
CACHE BOOL "enable linglong installer")
set(ENABLE_TESTTING
ON
CACHE BOOL "enable testting")
set(LINGLONG_USERNAME
"deepin-linglong"
CACHE STRING "The username for linglong package manager")
@ -99,6 +103,19 @@ if(ENABLE_CPM)
GIT_TAG v2.4.1
EXCLUDE_FROM_ALL ON
OPTIONS "CLI11_BUILD_TESTS OFF")
if(ENABLE_TESTTING)
include(CTest)
CPMFindPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG v1.14.0
VERSION 1.12.1
OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt"
FIND_PACKAGE_ARGUMENTS "NAMES GTest"
GIT_SHALLOW ON
EXCLUDE_FROM_ALL ON)
endif()
endif()
set(linglong_EXTERNALS "ytj ytj::ytj")
@ -126,6 +143,10 @@ if(NOT CLI11_FOUND)
list(APPEND linglong_EXTERNALS "CLI11 CLI11::CLI11")
endif()
if(ENABLE_TESTTING)
find_package(GTest REQUIRED)
endif()
function(get_real_target_name output target)
get_target_property("${output}" "${target}" ALIASED_TARGET)
if("${output}" STREQUAL "")

View File

@ -24,7 +24,8 @@
"cacheVariables": {
"CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Wno-c++20-extensions -Wno-pessimizing-move -Og -g -fsanitize=undefined",
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_COLOR_DIAGNOSTICS": true
"CMAKE_COLOR_DIAGNOSTICS": true,
"ENABLE_TESTING": true
}
},
{

View File

@ -73,9 +73,8 @@ pfl_add_library(
src/linglong/runtime/container_builder.h
src/linglong/runtime/container.cpp
src/linglong/runtime/container.h
# FIXME(black_desk): After refactory, all tests are failed to compile as I
# have no time to fix them now. Let's bring them back later. TESTS ll-tests
# http-client-tests
TESTS
ll-tests
COMPILE_FEATURES
PUBLIC
cxx_std_17

View File

@ -1,24 +0,0 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Test
REQUIRED)
pfl_add_executable(
OUTPUT_NAME
http_client_tests
DISABLE_INSTALL
SOURCES
src/ostree_repo_test.cpp
src/repo_client_test.cpp
src/mock-network.h
src/mock-network.cpp
LINK_LIBRARIES
PRIVATE
Qt${QT_VERSION_MAJOR}::Test
linglong::linglong)
add_test(NAME http_client_tests COMMAND http_client_tests)

View File

@ -1,54 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "mock-network.h"
MockReply::MockReply() { }
void MockReply::JSON(int code, QJsonDocument doc)
{
setRawHeader("Content-Type", QByteArray("application/json; charset=utf-8"));
this->Bytes(code, doc.toJson());
}
void MockReply::JSON(int code, QJsonObject obj)
{
this->JSON(code, QJsonDocument(obj));
}
void MockReply::JSON(int code, QJsonArray arr)
{
this->JSON(code, QJsonDocument(arr));
}
void MockReply::Bytes(int code, QByteArray data)
{
if (code >= 400) {
setError(NetworkError(code), "http code error");
}
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, code);
body = new QBuffer(this);
body->setData(data);
body->open(ReadOnly);
setOpenMode(ReadOnly);
QTimer::singleShot(0, this, &QNetworkReply::finished);
}
void MockReply::abort() { }
qint64 MockReply::readData(char *data, qint64 maxSize)
{
return body->read(data, maxSize);
}
QNetworkReply *MockQNetworkAccessManager::createRequest(Operation op,
const QNetworkRequest &req,
QIODevice *outgoingData)
{
auto rep = new MockReply();
Q_EMIT onCreateRequest(rep, op, req, outgoingData);
return rep;
}

View File

@ -1,51 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#pragma once
#include <QBuffer>
#include <QEventLoop>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QObject>
#include <QTimer>
class MockReply : public QNetworkReply
{
Q_OBJECT
QBuffer *body;
public:
MockReply();
void JSON(int code, QJsonArray doc);
void JSON(int code, QJsonObject doc);
void JSON(int code, QJsonDocument doc);
void Bytes(int code, QByteArray data);
void abort();
protected:
qint64 readData(char *data, qint64 maxSize);
};
class MockQNetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT
Q_SIGNALS:
void onCreateRequest(MockReply *reply,
Operation operation,
const QNetworkRequest &req,
QIODevice *outgoingData);
protected:
QNetworkReply *createRequest(Operation op,
const QNetworkRequest &req,
QIODevice *outgoingData = Q_NULLPTR);
};

View File

@ -1,125 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "../util/mock-network.h"
#include "linglong/repo/ostree_repo.h"
#include <qdir.h>
#include <qjsondocument.h>
#include <QTest>
using namespace linglong;
using namespace linglong::repo;
using namespace linglong::api::client;
class TestOSTreeRepo : public QObject
{
Q_OBJECT
private Q_SLOTS:
void push();
};
void TestOSTreeRepo::push()
{
MockQNetworkAccessManager http;
int requestStatusNumber = 0;
connect(&http,
&MockQNetworkAccessManager::onCreateRequest,
[&requestStatusNumber](MockReply *rep, auto op, QNetworkRequest req) {
auto url = req.url().toString();
qDebug() << "onCreateRequest"
<< "op" << op << "url" << url;
// 查询仓库信息
if (url.endsWith("/api/v1/repos/repo")) {
GetRepo_200_response resp;
resp.setCode(200);
rep->JSON(200, resp.asJsonObject());
return;
}
// 用户登陆
if (url.endsWith("/api/v1/sign-in")) {
SignIn_200_response resp;
Response_SignIn data;
data.setToken("token");
resp.setData(data);
resp.setCode(200);
rep->JSON(200, resp.asJsonObject());
return;
}
if (!req.hasRawHeader(QByteArray("X-Token"))) {
rep->JSON(401, QJsonDocument());
}
auto taskID = QString("test_task_id");
// 创建上传任务
if (url.endsWith("/api/v1/upload-tasks")) {
NewUploadTaskID_200_response resp;
Response_NewUploadTaskResp data;
data.setId(taskID);
resp.setData(data);
resp.setCode(200);
rep->JSON(200, resp.asJsonObject());
return;
}
// 上传tar包
if (url.endsWith(QString("/api/v1/upload-tasks/%1/tar").arg(taskID))) {
Api_UploadTaskFileResp resp;
Response_UploadTaskResp data;
data.setWatchId(0);
resp.setData(data);
resp.setCode(200);
rep->JSON(200, resp.asJsonObject());
return;
}
// 查询任务状态
if (url.endsWith(QString("/api/v1/upload-tasks/%1/status").arg(taskID))) {
UploadTaskInfo_200_response resp;
Response_UploadTaskStatusInfo data;
if (requestStatusNumber < 3) {
data.setStatus("pending");
} else {
data.setStatus("complete");
}
requestStatusNumber++;
resp.setData(data);
resp.setCode(200);
rep->JSON(200, resp.asJsonObject());
return;
}
rep->JSON(500, QJsonDocument());
});
auto endpoint = QString("https://testmock.deepin.org");
ClientApi api;
api.setNewServerForAllOperations(endpoint);
api.setNetworkAccessManager(&http);
auto config = config::ConfigV1{ "repo", { { "repo", endpoint.toStdString() } }, 1 };
// TODO(wurongjie) 不加 new 程序会挂掉
auto repo = new OSTreeRepo("./testdata/ostree_repo_test", config, api);
auto ref = package::Ref("test");
// 创建一个临时目录
QDir d("./testdata/package");
d.mkpath("./");
QFile f(d.filePath("info"));
QVERIFY2(f.open(QIODevice::WriteOnly | QIODevice::Text), "failed to open file");
QVERIFY2(f.write("this is test file"), "failded to write file");
f.close();
// 将目录做为包导入到ostree
auto importResult = repo->importDirectory(ref, d.path());
if (!importResult.has_value()) {
QVERIFY2(false, qPrintable("push error: " + importResult.error().message()));
}
auto pushResult = repo->push(ref);
if (!pushResult.has_value()) {
QVERIFY2(false, qPrintable("push error: " + pushResult.error().message()));
}
}
QTEST_GUILESS_MAIN(TestOSTreeRepo)
#include "ostree_repo_test.moc"

View File

@ -1,79 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "../util/mock-network.h"
#include "linglong/repo/repo_client.h"
#include <QTest>
using namespace linglong;
using namespace linglong::api::client;
class TestRepoClient : public QObject
{
Q_OBJECT
private Q_SLOTS:
void NetworkReply();
void QueryApps();
};
void TestRepoClient::NetworkReply()
{
MockQNetworkAccessManager http;
connect(&http, &MockQNetworkAccessManager::onCreateRequest, [](MockReply *req) {
req->Bytes(400, "");
});
ClientApi api;
api.setNewServerForAllOperations(QUrl("https://testmock.deepin.org"));
api.setNetworkAccessManager(&http);
auto client = repo::RepoClient(api);
auto apps = client.QueryApps(package::Ref(""));
QVERIFY(!apps.has_value());
QVERIFY(apps.error().code() == 400);
}
void TestRepoClient::QueryApps()
{
MockQNetworkAccessManager http;
connect(&http, &MockQNetworkAccessManager::onCreateRequest, [](MockReply *req) {
// 构造响应内容
Request_RegisterStruct reg;
reg.setAppId("org.deepin.music");
FuzzySearchApp_200_response data;
data.setCode(200);
data.setData({ reg });
req->JSON(200, data.asJsonObject());
});
ClientApi api;
api.setNewServerForAllOperations(QUrl("https://testmock.deepin.org"));
api.setNetworkAccessManager(&http);
// 构造请求内容
auto appID = "org.deepin.music";
auto client = repo::RepoClient(api);
auto ref = package::Ref("", appID, "", "x86_64");
{
auto apps = client.QueryApps(ref);
if (!apps.has_value()) {
qCritical() << apps.error().message();
}
QVERIFY(apps.has_value());
auto exists = false;
for (const auto &app : *apps) {
if (app->appId == appID) {
exists = true;
}
}
QVERIFY(exists);
}
}
QTEST_GUILESS_MAIN(TestRepoClient)
#include "repo_client_test.moc"

View File

@ -2,15 +2,9 @@
#
# SPDX-License-Identifier: LGPL-3.0-or-later
CPMFindPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG v1.14.0
VERSION 1.12.1
OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt"
FIND_PACKAGE_ARGUMENTS "NAMES GTest"
GIT_SHALLOW ON
EXCLUDE_FROM_ALL ON)
if(NOT ENABLE_TESTING)
return()
endif()
pfl_add_executable(
OUTPUT_NAME
@ -18,17 +12,9 @@ pfl_add_executable(
DISABLE_INSTALL
SOURCES
# find -regex '\./src/.+\.[ch]\(pp\)?' -type f -printf '%P\n'| sort
src/linglong/api/dbus/v1/mock_app_manager.h
src/linglong/api/dbus/v1/mock_package_manager.h
src/linglong/cli/cli_test.cpp
src/linglong/cli/dbus_reply.h
src/linglong/cli/mock_app_manager.h
src/linglong/cli/mock_printer.h
src/linglong/package_manager/mock_package_manager.h
src/linglong/package/reference_test.cpp
src/linglong/package/version_range_test.cpp
src/linglong/package/version_test.cpp
src/linglong/repo/ostree_repo_test.cpp
src/linglong/utils/error/result_test.cpp
src/linglong/utils/transaction_test.cpp
src/linglong/utils/xdg/desktop_entry_test.cpp
@ -40,8 +26,8 @@ pfl_add_executable(
PRIVATE
GTest::gmock
linglong::linglong
Qt::DBusPrivate)
Qt${QT_VERSION_MAJOR}::DBusPrivate)
include(GoogleTest)
get_real_target_name(tests linglong::linglong::ll_tests)
get_real_target_name(tests linglong::linglong::ll-tests)
gtest_discover_tests(${tests} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})

View File

@ -1,42 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#pragma once
#include <gmock/gmock.h>
#include "linglong/api/dbus/v1/package_manager.h"
namespace linglong::api::dbus::v1::test {
class MockPackageManager : public PackageManager
{
using PackageManager::PackageManager;
public:
MOCK_METHOD(QDBusPendingReply<linglong::service::Reply>,
Install,
(linglong::service::InstallParamOption installParamOption),
(override));
MOCK_METHOD(QDBusPendingReply<linglong::service::Reply>,
ModifyRepo,
(const QString &name, const QString &url),
(override));
MOCK_METHOD(QDBusPendingReply<linglong::service::QueryReply>,
Query,
(linglong::service::QueryParamOption paramOption),
(override));
MOCK_METHOD(QDBusPendingReply<linglong::service::Reply>,
Uninstall,
(linglong::service::UninstallParamOption paramOption),
(override));
MOCK_METHOD(QDBusPendingReply<linglong::service::Reply>,
Update,
(linglong::service::ParamOption paramOption),
(override));
MOCK_METHOD(QDBusPendingReply<linglong::service::QueryReply>, getRepoInfo, (), (override));
};
} // namespace linglong::api::dbus::v1::test

View File

@ -1,246 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "linglong/api/dbus/v1/mock_package_manager.h"
#include "linglong/cli/cli.h"
#include "linglong/cli/dbus_reply.h"
#include "linglong/cli/mock_printer.h"
#include "linglong/dbus_ipc/reply.h"
#include "linglong/package_manager/mock_package_manager.h"
#include "linglong/utils/error/error.h"
#include "linglong/utils/finally/finally.h"
#include <iostream>
#include <wordexp.h>
namespace linglong::cli::test {
TEST(SubwstrTest, WithinWidthLimit) {
std::wstring input = L"short";
int width = 10;
std::wstring result = subwstr(input, width);
EXPECT_EQ(result, input);
}
TEST(SubwstrTest, TrimmedString) {
std::wstring input = L"this is a very long string";
int width = 10;
std::wstring expected = L"this is a ";
std::wstring result = subwstr(input, width);
EXPECT_EQ(result, expected);
}
TEST(SubwstrTest, WideCharacters) {
std::wstring input = L"这是一个非常长的字符串";
int width = 10;
std::wstring expected = L"这是一个非";
std::wstring result = subwstr(input, width);
EXPECT_EQ(result, expected);
}
namespace {
std::map<std::string, docopt::value> parseCommand(const QString &command)
{
int argc = 0;
char **argv = nullptr;
auto words = command.toStdString();
wordexp_t exp{};
wordexp(words.c_str(), &exp, 0);
auto defer = utils::finally::finally([&exp]() {
wordfree(&exp);
});
argc = (int)exp.we_wordc;
argv = exp.we_wordv;
auto args = docopt::docopt(Cli::USAGE,
{ argv + 1, argv + argc },
false, // show help if requested
"linglong CLI 1.4.0"); // version string
return args;
}
} // namespace
using ::testing::StrictMock;
class CLITest : public ::testing::Test
{
protected:
std::unique_ptr<StrictMock<MockAppManager>> appMan;
std::shared_ptr<StrictMock<api::dbus::v1::test::MockPackageManager>> pkgMan;
std::unique_ptr<StrictMock<MockPrinter>> printer;
std::unique_ptr<Cli> cli;
static void SetUpTestSuite() { registerDBusParam(); }
void SetUp() override
{
printer = std::make_unique<StrictMock<MockPrinter>>();
appMan = std::make_unique<StrictMock<MockAppManager>>();
pkgMan = std::make_shared<StrictMock<api::dbus::v1::test::MockPackageManager>>(
"org.deepin.linglong.AppManager",
"/org/deepin/linglong/AppManager",
QDBusConnection::sessionBus());
cli = std::make_unique<Cli>(*printer, *appMan, pkgMan);
}
void TearDown() override
{
appMan = nullptr;
pkgMan = nullptr;
printer = nullptr;
}
};
using ::testing::Return;
TEST_F(CLITest, Run)
{
auto args = parseCommand("ll-cli run com.163.music");
EXPECT_CALL(*appMan, Run)
.Times(1)
.WillOnce([](const linglong::service::RunParamOption &paramOption)
-> linglong::utils::error::Result<void> {
return LINGLONG_OK;
});
auto ret = cli->run(args);
EXPECT_EQ(ret, 0);
}
TEST_F(CLITest, Exec)
{
auto args = parseCommand("ll-cli exec com.163.music ls");
EXPECT_CALL(*appMan, Exec).Times(1).WillOnce(Return(service::Reply{ 0, "" }));
auto ret = cli->exec(args);
EXPECT_EQ(ret, 0);
}
TEST_F(CLITest, Enter)
{
GTEST_SKIP() << "Skip test enter as that command is not implemented yet.";
auto args = parseCommand("ll-cli enter xxxx");
auto ret = cli->enter(args);
EXPECT_EQ(ret, 0);
}
TEST_F(CLITest, Ps)
{
auto args = parseCommand("ll-cli ps");
EXPECT_CALL(*appMan, ListContainer)
.Times(1)
.WillOnce(Return(service::QueryReply{ { 0, "" }, "[]" }));
EXPECT_CALL(*printer, printContainers);
auto ret = cli->ps(args);
EXPECT_EQ(ret, 0);
}
TEST_F(CLITest, Kill)
{
auto args = parseCommand("ll-cli kill xxxx");
EXPECT_CALL(*appMan, Stop)
.Times(1)
.WillOnce(Return(service::Reply{ STATUS_CODE(kErrorPkgKillSuccess), "" }));
auto ret = cli->kill(args);
EXPECT_EQ(ret, 0);
}
TEST_F(CLITest, Install)
{
GTEST_SKIP() << "skip install test for now";
auto args = parseCommand("ll-cli install \'xxxx\'");
EXPECT_CALL(*pkgMan, Install).Times(1).WillOnce(Return(createReply(service::Reply{ 0, "" })));
auto ret = cli->install(args);
EXPECT_EQ(ret, 0);
}
TEST_F(CLITest, Upgrade)
{
GTEST_SKIP() << "skip upgrade test for now";
auto args = parseCommand("ll-cli upgrade \'xxxx\'");
EXPECT_CALL(*pkgMan, Update)
.Times(1)
.WillOnce(Return(createReply(service::Reply{ STATUS_CODE(kErrorPkgUpdateSuccess), "" })));
auto ret = cli->upgrade(args);
EXPECT_EQ(ret, 0);
}
TEST_F(CLITest, Search)
{
auto args = parseCommand("ll-cli search xxxx");
EXPECT_CALL(*pkgMan, Query)
.Times(1)
.WillOnce(Return(
createReply(service::QueryReply{ { STATUS_CODE(kErrorPkgQuerySuccess), "" }, R"([])" })));
EXPECT_CALL(*printer, printErr).Times(1);
auto ret = cli->search(args);
EXPECT_EQ(ret, -1);
}
TEST_F(CLITest, Uninstall)
{
auto args = parseCommand("ll-cli uninstall \'xxx aaa\'");
EXPECT_CALL(*pkgMan, Uninstall)
.Times(1)
.WillOnce(Return(createReply(service::Reply{ STATUS_CODE(kPkgUninstallSuccess), "" })));
auto ret = cli->uninstall(args);
EXPECT_EQ(ret, 0);
}
TEST_F(CLITest, List)
{
auto args = parseCommand("ll-cli list");
EXPECT_CALL(*pkgMan, Query)
.Times(1)
.WillOnce(Return(
createReply(service::QueryReply{ { STATUS_CODE(kErrorPkgQuerySuccess), "" }, "[]" })));
EXPECT_CALL(*printer, printAppMetaInfos).Times(1);
auto ret = cli->list(args);
EXPECT_EQ(ret, 0);
}
TEST_F(CLITest, repo)
{
auto args = parseCommand("ll-cli repo list");
EXPECT_CALL(*pkgMan, getRepoInfo)
.Times(1)
.WillOnce(
Return(createReply(service::QueryReply{ { STATUS_CODE(kErrorPkgQuerySuccess), "" }, "" })));
auto ret = cli->repo(args);
EXPECT_EQ(ret, 0);
}
} // namespace linglong::cli::test

View File

@ -1,28 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#pragma once
#include <qdbusmetatype.h>
#define private public
#include <private/qdbusmessage_p.h>
#undef private
#include <QDBusPendingReply>
template<typename ReturnValue>
QDBusPendingReply<ReturnValue> createReply(const ReturnValue &value,
const QString &dest = "",
const QString &path = "",
const QString &interface = "",
const QString &method = "")
{
auto call = QDBusMessage::createMethodCall(dest, path, interface, method);
auto msg = call.createReply();
msg << QVariant::fromValue(value);
msg.d_ptr->signature = QDBusMetaType::typeToSignature(QMetaType::fromType<ReturnValue>().id());
return QDBusPendingCall::fromCompletedCall(msg);
}

View File

@ -1,47 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#pragma once
#include <gmock/gmock.h>
#include "linglong/service/app_manager.h"
#include "linglong/utils/error/error.h"
#include <QVector>
#include <iostream>
namespace linglong::cli::test {
class MockAppManager : public service::AppManager
{
private:
repo::Repo *nullRepo = nullptr;
ocppi::cli::CLI *nullCli = nullptr;
public:
MockAppManager()
: service::AppManager(*nullRepo, *nullCli)
{
}
MOCK_METHOD(linglong::utils::error::Result<void>,
Run,
(const linglong::service::RunParamOption &paramOption),
(override));
MOCK_METHOD(linglong::service::Reply,
Exec,
(const linglong::service::ExecParamOption &paramOption),
(override));
MOCK_METHOD(linglong::service::QueryReply, ListContainer, (), (override));
MOCK_METHOD(linglong::service::Reply, Stop, (const QString &ContainerID), (override));
};
} // namespace linglong::cli::test

View File

@ -1,31 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#pragma once
#include <gmock/gmock.h>
#include "linglong/cli/printer.h"
#include <QVector>
#include <iostream>
namespace linglong::cli::test {
class MockPrinter : public Printer
{
public:
MOCK_METHOD(void, printErr, (const utils::error::Error &), (override));
MOCK_METHOD(void,
printAppMetaInfos,
(const QList<QSharedPointer<linglong::package::AppMetaInfo>> &),
(override));
MOCK_METHOD(void, printContainers, (const QList<QSharedPointer<Container>> &));
};
} // namespace linglong::cli::test

View File

@ -17,12 +17,12 @@ TEST(Package, Reference)
"main:com.example.App/1.0.0.0/x86_64",
"some_channel:com.example.App/1.0.0.0/x86_64",
"main:com.example.App/1.0.0.0/x86_64",
"main:com.example.App/1.0.0.0-alpha/arm64",
"main:com.example.App/1.0.0.1-beta/arm64",
"main:com.example.App/1.0.0.0/arm64",
"main:com.example.App/1.0.0.1/arm64",
"main:1111/1.0.0.0/x86_64",
"main:2222/1.0.0.0/x86_64",
"main:3333/1.0.0.0-alpha/arm64",
"main:4444/1.0.0.1-beta/arm64",
"main:3333/1.0.0.0/arm64",
"main:4444/1.0.0.1/arm64",
};
for (const auto &vaildCase : vaildReferences) {
@ -57,9 +57,9 @@ TEST(Package, Reference)
{ "com.example.App/1.0.0.0/unknown", "unknown:com.example.App/1.0.0.0/unknown" },
{ "com.example.App/1.0.0.0", "unknown:com.example.App/1.0.0.0/unknown" },
{ "com.example.App", "unknown:com.example.App/unknown/unknown" },
{ "com.example.App/1.0.0.1-beta", "unknown:com.example.App/1.0.0.1-beta/unknown" },
{ "3333/1.0.0.0-alpha/arm64", "unknown:3333/1.0.0.0-alpha/arm64" },
{ "4444/1.0.0.1-beta/arm64", "unknown:4444/1.0.0.1-beta/arm64" },
{ "com.example.App/1.0.0.1", "unknown:com.example.App/1.0.0.1/unknown" },
{ "3333/1.0.0.0/arm64", "unknown:3333/1.0.0.0/arm64" },
{ "4444/1.0.0.1/arm64", "unknown:4444/1.0.0.1/arm64" },
};
for (const auto &vaildCase : vaildFuzzReferences) {

View File

@ -13,12 +13,7 @@ using namespace linglong::package;
TEST(Package, VersionRange)
{
QStringList versions = {
"1.0.0.0-alpha", "1.0.0.0-alpha.0", "1.0.0.0-alpha.1", "1.0.0.0-alpha.beta",
"1.0.0.0-beta", "1.0.0.0-beta.2", "1.0.0.0-beta.11", "1.0.0.0-rc.1",
"1.0.0.0", "1.0.0.1", "2.0.0.0", "2.1.0.0",
"2.1.1.0", "2.1.1.1"
};
QStringList versions = { "1.0.0.0", "1.0.0.1", "2.0.0.0", "2.1.0.0", "2.1.1.0", "2.1.1.1" };
for (int i = 0; i < versions.size() - 1; i++) {
for (int j = i + 1; j < versions.size(); j++) {
for (int k = 0; k < versions.size(); k++) {

View File

@ -18,34 +18,10 @@ TEST(Package, VersionRegex101)
"0.0.0.4",
"1.2.3.4",
"10.20.30.40",
"1.1.1.2-prerelease+meta",
"1.1.1.2+meta",
"1.1.1.2+meta-valid",
"1.0.0.0-alpha",
"1.0.0.0-beta",
"1.0.0.0-alpha.beta",
"1.0.0.0-alpha.beta.1",
"1.0.0.0-alpha.1",
"1.0.0.0-alpha0.valid",
"1.0.0.0-alpha.0valid",
"1.0.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay",
"1.0.0.0-rc.1+build.1",
"2.0.0.0-rc.1+build.123",
"1.2.3.0-beta",
"10.2.3.0-DEV-SNAPSHOT",
"1.2.3.0-SNAPSHOT-123",
"1.0.0.0",
"2.0.0.0",
"1.1.1.7",
"2.0.0.0+build.1848",
"2.0.0.1-alpha.1227",
"1.0.0.0-alpha+beta",
"1.2.3.4----RC-SNAPSHOT.12.9.1--.12+788",
"1.2.3.4----R-S.12.9.1--.12+meta",
"1.2.3.4----RC-SNAPSHOT.12.9.1--.12",
"1.0.0.0+0.build.1-rc.10000aaa-kk-0.1",
"999999999999999999.999999999999999999.99999999999999999.99999999999999999",
"1.0.0.0-0A.is.legal",
};
for (const auto &validCase : validCases) {
@ -103,7 +79,6 @@ TEST(Package, VersionRegex101)
"1.1.01.1",
"1.1.1.01",
"1.2",
"1.2.3",
"1.2.3.DEV",
"1.2.3.4.DEV",
"1.2-SNAPSHOT",
@ -132,29 +107,7 @@ TEST(Package, VersionRegex101)
TEST(Package, VersionCompare)
{
auto x = Version::parse("1.0.0.0+1");
ASSERT_EQ(x.has_value(), true) << "1.0.0.0+1 is valid.";
auto y = Version::parse("1.0.0.0+2");
ASSERT_EQ(y.has_value(), true) << "1.0.0.0+2 is valid.";
ASSERT_EQ(*x, *y) << "x:" << x->toString().toStdString()
<< " y:" << y->toString().toStdString();
ASSERT_EQ(*x < *y, false) << "x:" << x->toString().toStdString()
<< " y:" << y->toString().toStdString();
ASSERT_EQ(*x <= *y, true) << "x:" << x->toString().toStdString()
<< " y:" << y->toString().toStdString();
ASSERT_EQ(*x != *y, false) << "x:" << x->toString().toStdString()
<< " y:" << y->toString().toStdString();
ASSERT_EQ(*x > *y, false) << "x:" << x->toString().toStdString()
<< " y:" << y->toString().toStdString();
ASSERT_EQ(*x >= *y, true) << "x:" << x->toString().toStdString()
<< " y:" << y->toString().toStdString();
QStringList versions = {
"1.0.0.0-alpha", "1.0.0.0-alpha.0", "1.0.0.0-alpha.1", "1.0.0.0-alpha.beta",
"1.0.0.0-beta", "1.0.0.0-beta.2", "1.0.0.0-beta.11", "1.0.0.0-rc.1",
"1.0.0.0", "1.0.0.1", "2.0.0.0", "2.1.0.0",
"2.1.1.0", "2.1.1.1"
};
QStringList versions = { "1.0.0.0", "1.0.0.1", "2.0.0.0", "2.1.0.0", "2.1.1.0", "2.1.1.1" };
for (int i = 0; i < versions.size() - 1; i++) {
for (int j = i + 1; j < versions.size(); j++) {
auto x = Version::parse(versions[i]);

View File

@ -6,7 +6,7 @@
#include <gtest/gtest.h>
#include "linglong/package/ref.h"
#include "linglong/package/reference.h"
#include "linglong/repo/ostree_repo.h"
#include "linglong/util/file.h"
#include "linglong/utils/error/error.h"

View File

@ -12,6 +12,7 @@ BuildRequires: glib2-devel nlohmann-json-devel ostree-devel yaml-cpp-devel
BuildRequires: systemd-devel gtest-devel libseccomp-devel elfutils-libelf-devel
BuildRequires: glibc-static libstdc++-static
BuildRequires: libcurl-devel openssl-devel
BuildRequires: gtest-devel gmock-devel
Requires: linglong-bin = %{version}-%{release}
%description