| 1 | // SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | #include "dbusproxy/dldbushandler.h" |
| 7 | #include "../application/logallexportthread.h" |
| 8 | #include <stub.h> |
| 9 | |
| 10 | QStringList LogAllExportThread_stub_toString() |
| 11 | { |
| 12 | QStringList list; |
| 13 | list << "test" << "test2"; |
| 14 | return list; |
| 15 | } |
| 16 | |
| 17 | bool LogAllExportThread_stub_bool(const QString &outDir, const QString &in, bool isFile) |
| 18 | { |
| 19 | Q_UNUSED(outDir); |
| 20 | Q_UNUSED(in); |
| 21 | Q_UNUSED(isFile); |
| 22 | return false; |
| 23 | } |
| 24 | |
| 25 | |
| 26 | TEST(LogAllExportThread_LogAllExportThread_UT, LogAllExportThread_LogAllExportThread_UT_001) |
| 27 | { |
| 28 | QStringList thread; |
| 29 | thread << "test" << "test2"; |
| 30 | LogAllExportThread *p = new LogAllExportThread(thread, "path"); |
| 31 | ASSERT_TRUE(p); |
| 32 | EXPECT_EQ(p->m_outfile, "path"); |
| 33 | delete p; |
| 34 | } |
| 35 | |
| 36 | |
| 37 | TEST(LogAllExportThread_run_UT, LogAllExportThread_run_UT_001) |
| 38 | { |
| 39 | QStringList thread; |
| 40 | thread << "test" << "test2"; |
| 41 | LogAllExportThread *p = new LogAllExportThread(thread, "path"); |
| 42 | ASSERT_TRUE(p); |
| 43 | Stub stub; |
| 44 | stub.set(ADDR(DLDBusHandler, getFileInfo), LogAllExportThread_stub_toString); |
| 45 | stub.set(ADDR(DLDBusHandler, exportLog), LogAllExportThread_stub_bool); |
| 46 | p->m_types << JOUR_TREE_DATA << BOOT_KLU_TREE_DATA << DMESG_TREE_DATA << LAST_TREE_DATA << |
| 47 | DPKG_TREE_DATA << KERN_TREE_DATA << XORG_TREE_DATA << DNF_TREE_DATA << BOOT_TREE_DATA << |
| 48 | KWIN_TREE_DATA << APP_TREE_DATA; |
| 49 | p->run(); |
| 50 | delete p; |
| 51 | } |
| 52 | |
| 53 | TEST(LogAllExportThread_run_UT, LogAllExportThread_run_UT_002) |
| 54 | { |
| 55 | QStringList thread; |
| 56 | thread << "test" << "test2"; |
| 57 | Stub stub; |
| 58 | stub.set(ADDR(DLDBusHandler, getFileInfo), LogAllExportThread_stub_toString); |
| 59 | stub.set(ADDR(DLDBusHandler, exportLog), LogAllExportThread_stub_bool); |
| 60 | LogAllExportThread *p = new LogAllExportThread(thread, "path"); |
| 61 | ASSERT_TRUE(p); |
| 62 | p->run(); |
| 63 | delete p; |
| 64 | } |
| 65 | |
| 66 | TEST(LogAllExportThread_slot_cancelExport_UT, LogAllExportThread_slot_cancelExport_UT_001) |
| 67 | { |
| 68 | QStringList thread; |
| 69 | thread << "test" << "test2"; |
| 70 | LogAllExportThread *p = new LogAllExportThread(thread, "path"); |
| 71 | ASSERT_TRUE(p); |
| 72 | p->slot_cancelExport(); |
| 73 | delete p; |
| 74 | } |