| 1 | // SPDX-FileCopyrightText: 2019-2026 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "logfileparser.h" |
| 6 | #include "ut_stuballthread.h" |
| 7 | #include "logauththread.h" |
| 8 | #include "structdef.h" |
| 9 | #include "sharedmemorymanager.h" |
| 10 | #include "wtmpparse.h" |
| 11 | #include "../../application/qtcompat.h" |
| 12 | |
| 13 | #include <stub.h> |
| 14 | |
| 15 | #include <QDebug> |
| 16 | #include <QMessageBox> |
| 17 | #include <QThreadPool> |
| 18 | #include <QDateTime> |
| 19 | |
| 20 | #include <gtest/gtest.h> |
| 21 | |
| 22 | bool stub_isAttached001() |
| 23 | { |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | bool stub_Logexists001() |
| 28 | { |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | void stub_Logstart001(const QString &program, const QStringList &arguments, QIODevice::OpenMode mode) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | bool stub_LogwaitForFinished001(int msecs) |
| 37 | { |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | void stub_LogsetRunnableTag001(ShareMemoryInfo iShareInfo) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | QByteArray stub_LogreadAllStandardOutput001() |
| 46 | { |
| 47 | return "2020-11-24 01:57:24 startup archives install \n2020-11-24 01:57:24 install base-passwd:amd64 <none> 3.5.46\n 2021-01-09, 17:04:10.721 [Debug ] [ 0] onTermGetFocus 2"; |
| 48 | } |
| 49 | |
| 50 | QByteArray stub_LogreadAllStandardError001() |
| 51 | { |
| 52 | return "noerror"; |
| 53 | } |
| 54 | |
| 55 | void stub_wtmp_close001(void) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | QString stub_toString001(QStringView format) |
| 60 | { |
| 61 | Q_UNUSED(format); |
| 62 | return "20190120"; |
| 63 | } |
| 64 | |
| 65 | void stub_start001(QRunnable *runnable, int priority = 0) |
| 66 | { |
| 67 | Q_UNUSED(runnable); |
| 68 | Q_UNUSED(priority); |
| 69 | } |
| 70 | |
| 71 | TEST(LogFileParser_Constructor_UT, LogFileParser_Constructor_UT) |
| 72 | { |
| 73 | Stub stub; |
| 74 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 75 | LogFileParser *p = new LogFileParser(nullptr); |
| 76 | EXPECT_NE(p, nullptr); |
| 77 | p->deleteLater(); |
| 78 | } |
| 79 | |
| 80 | TEST(LogFileParser_Destructor_UT, LogFileParser_Destructor_UT) |
| 81 | { |
| 82 | Stub stub; |
| 83 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 84 | LogFileParser *p = new LogFileParser(nullptr); |
| 85 | EXPECT_NE(p, nullptr); |
| 86 | delete p; |
| 87 | } |
| 88 | |
| 89 | //TEST(LogFileParser_parseByJournalBoot_UT, LogFileParser_parseByJournalBoot_UT) |
| 90 | //{ |
| 91 | // Stub stub; |
| 92 | // stub.set(ADDR(QThreadPool, start), QThreadPool_start); |
| 93 | // stub.set(ADDR(QThread, start), QThread_start); |
| 94 | // LogFileParser *p = new LogFileParser(nullptr); |
| 95 | // EXPECT_NE(p, nullptr); |
| 96 | // p->parseByJournalBoot(QStringList() << "test"); |
| 97 | // p->deleteLater(); |
| 98 | //} |
| 99 | |
| 100 | |
| 101 | TEST(LogFileParser_stopAllLoad_UT, LogFileParser_stopAllLoad_UT) |
| 102 | { |
| 103 | Stub stub; |
| 104 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 105 | LogFileParser *p = new LogFileParser(nullptr); |
| 106 | EXPECT_NE(p, nullptr); |
| 107 | p->stopAllLoad(); |
| 108 | p->deleteLater(); |
| 109 | } |
| 110 | |
| 111 | TEST(LogFileParser_quitLogAuththread_UT, LogFileParser_quitLogAuththread_UT_001) |
| 112 | { |
| 113 | Stub stub; |
| 114 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 115 | LogFileParser *p = new LogFileParser(nullptr); |
| 116 | EXPECT_NE(p, nullptr); |
| 117 | p->quitLogAuththread(nullptr); |
| 118 | p->deleteLater(); |
| 119 | } |
| 120 | |
| 121 | TEST(LogFileParser_quitLogAuththread_UT, LogFileParser_quitLogAuththread_UT_002) |
| 122 | { |
| 123 | Stub stub; |
| 124 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 125 | LogFileParser *p = new LogFileParser(nullptr); |
| 126 | EXPECT_NE(p, nullptr); |
| 127 | QThread *thread = new QThread; |
| 128 | thread->start(); |
| 129 | p->quitLogAuththread(thread); |
| 130 | EXPECT_EQ(thread->isRunning(), false); |
| 131 | thread->deleteLater(); |
| 132 | p->deleteLater(); |
| 133 | } |
| 134 | |
| 135 | QMessageBox::StandardButton LogFileParser_slog_proccessError_UT_DMessageBox_information(QWidget *parent, const QString &title, |
| 136 | const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, |
| 137 | QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) |
| 138 | { |
| 139 | qDebug() << "info-------"; |
| 140 | return QMessageBox::NoButton; |
| 141 | } |
| 142 | TEST(LogFileParser_slog_proccessError_UT, LogFileParser_slog_proccessError_UT) |
| 143 | { |
| 144 | LogFileParser *p = new LogFileParser(nullptr); |
| 145 | EXPECT_NE(p, nullptr); |
| 146 | typedef QMessageBox::StandardButton (*fptr)(QWidget *, |
| 147 | const QString &, const QString &, QMessageBox::StandardButtons, |
| 148 | QMessageBox::StandardButton); |
| 149 | fptr p_func = (fptr)(&QMessageBox::information); |
| 150 | Stub stub; |
| 151 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 152 | stub.set(p_func, LogFileParser_slog_proccessError_UT_DMessageBox_information); |
| 153 | p->slog_proccessError(QString("testError")); |
| 154 | p->deleteLater(); |
| 155 | } |
| 156 | |
| 157 | void stubfileparser_setProcessChannelMode(QProcess::ProcessChannelMode mode) |
| 158 | { |
| 159 | } |
| 160 | |
| 161 | int stubfileparser_exitCode() |
| 162 | { |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | QStringList stubfileparser_getFileInfo(const QString &flag) |
| 167 | { |
| 168 | return QStringList() << "kern.log"; |
| 169 | } |
| 170 | |
| 171 | QString stub_FilereadLog(const QString &filePath) |
| 172 | { |
| 173 | Q_UNUSED(filePath); |
| 174 | return "2021-04-06 13:29:32 install code:amd64 <none> 1.55.0-1617120720"; |
| 175 | } |
| 176 | |
| 177 | class LogFileParser_UT : public testing::Test |
| 178 | { |
| 179 | public: |
| 180 | void SetUp() //TEST跑之前会执行SetUp |
| 181 | { |
| 182 | m_parser = new LogFileParser(); |
| 183 | qDebug() << "SetUp" << ENDL; |
| 184 | } |
| 185 | void TearDown() //TEST跑完之后会执行TearDown |
| 186 | { |
| 187 | delete m_parser; |
| 188 | } |
| 189 | LogFileParser *m_parser; |
| 190 | }; |
| 191 | |
| 192 | //TEST_F(LogFileParser_UT, sLogFileParser_UT001) |
| 193 | //{ |
| 194 | // Stub stub; |
| 195 | // typedef bool (QFile::*fptr)() const; |
| 196 | // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 197 | // stub.set(A_foo, stub_Logexists001); |
| 198 | // stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 199 | // stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 200 | // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 201 | // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 202 | // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 203 | // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 204 | // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 205 | // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 206 | // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 207 | // stub.set(ADDR(DLDBusHandler, getFileInfo), stubfileparser_getFileInfo); |
| 208 | // stub.set(wtmp_close, stub_wtmp_close001); |
| 209 | // stub.set(ADDR(DLDBusHandler, readLog), stub_FilereadLog); |
| 210 | // struct KWIN_FILTERS fitler = {"test"}; |
| 211 | // stub.set(ADDR(QThreadPool, start), stub_start001); |
| 212 | // int index=m_parser->parseByKwin(fitler); |
| 213 | // EXPECT_EQ(index,2)<<"check the status after LogFileParser()"; |
| 214 | // struct KERN_FILTERS kern_fitler; |
| 215 | // int index1=m_parser->parseByKern(kern_fitler); |
| 216 | // EXPECT_EQ(index1,3)<<"check the status after LogFileParser()"; |
| 217 | // struct DKPG_FILTERS dkpg_fitler; |
| 218 | // int index2=m_parser->parseByDpkg(dkpg_fitler); |
| 219 | // EXPECT_EQ(index2,4)<<"check the status after LogFileParser()"; EXPECT_EQ(index,2)<<"check the status after LogFileParser()"; |
| 220 | // struct BOOT_FILTERS boot_fitler; |
| 221 | // int index3=m_parser->parseByBoot(); |
| 222 | // EXPECT_EQ(index3,5)<<"check the status after LogFileParser()"; |
| 223 | //} |
| 224 | |
| 225 | //TEST_F(LogFileParser_UT, UT_ParseByKwin){ |
| 226 | // Stub stub; |
| 227 | // typedef bool (QFile::*fptr)() const; |
| 228 | // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 229 | // stub.set(A_foo, stub_Logexists001); |
| 230 | // stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 231 | // stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 232 | // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 233 | // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 234 | // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 235 | // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 236 | // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 237 | // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 238 | // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 239 | // stub.set(wtmp_close, stub_wtmp_close001); |
| 240 | // stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 241 | // struct KWIN_FILTERS fitler = {"test"}; |
| 242 | // int index=m_parser->parseByKwin(fitler); |
| 243 | // EXPECT_EQ(index,2)<<"check the status after LogFileParser()"; |
| 244 | //} |
| 245 | |
| 246 | //TEST_F(LogFileParser_UT, UT_ParseByKern){ |
| 247 | // Stub stub; |
| 248 | // typedef bool (QFile::*fptr)() const; |
| 249 | // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 250 | // stub.set(A_foo, stub_Logexists001); |
| 251 | // stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 252 | // stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 253 | // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 254 | // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 255 | // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 256 | // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 257 | // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 258 | // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 259 | // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 260 | // stub.set(ADDR(DLDBusHandler, getFileInfo), stubfileparser_getFileInfo); |
| 261 | // stub.set(wtmp_close, stub_wtmp_close001); |
| 262 | // stub.set(ADDR(DLDBusHandler, readLog), stub_FilereadLog); |
| 263 | // stub.set(ADDR(QThreadPool, start), stub_start001); |
| 264 | // struct DKPG_FILTERS dkpg_fitler; |
| 265 | // int index2=m_parser->parseByDpkg(dkpg_fitler); |
| 266 | // EXPECT_EQ(index2,3)<<"check the status after LogFileParser()"; |
| 267 | //} |
| 268 | |
| 269 | |
| 270 | //TEST_F(LogFileParser_UT, UT_ParseByBoot){ |
| 271 | // Stub stub; |
| 272 | // typedef bool (QFile::*fptr)() const; |
| 273 | // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 274 | // stub.set(A_foo, stub_Logexists001); |
| 275 | // stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 276 | // stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 277 | // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 278 | // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 279 | // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 280 | // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 281 | // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 282 | // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 283 | // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 284 | // stub.set(ADDR(DLDBusHandler, getFileInfo), stubfileparser_getFileInfo); |
| 285 | // stub.set(wtmp_close, stub_wtmp_close001); |
| 286 | // stub.set(ADDR(DLDBusHandler, readLog), stub_FilereadLog); |
| 287 | // stub.set(ADDR(QThreadPool, start), stub_start001); |
| 288 | // struct BOOT_FILTERS boot_fitler; |
| 289 | // int index3=m_parser->parseByBoot(); |
| 290 | // EXPECT_EQ(index3,4)<<"check the status after LogFileParser()"; |
| 291 | //} |
| 292 | |
| 293 | //TEST_F(LogFileParser_UT, UT_ParseByDpkg){ |
| 294 | // Stub stub; |
| 295 | // typedef bool (QFile::*fptr)() const; |
| 296 | // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 297 | // stub.set(A_foo, stub_Logexists001); |
| 298 | // stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 299 | // stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 300 | // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 301 | // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 302 | // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 303 | // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 304 | // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 305 | // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 306 | // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 307 | // stub.set(wtmp_close, stub_wtmp_close001); |
| 308 | // stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 309 | // struct DKPG_FILTERS dpkg_fitler; |
| 310 | // int index1=m_parser->parseByDpkg(dpkg_fitler); |
| 311 | //// EXPECT_EQ(index1,5)<<"check the status after LogFileParser()"; |
| 312 | //} |
| 313 | |
| 314 | |
| 315 | //TEST_F(LogFileParser_UT, UT_ParseByDnf) |
| 316 | //{ |
| 317 | // Stub stub; |
| 318 | // typedef bool (QFile::*fptr)() const; |
| 319 | // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 320 | // stub.set(A_foo, stub_Logexists001); |
| 321 | // stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 322 | // stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 323 | // stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 324 | // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 325 | // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 326 | // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 327 | // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 328 | // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 329 | // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 330 | // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 331 | // stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 332 | // stub.set(wtmp_close, stub_wtmp_close001); |
| 333 | // DNF_FILTERS dnfFilter = {10000, DNFPRIORITY::DEBUG}; |
| 334 | // m_parser->parseByDnf(dnfFilter); |
| 335 | // EXPECT_NE(m_parser,nullptr); |
| 336 | //} |
| 337 | |
| 338 | //TEST_F(LogFileParser_UT, UT_ParseByXorg) |
| 339 | //{ |
| 340 | // Stub stub; |
| 341 | // typedef bool (QFile::*fptr)() const; |
| 342 | // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 343 | // stub.set(A_foo, stub_Logexists001); |
| 344 | // stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 345 | // stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 346 | |
| 347 | // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 348 | // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 349 | // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 350 | // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 351 | // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 352 | // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 353 | // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 354 | // stub.set(ADDR(DLDBusHandler, getFileInfo), stubfileparser_getFileInfo); |
| 355 | // stub.set(ADDR(QThreadPool, start), stub_start001); |
| 356 | // stub.set(wtmp_close, stub_wtmp_close001); |
| 357 | // stub.set(ADDR(DLDBusHandler, readLog), stub_FilereadLog); |
| 358 | // XORG_FILTERS xorgFilter; |
| 359 | // m_parser->parseByXlog(xorgFilter); |
| 360 | // EXPECT_NE(m_parser,nullptr); |
| 361 | //} |
| 362 | |
| 363 | //TEST_F(LogFileParser_UT, UT_ParseByNormal) |
| 364 | //{ |
| 365 | // Stub stub; |
| 366 | // typedef bool (QFile::*fptr)() const; |
| 367 | // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 368 | // stub.set(A_foo, stub_Logexists001); |
| 369 | // stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 370 | // stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 371 | |
| 372 | // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 373 | // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 374 | // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 375 | // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 376 | // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 377 | // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 378 | // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 379 | // stub.set(ADDR(DLDBusHandler, getFileInfo), stubfileparser_getFileInfo); |
| 380 | // stub.set(ADDR(QThreadPool, start), stub_start001); |
| 381 | // stub.set(wtmp_close, stub_wtmp_close001); |
| 382 | // stub.set(ADDR(DLDBusHandler, readLog), stub_FilereadLog); |
| 383 | // NORMAL_FILTERS normalFilter; |
| 384 | // m_parser->parseByNormal(normalFilter); |
| 385 | // EXPECT_NE(m_parser,nullptr); |
| 386 | //} |
| 387 | |
| 388 | //TEST_F(LogFileParser_UT, UT_ParseByApp) |
| 389 | //{ |
| 390 | // Stub stub; |
| 391 | // typedef bool (QFile::*fptr)() const; |
| 392 | // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 393 | // stub.set(A_foo, stub_Logexists001); |
| 394 | // stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 395 | // stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 396 | |
| 397 | // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 398 | // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 399 | // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 400 | // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 401 | // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 402 | // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 403 | // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 404 | // stub.set(ADDR(DLDBusHandler, getFileInfo), stubfileparser_getFileInfo); |
| 405 | // stub.set(ADDR(QThreadPool, start), stub_start001); |
| 406 | // stub.set(wtmp_close, stub_wtmp_close001); |
| 407 | // stub.set(ADDR(DLDBusHandler, readLog), stub_FilereadLog); |
| 408 | // APP_FILTERS appFilter; |
| 409 | // appFilter.path="test"; |
| 410 | // appFilter.lvlFilter=1; |
| 411 | // m_parser->parseByApp(appFilter); |
| 412 | // EXPECT_NE(m_parser,nullptr); |
| 413 | //} |
| 414 | |
| 415 | TEST_F(LogFileParser_UT, UT_ParseByJournal_001) |
| 416 | { |
| 417 | Stub stub; |
| 418 | typedef bool (QFile::*fptr)() const; |
| 419 | fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 420 | stub.set(A_foo, stub_Logexists001); |
| 421 | stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 422 | stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 423 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 424 | stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 425 | stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 426 | stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 427 | stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 428 | stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 429 | stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 430 | stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 431 | stub.set(wtmp_close, stub_wtmp_close001); |
| 432 | m_parser->parseByJournal(); |
| 433 | } |
| 434 | |
| 435 | TEST_F(LogFileParser_UT, UT_parseByJournalBoot_001) |
| 436 | { |
| 437 | Stub stub; |
| 438 | typedef bool (QFile::*fptr)() const; |
| 439 | fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 440 | stub.set(A_foo, stub_Logexists001); |
| 441 | stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 442 | stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 443 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start001); |
| 444 | stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 445 | stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 446 | stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 447 | stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 448 | stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 449 | stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 450 | stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 451 | stub.set(wtmp_close, stub_wtmp_close001); |
| 452 | int index=m_parser->parseByJournalBoot(); |
| 453 | qInfo()<<index; |
| 454 | } |
| 455 | |
| 456 | TEST_F(LogFileParser_UT, UT_parseByOOC_001) |
| 457 | { |
| 458 | Stub stub; |
| 459 | typedef bool (QFile::*fptr)() const; |
| 460 | fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址 |
| 461 | stub.set(A_foo, stub_Logexists001); |
| 462 | stub.set(ADDR(QProcess, setProcessChannelMode), stubfileparser_setProcessChannelMode); |
| 463 | stub.set(ADDR(QProcess, exitCode), stubfileparser_exitCode); |
| 464 | stub.set(ADDR(QThread, start), QThread_start); |
| 465 | stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached001); |
| 466 | stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart001); |
| 467 | stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString001); |
| 468 | stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished001); |
| 469 | stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput001); |
| 470 | stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError001); |
| 471 | stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag001); |
| 472 | stub.set(wtmp_close, stub_wtmp_close001); |
| 473 | QString path("test"); |
| 474 | m_parser->parseByOOC(path); |
| 475 | } |