| 1 |
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#include "test_monthbrefwidget.h" |
| 6 |
|
| 7 |
#include <QResizeEvent> |
| 8 |
#include <QApplication> |
| 9 |
#include <QMouseEvent> |
| 10 |
#include <QTest> |
| 11 |
|
| 12 |
test_monthbrefwidget::test_monthbrefwidget() |
| 13 |
{ |
| 14 |
|
| 15 |
} |
| 16 |
|
| 17 |
test_monthbrefwidget::~test_monthbrefwidget() |
| 18 |
{ |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
void test_monthbrefwidget::SetUp() |
| 23 |
{ |
| 24 |
mMonthBrefWidget = new MonthBrefWidget(); |
| 25 |
mMonthDayRect = new CMonthDayRect(); |
| 26 |
} |
| 27 |
|
| 28 |
void test_monthbrefwidget::TearDown() |
| 29 |
{ |
| 30 |
delete mMonthBrefWidget; |
| 31 |
mMonthBrefWidget = nullptr; |
| 32 |
delete mMonthDayRect; |
| 33 |
mMonthDayRect = nullptr; |
| 34 |
} |
| 35 |
|
| 36 |
QVector<QDate> getDateList() |
| 37 |
{ |
| 38 |
QDate currentdate = QDate::currentDate(); |
| 39 |
QVector<QDate> dateList; |
| 40 |
for (int i = 0; i < 42; i++) { |
| 41 |
dateList.append(currentdate.addDays(i)); |
| 42 |
} |
| 43 |
return dateList; |
| 44 |
} |
| 45 |
|
| 46 |
QVector<bool> getBoolList() |
| 47 |
{ |
| 48 |
QVector<bool> lineList; |
| 49 |
for (int i = 0; i < 42; i++) { |
| 50 |
if (i % 2 == 0) |
| 51 |
lineList.append(true); |
| 52 |
else |
| 53 |
lineList.append(false); |
| 54 |
} |
| 55 |
return lineList; |
| 56 |
} |
| 57 |
|
| 58 |
//void MonthBrefWidget::setDate(const int showMonth, const QVector<QDate> &showDate) |
| 59 |
TEST_F(test_monthbrefwidget, setDate) |
| 60 |
{ |
| 61 |
const int month = 4; |
| 62 |
mMonthBrefWidget->setDate(month, getDateList()); |
| 63 |
} |
| 64 |
|
| 65 |
//void MonthBrefWidget::setTheMe(int type) |
| 66 |
TEST_F(test_monthbrefwidget, setTheMe) |
| 67 |
{ |
| 68 |
mMonthBrefWidget->setTheMe(1); |
| 69 |
mMonthBrefWidget->setTheMe(2); |
| 70 |
} |
| 71 |
|
| 72 |
//void MonthBrefWidget::setLintFlag(const QVector<bool> &lineFlag) |
| 73 |
TEST_F(test_monthbrefwidget, setLintFlag) |
| 74 |
{ |
| 75 |
mMonthBrefWidget->setLintFlag(getBoolList()); |
| 76 |
} |
| 77 |
|
| 78 |
//void MonthBrefWidget::setSearchScheduleFlag(const QVector<bool> &searchFlag) |
| 79 |
TEST_F(test_monthbrefwidget, setSearchScheduleFlag) |
| 80 |
{ |
| 81 |
mMonthBrefWidget->setSearchScheduleFlag(getBoolList()); |
| 82 |
} |
| 83 |
|
| 84 |
//void MonthBrefWidget::updateSize() |
| 85 |
TEST_F(test_monthbrefwidget, updateSize) |
| 86 |
{ |
| 87 |
mMonthBrefWidget->updateSize(); |
| 88 |
} |
| 89 |
|
| 90 |
//int MonthBrefWidget::getMousePosItem(const QPointF &pos) |
| 91 |
TEST_F(test_monthbrefwidget, getMousePosItem) |
| 92 |
{ |
| 93 |
QPointF pointf; |
| 94 |
mMonthBrefWidget->getMousePosItem(pointf); |
| 95 |
} |
| 96 |
|
| 97 |
//void MonthBrefWidget::mousePress(const QPoint &point |
| 98 |
TEST_F(test_monthbrefwidget, mousePress) |
| 99 |
{ |
| 100 |
QPoint point; |
| 101 |
mMonthBrefWidget->mousePress(point); |
| 102 |
} |
| 103 |
|
| 104 |
//void CMonthDayRect::setTheMe(int type) |
| 105 |
TEST_F(test_monthbrefwidget, settheme) |
| 106 |
{ |
| 107 |
mMonthDayRect->setTheMe(1); |
| 108 |
mMonthDayRect->setTheMe(2); |
| 109 |
} |
| 110 |
|
| 111 |
//void CMonthDayRect::setDate(const QDate &date) |
| 112 |
TEST_F(test_monthbrefwidget, setdate) |
| 113 |
{ |
| 114 |
mMonthDayRect->setDate(QDate::currentDate()); |
| 115 |
} |
| 116 |
|
| 117 |
//QDate CMonthDayRect::getDate() const |
| 118 |
TEST_F(test_monthbrefwidget, getdate) |
| 119 |
{ |
| 120 |
mMonthDayRect->setDate(QDate::currentDate()); |
| 121 |
mMonthDayRect->getDate(); |
| 122 |
} |
| 123 |
|
| 124 |
//void CMonthDayRect::setCellEvent(const CMonthDayRect::CellEventType &type) |
| 125 |
TEST_F(test_monthbrefwidget, setCellEvent) |
| 126 |
{ |
| 127 |
mMonthDayRect->setCellEvent(CMonthDayRect::CellEventType::Cellhover); |
| 128 |
} |
| 129 |
|
| 130 |
//void CMonthDayRect::setIsCurrentMonth(const bool isCurrMonth) |
| 131 |
TEST_F(test_monthbrefwidget, setIsCurrentMonth) |
| 132 |
{ |
| 133 |
mMonthDayRect->setIsCurrentMonth(true); |
| 134 |
} |
| 135 |
|
| 136 |
//QRectF CMonthDayRect::rect() const |
| 137 |
TEST_F(test_monthbrefwidget, rect) |
| 138 |
{ |
| 139 |
mMonthDayRect->setRect(QRect(10, 10, 8, 8)); |
| 140 |
mMonthDayRect->rect(); |
| 141 |
} |
| 142 |
|
| 143 |
//void CMonthDayRect::setRect(const QRectF &rect) |
| 144 |
TEST_F(test_monthbrefwidget, setRect) |
| 145 |
{ |
| 146 |
mMonthDayRect->setRect(QRect(10, 10, 8, 8)); |
| 147 |
} |
| 148 |
|
| 149 |
//void CMonthDayRect::setRect(qreal x, qreal y, qreal w, qreal h) |
| 150 |
TEST_F(test_monthbrefwidget, setrect) |
| 151 |
{ |
| 152 |
// mMonthDayRect->setRect(8, 8, 8, 8); |
| 153 |
} |
| 154 |
|
| 155 |
//void CMonthDayRect::setLineFlag(const bool flag) |
| 156 |
TEST_F(test_monthbrefwidget, setLIneflag) |
| 157 |
{ |
| 158 |
mMonthDayRect->setLineFlag(true); |
| 159 |
} |
| 160 |
|
| 161 |
//void CMonthDayRect::setSearchScheduleFlag(const bool flag) |
| 162 |
TEST_F(test_monthbrefwidget, setSearchScheduleflag) |
| 163 |
{ |
| 164 |
mMonthDayRect->setSearchScheduleFlag(true); |
| 165 |
} |
| 166 |
|
| 167 |
//void CMonthDayRect::setDevicePixelRatio(const qreal pixel) |
| 168 |
TEST_F(test_monthbrefwidget, setDevicePixelRatio) |
| 169 |
{ |
| 170 |
mMonthDayRect->setDevicePixelRatio(2); |
| 171 |
} |
| 172 |
|
| 173 |
//void CMonthDayRect::setCurrentRect(CMonthDayRect *currrect) |
| 174 |
TEST_F(test_monthbrefwidget, setCurrentrect) |
| 175 |
{ |
| 176 |
|
| 177 |
mMonthDayRect->setCurrentRect(mMonthDayRect); |
| 178 |
} |
| 179 |
|
| 180 |
//void CMonthDayRect::setSystemActiveColor(const QColor &activeColor) |
| 181 |
TEST_F(test_monthbrefwidget, setSystemActiveColor) |
| 182 |
{ |
| 183 |
mMonthDayRect->setSystemActiveColor(Qt::red); |
| 184 |
} |
| 185 |
|
| 186 |
//getPixmap |
| 187 |
TEST_F(test_monthbrefwidget, getPixmap) |
| 188 |
{ |
| 189 |
mMonthBrefWidget->setFixedSize(800, 500); |
| 190 |
mMonthBrefWidget->setDate(QDate::currentDate().month(), getDateList()); |
| 191 |
QPixmap pixmap(mMonthBrefWidget->size()); |
| 192 |
mMonthBrefWidget->render(&pixmap); |
| 193 |
} |
| 194 |
|
| 195 |
TEST_F(test_monthbrefwidget, resizeEvent) |
| 196 |
{ |
| 197 |
mMonthBrefWidget->setFixedSize(QSize(600, 500)); |
| 198 |
QResizeEvent resizeEvent(QSize(600, 501), QSize(600, 500)); |
| 199 |
QApplication::sendEvent(mMonthBrefWidget, &resizeEvent); |
| 200 |
} |
| 201 |
|
| 202 |
TEST_F(test_monthbrefwidget, mouseEvent) |
| 203 |
{ |
| 204 |
mMonthBrefWidget->setFixedSize(QSize(600, 500)); |
| 205 |
mMonthBrefWidget->setDate(QDate::currentDate().month(), getDateList()); |
| 206 |
QTest::mouseDClick(mMonthBrefWidget, Qt::MouseButton::LeftButton); |
| 207 |
QTest::mouseRelease(mMonthBrefWidget, Qt::MouseButton::LeftButton); |
| 208 |
} |
| 209 |
|
| 210 |
//mouseDoubleClickEvent |
| 211 |
TEST_F(test_monthbrefwidget, mouseDoubleClickEvent) |
| 212 |
{ |
| 213 |
mMonthBrefWidget->setFixedSize(QSize(600, 500)); |
| 214 |
mMonthBrefWidget->setDate(QDate::currentDate().month(), getDateList()); |
| 215 |
QTest::mouseDClick(mMonthBrefWidget, Qt::MouseButton::LeftButton); |
| 216 |
} |