calendarui/views/dayview/tsrc/unittests/unittest_calendayhourelement/unittest_calendayhourelement.cpp
changeset 55 2c54b51f39c4
parent 45 b6db4fd4947b
child 81 ce92091cbd61
equal deleted inserted replaced
51:0b38fc5b94c6 55:2c54b51f39c4
     9  * Initial Contributors:
     9  * Initial Contributors:
    10  * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11  *
    11  *
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description: Test class for CalenDayContentWidget
    14  * Description: Test class for TestCalenDayHourElement
    15  *
    15  *
    16  */
    16  */
    17 #include <QGraphicsItem>
    17 #include <QGraphicsItem>
    18 #include <QtTest/QtTest>
    18 #include <QtTest/QtTest>
    19 
    19 
    20 #include "calendayhourelement.h"
    20 #include "calendayhourelementtest.h"
       
    21 #include "calendayhourscrollarea.h"
       
    22 
       
    23 #include <QPainter>
       
    24 #include <QImage>
       
    25 #include <QPair>
       
    26 #include <QDateTime>
       
    27 
       
    28 const qreal WIDGET_WIDTH = 50;
       
    29 const qreal WIDGET_HEIGHT = 150;
    21 
    30 
    22 class TestCalenDayHourElement : public QObject
    31 class TestCalenDayHourElement : public QObject
    23 {
    32 {
    24 Q_OBJECT
    33 Q_OBJECT
    25 
    34 
    32     void cleanupTestCase();
    41     void cleanupTestCase();
    33     void init();
    42     void init();
    34     void cleanup();
    43     void cleanup();
    35 
    44 
    36     void testConstructors();
    45     void testConstructors();
       
    46     void testSetGetTime();
       
    47     void testPaint_data();
       
    48     void testPaint();
    37 
    49 
    38 private:
    50 private:
    39     CalenDayHourElement *mHourElement;
    51     CalenDayHourElementTest *mHourElement;
       
    52     CalenDayHourScrollArea  *mContainer;
    40     QTime   mTime;
    53     QTime   mTime;
    41 };
    54 };
    42 
    55 
    43 /*!
    56 /*!
    44  Constructor
    57  Constructor
    75 /*!
    88 /*!
    76  Called before every function
    89  Called before every function
    77  */
    90  */
    78 void TestCalenDayHourElement::init()
    91 void TestCalenDayHourElement::init()
    79 {
    92 {
    80     mHourElement = new CalenDayHourElement(mTime);
    93     mTime = QTime(12,0,0);
       
    94     mContainer = new CalenDayHourScrollArea();
       
    95     mHourElement = new CalenDayHourElementTest(mTime,mContainer);
    81 }
    96 }
    82 
    97 
    83 /*!
    98 /*!
    84  Called after everyfunction
    99  Called after everyfunction
    85  */
   100  */
    97  2. Test if content widget is correcty created
   112  2. Test if content widget is correcty created
    98  */
   113  */
    99 void TestCalenDayHourElement::testConstructors()
   114 void TestCalenDayHourElement::testConstructors()
   100 {
   115 {
   101     //1)
   116     //1)
   102     CalenDayHourElement *testHourElement = 0;
   117     CalenDayHourElementTest *testHourElement = 0;
   103     QVERIFY(!testHourElement);
   118     QVERIFY(!testHourElement);
   104     
   119     
   105     testHourElement = new CalenDayHourElement(mTime);
   120     testHourElement = new CalenDayHourElementTest(mTime,mContainer);
   106     
   121     
   107     QVERIFY(testHourElement);
   122     QVERIFY(testHourElement);
   108     
   123     
   109     delete testHourElement;
   124     delete testHourElement;
       
   125 }
       
   126 
       
   127 /*!
       
   128    \brief It test is setting and getting of time works good.
       
   129    
       
   130    0)Test if time from constructor works good
       
   131    1)Test set new time
       
   132    2)Change time and test new
       
   133  */
       
   134 void TestCalenDayHourElement::testSetGetTime()
       
   135 {
       
   136     //0)
       
   137     QVERIFY(mTime == mHourElement->time());
       
   138     
       
   139     QTime testValue(15,15,15);
       
   140     //1)
       
   141     mHourElement->setTime(testValue);
       
   142     
       
   143     QVERIFY(testValue == mHourElement->time());
       
   144     
       
   145     //2)
       
   146     testValue = QTime(10,10,10);
       
   147     
       
   148     mHourElement->setTime(testValue);
       
   149     QVERIFY(testValue == mHourElement->time());
       
   150 }
       
   151 
       
   152 /*!
       
   153    \brief Test data for \sa testPaint
       
   154    
       
   155    Tested data:
       
   156    1)Hour is eual 0
       
   157    2)Hour is bigger than 0
       
   158    3)Test current time
       
   159  */
       
   160 void TestCalenDayHourElement::testPaint_data()
       
   161 {
       
   162     QTest::addColumn<QDateTime>("testedValue");
       
   163     QTest::addColumn<QString>("testName");
       
   164     
       
   165     QTest::newRow("hour = 0") << QDateTime(QDate(2010,06,26),QTime(0,10,0)) 
       
   166                               << QString("hour = 0"); 
       
   167     QTest::newRow("hour != 0") << QDateTime(QDate(2010,06,26),QTime(15,15,15)) 
       
   168                                << QString("hour != 0");
       
   169     QTest::newRow("current time") << QDateTime::currentDateTime() 
       
   170                                   << QString("current time");
       
   171 }
       
   172 
       
   173 /*!
       
   174    \brief Test painting method
       
   175    
       
   176    It check painting based on given time.
       
   177    \sa testPaint_data
       
   178  */
       
   179 void TestCalenDayHourElement::testPaint()
       
   180 {
       
   181     
       
   182     //get data to test
       
   183     QFETCH(QDateTime, testedValue); 
       
   184     QFETCH(QString, testName); 
       
   185     
       
   186     mHourElement->setTime(testedValue.time());
       
   187     
       
   188     //set date to check
       
   189     mContainer->setDateTime(testedValue);
       
   190     
       
   191     QStyleOptionGraphicsItem * option = new QStyleOptionGraphicsItem();
       
   192     //preapre drawed area smaller because of drawing lines on corners
       
   193     option->rect = QRect(10,10,WIDGET_WIDTH-20,WIDGET_HEIGHT/2);
       
   194     mHourElement->resize(WIDGET_WIDTH,WIDGET_HEIGHT);
       
   195     QSize size = mHourElement->size().toSize();
       
   196      
       
   197     //create image that will simulate widget where painting should be done
       
   198     QImage img(size,QImage::Format_RGB32);
       
   199     //create painter which will be used to paint
       
   200     QPainter painter(&img);
       
   201     //fill image with grey color to have better filings with look of "paper"
       
   202     painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
       
   203     //run paint
       
   204     mHourElement->paint(&painter,option,0);
       
   205      
       
   206 #ifdef SAVE_IMAGES
       
   207     //save drawed image
       
   208     img.save("c:/unittest/TestCalenDayHourElement_testPaint_" + testName + ".jpg");
       
   209      
       
   210 #endif
   110 }
   211 }
   111 
   212 
   112 QTEST_MAIN(TestCalenDayHourElement);
   213 QTEST_MAIN(TestCalenDayHourElement);
   113 #include "unittest_calendayhourelement.moc"
   214 #include "unittest_calendayhourelement.moc"