| 1 | // SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "logoocfileparsethread.h" |
| 6 | #include "logfileparser.h" |
| 7 | #include "structdef.h" |
| 8 | #include "dbusproxy/dldbushandler.h" |
| 9 | #include "ut_stubpublic.h" |
| 10 | #include "../../application/qtcompat.h" |
| 11 | |
| 12 | #include <stub.h> |
| 13 | |
| 14 | #include <QDebug> |
| 15 | #include <QDir> |
| 16 | #include <QFileInfo> |
| 17 | |
| 18 | #include <gtest/gtest.h> |
| 19 | |
| 20 | QStringList stub_getOtherFileInfo(const QString &flag) |
| 21 | { |
| 22 | Q_UNUSED(flag); |
| 23 | return QStringList() << "test"; |
| 24 | } |
| 25 | |
| 26 | class LogOOCFileParseThread_UT : public testing::Test |
| 27 | { |
| 28 | public: |
| 29 | //添加日志 |
| 30 | static void SetUpTestCase() |
| 31 | { |
| 32 | qDebug() << "SetUpTestCase" << ENDL; |
| 33 | } |
| 34 | static void TearDownTestCase() |
| 35 | { |
| 36 | qDebug() << "TearDownTestCase" << ENDL; |
| 37 | } |
| 38 | void SetUp()//TEST跑之前会执行SetUp |
| 39 | { |
| 40 | m_logThread = new LogOOCFileParseThread(); |
| 41 | qDebug() << "SetUp" << ENDL; |
| 42 | } |
| 43 | void TearDown() //TEST跑完之后会执行TearDown |
| 44 | { |
| 45 | delete m_logThread; |
| 46 | } |
| 47 | LogOOCFileParseThread *m_logThread; |
| 48 | }; |
| 49 | |
| 50 | QString stub_ooc_readLog(const QString &filePath) |
| 51 | { |
| 52 | Q_UNUSED(filePath); |
| 53 | return "2021-04-06 13:29:32 install code:amd64 <none> 1.55.0-1617120720"; |
| 54 | } |
| 55 | |
| 56 | TEST_F(LogOOCFileParseThread_UT, UT_InitProccess_001){ |
| 57 | m_logThread->initProccess(); |
| 58 | EXPECT_EQ(m_logThread->getProcess().isNull(), false); |
| 59 | } |
| 60 | |
| 61 | TEST_F(LogOOCFileParseThread_UT, UT_getProcess_001){ |
| 62 | m_logThread->getProcess(); |
| 63 | } |
| 64 | |
| 65 | TEST_F(LogOOCFileParseThread_UT, UT_SetParam_001){ |
| 66 | QString path("test"); |
| 67 | m_logThread->setParam(path); |
| 68 | EXPECT_EQ(m_logThread->getPath(), path); |
| 69 | } |
| 70 | |
| 71 | TEST_F(LogOOCFileParseThread_UT, UT_getPath_001){ |
| 72 | m_logThread->getPath(); |
| 73 | } |
| 74 | |
| 75 | TEST_F(LogOOCFileParseThread_UT, UT_DoWork_001) |
| 76 | { |
| 77 | Stub stub; |
| 78 | stub.set(ADDR(DLDBusHandler, readLog), stub_ooc_readLog); |
| 79 | stub.set(ADDR(DLDBusHandler, getOtherFileInfo), stub_getOtherFileInfo); |
| 80 | QString path("test"); |
| 81 | m_logThread->setParam(path); |
| 82 | m_logThread->doWork(); |
| 83 | EXPECT_EQ(m_logThread->getFileData().length(),stub_ooc_readLog("").length()); |
| 84 | } |
| 85 | |
| 86 | TEST_F(LogOOCFileParseThread_UT, UT_getFileData) |
| 87 | { |
| 88 | m_logThread->getFileData(); |
| 89 | } |
| 90 | |
| 91 | TEST_F(LogOOCFileParseThread_UT, UT_stopProcess) |
| 92 | { |
| 93 | m_logThread->stopProccess(); |
| 94 | EXPECT_EQ(m_logThread->getProcess().isNull(), true); |
| 95 | } |
| 96 | |
| 97 | TEST_F(LogOOCFileParseThread_UT, UT_GetIndex_001){ |
| 98 | m_logThread->getIndex(); |
| 99 | } |
| 100 | |
| 101 | TEST_F(LogOOCFileParseThread_UT, UT_checkAuthentication_001){ |
| 102 | m_logThread->checkAuthentication("test"); |
| 103 | } |