calendarui/views/dayview/tsrc/unittests/unittest_calendayhourelement/unittest_calendayhourelement.cpp
changeset 81 ce92091cbd61
parent 55 2c54b51f39c4
equal deleted inserted replaced
75:7ac58b2aae6f 81:ce92091cbd61
    15  *
    15  *
    16  */
    16  */
    17 #include <QGraphicsItem>
    17 #include <QGraphicsItem>
    18 #include <QtTest/QtTest>
    18 #include <QtTest/QtTest>
    19 
    19 
       
    20 #ifndef __WINSCW__
       
    21 #define private public
       
    22 #define protected public
       
    23 #endif
       
    24 
    20 #include "calendayhourelementtest.h"
    25 #include "calendayhourelementtest.h"
    21 #include "calendayhourscrollarea.h"
    26 #include "calendayhourscrollarea.h"
    22 
    27 
    23 #include <QPainter>
    28 #include <QPainter>
    24 #include <QImage>
    29 #include <QImage>
    44 
    49 
    45     void testConstructors();
    50     void testConstructors();
    46     void testSetGetTime();
    51     void testSetGetTime();
    47     void testPaint_data();
    52     void testPaint_data();
    48     void testPaint();
    53     void testPaint();
       
    54     void testLocaleChanged();
    49 
    55 
    50 private:
    56 private:
    51     CalenDayHourElementTest *mHourElement;
    57     CalenDayHourElementTest *mHourElement;
    52     CalenDayHourScrollArea  *mContainer;
    58     CalenDayHourScrollArea  *mContainer;
    53     QTime   mTime;
    59     QTime   mTime;
   176    It check painting based on given time.
   182    It check painting based on given time.
   177    \sa testPaint_data
   183    \sa testPaint_data
   178  */
   184  */
   179 void TestCalenDayHourElement::testPaint()
   185 void TestCalenDayHourElement::testPaint()
   180 {
   186 {
   181     
   187     //1)
   182     //get data to test
   188     //get data to test
   183     QFETCH(QDateTime, testedValue); 
   189     QFETCH(QDateTime, testedValue); 
   184     QFETCH(QString, testName); 
   190     QFETCH(QString, testName); 
   185     
   191     
   186     mHourElement->setTime(testedValue.time());
   192     mHourElement->setTime(testedValue.time());
   203     //run paint
   209     //run paint
   204     mHourElement->paint(&painter,option,0);
   210     mHourElement->paint(&painter,option,0);
   205      
   211      
   206 #ifdef SAVE_IMAGES
   212 #ifdef SAVE_IMAGES
   207     //save drawed image
   213     //save drawed image
   208     img.save("c:/unittest/TestCalenDayHourElement_testPaint_" + testName + ".jpg");
   214     img.save("c:/unittest/TestCalenDayHourElement_testPaint_" + testName + ".jpg");   
   209      
   215 #endif
       
   216     
       
   217     //2)
       
   218     QDateTime currentDateTime = QDateTime::currentDateTime();
       
   219     int currentHour = currentDateTime.time().hour();
       
   220     mHourElement->setTime(QTime(currentHour + 1, 0 ));
       
   221     //fill image with grey color to have better filings with look of "paper"
       
   222     painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
       
   223     //run paint
       
   224     mHourElement->paint(&painter,option,0);
       
   225 
       
   226 #ifdef SAVE_IMAGES
       
   227     //save drawed image
       
   228     img.save("c:/unittest/TestCalenDayHourElement_testPaint_" + testName + "2.jpg");
       
   229 #endif
       
   230 
       
   231     //3)
       
   232 #ifndef __WINSCW__
       
   233     mHourElement->mContainer = NULL;    
       
   234     //fill image with grey color to have better filings with look of "paper"
       
   235     painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
       
   236     //run paint
       
   237     mHourElement->paint(&painter,option,0);
       
   238     
       
   239 #ifdef SAVE_IMAGES
       
   240     //save drawed image
       
   241     img.save("c:/unittest/TestCalenDayHourElement_testPaint_" + testName + "3.jpg");
       
   242 #endif
       
   243 
       
   244 #endif
       
   245 }
       
   246 
       
   247 /*!
       
   248  Test function for localChanged method
       
   249  */
       
   250 void TestCalenDayHourElement::testLocaleChanged() 
       
   251 {
       
   252 #ifndef __WINSCW__
       
   253     mHourElement->mTimeTextItem->setText(QString(""));
       
   254     mHourElement->localeChanged();
       
   255     QVERIFY(mHourElement->mTimeTextItem->text() != QString(""));
   210 #endif
   256 #endif
   211 }
   257 }
   212 
   258 
   213 QTEST_MAIN(TestCalenDayHourElement);
   259 QTEST_MAIN(TestCalenDayHourElement);
   214 #include "unittest_calendayhourelement.moc"
   260 #include "unittest_calendayhourelement.moc"