organizer_plat/agenda_interface_api/tsrc/unittest_agendautil/src/unittest_agendautil.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 55 2c54b51f39c4
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
     1 /*
     1 /*
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3  * All rights reserved.
     4  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8  *
     8  *
     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: AgendaUtil unit test class.
    14  * Description: AgendaUtil unit test class.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    24 #include "agendautil.h"
    24 #include "agendautil.h"
    25 
    25 
    26 class TestAgendaUtil : public QObject
    26 class TestAgendaUtil : public QObject
    27 {
    27 {
    28 	Q_OBJECT
    28 	Q_OBJECT
    29 	
    29 
    30 public slots:
    30 public slots:
    31 	void handleEntriesDeletion(int error);
    31 	void handleEntriesDeletion(int error);
    32 
    32 	void handleEntryViewCreationCompleted(int status);
    33 private:
    33 
    34 	int createMultipleEntries();
       
    35 	
       
    36 private slots:
    34 private slots:
    37 	// Test case setup.
    35 	// Test case setup.
    38 	void init();
    36 	void init();
    39 	void cleanup();
    37 	void cleanup();
    40 	void initTestCase();
    38 	void initTestCase();
    41 	void cleanupTestCase();
    39 	void cleanupTestCase();
    42 	
    40 
    43 	// Test cases.
    41 	// Test cases.
    44 	void test_addEntry();
    42 	void test_addEntry();
    45 	void test_deleteEntry();
    43 	void test_deleteEntry();
    46 	void test_deleteRepeatedEntry();
    44 	void test_deleteRepeatedEntry();
    47 	void test_fetchById();
    45 	void test_fetchById();
    49 	void test_createEntryIdListForDay();
    47 	void test_createEntryIdListForDay();
    50 	void test_entryIds();
    48 	void test_entryIds();
    51 	void test_fetchAllEntries();
    49 	void test_fetchAllEntries();
    52 	void test_deleteEntries();
    50 	void test_deleteEntries();
    53 	void test_fetchEntriesInRange();
    51 	void test_fetchEntriesInRange();
       
    52 	void test_cloneEntry();
       
    53 	void test_todoCompleted();
       
    54 
       
    55 private:
       
    56 	int createMultipleEntries();
       
    57 	void cloneNoteToTodo();
       
    58 	void cloneNoteToMeeting();
       
    59 	void cloneTodoToNote();
       
    60 	void cloneTodoToMeeting();
       
    61 	void cloneMeetingToNote();
       
    62 	void cloneMeetingToTodo();
       
    63 	void completeTodo();
       
    64 	void unCompletedTodo();
    54 
    65 
    55 private:
    66 private:
    56 	AgendaUtil *mAgendaUtil;
    67 	AgendaUtil *mAgendaUtil;
    57 	CActiveSchedulerWait* mWait;
    68 	CActiveSchedulerWait* mWait;
    58 };
    69 };
    59 
    70 
    60 /*!
    71 /*!
    61 	\class TestAgendaUtil
    72 	\class TestAgendaUtil
    62 	
    73 
    63 	This is unittest class for AgendaUtil apis.
    74 	This is unittest class for AgendaUtil apis.
    64  */
    75  */
    65 
    76 
    66 /*!
    77 /*!
    67 	This function is called to before every testcase.
    78 	This function is called to before every testcase.
    69 void TestAgendaUtil::init()
    80 void TestAgendaUtil::init()
    70 {
    81 {
    71 	/*QT_TRAP_THROWING(mAgendaUtil = new AgendaUtil);
    82 	/*QT_TRAP_THROWING(mAgendaUtil = new AgendaUtil);
    72 
    83 
    73 	Q_ASSERT_X(mAgendaUtil, "TestAgendaUtil::test_addEntry", "No agendautil");
    84 	Q_ASSERT_X(mAgendaUtil, "TestAgendaUtil::test_addEntry", "No agendautil");
    74 	
    85 
    75 	// Connect to the required signals
    86 	// Connect to the required signals
    76 	connect(
    87 	connect(
    77 			mAgendaUtil, SIGNAL(entriesDeleted(int)), this,
    88 			mAgendaUtil, SIGNAL(entriesDeleted(int)), this,
    78 			SLOT(handleEntriesDeletion(int)));
    89 			SLOT(handleEntriesDeletion(int)));
    79 
    90 
    83 /*!
    94 /*!
    84 	This function is called after every testcase.
    95 	This function is called after every testcase.
    85  */
    96  */
    86 void TestAgendaUtil::cleanup()
    97 void TestAgendaUtil::cleanup()
    87 {
    98 {
    88 		
    99 
    89 	//User::Exit(0);
   100 	//User::Exit(0);
    90     if (mWait && mWait->IsStarted()) {
   101     if (mWait && mWait->IsStarted()) {
    91                 mWait->AsyncStop();
   102                 mWait->AsyncStop();
    92     }
   103     }
    93     delete mWait;
   104     delete mWait;
    97 	This function is called to init the testcase.
   108 	This function is called to init the testcase.
    98  */
   109  */
    99 void TestAgendaUtil::initTestCase()
   110 void TestAgendaUtil::initTestCase()
   100 {
   111 {
   101 	QT_TRAP_THROWING(mAgendaUtil = new AgendaUtil);
   112 	QT_TRAP_THROWING(mAgendaUtil = new AgendaUtil);
   102 	
   113 
       
   114 	connect(
       
   115 			mAgendaUtil, SIGNAL(entryViewCreationCompleted(int)),
       
   116 			this, SLOT(handleEntryViewCreationCompleted(int)));
       
   117 
       
   118 	// Start the timer as the instanceview/entryview creation
       
   119 	// operation is asynchronous
       
   120 	QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
       
   121 		if (!mWait->IsStarted()) {
       
   122 			mWait->Start();
       
   123 	}
       
   124 
   103 	Q_ASSERT_X(mAgendaUtil, "TestAgendaUtil::test_addEntry", "No agendautil");
   125 	Q_ASSERT_X(mAgendaUtil, "TestAgendaUtil::test_addEntry", "No agendautil");
   104 	
   126 
   105 	// Connect to the required signals
   127 	// Connect to the required signals
   106 	connect(
   128 	connect(
   107 			mAgendaUtil, SIGNAL(entriesDeleted(int)), this,
   129 			mAgendaUtil, SIGNAL(entriesDeleted(int)), this,
   108 			SLOT(handleEntriesDeletion(int)));
   130 			SLOT(handleEntriesDeletion(int)));
   109 	
   131 
   110 	mWait = NULL;
   132 	mWait = NULL;
   111 }
   133 }
   112 
   134 
   113 void TestAgendaUtil::cleanupTestCase()
   135 void TestAgendaUtil::cleanupTestCase()
   114 {
   136 {
   115     //User::Exit(0);
   137 	QCoreApplication::processEvents();
   116     QCoreApplication::processEvents();
   138 	if (mAgendaUtil) {
   117     if (mAgendaUtil) {
   139 		delete mAgendaUtil;
   118             delete mAgendaUtil;
   140 	}
   119     }
       
   120 }
   141 }
   121 /*
   142 /*
   122 	Tests the AgendaUtil::addEntry.
   143 	Tests the AgendaUtil::addEntry.
   123  */
   144  */
   124 void TestAgendaUtil::test_addEntry()
   145 void TestAgendaUtil::test_addEntry()
   129 	QTime timeSet(10,10,10,10);
   150 	QTime timeSet(10,10,10,10);
   130 	QDateTime dateTimeSet(dateSet,timeSet);
   151 	QDateTime dateTimeSet(dateSet,timeSet);
   131 	entry.setType(AgendaEntry::TypeEvent);
   152 	entry.setType(AgendaEntry::TypeEvent);
   132 	entry.setSummary("Test case");
   153 	entry.setSummary("Test case");
   133 	entry.setStartAndEndTime(dateTimeSet, dateTimeSet);
   154 	entry.setStartAndEndTime(dateTimeSet, dateTimeSet);
   134 	
   155 
   135 	// Run the case.
   156 	// Run the case.
   136 	ulong id = mAgendaUtil->addEntry(entry);
   157 	ulong id = mAgendaUtil->addEntry(entry);
   137 	
   158 
   138 	// Verify.
   159 	// Verify.
   139 	AgendaEntry newEntry = mAgendaUtil->fetchById(id);
   160 	AgendaEntry newEntry = mAgendaUtil->fetchById(id);
   140 	QDateTime dateTimeRetrieved = newEntry.startTime();
   161 	QDateTime dateTimeRetrieved = newEntry.startTime();
   141 	QDate dateRetrieved = dateTimeRetrieved.date();
   162 	QDate dateRetrieved = dateTimeRetrieved.date();
   142 	QTime timeRetrieved = dateTimeRetrieved.time();
   163 	QTime timeRetrieved = dateTimeRetrieved.time();
   155 	// Test case setup.
   176 	// Test case setup.
   156 	AgendaEntry entry;
   177 	AgendaEntry entry;
   157 	entry.setType(AgendaEntry::TypeEvent);
   178 	entry.setType(AgendaEntry::TypeEvent);
   158 	entry.setSummary("Test case");
   179 	entry.setSummary("Test case");
   159 	entry.setStartAndEndTime(
   180 	entry.setStartAndEndTime(
   160 			QDateTime::currentDateTime(), 
   181 			QDateTime::currentDateTime(),
   161 			QDateTime::currentDateTime());
   182 			QDateTime::currentDateTime());
   162 	ulong id = mAgendaUtil->addEntry(entry);
   183 	ulong id = mAgendaUtil->addEntry(entry);
   163 	
   184 
   164 	// Run the case.
   185 	// Run the case.
   165 	QVERIFY(mAgendaUtil->deleteEntry(id));
   186 	QVERIFY(mAgendaUtil->deleteEntry(id));
   166 	
   187 
   167 	// Verify.
   188 	// Verify.
   168 	QVERIFY(mAgendaUtil->fetchById(id).isNull());
   189 	QVERIFY(mAgendaUtil->fetchById(id).isNull());
   169 }
   190 }
   170 
   191 
   171 /*!
   192 /*!
   176 	// Test case setup.
   197 	// Test case setup.
   177 	AgendaEntry entry;
   198 	AgendaEntry entry;
   178 	entry.setType(AgendaEntry::TypeAppoinment);
   199 	entry.setType(AgendaEntry::TypeAppoinment);
   179 	entry.setSummary("Test case");
   200 	entry.setSummary("Test case");
   180 	entry.setStartAndEndTime(
   201 	entry.setStartAndEndTime(
   181 			QDateTime::currentDateTime(), 
   202 			QDateTime::currentDateTime(),
   182 			QDateTime::currentDateTime());
   203 			QDateTime::currentDateTime());
   183 	AgendaRepeatRule repeatRule;
   204 	AgendaRepeatRule repeatRule;
   184 	repeatRule.setType(AgendaRepeatRule::DailyRule);
   205 	repeatRule.setType(AgendaRepeatRule::DailyRule);
   185 	QDateTime ruleStartDateTime(QDate(2019, 11, 3));
   206 	QDateTime ruleStartDateTime(QDate(2019, 11, 3));
   186 	repeatRule.setRepeatRuleStart(ruleStartDateTime);
   207 	repeatRule.setRepeatRuleStart(ruleStartDateTime);
   187 	QDateTime until(QDate(2019, 12, 3));
   208 	QDateTime until(QDate(2019, 12, 3));
   188 	repeatRule.setUntil(until);
   209 	repeatRule.setUntil(until);
   189 	repeatRule.setInterval(1);
   210 	repeatRule.setInterval(1);
   190 	entry.setRepeatRule(repeatRule);
   211 	entry.setRepeatRule(repeatRule);
   191 	
   212 
   192 	ulong id = mAgendaUtil->addEntry(entry);
   213 	ulong id = mAgendaUtil->addEntry(entry);
   193 	AgendaEntry savedEntry = mAgendaUtil->fetchById(id);
   214 	AgendaEntry savedEntry = mAgendaUtil->fetchById(id);
   194 	QVERIFY(!savedEntry.isNull());
   215 	QVERIFY(!savedEntry.isNull());
   195 	QVERIFY(savedEntry.isRepeating());
   216 	QVERIFY(savedEntry.isRepeating());
   196 	
   217 
   197 	// Run the case.
   218 	// Run the case.
   198 	mAgendaUtil->deleteRepeatedEntry(savedEntry, AgendaUtil::ThisAndAll);
   219 	mAgendaUtil->deleteRepeatedEntry(savedEntry, AgendaUtil::ThisAndAll);
   199 	
   220 
   200 	// Verify.
   221 	// Verify.
   201 	QVERIFY(mAgendaUtil->fetchById(id).isNull());
   222 	QVERIFY(mAgendaUtil->fetchById(id).isNull());
   202 }
   223 }
   203 
   224 
   204 /*!
   225 /*!
   218 	// Run the case.
   239 	// Run the case.
   219 	ulong id = mAgendaUtil->addEntry(entry);
   240 	ulong id = mAgendaUtil->addEntry(entry);
   220 
   241 
   221 	// Verify.
   242 	// Verify.
   222 	AgendaEntry retrievedEntry = mAgendaUtil->fetchById(id);
   243 	AgendaEntry retrievedEntry = mAgendaUtil->fetchById(id);
   223 	
   244 
   224 	// Check if the fetched entry is same st the added entry
   245 	// Check if the fetched entry is same st the added entry
   225 	QDateTime dateTimeRetrieved = retrievedEntry.startTime();
   246 	QDateTime dateTimeRetrieved = retrievedEntry.startTime();
   226 	QDate dateRetrieved = dateTimeRetrieved.date();
   247 	QDate dateRetrieved = dateTimeRetrieved.date();
   227 	QTime timeRetrieved = dateTimeRetrieved.time();
   248 	QTime timeRetrieved = dateTimeRetrieved.time();
   228 	QVERIFY(dateRetrieved == dateSet);
   249 	QVERIFY(dateRetrieved == dateSet);
   229 	QVERIFY(entry.type() == retrievedEntry.type());
   250 	QVERIFY(entry.type() == retrievedEntry.type());
   230 	QVERIFY(entry.summary() == retrievedEntry.summary());
   251 	QVERIFY(entry.summary() == retrievedEntry.summary());
   231 	mAgendaUtil->deleteEntry(id);
   252 	mAgendaUtil->deleteEntry(id);
   232 	
   253 
   233 	// Fetch the same again and check if its null.
   254 	// Fetch the same again and check if its null.
   234 	AgendaEntry checkEntryIsNull = mAgendaUtil->fetchById(id);
   255 	AgendaEntry checkEntryIsNull = mAgendaUtil->fetchById(id);
   235 	QVERIFY(checkEntryIsNull.isNull());
   256 	QVERIFY(checkEntryIsNull.isNull());
   236 }
   257 }
   237 
   258 
   245 	entry.setType(AgendaEntry::TypeAppoinment);
   266 	entry.setType(AgendaEntry::TypeAppoinment);
   246 	entry.setSummary("Test case");
   267 	entry.setSummary("Test case");
   247 	entry.setDescription("Entry to test the updateEntry API");
   268 	entry.setDescription("Entry to test the updateEntry API");
   248 	entry.setLocation("Nokia");
   269 	entry.setLocation("Nokia");
   249 	entry.setStartAndEndTime(
   270 	entry.setStartAndEndTime(
   250 			QDateTime::currentDateTime(), 
   271 			QDateTime::currentDateTime(),
   251 			QDateTime::currentDateTime());
   272 			QDateTime::currentDateTime());
   252 
   273 
   253 	// Save the entry
   274 	// Save the entry
   254 	ulong id = mAgendaUtil->addEntry(entry);
   275 	ulong id = mAgendaUtil->addEntry(entry);
   255 
   276 
   256 	// Fetch the same entry 
   277 	// Fetch the same entry
   257 	AgendaEntry savedEntry = mAgendaUtil->fetchById(id);
   278 	AgendaEntry savedEntry = mAgendaUtil->fetchById(id);
   258 	QVERIFY(!savedEntry.isNull());
   279 	QVERIFY(!savedEntry.isNull());
   259 	savedEntry.setSummary("Fetced Entry");
   280 	savedEntry.setSummary("Fetced Entry");
   260 	savedEntry.setLocation("India");
   281 	savedEntry.setLocation("India");
   261 	savedEntry.setStartAndEndTime(
   282 	savedEntry.setStartAndEndTime(
   262 			QDateTime::currentDateTime().addDays(1), 
   283 			QDateTime::currentDateTime().addDays(1),
   263 			QDateTime::currentDateTime().addDays(1));
   284 			QDateTime::currentDateTime().addDays(1));
   264 
   285 
   265 	// Update the entry
   286 	// Update the entry
   266 	bool success = mAgendaUtil->updateEntry(savedEntry);
   287 	bool success = mAgendaUtil->updateEntry(savedEntry);
   267 	QVERIFY(success);
   288 	QVERIFY(success);
   268 
   289 
   269 	// Fetch the updated entry again
   290 	// Fetch the updated entry again
   270 	AgendaEntry updatedEntry = mAgendaUtil->fetchById(id); 
   291 	AgendaEntry updatedEntry = mAgendaUtil->fetchById(id);
   271 
   292 
   272 	// Verify
   293 	// Verify
   273 	QVERIFY(savedEntry.summary() == updatedEntry.summary());
   294 	QVERIFY(savedEntry.summary() == updatedEntry.summary());
   274 	QVERIFY(savedEntry.type() == updatedEntry.type());
   295 	QVERIFY(savedEntry.type() == updatedEntry.type());
   275 
   296 
   284 {
   305 {
   285 	// Clean up all the entries.
   306 	// Clean up all the entries.
   286 	QDateTime startRange(QDate(1900, 01, 1), QTime(0, 0, 0, 0));
   307 	QDateTime startRange(QDate(1900, 01, 1), QTime(0, 0, 0, 0));
   287 	QDateTime endRange(QDate(2100, 01, 01), QTime(23, 59, 59, 0));
   308 	QDateTime endRange(QDate(2100, 01, 01), QTime(23, 59, 59, 0));
   288 	mAgendaUtil->deleteEntries(startRange, endRange);
   309 	mAgendaUtil->deleteEntries(startRange, endRange);
   289 	// Start the timer as the above operation is asynchronous   
   310 	// Start the timer as the above operation is asynchronous
   290 	if (!mWait) {
   311 	if (!mWait) {
   291 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   312 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   292 		if (!mWait->IsStarted()) {
   313 		if (!mWait->IsStarted()) {
   293 			mWait->Start();
   314 			mWait->Start();
   294 		}
   315 		}
   326 	QDateTime endRange(QDate(2100, 01, 01), QTime(23, 59, 59, 0));
   347 	QDateTime endRange(QDate(2100, 01, 01), QTime(23, 59, 59, 0));
   327 	mAgendaUtil->deleteEntries(startRange, endRange);
   348 	mAgendaUtil->deleteEntries(startRange, endRange);
   328 
   349 
   329 	qDebug("Request for deletion made.");
   350 	qDebug("Request for deletion made.");
   330 
   351 
   331 	// Start the timer as the above operation is asynchronous   
   352 	// Start the timer as the above operation is asynchronous
   332 	if (!mWait) {
   353 	if (!mWait) {
   333 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   354 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   334 		if (!mWait->IsStarted()) {
   355 		if (!mWait->IsStarted()) {
   335 			mWait->Start();
   356 			mWait->Start();
   336 		}
   357 		}
   390 	QDateTime endRange(QDate(2100, 12, 30), QTime(23, 59, 59, 0));
   411 	QDateTime endRange(QDate(2100, 12, 30), QTime(23, 59, 59, 0));
   391 	mAgendaUtil->deleteEntries(startRange, endRange);
   412 	mAgendaUtil->deleteEntries(startRange, endRange);
   392 
   413 
   393 	qDebug("Request for deletion made.");
   414 	qDebug("Request for deletion made.");
   394 
   415 
   395 	// Start the timer as the above operation is asynchronous   
   416 	// Start the timer as the above operation is asynchronous
   396 	if (!mWait) {
   417 	if (!mWait) {
   397 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   418 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   398 		if (!mWait->IsStarted()) {
   419 		if (!mWait->IsStarted()) {
   399 			mWait->Start();
   420 			mWait->Start();
   400 		}
   421 		}
   411 	if (numOfEntriesRetrieved != 0 || checkNum != 0) {
   432 	if (numOfEntriesRetrieved != 0 || checkNum != 0) {
   412 		mAgendaUtil->deleteEntries(startRange, endRange);
   433 		mAgendaUtil->deleteEntries(startRange, endRange);
   413 
   434 
   414 		qDebug("Request for deletion made.");
   435 		qDebug("Request for deletion made.");
   415 
   436 
   416 		// Start the timer as the above operation is asynchronous   
   437 		// Start the timer as the above operation is asynchronous
   417 		if (!mWait) {
   438 		if (!mWait) {
   418 			QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   439 			QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   419 			if (!mWait->IsStarted()) {
   440 			if (!mWait->IsStarted()) {
   420 				mWait->Start();
   441 				mWait->Start();
   421 			}
   442 			}
   451 	entries.clear();
   472 	entries.clear();
   452 	entries = mAgendaUtil->fetchAllEntries();
   473 	entries = mAgendaUtil->fetchAllEntries();
   453 
   474 
   454 	// Verfiy
   475 	// Verfiy
   455 	numOfEntriesRetrieved = entries.count();
   476 	numOfEntriesRetrieved = entries.count();
   456 	QVERIFY(numOfEntries == numOfEntriesRetrieved);
   477 	QCOMPARE(numOfEntries,numOfEntriesRetrieved);
   457 }
   478 }
   458 
   479 
   459 /*!
   480 /*!
   460 	Test the api AgendaUtil::deleteEntries.
   481 	Test the api AgendaUtil::deleteEntries.
   461  */
   482  */
   469 	QList<AgendaEntry> entriesRetrieved =
   490 	QList<AgendaEntry> entriesRetrieved =
   470 	        mAgendaUtil->fetchEntriesInRange(startRange, endRange);
   491 	        mAgendaUtil->fetchEntriesInRange(startRange, endRange);
   471 	int numOfEntriesRetrieved = entriesRetrieved.count();
   492 	int numOfEntriesRetrieved = entriesRetrieved.count();
   472 	QList<ulong> checkList = mAgendaUtil->entryIds();
   493 	QList<ulong> checkList = mAgendaUtil->entryIds();
   473 	int checkNum = checkList.count();
   494 	int checkNum = checkList.count();
   474 		
   495 
   475 	// Create the required entries.
   496 	// Create the required entries.
   476 	int numOfEntries = createMultipleEntries();
   497 	int numOfEntries = createMultipleEntries();
   477 	
   498 
   478 	entriesRetrieved = mAgendaUtil->fetchEntriesInRange(startRange, endRange);
   499 	entriesRetrieved = mAgendaUtil->fetchEntriesInRange(startRange, endRange);
   479 	numOfEntriesRetrieved = entriesRetrieved.count();
   500 	numOfEntriesRetrieved = entriesRetrieved.count();
   480 	checkList = mAgendaUtil->entryIds();
   501 	checkList = mAgendaUtil->entryIds();
   481 	checkNum = checkList.count();
   502 	checkNum = checkList.count();
   482 
   503 
   483 	Q_ASSERT(numOfEntries);
   504 	Q_ASSERT(numOfEntries);
   484 	
   505 
   485 	qDebug("Entries have been created");
   506 	qDebug("Entries have been created");
   486 
   507 
   487 	// Execute the case.
   508 	// Execute the case.
   488 	mAgendaUtil->deleteEntries(startRange, endRange);
   509 	mAgendaUtil->deleteEntries(startRange, endRange);
   489 	
   510 
   490 	qDebug("Request for deletion made.");
   511 	qDebug("Request for deletion made.");
   491 
   512 
   492 	// Start the timer as the above operation is asynchronous   
   513 	// Start the timer as the above operation is asynchronous
   493 	if (!mWait) {
   514 	if (!mWait) {
   494 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   515 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   495 		if (!mWait->IsStarted()) {
   516 		if (!mWait->IsStarted()) {
   496 			mWait->Start();
   517 			mWait->Start();
   497 		}
   518 		}
   498 	}
   519 	}
   499 	
   520 
   500 	qDebug("Waiting for confirmation.");
   521 	qDebug("Waiting for confirmation.");
   501 	entriesRetrieved = mAgendaUtil->fetchEntriesInRange(startRange, endRange);
   522 	entriesRetrieved = mAgendaUtil->fetchEntriesInRange(startRange, endRange);
   502 	numOfEntriesRetrieved = entriesRetrieved.count();
   523 	numOfEntriesRetrieved = entriesRetrieved.count();
   503 	checkList = mAgendaUtil->entryIds();
   524 	checkList = mAgendaUtil->entryIds();
   504 	checkNum = checkList.count();
   525 	checkNum = checkList.count();
   512 {
   533 {
   513 	// Clean up all the entries.
   534 	// Clean up all the entries.
   514 	QDateTime startRange(QDate(1900, 01, 1), QTime(0, 0, 0, 0));
   535 	QDateTime startRange(QDate(1900, 01, 1), QTime(0, 0, 0, 0));
   515 	QDateTime endRange(QDate(2100, 12, 30), QTime(23, 59, 59, 0));
   536 	QDateTime endRange(QDate(2100, 12, 30), QTime(23, 59, 59, 0));
   516 	mAgendaUtil->deleteEntries(startRange,endRange);
   537 	mAgendaUtil->deleteEntries(startRange,endRange);
   517 	
   538 
   518 	//qDebug("Request for deletion made.");
   539 	//qDebug("Request for deletion made.");
   519 
   540 
   520 	// Start the timer as the above operation is asynchronous   
   541 	// Start the timer as the above operation is asynchronous
   521 	if (!mWait) {
   542 	if (!mWait) {
   522 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   543 		QT_TRAP_THROWING(mWait = new (ELeave) CActiveSchedulerWait;);
   523 		if (!mWait->IsStarted()) {
   544 		if (!mWait->IsStarted()) {
   524 			mWait->Start();
   545 			mWait->Start();
   525 		}
   546 		}
   526 	}
   547 	}
   527 
   548 
   528 	//qDebug("Waiting for confirmation.");
   549 	//qDebug("Waiting for confirmation.");
   529 	
   550 
   530 	QList<AgendaEntry> entriesRetrieved =
   551 	QList<AgendaEntry> entriesRetrieved =
   531 			mAgendaUtil->fetchEntriesInRange(startRange, endRange);
   552 			mAgendaUtil->fetchEntriesInRange(startRange, endRange);
   532 	int numOfEntriesRetrieved = entriesRetrieved.count();
   553 	int numOfEntriesRetrieved = entriesRetrieved.count();
   533 	QList<ulong> checkList = mAgendaUtil->entryIds();
   554 	QList<ulong> checkList = mAgendaUtil->entryIds();
   534 	int checkNum = checkList.count();
   555 	int checkNum = checkList.count();
   535 		
   556 
   536 	// Appointment.
   557 	// Appointment.
   537 	AgendaEntry firstEntry;
   558 	AgendaEntry firstEntry;
   538 	firstEntry.setType(AgendaEntry::TypeAppoinment);
   559 	firstEntry.setType(AgendaEntry::TypeAppoinment);
   539 	firstEntry.setSummary("first entry");
   560 	firstEntry.setSummary("first entry");
   540 	QDateTime firstEntryStart(
   561 	QDateTime firstEntryStart(
   541 			QDate(2020, 05, 01), QTime(9, 0, 0, 0));
   562 			QDate(2020, 05, 01), QTime(9, 0, 0, 0));
   542 	QDateTime firstEntryEnd(
   563 	QDateTime firstEntryEnd(
   543 			QDate(2020, 05, 01), QTime(10, 0, 0, 0));
   564 			QDate(2020, 05, 01), QTime(10, 0, 0, 0));
   544 	firstEntry.setStartAndEndTime(firstEntryStart, firstEntryEnd);
   565 	firstEntry.setStartAndEndTime(firstEntryStart, firstEntryEnd);
   545 	ulong id = mAgendaUtil->addEntry(firstEntry);
   566 	ulong id = mAgendaUtil->addEntry(firstEntry);
   546 	
   567 
   547 	// Create the range for which entries are needed
   568 	// Create the range for which entries are needed
   548 	QDateTime fromRange(
   569 	QDateTime fromRange(
   549 			QDate(2020, 01, 01), QTime(0, 0, 0, 0));
   570 			QDate(2020, 01, 01), QTime(0, 0, 0, 0));
   550 	QDateTime toRange(
   571 	QDateTime toRange(
   551 			QDate(2023, 12, 31), QTime(23, 59, 0, 0));
   572 			QDate(2023, 12, 31), QTime(23, 59, 0, 0));
   552 	// Run the test case
   573 	// Run the test case
   553 	QList<AgendaEntry> entries = mAgendaUtil->fetchEntriesInRange(
   574 	QList<AgendaEntry> entries = mAgendaUtil->fetchEntriesInRange(
   554 			fromRange, toRange);
   575 			fromRange, toRange);
   555 
   576 
   556 	// Verify
   577 	// Verify
   557 	int num = entries.count();                             
   578 	int num = entries.count();
   558 	QVERIFY( 1 == entries.count());
   579 	QVERIFY( 1 == entries.count());
   559 	
   580 
   560 	//cleanup();
   581 	//cleanup();
   561 	
   582 
   562 	//User::Exit(0);
   583 	//User::Exit(0);
       
   584 }
       
   585 
       
   586 /*!
       
   587 	Test the api AgendaUtil::cloneEntry
       
   588  */
       
   589 void TestAgendaUtil::test_cloneEntry()
       
   590 {
       
   591 	cloneNoteToTodo();
       
   592 	cloneNoteToMeeting();
       
   593 	cloneTodoToNote();
       
   594 	cloneTodoToMeeting();
       
   595 	cloneMeetingToNote();
       
   596 	cloneMeetingToTodo();
       
   597 }
       
   598 
       
   599 /*
       
   600 	Test the api AgendaUtil::setCompleted
       
   601  */
       
   602 void TestAgendaUtil::test_todoCompleted()
       
   603 {
       
   604 	completeTodo();
       
   605 	unCompletedTodo();
   563 }
   606 }
   564 
   607 
   565 /*!
   608 /*!
   566 	Slot to listen for the completion of deleting the entries asynchronously.
   609 	Slot to listen for the completion of deleting the entries asynchronously.
   567  */
   610  */
   570 	// Stop the wait timer.
   613 	// Stop the wait timer.
   571 	if (mWait && mWait->IsStarted()) {
   614 	if (mWait && mWait->IsStarted()) {
   572 		mWait->AsyncStop();
   615 		mWait->AsyncStop();
   573 	}
   616 	}
   574 	QVERIFY(!error);
   617 	QVERIFY(!error);
       
   618 }
       
   619 
       
   620 /*!
       
   621 	Slot to handle the entry view creation.
       
   622  */
       
   623 void TestAgendaUtil::handleEntryViewCreationCompleted(int status)
       
   624 {
       
   625 	// Stop the wait timer.
       
   626 	if (mWait && mWait->IsStarted()) {
       
   627 		mWait->AsyncStop();
       
   628 	}
       
   629 	QVERIFY(!status);
   575 }
   630 }
   576 
   631 
   577 /*!
   632 /*!
   578 	Private function to create entries needed for some of the test cases.
   633 	Private function to create entries needed for some of the test cases.
   579  */
   634  */
   619 	numOfEntries++;
   674 	numOfEntries++;
   620 
   675 
   621 	return numOfEntries;
   676 	return numOfEntries;
   622 }
   677 }
   623 
   678 
   624 QTEST_MAIN(TestAgendaUtil)
   679 /*!
       
   680 	Test Cloning of Note to To-do
       
   681  */
       
   682 void TestAgendaUtil::cloneNoteToTodo()
       
   683 {
       
   684 	// Create an agenda entry(TypeNote) and save it.
       
   685 	AgendaEntry noteEntry(AgendaEntry::TypeNote);
       
   686 	noteEntry.setDescription(QString("test cloning of note to todo"));
       
   687 
       
   688 	// Clone the entry type TypeNote to TypeTodo
       
   689 	long notSavedEntryId = mAgendaUtil->cloneEntry(
       
   690 			noteEntry, AgendaEntry::TypeTodo);
       
   691 	// Shouldn't clone the entry as AgendaEntry is not yet saved.
       
   692 	QVERIFY(!notSavedEntryId);
       
   693 
       
   694 	long noteId = mAgendaUtil->addEntry(noteEntry);
       
   695 	QVERIFY(noteId);
       
   696 
       
   697 	// Fetch the saved note entry for cloning
       
   698 	AgendaEntry fetchedNoteEntry = mAgendaUtil->fetchById(noteId);
       
   699 
       
   700 	// Clone the entry type ENote to ETodo
       
   701 	long clonedTodoEntryId = mAgendaUtil->cloneEntry(
       
   702 			fetchedNoteEntry, AgendaEntry::TypeTodo);
       
   703 	QVERIFY(clonedTodoEntryId);
       
   704 
       
   705 	AgendaEntry clonedTodoEntry = mAgendaUtil->fetchById(clonedTodoEntryId);
       
   706 	// Compare the attributes.
       
   707 	QCOMPARE(AgendaEntry::TypeTodo,clonedTodoEntry.type());
       
   708 	QCOMPARE(fetchedNoteEntry.description(),clonedTodoEntry.description());
       
   709 }
       
   710 
       
   711 /*!
       
   712 	Test Cloning of Note to Meeting
       
   713  */
       
   714 
       
   715 void TestAgendaUtil::cloneNoteToMeeting()
       
   716 {
       
   717 	// Create an agenda entry(TypeNote) and save it.
       
   718 	AgendaEntry noteEntry(AgendaEntry::TypeNote);
       
   719 	noteEntry.setDescription(QString("test cloning of note to meeting"));
       
   720 
       
   721 	long noteId = mAgendaUtil->addEntry(noteEntry);
       
   722 	QVERIFY(noteId);
       
   723 
       
   724 	// Fetch the saved note entry for cloning
       
   725 	AgendaEntry fetchedNoteEntry = mAgendaUtil->fetchById(noteId);
       
   726 
       
   727 	// Clone the entry type TypeNote to TypeTodo
       
   728 	long clonedMeetingEntryId = mAgendaUtil->cloneEntry(
       
   729 			fetchedNoteEntry, AgendaEntry::TypeAppoinment);
       
   730 	QVERIFY(clonedMeetingEntryId);
       
   731 
       
   732 	AgendaEntry clonedMeetingEntry = mAgendaUtil->fetchById(clonedMeetingEntryId);
       
   733 	// Compare the attributes.
       
   734 	QCOMPARE(AgendaEntry::TypeAppoinment,clonedMeetingEntry.type());
       
   735 	QCOMPARE(fetchedNoteEntry.description(),clonedMeetingEntry.description());
       
   736 }
       
   737 
       
   738 /*!
       
   739 	Test Cloning of To-do to Note
       
   740  */
       
   741 void TestAgendaUtil::cloneTodoToNote()
       
   742 {
       
   743 	// Create an agenda entry(TypeTodo) and save it.
       
   744 	AgendaEntry todoEntry(AgendaEntry::TypeTodo);
       
   745 	todoEntry.setDescription(QString("test cloning of todo to note"));
       
   746 	QDateTime dueDate(QDate(2011, 06, 01), QTime(10, 0, 0, 0));
       
   747 	todoEntry.setStartAndEndTime(dueDate, dueDate);
       
   748 	long todoId = mAgendaUtil->addEntry(todoEntry);
       
   749 	QVERIFY(todoId);
       
   750 
       
   751 	// Fetch the saved note entry for cloning
       
   752 	AgendaEntry fetchedTodoEntry = mAgendaUtil->fetchById(todoId);
       
   753 
       
   754 	// Clone the entry type ETodo to EANote
       
   755 	ulong clonedNoteId = mAgendaUtil->cloneEntry(
       
   756 			fetchedTodoEntry, AgendaEntry::TypeNote);
       
   757 	QVERIFY(clonedNoteId);
       
   758 	AgendaEntry clonedNoteEntry =
       
   759 			mAgendaUtil->fetchById(clonedNoteId);
       
   760 
       
   761 	// Compare the attributes.
       
   762 	QCOMPARE(AgendaEntry::TypeNote,clonedNoteEntry.type());
       
   763 	QCOMPARE(fetchedTodoEntry.description(),clonedNoteEntry.description());
       
   764 	QCOMPARE(fetchedTodoEntry.favourite(),clonedNoteEntry.favourite());
       
   765 }
       
   766 
       
   767 /*!
       
   768 	Test Cloning of To-do to Meeting
       
   769  */
       
   770 void TestAgendaUtil::cloneTodoToMeeting()
       
   771 {
       
   772 	// Create an agenda entry(TypeTodo) and save it.
       
   773 	AgendaEntry todoEntry(AgendaEntry::TypeTodo);
       
   774 	todoEntry.setSummary(QString("test cloning of todo to meeting"));
       
   775 	QDateTime dueDate(QDate(2011, 06, 01), QTime(10, 0, 0, 0));
       
   776 	todoEntry.setStartAndEndTime(dueDate, dueDate);
       
   777 	long todoId = mAgendaUtil->addEntry(todoEntry);
       
   778 	QVERIFY(todoId);
       
   779 
       
   780 	// Fetch the saved note entry for cloning
       
   781 	AgendaEntry fetchedTodoEntry = mAgendaUtil->fetchById(todoId);
       
   782 
       
   783 	// Clone the entry type TypeTodo to TypeAppointment
       
   784 	ulong clonedAppointmentId = mAgendaUtil->cloneEntry(
       
   785 			fetchedTodoEntry, AgendaEntry::TypeAppoinment);
       
   786 	QVERIFY(clonedAppointmentId);
       
   787 	AgendaEntry clonedAppointmentEntry =
       
   788 			mAgendaUtil->fetchById(clonedAppointmentId);
       
   789 
       
   790 	// Compare the attributes.
       
   791 	QCOMPARE(AgendaEntry::TypeAppoinment,clonedAppointmentEntry.type());
       
   792 	QCOMPARE(fetchedTodoEntry.summary(),clonedAppointmentEntry.summary());
       
   793 	QCOMPARE(fetchedTodoEntry.startTime(),clonedAppointmentEntry.startTime());
       
   794 	QCOMPARE(fetchedTodoEntry.endTime(),clonedAppointmentEntry.endTime());
       
   795 }
       
   796 
       
   797 /*!
       
   798 	Test Cloning of Meeting to Note
       
   799  */
       
   800 void TestAgendaUtil::cloneMeetingToNote()
       
   801 {
       
   802 	// Create an agenda entry(TypeAppointment) and save it.
       
   803 	AgendaEntry appointment(AgendaEntry::TypeAppoinment);
       
   804 	appointment.setSummary(QString("test cloning of meeting to note"));
       
   805 	QDateTime startDate(QDate(2011, 06, 01), QTime(10, 0, 0, 0));
       
   806 	QDateTime endDate(QDate(2011, 06, 01), QTime(12, 0, 0, 0));
       
   807 	appointment.setStartAndEndTime(startDate, endDate);
       
   808 	long appointmentId = mAgendaUtil->addEntry(appointment);
       
   809 	QVERIFY(appointmentId);
       
   810 
       
   811 	// Fetch the saved note entry for cloning
       
   812 	AgendaEntry fetchedAppointment = mAgendaUtil->fetchById(appointmentId);
       
   813 
       
   814 	// Clone the entry type TypeAppointment to TypeNote
       
   815 	ulong clonedNoteId = mAgendaUtil->cloneEntry(
       
   816 			fetchedAppointment, AgendaEntry::TypeNote);
       
   817 	QVERIFY(clonedNoteId);
       
   818 
       
   819 	AgendaEntry clonedNote = mAgendaUtil->fetchById(clonedNoteId);
       
   820 	// Compare the attributes.
       
   821 	QCOMPARE(AgendaEntry::TypeNote,clonedNote.type());
       
   822 	QCOMPARE(fetchedAppointment.description(),clonedNote.description());
       
   823 	QCOMPARE(fetchedAppointment.favourite(),clonedNote.favourite());
       
   824 }
       
   825 
       
   826 /*!
       
   827 	Test Cloning of Meeting to To-do
       
   828  */
       
   829 void TestAgendaUtil::cloneMeetingToTodo()
       
   830 {
       
   831 	// Create an agenda entry(TypeAppointment) and save it.
       
   832 	AgendaEntry appointment(AgendaEntry::TypeAppoinment);
       
   833 	appointment.setSummary(QString("test cloning of meeting to todo"));
       
   834 	QDateTime startDate(QDate(2011, 06, 01), QTime(10, 0, 0, 0));
       
   835 	QDateTime endDate(QDate(2011, 06, 01), QTime(12, 0, 0, 0));
       
   836 	appointment.setStartAndEndTime(startDate, endDate);
       
   837 	long appointmentId = mAgendaUtil->addEntry(appointment);
       
   838 	QVERIFY(appointmentId);
       
   839 
       
   840 	// Fetch the saved note entry for cloning
       
   841 	AgendaEntry fetchedAppointment = mAgendaUtil->fetchById(appointmentId);
       
   842 
       
   843 	// Clone the entry type EAppointment to TypeNote
       
   844 	ulong clonedTodoId = mAgendaUtil->cloneEntry(
       
   845 			fetchedAppointment, AgendaEntry::TypeTodo);
       
   846 	QVERIFY(clonedTodoId);
       
   847 
       
   848 	AgendaEntry clonedTodo = mAgendaUtil->fetchById(clonedTodoId);
       
   849 	// Compare the attributes.
       
   850 	QCOMPARE(AgendaEntry::TypeTodo,clonedTodo.type());
       
   851 	QCOMPARE(fetchedAppointment.summary(),clonedTodo.summary());
       
   852 	QCOMPARE(fetchedAppointment.startTime(),clonedTodo.startTime());
       
   853 	QCOMPARE(fetchedAppointment.endTime(),clonedTodo.endTime());
       
   854 }
       
   855 
       
   856 /*!
       
   857 	test making To-do as completed
       
   858  */
       
   859 void TestAgendaUtil::completeTodo()
       
   860 {
       
   861 	// Create and Save a To-do event.
       
   862 	AgendaEntry todoEntry(AgendaEntry::TypeTodo);
       
   863 	todoEntry.setSummary(QString("Test making To-do event as Completed"));
       
   864 	QDateTime dueDate(QDate(2011, 06, 01), QTime(0, 0, 0, 0));
       
   865 	todoEntry.setStartAndEndTime(dueDate, dueDate);
       
   866 
       
   867 	ulong todoId = mAgendaUtil->addEntry(todoEntry);
       
   868 	QVERIFY(todoId);
       
   869 
       
   870 	// Complete the to-do.
       
   871 	AgendaEntry fetchedTodoEntry = mAgendaUtil->fetchById(todoId);
       
   872 	QDateTime completedTime(QDate(2011, 07, 01),QTime(0, 0, 0, 0));
       
   873 	mAgendaUtil->setCompleted(fetchedTodoEntry, true, completedTime);
       
   874 
       
   875 	// Compare the completed time.
       
   876 	AgendaEntry completedTodo = mAgendaUtil->fetchById(todoId);
       
   877 	QCOMPARE(completedTime,completedTodo.completedDateTime());
       
   878 }
       
   879 
       
   880 /*!
       
   881 	test making To-do as uncompleted
       
   882  */
       
   883 void TestAgendaUtil::unCompletedTodo()
       
   884 {
       
   885 	// Create and Save a To-do event.
       
   886 	AgendaEntry todoEntry(AgendaEntry::TypeTodo);
       
   887 	todoEntry.setSummary(QString("Test making To-do event as Completed"));
       
   888 	QDateTime dueDate(QDate(2011, 06, 01), QTime(0, 0, 0, 0));
       
   889 	todoEntry.setStartAndEndTime(dueDate, dueDate);
       
   890 
       
   891 	ulong todoId = mAgendaUtil->addEntry(todoEntry);
       
   892 	QVERIFY(todoId);
       
   893 
       
   894 	// Complete the to-do.
       
   895 	AgendaEntry fetchedTodoEntry = mAgendaUtil->fetchById(todoId);
       
   896 	QDateTime completedTime(QDate(2011, 07, 01),QTime(0, 0, 0, 0));
       
   897 	mAgendaUtil->setCompleted(fetchedTodoEntry, true, completedTime);
       
   898 
       
   899 	// Compare the completed time.
       
   900 	AgendaEntry unCompletedTodo = mAgendaUtil->fetchById(todoId);
       
   901 	// make to-do as uncompleted.
       
   902 	mAgendaUtil->setCompleted(fetchedTodoEntry, false, completedTime);
       
   903 
       
   904 	QCOMPARE(completedTime, unCompletedTodo.completedDateTime());
       
   905 }
       
   906 
       
   907 int main(int argc, char *argv[])
       
   908 {
       
   909 	QApplication app(argc, argv);
       
   910 	TestAgendaUtil tc;
       
   911 
       
   912 	char *pass[3];
       
   913 	pass[0] = argv[0];
       
   914 	pass[1] = "-o";
       
   915 	pass[2] = "c:\\data\\TestAgendaUtil.txt";
       
   916 
       
   917 	int res = QTest::qExec(&tc, 3, pass);
       
   918 	return res;
       
   919 }
       
   920 
   625 #include "unittest_agendautil.moc"
   921 #include "unittest_agendautil.moc"
   626 
   922 
   627 // End of file	--Don't remove this.
   923 // End of file	--Don't remove this.