Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,26 @@ add_custom_target(test
COMMAND ${CMAKE_BINARY_DIR}/bin/tests/readonlylibarchiveplugin_test
COMMAND ${CMAKE_BINARY_DIR}/bin/tests/readwritelibarchiveplugin_test
COMMAND ${CMAKE_BINARY_DIR}/bin/tests/xzplugin_test
COMMAND ${CMAKE_BINARY_DIR}/bin/tests/contract_test
COMMAND echo " =================== TEST END ==================== "
)

add_dependencies(test
bz2plugin_test
cli7zplugin_test
clirarplugin_test
deepin-compressor_test
gzplugin_test
interface_test
libminizipplugin_test
libpigzplugin_test
libzipplugin_test
readonlylibarchiveplugin_test
readwritelibarchiveplugin_test
xzplugin_test
contract_test
)

# debian 会自动执行 make test
#'make test'命令依赖与我们的测试程序
#add_dependencies(test ${PROJECT_NAME_TEST})

2 changes: 2 additions & 0 deletions tests/UnitTest/3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ add_subdirectory(libminizipplugin)
##add_subdirectory(cliunarchiverplugin) #不可用

##add_subdirectory(clizipplugin) #不可用

add_subdirectory(contract)
37 changes: 17 additions & 20 deletions tests/UnitTest/3rdparty/cli7zplugin/ut_cli7zplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ TEST_F(UT_Cli7zPlugin, test_setupCliProperties)
EXPECT_EQ(m_tester->m_cliProps->property("captureProgress"), false);
EXPECT_EQ(m_tester->m_cliProps->property("addProgram"), QStringLiteral("7z"));

EXPECT_EQ(m_tester->m_cliProps->property("addSwitch"), QStringList({QStringLiteral("a"), QStringLiteral("-l")}));
EXPECT_EQ(m_tester->m_cliProps->property("addSwitch"), QStringList({QStringLiteral("a"), QStringLiteral("-snl")}));
EXPECT_EQ(m_tester->m_cliProps->property("deleteProgram"), QStringLiteral("7z"));
EXPECT_EQ(m_tester->m_cliProps->property("deleteSwitch"), QStringLiteral("d"));

EXPECT_EQ(m_tester->m_cliProps->property("extractProgram"), QStringLiteral("7z"));
EXPECT_EQ(m_tester->m_cliProps->property("extractSwitch"), QStringLiteral("x"));
EXPECT_EQ(m_tester->m_cliProps->property("extractSwitch"), QStringList{QStringLiteral("x")});
EXPECT_EQ(m_tester->m_cliProps->property("progressarg"), QStringLiteral("-bsp1"));
EXPECT_EQ(m_tester->m_cliProps->property("extractSwitchNoPreserve"), QStringList{QStringLiteral("e")});

Expand All @@ -250,9 +250,9 @@ TEST_F(UT_Cli7zPlugin, test_setupCliProperties)
EXPECT_EQ(m_tester->m_cliProps->property("moveSwitch"), QStringLiteral("rn"));

EXPECT_EQ(m_tester->m_cliProps->property("testProgram"), QStringLiteral("7z")) ;
EXPECT_EQ(m_tester->m_cliProps->property("testSwitch"), QStringLiteral("t")) ;
EXPECT_EQ(m_tester->m_cliProps->property("testSwitch"), QStringList{QStringLiteral("t")});

EXPECT_EQ(m_tester->m_cliProps->property("passwordSwitch"), QStringLiteral("-p$Password")) ;
EXPECT_EQ(m_tester->m_cliProps->property("passwordSwitch"), QStringList{QStringLiteral("-p$Password")});
EXPECT_EQ(m_tester->m_cliProps->property("passwordSwitchHeaderEnc"), QStringList({QStringLiteral("-p$Password"), QStringLiteral("-mhe=on")})) ;

EXPECT_EQ(m_tester->m_cliProps->property("compressionLevelSwitch"), QStringLiteral("-mx=$CompressionLevel")) ;
Expand Down Expand Up @@ -589,13 +589,19 @@ TEST_F(UT_Cli7zPlugin, test_extractFiles_001)
Stub stub;
stub.set(ADDR(CliInterface, runProcess), cliInterface_runProcess_stub);

