Skip to content
Merged
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
8 changes: 7 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ set(LINK_LIBS

if (QT_DESIRED_VERSION MATCHES 6)
list(APPEND LINK_LIBS Qt${QT_DESIRED_VERSION}::Core5Compat)
list(APPEND LINK_LIBS Qt${QT_DESIRED_VERSION}::GuiPrivate Qt${QT_DESIRED_VERSION}::CorePrivate)
else()
list(APPEND LINK_LIBS ${Gsetting_LIBRARIES})
include_directories(${Gsetting_INCLUDE_DIRS})
Expand All @@ -101,6 +102,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty)

FILE(GLOB allSource
../application/filtercontent.cpp
../application/cliapplicationhelper.cpp
../application/logtableview.cpp
../application/displaycontent.cpp
../application/logcollectormain.cpp
../application/logfileparser.cpp
Expand Down Expand Up @@ -144,6 +147,7 @@ FILE(GLOB allSource
../application/parsethread/parsethreadbase.cpp
../application/parsethread/parsethreadkern.cpp
../application/parsethread/parsethreadkwin.cpp
../logViewerService/logviewerservice.cpp
)
FILE(GLOB qrcFiles
../application/assets/resources.qrc
Expand Down Expand Up @@ -259,6 +263,8 @@ include_sub_directories_recursively("${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/tmp
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_sub_directories_recursively("${CMAKE_CURRENT_SOURCE_DIR}/../application")
include_sub_directories_recursively("${CMAKE_CURRENT_SOURCE_DIR}/../liblogviewerplugin")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../logViewerService)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../logViewerAuth)

include_directories( ${Boost_INCLUDE_DIRS})
include_directories( ${ZLIB_INCLUDE_DIRS})
Expand All @@ -269,7 +275,7 @@ include_directories(${GTEST_INCLUDE_DIRS})

include_directories(src)

add_executable (${PROJECT_NAME_TEST} ${allSource} ${APP_QRC_FILES} ${qrcFiles} ${allTestSource} ${MINIZIP_SOURCES} ${LXW_SOURCES} ${DOCXFAC_SOURCES} ${DOCXFAC_SOURCES_C} ${TMPFILE_SOURCES} ${MD5SOURCES})
add_executable (${PROJECT_NAME_TEST} ${allSource} ../application/configs/json/org_deepin_log_viewer.hpp ${APP_QRC_FILES} ${qrcFiles} ${allTestSource} ${MINIZIP_SOURCES} ${LXW_SOURCES} ${DOCXFAC_SOURCES} ${DOCXFAC_SOURCES_C} ${TMPFILE_SOURCES} ${MD5SOURCES})
#添加插件单元测试进程
add_executable (${PROJECT_NAME_PLUGIN_TEST} ${allPluginTestSource} ${LVP_HEADERS} ${LVP_SOURCES} ${MINIZIP_SOURCES} ${LXW_SOURCES} ${DOCXFAC_SOURCES} ${DOCXFAC_SOURCES_C} ${TMPFILE_SOURCES} ${MD5SOURCES})

Expand Down
6 changes: 3 additions & 3 deletions tests/dbusproxy/ut_dldbushandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ TEST_F(UT_DLDBusHandler, openLogStream_home_branch_returns_local_token)
{
Utils::homePath = m_homeDir.path();
QString abs = makeHomeFile("stream.log", "stream-content\n");
QString [REDACTED CREDENTIAL]
QString token = m_handler->openLogStream(abs);
EXPECT_TRUE(token.startsWith(QStringLiteral("local-")));
}

TEST_F(UT_DLDBusHandler, openLogStream_home_branch_unreadable_returns_empty)
{
Utils::homePath = m_homeDir.path();
QString [REDACTED CREDENTIAL] + "/no_such_file.log");
QString token = m_handler->openLogStream(m_homeDir.path() + "/no_such_file.log");
EXPECT_TRUE(token.isEmpty());
}

Expand All @@ -176,7 +176,7 @@ TEST_F(UT_DLDBusHandler, readLogInStream_local_token_returns_content)
{
Utils::homePath = m_homeDir.path();
QString abs = makeHomeFile("stream2.log", "data-line\n");
QString [REDACTED CREDENTIAL]
QString token = m_handler->openLogStream(abs);
ASSERT_FALSE(token.isEmpty());
QString result = m_handler->readLogInStream(token);
EXPECT_FALSE(result.isEmpty());
Expand Down
6 changes: 3 additions & 3 deletions tests/dbusproxy/ut_userlogaccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ TEST(UT_UserLogAccess_openLogStream, UT_UserLogAccess_openLogStream_normal)
tmp.write("stream line 1\nstream line 2\n");
tmp.close();

QString [REDACTED CREDENTIAL]
QString token = UserLogAccess::instance()->openLogStream(tmp.fileName());
EXPECT_FALSE(token.isEmpty());
EXPECT_TRUE(token.startsWith(QStringLiteral("local-")));
}

