calendarui/views/dayview/tsrc/unittests/unittest_calendaymodel/unittest_calendaymodel.cpp
changeset 81 ce92091cbd61
parent 55 2c54b51f39c4
equal deleted inserted replaced
75:7ac58b2aae6f 81:ce92091cbd61
   103 
   103 
   104 /*!
   104 /*!
   105  Test function for constructors
   105  Test function for constructors
   106  1. Test if model is not initialized
   106  1. Test if model is not initialized
   107  2. Test if model is correcty created
   107  2. Test if model is correcty created
       
   108  3. Test if model is created but not initialized
   108  */
   109  */
   109 void TestCalenDayModel::testConstructors()
   110 void TestCalenDayModel::testConstructors()
   110 {
   111 {
   111     //1)
   112     //1)
   112     CalenDayModel *testModel = 0;
   113     CalenDayModel *testModel = 0;
   115     //2)
   116     //2)
   116     testModel = new CalenDayModel(mDateTime, *mServices);
   117     testModel = new CalenDayModel(mDateTime, *mServices);
   117     QVERIFY(testModel);
   118     QVERIFY(testModel);
   118     
   119     
   119     delete testModel;
   120     delete testModel;
       
   121     testModel = 0;
       
   122     //3)
       
   123     QDateTime invalidDate = QDateTime::fromString("Invalid text");
       
   124     testModel = new CalenDayModel(invalidDate, *mServices);
       
   125     
       
   126     QVERIFY(testModel);
       
   127     QVERIFY(testModel->modelDate().isValid() == false);
   120 }
   128 }
   121 
   129 
   122 void TestCalenDayModel::testRowCount()
   130 void TestCalenDayModel::testRowCount()
   123 	{
   131 	{
   124 		mModel->refreshModel(QDateTime());
   132 		mModel->refreshModel(QDateTime());
   125 		QCOMPARE(mModel->rowCount(QModelIndex()), 1);
   133 		QCOMPARE(mModel->rowCount(QModelIndex()), 1);
   126 	}
   134 	}
   127 
   135 
       
   136 /*!
       
   137    Test if it return good model data
       
   138    1)Test invalid model index
       
   139    2)Index is bigger than entry values
       
   140    3)Index is valid and there is entry value
       
   141    4)Wrong role
       
   142  */
   128 void TestCalenDayModel::testData()
   143 void TestCalenDayModel::testData()
   129 	{
   144 	{
       
   145     
       
   146     
   130 		mModel->refreshModel(QDateTime());
   147 		mModel->refreshModel(QDateTime());
   131 		
   148 		
       
   149 		//1)
   132 		QVariant var = mModel->data(QModelIndex(), Qt::UserRole + 1);
   150 		QVariant var = mModel->data(QModelIndex(), Qt::UserRole + 1);
   133 		QString typeName(var.typeName());
   151 		QCOMPARE(var, QVariant());
   134 		QCOMPARE(typeName, QString());
       
   135 		mModel->refreshModel(QDateTime());
       
   136 		
   152 		
   137 		var = mModel->data(QModelIndex(), Qt::UserRole + 1);
   153 		//2)
   138 		typeName = QString(var.typeName());
   154 		QModelIndex index = mModel->index(5);
   139 		QCOMPARE(typeName, QString(""));
       
   140 		
   155 		
       
   156 		var = mModel->data(index, Qt::UserRole + 1);
       
   157 		QCOMPARE(var, QVariant());
       
   158 		
       
   159 		//3)
       
   160 		index = mModel->index(0);
       
   161 		var = mModel->data(index, Qt::UserRole + 1);
       
   162 		QCOMPARE(var.canConvert<AgendaEntry> (),true);
       
   163 		
       
   164 		//4)
       
   165 		var = mModel->data(index, Qt::UserRole + 10);
       
   166 		QCOMPARE(var, QVariant());
   141 	}
   167 	}
   142 
   168 
   143 void TestCalenDayModel::testRefreshModel()
   169 void TestCalenDayModel::testRefreshModel()
   144 	{
   170 	{
   145 		QDateTime date(QDate(2001, 1, 2), QTime(1, 0, 0));
   171 		QDateTime date(QDate(2001, 1, 2), QTime(1, 0, 0));