FileEntry rootEntry;
rootEntry.strFullPath = "1.txt";
rootEntry.strFileName = "1.txt";
DataManager::get_instance().archiveData().listRootEntry << rootEntry;

ExtractionOptions options;
options.strTargetPath = _UTSOURCEDIR;
options.strTargetPath += "/test_sources/7z/extract";
options.bAllExtract = true;
EXPECT_EQ(m_tester->extractFiles(QList<FileEntry>(), options), PFT_Nomral);
EXPECT_EQ(m_tester->m_strPassword.isEmpty(), true);
EXPECT_EQ(m_tester->m_workStatus, WT_Extract);
DataManager::get_instance().resetArchiveData();
}

TEST_F(UT_Cli7zPlugin, test_extractFiles_002)
Expand All @@ -606,13 +612,15 @@ TEST_F(UT_Cli7zPlugin, test_extractFiles_002)
FileEntry entry;
entry.strFullPath = "1.txt";
entry.strFileName = "1.txt";
DataManager::get_instance().archiveData().listRootEntry << entry;
ExtractionOptions options;
options.strTargetPath = _UTSOURCEDIR;
options.strTargetPath += "/test_sources/7z/extract";
options.bAllExtract = false;
EXPECT_EQ(m_tester->extractFiles(QList<FileEntry>() << entry, options), PFT_Nomral);
EXPECT_EQ(m_tester->m_strPassword.isEmpty(), true);
EXPECT_EQ(m_tester->m_workStatus, WT_Extract);
DataManager::get_instance().resetArchiveData();
}

TEST_F(UT_Cli7zPlugin, test_pauseOperation)
Expand All @@ -622,6 +630,7 @@ TEST_F(UT_Cli7zPlugin, test_pauseOperation)
m_tester->m_childProcessId << 123456 << 234567;
m_tester->m_processId = 012345;
m_tester->pauseOperation();
EXPECT_EQ(m_tester->status(), true);
}

TEST_F(UT_Cli7zPlugin, test_continueOperation)
Expand All @@ -630,7 +639,10 @@ TEST_F(UT_Cli7zPlugin, test_continueOperation)
stub.set(kill, kill_stub);
m_tester->m_childProcessId << 123456 << 234567;
m_tester->m_processId = 012345;
m_tester->pauseOperation();
EXPECT_EQ(m_tester->status(), true);
m_tester->continueOperation();
EXPECT_EQ(m_tester->status(), false);
}

TEST_F(UT_Cli7zPlugin, test_doKill_001)
Expand Down Expand Up @@ -1052,16 +1064,6 @@ TEST_F(UT_Cli7zPlugin, test_writeToProcess)
EXPECT_NE(m_tester->m_process->pty(), nullptr);
}

TEST_F(UT_Cli7zPlugin, test_moveExtractTempFilesToDest)
{

}

TEST_F(UT_Cli7zPlugin, test_readStdout)
{

}

TEST_F(UT_Cli7zPlugin, test_processFinished)
{
Stub stub;
Expand All @@ -1075,7 +1077,7 @@ TEST_F(UT_Cli7zPlugin, test_processFinished)
m_tester->m_workStatus = WT_List;
m_tester->processFinished(0, QProcess::NormalExit);
EXPECT_EQ(m_tester->m_eErrorType, ET_MissingVolume);
EXPECT_EQ(m_tester->m_finishType, PFT_Nomral);
EXPECT_EQ(m_tester->m_finishType, PFT_Cancel);
EXPECT_EQ(m_tester->m_isCorruptArchive, false);
}

Expand Down Expand Up @@ -1109,11 +1111,6 @@ TEST_F(UT_Cli7zPlugin, test_extractProcessFinished_002)
EXPECT_EQ(m_tester->m_rootNode.isEmpty(), true);
}

TEST_F(UT_Cli7zPlugin, test_getChildProcessId)
{

}