// openLogStream:读取失败返回空 token
TEST(UT_UserLogAccess_openLogStream, UT_UserLogAccess_openLogStream_empty)
{
QString [REDACTED CREDENTIAL]
QString token = UserLogAccess::instance()->openLogStream("/tmp/dlv_ut_nonexistent.log");
EXPECT_TRUE(token.isEmpty());
}

Expand All @@ -198,7 +198,7 @@ TEST(UT_UserLogAccess_readLogInStream, UT_UserLogAccess_readLogInStream_valid)
tmp.write("aaa\nbbb\n");
tmp.close();

QString [REDACTED CREDENTIAL]
QString token = UserLogAccess::instance()->openLogStream(tmp.fileName());
ASSERT_FALSE(token.isEmpty());

QString first = UserLogAccess::instance()->readLogInStream(token);
Expand Down
15 changes: 15 additions & 0 deletions tests/src/ut_displaycontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ bool stub_isCoredumpctlExist_false()
return false;
}

int LogFileParser_parseByAudit(const AUDIT_FILTERS &)
{
return 0;
}

int LogFileParser_parseByAuth(const AUTH_FILTERS &)
{
return 0;
}

int LogFileParser_parseByCoredump(const COREDUMP_FILTERS &, bool)
{
return 0;
}

void stub_refreshAuthLogList()
{
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/ut_logauththread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ bool stub_isFileExist_true(const QString &filePath)
return true;
}

bool stub_isFileExist_false(const QString &filePath)
static bool stub_isFileExist_false(const QString &filePath)
{
Q_UNUSED(filePath);
return false;
Expand Down
6 changes: 4 additions & 2 deletions tests/src/ut_logbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ static QDateTime stub_appHelper_getLastReportTime()
}

static void stub_appHelper_saveLastRerportTime(const QDateTime &) {}
static LogApplicationHelper *stub_appHelper_instance() { return reinterpret_cast<LogApplicationHelper *>(0x1); }
alignas(LogApplicationHelper) static char stub_appHelper_buf[sizeof(LogApplicationHelper)] = {};
static LogApplicationHelper *stub_appHelper_instance() { return reinterpret_cast<LogApplicationHelper *>(stub_appHelper_buf); }

static int stub_appHelper_getMaxReportCoredump()
{
Expand Down Expand Up @@ -134,7 +135,8 @@ static QString stub_dlbus_readLogLinesInRange(const QString &, int, int)
{
return QString();
}
static DLDBusHandler *stub_dlbus_instance() { return reinterpret_cast<DLDBusHandler *>(0x1); }
alignas(DLDBusHandler) static char stub_dlbus_buf[sizeof(DLDBusHandler)] = {};
static DLDBusHandler *stub_dlbus_instance() { return reinterpret_cast<DLDBusHandler *>(stub_dlbus_buf); }

static QString stub_Utils_mkMutiDir(const QString &) { return QString(); }
static bool stub_Utils_checkAndDeleteDir(const QString &) { return true; }
Expand Down
26 changes: 26 additions & 0 deletions tests/src/ut_logcollectormain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,21 @@ bool LogCollectorMain_notify(QObject *obj, QEvent *event)
return false;
}


// 兜底:部分用例链中 QApplication 可能被 deleteLater 销毁,建 QWidget 前确保实例存在
static QApplication *ensureQtApp()
{
if (qApp == nullptr) {
static int argc = 0;
static QApplication *app = new QApplication(argc, nullptr);
return app;
}
return static_cast<QApplication *>(qApp);
}

TEST(LogCollectorMain_Constructor_UT, LogCollectorMain_Constructor_UT)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand All @@ -96,6 +109,7 @@ TEST(LogCollectorMain_Constructor_UT, LogCollectorMain_Constructor_UT)

TEST(LogCollectorMain_Destructor_UT, LogCollectorMain_Destructor_UT)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand All @@ -114,6 +128,7 @@ TEST(LogCollectorMain_Destructor_UT, LogCollectorMain_Destructor_UT)
}
TEST(LogCollectorMain_initUI_UT, LogCollectorMain_initUI_UT)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand All @@ -133,6 +148,7 @@ TEST(LogCollectorMain_initUI_UT, LogCollectorMain_initUI_UT)

TEST(LogCollectorMain_initShortCut_UT, LogCollectorMain_initShortCut_UT_001)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand All @@ -153,6 +169,7 @@ TEST(LogCollectorMain_initShortCut_UT, LogCollectorMain_initShortCut_UT_001)

