| 1 | // SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "../application/utils.h" |
| 6 | #include "ut_logViewerPlugin.h" |
| 7 | #include "../application/qtcompat.h" |
| 8 | |
| 9 | #include <stub.h> |
| 10 | |
| 11 | LogViewerPlugin_UT::LogViewerPlugin_UT() |
| 12 | { |
| 13 | |
| 14 | } |
| 15 | |
| 16 | void LogViewerPlugin_UT::SetUp() |
| 17 | { |
| 18 | m_instance = new LogViewerPlugin; |
| 19 | qDebug() << "SetUp" << ENDL; |
| 20 | } |
| 21 | |
| 22 | void LogViewerPlugin_UT::TearDown() |
| 23 | { |
| 24 | delete m_instance; |
| 25 | } |
| 26 | |
| 27 | void QThreadPool_start(QRunnable *runnable, int priority) |
| 28 | { |
| 29 | qDebug() << "QThreadPool_start--"; |
| 30 | } |
| 31 | |
| 32 | |
| 33 | void QThread_start(QThread::Priority) |
| 34 | { |
| 35 | qDebug() << "QThread_start--"; |
| 36 | } |
| 37 | |
| 38 | TEST_F(LogViewerPlugin_UT, generateAppFile_UT001) |
| 39 | { |
| 40 | Utils::sleep(200); |
| 41 | Stub stub; |
| 42 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), QThreadPool_start); |
| 43 | stub.set(ADDR(QThread, start), QThread_start); |
| 44 | |
| 45 | LogViewerPlugin *p = new LogViewerPlugin; |
| 46 | p->generateAppFile(Utils::homePath + "/.cache/deepin/deepin-log-viewer/deepin-log-viewer.log", ALL, INF, ""); |
| 47 | connect(p, &LogViewerPlugin::sigAppData, this, [=](int index, QList<LOG_MSG_APPLICATOIN> iList) { |
| 48 | qDebug() << "index:" << index << ENDL; |
| 49 | qDebug() << "appDatas:" << ENDL; |
| 50 | int listCount = iList.size(); |
| 51 | for (int i = 0; i < listCount; i++) { |
| 52 | qDebug() << "datetime=" << iList[i].dateTime |
| 53 | << " level=" << iList[i].level |
| 54 | << " src=" << iList[i].src |
| 55 | << " msg=" << iList[i].msg |
| 56 | << " detailInfo=" << iList[i].detailInfo << ENDL; |
| 57 | } |
| 58 | }); |
| 59 | connect(p, &LogViewerPlugin::sigAppFinished, p, &LogViewerPlugin::deleteLater); |
| 60 | } |
| 61 | |
| 62 | TEST_F(LogViewerPlugin_UT, exportLogFile_UT001) |
| 63 | { |
| 64 | Utils::sleep(200); |
| 65 | Stub stub; |
| 66 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), QThreadPool_start); |
| 67 | stub.set(ADDR(QThread, start), QThread_start); |
| 68 | |
| 69 | LogViewerPlugin *p = new LogViewerPlugin; |
| 70 | p->exportAppLogFile("/home/Desktop/test-plugin.txt", ALL, INF, "deepin-log-viewer"); |
| 71 | connect(p, &LogViewerPlugin::sigExportResult, p, &LogViewerPlugin::deleteLater); |
| 72 | } |
| 73 | |
| 74 | class LogViewerPlugin_generateAppFile_UT_Param |
| 75 | { |
| 76 | public: |
| 77 | explicit LogViewerPlugin_generateAppFile_UT_Param(BUTTONID id) |
| 78 | { |
| 79 | time = id; |
| 80 | } |
| 81 | BUTTONID time; |
| 82 | }; |
| 83 | |
| 84 | class LogViewerPlugin_generateAppFile_UT : public ::testing::TestWithParam<LogViewerPlugin_generateAppFile_UT_Param> |
| 85 | { |
| 86 | virtual void nothing();//消除编译警告 |
| 87 | }; |
| 88 | |
| 89 | void LogViewerPlugin_generateAppFile_UT::nothing(){} |
| 90 | |
| 91 | INSTANTIATE_TEST_CASE_P(LogViewerPlugin, LogViewerPlugin_generateAppFile_UT, |
| 92 | ::testing::Values(LogViewerPlugin_generateAppFile_UT_Param(ALL), LogViewerPlugin_generateAppFile_UT_Param(ONE_DAY), |
| 93 | LogViewerPlugin_generateAppFile_UT_Param(THREE_DAYS), LogViewerPlugin_generateAppFile_UT_Param(ONE_WEEK), |
| 94 | LogViewerPlugin_generateAppFile_UT_Param(ONE_MONTH), LogViewerPlugin_generateAppFile_UT_Param(THREE_MONTHS))); |
| 95 | |
| 96 | TEST_P(LogViewerPlugin_generateAppFile_UT, LogViewerPlugin_generateAppFile_UT_001) |
| 97 | { |
| 98 | Stub stub; |
| 99 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), QThreadPool_start); |
| 100 | stub.set(ADDR(QThread, start), QThread_start); |
| 101 | |
| 102 | LogViewerPlugin_generateAppFile_UT_Param param = GetParam(); |
| 103 | LogViewerPlugin *p = new LogViewerPlugin(); |
| 104 | EXPECT_NE(p, nullptr); |
| 105 | Utils::sleep(200); |
| 106 | p->generateAppFile("", param.time, INF, ""); |
| 107 | p->deleteLater(); |
| 108 | } |
| 109 | |
| 110 | //TEST_P(LogViewerPlugin_generateAppFile_UT, LogViewerPlugin_generateAppFile_UT_001) |
| 111 | //{ |
| 112 | // Stub stub; |
| 113 | // stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 114 | // stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 115 | // stub.set(ADDR(LogFileParser, parseByApp), LogFileParser_parseByApp); |
| 116 | // LogViewerPlugin_generateAppFile_UT_Param param = GetParam(); |
| 117 | // QPluginLoader loader("ProcessMultimeterD.dll"); |
| 118 | // if(loader.load()) |
| 119 | // { |
| 120 | // if(QObject * plugin = loader.instance()) |
| 121 | // { |
| 122 | // LogViewerPluginInterface *p = dynamic_cast<LogViewerPluginInterface *>(plugin); |
| 123 | // qDebug()<<p; |
| 124 | // p->generateAppFile("", param.time, 7, ""); |
| 125 | // } |
| 126 | // } |
| 127 | // else |
| 128 | // { |
| 129 | // qDebug()<<loader.errorString(); |
| 130 | // } |
| 131 | //} |
| 132 |