Debian Codegraph @

tests/dde-calendar-client-test/src/test_widget/test_yearWidget/test_yearview.cpp

raw
1 // SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4
5 #include "test_yearview.h"
6
7 #include "../third-party_stub/stub.h"
8 #include <QTest>
9
10 test_yearview::test_yearview()
11 {
12 }
13
14 test_yearview::~test_yearview()
15 {
16 }
17
18 void test_yearview::SetUp()
19 {
20 cYearView = new CYearView();
21 }
22
23 void test_yearview::TearDown()
24 {
25 delete cYearView;
26 cYearView = nullptr;
27 }
28
29 QVector<QDate> getListDate()
30 {
31 QVector<QDate> listDate {};
32 QDate date = QDate::currentDate();
33 for (int i = 0; i < 42; i++) {
34 listDate.append(date);
35 date = date.addDays(1);
36 }
37 return listDate;
38 }
39
40 //void CYearView::slotDoubleClickDate(const QDate &date)
41 TEST_F(test_yearview, slotDoubltClickDate)
42 {
43 cYearView->slotDoubleClickDate(QDate(2021, 1, 6));
44 }
45
46 //void CYearView::slotPressClickDate(const QDate &date)
47 TEST_F(test_yearview, slotPressClickDate)
48 {
49 cYearView->slotPressClickDate(QDate(2021, 1, 6));
50 }
51
52 //void CYearView::setTheMe(int type)
53 TEST_F(test_yearview, setTheMe)
54 {
55 cYearView->setTheMe(1);
56 cYearView->setTheMe(2);
57 }
58
59 //void CYearView::setShowDate(const QDate &showMonth, const QVector<QDate> &showDate)
60 TEST_F(test_yearview, setShowDate)
61 {
62 cYearView->setShowDate(getListDate().first(), getListDate());
63 }
64
65 //void CYearView::setHasScheduleFlag(const QVector<bool> &hasScheduleFlag)
66 TEST_F(test_yearview, setHasScheduleFlag)
67 {
68 QVector<bool> listLintFlag {};
69 listLintFlag.append(false);
70 listLintFlag.append(true);
71
72 cYearView->setHasScheduleFlag(listLintFlag);
73 }
74
75 //void CYearView::setHasSearchScheduleFlag(const QVector<bool> &hasSearchScheduleFlag)
76 TEST_F(test_yearview, setHasSearchScheduleFlag)
77 {
78 QVector<bool> listLintFlag {};
79 listLintFlag.append(false);
80 listLintFlag.append(true);
81
82 cYearView->setHasSearchScheduleFlag(listLintFlag);
83 }
84
85 void setDate_Stub(const int showMonth, const QVector<QDate> &showDate) {
86 Q_UNUSED(showMonth)
87 Q_UNUSED(showDate)}
88
89 //bool CYearView::getStartAndStopDate(QDate &startDate, QDate &stopDate)
90 TEST_F(test_yearview, getStartAndStopDate)
91 {
92 QDate startDate(QDate(2021, 1, 7));
93 QDate stopDate(QDate(2021, 1, 8));
94
95 cYearView->setShowDate(getListDate().first(), getListDate());
96 bool result = cYearView->getStartAndStopDate(startDate, stopDate);
97 EXPECT_TRUE(result);
98
99 QVector<QDate> listDate {};
100 Stub stub;
101 stub.set(ADDR(MonthBrefWidget, setDate), setDate_Stub);
102 cYearView->setShowDate(getListDate().first(), listDate);
103 bool result_false = cYearView->getStartAndStopDate(startDate, stopDate);
104 EXPECT_FALSE(result_false);
105 }
106
107 bool hasFocus_Stub()
108 {
109 return true;
110 }
111
112 TEST_F(test_yearview, paintEvent)
113 {
114 Stub stub;
115 stub.set(ADDR(QWidget, hasFocus), hasFocus_Stub);
116 cYearView->setFixedSize(600, 600);
117 QPixmap pixmap(cYearView->size());
118 cYearView->render(&pixmap);
119 }
120
121 TEST_F(test_yearview, guitest)
122 {
123 QWidget *currentMonth = cYearView->findChild<QWidget *>("currentMouth");
124 if (currentMonth) {
125 QTest::mouseDClick(currentMonth, Qt::LeftButton);
126 }
127 }