Debian Codegraph @

tests/src/ut_logauththread.cpp

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 #include "logauththread.h"
6 #include "structdef.h"
7 #include "sharedmemorymanager.h"
8 #include "wtmpparse.h"
9 #include "dldbushandler.h"
10 #include "qtcompat.h"
11
12 #include <stub.h>
13
14 #include <QDebug>
15 #include <QDateTime>
16
17 #include <gtest/gtest.h>
18 bool stub_isAttached()
19 {
20 return true;
21 }
22
23 bool stub_Logexists()
24 {
25 return true;
26 }
27
28 void stub_Logstart(const QString &program, const QStringList &arguments, QIODevice::OpenMode mode)
29 {
30 Q_UNUSED(program);
31 Q_UNUSED(arguments);
32 Q_UNUSED(mode);
33 }
34
35 bool stub_LogwaitForFinished(int msecs)
36 {
37 Q_UNUSED(msecs);
38 return true;
39 }
40
41 void stub_LogsetRunnableTag(ShareMemoryInfo iShareInfo)
42 {
43 Q_UNUSED(iShareInfo);
44 }
45
46 QByteArray stub_LogreadAllStandardOutput()
47 {
48 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";
49 }
50
51 QByteArray dmesgLogreadAllStandardOutput()
52 {
53 return "[101619.805280] snd_hda_codec_hdmi hdaudioC1D0: hda_codec_cleanup_stream: NID=0x8";
54 }
55
56 QByteArray stub_LogreadAllStandardError()
57 {
58 return "noerror";
59 }
60
61 void stub_wtmp_close(void)
62 {
63 }
64
65 QString stub_toString(QStringView format)
66 {
67 Q_UNUSED(format);
68 return "20190120";
69 }
70
71 void stub_setProcessChannelMode(QProcess::ProcessChannelMode mode)
72 {
73 Q_UNUSED(mode);
74 }
75
76 int stub_exitCode()
77 {
78 return 0;
79 }
80
81 QString stub_readLog(const QString &filePath)
82 {
83 Q_UNUSED(filePath);
84 return "2021-04-06 13:29:32 install code:amd64 <none> 1.55.0-1617120720";
85 }
86
87 QString stub_xorgReadLog(const QString &filePath)
88 {
89 Q_UNUSED(filePath);
90 return "[ 9.576 ] (II) Loading /usr/lib/xorg/modules/drivers/fbdev_drv.so";
91 }
92
93 QString stub_dnfReadLog(const QString &filePath)
94 {
95 Q_UNUSED(filePath);
96 return "2021-05-21T02:08:36Z DEBUG 加载插件:builddep, changelog, \nconfig-manager, copr, debug, debuginfo-install, download, \ngenerate_completion_cache, needs-restarting, playground, repoclosure, repodiff, repograph, repomanage, reposync";
97 }
98
99 QString stub_dnfReadStream(const QString &filePath)
100 {
101 Q_UNUSED(filePath);
102 static int i = 0;
103 QString result;
104 if(i % 2 == 0) {
105 result = "2021-05-21T02:08:36Z DEBUG 加载插件:builddep, changelog, \nconfig-manager, copr, debug, debuginfo-install, download, \ngenerate_completion_cache, needs-restarting, playground, repoclosure, repodiff, repograph, repomanage, reposync";
106 } else {
107 result = "";
108 }
109 ++i;
110 return result;
111 }
112
113 QString stub_BootReadLog(const QString &filePath)
114 {
115 Q_UNUSED(filePath);
116 return "[ 10.336791] rc.local[1655]: net.ipv4.tcp_max_syn_backlog = 2048";
117 }
118
119 QString stub_KernReadLog(const QString &filePath)
120 {
121 Q_UNUSED(filePath);
122 return "Aug 21 13:23:33 uos-PC deepin-deepinid-daemon[2946]: #033[33m[WAR] manager.go:218:#033[0m skip doSync";
123 }
124
125 QByteArray fileReadLine(qint64 maxlen = 0)
126 {
127 Q_UNUSED(maxlen);
128 return "211111";
129 }
130
131 qint64 dnfToMSecsSinceEpoch()
132 {
133 return 1999999999999999999;
134 }
135
136 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
137 int dmesgIndexIn(const QString &str, int offset = 0, QRegExp::CaretMode caretMode = QRegExp::CaretAtZero)
138 {
139 Q_UNUSED(caretMode);
140 Q_UNUSED(str);
141 Q_UNUSED(offset);
142 return 1;
143 }
144
145 QString &dmesgReplace(const REG_EXP &rx, const QString &after)
146 {
147 Q_UNUSED(rx);
148 Q_UNUSED(after);
149 static QString str = "[ 101619.805280 ] snd_hda_codec_hdmi hdaudioC1D0: hda_codec_cleanup_stream: NID=0x8";
150 return str;
151 }
152
153 QStringList dmesgCapturedTexts()
154 {
155 return QStringList() << "[ 101619.805280"
156 << "snd_hda_codec_"
157 << "ddd"
158 << "5555555"
159 << "test"
160 << "NID=0x8";
161 }
162 #endif
163
164 void handleFile()
165 {
166 }
167
168 class LogAuthThread_UT : public testing::Test
169 {
170 public:
171 //添加日志
172 static void SetUpTestCase()
173 {
174 qDebug() << "SetUpTestCase" << ENDL;
175 }
176 static void TearDownTestCase()
177 {
178 qDebug() << "TearDownTestCase" << ENDL;
179 }
180 void SetUp() //TEST跑之前会执行SetUp
181 {
182 m_logAuthThread = new LogAuthThread();
183 qDebug() << "SetUp" << ENDL;
184 }
185 void TearDown() //TEST跑完之后会执行TearDown
186 {
187 }
188 LogAuthThread *m_logAuthThread;
189 };
190
191 //TEST_F(LogAuthThread_UT, LogAuthThread_UT001)
192 //{
193 // Stub stub;
194 // typedef bool (QFile::*fptr)() const;
195 // fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
196 // stub.set(A_foo, stub_Logexists);
197
198 // stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
199 // stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
200 // stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
201 // stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
202 // stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput);
203 // stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
204 // stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
205 // stub.set(wtmp_close, stub_wtmp_close);
206 // stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
207 // stub.set(ADDR(QProcess, exitCode), stub_exitCode);
208 // stub.set(ADDR(DLDBusHandler, readLog), stub_readLog);
209
210 // m_logAuthThread->m_process.reset(new QProcess);
211 // m_logAuthThread->m_isStopProccess = true;
212 // m_logAuthThread->m_type = LOG_FLAG::KERN;
213 // m_logAuthThread->m_FilePath = QStringList() << "/var/log/kern.log";
214 // m_logAuthThread->run();
215 // m_logAuthThread->m_canRun = true;
216 // m_logAuthThread->m_type = LOG_FLAG::BOOT;
217 // m_logAuthThread->m_FilePath = QStringList() << "/var/log/boot.log";
218 // m_logAuthThread->handleBoot();
219 // m_logAuthThread->m_FilePath = QStringList() << "/test";
220 // m_logAuthThread->handleBoot();
221 // m_logAuthThread->m_type = LOG_FLAG::DPKG;
222 // m_logAuthThread->m_FilePath = QStringList() << "/var/log/dpkg.log";
223 // m_logAuthThread->handleDkpg();
224 // m_logAuthThread->m_FilePath = QStringList() << "/test";
225 // m_logAuthThread->handleDkpg();
226 // m_logAuthThread->m_type = LOG_FLAG::Normal;
227 // m_logAuthThread->handleNormal();
228 // m_logAuthThread->m_type = LOG_FLAG::Kwin;
229 // m_logAuthThread->handleKwin();
230
231
232
233
234 // m_logAuthThread->thread_count = 1;
235 // EXPECT_EQ(, 1);
236 //}
237
238 TEST_F(LogAuthThread_UT, UT_GetIndex_001){
239 int index=m_logAuthThread->getIndex();
240 EXPECT_EQ(index,1);
241 }
242
243 TEST_F(LogAuthThread_UT, UT_FormatDateTime_001){
244 qint64 timeMesc= m_logAuthThread->formatDateTime("2021", "08-30", "14:25");
245 qint64 timeMesc1= m_logAuthThread->formatDateTime("Aug 30" ,"19:04:43");
246 EXPECT_NE(timeMesc,-1);
247 EXPECT_NE(timeMesc1,-1);
248 }
249
250 TEST_F(LogAuthThread_UT, UT_SetFileterParam_001){
251 KWIN_FILTERS kwin;
252 m_logAuthThread->setFileterParam(kwin);
253 EXPECT_EQ(m_logAuthThread->m_kwinFilters.msg,kwin.msg);
254 KERN_FILTERS kern;
255 m_logAuthThread->setFileterParam(kern);
256 EXPECT_EQ(m_logAuthThread->m_kernFilters.timeFilterEnd,kern.timeFilterEnd);
257 DKPG_FILTERS dpkg;
258 m_logAuthThread->setFileterParam(dpkg);
259 EXPECT_EQ(m_logAuthThread->m_dkpgFilters.timeFilterEnd,dpkg.timeFilterEnd);
260 XORG_FILTERS xorg;
261 m_logAuthThread->setFileterParam(xorg);
262 EXPECT_EQ(m_logAuthThread->m_xorgFilters.timeFilterEnd,xorg.timeFilterEnd);
263 NORMAL_FILTERS normal;
264 m_logAuthThread->setFileterParam(normal);
265 EXPECT_EQ(m_logAuthThread->m_normalFilters.timeFilterEnd,normal.timeFilterEnd);
266 }
267
268 TEST_F(LogAuthThread_UT, UT_handleXorg_001)
269 {
270 Stub stub;
271 typedef bool (QFile::*fptr)() const;
272 fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
273 stub.set(A_foo, stub_Logexists);
274
275 stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
276 stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
277 stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
278 stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
279 stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput);
280 stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
281 stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
282 stub.set(wtmp_close, stub_wtmp_close);
283 stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
284 stub.set(ADDR(QProcess, exitCode), stub_exitCode);
285 stub.set(ADDR(DLDBusHandler, readLog), stub_xorgReadLog);
286 stub.set((QByteArray(QIODevice::*)(qint64))ADDR(QIODevice, readLine), fileReadLine);
287 m_logAuthThread->m_FilePath = QStringList() << "/test" << "/xorg.old";
288 m_logAuthThread->m_canRun=true;
289 m_logAuthThread->handleXorg();
290 EXPECT_NE(m_logAuthThread,nullptr);
291 EXPECT_EQ(m_logAuthThread->m_canRun,true);
292 }
293
294 TEST_F(LogAuthThread_UT, UT_HandleDnf_001)
295 {
296 Stub stub;
297 typedef bool (QFile::*fptr)() const;
298 fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
299 stub.set(A_foo, stub_Logexists);
300
301 stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
302 stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
303 stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
304 stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
305 stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput);
306 stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
307 stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
308 stub.set(wtmp_close, stub_wtmp_close);
309 stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
310 stub.set(ADDR(QProcess, exitCode), stub_exitCode);
311 stub.set(ADDR(DLDBusHandler, readLog), stub_dnfReadLog);
312 stub.set((QByteArray(QIODevice::*)(qint64))ADDR(QIODevice, readLine), fileReadLine);
313 stub.set(ADDR(QDateTime, toMSecsSinceEpoch), dnfToMSecsSinceEpoch);
314 m_logAuthThread->m_FilePath = QStringList() << "/test"
315 << "/xorg.old";
316 m_logAuthThread->m_dnfFilters.levelfilter = DNFPRIORITY::DNFLVALL;
317 m_logAuthThread->m_canRun=true;
318 m_logAuthThread->handleDnf();
319 EXPECT_NE(m_logAuthThread,nullptr);
320 EXPECT_EQ(m_logAuthThread->m_canRun,true);
321 }
322
323 TEST_F(LogAuthThread_UT, UT_HandleKern_001)
324 {
325 Stub stub;
326 typedef bool (QFile::*fptr)() const;
327 fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
328 stub.set(A_foo, stub_Logexists);
329
330 stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
331 stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
332 stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
333 stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
334 stub.set(ADDR(QProcess, readAllStandardOutput), dmesgLogreadAllStandardOutput);
335 stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
336 stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
337 stub.set(wtmp_close, stub_wtmp_close);
338 stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
339 stub.set(ADDR(QProcess, exitCode), stub_exitCode);
340 stub.set(ADDR(DLDBusHandler, openLogStream), stub_dnfReadLog);
341 stub.set(ADDR(DLDBusHandler, readLogInStream), stub_dnfReadStream);
342 stub.set((QByteArray(QIODevice::*)(qint64))ADDR(QIODevice, readLine), fileReadLine);
343 stub.set(ADDR(QDateTime, toMSecsSinceEpoch), dnfToMSecsSinceEpoch);
344
345 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
346 stub.set(ADDR(REG_EXP, indexIn), dmesgIndexIn);
347 stub.set((QStringList(REG_EXP::*)())ADDR(REG_EXP, capturedTexts), dmesgCapturedTexts);
348 stub.set((QString & (QString::*)(const REG_EXP &, const QString &)) ADDR(QString, replace), dmesgReplace);
349 #endif
350 m_logAuthThread->m_FilePath = QStringList() << "/test" << "/xorg.old";
351 m_logAuthThread->m_canRun=true;
352 m_logAuthThread->handleKern();
353 EXPECT_NE(m_logAuthThread,nullptr);
354 EXPECT_EQ(m_logAuthThread->m_canRun,true);
355 }
356
357
358
359 TEST_F(LogAuthThread_UT, UT_HandleDmesg_001)
360 {
361 Stub stub;
362 typedef bool (QFile::*fptr)() const;
363 fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
364 stub.set(A_foo, stub_Logexists);
365
366 stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
367 stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
368 stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
369 stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
370 stub.set(ADDR(QProcess, readAllStandardOutput), dmesgLogreadAllStandardOutput);
371 stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
372 stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
373 stub.set(wtmp_close, stub_wtmp_close);
374 stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
375 stub.set(ADDR(QProcess, exitCode), stub_exitCode);
376 stub.set(ADDR(DLDBusHandler, readLog), stub_KernReadLog);
377 stub.set((QByteArray(QIODevice::*)(qint64))ADDR(QIODevice, readLine), fileReadLine);
378 stub.set(ADDR(QDateTime, toMSecsSinceEpoch), dnfToMSecsSinceEpoch);
379 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
380 stub.set(ADDR(REG_EXP, indexIn), dmesgIndexIn);
381 stub.set((QString & (QString::*)(const REG_EXP &, const QString &)) ADDR(QString, replace), dmesgReplace);
382 stub.set((QStringList(REG_EXP::*)())ADDR(REG_EXP, capturedTexts), dmesgCapturedTexts);
383 #endif
384
385 m_logAuthThread->m_FilePath = QStringList() << "/test"<< "/xorg.old";
386 m_logAuthThread->m_canRun=true;
387 m_logAuthThread->handleDmesg();
388 EXPECT_NE(m_logAuthThread,nullptr);
389 EXPECT_EQ(m_logAuthThread->m_canRun,true);
390 }
391
392 TEST_F(LogAuthThread_UT, handleBoot_UT_001)
393 {
394 Stub stub;
395 typedef bool (QFile::*fptr)() const;
396 fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
397 stub.set(A_foo, stub_Logexists);
398
399 stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
400 stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
401 stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
402 stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
403 stub.set(ADDR(QProcess, readAllStandardOutput), dmesgLogreadAllStandardOutput);
404 stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
405 stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
406 stub.set(wtmp_close, stub_wtmp_close);
407 stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
408 stub.set(ADDR(QProcess, exitCode), stub_exitCode);
409 stub.set(ADDR(DLDBusHandler, readLog), stub_BootReadLog);
410 stub.set((QByteArray(QIODevice::*)(qint64))ADDR(QIODevice, readLine), fileReadLine);
411 stub.set(ADDR(QDateTime, toMSecsSinceEpoch), dnfToMSecsSinceEpoch);
412 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
413 stub.set(ADDR(REG_EXP, indexIn), dmesgIndexIn);
414 stub.set((QString & (QString::*)(const REG_EXP &, const QString &)) ADDR(QString, replace), dmesgReplace);
415 stub.set((QStringList(REG_EXP::*)())ADDR(REG_EXP, capturedTexts), dmesgCapturedTexts);
416 #endif
417 m_logAuthThread->m_FilePath = QStringList() << "/test"<< "/xorg.old";
418 m_logAuthThread->m_canRun=true;
419 m_logAuthThread->handleBoot();
420 EXPECT_NE(m_logAuthThread,nullptr);
421 EXPECT_EQ(m_logAuthThread->m_canRun,true);
422 }
423
424 TEST_F(LogAuthThread_UT, handleKwin_UT_001)
425 {
426 Stub stub;
427 typedef bool (QFile::*fptr)() const;
428 fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
429 stub.set(A_foo, stub_Logexists);
430
431 stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
432 stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
433 stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
434 stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
435 stub.set(ADDR(QProcess, readAllStandardOutput), dmesgLogreadAllStandardOutput);
436 stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
437 stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
438 stub.set(wtmp_close, stub_wtmp_close);
439 stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
440 stub.set(ADDR(QProcess, exitCode), stub_exitCode);
441 stub.set(ADDR(DLDBusHandler, readLog), stub_BootReadLog);
442 stub.set((QByteArray(QIODevice::*)(qint64))ADDR(QIODevice, readLine), fileReadLine);
443 stub.set(ADDR(QDateTime, toMSecsSinceEpoch), dnfToMSecsSinceEpoch);
444 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
445 stub.set(ADDR(REG_EXP, indexIn), dmesgIndexIn);
446 stub.set((QString & (QString::*)(const REG_EXP &, const QString &)) ADDR(QString, replace), dmesgReplace);
447 stub.set((QStringList(REG_EXP::*)())ADDR(REG_EXP, capturedTexts), dmesgCapturedTexts);
448 #endif
449 m_logAuthThread->m_FilePath = QStringList() << "/test"<< "/xorg.old";
450 m_logAuthThread->m_canRun=true;
451 m_logAuthThread->handleKwin();
452 EXPECT_NE(m_logAuthThread,nullptr);
453 EXPECT_EQ(m_logAuthThread->m_canRun,true);
454 }
455
456 TEST_F(LogAuthThread_UT, handleDpkg_UT_001)
457 {
458 Stub stub;
459 typedef bool (QFile::*fptr)() const;
460 fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
461 stub.set(A_foo, stub_Logexists);
462
463 stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
464 stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
465 stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
466 stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
467 stub.set(ADDR(QProcess, readAllStandardOutput), dmesgLogreadAllStandardOutput);
468 stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
469 stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
470 stub.set(wtmp_close, stub_wtmp_close);
471 stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
472 stub.set(ADDR(QProcess, exitCode), stub_exitCode);
473 stub.set(ADDR(DLDBusHandler, readLog), stub_BootReadLog);
474 stub.set((QByteArray(QIODevice::*)(qint64))ADDR(QIODevice, readLine), fileReadLine);
475 stub.set(ADDR(QDateTime, toMSecsSinceEpoch), dnfToMSecsSinceEpoch);
476 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
477 stub.set(ADDR(REG_EXP, indexIn), dmesgIndexIn);
478 stub.set((QString & (QString::*)(const REG_EXP &, const QString &)) ADDR(QString, replace), dmesgReplace);
479 stub.set((QStringList(REG_EXP::*)())ADDR(REG_EXP, capturedTexts), dmesgCapturedTexts);
480 #endif
481 m_logAuthThread->m_FilePath = QStringList() << "/test"<< "/xorg.old";
482 m_logAuthThread->m_canRun=true;
483 m_logAuthThread->handleDkpg();
484 EXPECT_NE(m_logAuthThread,nullptr);
485 EXPECT_EQ(m_logAuthThread->m_canRun,true);
486 }
487
488 TEST_F(LogAuthThread_UT, handleNormal_UT_001)
489 {
490 Stub stub;
491 typedef bool (QFile::*fptr)() const;
492 fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
493 stub.set(A_foo, stub_Logexists);
494
495 stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
496 stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
497 stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
498 stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
499 stub.set(ADDR(QProcess, readAllStandardOutput), dmesgLogreadAllStandardOutput);
500 stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
501 stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
502 stub.set(wtmp_close, stub_wtmp_close);
503 stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
504 stub.set(ADDR(QProcess, exitCode), stub_exitCode);
505 stub.set(ADDR(DLDBusHandler, readLog), stub_BootReadLog);
506 stub.set((QByteArray(QIODevice::*)(qint64))ADDR(QIODevice, readLine), fileReadLine);
507 stub.set(ADDR(QDateTime, toMSecsSinceEpoch), dnfToMSecsSinceEpoch);
508 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
509 stub.set(ADDR(REG_EXP, indexIn), dmesgIndexIn);
510 stub.set((QString & (QString::*)(const REG_EXP &, const QString &)) ADDR(QString, replace), dmesgReplace);
511 stub.set((QStringList(REG_EXP::*)())ADDR(REG_EXP, capturedTexts), dmesgCapturedTexts);
512 #endif
513 m_logAuthThread->m_FilePath = QStringList() << "/test"<< "/xorg.old";
514 m_logAuthThread->m_canRun=true;
515 m_logAuthThread->handleNormal();
516 EXPECT_NE(m_logAuthThread,nullptr);
517 EXPECT_EQ(m_logAuthThread->m_canRun,true);
518 }
519
520 TEST_F(LogAuthThread_UT, UT_Run_001)
521 {
522 Stub stub;
523 typedef bool (QFile::*fptr)() const;
524 fptr A_foo = (fptr)(&QFile::exists); //获取虚函数地址
525 stub.set(A_foo, stub_Logexists);
526
527 stub.set(ADDR(SharedMemoryManager, isAttached), stub_isAttached);
528 stub.set((void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode))ADDR(QProcess, start), stub_Logstart);
529 stub.set((QString(QDateTime::*)(QStringView) const)ADDR(QDateTime, toString), stub_toString);
530 stub.set(ADDR(QProcess, waitForFinished), stub_LogwaitForFinished);
531 stub.set(ADDR(QProcess, readAllStandardOutput), stub_LogreadAllStandardOutput);
532 stub.set(ADDR(QProcess, readAllStandardError), stub_LogreadAllStandardError);
533 stub.set(ADDR(SharedMemoryManager, setRunnableTag), stub_LogsetRunnableTag);
534 stub.set(wtmp_close, stub_wtmp_close);
535 stub.set(ADDR(QProcess, setProcessChannelMode), stub_setProcessChannelMode);
536 stub.set(ADDR(QProcess, exitCode), stub_exitCode);
537 stub.set(ADDR(DLDBusHandler, readLog), stub_readLog);
538 stub.set(ADDR(LogAuthThread, handleDkpg), handleFile);
539 stub.set(ADDR(LogAuthThread, handleNormal), handleFile);
540 stub.set(ADDR(LogAuthThread, handleDnf), handleFile);
541 stub.set(ADDR(LogAuthThread, handleDmesg), handleFile);
542 m_logAuthThread->m_type = LOG_FLAG::DPKG;
543 m_logAuthThread->run();
544 m_logAuthThread->m_type = LOG_FLAG::Normal;
545 m_logAuthThread->run();
546 m_logAuthThread->m_type = LOG_FLAG::Dnf;
547 m_logAuthThread->run();
548 m_logAuthThread->m_type = LOG_FLAG::Dmesg;
549 m_logAuthThread->run();
550 m_logAuthThread->m_type = LOG_FLAG::NONE;
551 m_logAuthThread->run();
552 EXPECT_NE(m_logAuthThread,nullptr);
553 EXPECT_EQ(m_logAuthThread->m_canRun,false);
554 }
555
556 TEST(LogAuthThread_initDnfLevelMap_UT, LogAuthThread_initDnfLevelMap_UT_001)
557 {
558 LogAuthThread *p = new LogAuthThread();
559 ASSERT_TRUE(p);
560 p->initDnfLevelMap();
561 EXPECT_TRUE(p->m_dnfLevelDict.size());
562 EXPECT_TRUE(p->m_transDnfDict.size());
563 delete p;
564 }
565
566 TEST(LogAuthThread_initLevelMap_UT, LogAuthThread_initLevelMap_UT_001)
567 {
568 LogAuthThread *p = new LogAuthThread();
569 ASSERT_TRUE(p);
570 p->initLevelMap();
571 EXPECT_TRUE(p->m_levelMap.size());
572 delete p;
573 }
574
575 TEST(LogAuthThread_stopProccess_UT, LogAuthThread_stopProccess_UT_001)
576 {
577 LogAuthThread *p = new LogAuthThread();
578 ASSERT_TRUE(p);
579 p->m_isStopProccess = false;
580 p->stopProccess();
581 EXPECT_TRUE(p->m_isStopProccess);
582 EXPECT_FALSE(p->m_canRun);
583 delete p;
584 }
585
586 TEST(LogAuthThread_setFilePath_UT, LogAuthThread_setFilePath_UT_001)
587 {
588 LogAuthThread *p = new LogAuthThread();
589 ASSERT_TRUE(p);
590 QStringList list;
591 list << "test" << "test2";
592 p->setFilePath(list);
593 EXPECT_EQ(p->m_FilePath, list);
594 delete p;
595 }
596
597 TEST(LogAuthThread_getIndex_UT, LogAuthThread_getIndex_UT_001)
598 {
599 LogAuthThread *p = new LogAuthThread();
600 ASSERT_TRUE(p);
601 p->m_threadCount = 0;
602 p->getIndex();
603 EXPECT_EQ(p->getIndex(), p->m_threadCount);
604 delete p;
605 }
606
607 TEST(LogAuthThread_startTime_UT, LogAuthThread_startTime_UT_001)
608 {
609 LogAuthThread *p = new LogAuthThread();
610 ASSERT_TRUE(p);
611 p->startTime();
612 delete p;
613 }
614
615 TEST(LogAuthThread_run_UT, LogAuthThread_run_UT_001)
616 {
617 LogAuthThread *p = new LogAuthThread();
618 ASSERT_TRUE(p);
619 p->m_type = LOG_FLAG::KERN;
620 Stub stub;
621 stub.set(ADDR(LogAuthThread, handleKern), handleFile);
622 p->run();
623 EXPECT_FALSE(p->m_canRun);
624 delete p;
625 }
626
627 TEST(LogAuthThread_run_UT, LogAuthThread_run_UT_002)
628 {
629 LogAuthThread *p = new LogAuthThread();
630 ASSERT_TRUE(p);
631 p->m_type = LOG_FLAG::BOOT;
632 Stub stub;
633 stub.set(ADDR(LogAuthThread, handleBoot), handleFile);
634 p->run();
635 EXPECT_FALSE(p->m_canRun);
636 delete p;
637 }
638
639 TEST(LogAuthThread_run_UT, LogAuthThread_run_UT_003)
640 {
641 LogAuthThread *p = new LogAuthThread();
642 ASSERT_TRUE(p);
643 p->m_type = LOG_FLAG::Kwin;
644 Stub stub;
645 stub.set(ADDR(LogAuthThread, handleKwin), handleFile);
646 p->run();
647 EXPECT_FALSE(p->m_canRun);
648 delete p;
649 }
650
651 TEST(LogAuthThread_run_UT, LogAuthThread_run_UT_004)
652 {
653 LogAuthThread *p = new LogAuthThread();
654 ASSERT_TRUE(p);
655 p->m_type = LOG_FLAG::XORG;
656 Stub stub;
657 stub.set(ADDR(LogAuthThread, handleXorg), handleFile);
658 p->run();
659 EXPECT_FALSE(p->m_canRun);
660 delete p;
661 }
662
663 TEST(LogAuthThread_run_UT, LogAuthThread_run_UT_005)
664 {
665 LogAuthThread *p = new LogAuthThread();
666 ASSERT_TRUE(p);
667 p->m_type = LOG_FLAG::DPKG;
668 Stub stub;
669 stub.set(ADDR(LogAuthThread, handleDkpg), handleFile);
670 p->run();
671 EXPECT_FALSE(p->m_canRun);
672 delete p;
673 }
674
675 TEST(LogAuthThread_run_UT, LogAuthThread_run_UT_006)
676 {
677 LogAuthThread *p = new LogAuthThread();
678 ASSERT_TRUE(p);
679 p->m_type = LOG_FLAG::Normal;
680 Stub stub;
681 stub.set(ADDR(LogAuthThread, handleNormal), handleFile);
682 p->run();
683 EXPECT_FALSE(p->m_canRun);
684 delete p;
685 }
686
687 TEST(LogAuthThread_run_UT, LogAuthThread_run_UT_007)
688 {
689 LogAuthThread *p = new LogAuthThread();
690 ASSERT_TRUE(p);
691 p->m_type = LOG_FLAG::Dnf;
692 Stub stub;
693 stub.set(ADDR(LogAuthThread, handleDnf), handleFile);
694 p->run();
695 EXPECT_FALSE(p->m_canRun);
696 delete p;
697 }
698
699 TEST(LogAuthThread_run_UT, LogAuthThread_run_UT_008)
700 {
701 LogAuthThread *p = new LogAuthThread();
702 ASSERT_TRUE(p);
703 p->m_type = LOG_FLAG::Dmesg;
704 Stub stub;
705 stub.set(ADDR(LogAuthThread, handleDmesg), handleFile);
706 p->run();
707 EXPECT_FALSE(p->m_canRun);
708 delete p;
709 }
710
711
712