TEST_F(UT_Cli7zPlugin, test_getTargetPath)
{
m_tester->m_extractOptions.strTargetPath = "a/b";
Expand Down
4 changes: 2 additions & 2 deletions tests/UnitTest/3rdparty/clirarplugin/ut_clirarplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ TEST_F(UT_CliRarPlugin, test_setupCliProperties)
EXPECT_EQ(m_tester->m_cliProps->property("moveSwitch"), QStringLiteral("rn"));

EXPECT_EQ(m_tester->m_cliProps->property("testProgram"), QStringLiteral("unrar"));
EXPECT_EQ(m_tester->m_cliProps->property("testSwitch"), QStringLiteral("t"));
EXPECT_EQ(m_tester->m_cliProps->property("testSwitch"), QStringList{QStringLiteral("t")});

EXPECT_EQ(m_tester->m_cliProps->property("commentSwitch"), QStringList({QStringLiteral("c"), QStringLiteral("-z$CommentFile")}));

Expand Down Expand Up @@ -294,7 +294,7 @@ TEST_F(UT_CliRarPlugin, test_handleLine_002)

TEST_F(UT_CliRarPlugin, test_handleLine_003)
{
EXPECT_EQ(m_tester->handleLine("The specified password is incorrect", WT_Extract), true);
EXPECT_EQ(m_tester->handleLine("The specified password is incorrect", WT_Extract), false);
EXPECT_EQ(m_tester->m_eErrorType, ET_WrongPassword);
}

Expand Down
97 changes: 97 additions & 0 deletions tests/UnitTest/3rdparty/contract/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

cmake_minimum_required(VERSION 3.9.5)

set(EXE_NAME contract)
project(${EXE_NAME}_test)

find_package(PkgConfig REQUIRED)
find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets)
find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED)
find_package(KF${KF_VERSION_MAJOR}Archive REQUIRED)
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core Widget)

if (QT_DESIRED_VERSION MATCHES 6)
find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Core5Compat)
endif()

find_package(ZLIB REQUIRED)
find_package(LibArchive REQUIRED)
include(FindPkgConfig)

pkg_search_module(MOUNT REQUIRED mount)

# Header search paths for all plugin and interface headers
include_directories(${HFILES_OUTPUT_PATH})
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/interface)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/interface/archiveinterface)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/interface/plugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/interface/process)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/cli7zplugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/clirarplugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libzipplugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libminizipplugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libpigzplugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libarchive/libarchive)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libarchive/readonlylibarchiveplugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libarchive/readwritelibarchiveplugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libsinglefileplugin/singlefile)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libsinglefileplugin/gzplugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libsinglefileplugin/bz2plugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libsinglefileplugin/xzplugin)
include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/ChardetDetector)

link_directories(${LIBRARY_OUTPUT_PATH})

# Ensure linker can find libarchive (transitive dependency from compressor-archive
# via plugin shared libraries).
if(LibArchive_LIBRARIES)
get_filename_component(LIBARCHIVE_LIB_DIR "${LibArchive_LIBRARIES}" DIRECTORY)
link_directories(${LIBARCHIVE_LIB_DIR})
endif()

# Only compile the contract test sources — plugin sources come from the
# pre-built shared libraries to avoid Q_PLUGIN_METADATA symbol conflicts.
file(GLOB c_files ./*.cpp)
file(GLOB h_files ./*.h)

add_executable(${EXE_NAME}_test ${c_files} ${h_files})

target_link_libraries(${EXE_NAME}_test
Qt${QT_DESIRED_VERSION}::Widgets
KF${KF_VERSION_MAJOR}::Codecs
KF${KF_VERSION_MAJOR}::Archive
Dtk${DTK_VERSION_MAJOR}::Core
Dtk${DTK_VERSION_MAJOR}::Widget
${MOUNT_LIBRARIES}
# Pre-built plugin shared libraries (each carries its own Q_PLUGIN_METADATA)
cli7zplugin
clirarplugin
libzipplugin
minizipplugin
libpigzplugin
readonlylibarchiveplugin
readwritelibarchiveplugin
gzplugin
bz2plugin
xzplugin
# libarchive transitive dependencies
acl
xml2
# Base libraries
compressor-interface
ZLIB::ZLIB
compressor-singlefile
compressor-ChardetDetector
${GTEST_LIBRARIES}
pthread
)

if (QT_DESIRED_VERSION MATCHES 6)
target_link_libraries(${EXE_NAME}_test
Qt${QT_DESIRED_VERSION}::Core5Compat
)
endif()
Loading
Loading