tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    73 
    73 
    74     void setTextFormat();
    74     void setTextFormat();
    75     void resetTextFormat();
    75     void resetTextFormat();
    76 
    76 
    77     void setWeekdayFormat();
    77     void setWeekdayFormat();
       
    78     void showPrevNext_data();
       
    79     void showPrevNext();
    78 };
    80 };
    79 
    81 
    80 // Testing get/set functions
    82 // Testing get/set functions
    81 void tst_QCalendarWidget::getSetCheck()
    83 void tst_QCalendarWidget::getSetCheck()
    82 {
    84 {
   291 
   293 
   292 void tst_QCalendarWidget::cleanup()
   294 void tst_QCalendarWidget::cleanup()
   293 {
   295 {
   294 }
   296 }
   295 
   297 
       
   298 
       
   299 typedef void (QCalendarWidget::*ShowFunc)();
       
   300 Q_DECLARE_METATYPE(ShowFunc)
       
   301 
       
   302 void tst_QCalendarWidget::showPrevNext_data()
       
   303 {
       
   304     QTest::addColumn<ShowFunc>("function");
       
   305     QTest::addColumn<QDate>("dateOrigin");
       
   306     QTest::addColumn<QDate>("expectedDate");
       
   307 
       
   308     QTest::newRow("showNextMonth") << &QCalendarWidget::showNextMonth << QDate(1984,7,30) << QDate(1984,8,30);
       
   309     QTest::newRow("showPrevMonth") << &QCalendarWidget::showPreviousMonth << QDate(1984,7,30) << QDate(1984,6,30);
       
   310     QTest::newRow("showNextYear") << &QCalendarWidget::showNextYear << QDate(1984,7,30) << QDate(1985,7,30);
       
   311     QTest::newRow("showPrevYear") << &QCalendarWidget::showPreviousYear << QDate(1984,7,30) << QDate(1983,7,30);
       
   312 
       
   313     QTest::newRow("showNextMonth limit") << &QCalendarWidget::showNextMonth << QDate(2007,12,4) << QDate(2008,1,4);
       
   314     QTest::newRow("showPreviousMonth limit") << &QCalendarWidget::showPreviousMonth << QDate(2006,1,23) << QDate(2005,12,23);
       
   315 
       
   316     QTest::newRow("showNextMonth now") << &QCalendarWidget::showNextMonth << QDate() << QDate::currentDate().addMonths(1);
       
   317     QTest::newRow("showNextYear now") << &QCalendarWidget::showNextYear << QDate() << QDate::currentDate().addYears(1);
       
   318     QTest::newRow("showPrevieousMonth now") << &QCalendarWidget::showPreviousMonth << QDate() << QDate::currentDate().addMonths(-1);
       
   319     QTest::newRow("showPreviousYear now") << &QCalendarWidget::showPreviousYear << QDate() << QDate::currentDate().addYears(-1);
       
   320 
       
   321     QTest::newRow("showToday now") << &QCalendarWidget::showToday << QDate(2000,1,31) << QDate::currentDate();
       
   322     QTest::newRow("showNextMonth 31") << &QCalendarWidget::showNextMonth << QDate(2000,1,31) << QDate(2000,2,28);
       
   323     QTest::newRow("selectedDate") << &QCalendarWidget::showSelectedDate << QDate(2008,2,29) << QDate(2008,2,29);
       
   324 
       
   325 }
       
   326 
       
   327 void tst_QCalendarWidget::showPrevNext()
       
   328 {
       
   329     QFETCH(ShowFunc, function);
       
   330     QFETCH(QDate, dateOrigin);
       
   331     QFETCH(QDate, expectedDate);
       
   332 
       
   333     QCalendarWidget calWidget;
       
   334     calWidget.show();
       
   335     QTest::qWaitForWindowShown(&calWidget);
       
   336     if(!dateOrigin.isNull()) {
       
   337         calWidget.setSelectedDate(dateOrigin);
       
   338         calWidget.setCurrentPage(dateOrigin.year(), dateOrigin.month());
       
   339 
       
   340         QCOMPARE(calWidget.yearShown(), dateOrigin.year());
       
   341         QCOMPARE(calWidget.monthShown(), dateOrigin.month());
       
   342     } else {
       
   343         QCOMPARE(calWidget.yearShown(), QDate::currentDate().year());
       
   344         QCOMPARE(calWidget.monthShown(), QDate::currentDate().month());
       
   345     }
       
   346 
       
   347     (calWidget.*function)();
       
   348 
       
   349     QCOMPARE(calWidget.yearShown(), expectedDate.year());
       
   350     QCOMPARE(calWidget.monthShown(), expectedDate.month());
       
   351 
       
   352     // QTBUG-4058
       
   353     QTest::qWait(20);
       
   354     QToolButton *button = qFindChild<QToolButton *>(&calWidget, "qt_calendar_prevmonth");
       
   355     QTest::mouseClick(button, Qt::LeftButton);
       
   356     expectedDate = expectedDate.addMonths(-1);
       
   357     QCOMPARE(calWidget.yearShown(), expectedDate.year());
       
   358     QCOMPARE(calWidget.monthShown(), expectedDate.month());
       
   359 
       
   360     if(!dateOrigin.isNull()) {
       
   361         //the selectedDate should not have changed
       
   362         QCOMPARE(calWidget.selectedDate(), dateOrigin);
       
   363     }
       
   364 }
       
   365 
   296 QTEST_MAIN(tst_QCalendarWidget)
   366 QTEST_MAIN(tst_QCalendarWidget)
   297 #include "tst_qcalendarwidget.moc"
   367 #include "tst_qcalendarwidget.moc"