TEST(LogCollectorMain_initShortCut_UT, LogCollectorMain_initShortCut_UT_002)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand Down Expand Up @@ -182,6 +199,7 @@ TEST(LogCollectorMain_initShortCut_UT, LogCollectorMain_initShortCut_UT_002)

TEST(LogCollectorMain_initConnection_UT, LogCollectorMain_initConnection_UT)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand Down Expand Up @@ -306,6 +324,7 @@ TEST_P(LogCollectorMain_handleApplicationTabEventNotify_UT, LogCollectorMain_han

TEST(LogCollectorMain_switchRefreshActionTriggered_UT, LogCollectorMain_switchRefreshActionTriggered_UT_001)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand Down Expand Up @@ -337,6 +356,7 @@ TEST(LogCollectorMain_switchRefreshActionTriggered_UT, LogCollectorMain_switchRe

TEST(LogCollectorMain_exportAllLogs_UT, LogCollectorMain_exportAllLogs_UT_001)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand All @@ -361,6 +381,7 @@ TEST(LogCollectorMain_exportAllLogs_UT, LogCollectorMain_exportAllLogs_UT_001)

TEST(LogCollectorMain_exportAllLogs_UT, LogCollectorMain_exportAllLogs_UT_002)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand Down Expand Up @@ -392,6 +413,7 @@ TEST(LogCollectorMain_exportAllLogs_UT, LogCollectorMain_exportAllLogs_UT_002)

TEST(LogCollectorMain_closeEvent_UT, LogCollectorMain_closeEvent_UT_001)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand Down Expand Up @@ -472,6 +494,7 @@ int LogCollectorMain_exec_processEvents(DDialog *self)
// ===== initShortCut lambda coverage =====
TEST(LogCollectorMain_initShortCut_UT, LogCollectorMain_initShortCut_UT_003)
{
ensureQtApp();
// Set DStyle so DApplication::style() returns a valid DStyle* — prevents SEGV
// in LogPeriodButton::paintEvent when showMaximized()/showNormal() triggers repaints
qApp->setStyle(new DStyle);
Expand Down Expand Up @@ -509,6 +532,7 @@ TEST(LogCollectorMain_initShortCut_UT, LogCollectorMain_initShortCut_UT_003)
// ===== initTitlebarExtensions lambda coverage =====
TEST(LogCollectorMain_initTitlebarExtensions_UT, LogCollectorMain_initTitlebarExtensions_UT_002)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand Down Expand Up @@ -539,6 +563,7 @@ TEST(LogCollectorMain_initTitlebarExtensions_UT, LogCollectorMain_initTitlebarEx
// ===== switchRefreshActionTriggered lambda coverage =====
TEST(LogCollectorMain_switchRefreshActionTriggered_UT, LogCollectorMain_switchRefreshActionTriggered_UT_002)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand Down Expand Up @@ -580,6 +605,7 @@ TEST(LogCollectorMain_switchRefreshActionTriggered_UT, LogCollectorMain_switchRe
// ===== exportAllLogs lambda coverage =====
TEST(LogCollectorMain_exportAllLogs_UT, LogCollectorMain_exportAllLogs_UT_003)
{
ensureQtApp();
Stub stub;
stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux);
stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/ut_loglistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ int stub_ddialog_exec_rejected()
return 0;
}

bool stub_showFileItem(const QString &localFilePath, const QString &startupId)
static bool stub_showFileItem(const QString &localFilePath, const QString &startupId)
{
Q_UNUSED(localFilePath);
Q_UNUSED(startupId);
Expand Down
4 changes: 2 additions & 2 deletions tests/src/ut_logviewerservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ TEST_F(LogViewerServiceTest, OpenLogStreamAuthOk)
ASSERT_TRUE(tmpFile.open());
tmpFile.write("stream line\n");
tmpFile.flush();
QString [REDACTED CREDENTIAL]
QString token = m_service->openLogStream(tmpFile.fileName());
EXPECT_FALSE(token.isEmpty());
}

Expand All @@ -500,7 +500,7 @@ TEST_F(LogViewerServiceTest, ReadLogInStreamValidToken)
ASSERT_TRUE(tmpFile.open());
tmpFile.write("stream data 1\nstream data 2\n");
tmpFile.flush();
QString [REDACTED CREDENTIAL]
QString token = m_service->openLogStream(tmpFile.fileName());
ASSERT_FALSE(token.isEmpty());
QString result = m_service->readLogInStream(token);
EXPECT_TRUE(result.contains("stream data"));
Expand Down
Loading