| 1 | // SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "ut_displaycontent.h" |
| 6 | #include "../application/displaycontent.h" |
| 7 | #include "../application/exportprogressdlg.h" |
| 8 | #include "../application/utils.h" |
| 9 | #include "../logbackend.h" |
| 10 | #include "../application/logexportthread.h" |
| 11 | #include "ut_stuballthread.h" |
| 12 | #include "../application/DebugTimeManager.h" |
| 13 | #include "../application/logtreeview.h" |
| 14 | #include "ut_stubpublic.h" |
| 15 | |
| 16 | #include <stub.h> |
| 17 | |
| 18 | #include <DApplication> |
| 19 | |
| 20 | #include <QDebug> |
| 21 | #include <QFileDialog> |
| 22 | #include <QPaintEvent> |
| 23 | #include <QDBusAbstractInterfaceBase> |
| 24 | #include <QStandardPaths> |
| 25 | #include <QMenu> |
| 26 | #include <QAction> |
| 27 | |
| 28 | class DisplayContentlx_UT : public testing::Test |
| 29 | { |
| 30 | public: |
| 31 | void SetUp() //TEST跑之前会执行SetUp |
| 32 | { |
| 33 | m_content = new DisplayContent; |
| 34 | qDebug() << "SetUp" << ENDL; |
| 35 | } |
| 36 | void TearDown() //TEST跑完之后会执行TearDown |
| 37 | { |
| 38 | delete m_content; |
| 39 | } |
| 40 | DisplayContent *m_content; |
| 41 | }; |
| 42 | |
| 43 | QString stub_writableLocation(QStandardPaths::StandardLocation type) |
| 44 | { |
| 45 | Q_UNUSED(type); |
| 46 | return "test"; |
| 47 | } |
| 48 | |
| 49 | QString stub_getSaveDocFileName(QWidget *parent = nullptr, |
| 50 | const QString &caption = QString(), |
| 51 | const QString &dir = QString(), |
| 52 | const QString &filter = QString(), |
| 53 | QString *selectedFilter = nullptr, |
| 54 | QFileDialog::Options options = QFileDialog::Options()) |
| 55 | { |
| 56 | Q_UNUSED(parent); |
| 57 | Q_UNUSED(caption); |
| 58 | Q_UNUSED(dir); |
| 59 | Q_UNUSED(filter); |
| 60 | Q_UNUSED(selectedFilter); |
| 61 | Q_UNUSED(options); |
| 62 | return "/home/Desktop/test.doc"; |
| 63 | } |
| 64 | |
| 65 | QString stub_getSaveTxtFileName(QWidget *parent = nullptr, |
| 66 | const QString &caption = QString(), |
| 67 | const QString &dir = QString(), |
| 68 | const QString &filter = QString(), |
| 69 | QString *selectedFilter = nullptr, |
| 70 | QFileDialog::Options options = QFileDialog::Options()) |
| 71 | { |
| 72 | Q_UNUSED(parent); |
| 73 | Q_UNUSED(caption); |
| 74 | Q_UNUSED(dir); |
| 75 | Q_UNUSED(filter); |
| 76 | Q_UNUSED(selectedFilter); |
| 77 | Q_UNUSED(options); |
| 78 | return "/home/Desktop/test.txt"; |
| 79 | } |
| 80 | |
| 81 | QString stub_getSaveXlsFileName(QWidget *parent = nullptr, |
| 82 | const QString &caption = QString(), |
| 83 | const QString &dir = QString(), |
| 84 | const QString &filter = QString(), |
| 85 | QString *selectedFilter = nullptr, |
| 86 | QFileDialog::Options options = QFileDialog::Options()) |
| 87 | { |
| 88 | Q_UNUSED(parent); |
| 89 | Q_UNUSED(caption); |
| 90 | Q_UNUSED(dir); |
| 91 | Q_UNUSED(filter); |
| 92 | Q_UNUSED(selectedFilter); |
| 93 | Q_UNUSED(options); |
| 94 | return "/home/Desktop/test.xls"; |
| 95 | } |
| 96 | |
| 97 | QString stub_getSaveHtmlFileName(QWidget *parent = nullptr, |
| 98 | const QString &caption = QString(), |
| 99 | const QString &dir = QString(), |
| 100 | const QString &filter = QString(), |
| 101 | QString *selectedFilter = nullptr, |
| 102 | QFileDialog::Options options = QFileDialog::Options()) |
| 103 | { |
| 104 | Q_UNUSED(parent); |
| 105 | Q_UNUSED(caption); |
| 106 | Q_UNUSED(dir); |
| 107 | Q_UNUSED(filter); |
| 108 | Q_UNUSED(selectedFilter); |
| 109 | Q_UNUSED(options); |
| 110 | return "/home/Desktop/test.html"; |
| 111 | } |
| 112 | |
| 113 | int stub_singleRowHeight() |
| 114 | { |
| 115 | return 1; |
| 116 | } |
| 117 | |
| 118 | void stub_start(QRunnable *runnable, int priority = 0) |
| 119 | { |
| 120 | Q_UNUSED(runnable); |
| 121 | Q_UNUSED(priority); |
| 122 | } |
| 123 | |
| 124 | void parseDnfNull(DNF_FILTERS iDnfFilter) |
| 125 | { |
| 126 | Q_UNUSED(iDnfFilter); |
| 127 | } |
| 128 | |
| 129 | void parseDmesgNull(DMESG_FILTERS iDmesgFilter) |
| 130 | { |
| 131 | Q_UNUSED(iDmesgFilter); |
| 132 | } |
| 133 | |
| 134 | void generateAppFileNull(QString path, int id, int lId, const QString &iSearchStr) |
| 135 | { |
| 136 | Q_UNUSED(path); |
| 137 | Q_UNUSED(id); |
| 138 | Q_UNUSED(lId); |
| 139 | Q_UNUSED(iSearchStr); |
| 140 | } |
| 141 | |
| 142 | qint64 stub_msecsTo(const QDateTime &){ |
| 143 | return 200; |
| 144 | } |
| 145 | |
| 146 | void stub_generateDnfFile(BUTTONID iDate, DNFPRIORITY iLevel){ |
| 147 | Q_UNUSED(iDate); |
| 148 | Q_UNUSED(iLevel); |
| 149 | } |
| 150 | |
| 151 | QString stub_getReplaceColorStr_bootwork(const char *d) |
| 152 | { |
| 153 | return "testaaaa"; |
| 154 | } |
| 155 | |
| 156 | void stub_jounalWorkRun(){ |
| 157 | |
| 158 | } |
| 159 | |
| 160 | TEST_F(DisplayContentlx_UT, exportClicked_UT) |
| 161 | { |
| 162 | Stub stub; |
| 163 | m_content->selectFilter = "TEXT (*.txt)"; |
| 164 | stub.set(ADDR(QStandardPaths, writableLocation), stub_writableLocation); |
| 165 | stub.set(ADDR(QFileDialog, getSaveFileName), stub_getSaveTxtFileName); |
| 166 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start); |
| 167 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 168 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 169 | m_content->m_flag = LOG_FLAG::BOOT; |
| 170 | m_content->slot_exportClicked(); |
| 171 | m_content->m_flag = LOG_FLAG::APP; |
| 172 | m_content->slot_exportClicked(); |
| 173 | m_content->m_flag = LOG_FLAG::KERN; |
| 174 | m_content->slot_exportClicked(); |
| 175 | m_content->m_flag = LOG_FLAG::JOURNAL; |
| 176 | m_content->slot_exportClicked(); |
| 177 | m_content->m_flag = LOG_FLAG::XORG; |
| 178 | m_content->slot_exportClicked(); |
| 179 | m_content->m_flag = LOG_FLAG::DPKG; |
| 180 | m_content->slot_exportClicked(); |
| 181 | m_content->m_flag = LOG_FLAG::Normal; |
| 182 | m_content->slot_exportClicked(); |
| 183 | m_content->m_flag = LOG_FLAG::Kwin; |
| 184 | m_content->slot_exportClicked(); |
| 185 | m_content->m_flag = LOG_FLAG::NONE; |
| 186 | m_content->slot_exportClicked(); |
| 187 | m_content->m_flag = LOG_FLAG::Dnf; |
| 188 | m_content->slot_exportClicked(); |
| 189 | m_content->m_flag = LOG_FLAG::Dmesg; |
| 190 | m_content->slot_exportClicked(); |
| 191 | EXPECT_EQ(m_content->selectFilter, "TEXT (*.txt)")<<"check the status after slot_exportClicked()"; |
| 192 | EXPECT_NE(m_content, nullptr)<<"check the status after slot_exportClicked()"; |
| 193 | EXPECT_NE(m_content->m_exportDlg, nullptr)<<"check the status after slot_exportClicked()"; |
| 194 | |
| 195 | |
| 196 | } |
| 197 | |
| 198 | TEST_F(DisplayContentlx_UT, exportClicked_UT001) |
| 199 | { |
| 200 | Stub stub; |
| 201 | m_content->selectFilter = "Html (*.html)"; |
| 202 | stub.set(ADDR(QStandardPaths, writableLocation), stub_writableLocation); |
| 203 | stub.set(ADDR(QFileDialog, getSaveFileName), stub_getSaveHtmlFileName); |
| 204 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start); |
| 205 | m_content->m_flag = LOG_FLAG::BOOT; |
| 206 | m_content->slot_exportClicked(); |
| 207 | m_content->m_flag = LOG_FLAG::APP; |
| 208 | m_content->slot_exportClicked(); |
| 209 | m_content->m_flag = LOG_FLAG::KERN; |
| 210 | m_content->slot_exportClicked(); |
| 211 | m_content->m_flag = LOG_FLAG::JOURNAL; |
| 212 | m_content->slot_exportClicked(); |
| 213 | m_content->m_flag = LOG_FLAG::XORG; |
| 214 | m_content->slot_exportClicked(); |
| 215 | m_content->m_flag = LOG_FLAG::DPKG; |
| 216 | m_content->slot_exportClicked(); |
| 217 | m_content->m_flag = LOG_FLAG::Normal; |
| 218 | m_content->slot_exportClicked(); |
| 219 | m_content->m_flag = LOG_FLAG::Kwin; |
| 220 | m_content->slot_exportClicked(); |
| 221 | m_content->m_flag = LOG_FLAG::NONE; |
| 222 | m_content->slot_exportClicked(); |
| 223 | m_content->m_flag = LOG_FLAG::Dnf; |
| 224 | m_content->slot_exportClicked(); |
| 225 | m_content->m_flag = LOG_FLAG::Dmesg; |
| 226 | m_content->slot_exportClicked(); |
| 227 | EXPECT_EQ(m_content->selectFilter, "Html (*.html)")<<"check the status after slot_exportClicked()"; |
| 228 | EXPECT_NE(m_content, nullptr)<<"check the status after slot_exportClicked()"; |
| 229 | EXPECT_NE(m_content->m_exportDlg, nullptr)<<"check the status after slot_exportClicked()"; |
| 230 | } |
| 231 | |
| 232 | TEST_F(DisplayContentlx_UT, exportClicked_UT002) |
| 233 | { |
| 234 | Stub stub; |
| 235 | m_content->selectFilter = "Doc (*.doc)"; |
| 236 | stub.set(ADDR(QStandardPaths, writableLocation), stub_writableLocation); |
| 237 | stub.set(ADDR(QFileDialog, getSaveFileName), stub_getSaveDocFileName); |
| 238 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start); |
| 239 | m_content->m_flag = LOG_FLAG::BOOT; |
| 240 | m_content->slot_exportClicked(); |
| 241 | m_content->m_flag = LOG_FLAG::APP; |
| 242 | m_content->slot_exportClicked(); |
| 243 | m_content->m_flag = LOG_FLAG::KERN; |
| 244 | m_content->slot_exportClicked(); |
| 245 | m_content->m_flag = LOG_FLAG::JOURNAL; |
| 246 | m_content->slot_exportClicked(); |
| 247 | m_content->m_flag = LOG_FLAG::XORG; |
| 248 | m_content->slot_exportClicked(); |
| 249 | m_content->m_flag = LOG_FLAG::DPKG; |
| 250 | m_content->slot_exportClicked(); |
| 251 | m_content->m_flag = LOG_FLAG::Normal; |
| 252 | m_content->slot_exportClicked(); |
| 253 | m_content->m_flag = LOG_FLAG::Kwin; |
| 254 | m_content->slot_exportClicked(); |
| 255 | m_content->m_flag = LOG_FLAG::NONE; |
| 256 | m_content->slot_exportClicked(); |
| 257 | m_content->m_flag = LOG_FLAG::Dnf; |
| 258 | m_content->slot_exportClicked(); |
| 259 | m_content->m_flag = LOG_FLAG::Dmesg; |
| 260 | m_content->slot_exportClicked(); |
| 261 | EXPECT_EQ(m_content->selectFilter, "Doc (*.doc)")<<"check the status after slot_exportClicked()"; |
| 262 | EXPECT_NE(m_content, nullptr)<<"check the status after slot_exportClicked()"; |
| 263 | EXPECT_NE(m_content->m_exportDlg, nullptr)<<"check the status after slot_exportClicked()"; |
| 264 | } |
| 265 | |
| 266 | TEST_F(DisplayContentlx_UT, exportClicked_UT003) |
| 267 | { |
| 268 | Stub stub; |
| 269 | m_content->selectFilter = "Xls (*.xls)"; |
| 270 | stub.set(ADDR(QStandardPaths, writableLocation), stub_writableLocation); |
| 271 | stub.set(ADDR(QFileDialog, getSaveFileName), stub_getSaveXlsFileName); |
| 272 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), stub_start); |
| 273 | m_content->m_flag = LOG_FLAG::BOOT; |
| 274 | m_content->slot_exportClicked(); |
| 275 | m_content->m_flag = LOG_FLAG::APP; |
| 276 | m_content->slot_exportClicked(); |
| 277 | m_content->m_flag = LOG_FLAG::KERN; |
| 278 | m_content->slot_exportClicked(); |
| 279 | m_content->m_flag = LOG_FLAG::JOURNAL; |
| 280 | m_content->slot_exportClicked(); |
| 281 | m_content->m_flag = LOG_FLAG::XORG; |
| 282 | m_content->slot_exportClicked(); |
| 283 | m_content->m_flag = LOG_FLAG::DPKG; |
| 284 | m_content->slot_exportClicked(); |
| 285 | m_content->m_flag = LOG_FLAG::Normal; |
| 286 | m_content->slot_exportClicked(); |
| 287 | m_content->m_flag = LOG_FLAG::Kwin; |
| 288 | m_content->slot_exportClicked(); |
| 289 | m_content->m_flag = LOG_FLAG::NONE; |
| 290 | m_content->slot_exportClicked(); |
| 291 | m_content->m_flag = LOG_FLAG::Dnf; |
| 292 | m_content->slot_exportClicked(); |
| 293 | m_content->m_flag = LOG_FLAG::Dmesg; |
| 294 | m_content->slot_exportClicked(); |
| 295 | EXPECT_EQ(m_content->selectFilter, "Xls (*.xls)")<<"check the status after slot_exportClicked()"; |
| 296 | EXPECT_NE(m_content, nullptr)<<"check the status after slot_exportClicked()"; |
| 297 | EXPECT_NE(m_content->m_exportDlg, nullptr)<<"check the status after slot_exportClicked()"; |
| 298 | } |
| 299 | |
| 300 | TEST_F(DisplayContentlx_UT, ScrollValueChanged_UT) |
| 301 | { |
| 302 | Stub stub; |
| 303 | m_content->m_flag = LOG_FLAG::JOURNAL; |
| 304 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 305 | m_content->slot_vScrollValueChanged(275); |
| 306 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 307 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 308 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 309 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::JOURNAL)<<"check the status after slot_vScrollValueChanged()"; |
| 310 | } |
| 311 | |
| 312 | TEST_F(DisplayContentlx_UT, ScrollValueChanged_UT002) |
| 313 | { |
| 314 | Stub stub; |
| 315 | m_content->m_flag = LOG_FLAG::BOOT; |
| 316 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 317 | m_content->slot_vScrollValueChanged(275); |
| 318 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 319 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 320 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 321 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::BOOT)<<"check the status after slot_vScrollValueChanged()"; |
| 322 | } |
| 323 | |
| 324 | TEST_F(DisplayContentlx_UT, ScrollValueChanged_UT003) |
| 325 | { |
| 326 | Stub stub; |
| 327 | m_content->m_flag = LOG_FLAG::BOOT_KLU; |
| 328 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 329 | m_content->slot_vScrollValueChanged(275); |
| 330 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 331 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 332 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 333 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::BOOT_KLU)<<"check the status after slot_vScrollValueChanged()"; |
| 334 | } |
| 335 | |
| 336 | TEST_F(DisplayContentlx_UT, ScrollValueChanged_UT005) |
| 337 | { |
| 338 | Stub stub; |
| 339 | m_content->m_flag = LOG_FLAG::APP; |
| 340 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 341 | m_content->slot_vScrollValueChanged(275); |
| 342 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 343 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 344 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 345 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::APP)<<"check the status after slot_vScrollValueChanged()"; |
| 346 | } |
| 347 | |
| 348 | TEST_F(DisplayContentlx_UT, ScrollValueChanged_UT006) |
| 349 | { |
| 350 | Stub stub; |
| 351 | m_content->m_flag = LOG_FLAG::XORG; |
| 352 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 353 | m_content->slot_vScrollValueChanged(275); |
| 354 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 355 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 356 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 357 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::XORG)<<"check the status after slot_vScrollValueChanged()"; |
| 358 | } |
| 359 | |
| 360 | TEST_F(DisplayContentlx_UT, ScrollValueChanged_UT007) |
| 361 | { |
| 362 | Stub stub; |
| 363 | m_content->m_flag = LOG_FLAG::KERN; |
| 364 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 365 | m_content->slot_vScrollValueChanged(275); |
| 366 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 367 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 368 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 369 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::KERN)<<"check the status after slot_vScrollValueChanged()"; |
| 370 | } |
| 371 | |
| 372 | TEST_F(DisplayContentlx_UT, DmesgScrollValueChanged_UT) |
| 373 | { |
| 374 | Stub stub; |
| 375 | m_content->m_flag = LOG_FLAG::Dmesg; |
| 376 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 377 | m_content->slot_vScrollValueChanged(275); |
| 378 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 379 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 380 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 381 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Dmesg)<<"check the status after slot_vScrollValueChanged()"; |
| 382 | } |
| 383 | |
| 384 | TEST_F(DisplayContentlx_UT, DnfScrollValueChanged_UT) |
| 385 | { |
| 386 | Stub stub; |
| 387 | m_content->m_flag = LOG_FLAG::Dnf; |
| 388 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 389 | m_content->slot_vScrollValueChanged(275); |
| 390 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 391 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 392 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 393 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Dnf)<<"check the status after slot_vScrollValueChanged()"; |
| 394 | } |
| 395 | |
| 396 | TEST_F(DisplayContentlx_UT, NormalScrollValueChanged_UT) |
| 397 | { |
| 398 | Stub stub; |
| 399 | m_content->m_flag = LOG_FLAG::Normal; |
| 400 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 401 | m_content->slot_vScrollValueChanged(275); |
| 402 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 403 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 404 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 405 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Normal)<<"check the status after slot_vScrollValueChanged()"; |
| 406 | } |
| 407 | |
| 408 | TEST_F(DisplayContentlx_UT, KwinScrollValueChanged_UT) |
| 409 | { |
| 410 | Stub stub; |
| 411 | m_content->m_flag = LOG_FLAG::Kwin; |
| 412 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 413 | m_content->slot_vScrollValueChanged(275); |
| 414 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 415 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 416 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 417 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Kwin)<<"check the status after slot_vScrollValueChanged()"; |
| 418 | } |
| 419 | |
| 420 | TEST_F(DisplayContentlx_UT, ScrollValueChanged_UT008) |
| 421 | { |
| 422 | Stub stub; |
| 423 | m_content->m_flag = LOG_FLAG::DPKG; |
| 424 | stub.set(ADDR(LogTreeView, singleRowHeight), stub_singleRowHeight); |
| 425 | m_content->slot_vScrollValueChanged(275); |
| 426 | EXPECT_NE(m_content->m_treeView,nullptr)<<"check the status after slot_vScrollValueChanged()"; |
| 427 | EXPECT_EQ(m_content->m_treeViewLastScrollValue, 275)<<"check the status after slot_vScrollValueChanged()"; |
| 428 | EXPECT_EQ(m_content->m_limitTag, 1)<<"check the status after slot_vScrollValueChanged()"; |
| 429 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::DPKG)<<"check the status after slot_vScrollValueChanged()"; |
| 430 | } |
| 431 | |
| 432 | TEST_F(DisplayContentlx_UT, FileParse_UT) |
| 433 | { |
| 434 | DisplayContent *p = new DisplayContent(nullptr); |
| 435 | QList<LOG_MSG_DNF> list; |
| 436 | QStandardItemModel m_model; |
| 437 | p->parseListToModel(list, &m_model); |
| 438 | QList<LOG_MSG_DMESG> m_list; |
| 439 | p->parseListToModel(m_list, &m_model); |
| 440 | QList<LOG_MSG_BOOT> m_list1; |
| 441 | p->parseListToModel(m_list, &m_model); |
| 442 | EXPECT_NE(p, nullptr); |
| 443 | EXPECT_NE(p->m_transDict.count(),0)<<"check the status after parseListToModel()"; |
| 444 | EXPECT_NE(p->m_iconPrefix.count(),0)<<"check the status after parseListToModel()"; |
| 445 | EXPECT_NE(p->m_dnfIconNameMap.count(),0)<<"check the status after parseListToModel()"; |
| 446 | p->deleteLater(); |
| 447 | } |
| 448 | |
| 449 | TEST_F(DisplayContentlx_UT, generateDnfFile_UT) |
| 450 | { |
| 451 | Stub stub; |
| 452 | stub.set(ADDR(LogFileParser, parseByDnf), parseDnfNull); |
| 453 | m_content->generateDnfFile(BUTTONID::ALL, DNFPRIORITY::DEBUG); |
| 454 | m_content->generateDnfFile(BUTTONID::ONE_DAY, DNFPRIORITY::DEBUG); |
| 455 | m_content->generateDnfFile(BUTTONID::THREE_DAYS, DNFPRIORITY::DEBUG); |
| 456 | m_content->generateDnfFile(BUTTONID::ONE_WEEK, DNFPRIORITY::DEBUG); |
| 457 | m_content->generateDnfFile(BUTTONID::ONE_MONTH, DNFPRIORITY::DEBUG); |
| 458 | m_content->generateDnfFile(BUTTONID::THREE_MONTHS, DNFPRIORITY::DEBUG); |
| 459 | m_content->generateDnfFile(BUTTONID::INVALID, DNFPRIORITY::DEBUG); |
| 460 | EXPECT_NE(m_content, nullptr); |
| 461 | } |
| 462 | |
| 463 | |
| 464 | TEST_F(DisplayContentlx_UT, generateJournalFile_UT) |
| 465 | { |
| 466 | Stub stub; |
| 467 | stub.set(ADDR(LogFileParser, parseByDnf), parseDnfNull); |
| 468 | stub.set(ADDR(QDateTime,msecsTo),stub_msecsTo); |
| 469 | m_content->m_journalFilter.timeFilter=0; |
| 470 | m_content->m_journalFilter.eventTypeFilter=0; |
| 471 | m_content->generateJournalFile(0,0,"" ); |
| 472 | EXPECT_NE(strlen(m_content->m_lastJournalGetTime.toString().toLatin1()),0)<<"check the status after generateJournalFile()"; |
| 473 | EXPECT_EQ(m_content->m_journalFilter.timeFilter, 0)<<"check the status after generateJournalFile()"; |
| 474 | EXPECT_EQ(m_content->m_journalFilter.eventTypeFilter, 0)<<"check the status after generateJournalFile()"; |
| 475 | } |
| 476 | |
| 477 | TEST_F(DisplayContentlx_UT, createDnfTable_UT) |
| 478 | { |
| 479 | QList<LOG_MSG_DNF> dnfList; |
| 480 | LOG_MSG_DNF dnfLog = {"2021-05-21", "DEBUG", "DNF version: 4.2.23"}; |
| 481 | dnfList.push_back(dnfLog); |
| 482 | m_content->createDnfTable(dnfList); |
| 483 | EXPECT_EQ(m_content->m_limitTag, 0)<<"check the status after createDnfTable()"; |
| 484 | EXPECT_NE(m_content->m_pModel, nullptr)<<"check the status after createDnfTable()"; |
| 485 | } |
| 486 | |
| 487 | TEST_F(DisplayContentlx_UT, generateDmesgFile_UT) |
| 488 | { |
| 489 | Stub stub; |
| 490 | stub.set(ADDR(LogFileParser, parseByDmesg), parseDmesgNull); |
| 491 | m_content->generateDmesgFile(BUTTONID::ALL, PRIORITY::ERR); |
| 492 | m_content->generateDmesgFile(BUTTONID::ONE_DAY, PRIORITY::ERR); |
| 493 | m_content->generateDmesgFile(BUTTONID::THREE_DAYS, PRIORITY::ERR); |
| 494 | m_content->generateDmesgFile(BUTTONID::ONE_WEEK, PRIORITY::ERR); |
| 495 | m_content->generateDmesgFile(BUTTONID::ONE_MONTH, PRIORITY::ERR); |
| 496 | m_content->generateDmesgFile(BUTTONID::THREE_MONTHS, PRIORITY::ERR); |
| 497 | m_content->generateDmesgFile(BUTTONID::INVALID, PRIORITY::ERR); |
| 498 | EXPECT_NE(m_content, nullptr); |
| 499 | } |
| 500 | |
| 501 | TEST_F(DisplayContentlx_UT, createDmesgTable_UT) |
| 502 | { |
| 503 | QList<LOG_MSG_DMESG> dmesgList; |
| 504 | LOG_MSG_DMESG dmesgLog = {"ERR", "2021-05-21", "DNF version: 4.2.23"}; |
| 505 | dmesgList.push_back(dmesgLog); |
| 506 | m_content->createDmesgTable(dmesgList); |
| 507 | EXPECT_EQ(m_content->m_limitTag, 0)<<"check the status after createDmesgTable()"; |
| 508 | EXPECT_NE(m_content->m_pModel, nullptr)<<"check the status after createDmesgTable()"; |
| 509 | } |
| 510 | |
| 511 | TEST_F(DisplayContentlx_UT, createDnfForm_UT) |
| 512 | { |
| 513 | m_content->createDnfForm(); |
| 514 | EXPECT_NE(m_content->m_pModel, nullptr)<<"check the status after createDnfForm()"; |
| 515 | EXPECT_EQ(m_content->m_pModel->rowCount(), 0)<<"check the status after createDnfForm()"; |
| 516 | } |
| 517 | |
| 518 | TEST_F(DisplayContentlx_UT, insertDmesgTable_UT) |
| 519 | { |
| 520 | QList<LOG_MSG_DMESG> dmesgList; |
| 521 | LOG_MSG_DMESG dmesgLog = {"ERR", "2021-05-21", "DNF version: 4.2.23"}; |
| 522 | dmesgList.push_back(dmesgLog); |
| 523 | m_content->insertDmesgTable(dmesgList, -1, -1); |
| 524 | EXPECT_NE(m_content, nullptr); |
| 525 | } |
| 526 | |
| 527 | TEST_F(DisplayContentlx_UT, insertDnfTable_UT) |
| 528 | { |
| 529 | QList<LOG_MSG_DNF> dnfList; |
| 530 | LOG_MSG_DNF dnfLog = {"2021-05-21", "DEBUG", "DNF version: 4.2.23"}; |
| 531 | dnfList.push_back(dnfLog); |
| 532 | m_content->insertDnfTable(dnfList, -1, -1); |
| 533 | EXPECT_NE(m_content, nullptr); |
| 534 | } |
| 535 | |
| 536 | TEST_F(DisplayContentlx_UT, slot_tableItemClicked_UT) |
| 537 | { |
| 538 | m_content->slot_tableItemClicked(QModelIndex()); |
| 539 | EXPECT_NE(m_content, nullptr); |
| 540 | EXPECT_EQ(m_content->m_pModel->rowCount(), 0)<<"check the status after slot_tableItemClicked()"; |
| 541 | } |
| 542 | |
| 543 | TEST_F(DisplayContentlx_UT, slot_appLogs_UT) |
| 544 | { |
| 545 | Stub stub; |
| 546 | stub.set(ADDR(DisplayContent, generateAppFile), generateAppFileNull); |
| 547 | m_content->slot_appLogs(1, "~/.cache/deepin/deepin-log-viewer/deepin-log-viewer.log"); |
| 548 | EXPECT_NE(m_content, nullptr); |
| 549 | EXPECT_EQ(m_content->m_pLogBackend->appList.size(), 0)<<"check the status after slot_appLogs()"; |
| 550 | EXPECT_EQ(m_content->m_curBtnId, 1)<<"check the status after slot_appLogs()"; |
| 551 | EXPECT_EQ(m_content->m_curApp,"deepin-log-viewer")<<"check the status after slot_appLogs()"; |
| 552 | } |
| 553 | |
| 554 | TEST_F(DisplayContentlx_UT, slot_dpkgData_UT) |
| 555 | { |
| 556 | QList<LOG_MSG_DPKG> dpkgList; |
| 557 | LOG_MSG_DPKG dpkgLog = {"2021-05-21", "DEBUG", "DNF version: 4.2.23"}; |
| 558 | dpkgList.push_back(dpkgLog); |
| 559 | m_content->m_flag = LOG_FLAG::DPKG; |
| 560 | m_content->m_firstLoadPageData = true; |
| 561 | m_content->slot_dpkgData(dpkgList); |
| 562 | EXPECT_NE(m_content->m_pLogBackend->dListOrigin.size(), 0)<<"check the status after slot_dpkgData()"; |
| 563 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::DPKG)<<"check the status after slot_dpkgData()"; |
| 564 | } |
| 565 | |
| 566 | TEST_F(DisplayContentlx_UT, slot_XorgFinished_UT) |
| 567 | { |
| 568 | m_content->m_flag = LOG_FLAG::XORG; |
| 569 | m_content->m_firstLoadPageData = true; |
| 570 | m_content->slot_XorgFinished(); |
| 571 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::XORG)<<"check the status after slot_XorgFinished()"; |
| 572 | EXPECT_EQ(m_content->m_isDataLoadComplete, true)<<"check the status after slot_XorgFinished()"; |
| 573 | } |
| 574 | |
| 575 | TEST_F(DisplayContentlx_UT, slot_kernData_UT) |
| 576 | { |
| 577 | QList<LOG_MSG_JOURNAL> kernList; |
| 578 | LOG_MSG_JOURNAL kernLog = {"2021-05-21", "UOS", "dde-daemon", "1122", "DEBUG", "DNF version: 4.2.23"}; |
| 579 | kernList.push_back(kernLog); |
| 580 | m_content->m_flag = LOG_FLAG::KERN; |
| 581 | m_content->m_firstLoadPageData = true; |
| 582 | m_content->slot_kernData(kernList); |
| 583 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::KERN)<<"check the status after slot_kernData()"; |
| 584 | EXPECT_NE(m_content->m_pLogBackend->kListOrigin.size(),0)<<"check the status after slot_kernData()"; |
| 585 | } |
| 586 | |
| 587 | TEST_F(DisplayContentlx_UT, slot_kwinData_UT) |
| 588 | { |
| 589 | QList<LOG_MSG_KWIN> kwinList; |
| 590 | LOG_MSG_KWIN kwinLog = {"DNF version: 4.2.23"}; |
| 591 | kwinList.push_back(kwinLog); |
| 592 | m_content->m_flag = LOG_FLAG::Kwin; |
| 593 | m_content->m_firstLoadPageData = true; |
| 594 | m_content->slot_kwinData(kwinList); |
| 595 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Kwin)<<"check the status after slot_kwinData()"; |
| 596 | EXPECT_NE(m_content->m_pLogBackend->m_kwinList.size(),0)<<"check the status after slot_kwinData()"; |
| 597 | } |
| 598 | |
| 599 | TEST_F(DisplayContentlx_UT, slot_bootData_UT) |
| 600 | { |
| 601 | QList<LOG_MSG_BOOT> bootList; |
| 602 | LOG_MSG_BOOT bootLog = {"ok", "DNF version: 4.2.23"}; |
| 603 | bootList.push_back(bootLog); |
| 604 | m_content->m_flag = LOG_FLAG::BOOT; |
| 605 | m_content->m_firstLoadPageData = true; |
| 606 | m_content->slot_bootData(bootList); |
| 607 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::BOOT)<<"check the status after slot_bootData()"; |
| 608 | EXPECT_NE(m_content->m_pLogBackend->bList.size(), 0)<<"check the status after slot_bootData()"; |
| 609 | } |
| 610 | |
| 611 | TEST_F(DisplayContentlx_UT, slot_journalFinished_UT) |
| 612 | { |
| 613 | m_content->m_flag = LOG_FLAG::JOURNAL; |
| 614 | m_content->m_firstLoadPageData = true; |
| 615 | m_content->slot_journalFinished(); |
| 616 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::JOURNAL)<<"check the status after slot_journalFinished()"; |
| 617 | EXPECT_EQ(m_content->m_isDataLoadComplete, true)<<"check the status after slot_journalFinished()"; |
| 618 | } |
| 619 | |
| 620 | TEST_F(DisplayContentlx_UT, slot_dnfFinished_UT) |
| 621 | { |
| 622 | QList<LOG_MSG_DNF> dnfList; |
| 623 | LOG_MSG_DNF dnfLog = {"ok", "DEBUG", "DNF version: 4.2.23"}; |
| 624 | dnfList.push_back(dnfLog); |
| 625 | m_content->m_flag = LOG_FLAG::Dnf; |
| 626 | m_content->m_firstLoadPageData = true; |
| 627 | m_content->slot_dnfFinished(dnfList); |
| 628 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Dnf)<<"check the status after slot_dnfFinished()"; |
| 629 | EXPECT_EQ(m_content->m_pLogBackend->dnfList.size(), 1)<<"check the status after slot_dnfFinished()"; |
| 630 | } |
| 631 | |
| 632 | TEST_F(DisplayContentlx_UT, slot_dmesgFinished_UT) |
| 633 | { |
| 634 | QList<LOG_MSG_DMESG> dmesgList; |
| 635 | LOG_MSG_DMESG dmesgLog = {"DEBUG", "ok", "DNF version: 4.2.23"}; |
| 636 | dmesgList.push_back(dmesgLog); |
| 637 | m_content->m_flag = LOG_FLAG::Dmesg; |
| 638 | m_content->m_firstLoadPageData = true; |
| 639 | m_content->slot_dmesgFinished(dmesgList); |
| 640 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Dmesg)<<"check the status after slot_dmesgFinished()"; |
| 641 | EXPECT_EQ(m_content->m_pLogBackend->dmesgList.size(), 1)<<"check the status after slot_dmesgFinished()"; |
| 642 | } |
| 643 | |
| 644 | TEST_F(DisplayContentlx_UT, slot_normalFinished_UT) |
| 645 | { |
| 646 | m_content->m_flag = LOG_FLAG::Normal; |
| 647 | m_content->m_firstLoadPageData = true; |
| 648 | m_content->slot_normalFinished(); |
| 649 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Normal)<<"check the status after slot_normalFinished()"; |
| 650 | EXPECT_EQ(m_content->m_pLogBackend->nortempList.size(), 0)<<"check the status after slot_normalFinished()"; |
| 651 | } |
| 652 | |
| 653 | TEST_F(DisplayContentlx_UT, slot_searchResult_UT) |
| 654 | { |
| 655 | m_content->m_flag = LOG_FLAG::Dmesg; |
| 656 | m_content->slot_searchResult("test"); |
| 657 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Dmesg)<<"check the status after slot_searchResult()"; |
| 658 | m_content->m_flag = LOG_FLAG::Dnf; |
| 659 | m_content->slot_searchResult("test"); |
| 660 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::Dnf)<<"check the status after slot_searchResult()"; |
| 661 | m_content->m_flag = LOG_FLAG::NONE; |
| 662 | m_content->slot_searchResult("test"); |
| 663 | EXPECT_EQ(m_content->m_flag, LOG_FLAG::NONE)<<"check the status after slot_searchResult()"; |
| 664 | EXPECT_EQ(m_content->m_pLogBackend->m_currentSearchStr, "test")<<"check the status after slot_searchResult()"; |
| 665 | } |
| 666 | |
| 667 | TEST_F(DisplayContentlx_UT, slot_BtnSelected_UT) |
| 668 | { |
| 669 | Stub stub; |
| 670 | stub.set(ADDR(DisplayContent, generateDnfFile), stub_generateDnfFile); |
| 671 | stub.set(ADDR(DisplayContent, generateDmesgFile), stub_generateDnfFile); |
| 672 | QStandardItemModel *model=new QStandardItemModel; |
| 673 | QStandardItem *item=new QStandardItem; |
| 674 | model->appendRow(item); |
| 675 | model->appendRow(item); |
| 676 | model->setData(model->index(0,0),"/var/log/dnf.log",Qt::UserRole + 66); |
| 677 | model->setData(model->index(1,0),"dmesg",Qt::UserRole + 66); |
| 678 | m_content->slot_BtnSelected(0,0,model->index(0,0)); |
| 679 | m_content->slot_BtnSelected(0,0,model->index(1,0)); |
| 680 | EXPECT_EQ(m_content->m_curLevel, 0)<<"check the status after slot_BtnSelected()"; |
| 681 | EXPECT_EQ(m_content-> m_curBtnId, 0)<<"check the status after slot_BtnSelected()"; |
| 682 | delete item; |
| 683 | delete model; |
| 684 | } |
| 685 | |
| 686 | TEST_F(DisplayContentlx_UT, slot_logCatelogueClicked_UT){ |
| 687 | Stub stub; |
| 688 | stub.set(ADDR(DisplayContent, generateDnfFile), stub_generateDnfFile); |
| 689 | stub.set(ADDR(DisplayContent, generateDmesgFile), stub_generateDnfFile); |
| 690 | QStandardItemModel *model=new QStandardItemModel; |
| 691 | QStandardItem *item=new QStandardItem; |
| 692 | model->appendRow(item); |
| 693 | model->appendRow(item); |
| 694 | model->setData(model->index(0,0),"/var/log/dnf.log",Qt::UserRole + 66); |
| 695 | model->setData(model->index(1,0),"dmesg",Qt::UserRole + 66); |
| 696 | m_content->slot_logCatelogueClicked(model->index(0,0)); |
| 697 | m_content->slot_logCatelogueClicked(model->index(1,0)); |
| 698 | EXPECT_EQ(m_content->m_curListIdx,model->index(1,0))<<"check the status after slot_logCatelogueClicked()"; |
| 699 | m_content->m_curListIdx=model->index(0,0); |
| 700 | m_content->m_flag=LOG_FLAG::Dmesg; |
| 701 | m_content->slot_logCatelogueClicked(model->index(0,0)); |
| 702 | EXPECT_EQ(m_content->m_curListIdx,model->index(0,0))<<"check the status after slot_logCatelogueClicked()"; |
| 703 | delete item; |
| 704 | delete model; |
| 705 | } |
| 706 | |
| 707 | TEST_F(DisplayContentlx_UT, slot_xorgData_UT){ |
| 708 | LOG_MSG_XORG xorg={"20210202","test"}; |
| 709 | QList<LOG_MSG_XORG>listXorg; |
| 710 | listXorg.append(xorg); |
| 711 | m_content->slot_xorgData(listXorg); |
| 712 | m_content->m_flag=LOG_FLAG::XORG; |
| 713 | m_content->m_pLogBackend->m_xorgCurrentIndex=1; |
| 714 | m_content->m_firstLoadPageData=true; |
| 715 | m_content->slot_xorgData(listXorg); |
| 716 | EXPECT_EQ(m_content->m_flag,LOG_FLAG::XORG)<<"check the status after slot_xorgData()"; |
| 717 | EXPECT_NE(m_content->m_pLogBackend->xListOrigin.size(), 0)<<"check the status after slot_xorgData()"; |
| 718 | } |
| 719 | |
| 720 | TEST_F(DisplayContentlx_UT, slot_journalBootFinished_UT){ |
| 721 | m_content->m_flag=LOG_FLAG::JOURNAL; |
| 722 | m_content->m_pLogBackend->m_journalCurrentIndex=1; |
| 723 | m_content->slot_journalFinished(); |
| 724 | EXPECT_EQ(m_content->m_flag,LOG_FLAG::JOURNAL)<<"check the status after slot_journalBootFinished()"; |
| 725 | EXPECT_EQ(m_content->m_isDataLoadComplete, true)<<"check the status after slot_journalBootFinished()"; |
| 726 | } |
| 727 | |
| 728 | |
| 729 | |
| 730 | TEST_F(DisplayContentlx_UT, slot_applicationData_UT){ |
| 731 | LOG_MSG_APPLICATOIN app={"20210202","waring","test","test","test"}; |
| 732 | QList<LOG_MSG_APPLICATOIN>listApp; |
| 733 | listApp.append(app); |
| 734 | m_content->m_flag=LOG_FLAG::APP; |
| 735 | m_content->m_pLogBackend->m_appCurrentIndex=1; |
| 736 | m_content->m_firstLoadPageData=true; |
| 737 | m_content->slot_applicationData(listApp); |
| 738 | EXPECT_EQ(m_content->m_flag,LOG_FLAG::APP)<<"check the status after slot_applicationData()"; |
| 739 | EXPECT_NE(m_content->m_pLogBackend->appListOrigin.size(),0)<<"check the status after slot_applicationData()"; |
| 740 | } |
| 741 | |
| 742 | TEST_F(DisplayContentlx_UT, slot_logLoadFailed_UT){ |
| 743 | m_content->slot_logLoadFailed("error"); |
| 744 | EXPECT_NE(m_content,nullptr)<<"check the status after slot_logLoadFailed()"; |
| 745 | } |
| 746 | |
| 747 | TEST_F(DisplayContentlx_UT, filterNomal_UT){ |
| 748 | NORMAL_FILTERS fiter; |
| 749 | LOG_MSG_NORMAL normal={"20210202","waring","test","test"}; |
| 750 | QList<LOG_MSG_NORMAL>listNormal; |
| 751 | listNormal.append(normal); |
| 752 | LogBackend::filterNomal(fiter,listNormal); |
| 753 | fiter.eventTypeFilter=1; |
| 754 | LogBackend::filterNomal(fiter,listNormal); |
| 755 | fiter.eventTypeFilter=2; |
| 756 | LogBackend::filterNomal(fiter,listNormal); |
| 757 | fiter.eventTypeFilter=3; |
| 758 | LogBackend::filterNomal(fiter,listNormal); |
| 759 | EXPECT_NE(m_content,nullptr)<<"check the status after filterNomal()"; |
| 760 | } |
| 761 | |
| 762 | TEST_F(DisplayContentlx_UT, slot_refreshClicked_UT){ |
| 763 | |
| 764 | Stub stub; |
| 765 | stub.set(ADDR(DisplayContent, generateDnfFile), stub_generateDnfFile); |
| 766 | stub.set(ADDR(DisplayContent, generateDmesgFile), stub_generateDnfFile); |
| 767 | QStandardItemModel *model=new QStandardItemModel; |
| 768 | QStandardItem *item=new QStandardItem; |
| 769 | model->appendRow(item); |
| 770 | model->appendRow(item); |
| 771 | model->setData(model->index(0,0),"/var/log/dnf.log",Qt::UserRole + 66); |
| 772 | model->setData(model->index(1,0),"dmesg",Qt::UserRole + 66); |
| 773 | m_content->slot_refreshClicked(model->index(0,0)); |
| 774 | m_content->slot_refreshClicked(model->index(1,0)); |
| 775 | m_content->m_curListIdx=model->index(0,0); |
| 776 | m_content->m_flag=LOG_FLAG::Dmesg; |
| 777 | m_content->slot_refreshClicked(model->index(0,0)); |
| 778 | EXPECT_EQ(m_content->m_curListIdx,model->index(0,0))<<"check the status after slot_refreshClicked()"; |
| 779 | delete item; |
| 780 | delete model; |
| 781 | } |
| 782 | |
| 783 | TEST_F(DisplayContentlx_UT, filterJournal_UT){ |
| 784 | |
| 785 | NORMAL_FILTERS fiter; |
| 786 | LOG_MSG_JOURNAL journal={"20210202","waring","test","test","test","test"}; |
| 787 | QList<LOG_MSG_JOURNAL>listjournal; |
| 788 | listjournal.append(journal); |
| 789 | QList<LOG_MSG_JOURNAL> list= LogBackend::filterJournal("",listjournal); |
| 790 | EXPECT_EQ(list.at(0).daemonId,"test")<<"check the status after filterJournal()"; |
| 791 | EXPECT_EQ(list.at(0).daemonName,"test")<<"check the status after filterJournal()"; |
| 792 | EXPECT_EQ(list.at(0).dateTime,"20210202")<<"check the status after filterJournal()"; |
| 793 | EXPECT_EQ(list.at(0).level,"test")<<"check the status after filterJournal()"; |
| 794 | EXPECT_EQ(list.at(0).msg,"test")<<"check the status after filterJournal()"; |
| 795 | LogBackend::filterJournal("test",listjournal); |
| 796 | } |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | //zyc |
| 804 | |
| 805 | TEST(DisplayContent_Constructor_UT, DisplayContent_Constructor_UT_001) |
| 806 | { |
| 807 | DisplayContent *p = new DisplayContent(nullptr); |
| 808 | EXPECT_NE(p, nullptr); |
| 809 | delete p; |
| 810 | } |
| 811 | |
| 812 | void stub_endPointLinux(const QString &point, const QString &status) |
| 813 | { |
| 814 | } |
| 815 | |
| 816 | TEST(DisplayContent_Constructor_UT, Dslot_normalData_UT_001) |
| 817 | { |
| 818 | Stub stub; |
| 819 | stub.set(ADDR(DebugTimeManager, endPointLinux), stub_endPointLinux); |
| 820 | DisplayContent *p = new DisplayContent(nullptr); |
| 821 | EXPECT_NE(p, nullptr); |
| 822 | LOG_MSG_NORMAL test; |
| 823 | test.msg = "test"; |
| 824 | test.dateTime = "20201231"; |
| 825 | test.userName = "user"; |
| 826 | test.eventType = "type"; |
| 827 | p->m_flag = Normal; |
| 828 | p->m_firstLoadPageData = true; |
| 829 | p->slot_normalData(QList<LOG_MSG_NORMAL> {test}); |
| 830 | EXPECT_EQ(p->m_flag,LOG_FLAG::Normal)<<"check the status after slot_normalData()"; |
| 831 | delete p; |
| 832 | } |
| 833 | |
| 834 | |
| 835 | TEST(DisplayContent_MainLogTableView_UT, DisplayContent_MainLogTableView_UT_001) |
| 836 | { |
| 837 | DisplayContent *p = new DisplayContent(nullptr); |
| 838 | EXPECT_NE(p, nullptr); |
| 839 | LogTreeView *t = p->mainLogTableView(); |
| 840 | EXPECT_NE(t, nullptr); |
| 841 | delete p; |
| 842 | } |
| 843 | |
| 844 | TEST(DisplayContent_initMap_UT, DisplayContent_initMap_UT_001) |
| 845 | { |
| 846 | DisplayContent *p = new DisplayContent(nullptr); |
| 847 | EXPECT_NE(p, nullptr); |
| 848 | p->initMap(); |
| 849 | QMap<QString, QString> map1; |
| 850 | map1.insert("Warning", Dtk::Widget::DApplication::translate("Level", "Warning")); //add by Airy for bug 19167 and 19161 |
| 851 | map1.insert("Debug", Dtk::Widget::DApplication::translate("Level", "Debug")); //add by Airy for bug 19167 and 19161 |
| 852 | map1.insert("Info", Dtk::Widget::DApplication::translate("Level", "Info")); |
| 853 | map1.insert("Error", Dtk::Widget::DApplication::translate("Level", "Error")); |
| 854 | QMap<QString, QString> map2; |
| 855 | map2.insert(Dtk::Widget::DApplication::translate("Level", "Emergency"), "warning2.svg"); |
| 856 | map2.insert(Dtk::Widget::DApplication::translate("Level", "Alert"), "warning3.svg"); |
| 857 | map2.insert(Dtk::Widget::DApplication::translate("Level", "Critical"), "warning2.svg"); |
| 858 | map2.insert(Dtk::Widget::DApplication::translate("Level", "Error"), "wrong.svg"); |
| 859 | map2.insert(Dtk::Widget::DApplication::translate("Level", "Warning"), "warning.svg"); |
| 860 | map2.insert(Dtk::Widget::DApplication::translate("Level", "Notice"), "warning.svg"); |
| 861 | map2.insert(Dtk::Widget::DApplication::translate("Level", "Info"), ""); |
| 862 | map2.insert(Dtk::Widget::DApplication::translate("Level", "Debug"), ""); |
| 863 | map2.insert("Warning", "warning.svg"); |
| 864 | map2.insert("Debug", ""); |
| 865 | map2.insert("Error", "wrong.svg"); |
| 866 | EXPECT_EQ(p->m_transDict, map1); |
| 867 | EXPECT_EQ(p->m_icon_name_map, map2); |
| 868 | delete p; |
| 869 | } |
| 870 | TEST(DisplayContent_initTableView_UT, DisplayContent_initTableView_UT_001) |
| 871 | { |
| 872 | DisplayContent *p = new DisplayContent(nullptr); |
| 873 | EXPECT_NE(p, nullptr); |
| 874 | p->initTableView(); |
| 875 | EXPECT_NE(p->m_treeView, nullptr); |
| 876 | EXPECT_TRUE(p->m_pModel); |
| 877 | // EXPECT_TRUE(p->m_sortData); |
| 878 | EXPECT_EQ(p->m_treeView->objectName(), "mainLogTable"); |
| 879 | delete p; |
| 880 | } |
| 881 | |
| 882 | TEST(DisplayContent_initConnections_UT, DisplayContent_initConnections_UT_001) |
| 883 | { |
| 884 | DisplayContent *p = new DisplayContent(nullptr); |
| 885 | EXPECT_NE(p, nullptr); |
| 886 | p->initConnections(); |
| 887 | delete p; |
| 888 | } |
| 889 | |
| 890 | class DisplayContent_generateJournalFile_UT_Param |
| 891 | { |
| 892 | public: |
| 893 | DisplayContent_generateJournalFile_UT_Param(int id, int Iid) |
| 894 | { |
| 895 | time = id; |
| 896 | level = Iid; |
| 897 | } |
| 898 | int time; |
| 899 | int level; |
| 900 | }; |
| 901 | |
| 902 | class DisplayContent_generateJournalFile_UT : public ::testing::TestWithParam<DisplayContent_generateJournalFile_UT_Param> |
| 903 | { |
| 904 | }; |
| 905 | /**/ |
| 906 | |
| 907 | std::vector<DisplayContent_generateJournalFile_UT_Param> vec_DisplayContent_generateJournalFile_UT_Param {DisplayContent_generateJournalFile_UT_Param(0, -1), DisplayContent_generateJournalFile_UT_Param(0, 0), DisplayContent_generateJournalFile_UT_Param(0, 1), DisplayContent_generateJournalFile_UT_Param(0, 2), DisplayContent_generateJournalFile_UT_Param(0, 3), DisplayContent_generateJournalFile_UT_Param(0, 4), DisplayContent_generateJournalFile_UT_Param(0, 5), DisplayContent_generateJournalFile_UT_Param(0, 6), DisplayContent_generateJournalFile_UT_Param(0, 7), DisplayContent_generateJournalFile_UT_Param(1, -1), DisplayContent_generateJournalFile_UT_Param(1, 0), DisplayContent_generateJournalFile_UT_Param(1, 1), DisplayContent_generateJournalFile_UT_Param(1, 2), DisplayContent_generateJournalFile_UT_Param(1, 3), DisplayContent_generateJournalFile_UT_Param(1, 4), DisplayContent_generateJournalFile_UT_Param(1, 5), DisplayContent_generateJournalFile_UT_Param(1, 6), DisplayContent_generateJournalFile_UT_Param(1, 7), DisplayContent_generateJournalFile_UT_Param(2, -1), DisplayContent_generateJournalFile_UT_Param(2, 0), DisplayContent_generateJournalFile_UT_Param(2, 1), DisplayContent_generateJournalFile_UT_Param(2, 2), DisplayContent_generateJournalFile_UT_Param(2, 3), DisplayContent_generateJournalFile_UT_Param(2, 4), DisplayContent_generateJournalFile_UT_Param(2, 5), DisplayContent_generateJournalFile_UT_Param(2, 6), DisplayContent_generateJournalFile_UT_Param(2, 7), DisplayContent_generateJournalFile_UT_Param(3, -1), DisplayContent_generateJournalFile_UT_Param(3, 0), DisplayContent_generateJournalFile_UT_Param(3, 1), DisplayContent_generateJournalFile_UT_Param(3, 2), DisplayContent_generateJournalFile_UT_Param(3, 3), DisplayContent_generateJournalFile_UT_Param(3, 4), DisplayContent_generateJournalFile_UT_Param(3, 5), DisplayContent_generateJournalFile_UT_Param(3, 6), DisplayContent_generateJournalFile_UT_Param(3, 7), DisplayContent_generateJournalFile_UT_Param(4, -1), DisplayContent_generateJournalFile_UT_Param(4, 0), DisplayContent_generateJournalFile_UT_Param(4, 1), DisplayContent_generateJournalFile_UT_Param(4, 2), DisplayContent_generateJournalFile_UT_Param(4, 3), DisplayContent_generateJournalFile_UT_Param(4, 4), DisplayContent_generateJournalFile_UT_Param(4, 5), DisplayContent_generateJournalFile_UT_Param(4, 6), DisplayContent_generateJournalFile_UT_Param(4, 7), DisplayContent_generateJournalFile_UT_Param(5, -1), DisplayContent_generateJournalFile_UT_Param(5, 0), DisplayContent_generateJournalFile_UT_Param(5, 1), DisplayContent_generateJournalFile_UT_Param(5, 2), DisplayContent_generateJournalFile_UT_Param(5, 3), DisplayContent_generateJournalFile_UT_Param(5, 4), DisplayContent_generateJournalFile_UT_Param(5, 5), DisplayContent_generateJournalFile_UT_Param(5, 6), DisplayContent_generateJournalFile_UT_Param(5, 7)}; |
| 908 | |
| 909 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_generateJournalFile_UT, ::testing::ValuesIn(vec_DisplayContent_generateJournalFile_UT_Param)); |
| 910 | |
| 911 | TEST_P(DisplayContent_generateJournalFile_UT, DisplayContent_generateJournalFile_UT_001) |
| 912 | { |
| 913 | Stub stub; |
| 914 | stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal); |
| 915 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 916 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 917 | DisplayContent_generateJournalFile_UT_Param param = GetParam(); |
| 918 | DisplayContent *p = new DisplayContent(nullptr); |
| 919 | EXPECT_NE(p, nullptr); |
| 920 | |
| 921 | p->generateJournalFile(param.time, param.level); |
| 922 | p->deleteLater(); |
| 923 | } |
| 924 | TEST(DisplayContent_createJournalTableStart_UT, DisplayContent_createJournalTableStart_UT_001) |
| 925 | { |
| 926 | Stub stub; |
| 927 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 928 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 929 | DisplayContent *p = new DisplayContent(nullptr); |
| 930 | EXPECT_NE(p, nullptr); |
| 931 | QList<LOG_MSG_JOURNAL> list; |
| 932 | for (int i = 0; i < 100; ++i) { |
| 933 | LOG_MSG_JOURNAL item; |
| 934 | item.msg = ""; |
| 935 | item.level = ""; |
| 936 | item.daemonId = ""; |
| 937 | item.dateTime = ""; |
| 938 | item.hostName = ""; |
| 939 | item.daemonName = ""; |
| 940 | list.append(item); |
| 941 | } |
| 942 | p->createJournalTableStart(list); |
| 943 | delete p; |
| 944 | } |
| 945 | TEST(DisplayContent_createJournalTableForm_UT, DisplayContent_createJournalTableForm_UT_001) |
| 946 | { |
| 947 | Stub stub; |
| 948 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 949 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 950 | DisplayContent *p = new DisplayContent(nullptr); |
| 951 | EXPECT_NE(p, nullptr); |
| 952 | |
| 953 | p->createJournalTableForm(); |
| 954 | QStringList a; |
| 955 | a << Dtk::Widget::DApplication::translate("Table", "Level") |
| 956 | << Dtk::Widget::DApplication::translate("Table", "Process") // modified by Airy |
| 957 | << Dtk::Widget::DApplication::translate("Table", "Date and Time") |
| 958 | << Dtk::Widget::DApplication::translate("Table", "Info") |
| 959 | << Dtk::Widget::DApplication::translate("Table", "User") |
| 960 | << Dtk::Widget::DApplication::translate("Table", "PID"); |
| 961 | bool rs = true; |
| 962 | for (int i = 0; i < a.size(); ++i) { |
| 963 | if (p->m_pModel->horizontalHeaderItem(i)->text() != a.value(i)) { |
| 964 | rs = false; |
| 965 | } |
| 966 | } |
| 967 | EXPECT_EQ(rs, true); |
| 968 | delete p; |
| 969 | } |
| 970 | |
| 971 | class DisplayContent_generateDpkgFile_UT_Param |
| 972 | { |
| 973 | public: |
| 974 | explicit DisplayContent_generateDpkgFile_UT_Param(int id) |
| 975 | { |
| 976 | time = id; |
| 977 | } |
| 978 | int time; |
| 979 | }; |
| 980 | |
| 981 | class DisplayContent_generateDpkgFile_UT : public ::testing::TestWithParam<DisplayContent_generateDpkgFile_UT_Param> |
| 982 | { |
| 983 | }; |
| 984 | |
| 985 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_generateDpkgFile_UT, ::testing::Values(DisplayContent_generateDpkgFile_UT_Param(0), DisplayContent_generateDpkgFile_UT_Param(1), DisplayContent_generateDpkgFile_UT_Param(2), DisplayContent_generateDpkgFile_UT_Param(3), DisplayContent_generateDpkgFile_UT_Param(4), DisplayContent_generateDpkgFile_UT_Param(5))); |
| 986 | |
| 987 | TEST_P(DisplayContent_generateDpkgFile_UT, DisplayContent_generateDpkgFile_UT_001) |
| 988 | { |
| 989 | Stub stub; |
| 990 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 991 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 992 | stub.set(ADDR(LogFileParser, parseByDpkg), LogFileParser_parseByDpkg); |
| 993 | DisplayContent_generateDpkgFile_UT_Param param = GetParam(); |
| 994 | DisplayContent *p = new DisplayContent(nullptr); |
| 995 | EXPECT_NE(p, nullptr); |
| 996 | Utils::sleep(200); |
| 997 | p->generateDpkgFile(param.time); |
| 998 | p->deleteLater(); |
| 999 | } |
| 1000 | |
| 1001 | TEST(DisplayContent_createDpkgTable_UT, DisplayContent_createDpkgTable_UT_001) |
| 1002 | { |
| 1003 | Stub stub; |
| 1004 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1005 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1006 | DisplayContent *p = new DisplayContent(nullptr); |
| 1007 | EXPECT_NE(p, nullptr); |
| 1008 | |
| 1009 | QList<LOG_MSG_DPKG> list; |
| 1010 | for (int i = 0; i < 100; ++i) { |
| 1011 | LOG_MSG_DPKG item; |
| 1012 | item.msg = ""; |
| 1013 | item.dateTime = ""; |
| 1014 | item.action = ""; |
| 1015 | list.append(item); |
| 1016 | } |
| 1017 | p->createDpkgTableStart(list); |
| 1018 | delete p; |
| 1019 | } |
| 1020 | |
| 1021 | class DisplayContent_generateKernFile_UT_Param |
| 1022 | { |
| 1023 | public: |
| 1024 | explicit DisplayContent_generateKernFile_UT_Param(int id) |
| 1025 | { |
| 1026 | time = id; |
| 1027 | } |
| 1028 | int time; |
| 1029 | }; |
| 1030 | void parseByKern(void *obj, KERN_FILTERS &iKernFilter) |
| 1031 | { |
| 1032 | qDebug() << "parseByKern---"; |
| 1033 | } |
| 1034 | class DisplayContent_generateKernFile_UT : public ::testing::TestWithParam<DisplayContent_generateKernFile_UT_Param> |
| 1035 | { |
| 1036 | }; |
| 1037 | |
| 1038 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_generateKernFile_UT, ::testing::Values(DisplayContent_generateKernFile_UT_Param(0), DisplayContent_generateKernFile_UT_Param(1), DisplayContent_generateKernFile_UT_Param(2), DisplayContent_generateKernFile_UT_Param(3), DisplayContent_generateKernFile_UT_Param(4), DisplayContent_generateKernFile_UT_Param(5))); |
| 1039 | |
| 1040 | TEST_P(DisplayContent_generateKernFile_UT, DisplayContent_generateKernFile_UT_001) |
| 1041 | { |
| 1042 | Stub stub; |
| 1043 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1044 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1045 | stub.set(ADDR(journalWork, doWork), stub_jounalWorkRun); |
| 1046 | stub.set(ADDR(JournalBootWork, doWork),stub_jounalWorkRun); |
| 1047 | DisplayContent_generateKernFile_UT_Param param = GetParam(); |
| 1048 | DisplayContent *p = new DisplayContent(nullptr); |
| 1049 | EXPECT_NE(p, nullptr); |
| 1050 | Utils::sleep(200); |
| 1051 | stub.set(ADDR(LogFileParser, parseByKern), parseByKern); |
| 1052 | p->generateKernFile(param.time); |
| 1053 | p->deleteLater(); |
| 1054 | } |
| 1055 | |
| 1056 | TEST(DisplayContent_createKernTableForm_UT, DisplayContent_createKernTableForm_UT_001) |
| 1057 | { |
| 1058 | Stub stub; |
| 1059 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1060 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1061 | DisplayContent *p = new DisplayContent(nullptr); |
| 1062 | EXPECT_NE(p, nullptr); |
| 1063 | |
| 1064 | p->createKernTableForm(); |
| 1065 | QStringList a; |
| 1066 | a << Dtk::Widget::DApplication::translate("Table", "Date and Time") |
| 1067 | << Dtk::Widget::DApplication::translate("Table", "User") // modified by Airy |
| 1068 | << Dtk::Widget::DApplication::translate("Table", "Process") |
| 1069 | << Dtk::Widget::DApplication::translate("Table", "Info"); |
| 1070 | bool rs = true; |
| 1071 | for (int i = 0; i < a.size(); ++i) { |
| 1072 | if (p->m_pModel->horizontalHeaderItem(i)->text() != a.value(i)) { |
| 1073 | rs = false; |
| 1074 | } |
| 1075 | } |
| 1076 | EXPECT_EQ(rs, true); |
| 1077 | delete p; |
| 1078 | } |
| 1079 | |
| 1080 | TEST(DisplayContent_createOOCTableForm_UT, DisplayContent_createOOCTableForm_UT_001) |
| 1081 | { |
| 1082 | DisplayContent *p = new DisplayContent(nullptr); |
| 1083 | EXPECT_NE(p, nullptr); |
| 1084 | |
| 1085 | p->createOOCTableForm(); |
| 1086 | QStringList a; |
| 1087 | a << DApplication::translate("Table", "File Name") |
| 1088 | << DApplication::translate("Table", "Time Modified"); |
| 1089 | bool rs = true; |
| 1090 | for (int i = 0; i < a.size(); ++i) { |
| 1091 | if (p->m_pModel->horizontalHeaderItem(i)->text() != a.value(i)) { |
| 1092 | rs = false; |
| 1093 | } |
| 1094 | } |
| 1095 | EXPECT_EQ(rs, true); |
| 1096 | p->deleteLater(); |
| 1097 | } |
| 1098 | |
| 1099 | TEST(DisplayContent_createKernTable_UT, DisplayContent_createKernTable_UT_001) |
| 1100 | { |
| 1101 | Stub stub; |
| 1102 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1103 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1104 | DisplayContent *p = new DisplayContent(nullptr); |
| 1105 | EXPECT_NE(p, nullptr); |
| 1106 | QList<LOG_MSG_JOURNAL> list; |
| 1107 | LOG_MSG_JOURNAL item; |
| 1108 | for (int i = 0; i < 100; ++i) { |
| 1109 | item.msg = QString("msg%1").arg(i); |
| 1110 | item.level = "Debug"; |
| 1111 | item.daemonId = "1"; |
| 1112 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 1113 | item.hostName = "test_host"; |
| 1114 | item.daemonName = "test_daemon"; |
| 1115 | list.append(item); |
| 1116 | } |
| 1117 | p->createKernTable(list); |
| 1118 | p->deleteLater(); |
| 1119 | } |
| 1120 | |
| 1121 | TEST(DisplayContent_createOOCTable_UT, DisplayContent_createOOCTable_UT_001) |
| 1122 | { |
| 1123 | DisplayContent *p = new DisplayContent(nullptr); |
| 1124 | EXPECT_NE(p, nullptr); |
| 1125 | QList<LOG_FILE_OTHERORCUSTOM> list; |
| 1126 | for (int i = 0; i < 100; ++i) { |
| 1127 | LOG_FILE_OTHERORCUSTOM data; |
| 1128 | data.name = "deepin-installer-init.log"; |
| 1129 | data.path = "/var/log/deepin-installer-init.log"; |
| 1130 | list.append(data); |
| 1131 | } |
| 1132 | p->createOOCTable(list); |
| 1133 | p->deleteLater(); |
| 1134 | } |
| 1135 | |
| 1136 | TEST(DisplayContent_insertKernTable_UT, DisplayContent_insertKernTable_UT_001) |
| 1137 | { |
| 1138 | Stub stub; |
| 1139 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1140 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1141 | DisplayContent *p = new DisplayContent(nullptr); |
| 1142 | EXPECT_NE(p, nullptr); |
| 1143 | QList<LOG_MSG_JOURNAL> list; |
| 1144 | LOG_MSG_JOURNAL item; |
| 1145 | for (int i = 0; i < 100; ++i) { |
| 1146 | item.msg = QString("msg%1").arg(i); |
| 1147 | item.level = "Debug"; |
| 1148 | item.daemonId = "1"; |
| 1149 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 1150 | item.hostName = "test_host"; |
| 1151 | item.daemonName = "test_daemon"; |
| 1152 | list.append(item); |
| 1153 | } |
| 1154 | p->insertKernTable(list, 0, list.size()); |
| 1155 | p->deleteLater(); |
| 1156 | } |
| 1157 | |
| 1158 | class DisplayContent_generateAppFile_UT_Param |
| 1159 | { |
| 1160 | public: |
| 1161 | explicit DisplayContent_generateAppFile_UT_Param(int id) |
| 1162 | { |
| 1163 | time = id; |
| 1164 | } |
| 1165 | int time; |
| 1166 | }; |
| 1167 | |
| 1168 | class DisplayContent_generateAppFile_UT : public ::testing::TestWithParam<DisplayContent_generateAppFile_UT_Param> |
| 1169 | { |
| 1170 | }; |
| 1171 | |
| 1172 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_generateAppFile_UT, ::testing::Values(DisplayContent_generateAppFile_UT_Param(0), DisplayContent_generateAppFile_UT_Param(1), DisplayContent_generateAppFile_UT_Param(2), DisplayContent_generateAppFile_UT_Param(3), DisplayContent_generateAppFile_UT_Param(4), DisplayContent_generateAppFile_UT_Param(5))); |
| 1173 | |
| 1174 | TEST_P(DisplayContent_generateAppFile_UT, DisplayContent_generateAppFile_UT_001) |
| 1175 | { |
| 1176 | Stub stub; |
| 1177 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1178 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1179 | stub.set(ADDR(LogFileParser, parseByApp), LogFileParser_parseByApp); |
| 1180 | DisplayContent_generateAppFile_UT_Param param = GetParam(); |
| 1181 | DisplayContent *p = new DisplayContent(nullptr); |
| 1182 | EXPECT_NE(p, nullptr); |
| 1183 | Utils::sleep(200); |
| 1184 | p->generateAppFile("", param.time, 7, ""); |
| 1185 | p->deleteLater(); |
| 1186 | } |
| 1187 | |
| 1188 | TEST(DisplayContent_createAppTableForm_UT, DisplayContent_createAppTableForm_UT_001) |
| 1189 | { |
| 1190 | Stub stub; |
| 1191 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1192 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1193 | DisplayContent *p = new DisplayContent(nullptr); |
| 1194 | EXPECT_NE(p, nullptr); |
| 1195 | |
| 1196 | p->createAppTableForm(); |
| 1197 | QStringList a; |
| 1198 | a << Dtk::Widget::DApplication::translate("Table", "Level") |
| 1199 | << Dtk::Widget::DApplication::translate("Table", "Date and Time") // modified by Airy |
| 1200 | << Dtk::Widget::DApplication::translate("Table", "Source") |
| 1201 | << Dtk::Widget::DApplication::translate("Table", "Info"); |
| 1202 | bool rs = true; |
| 1203 | for (int i = 0; i < a.size(); ++i) { |
| 1204 | if (p->m_pModel->horizontalHeaderItem(i)->text() != a.value(i)) { |
| 1205 | rs = false; |
| 1206 | } |
| 1207 | } |
| 1208 | EXPECT_EQ(rs, true); |
| 1209 | delete p; |
| 1210 | } |
| 1211 | |
| 1212 | TEST(DisplayContent_createAppTable_UT, DisplayContent_createAppTable_UT_001) |
| 1213 | { |
| 1214 | Stub stub; |
| 1215 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1216 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1217 | DisplayContent *p = new DisplayContent(nullptr); |
| 1218 | EXPECT_NE(p, nullptr); |
| 1219 | QList<LOG_MSG_APPLICATOIN> list; |
| 1220 | LOG_MSG_APPLICATOIN item; |
| 1221 | for (int i = 0; i < 100; ++i) { |
| 1222 | item.msg = QString("msg%1").arg(i); |
| 1223 | item.level = "Debug"; |
| 1224 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 1225 | item.src = "test_src"; |
| 1226 | list.append(item); |
| 1227 | } |
| 1228 | p->createAppTable(list); |
| 1229 | p->deleteLater(); |
| 1230 | } |
| 1231 | TEST(DisplayContent_createBootTable_UT, DisplayContent_createBootTable_UT_001) |
| 1232 | { |
| 1233 | Stub stub; |
| 1234 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1235 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1236 | DisplayContent *p = new DisplayContent(nullptr); |
| 1237 | EXPECT_NE(p, nullptr); |
| 1238 | QList<LOG_MSG_BOOT> list; |
| 1239 | LOG_MSG_BOOT item; |
| 1240 | for (int i = 0; i < 100; ++i) { |
| 1241 | item.msg = QString("msg%1").arg(i); |
| 1242 | item.status = "OK"; |
| 1243 | list.append(item); |
| 1244 | } |
| 1245 | p->createBootTable(list); |
| 1246 | p->deleteLater(); |
| 1247 | } |
| 1248 | |
| 1249 | TEST(DisplayContent_createXorgTable_UT, DisplayContent_createXorgTable_UT_001) |
| 1250 | { |
| 1251 | Stub stub; |
| 1252 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1253 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1254 | DisplayContent *p = new DisplayContent(nullptr); |
| 1255 | EXPECT_NE(p, nullptr); |
| 1256 | QList<LOG_MSG_XORG> list; |
| 1257 | LOG_MSG_XORG item; |
| 1258 | for (int i = 0; i < 100; ++i) { |
| 1259 | item.msg = QString("msg%1").arg(i); |
| 1260 | item.offset = "3.541"; |
| 1261 | list.append(item); |
| 1262 | } |
| 1263 | p->createXorgTable(list); |
| 1264 | p->deleteLater(); |
| 1265 | } |
| 1266 | |
| 1267 | class DisplayContent_generateXorgFile_UT_Param |
| 1268 | { |
| 1269 | public: |
| 1270 | explicit DisplayContent_generateXorgFile_UT_Param(int id) |
| 1271 | { |
| 1272 | time = id; |
| 1273 | } |
| 1274 | int time; |
| 1275 | }; |
| 1276 | |
| 1277 | class DisplayContent_generateXorgFile_UT : public ::testing::TestWithParam<DisplayContent_generateXorgFile_UT_Param> |
| 1278 | { |
| 1279 | }; |
| 1280 | |
| 1281 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_generateXorgFile_UT, ::testing::Values(DisplayContent_generateXorgFile_UT_Param(0), DisplayContent_generateXorgFile_UT_Param(1), DisplayContent_generateXorgFile_UT_Param(2), DisplayContent_generateXorgFile_UT_Param(3), DisplayContent_generateXorgFile_UT_Param(4), DisplayContent_generateXorgFile_UT_Param(5))); |
| 1282 | |
| 1283 | void DisplayContent_generateXorgFile_UT_parseByXlog(XORG_FILTERS &iXorgFilter) |
| 1284 | { |
| 1285 | return; |
| 1286 | } |
| 1287 | |
| 1288 | TEST_P(DisplayContent_generateXorgFile_UT, DisplayContent_generateXorgFile_UT_001) |
| 1289 | { |
| 1290 | Stub stub; |
| 1291 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1292 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1293 | stub.set(ADDR(LogFileParser, parseByXlog), DisplayContent_generateXorgFile_UT_parseByXlog); |
| 1294 | DisplayContent_generateXorgFile_UT_Param param = GetParam(); |
| 1295 | DisplayContent *p = new DisplayContent(nullptr); |
| 1296 | EXPECT_NE(p, nullptr); |
| 1297 | Utils::sleep(200); |
| 1298 | p->generateXorgFile(param.time); |
| 1299 | delete p; |
| 1300 | } |
| 1301 | |
| 1302 | TEST(DisplayContent_creatKwinTable_UT, DisplayContent_creatKwinTable_UT_001) |
| 1303 | { |
| 1304 | Stub stub; |
| 1305 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1306 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1307 | DisplayContent *p = new DisplayContent(nullptr); |
| 1308 | EXPECT_NE(p, nullptr); |
| 1309 | QList<LOG_MSG_KWIN> list; |
| 1310 | LOG_MSG_KWIN item; |
| 1311 | for (int i = 0; i < 100; ++i) { |
| 1312 | item.msg = QString("msg%1").arg(i); |
| 1313 | list.append(item); |
| 1314 | } |
| 1315 | p->creatKwinTable(list); |
| 1316 | p->deleteLater(); |
| 1317 | } |
| 1318 | |
| 1319 | TEST(DisplayContent_generateKwinFile_UT, DisplayContent_generateKwinFile_UT_001) |
| 1320 | { |
| 1321 | Stub stub; |
| 1322 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1323 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1324 | stub.set(ADDR(LogFileParser, parseByKwin), LogFileParser_parseByKwin); |
| 1325 | DisplayContent *p = new DisplayContent(nullptr); |
| 1326 | EXPECT_NE(p, nullptr); |
| 1327 | KWIN_FILTERS f; |
| 1328 | f.msg = ""; |
| 1329 | p->generateKwinFile(f); |
| 1330 | p->deleteLater(); |
| 1331 | } |
| 1332 | |
| 1333 | TEST(DisplayContent_createNormalTable_UT, DisplayContent_createNormalTable_UT_001) |
| 1334 | { |
| 1335 | Stub stub; |
| 1336 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1337 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1338 | DisplayContent *p = new DisplayContent(nullptr); |
| 1339 | EXPECT_NE(p, nullptr); |
| 1340 | QList<LOG_MSG_NORMAL> list; |
| 1341 | LOG_MSG_NORMAL item; |
| 1342 | for (int i = 0; i < 100; ++i) { |
| 1343 | item.msg = QString("msg%1").arg(i); |
| 1344 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 1345 | item.userName = "test_user"; |
| 1346 | item.eventType = "Login"; |
| 1347 | list.append(item); |
| 1348 | } |
| 1349 | p->createNormalTable(list); |
| 1350 | p->deleteLater(); |
| 1351 | } |
| 1352 | |
| 1353 | TEST(DisplayContent_generateOOCFile_UT, DisplayContent_generateOOCFile_UT_001) |
| 1354 | { |
| 1355 | Stub stub; |
| 1356 | stub.set(ADDR(LogFileParser, parseByOOC), LogFileParser_parseByOOC); |
| 1357 | DisplayContent *p = new DisplayContent(nullptr); |
| 1358 | EXPECT_NE(p, nullptr); |
| 1359 | p->generateOOCFile("/var/log/deepin-installer-init.log"); |
| 1360 | p->deleteLater(); |
| 1361 | } |
| 1362 | |
| 1363 | class DisplayContent_generateNormalFile_UT_Param |
| 1364 | { |
| 1365 | public: |
| 1366 | explicit DisplayContent_generateNormalFile_UT_Param(int id) |
| 1367 | { |
| 1368 | time = id; |
| 1369 | } |
| 1370 | int time; |
| 1371 | }; |
| 1372 | |
| 1373 | class DisplayContent_generateNormalFile_UT : public ::testing::TestWithParam<DisplayContent_generateNormalFile_UT_Param> |
| 1374 | { |
| 1375 | }; |
| 1376 | |
| 1377 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_generateNormalFile_UT, ::testing::Values(DisplayContent_generateNormalFile_UT_Param(0), DisplayContent_generateNormalFile_UT_Param(1), DisplayContent_generateNormalFile_UT_Param(2), DisplayContent_generateNormalFile_UT_Param(3), DisplayContent_generateNormalFile_UT_Param(4), DisplayContent_generateNormalFile_UT_Param(5))); |
| 1378 | |
| 1379 | TEST_P(DisplayContent_generateNormalFile_UT, DisplayContent_generateNormalFile_UT_001) |
| 1380 | { |
| 1381 | Stub stub; |
| 1382 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1383 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1384 | stub.set(ADDR(LogFileParser, parseByNormal), LogFileParser_parseByNormal); |
| 1385 | |
| 1386 | DisplayContent_generateNormalFile_UT_Param param = GetParam(); |
| 1387 | DisplayContent *p = new DisplayContent(nullptr); |
| 1388 | EXPECT_NE(p, nullptr); |
| 1389 | Utils::sleep(200); |
| 1390 | p->generateNormalFile(param.time); |
| 1391 | p->deleteLater(); |
| 1392 | } |
| 1393 | |
| 1394 | TEST(DisplayContent_insertJournalTable_UT, DisplayContent_insertJournalTable_UT_001) |
| 1395 | { |
| 1396 | Stub stub; |
| 1397 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1398 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1399 | DisplayContent *p = new DisplayContent(nullptr); |
| 1400 | EXPECT_NE(p, nullptr); |
| 1401 | QList<LOG_MSG_JOURNAL> list; |
| 1402 | LOG_MSG_JOURNAL item; |
| 1403 | for (int i = 0; i < 100; ++i) { |
| 1404 | item.msg = QString("msg%1").arg(i); |
| 1405 | item.level = "Debug"; |
| 1406 | item.daemonId = "1"; |
| 1407 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 1408 | item.hostName = "test_host"; |
| 1409 | item.daemonName = "test_daemon"; |
| 1410 | list.append(item); |
| 1411 | } |
| 1412 | p->insertJournalTable(list, 0, list.size()); |
| 1413 | p->deleteLater(); |
| 1414 | } |
| 1415 | |
| 1416 | class DisplayContent_getAppName_UT_Param |
| 1417 | { |
| 1418 | public: |
| 1419 | DisplayContent_getAppName_UT_Param(const QString &iPath, const QString &iResult) |
| 1420 | : path(iPath) |
| 1421 | , rs(iResult) |
| 1422 | { |
| 1423 | } |
| 1424 | QString path; |
| 1425 | QString rs; |
| 1426 | }; |
| 1427 | |
| 1428 | class DisplayContent_getAppName_UT : public ::testing::TestWithParam<DisplayContent_getAppName_UT_Param> |
| 1429 | { |
| 1430 | }; |
| 1431 | |
| 1432 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_getAppName_UT, ::testing::Values(DisplayContent_getAppName_UT_Param("", ""), DisplayContent_getAppName_UT_Param("deepin-log-viewer.log", "日志收集工具"), DisplayContent_getAppName_UT_Param("deepin-log-viewer", "日志收集工具"), DisplayContent_getAppName_UT_Param("/test/deepin-log-viewer.log", "日志收集工具"))); |
| 1433 | |
| 1434 | TEST_P(DisplayContent_getAppName_UT, DisplayContent_getAppName_UT_001) |
| 1435 | { |
| 1436 | Stub stub; |
| 1437 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1438 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1439 | DisplayContent_getAppName_UT_Param param = GetParam(); |
| 1440 | DisplayContent *p = new DisplayContent(nullptr); |
| 1441 | EXPECT_NE(p, nullptr); |
| 1442 | QString result = p->getAppName(param.path); |
| 1443 | qDebug() << param.path << "result" << result; |
| 1444 | // EXPECT_EQ(result, param.rs); |
| 1445 | p->deleteLater(); |
| 1446 | } |
| 1447 | |
| 1448 | TEST(DisplayContent_isAuthProcessAlive_UT, DisplayContent_isAuthProcessAlive_UT_001) |
| 1449 | { |
| 1450 | Stub stub; |
| 1451 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1452 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1453 | DisplayContent *p = new DisplayContent(nullptr); |
| 1454 | EXPECT_NE(p, nullptr); |
| 1455 | p->isAuthProcessAlive(); |
| 1456 | p->deleteLater(); |
| 1457 | } |
| 1458 | |
| 1459 | class DisplayContent_generateJournalBootFile_UT_Param |
| 1460 | { |
| 1461 | public: |
| 1462 | explicit DisplayContent_generateJournalBootFile_UT_Param(int id) |
| 1463 | { |
| 1464 | level = id; |
| 1465 | } |
| 1466 | int level; |
| 1467 | }; |
| 1468 | |
| 1469 | class DisplayContent_generateJournalBootFile_UT : public ::testing::TestWithParam<DisplayContent_generateJournalBootFile_UT_Param> |
| 1470 | { |
| 1471 | }; |
| 1472 | |
| 1473 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_generateJournalBootFile_UT, ::testing::Values(DisplayContent_generateJournalBootFile_UT_Param(0), DisplayContent_generateJournalBootFile_UT_Param(1), DisplayContent_generateJournalBootFile_UT_Param(2), DisplayContent_generateJournalBootFile_UT_Param(3), DisplayContent_generateJournalBootFile_UT_Param(4), DisplayContent_generateJournalBootFile_UT_Param(5), DisplayContent_generateJournalBootFile_UT_Param(6), DisplayContent_generateJournalBootFile_UT_Param(7))); |
| 1474 | |
| 1475 | TEST_P(DisplayContent_generateJournalBootFile_UT, DisplayContent_generateJournalBootFile_UT) |
| 1476 | { |
| 1477 | Stub stub; |
| 1478 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1479 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1480 | stub.set(ADDR(LogFileParser, parseByJournalBoot), LogFileParser_parseByJournalBoot); |
| 1481 | DisplayContent_generateJournalBootFile_UT_Param param = GetParam(); |
| 1482 | DisplayContent *p = new DisplayContent(nullptr); |
| 1483 | EXPECT_NE(p, nullptr); |
| 1484 | p->generateJournalBootFile(param.level); |
| 1485 | p->deleteLater(); |
| 1486 | } |
| 1487 | |
| 1488 | TEST(DisplayContent_createJournalBootTableStart_UT, DisplayContent_createJournalBootTableStart_UT_001) |
| 1489 | { |
| 1490 | Stub stub; |
| 1491 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1492 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1493 | DisplayContent *p = new DisplayContent(nullptr); |
| 1494 | EXPECT_NE(p, nullptr); |
| 1495 | QList<LOG_MSG_JOURNAL> list; |
| 1496 | for (int i = 0; i < 100; ++i) { |
| 1497 | LOG_MSG_JOURNAL item; |
| 1498 | item.msg = ""; |
| 1499 | item.level = ""; |
| 1500 | item.daemonId = ""; |
| 1501 | item.dateTime = ""; |
| 1502 | item.hostName = ""; |
| 1503 | item.daemonName = ""; |
| 1504 | list.append(item); |
| 1505 | } |
| 1506 | // p->createJournalBootTableStart(list); |
| 1507 | delete p; |
| 1508 | } |
| 1509 | TEST(DisplayContent_createJournalBootTableForm_UT, DisplayContent_createJournalBootTableForm_UT_001) |
| 1510 | { |
| 1511 | Stub stub; |
| 1512 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1513 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1514 | DisplayContent *p = new DisplayContent(nullptr); |
| 1515 | EXPECT_NE(p, nullptr); |
| 1516 | |
| 1517 | p->createJournalBootTableForm(); |
| 1518 | QStringList a; |
| 1519 | a << Dtk::Widget::DApplication::translate("Table", "Level") |
| 1520 | << Dtk::Widget::DApplication::translate("Table", "Process") |
| 1521 | << Dtk::Widget::DApplication::translate("Table", "Date and Time") // modified by Airy |
| 1522 | << Dtk::Widget::DApplication::translate("Table", "Info") |
| 1523 | << Dtk::Widget::DApplication::translate("Table", "User") |
| 1524 | << Dtk::Widget::DApplication::translate("Table", "PID"); |
| 1525 | bool rs = true; |
| 1526 | for (int i = 0; i < a.size(); ++i) { |
| 1527 | if (p->m_pModel->horizontalHeaderItem(i)->text() != a.value(i)) { |
| 1528 | rs = false; |
| 1529 | } |
| 1530 | } |
| 1531 | EXPECT_EQ(rs, true); |
| 1532 | delete p; |
| 1533 | } |
| 1534 | |
| 1535 | TEST(DisplayContent_insertJournalBootTable_UT, DisplayContent_insertJournalBootTable_UT_001) |
| 1536 | { |
| 1537 | Stub stub; |
| 1538 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1539 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1540 | DisplayContent *p = new DisplayContent(nullptr); |
| 1541 | EXPECT_NE(p, nullptr); |
| 1542 | QList<LOG_MSG_JOURNAL> list; |
| 1543 | LOG_MSG_JOURNAL item; |
| 1544 | for (int i = 0; i < 100; ++i) { |
| 1545 | item.msg = QString("msg%1").arg(i); |
| 1546 | item.level = "Debug"; |
| 1547 | item.daemonId = "1"; |
| 1548 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 1549 | item.hostName = "test_host"; |
| 1550 | item.daemonName = "test_daemon"; |
| 1551 | list.append(item); |
| 1552 | } |
| 1553 | p->insertJournalBootTable(list, 0, list.size()); |
| 1554 | p->deleteLater(); |
| 1555 | } |
| 1556 | |
| 1557 | TEST(DisplayContent_slot_tableItemClicked_UT, DisplayContent_slot_tableItemClicked_UT_001) |
| 1558 | { |
| 1559 | Stub stub; |
| 1560 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1561 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1562 | DisplayContent *p = new DisplayContent(nullptr); |
| 1563 | EXPECT_NE(p, nullptr); |
| 1564 | |
| 1565 | p->slot_tableItemClicked(QModelIndex()); |
| 1566 | p->deleteLater(); |
| 1567 | } |
| 1568 | |
| 1569 | TEST(DisplayContent_slot_valueChanged_dConfig_or_gSetting_UT, DisplayContent_slot_valueChanged_dConfig_or_gSetting_UT_001) |
| 1570 | { |
| 1571 | DisplayContent *p = new DisplayContent(nullptr); |
| 1572 | EXPECT_NE(p, nullptr); |
| 1573 | |
| 1574 | p->slot_valueChanged_dConfig_or_gSetting("customLogFiles"); |
| 1575 | p->deleteLater(); |
| 1576 | } |
| 1577 | |
| 1578 | TEST(DisplayContent_slot_requestShowRightMenu_UT, DisplayContent_slot_requestShowRightMenu_UT_001) |
| 1579 | { |
| 1580 | Stub stub; |
| 1581 | stub.set((QAction * (QMenu::*)(const QPoint &, QAction *)) ADDR(QMenu, exec), stub_menu_exec); |
| 1582 | |
| 1583 | DisplayContent *p = new DisplayContent(nullptr); |
| 1584 | EXPECT_NE(p, nullptr); |
| 1585 | QPoint point(20, 10); |
| 1586 | p->m_flag = OtherLog; |
| 1587 | QStandardItem * standItem = new QStandardItem (); |
| 1588 | standItem->setData("path", Qt::UserRole + 2); |
| 1589 | p->m_pModel->appendRow(QList<QStandardItem*>()<<new QStandardItem ()<<new QStandardItem ()); |
| 1590 | p->m_treeView->selectionModel()->select(p->m_pModel->index(0, 0), QItemSelectionModel::Rows | QItemSelectionModel::Select); |
| 1591 | p->m_treeView->setCurrentIndex(p->m_pModel->index(0, 0)); |
| 1592 | p->slot_requestShowRightMenu(point); |
| 1593 | p->deleteLater(); |
| 1594 | } |
| 1595 | |
| 1596 | class DisplayContent_slot_BtnSelected_UT_Param |
| 1597 | { |
| 1598 | public: |
| 1599 | explicit DisplayContent_slot_BtnSelected_UT_Param(int iIndex) |
| 1600 | { |
| 1601 | index = iIndex; |
| 1602 | } |
| 1603 | int index; |
| 1604 | }; |
| 1605 | |
| 1606 | class DisplayContent_slot_BtnSelected_UT : public ::testing::TestWithParam<DisplayContent_slot_BtnSelected_UT_Param> |
| 1607 | { |
| 1608 | }; |
| 1609 | |
| 1610 | const char *slot_BtnSelected_ModelIndex_data = ""; |
| 1611 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_slot_BtnSelected_UT, ::testing::Values(DisplayContent_slot_BtnSelected_UT_Param(0), DisplayContent_slot_BtnSelected_UT_Param(1), DisplayContent_slot_BtnSelected_UT_Param(2), DisplayContent_slot_BtnSelected_UT_Param(3), DisplayContent_slot_BtnSelected_UT_Param(4), DisplayContent_slot_BtnSelected_UT_Param(5), DisplayContent_slot_BtnSelected_UT_Param(6), DisplayContent_slot_BtnSelected_UT_Param(7), DisplayContent_slot_BtnSelected_UT_Param(8))); |
| 1612 | QVariant slot_BtnSelected_ModelIndex_data_Func(void *obj, int arole) |
| 1613 | { |
| 1614 | Q_UNUSED(obj); |
| 1615 | Q_UNUSED(arole); |
| 1616 | return QString(slot_BtnSelected_ModelIndex_data); |
| 1617 | } |
| 1618 | void DisplayContent_slot_BtnSelected_UT_DisplayContent_generateKernFile(int id, const QString &iSearchStr = "") |
| 1619 | { |
| 1620 | qDebug() << "DisplayContent_slot_BtnSelected_UT_DisplayContent_generateKernFile--"; |
| 1621 | } |
| 1622 | |
| 1623 | void DisplayContent_slot_BtnSelected_UT_generateJournalFile(int id, int lId, const QString &iSearchStr = "") |
| 1624 | { |
| 1625 | } |
| 1626 | void DisplayContent_slot_BtnSelected_UT_generateAppFile(QString path, int id, int lId, const QString &iSearchStr = "") |
| 1627 | { |
| 1628 | Q_UNUSED(path); |
| 1629 | Q_UNUSED(id); |
| 1630 | Q_UNUSED(lId); |
| 1631 | } |
| 1632 | void DisplayContent_slot_BtnSelected_UT_generateXorgFile(int id) |
| 1633 | { |
| 1634 | } |
| 1635 | |
| 1636 | void DisplayContent_slot_BtnSelected_UT_generateKwinFile(KWIN_FILTERS iFilters) |
| 1637 | { |
| 1638 | } |
| 1639 | |
| 1640 | void DisplayContent_slot_BtnSelected_UT_generateBootFile() |
| 1641 | { |
| 1642 | } |
| 1643 | |
| 1644 | TEST_P(DisplayContent_slot_BtnSelected_UT, DisplayContent_slot_BtnSelected_UT_001) |
| 1645 | { |
| 1646 | Stub stub; |
| 1647 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1648 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1649 | DisplayContent_slot_BtnSelected_UT_Param param = GetParam(); |
| 1650 | DisplayContent *p = new DisplayContent(nullptr); |
| 1651 | EXPECT_NE(p, nullptr); |
| 1652 | |
| 1653 | switch (param.index) { |
| 1654 | case 0: |
| 1655 | slot_BtnSelected_ModelIndex_data = JOUR_TREE_DATA; |
| 1656 | break; |
| 1657 | case 1: |
| 1658 | slot_BtnSelected_ModelIndex_data = BOOT_KLU_TREE_DATA; |
| 1659 | break; |
| 1660 | case 2: |
| 1661 | slot_BtnSelected_ModelIndex_data = DPKG_TREE_DATA; |
| 1662 | break; |
| 1663 | case 3: |
| 1664 | slot_BtnSelected_ModelIndex_data = KERN_TREE_DATA; |
| 1665 | break; |
| 1666 | case 4: |
| 1667 | slot_BtnSelected_ModelIndex_data = APP_TREE_DATA; |
| 1668 | break; |
| 1669 | case 5: |
| 1670 | slot_BtnSelected_ModelIndex_data = XORG_TREE_DATA; |
| 1671 | break; |
| 1672 | case 6: |
| 1673 | slot_BtnSelected_ModelIndex_data = LAST_TREE_DATA; |
| 1674 | break; |
| 1675 | case 7: |
| 1676 | slot_BtnSelected_ModelIndex_data = ".cache"; |
| 1677 | break; |
| 1678 | case 8: |
| 1679 | slot_BtnSelected_ModelIndex_data = ""; |
| 1680 | break; |
| 1681 | default: |
| 1682 | break; |
| 1683 | } |
| 1684 | |
| 1685 | stub.set(ADDR(QModelIndex, data), slot_BtnSelected_ModelIndex_data_Func); |
| 1686 | stub.set(ADDR(DisplayContent, generateKernFile), DisplayContent_slot_BtnSelected_UT_DisplayContent_generateKernFile); |
| 1687 | stub.set(ADDR(DisplayContent, generateJournalFile), DisplayContent_slot_BtnSelected_UT_generateJournalFile); |
| 1688 | stub.set(ADDR(DisplayContent, generateDpkgFile), DisplayContent_slot_BtnSelected_UT_DisplayContent_generateKernFile); |
| 1689 | stub.set(ADDR(DisplayContent, generateAppFile), DisplayContent_slot_BtnSelected_UT_generateAppFile); |
| 1690 | stub.set(ADDR(DisplayContent, generateXorgFile), DisplayContent_slot_BtnSelected_UT_generateXorgFile); |
| 1691 | stub.set(ADDR(DisplayContent, generateKwinFile), DisplayContent_slot_BtnSelected_UT_generateKwinFile); |
| 1692 | stub.set(ADDR(DisplayContent, generateNormalFile), DisplayContent_slot_BtnSelected_UT_generateXorgFile); |
| 1693 | stub.set(ADDR(DisplayContent, generateJournalBootFile), DisplayContent_slot_BtnSelected_UT_generateJournalFile); |
| 1694 | stub.set(ADDR(DisplayContent, generateBootFile), DisplayContent_slot_BtnSelected_UT_generateBootFile); |
| 1695 | p->slot_BtnSelected(0, 0, QModelIndex()); |
| 1696 | |
| 1697 | p->deleteLater(); |
| 1698 | } |
| 1699 | |
| 1700 | TEST(DisplayContent_slot_appLogs_UT, DisplayContent_slot_appLogs_UT_001) |
| 1701 | { |
| 1702 | Stub stub; |
| 1703 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1704 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1705 | DisplayContent *p = new DisplayContent(nullptr); |
| 1706 | EXPECT_NE(p, nullptr); |
| 1707 | stub.set(ADDR(DisplayContent, generateAppFile), DisplayContent_slot_BtnSelected_UT_generateAppFile); |
| 1708 | p->slot_appLogs(1, Utils::homePath + "/.cache/deepin/deepin-log-viewer/deepin-log-viewer.log"); |
| 1709 | p->deleteLater(); |
| 1710 | } |
| 1711 | |
| 1712 | class DisplayContent_slot_logCatelogueClicked_UT_Param |
| 1713 | { |
| 1714 | public: |
| 1715 | explicit DisplayContent_slot_logCatelogueClicked_UT_Param(int iIndex) |
| 1716 | { |
| 1717 | index = iIndex; |
| 1718 | } |
| 1719 | int index; |
| 1720 | }; |
| 1721 | |
| 1722 | class DisplayContent_slot_logCatelogueClicked_UT : public ::testing::TestWithParam<DisplayContent_slot_logCatelogueClicked_UT_Param> |
| 1723 | { |
| 1724 | }; |
| 1725 | |
| 1726 | QString slot_logCatelogueClicked_ModelIndex_data = ""; |
| 1727 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_slot_logCatelogueClicked_UT, ::testing::Values(DisplayContent_slot_logCatelogueClicked_UT_Param(0), DisplayContent_slot_logCatelogueClicked_UT_Param(1), DisplayContent_slot_logCatelogueClicked_UT_Param(2), DisplayContent_slot_logCatelogueClicked_UT_Param(3), DisplayContent_slot_logCatelogueClicked_UT_Param(4), DisplayContent_slot_logCatelogueClicked_UT_Param(5), DisplayContent_slot_logCatelogueClicked_UT_Param(6), DisplayContent_slot_logCatelogueClicked_UT_Param(7), DisplayContent_slot_logCatelogueClicked_UT_Param(8), DisplayContent_slot_logCatelogueClicked_UT_Param(9))); |
| 1728 | QVariant slot_logCatelogueClicked_ModelIndex_data_Func(void *obj, int arole) |
| 1729 | { |
| 1730 | return QString(slot_logCatelogueClicked_ModelIndex_data); |
| 1731 | } |
| 1732 | bool slot_logCatelogueClicked_ModelIndex_isValid_Func(void *obj) |
| 1733 | { |
| 1734 | return true; |
| 1735 | } |
| 1736 | |
| 1737 | QStringList stub_getFileInfo(const QString &flag) |
| 1738 | { |
| 1739 | Q_UNUSED(flag); |
| 1740 | return QStringList() << "test"; |
| 1741 | } |
| 1742 | |
| 1743 | TEST_P(DisplayContent_slot_logCatelogueClicked_UT, DisplayContent_slot_logCatelogueClicked_UT_001) |
| 1744 | { |
| 1745 | DisplayContent_slot_logCatelogueClicked_UT_Param param = GetParam(); |
| 1746 | DisplayContent *p = new DisplayContent(nullptr); |
| 1747 | EXPECT_NE(p, nullptr); |
| 1748 | Stub stub; |
| 1749 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1750 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1751 | switch (param.index) { |
| 1752 | case 0: |
| 1753 | slot_logCatelogueClicked_ModelIndex_data = JOUR_TREE_DATA; |
| 1754 | break; |
| 1755 | case 1: |
| 1756 | slot_logCatelogueClicked_ModelIndex_data = DPKG_TREE_DATA; |
| 1757 | break; |
| 1758 | case 2: |
| 1759 | slot_logCatelogueClicked_ModelIndex_data = XORG_TREE_DATA; |
| 1760 | break; |
| 1761 | case 3: |
| 1762 | slot_logCatelogueClicked_ModelIndex_data = BOOT_TREE_DATA; |
| 1763 | break; |
| 1764 | case 4: |
| 1765 | slot_logCatelogueClicked_ModelIndex_data = KERN_TREE_DATA; |
| 1766 | break; |
| 1767 | case 5: |
| 1768 | slot_logCatelogueClicked_ModelIndex_data = APP_TREE_DATA; |
| 1769 | break; |
| 1770 | case 6: |
| 1771 | slot_logCatelogueClicked_ModelIndex_data = LAST_TREE_DATA; |
| 1772 | break; |
| 1773 | case 7: |
| 1774 | slot_logCatelogueClicked_ModelIndex_data = KWIN_TREE_DATA; |
| 1775 | break; |
| 1776 | case 8: |
| 1777 | slot_logCatelogueClicked_ModelIndex_data = BOOT_KLU_TREE_DATA; |
| 1778 | break; |
| 1779 | case 9: |
| 1780 | slot_logCatelogueClicked_ModelIndex_data = ""; |
| 1781 | break; |
| 1782 | default: |
| 1783 | break; |
| 1784 | } |
| 1785 | stub.set(ADDR(DisplayContent, generateKernFile), DisplayContent_slot_BtnSelected_UT_DisplayContent_generateKernFile); |
| 1786 | stub.set(ADDR(DisplayContent, generateJournalFile), DisplayContent_slot_BtnSelected_UT_generateJournalFile); |
| 1787 | stub.set(ADDR(DisplayContent, generateDpkgFile), DisplayContent_slot_BtnSelected_UT_DisplayContent_generateKernFile); |
| 1788 | stub.set(ADDR(DisplayContent, generateAppFile), DisplayContent_slot_BtnSelected_UT_generateAppFile); |
| 1789 | stub.set(ADDR(DisplayContent, generateXorgFile), DisplayContent_slot_BtnSelected_UT_generateXorgFile); |
| 1790 | stub.set(ADDR(DisplayContent, generateKwinFile), DisplayContent_slot_BtnSelected_UT_generateKwinFile); |
| 1791 | stub.set(ADDR(DisplayContent, generateNormalFile), DisplayContent_slot_BtnSelected_UT_generateXorgFile); |
| 1792 | stub.set(ADDR(DisplayContent, generateJournalBootFile), DisplayContent_slot_BtnSelected_UT_generateJournalFile); |
| 1793 | stub.set(ADDR(DisplayContent, generateBootFile), DisplayContent_slot_BtnSelected_UT_generateBootFile); |
| 1794 | stub.set(ADDR(QModelIndex, data), slot_logCatelogueClicked_ModelIndex_data_Func); |
| 1795 | stub.set(ADDR(QModelIndex, isValid), slot_logCatelogueClicked_ModelIndex_isValid_Func); |
| 1796 | stub.set(ADDR(DLDBusHandler, getFileInfo), stub_getFileInfo); |
| 1797 | p->m_flag = KERN; |
| 1798 | p->slot_logCatelogueClicked(QModelIndex()); |
| 1799 | p->deleteLater(); |
| 1800 | } |
| 1801 | |
| 1802 | class DisplayContent_slot_exportClicked_UT_Param |
| 1803 | { |
| 1804 | public: |
| 1805 | explicit DisplayContent_slot_exportClicked_UT_Param(int iIndex) |
| 1806 | { |
| 1807 | index = iIndex; |
| 1808 | } |
| 1809 | int index; |
| 1810 | }; |
| 1811 | |
| 1812 | class DisplayContent_slot_exportClicked_UT : public ::testing::TestWithParam<DisplayContent_slot_exportClicked_UT_Param> |
| 1813 | { |
| 1814 | }; |
| 1815 | |
| 1816 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_slot_exportClicked_UT, ::testing::Values(DisplayContent_slot_exportClicked_UT_Param(0), DisplayContent_slot_exportClicked_UT_Param(1), DisplayContent_slot_exportClicked_UT_Param(2), DisplayContent_slot_exportClicked_UT_Param(3), DisplayContent_slot_exportClicked_UT_Param(4), DisplayContent_slot_exportClicked_UT_Param(5), DisplayContent_slot_exportClicked_UT_Param(6), DisplayContent_slot_exportClicked_UT_Param(7), DisplayContent_slot_exportClicked_UT_Param(8), DisplayContent_slot_exportClicked_UT_Param(9))); |
| 1817 | QString slot_exportClicked_ModelIndex_data = ""; |
| 1818 | |
| 1819 | |
| 1820 | TEST(DisplayContent_slot_statusChagned_UT, DisplayContent_slot_statusChagned_UT_001) |
| 1821 | { |
| 1822 | DisplayContent *p = new DisplayContent(nullptr); |
| 1823 | EXPECT_NE(p, nullptr); |
| 1824 | Stub stub; |
| 1825 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1826 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1827 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), QThreadPool_start); |
| 1828 | stub.set(ADDR(QThread, start), QThread_start); |
| 1829 | p->slot_statusChagned("OK"); |
| 1830 | p->deleteLater(); |
| 1831 | } |
| 1832 | |
| 1833 | TEST(DisplayContent_slot_dpkgFinished_UT, DisplayContent_slot_dpkgFinished_UT_001) |
| 1834 | { |
| 1835 | Stub stub; |
| 1836 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1837 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1838 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), QThreadPool_start); |
| 1839 | stub.set(ADDR(QThread, start), QThread_start); |
| 1840 | DisplayContent *p = new DisplayContent(nullptr); |
| 1841 | EXPECT_NE(p, nullptr); |
| 1842 | |
| 1843 | QList<LOG_MSG_DPKG> list; |
| 1844 | for (int i = 0; i < 100; ++i) { |
| 1845 | LOG_MSG_DPKG item; |
| 1846 | item.msg = ""; |
| 1847 | item.dateTime = ""; |
| 1848 | item.action = ""; |
| 1849 | list.append(item); |
| 1850 | } |
| 1851 | p->m_flag = DPKG; |
| 1852 | p->slot_dpkgFinished(); |
| 1853 | p->m_flag = NONE; |
| 1854 | p->slot_dpkgFinished(); |
| 1855 | delete p; |
| 1856 | } |
| 1857 | |
| 1858 | TEST(DisplayContent_slot_XorgFinished_UT, DisplayContent_slot_XorgFinished_UT_001) |
| 1859 | { |
| 1860 | Stub stub; |
| 1861 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1862 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1863 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), QThreadPool_start); |
| 1864 | stub.set(ADDR(QThread, start), QThread_start); |
| 1865 | DisplayContent *p = new DisplayContent(nullptr); |
| 1866 | EXPECT_NE(p, nullptr); |
| 1867 | QList<LOG_MSG_XORG> list; |
| 1868 | LOG_MSG_XORG item; |
| 1869 | for (int i = 0; i < 100; ++i) { |
| 1870 | item.msg = QString("msg%1").arg(i); |
| 1871 | item.offset = "3.541"; |
| 1872 | list.append(item); |
| 1873 | } |
| 1874 | p->m_flag = XORG; |
| 1875 | p->slot_XorgFinished(); |
| 1876 | p->m_flag = NONE; |
| 1877 | p->slot_XorgFinished(); |
| 1878 | p->deleteLater(); |
| 1879 | } |
| 1880 | |
| 1881 | TEST(DisplayContent_slot_bootFinished_UT, DisplayContent_slot_bootFinished_UT_001) |
| 1882 | { |
| 1883 | Stub stub; |
| 1884 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1885 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1886 | DisplayContent *p = new DisplayContent(nullptr); |
| 1887 | EXPECT_NE(p, nullptr); |
| 1888 | QList<LOG_MSG_BOOT> list; |
| 1889 | LOG_MSG_BOOT item; |
| 1890 | for (int i = 0; i < 100; ++i) { |
| 1891 | item.msg = QString("msg%1").arg(i); |
| 1892 | item.status = "OK"; |
| 1893 | list.append(item); |
| 1894 | } |
| 1895 | p->m_flag = BOOT; |
| 1896 | p->slot_bootFinished(); |
| 1897 | p->m_flag = NONE; |
| 1898 | p->slot_bootFinished(); |
| 1899 | p->deleteLater(); |
| 1900 | } |
| 1901 | TEST(DisplayContent_slot_kernFinished_UT, DisplayContent_slot_kernFinished_UT_001) |
| 1902 | { |
| 1903 | Stub stub; |
| 1904 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1905 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1906 | DisplayContent *p = new DisplayContent(nullptr); |
| 1907 | EXPECT_NE(p, nullptr); |
| 1908 | QList<LOG_MSG_JOURNAL> list; |
| 1909 | LOG_MSG_JOURNAL item; |
| 1910 | for (int i = 0; i < 100; ++i) { |
| 1911 | item.msg = QString("msg%1").arg(i); |
| 1912 | item.level = "Debug"; |
| 1913 | item.daemonId = "1"; |
| 1914 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 1915 | item.hostName = "test_host"; |
| 1916 | item.daemonName = "test_daemon"; |
| 1917 | list.append(item); |
| 1918 | } |
| 1919 | p->m_flag = KERN; |
| 1920 | p->slot_kernFinished(); |
| 1921 | p->m_flag = NONE; |
| 1922 | p->slot_kernFinished(); |
| 1923 | p->deleteLater(); |
| 1924 | } |
| 1925 | TEST(DisplayContent_slot_kwinFinished_UT, DisplayContent_slot_kwinFinished_UT_001) |
| 1926 | { |
| 1927 | Stub stub; |
| 1928 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1929 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1930 | DisplayContent *p = new DisplayContent(nullptr); |
| 1931 | EXPECT_NE(p, nullptr); |
| 1932 | QList<LOG_MSG_KWIN> list; |
| 1933 | LOG_MSG_KWIN item; |
| 1934 | for (int i = 0; i < 100; ++i) { |
| 1935 | item.msg = QString("msg%1").arg(i); |
| 1936 | list.append(item); |
| 1937 | } |
| 1938 | p->m_flag = Kwin; |
| 1939 | p->slot_kwinFinished(); |
| 1940 | p->m_flag = NONE; |
| 1941 | p->slot_kwinFinished(); |
| 1942 | p->deleteLater(); |
| 1943 | } |
| 1944 | |
| 1945 | TEST(DisplayContent_slot_journalBootFinished_UT, DisplayContent_slot_journalBootFinished_UT_001) |
| 1946 | { |
| 1947 | Stub stub; |
| 1948 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1949 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 1950 | DisplayContent *p = new DisplayContent(nullptr); |
| 1951 | EXPECT_NE(p, nullptr); |
| 1952 | p->slot_journalBootFinished(); |
| 1953 | p->deleteLater(); |
| 1954 | } |
| 1955 | |
| 1956 | TEST(DisplayContent_slot_OOCFinished_UT, DisplayContent_slot_OOCFinished_UT_001) |
| 1957 | { |
| 1958 | DisplayContent *p = new DisplayContent(nullptr); |
| 1959 | EXPECT_NE(p, nullptr); |
| 1960 | QStandardItem * standItem = new QStandardItem (); |
| 1961 | standItem->setData("path", Qt::UserRole + 2); |
| 1962 | p->m_pModel->appendRow(QList<QStandardItem*>()<<new QStandardItem ()<<new QStandardItem ()); |
| 1963 | p->m_treeView->selectionModel()->select(p->m_pModel->index(0, 0), QItemSelectionModel::Rows | QItemSelectionModel::Select); |
| 1964 | p->m_treeView->setCurrentIndex(p->m_pModel->index(0, 0)); |
| 1965 | p->m_pLogBackend->m_OOCCurrentIndex = 1; |
| 1966 | p->m_flag = OtherLog; |
| 1967 | p->slot_OOCFinished(); |
| 1968 | p->slot_OOCFinished(); |
| 1969 | p->m_flag = CustomLog; |
| 1970 | p->slot_OOCFinished(); |
| 1971 | p->slot_OOCFinished(); |
| 1972 | p->deleteLater(); |
| 1973 | } |
| 1974 | |
| 1975 | TEST(DisplayContent_slot_OOCData_UT, DisplayContent_slot_OOCData_UT_001) |
| 1976 | { |
| 1977 | DisplayContent *p = new DisplayContent(nullptr); |
| 1978 | EXPECT_NE(p, nullptr); |
| 1979 | QStandardItem * standItem = new QStandardItem (); |
| 1980 | standItem->setData("path", Qt::UserRole + 2); |
| 1981 | p->m_pModel->appendRow(QList<QStandardItem*>()<<new QStandardItem ()<<new QStandardItem ()); |
| 1982 | p->m_treeView->selectionModel()->select(p->m_pModel->index(0, 0), QItemSelectionModel::Rows | QItemSelectionModel::Select); |
| 1983 | p->m_treeView->setCurrentIndex(p->m_pModel->index(0, 0)); |
| 1984 | p->m_pLogBackend->m_OOCCurrentIndex = 1; |
| 1985 | p->m_flag = OtherLog; |
| 1986 | p->slot_OOCData("data"); |
| 1987 | p->m_flag = CustomLog; |
| 1988 | p->slot_OOCData("data"); |
| 1989 | p->deleteLater(); |
| 1990 | } |
| 1991 | |
| 1992 | class DisplayContent_slot_journalData_UT_Param |
| 1993 | { |
| 1994 | public: |
| 1995 | DisplayContent_slot_journalData_UT_Param(LOG_FLAG iFlag, bool iIndexEqual, bool iListIsEmpty, bool iFirstLoadPageData) |
| 1996 | : m_flag(iFlag) |
| 1997 | , indexEqual(iIndexEqual) |
| 1998 | , listIsEmpty(iListIsEmpty) |
| 1999 | , m_firstLoadPageData(iFirstLoadPageData) |
| 2000 | { |
| 2001 | } |
| 2002 | LOG_FLAG m_flag; |
| 2003 | bool indexEqual; |
| 2004 | bool listIsEmpty; |
| 2005 | bool m_firstLoadPageData; |
| 2006 | }; |
| 2007 | |
| 2008 | class DisplayContent_slot_journalData_UT : public ::testing::TestWithParam<DisplayContent_slot_journalData_UT_Param> |
| 2009 | { |
| 2010 | }; |
| 2011 | |
| 2012 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_slot_journalData_UT, ::testing::Values(DisplayContent_slot_journalData_UT_Param(JOURNAL, true, true, true), DisplayContent_slot_journalData_UT_Param(JOURNAL, true, true, false), DisplayContent_slot_journalData_UT_Param(JOURNAL, true, false, true), DisplayContent_slot_journalData_UT_Param(JOURNAL, true, false, false), DisplayContent_slot_journalData_UT_Param(JOURNAL, false, true, true), DisplayContent_slot_journalData_UT_Param(JOURNAL, false, true, false), DisplayContent_slot_journalData_UT_Param(JOURNAL, false, false, true), DisplayContent_slot_journalData_UT_Param(JOURNAL, false, false, false), DisplayContent_slot_journalData_UT_Param(NONE, true, true, true), DisplayContent_slot_journalData_UT_Param(NONE, true, true, false), DisplayContent_slot_journalData_UT_Param(NONE, true, false, true), DisplayContent_slot_journalData_UT_Param(NONE, true, false, false), DisplayContent_slot_journalData_UT_Param(NONE, false, true, true), DisplayContent_slot_journalData_UT_Param(NONE, false, true, false), DisplayContent_slot_journalData_UT_Param(NONE, false, false, true), DisplayContent_slot_journalData_UT_Param(NONE, false, false, false))); |
| 2013 | |
| 2014 | TEST_P(DisplayContent_slot_journalData_UT, DisplayContent_slot_journalData_UT_001) |
| 2015 | { |
| 2016 | Stub stub; |
| 2017 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2018 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2019 | DisplayContent_slot_journalData_UT_Param param = GetParam(); |
| 2020 | DisplayContent *p = new DisplayContent(nullptr); |
| 2021 | EXPECT_NE(p, nullptr); |
| 2022 | QList<LOG_MSG_JOURNAL> list; |
| 2023 | if (!param.listIsEmpty) { |
| 2024 | LOG_MSG_JOURNAL item; |
| 2025 | for (int i = 0; i < 100; ++i) { |
| 2026 | item.msg = QString("msg%1").arg(i); |
| 2027 | item.level = "Debug"; |
| 2028 | item.daemonId = "1"; |
| 2029 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2030 | item.hostName = "test_host"; |
| 2031 | item.daemonName = "test_daemon"; |
| 2032 | list.append(item); |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | p->m_flag = param.m_flag; |
| 2037 | p->m_pLogBackend->m_journalCurrentIndex = 0; |
| 2038 | p->m_firstLoadPageData = param.m_firstLoadPageData; |
| 2039 | p->slot_journalData(list); |
| 2040 | p->deleteLater(); |
| 2041 | } |
| 2042 | |
| 2043 | class DisplayContent_slot_journalBootData_UT_Param |
| 2044 | { |
| 2045 | public: |
| 2046 | DisplayContent_slot_journalBootData_UT_Param(LOG_FLAG iFlag, bool iIndexEqual, bool iListIsEmpty, bool iFirstLoadPageData) |
| 2047 | : m_flag(iFlag) |
| 2048 | , indexEqual(iIndexEqual) |
| 2049 | , listIsEmpty(iListIsEmpty) |
| 2050 | , m_firstLoadPageData(iFirstLoadPageData) |
| 2051 | { |
| 2052 | } |
| 2053 | LOG_FLAG m_flag; |
| 2054 | bool indexEqual; |
| 2055 | bool listIsEmpty; |
| 2056 | bool m_firstLoadPageData; |
| 2057 | }; |
| 2058 | |
| 2059 | class DisplayContent_slot_journalBootData_UT : public ::testing::TestWithParam<DisplayContent_slot_journalBootData_UT_Param> |
| 2060 | { |
| 2061 | }; |
| 2062 | |
| 2063 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_slot_journalBootData_UT, ::testing::Values(DisplayContent_slot_journalBootData_UT_Param(BOOT_KLU, true, true, true), DisplayContent_slot_journalBootData_UT_Param(BOOT_KLU, true, true, false), DisplayContent_slot_journalBootData_UT_Param(BOOT_KLU, true, false, true), DisplayContent_slot_journalBootData_UT_Param(BOOT_KLU, true, false, false), DisplayContent_slot_journalBootData_UT_Param(BOOT_KLU, false, true, true), DisplayContent_slot_journalBootData_UT_Param(BOOT_KLU, false, true, false), DisplayContent_slot_journalBootData_UT_Param(BOOT_KLU, false, false, true), DisplayContent_slot_journalBootData_UT_Param(BOOT_KLU, false, false, false), DisplayContent_slot_journalBootData_UT_Param(NONE, true, true, true), DisplayContent_slot_journalBootData_UT_Param(NONE, true, true, false), DisplayContent_slot_journalBootData_UT_Param(NONE, true, false, true), DisplayContent_slot_journalBootData_UT_Param(NONE, true, false, false), DisplayContent_slot_journalBootData_UT_Param(NONE, false, true, true), DisplayContent_slot_journalBootData_UT_Param(NONE, false, true, false), DisplayContent_slot_journalBootData_UT_Param(NONE, false, false, true), DisplayContent_slot_journalBootData_UT_Param(NONE, false, false, false))); |
| 2064 | |
| 2065 | TEST_P(DisplayContent_slot_journalBootData_UT, DisplayContent_slot_journalBootData_UT_001) |
| 2066 | { |
| 2067 | Stub stub; |
| 2068 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2069 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2070 | DisplayContent_slot_journalBootData_UT_Param param = GetParam(); |
| 2071 | DisplayContent *p = new DisplayContent(nullptr); |
| 2072 | EXPECT_NE(p, nullptr); |
| 2073 | QList<LOG_MSG_JOURNAL> list; |
| 2074 | if (!param.listIsEmpty) { |
| 2075 | LOG_MSG_JOURNAL item; |
| 2076 | for (int i = 0; i < 100; ++i) { |
| 2077 | item.msg = QString("msg%1").arg(i); |
| 2078 | item.level = "Debug"; |
| 2079 | item.daemonId = "1"; |
| 2080 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2081 | item.hostName = "test_host"; |
| 2082 | item.daemonName = "test_daemon"; |
| 2083 | list.append(item); |
| 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | p->m_flag = param.m_flag; |
| 2088 | p->m_pLogBackend->m_journalBootCurrentIndex = 0; |
| 2089 | p->m_firstLoadPageData = param.m_firstLoadPageData; |
| 2090 | int index = param.indexEqual ? 0 : 1; |
| 2091 | p->slot_journalBootData(list); |
| 2092 | p->deleteLater(); |
| 2093 | } |
| 2094 | |
| 2095 | TEST(DisplayContent_slot_applicationFinished_UT, DisplayContent_slot_applicationFinished_UT_001) |
| 2096 | { |
| 2097 | Stub stub; |
| 2098 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2099 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2100 | DisplayContent *p = new DisplayContent(nullptr); |
| 2101 | EXPECT_NE(p, nullptr); |
| 2102 | QList<LOG_MSG_APPLICATOIN> list; |
| 2103 | LOG_MSG_APPLICATOIN item; |
| 2104 | for (int i = 0; i < 100; ++i) { |
| 2105 | item.msg = QString("msg%1").arg(i); |
| 2106 | item.level = "Debug"; |
| 2107 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2108 | item.src = "test_src"; |
| 2109 | list.append(item); |
| 2110 | } |
| 2111 | p->m_flag = APP; |
| 2112 | p->slot_applicationFinished(); |
| 2113 | p->m_flag = NONE; |
| 2114 | p->slot_applicationFinished(); |
| 2115 | p->deleteLater(); |
| 2116 | } |
| 2117 | |
| 2118 | TEST(DisplayContent_slot_NormalFinished_UT, DisplayContent_NormalFinished_UT_001) |
| 2119 | { |
| 2120 | Stub stub; |
| 2121 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2122 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2123 | DisplayContent *p = new DisplayContent(nullptr); |
| 2124 | EXPECT_NE(p, nullptr); |
| 2125 | p->m_flag = Normal; |
| 2126 | p->slot_normalFinished(); |
| 2127 | p->m_flag = NONE; |
| 2128 | p->slot_normalFinished(); |
| 2129 | p->deleteLater(); |
| 2130 | } |
| 2131 | TEST(DisplayContent_slot_themeChanged_UT, DisplayContent_slot_themeChanged_UT_001) |
| 2132 | { |
| 2133 | Stub stub; |
| 2134 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2135 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2136 | DisplayContent *p = new DisplayContent(nullptr); |
| 2137 | EXPECT_NE(p, nullptr); |
| 2138 | p->deleteLater(); |
| 2139 | } |
| 2140 | |
| 2141 | TEST(DisplayContent_resizeEvent_UT, DisplayContent_resizeEvent_UT_001) |
| 2142 | { |
| 2143 | Stub stub; |
| 2144 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2145 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2146 | DisplayContent *p = new DisplayContent(nullptr); |
| 2147 | EXPECT_NE(p, nullptr); |
| 2148 | p->resizeEvent(nullptr); |
| 2149 | p->deleteLater(); |
| 2150 | } |
| 2151 | |
| 2152 | ////TEST(DisplayContent_paintEvent_UT, DisplayContent_paintEvent_UT_001) |
| 2153 | ////{ |
| 2154 | //// DisplayContent *p = new DisplayContent(nullptr); |
| 2155 | //// EXPECT_NE(p, nullptr); |
| 2156 | //// p->paintEvent(new QPaintEvent(p->rect())); |
| 2157 | //// p->deleteLater(); |
| 2158 | ////} |
| 2159 | class DisplayContent_slot_vScrollValueChanged_UT_Param |
| 2160 | { |
| 2161 | public: |
| 2162 | DisplayContent_slot_vScrollValueChanged_UT_Param(LOG_FLAG iFlag, bool iIsTreeView, bool iIsTreeViewHeight, bool iIsLastHeight, bool iIsLoadData, bool iIsOutLoad) |
| 2163 | { |
| 2164 | m_flag = iFlag; |
| 2165 | isTreeView = iIsTreeView; |
| 2166 | isTreeViewHeight = iIsTreeViewHeight; |
| 2167 | isLastHeight = iIsLastHeight; |
| 2168 | isLoadData = iIsLoadData; |
| 2169 | isOutLoad = iIsOutLoad; |
| 2170 | } |
| 2171 | LOG_FLAG m_flag; |
| 2172 | bool isTreeView; |
| 2173 | bool isTreeViewHeight; |
| 2174 | bool isLastHeight; |
| 2175 | bool isLoadData; |
| 2176 | bool isOutLoad; |
| 2177 | }; |
| 2178 | |
| 2179 | class DisplayContent_slot_vScrollValueChanged_UT : public ::testing::TestWithParam<DisplayContent_slot_vScrollValueChanged_UT_Param> |
| 2180 | { |
| 2181 | }; |
| 2182 | int DisplayContent_slot_vScrollValueChanged_treeView_singleRowHeight = -1; |
| 2183 | int DisplayContent_slot_vScrollValueChanged_treeView_singleRowHeight_Func(void *obj) |
| 2184 | { |
| 2185 | return DisplayContent_slot_vScrollValueChanged_treeView_singleRowHeight; |
| 2186 | } |
| 2187 | |
| 2188 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_slot_vScrollValueChanged_UT, ::testing::Values(DisplayContent_slot_vScrollValueChanged_UT_Param(JOURNAL, false, true, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(JOURNAL, true, false, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(JOURNAL, true, true, false, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(JOURNAL, true, true, true, false, true), DisplayContent_slot_vScrollValueChanged_UT_Param(JOURNAL, true, true, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(JOURNAL, true, true, true, true, false), DisplayContent_slot_vScrollValueChanged_UT_Param(BOOT_KLU, false, true, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(BOOT_KLU, true, false, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(BOOT_KLU, true, true, false, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(BOOT_KLU, true, true, true, false, true), DisplayContent_slot_vScrollValueChanged_UT_Param(BOOT_KLU, true, true, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(BOOT_KLU, true, true, true, true, false), DisplayContent_slot_vScrollValueChanged_UT_Param(APP, false, true, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(APP, true, false, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(APP, true, true, false, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(APP, true, true, true, false, true), DisplayContent_slot_vScrollValueChanged_UT_Param(APP, true, true, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(APP, true, true, true, true, false), DisplayContent_slot_vScrollValueChanged_UT_Param(KERN, false, true, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(KERN, true, false, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(KERN, true, true, false, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(KERN, true, true, true, false, true), DisplayContent_slot_vScrollValueChanged_UT_Param(KERN, true, true, true, true, true), DisplayContent_slot_vScrollValueChanged_UT_Param(KERN, true, true, true, true, false))); |
| 2189 | |
| 2190 | TEST_P(DisplayContent_slot_vScrollValueChanged_UT, DisplayContent_slot_vScrollValueChanged_UT_001) |
| 2191 | { |
| 2192 | Stub stub; |
| 2193 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2194 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2195 | DisplayContent_slot_vScrollValueChanged_UT_Param param = GetParam(); |
| 2196 | DisplayContent *p = new DisplayContent(nullptr); |
| 2197 | EXPECT_NE(p, nullptr); |
| 2198 | int valuePixel = 0; |
| 2199 | |
| 2200 | p->m_flag = param.m_flag; |
| 2201 | if (!param.isTreeView) { |
| 2202 | p->m_treeView->deleteLater(); |
| 2203 | p->m_treeView = nullptr; |
| 2204 | } |
| 2205 | DisplayContent_slot_vScrollValueChanged_treeView_singleRowHeight = param.isTreeViewHeight ? 20 : -1; |
| 2206 | if (param.isLoadData) { |
| 2207 | valuePixel = 190 * DisplayContent_slot_vScrollValueChanged_treeView_singleRowHeight; |
| 2208 | } else { |
| 2209 | valuePixel = 5 * DisplayContent_slot_vScrollValueChanged_treeView_singleRowHeight; |
| 2210 | } |
| 2211 | if (param.isOutLoad) { |
| 2212 | p->m_limitTag = -1; |
| 2213 | } else { |
| 2214 | p->m_limitTag = (valuePixel / DisplayContent_slot_vScrollValueChanged_treeView_singleRowHeight + 25) / 200; |
| 2215 | } |
| 2216 | stub.set(ADDR(LogTreeView, singleRowHeight), DisplayContent_slot_vScrollValueChanged_treeView_singleRowHeight_Func); |
| 2217 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), QThreadPool_start); |
| 2218 | stub.set(ADDR(QThread, start), QThread_start); |
| 2219 | if (!param.isLastHeight) { |
| 2220 | p->m_treeViewLastScrollValue = valuePixel; |
| 2221 | } else { |
| 2222 | p->m_treeViewLastScrollValue = -1; |
| 2223 | } |
| 2224 | p->slot_vScrollValueChanged(valuePixel); |
| 2225 | p->deleteLater(); |
| 2226 | } |
| 2227 | |
| 2228 | class DisplayContent_slot_searchResult_UT_Param |
| 2229 | { |
| 2230 | public: |
| 2231 | DisplayContent_slot_searchResult_UT_Param(LOG_FLAG iFlag, bool iIsContains, bool iIsSearchEmpty) |
| 2232 | : m_flag(iFlag) |
| 2233 | , isContains(iIsContains) |
| 2234 | , isSearchEmpty(iIsSearchEmpty) |
| 2235 | { |
| 2236 | } |
| 2237 | LOG_FLAG m_flag; |
| 2238 | bool isContains; |
| 2239 | bool isSearchEmpty; |
| 2240 | }; |
| 2241 | bool DisplayContent_slot_searchResult_QString_contains = false; |
| 2242 | bool DisplayContent_slot_searchResult_QString_contains_Func(const QString &s, Qt::CaseSensitivity cs) |
| 2243 | { |
| 2244 | Q_UNUSED(s) |
| 2245 | Q_UNUSED(cs) |
| 2246 | return DisplayContent_slot_searchResult_QString_contains; |
| 2247 | } |
| 2248 | class DisplayContent_slot_searchResult_UT : public ::testing::TestWithParam<DisplayContent_slot_searchResult_UT_Param> |
| 2249 | { |
| 2250 | }; |
| 2251 | |
| 2252 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_slot_searchResult_UT, ::testing::Values(DisplayContent_slot_searchResult_UT_Param(JOURNAL, true, true), DisplayContent_slot_searchResult_UT_Param(JOURNAL, false, true), DisplayContent_slot_searchResult_UT_Param(JOURNAL, true, false), DisplayContent_slot_searchResult_UT_Param(NONE, true, true), DisplayContent_slot_searchResult_UT_Param(BOOT_KLU, true, true), DisplayContent_slot_searchResult_UT_Param(BOOT_KLU, false, true), DisplayContent_slot_searchResult_UT_Param(BOOT_KLU, true, false), DisplayContent_slot_searchResult_UT_Param(KERN, true, true), DisplayContent_slot_searchResult_UT_Param(KERN, false, true), DisplayContent_slot_searchResult_UT_Param(KERN, true, false), DisplayContent_slot_searchResult_UT_Param(BOOT, true, true), DisplayContent_slot_searchResult_UT_Param(BOOT, false, true), DisplayContent_slot_searchResult_UT_Param(BOOT, true, false), DisplayContent_slot_searchResult_UT_Param(XORG, true, true), DisplayContent_slot_searchResult_UT_Param(XORG, false, true), DisplayContent_slot_searchResult_UT_Param(XORG, true, false), DisplayContent_slot_searchResult_UT_Param(DPKG, true, true), DisplayContent_slot_searchResult_UT_Param(DPKG, false, true), DisplayContent_slot_searchResult_UT_Param(DPKG, true, false), DisplayContent_slot_searchResult_UT_Param(APP, true, true), DisplayContent_slot_searchResult_UT_Param(APP, false, true), DisplayContent_slot_searchResult_UT_Param(APP, true, false), DisplayContent_slot_searchResult_UT_Param(Normal, true, true), DisplayContent_slot_searchResult_UT_Param(Normal, false, true), DisplayContent_slot_searchResult_UT_Param(Normal, true, false), DisplayContent_slot_searchResult_UT_Param(Kwin, true, true), DisplayContent_slot_searchResult_UT_Param(Kwin, false, true), DisplayContent_slot_searchResult_UT_Param(Kwin, true, false))); |
| 2253 | |
| 2254 | TEST_P(DisplayContent_slot_searchResult_UT, DisplayContent_slot_searchResult_UT_001) |
| 2255 | { |
| 2256 | Stub stub; |
| 2257 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2258 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2259 | DisplayContent_slot_searchResult_UT_Param param = GetParam(); |
| 2260 | DisplayContent *p = new DisplayContent(nullptr); |
| 2261 | EXPECT_NE(p, nullptr); |
| 2262 | p->m_flag = param.m_flag; |
| 2263 | switch (p->m_flag) { |
| 2264 | case JOURNAL: { |
| 2265 | QList<LOG_MSG_JOURNAL> list; |
| 2266 | LOG_MSG_JOURNAL item; |
| 2267 | for (int i = 0; i < 100; ++i) { |
| 2268 | item.msg = QString("msg%1").arg(i); |
| 2269 | item.level = "Debug"; |
| 2270 | item.daemonId = "1"; |
| 2271 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2272 | item.hostName = "test_host"; |
| 2273 | item.daemonName = "test_daemon"; |
| 2274 | list.append(item); |
| 2275 | } |
| 2276 | p->m_pLogBackend->jBootListOrigin.append(list); |
| 2277 | break; |
| 2278 | } |
| 2279 | case BOOT_KLU: { |
| 2280 | QList<LOG_MSG_JOURNAL> list; |
| 2281 | LOG_MSG_JOURNAL item; |
| 2282 | for (int i = 0; i < 100; ++i) { |
| 2283 | item.msg = QString("msg%1").arg(i); |
| 2284 | item.level = "Debug"; |
| 2285 | item.daemonId = "1"; |
| 2286 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2287 | item.hostName = "test_host"; |
| 2288 | item.daemonName = "test_daemon"; |
| 2289 | list.append(item); |
| 2290 | } |
| 2291 | p->m_pLogBackend->jBootListOrigin.append(list); |
| 2292 | break; |
| 2293 | } |
| 2294 | case KERN: { |
| 2295 | QList<LOG_MSG_JOURNAL> list; |
| 2296 | LOG_MSG_JOURNAL item; |
| 2297 | for (int i = 0; i < 100; ++i) { |
| 2298 | item.msg = QString("msg%1").arg(i); |
| 2299 | item.level = "Debug"; |
| 2300 | item.daemonId = "1"; |
| 2301 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2302 | item.hostName = "test_host"; |
| 2303 | item.daemonName = "test_daemon"; |
| 2304 | list.append(item); |
| 2305 | } |
| 2306 | p->m_pLogBackend->kListOrigin.append(list); |
| 2307 | break; |
| 2308 | } |
| 2309 | case BOOT: { |
| 2310 | break; |
| 2311 | } |
| 2312 | case XORG: { |
| 2313 | QList<LOG_MSG_XORG> list; |
| 2314 | LOG_MSG_XORG item; |
| 2315 | for (int i = 0; i < 100; ++i) { |
| 2316 | item.msg = QString("msg%1").arg(i); |
| 2317 | item.offset = "3.541"; |
| 2318 | list.append(item); |
| 2319 | } |
| 2320 | p->m_pLogBackend->xListOrigin.append(list); |
| 2321 | break; |
| 2322 | } |
| 2323 | case DPKG: { |
| 2324 | QList<LOG_MSG_DPKG> list; |
| 2325 | for (int i = 0; i < 100; ++i) { |
| 2326 | LOG_MSG_DPKG item; |
| 2327 | item.msg = ""; |
| 2328 | item.dateTime = ""; |
| 2329 | item.action = ""; |
| 2330 | list.append(item); |
| 2331 | } |
| 2332 | p->m_pLogBackend->dListOrigin.append(list); |
| 2333 | break; |
| 2334 | } |
| 2335 | case APP: { |
| 2336 | QList<LOG_MSG_APPLICATOIN> list; |
| 2337 | LOG_MSG_APPLICATOIN item; |
| 2338 | for (int i = 0; i < 100; ++i) { |
| 2339 | item.msg = QString("msg%1").arg(i); |
| 2340 | item.level = "Debug"; |
| 2341 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2342 | item.src = "test_src"; |
| 2343 | list.append(item); |
| 2344 | } |
| 2345 | p->m_pLogBackend->appListOrigin.append(list); |
| 2346 | break; |
| 2347 | } |
| 2348 | case Normal: { |
| 2349 | break; |
| 2350 | } |
| 2351 | case Kwin: { |
| 2352 | QList<LOG_MSG_KWIN> list; |
| 2353 | LOG_MSG_KWIN item; |
| 2354 | for (int i = 0; i < 100; ++i) { |
| 2355 | item.msg = QString("msg%1").arg(i); |
| 2356 | list.append(item); |
| 2357 | } |
| 2358 | p->m_pLogBackend->m_kwinList.append(list); |
| 2359 | break; |
| 2360 | } |
| 2361 | default: |
| 2362 | break; |
| 2363 | } |
| 2364 | DisplayContent_slot_searchResult_QString_contains = param.isContains; |
| 2365 | stub.set((bool (QString::*)(const QString &, Qt::CaseSensitivity) const)ADDR(QString, contains), DisplayContent_slot_searchResult_QString_contains_Func); |
| 2366 | stub.set((void (QThreadPool::*)(QRunnable *, int))ADDR(QThreadPool, start), QThreadPool_start); |
| 2367 | stub.set(ADDR(QThread, start), QThread_start); |
| 2368 | QString searchstr = param.isSearchEmpty ? "" : "testsearchstr"; |
| 2369 | p->slot_searchResult(searchstr); |
| 2370 | p->deleteLater(); |
| 2371 | } |
| 2372 | |
| 2373 | TEST(DisplayContent_slot_getLogtype_UT, DisplayContent_slot_getLogtype_UT_001) |
| 2374 | { |
| 2375 | Stub stub; |
| 2376 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2377 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2378 | DisplayContent *p = new DisplayContent(nullptr); |
| 2379 | EXPECT_NE(p, nullptr); |
| 2380 | p->slot_getLogtype(0); |
| 2381 | p->deleteLater(); |
| 2382 | } |
| 2383 | |
| 2384 | class DisplayContent_parseListToModel_DPKG_UT_Param |
| 2385 | { |
| 2386 | public: |
| 2387 | DisplayContent_parseListToModel_DPKG_UT_Param(bool iIsEmptyList, bool iIsEmptyModel) |
| 2388 | { |
| 2389 | isEmptyList = iIsEmptyList; |
| 2390 | isEmptyModel = iIsEmptyModel; |
| 2391 | } |
| 2392 | bool isEmptyList; |
| 2393 | bool isEmptyModel; |
| 2394 | }; |
| 2395 | |
| 2396 | class DisplayContent_parseListToModel_DPKG_UT : public ::testing::TestWithParam<DisplayContent_parseListToModel_DPKG_UT_Param> |
| 2397 | { |
| 2398 | }; |
| 2399 | |
| 2400 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_parseListToModel_DPKG_UT, ::testing::Values(DisplayContent_parseListToModel_DPKG_UT_Param(true, true), DisplayContent_parseListToModel_DPKG_UT_Param(true, false), DisplayContent_parseListToModel_DPKG_UT_Param(false, false))); |
| 2401 | |
| 2402 | TEST_P(DisplayContent_parseListToModel_DPKG_UT, DisplayContent_parseListToModel_DPKG_UT) |
| 2403 | { |
| 2404 | Stub stub; |
| 2405 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2406 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2407 | DisplayContent *p = new DisplayContent(nullptr); |
| 2408 | EXPECT_NE(p, nullptr); |
| 2409 | DisplayContent_parseListToModel_DPKG_UT_Param param = GetParam(); |
| 2410 | QList<LOG_MSG_DPKG> list; |
| 2411 | if (!param.isEmptyList) { |
| 2412 | for (int i = 0; i < 100; ++i) { |
| 2413 | LOG_MSG_DPKG item; |
| 2414 | item.msg = ""; |
| 2415 | item.dateTime = ""; |
| 2416 | item.action = ""; |
| 2417 | list.append(item); |
| 2418 | } |
| 2419 | } |
| 2420 | |
| 2421 | p->parseListToModel(list, (param.isEmptyModel ? nullptr : p->m_pModel)); |
| 2422 | p->deleteLater(); |
| 2423 | } |
| 2424 | |
| 2425 | class DisplayContent_parseListToModel_BOOT_UT_Param |
| 2426 | { |
| 2427 | public: |
| 2428 | DisplayContent_parseListToModel_BOOT_UT_Param(bool iIsEmptyList, bool iIsEmptyModel) |
| 2429 | { |
| 2430 | isEmptyList = iIsEmptyList; |
| 2431 | isEmptyModel = iIsEmptyModel; |
| 2432 | } |
| 2433 | bool isEmptyList; |
| 2434 | bool isEmptyModel; |
| 2435 | }; |
| 2436 | |
| 2437 | class DisplayContent_parseListToModel_BOOT_UT : public ::testing::TestWithParam<DisplayContent_parseListToModel_BOOT_UT_Param> |
| 2438 | { |
| 2439 | }; |
| 2440 | |
| 2441 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_parseListToModel_BOOT_UT, ::testing::Values(DisplayContent_parseListToModel_BOOT_UT_Param(true, true), DisplayContent_parseListToModel_BOOT_UT_Param(true, false), DisplayContent_parseListToModel_BOOT_UT_Param(false, false))); |
| 2442 | |
| 2443 | TEST_P(DisplayContent_parseListToModel_BOOT_UT, DisplayContent_parseListToModel_BOOT_UT) |
| 2444 | { |
| 2445 | Stub stub; |
| 2446 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2447 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2448 | DisplayContent *p = new DisplayContent(nullptr); |
| 2449 | EXPECT_NE(p, nullptr); |
| 2450 | DisplayContent_parseListToModel_BOOT_UT_Param param = GetParam(); |
| 2451 | QList<LOG_MSG_BOOT> list; |
| 2452 | |
| 2453 | if (!param.isEmptyList) { |
| 2454 | LOG_MSG_BOOT item; |
| 2455 | for (int i = 0; i < 100; ++i) { |
| 2456 | item.msg = QString("msg%1").arg(i); |
| 2457 | item.status = "OK"; |
| 2458 | list.append(item); |
| 2459 | } |
| 2460 | } |
| 2461 | |
| 2462 | p->parseListToModel(list, (param.isEmptyModel ? nullptr : p->m_pModel)); |
| 2463 | p->deleteLater(); |
| 2464 | } |
| 2465 | |
| 2466 | class DisplayContent_parseListToModel_APP_UT_Param |
| 2467 | { |
| 2468 | public: |
| 2469 | DisplayContent_parseListToModel_APP_UT_Param(bool iIsEmptyList, bool iIsEmptyModel) |
| 2470 | { |
| 2471 | isEmptyList = iIsEmptyList; |
| 2472 | isEmptyModel = iIsEmptyModel; |
| 2473 | } |
| 2474 | bool isEmptyList; |
| 2475 | bool isEmptyModel; |
| 2476 | }; |
| 2477 | |
| 2478 | class DisplayContent_parseListToModel_APP_UT : public ::testing::TestWithParam<DisplayContent_parseListToModel_APP_UT_Param> |
| 2479 | { |
| 2480 | }; |
| 2481 | |
| 2482 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_parseListToModel_APP_UT, ::testing::Values(DisplayContent_parseListToModel_APP_UT_Param(true, true), DisplayContent_parseListToModel_APP_UT_Param(true, false), DisplayContent_parseListToModel_APP_UT_Param(false, false))); |
| 2483 | |
| 2484 | TEST_P(DisplayContent_parseListToModel_APP_UT, DisplayContent_parseListToModel_APP_UT) |
| 2485 | { |
| 2486 | Stub stub; |
| 2487 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2488 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2489 | DisplayContent *p = new DisplayContent(nullptr); |
| 2490 | EXPECT_NE(p, nullptr); |
| 2491 | DisplayContent_parseListToModel_APP_UT_Param param = GetParam(); |
| 2492 | QList<LOG_MSG_APPLICATOIN> list; |
| 2493 | |
| 2494 | if (!param.isEmptyList) { |
| 2495 | LOG_MSG_APPLICATOIN item; |
| 2496 | for (int i = 0; i < 100; ++i) { |
| 2497 | item.msg = QString("msg%1").arg(i); |
| 2498 | item.level = "Debug"; |
| 2499 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2500 | item.src = "test_src"; |
| 2501 | list.append(item); |
| 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | p->parseListToModel(list, (param.isEmptyModel ? nullptr : p->m_pModel)); |
| 2506 | p->deleteLater(); |
| 2507 | } |
| 2508 | |
| 2509 | class DisplayContent_parseListToModel_XORG_UT_Param |
| 2510 | { |
| 2511 | public: |
| 2512 | DisplayContent_parseListToModel_XORG_UT_Param(bool iIsEmptyList, bool iIsEmptyModel) |
| 2513 | { |
| 2514 | isEmptyList = iIsEmptyList; |
| 2515 | isEmptyModel = iIsEmptyModel; |
| 2516 | } |
| 2517 | bool isEmptyList; |
| 2518 | bool isEmptyModel; |
| 2519 | }; |
| 2520 | |
| 2521 | class DisplayContent_parseListToModel_XORG_UT : public ::testing::TestWithParam<DisplayContent_parseListToModel_XORG_UT_Param> |
| 2522 | { |
| 2523 | }; |
| 2524 | |
| 2525 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_parseListToModel_XORG_UT, ::testing::Values(DisplayContent_parseListToModel_XORG_UT_Param(true, true), DisplayContent_parseListToModel_XORG_UT_Param(true, false), DisplayContent_parseListToModel_XORG_UT_Param(false, false))); |
| 2526 | |
| 2527 | TEST_P(DisplayContent_parseListToModel_XORG_UT, DisplayContent_parseListToModel_XORG_UT) |
| 2528 | { |
| 2529 | Stub stub; |
| 2530 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2531 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2532 | DisplayContent *p = new DisplayContent(nullptr); |
| 2533 | EXPECT_NE(p, nullptr); |
| 2534 | DisplayContent_parseListToModel_XORG_UT_Param param = GetParam(); |
| 2535 | QList<LOG_MSG_XORG> list; |
| 2536 | |
| 2537 | if (!param.isEmptyList) { |
| 2538 | LOG_MSG_XORG item; |
| 2539 | for (int i = 0; i < 100; ++i) { |
| 2540 | item.msg = QString("msg%1").arg(i); |
| 2541 | item.offset = "3.541"; |
| 2542 | list.append(item); |
| 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | p->parseListToModel(list, (param.isEmptyModel ? nullptr : p->m_pModel)); |
| 2547 | p->deleteLater(); |
| 2548 | } |
| 2549 | |
| 2550 | class DisplayContent_parseListToModel_NORMAL_UT_Param |
| 2551 | { |
| 2552 | public: |
| 2553 | DisplayContent_parseListToModel_NORMAL_UT_Param(bool iIsEmptyList, bool iIsEmptyModel) |
| 2554 | { |
| 2555 | isEmptyList = iIsEmptyList; |
| 2556 | isEmptyModel = iIsEmptyModel; |
| 2557 | } |
| 2558 | bool isEmptyList; |
| 2559 | bool isEmptyModel; |
| 2560 | }; |
| 2561 | |
| 2562 | class DisplayContent_parseListToModel_NORMAL_UT : public ::testing::TestWithParam<DisplayContent_parseListToModel_NORMAL_UT_Param> |
| 2563 | { |
| 2564 | }; |
| 2565 | |
| 2566 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_parseListToModel_NORMAL_UT, ::testing::Values(DisplayContent_parseListToModel_NORMAL_UT_Param(true, true), DisplayContent_parseListToModel_NORMAL_UT_Param(true, false), DisplayContent_parseListToModel_NORMAL_UT_Param(false, false))); |
| 2567 | |
| 2568 | TEST_P(DisplayContent_parseListToModel_NORMAL_UT, DisplayContent_parseListToModel_NORMAL_UT) |
| 2569 | { |
| 2570 | Stub stub; |
| 2571 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2572 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2573 | DisplayContent *p = new DisplayContent(nullptr); |
| 2574 | EXPECT_NE(p, nullptr); |
| 2575 | DisplayContent_parseListToModel_NORMAL_UT_Param param = GetParam(); |
| 2576 | QList<LOG_MSG_NORMAL> list; |
| 2577 | |
| 2578 | if (!param.isEmptyList) { |
| 2579 | LOG_MSG_NORMAL item; |
| 2580 | for (int i = 0; i < 100; ++i) { |
| 2581 | item.msg = QString("msg%1").arg(i); |
| 2582 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2583 | item.userName = "test_user"; |
| 2584 | item.eventType = "Login"; |
| 2585 | list.append(item); |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | p->parseListToModel(list, (param.isEmptyModel ? nullptr : p->m_pModel)); |
| 2590 | p->deleteLater(); |
| 2591 | } |
| 2592 | |
| 2593 | class DisplayContent_parseListToModel_KWIN_UT_Param |
| 2594 | { |
| 2595 | public: |
| 2596 | DisplayContent_parseListToModel_KWIN_UT_Param(bool iIsEmptyList, bool iIsEmptyModel) |
| 2597 | { |
| 2598 | isEmptyList = iIsEmptyList; |
| 2599 | isEmptyModel = iIsEmptyModel; |
| 2600 | } |
| 2601 | bool isEmptyList; |
| 2602 | bool isEmptyModel; |
| 2603 | }; |
| 2604 | |
| 2605 | class DisplayContent_parseListToModel_KWIN_UT : public ::testing::TestWithParam<DisplayContent_parseListToModel_KWIN_UT_Param> |
| 2606 | { |
| 2607 | }; |
| 2608 | |
| 2609 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_parseListToModel_KWIN_UT, ::testing::Values(DisplayContent_parseListToModel_KWIN_UT_Param(true, true), DisplayContent_parseListToModel_KWIN_UT_Param(true, false), DisplayContent_parseListToModel_KWIN_UT_Param(false, false))); |
| 2610 | |
| 2611 | TEST_P(DisplayContent_parseListToModel_KWIN_UT, DisplayContent_parseListToModel_KWIN_UT) |
| 2612 | { |
| 2613 | Stub stub; |
| 2614 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2615 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2616 | DisplayContent *p = new DisplayContent(nullptr); |
| 2617 | EXPECT_NE(p, nullptr); |
| 2618 | DisplayContent_parseListToModel_KWIN_UT_Param param = GetParam(); |
| 2619 | QList<LOG_MSG_KWIN> list; |
| 2620 | |
| 2621 | if (!param.isEmptyList) { |
| 2622 | LOG_MSG_KWIN item; |
| 2623 | for (int i = 0; i < 100; ++i) { |
| 2624 | item.msg = QString("msg%1").arg(i); |
| 2625 | list.append(item); |
| 2626 | } |
| 2627 | } |
| 2628 | |
| 2629 | p->parseListToModel(list, (param.isEmptyModel ? nullptr : p->m_pModel)); |
| 2630 | p->deleteLater(); |
| 2631 | } |
| 2632 | |
| 2633 | class DisplayContent_parseListToModel_OOC_UT_Param |
| 2634 | { |
| 2635 | public: |
| 2636 | DisplayContent_parseListToModel_OOC_UT_Param(bool iIsEmptyList, bool iIsEmptyModel) |
| 2637 | { |
| 2638 | isEmptyList = iIsEmptyList; |
| 2639 | isEmptyModel = iIsEmptyModel; |
| 2640 | } |
| 2641 | bool isEmptyList; |
| 2642 | bool isEmptyModel; |
| 2643 | }; |
| 2644 | |
| 2645 | class DisplayContent_parseListToModel_OOC_UT : public ::testing::TestWithParam<DisplayContent_parseListToModel_OOC_UT_Param> |
| 2646 | { |
| 2647 | }; |
| 2648 | |
| 2649 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_parseListToModel_OOC_UT, ::testing::Values(DisplayContent_parseListToModel_OOC_UT_Param(true, true), DisplayContent_parseListToModel_OOC_UT_Param(true, false), DisplayContent_parseListToModel_OOC_UT_Param(false, false))); |
| 2650 | |
| 2651 | TEST_P(DisplayContent_parseListToModel_OOC_UT, DisplayContent_parseListToModel_OOC_UT) |
| 2652 | { |
| 2653 | DisplayContent *p = new DisplayContent(nullptr); |
| 2654 | EXPECT_NE(p, nullptr); |
| 2655 | DisplayContent_parseListToModel_OOC_UT_Param param = GetParam(); |
| 2656 | QList<LOG_FILE_OTHERORCUSTOM> list; |
| 2657 | |
| 2658 | if (!param.isEmptyList) { |
| 2659 | LOG_FILE_OTHERORCUSTOM item; |
| 2660 | for (int i = 0; i < 100; ++i) { |
| 2661 | item.name = "name"; |
| 2662 | item.path = "path"; |
| 2663 | list.append(item); |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | p->parseListToModel(list, (param.isEmptyModel ? nullptr : p->m_pModel)); |
| 2668 | p->deleteLater(); |
| 2669 | } |
| 2670 | |
| 2671 | class DisplayContent_setLoadState_UT_Param |
| 2672 | { |
| 2673 | public: |
| 2674 | DisplayContent_setLoadState_UT_Param(DisplayContent::LOAD_STATE iLoadState, bool iSpinnerWgtIsHide, |
| 2675 | bool iSpinnerWgtKIsHide, |
| 2676 | bool iNoResultLabelIsHide, |
| 2677 | bool iTreeViewIsHide, |
| 2678 | bool iSpinnerWgtIsShowResult, |
| 2679 | bool iSpinnerWgtKIsShowResult, |
| 2680 | bool iNoResultLabelIsShowResult, |
| 2681 | bool iTreeViewIsShowResult) |
| 2682 | { |
| 2683 | m_loadState = iLoadState; |
| 2684 | m_spinnerWgtIsHide = iSpinnerWgtIsHide; |
| 2685 | m_spinnerWgtKIsHide = iSpinnerWgtKIsHide; |
| 2686 | m_noResultLabelIsHide = iNoResultLabelIsHide; |
| 2687 | m_treeViewIsHide = iTreeViewIsHide; |
| 2688 | m_spinnerWgtIsShowResult = iSpinnerWgtIsShowResult; |
| 2689 | m_spinnerWgtKIsShowResult = iSpinnerWgtKIsShowResult; |
| 2690 | m_noResultLabelIsShowResult = iNoResultLabelIsShowResult; |
| 2691 | m_treeViewIsShowResult = iTreeViewIsShowResult; |
| 2692 | } |
| 2693 | DisplayContent::LOAD_STATE m_loadState; |
| 2694 | bool m_spinnerWgtIsHide; |
| 2695 | bool m_spinnerWgtKIsHide; |
| 2696 | bool m_noResultLabelIsHide; |
| 2697 | bool m_treeViewIsHide; |
| 2698 | bool m_spinnerWgtIsShowResult; |
| 2699 | bool m_spinnerWgtKIsShowResult; |
| 2700 | bool m_noResultLabelIsShowResult; |
| 2701 | bool m_treeViewIsShowResult; |
| 2702 | }; |
| 2703 | |
| 2704 | class DisplayContent_setLoadState_UT : public ::testing::TestWithParam<DisplayContent_setLoadState_UT_Param> |
| 2705 | { |
| 2706 | }; |
| 2707 | |
| 2708 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_setLoadState_UT, ::testing::Values(DisplayContent_setLoadState_UT_Param(DisplayContent::DATA_LOADING, true, true, true, true, true, false, false, false), DisplayContent_setLoadState_UT_Param(DisplayContent::DATA_COMPLETE, true, true, true, true, false, false, false, true), DisplayContent_setLoadState_UT_Param(DisplayContent::DATA_LOADING_K, true, true, true, true, false, true, false, false), DisplayContent_setLoadState_UT_Param(DisplayContent::DATA_NO_SEARCH_RESULT, true, true, true, true, false, false, true, true), DisplayContent_setLoadState_UT_Param(DisplayContent::DATA_LOADING, false, false, false, false, true, false, false, false), DisplayContent_setLoadState_UT_Param(DisplayContent::DATA_COMPLETE, false, false, false, false, false, false, false, true), DisplayContent_setLoadState_UT_Param(DisplayContent::DATA_LOADING_K, false, false, false, false, false, true, false, true), DisplayContent_setLoadState_UT_Param(DisplayContent::DATA_NO_SEARCH_RESULT, false, false, false, false, false, false, true, true))); |
| 2709 | |
| 2710 | TEST_P(DisplayContent_setLoadState_UT, DisplayContent_setLoadState_UT) |
| 2711 | { |
| 2712 | Stub stub; |
| 2713 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2714 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2715 | DisplayContent *p = new DisplayContent(nullptr); |
| 2716 | EXPECT_NE(p, nullptr); |
| 2717 | DisplayContent_setLoadState_UT_Param param = GetParam(); |
| 2718 | |
| 2719 | p->m_spinnerWgt->setHidden(param.m_spinnerWgtIsHide); |
| 2720 | p->m_spinnerWgt_K->setHidden(param.m_spinnerWgtKIsHide); |
| 2721 | p->noResultLabel->setHidden(param.m_noResultLabelIsHide); |
| 2722 | p->m_treeView->setHidden(param.m_treeViewIsHide); |
| 2723 | |
| 2724 | p->setLoadState(param.m_loadState); |
| 2725 | EXPECT_EQ(param.m_spinnerWgtIsShowResult, !p->m_spinnerWgt->isHidden()); |
| 2726 | EXPECT_EQ(param.m_spinnerWgtKIsShowResult, !p->m_spinnerWgt_K->isHidden()); |
| 2727 | EXPECT_EQ(param.m_noResultLabelIsShowResult, !p->noResultLabel->isHidden()); |
| 2728 | EXPECT_EQ(param.m_treeViewIsShowResult, !p->m_treeView->isHidden()); |
| 2729 | p->deleteLater(); |
| 2730 | } |
| 2731 | |
| 2732 | class DisplayContent_onExportResult_UT_Param |
| 2733 | { |
| 2734 | public: |
| 2735 | DisplayContent_onExportResult_UT_Param(bool iIsSuccess, bool iNeedHide) |
| 2736 | { |
| 2737 | m_isSuccess = iIsSuccess; |
| 2738 | m_NeedHide = iNeedHide; |
| 2739 | } |
| 2740 | bool m_isSuccess; |
| 2741 | bool m_NeedHide; |
| 2742 | }; |
| 2743 | |
| 2744 | class DisplayContent_onExportResult_UT : public ::testing::TestWithParam<DisplayContent_onExportResult_UT_Param> |
| 2745 | { |
| 2746 | }; |
| 2747 | |
| 2748 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_onExportResult_UT, ::testing::Values(DisplayContent_onExportResult_UT_Param(false, true), DisplayContent_onExportResult_UT_Param(true, true), DisplayContent_onExportResult_UT_Param(true, false))); |
| 2749 | |
| 2750 | #include "exportprogressdlg.h" |
| 2751 | TEST_P(DisplayContent_onExportResult_UT, DisplayContent_onExportResult_UT) |
| 2752 | { |
| 2753 | Stub stub; |
| 2754 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2755 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2756 | DisplayContent *p = new DisplayContent(nullptr); |
| 2757 | EXPECT_NE(p, nullptr); |
| 2758 | DisplayContent_onExportResult_UT_Param param = GetParam(); |
| 2759 | if (param.m_NeedHide) { |
| 2760 | p->m_exportDlg->show(); |
| 2761 | } else { |
| 2762 | p->m_exportDlg->hide(); |
| 2763 | } |
| 2764 | p->onExportResult(param.m_isSuccess); |
| 2765 | p->deleteLater(); |
| 2766 | } |
| 2767 | |
| 2768 | TEST(DisplayContent_onExportFakeCloseDlg_UT, DisplayContent_onExportFakeCloseDlg_UT) |
| 2769 | { |
| 2770 | Stub stub; |
| 2771 | stub.set(ADDR(JournalBootWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2772 | stub.set(ADDR(journalWork, getReplaceColorStr), stub_getReplaceColorStr_bootwork); |
| 2773 | DisplayContent *p = new DisplayContent(nullptr); |
| 2774 | EXPECT_NE(p, nullptr); |
| 2775 | p->m_exportDlg->show(); |
| 2776 | p->onExportFakeCloseDlg(); |
| 2777 | EXPECT_EQ(p->m_exportDlg->isHidden(), true); |
| 2778 | p->m_exportDlg->hide(); |
| 2779 | p->onExportFakeCloseDlg(); |
| 2780 | EXPECT_EQ(p->m_exportDlg->isHidden(), true); |
| 2781 | p->deleteLater(); |
| 2782 | } |
| 2783 | |
| 2784 | TEST(DisplayContent_clearAllFilter_UT, DisplayContent_clearAllFilter_UT) |
| 2785 | { |
| 2786 | DisplayContent *p = new DisplayContent(nullptr); |
| 2787 | EXPECT_NE(p, nullptr); |
| 2788 | |
| 2789 | p->m_pLogBackend->clearAllFilter(); |
| 2790 | |
| 2791 | EXPECT_EQ(p->m_pLogBackend->m_bootFilter.searchstr, ""); |
| 2792 | EXPECT_EQ(p->m_pLogBackend->m_bootFilter.statusFilter, ""); |
| 2793 | EXPECT_EQ(p->m_pLogBackend->m_currentSearchStr.isEmpty(), true); |
| 2794 | EXPECT_EQ(p->m_pLogBackend->m_normalFilter.searchstr, ""); |
| 2795 | EXPECT_EQ(p->m_pLogBackend->m_normalFilter.timeFilterEnd, -1); |
| 2796 | EXPECT_EQ(p->m_pLogBackend->m_normalFilter.timeFilterBegin, -1); |
| 2797 | EXPECT_EQ(p->m_pLogBackend->m_normalFilter.eventTypeFilter, 0); |
| 2798 | p->deleteLater(); |
| 2799 | } |
| 2800 | |
| 2801 | #include <QStandardItemModel> |
| 2802 | TEST(DisplayContent_clearAllDatalist_UT, DisplayContent_clearAllDatalist_UT) |
| 2803 | { |
| 2804 | DisplayContent *p = new DisplayContent(nullptr); |
| 2805 | EXPECT_NE(p, nullptr); |
| 2806 | |
| 2807 | p->clearAllDatas(); |
| 2808 | |
| 2809 | EXPECT_EQ(p->m_pModel->rowCount(), 0); |
| 2810 | EXPECT_EQ(p->m_pModel->columnCount(), 0); |
| 2811 | EXPECT_EQ(p->m_pLogBackend->jList.size(), 0); |
| 2812 | EXPECT_EQ(p->m_pLogBackend->jListOrigin.size(), 0); |
| 2813 | EXPECT_EQ(p->m_pLogBackend->dListOrigin.size(), 0); |
| 2814 | EXPECT_EQ(p->m_pLogBackend->xList.size(), 0); |
| 2815 | EXPECT_EQ(p->m_pLogBackend->xListOrigin.size(), 0); |
| 2816 | EXPECT_EQ(p->m_pLogBackend->bList.size(), 0); |
| 2817 | EXPECT_EQ(p->m_pLogBackend->currentBootList.size(), 0); |
| 2818 | EXPECT_EQ(p->m_pLogBackend->kList.size(), 0); |
| 2819 | EXPECT_EQ(p->m_pLogBackend->kListOrigin.size(), 0); |
| 2820 | EXPECT_EQ(p->m_pLogBackend->appList.size(), 0); |
| 2821 | EXPECT_EQ(p->m_pLogBackend->appListOrigin.size(), 0); |
| 2822 | EXPECT_EQ(p->m_pLogBackend->norList.size(), 0); |
| 2823 | EXPECT_EQ(p->m_pLogBackend->nortempList.size(), 0); |
| 2824 | EXPECT_EQ(p->m_pLogBackend->m_currentKwinList.size(), 0); |
| 2825 | EXPECT_EQ(p->m_pLogBackend->m_kwinList.size(), 0); |
| 2826 | EXPECT_EQ(p->m_pLogBackend->jBootList.size(), 0); |
| 2827 | EXPECT_EQ(p->m_pLogBackend->jBootListOrigin.size(), 0); |
| 2828 | p->deleteLater(); |
| 2829 | } |
| 2830 | |
| 2831 | class DisplayContent_filterBoot_UT_Param |
| 2832 | { |
| 2833 | public: |
| 2834 | DisplayContent_filterBoot_UT_Param(bool iIsStatusFilerEmpty, bool iIsMsgFilerEmpty) |
| 2835 | { |
| 2836 | m_isStatusFilerEmpty = iIsStatusFilerEmpty; |
| 2837 | m_isMsgFilerEmpty = iIsMsgFilerEmpty; |
| 2838 | } |
| 2839 | bool m_isStatusFilerEmpty; |
| 2840 | bool m_isMsgFilerEmpty; |
| 2841 | }; |
| 2842 | |
| 2843 | class DisplayContent_filterBoot_UT : public ::testing::TestWithParam<DisplayContent_filterBoot_UT_Param> |
| 2844 | { |
| 2845 | }; |
| 2846 | |
| 2847 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_filterBoot_UT, ::testing::Values(DisplayContent_filterBoot_UT_Param(false, false), DisplayContent_filterBoot_UT_Param(true, true), DisplayContent_filterBoot_UT_Param(true, false))); |
| 2848 | |
| 2849 | TEST_P(DisplayContent_filterBoot_UT, DisplayContent_filterBoot_UT) |
| 2850 | { |
| 2851 | DisplayContent *p = new DisplayContent(nullptr); |
| 2852 | EXPECT_NE(p, nullptr); |
| 2853 | DisplayContent_filterBoot_UT_Param param = GetParam(); |
| 2854 | BOOT_FILTERS filter; |
| 2855 | filter.searchstr = param.m_isMsgFilerEmpty ? "" : "msg"; |
| 2856 | filter.statusFilter = param.m_isStatusFilerEmpty ? "" : "OK"; |
| 2857 | QList<LOG_MSG_BOOT> list; |
| 2858 | LOG_MSG_BOOT item; |
| 2859 | for (int i = 0; i < 100; ++i) { |
| 2860 | item.msg = QString("msg%1").arg(i); |
| 2861 | item.status = "OK"; |
| 2862 | list.append(item); |
| 2863 | } |
| 2864 | QList<LOG_MSG_BOOT> rslist = LogBackend::filterBoot(filter, list); |
| 2865 | |
| 2866 | EXPECT_EQ(rslist.size(), 100); |
| 2867 | p->deleteLater(); |
| 2868 | } |
| 2869 | |
| 2870 | class DisplayContent_filterNomal_UT_Param |
| 2871 | { |
| 2872 | public: |
| 2873 | DisplayContent_filterNomal_UT_Param(bool iIsEventTypeFilterEmpty, bool iIsMsgFilerEmpty) |
| 2874 | { |
| 2875 | m_isEventTypeFilterEmpty = iIsEventTypeFilterEmpty; |
| 2876 | m_isMsgFilerEmpty = iIsMsgFilerEmpty; |
| 2877 | } |
| 2878 | bool m_isEventTypeFilterEmpty; |
| 2879 | bool m_isMsgFilerEmpty; |
| 2880 | }; |
| 2881 | |
| 2882 | class DisplayContent_filterNomal_UT : public ::testing::TestWithParam<DisplayContent_filterNomal_UT_Param> |
| 2883 | { |
| 2884 | }; |
| 2885 | |
| 2886 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_filterNomal_UT, ::testing::Values(DisplayContent_filterNomal_UT_Param(false, false), DisplayContent_filterNomal_UT_Param(true, true), DisplayContent_filterNomal_UT_Param(true, false), DisplayContent_filterNomal_UT_Param(false, true))); |
| 2887 | |
| 2888 | TEST_P(DisplayContent_filterNomal_UT, DisplayContent_filterNomal_UT) |
| 2889 | { |
| 2890 | DisplayContent *p = new DisplayContent(nullptr); |
| 2891 | EXPECT_NE(p, nullptr); |
| 2892 | DisplayContent_filterNomal_UT_Param param = GetParam(); |
| 2893 | NORMAL_FILTERS filter; |
| 2894 | filter.searchstr = param.m_isMsgFilerEmpty ? "" : "msg"; |
| 2895 | filter.eventTypeFilter = param.m_isEventTypeFilterEmpty ? -1 : 2; |
| 2896 | QList<LOG_MSG_NORMAL> list; |
| 2897 | LOG_MSG_NORMAL item; |
| 2898 | for (int i = 0; i < 100; ++i) { |
| 2899 | item.msg = QString("msg%1").arg(i); |
| 2900 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2901 | item.userName = "test_user"; |
| 2902 | item.eventType = "Boot"; |
| 2903 | list.append(item); |
| 2904 | } |
| 2905 | |
| 2906 | QList<LOG_MSG_NORMAL> rslist = LogBackend::filterNomal(filter, list); |
| 2907 | int resultCount = (param.m_isEventTypeFilterEmpty && (!param.m_isMsgFilerEmpty)) ? 0 : 100; |
| 2908 | |
| 2909 | EXPECT_EQ(rslist.size(), resultCount); |
| 2910 | p->deleteLater(); |
| 2911 | } |
| 2912 | |
| 2913 | TEST(DisplayContent_onExportProgress_UT, DisplayContent_onExportProgress_UT) |
| 2914 | { |
| 2915 | DisplayContent *p = new DisplayContent(nullptr); |
| 2916 | EXPECT_NE(p, nullptr); |
| 2917 | p->onExportProgress(5, 100); |
| 2918 | p->deleteLater(); |
| 2919 | } |
| 2920 | |
| 2921 | class DisplayContent_parseListToModel_JOURNAL_UT_Param |
| 2922 | { |
| 2923 | public: |
| 2924 | DisplayContent_parseListToModel_JOURNAL_UT_Param(bool iIsEmptyList, bool iIsEmptyModel) |
| 2925 | { |
| 2926 | isEmptyList = iIsEmptyList; |
| 2927 | isEmptyModel = iIsEmptyModel; |
| 2928 | } |
| 2929 | bool isEmptyList; |
| 2930 | bool isEmptyModel; |
| 2931 | }; |
| 2932 | |
| 2933 | class DisplayContent_parseListToModel_JOURNAL_UT : public ::testing::TestWithParam<DisplayContent_parseListToModel_JOURNAL_UT_Param> |
| 2934 | { |
| 2935 | }; |
| 2936 | |
| 2937 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_parseListToModel_JOURNAL_UT, ::testing::Values(DisplayContent_parseListToModel_JOURNAL_UT_Param(true, true), DisplayContent_parseListToModel_JOURNAL_UT_Param(true, false), DisplayContent_parseListToModel_JOURNAL_UT_Param(false, false))); |
| 2938 | |
| 2939 | TEST_P(DisplayContent_parseListToModel_JOURNAL_UT, DisplayContent_parseListToModel_JOURNAL_UT) |
| 2940 | { |
| 2941 | DisplayContent *p = new DisplayContent(nullptr); |
| 2942 | EXPECT_NE(p, nullptr); |
| 2943 | DisplayContent_parseListToModel_JOURNAL_UT_Param param = GetParam(); |
| 2944 | QList<LOG_MSG_JOURNAL> list; |
| 2945 | if (!param.isEmptyList) { |
| 2946 | LOG_MSG_JOURNAL item; |
| 2947 | for (int i = 0; i < 100; ++i) { |
| 2948 | item.msg = QString("msg%1").arg(i); |
| 2949 | item.level = "Debug"; |
| 2950 | item.daemonId = "1"; |
| 2951 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2952 | item.hostName = "test_host"; |
| 2953 | item.daemonName = "test_daemon"; |
| 2954 | list.append(item); |
| 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | p->parseListToModel(list, (param.isEmptyModel ? nullptr : p->m_pModel)); |
| 2959 | p->deleteLater(); |
| 2960 | } |
| 2961 | |
| 2962 | class DisplayContent_getIconByname_UT_Param |
| 2963 | { |
| 2964 | public: |
| 2965 | DisplayContent_getIconByname_UT_Param(const QString &iKey, const QString &iValue) |
| 2966 | : key(iKey) |
| 2967 | , value(iValue) |
| 2968 | { |
| 2969 | } |
| 2970 | QString key; |
| 2971 | QString value; |
| 2972 | }; |
| 2973 | |
| 2974 | class DisplayContent_getIconByname_UT : public ::testing::TestWithParam<DisplayContent_getIconByname_UT_Param> |
| 2975 | { |
| 2976 | }; |
| 2977 | |
| 2978 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_getIconByname_UT, ::testing::Values(DisplayContent_getIconByname_UT_Param(DApplication::translate("Level", "Emergency"), "warning2.svg"), DisplayContent_getIconByname_UT_Param(DApplication::translate("Level", "Alert"), "warning3.svg"), DisplayContent_getIconByname_UT_Param(DApplication::translate("Level", "Critical"), "warning2.svg"), DisplayContent_getIconByname_UT_Param(DApplication::translate("Level", "Error"), "wrong.svg"), DisplayContent_getIconByname_UT_Param(DApplication::translate("Level", "Warning"), "warning.svg"), DisplayContent_getIconByname_UT_Param(DApplication::translate("Level", "Notice"), "warning.svg"), DisplayContent_getIconByname_UT_Param(DApplication::translate("Level", "Info"), ""), DisplayContent_getIconByname_UT_Param(DApplication::translate("Level", "Debug"), ""), DisplayContent_getIconByname_UT_Param("Warning", "warning.svg"), DisplayContent_getIconByname_UT_Param("Debug", ""), DisplayContent_getIconByname_UT_Param("Error", "wrong.svg"))); |
| 2979 | |
| 2980 | TEST_P(DisplayContent_getIconByname_UT, DisplayContent_getIconByname_UT) |
| 2981 | { |
| 2982 | DisplayContent *p = new DisplayContent(nullptr); |
| 2983 | EXPECT_NE(p, nullptr); |
| 2984 | DisplayContent_getIconByname_UT_Param param = GetParam(); |
| 2985 | EXPECT_EQ(p->getIconByname(param.key), param.value); |
| 2986 | p->deleteLater(); |
| 2987 | } |
| 2988 | |
| 2989 | TEST(DisplayContent_createApplicationTable_UT, DisplayContent_createApplicationTable_UT_001) |
| 2990 | { |
| 2991 | DisplayContent *p = new DisplayContent(nullptr); |
| 2992 | EXPECT_NE(p, nullptr); |
| 2993 | QList<LOG_MSG_APPLICATOIN> list; |
| 2994 | LOG_MSG_APPLICATOIN item; |
| 2995 | for (int i = 0; i < 100; ++i) { |
| 2996 | item.msg = QString("msg%1").arg(i); |
| 2997 | item.level = "Debug"; |
| 2998 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 2999 | item.src = "test_src"; |
| 3000 | list.append(item); |
| 3001 | } |
| 3002 | p->createAppTable(list); |
| 3003 | EXPECT_EQ(p->m_limitTag, 0); |
| 3004 | EXPECT_NE(p->m_pModel,nullptr); |
| 3005 | p->deleteLater(); |
| 3006 | } |
| 3007 | |
| 3008 | class DisplayContent_insertApplicationTable_UT_Param |
| 3009 | { |
| 3010 | public: |
| 3011 | explicit DisplayContent_insertApplicationTable_UT_Param(bool iIsEndMore) |
| 3012 | { |
| 3013 | m_isEndMore = iIsEndMore; |
| 3014 | } |
| 3015 | bool m_isEndMore; |
| 3016 | }; |
| 3017 | |
| 3018 | class DisplayContent_insertApplicationTable_UT : public ::testing::TestWithParam<DisplayContent_insertApplicationTable_UT_Param> |
| 3019 | { |
| 3020 | }; |
| 3021 | |
| 3022 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_insertApplicationTable_UT, ::testing::Values(DisplayContent_insertApplicationTable_UT_Param(true), DisplayContent_insertApplicationTable_UT_Param(false))); |
| 3023 | |
| 3024 | TEST_P(DisplayContent_insertApplicationTable_UT, DisplayContent_insertApplicationTable_UT_001) |
| 3025 | { |
| 3026 | DisplayContent *p = new DisplayContent(nullptr); |
| 3027 | EXPECT_NE(p, nullptr); |
| 3028 | DisplayContent_insertApplicationTable_UT_Param param = GetParam(); |
| 3029 | QList<LOG_MSG_APPLICATOIN> list; |
| 3030 | LOG_MSG_APPLICATOIN item; |
| 3031 | for (int i = 0; i < 100; ++i) { |
| 3032 | item.msg = QString("msg%1").arg(i); |
| 3033 | item.level = "Debug"; |
| 3034 | item.dateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); |
| 3035 | item.src = "test_src"; |
| 3036 | list.append(item); |
| 3037 | } |
| 3038 | int end = 0; |
| 3039 | int start = 0; |
| 3040 | if (param.m_isEndMore) { |
| 3041 | qDebug() << "param.m_isEndMore"; |
| 3042 | start = 0; |
| 3043 | end = 20; |
| 3044 | } else { |
| 3045 | qDebug() << "param.m_noEndMore"; |
| 3046 | start = 20; |
| 3047 | end = 0; |
| 3048 | } |
| 3049 | p->insertApplicationTable(list, start, end); |
| 3050 | EXPECT_NE(p->m_pModel,nullptr)<<"check the status after insertApplicationTable()"; |
| 3051 | p->deleteLater(); |
| 3052 | } |
| 3053 | |
| 3054 | class DisplayContent_slot_refreshClicked_UT_Param |
| 3055 | { |
| 3056 | public: |
| 3057 | explicit DisplayContent_slot_refreshClicked_UT_Param(int iIndex) |
| 3058 | { |
| 3059 | index = iIndex; |
| 3060 | } |
| 3061 | int index; |
| 3062 | }; |
| 3063 | |
| 3064 | class DisplayContent_slot_refreshClicked_UT : public ::testing::TestWithParam<DisplayContent_slot_refreshClicked_UT_Param> |
| 3065 | { |
| 3066 | }; |
| 3067 | |
| 3068 | static QString slot_refreshClicked_ModelIndex_data = ""; |
| 3069 | INSTANTIATE_TEST_CASE_P(DisplayContent, DisplayContent_slot_refreshClicked_UT, ::testing::Values(DisplayContent_slot_refreshClicked_UT_Param(0), DisplayContent_slot_refreshClicked_UT_Param(1), DisplayContent_slot_refreshClicked_UT_Param(2), DisplayContent_slot_refreshClicked_UT_Param(3), DisplayContent_slot_refreshClicked_UT_Param(4), DisplayContent_slot_refreshClicked_UT_Param(5), DisplayContent_slot_refreshClicked_UT_Param(6), DisplayContent_slot_refreshClicked_UT_Param(7), DisplayContent_slot_refreshClicked_UT_Param(8), DisplayContent_slot_refreshClicked_UT_Param(9))); |
| 3070 | QVariant slot_refreshClicked_ModelIndex_data_Func(void *obj, int arole) |
| 3071 | { |
| 3072 | return QString(slot_refreshClicked_ModelIndex_data); |
| 3073 | } |
| 3074 | bool slot_refreshClicked_ModelIndex_isValid_Func(void *obj) |
| 3075 | { |
| 3076 | return true; |
| 3077 | } |
| 3078 | |
| 3079 | TEST_P(DisplayContent_slot_refreshClicked_UT, DisplayContent_slot_refreshClicked_UT_001) |
| 3080 | { |
| 3081 | Stub stub; |
| 3082 | DisplayContent_slot_refreshClicked_UT_Param param = GetParam(); |
| 3083 | DisplayContent *p = new DisplayContent(nullptr); |
| 3084 | EXPECT_NE(p, nullptr); |
| 3085 | |
| 3086 | switch (param.index) { |
| 3087 | case 0: |
| 3088 | slot_refreshClicked_ModelIndex_data = JOUR_TREE_DATA; |
| 3089 | break; |
| 3090 | case 1: |
| 3091 | slot_refreshClicked_ModelIndex_data = DPKG_TREE_DATA; |
| 3092 | break; |
| 3093 | case 2: |
| 3094 | slot_refreshClicked_ModelIndex_data = XORG_TREE_DATA; |
| 3095 | break; |
| 3096 | case 3: |
| 3097 | slot_refreshClicked_ModelIndex_data = BOOT_TREE_DATA; |
| 3098 | break; |
| 3099 | case 4: |
| 3100 | slot_refreshClicked_ModelIndex_data = KERN_TREE_DATA; |
| 3101 | break; |
| 3102 | case 5: |
| 3103 | slot_refreshClicked_ModelIndex_data = APP_TREE_DATA; |
| 3104 | break; |
| 3105 | case 6: |
| 3106 | slot_refreshClicked_ModelIndex_data = LAST_TREE_DATA; |
| 3107 | break; |
| 3108 | case 7: |
| 3109 | slot_refreshClicked_ModelIndex_data = KWIN_TREE_DATA; |
| 3110 | break; |
| 3111 | case 8: |
| 3112 | slot_refreshClicked_ModelIndex_data = BOOT_KLU_TREE_DATA; |
| 3113 | break; |
| 3114 | case 9: |
| 3115 | slot_refreshClicked_ModelIndex_data = ""; |
| 3116 | break; |
| 3117 | default: |
| 3118 | break; |
| 3119 | } |
| 3120 | |
| 3121 | stub.set(ADDR(QModelIndex, data), slot_refreshClicked_ModelIndex_data_Func); |
| 3122 | stub.set(ADDR(QModelIndex, isValid), slot_refreshClicked_ModelIndex_isValid_Func); |
| 3123 | stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal); |
| 3124 | stub.set(ADDR(LogFileParser, parseByJournalBoot), LogFileParser_parseByJournalBoot); |
| 3125 | stub.set(ADDR(LogFileParser, parseByDpkg), LogFileParser_parseByDpkg); |
| 3126 | stub.set(ADDR(LogFileParser, parseByXlog), LogFileParser_parseByXlog); |
| 3127 | stub.set(ADDR(LogFileParser, parseByBoot), LogFileParser_parseByBoot); |
| 3128 | stub.set(ADDR(LogFileParser, parseByKern), LogFileParser_parseByKern); |
| 3129 | stub.set(ADDR(LogFileParser, parseByApp), LogFileParser_parseByApp); |
| 3130 | stub.set(ADDR(LogFileParser, parseByNormal), LogFileParser_parseByNormal); |
| 3131 | stub.set(ADDR(LogFileParser, parseByKwin), LogFileParser_parseByKwin); |
| 3132 | p->slot_refreshClicked(QModelIndex()); |
| 3133 | EXPECT_EQ(p->m_curListIdx,QModelIndex())<<"check the status after slot_refreshClicked()"; |
| 3134 | p->deleteLater(); |
| 3135 | } |
| 3136 | |
| 3137 | displaycontent_test::displaycontent_test() |
| 3138 | { |
| 3139 | } |
| 3140 | |
| 3141 | void displaycontent_test::SetUp() |
| 3142 | { |
| 3143 | |
| 3144 | } |
| 3145 | |
| 3146 | void displaycontent_test::TearDown() |
| 3147 | { |
| 3148 | |
| 3149 | } |