LOCAL_C void CheckBasicPopulatedGroup() { test.Next(_L("Populate Basic Group")); CntTest->CloseDatabase(); CntTest->DeleteDatabaseL(); CntTest->CreateDatabaseL(); TRAP_IGNORE(PopulateDatabaseL(KFamilySizeRecords,ETrue)); CContactItem* newGroup = CntTest->Db()->CreateContactGroupLC(_L("Family Group")); TContactItemId groupId = newGroup->Id(); for(TInt ii=2;ii<12;ii++) { CntTest->Db()->AddContactToGroupL(ii,groupId); } CntTest->CloseDatabase(); CntTest->OpenDatabaseL(); // CContactItem* familyGroup = CntTest->Db()->ReadContactLC(groupId); CContactIdArray* memberArray = STATIC_CAST(CContactGroup*,familyGroup)->ItemsContainedLC(); test(memberArray->Count()==10); // CContactItem* familyMember = CntTest->Db()->ReadContactLC(2); CContactIdArray* groups = STATIC_CAST(CContactCard*, familyMember)->GroupsJoinedLC(); test(groups->Count()==1); TContactItemId memberShip = (*groups)[0]; test(memberShip==groupId); CleanupStack::PopAndDestroy(5); // newGroup familyGroup memberArray familyMember groups }
CContactDatabase* DbCreator::CreateDbL(const TDesC &aFileName, TInt aNumContacts) { CContactDatabase* db = CContactDatabase::ReplaceL(aFileName); CleanupStack::PushL(db); PopulateDatabaseL(*db, aNumContacts); CleanupStack::Pop(); return db; }
LOCAL_D void TestFirstL(RTest& aTest) { aTest.Next(_L("@SYMTestCaseID:PIM-T-OWNCARDDELETE-0001 -- First Owncard Test --")); aTest.Printf(_L("Replacing database \n")); CContactDatabase* db = CContactDatabase::ReplaceL(KDatabaseFileName); CleanupStack::PushL(db); CContactDatabase* dbAnother = CContactDatabase::OpenL(KDatabaseFileName); CleanupStack::PushL(dbAnother); PopulateDatabaseL(db, KTotalContacts); WaitForNotificationsL(db); TestSetOwnCardL(db); WaitForNotificationsL(db); aTest.Printf(_L("Checking the count value \n")); TInt count = dbAnother->CountL(); aTest.Printf(_L("Count: %d \n"), count); aTest(count == KTotalContacts, __LINE__); aTest.Printf(_L("Checking the id \n")); TContactItemId id = dbAnother->OwnCardId(); aTest.Printf(_L("id: %d \n"), id); aTest(id != KNullContactId, __LINE__); TContactIter iter(*db); //Test that the iterator is updated TContactItemId firstContactId; firstContactId = iter.FirstL(); //should be own contactId DeleteOwnContactL(dbAnother); WaitForNotificationsL(dbAnother); TContactItemId secondContactId; TRAPD (err, secondContactId = iter.FirstL()); aTest(err == KErrNone && firstContactId != secondContactId, __LINE__); DeleteMultipleContactsL(db); WaitForNotificationsL(db); aTest.Printf(_L("Checking the deleted count value \n")); count = dbAnother->CountL(); aTest.Printf(_L("Count: %d \n"), count); aTest(count == 0, __LINE__); aTest.Printf(_L("Checking the deleted id \n")); id = dbAnother->OwnCardId(); aTest.Printf(_L("id: %d \n"), id); aTest(id == KNullContactId, __LINE__); aTest(gEventCounter == KMaxNumOfEvents, __LINE__); aTest(gUnknownEventCounter == KMaxUnknownEvents, __LINE__); CleanupStack::PopAndDestroy(2,db); }
LOCAL_C void CheckLargePopulatedGroup() { test.Next(_L("Create MANY Contacts")); CntTest->CloseDatabase(); CntTest->DeleteDatabaseL(); CntTest->CreateDatabaseL(); TRAP_IGNORE(PopulateDatabaseL(KLargeSizeRecords,ETrue)); CContactItem* newGroup = CntTest->Db()->CreateContactGroupL(_L("Large Group")); CleanupStack::PushL(newGroup); TContactItemId groupId = newGroup->Id(); test.Next(_L("Add MANY Contacts to a Group")); TTime before; before.UniversalTime(); for(TInt ii=1;ii<KLargeSizeRecords+1;ii++) { CntTest->Db()->AddContactToGroupL(ii, groupId); //*tempContact,*newGroup); if (ii%100==0) test.Printf(_L(".")); // Just to show some life } test(TestGroupStateL(CntTest->Db(),1,KLargeSizeRecords)); TTime after; after.UniversalTime(); TTimeIntervalSeconds secondsTaken; after.SecondsFrom(before,secondsTaken); test.Printf(_L(" TIME: %d Secs"),secondsTaken.Int()); test.Printf(_L("\n")); //test.Getch(); CntTest->CloseDatabase(); CntTest->OpenDatabaseL(); // CContactItem* familyGroup = CntTest->Db()->ReadContactL(groupId); CContactIdArray* memberArray = STATIC_CAST(CContactGroup*,familyGroup)->ItemsContainedLC(); test(memberArray->Count()==KLargeSizeRecords); delete familyGroup; // CContactItem* familyMember = CntTest->Db()->ReadContactL(2); CContactIdArray* groups = STATIC_CAST(CContactCard*, familyMember)->GroupsJoinedLC(); test(groups->Count()==1); TContactItemId memberShip = (*groups)[0]; test(memberShip==groupId); delete familyMember; CleanupStack::PopAndDestroy(3); // newGroup groups memberArray }
LOCAL_C void DoTestsL() { test.Start(_L("@SYMTESTCaseID:PIM-T-CONNEC-0001 Connectivity functionality tests")); OriginalLocale.Refresh(); CleanupStack::PushL(TCleanupItem(RetrieveLocale, 0)); CntTest->CreateDatabaseL(); CntTest->OpenDatabaseL(); PopulateDatabaseL(KTotalNumRecords); TestFilterL(); TestFilterLocalesL(); TRAPD(err,TestSyncUid()); test(err==KErrNone); CntTest->CloseDatabase(); CntTest->DeleteDatabaseL(); CleanupStack::PopAndDestroy(); // locale }
/** *Add five contacts. * Set two speed dials - remove one & check the other is still there. */ LOCAL_C void TestRemovingSpeedDialsL() { ResetDatabaseL(); PopulateDatabaseL(KTestContactsNum); const CContactIdArray* sortedItems = CntTest->Db()->SortedItemsL(); //doesn't take ownership const TInt speedDialPositionOne=1; const TInt speedDialPositionNine=9; const TContactItemId firstId = (*sortedItems)[3]; const TContactItemId secondId = (*sortedItems)[5]; CContactItem* first = CntTest->Db()->OpenContactL(firstId); CleanupStack::PushL(first); CContactItemFieldSet& aFieldSet = first->CardFields(); for(TInt fieldLoop=0; fieldLoop<aFieldSet.Count(); fieldLoop++) { CContactItemField& field = aFieldSet[fieldLoop]; if (field.ContentType().ContainsFieldType(KUidContactFieldPhoneNumber)) { // change it... field.TextStorage()->SetTextL(_L("956431458")); } } CntTest->Db()->CommitContactL(*first); CleanupStack::PopAndDestroy(); //first first = CntTest->Db()->OpenContactL(firstId); CleanupStack::PushL(first); TInt fieldId=first->CardFields().Find(KUidContactFieldPhoneNumber); CntTest->Db()->SetFieldAsSpeedDialL(*first, fieldId, speedDialPositionOne); CContactItem* second = CntTest->Db()->OpenContactL(secondId); CleanupStack::PushL(second); TInt fieldId2=first->CardFields().Find(KUidContactFieldPhoneNumber); CntTest->Db()->SetFieldAsSpeedDialL(*second, fieldId2, speedDialPositionNine); // check they are all established ok HBufC* buf=HBufC::NewLC(100); TPtr fieldContents=buf->Des(); TContactItemId id = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionOne, fieldContents); test(id==firstId); id = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionNine, fieldContents); test(id==secondId); CleanupStack::PopAndDestroy(); //buf CntTest->Db()->RemoveSpeedDialFieldL(firstId, speedDialPositionOne); HBufC* buf2=HBufC::NewLC(100); TPtr phoneNum=buf2->Des(); TContactItemId idOne = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionOne, phoneNum); test(idOne==KNullContactId); test(phoneNum==KNullDesC); CleanupStack::PopAndDestroy(); //buf2 HBufC* buf3=HBufC::NewLC(100); TPtr phoneNo2=buf3->Des(); TContactItemId id2 = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionNine, phoneNo2); test(id2==secondId); CleanupStack::PopAndDestroy(); //buf CntTest->Db()->RemoveSpeedDialFieldL(secondId, speedDialPositionNine); HBufC* buf4=HBufC::NewLC(100); TPtr phoneNo3=buf4->Des(); id = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionNine, phoneNo3); test(id==KNullContactId); test(phoneNum==KNullDesC); CleanupStack::PopAndDestroy(); //buf4 CleanupStack::PopAndDestroy(2); //first, second }
/** * Check that speed dials are working correctly; * Add first contact to speed dial 1, add second contact to speed dial 9. * Check speed dial 1 still matches contact 1 after adding speed dial * Check persistance of speed dial list * Check overwriting old speed dial with new contact id * Check deletion of contact removes all existing speed dials */ LOCAL_C void SpeedDialSimpleTest() { ResetDatabaseL(); TRAP_IGNORE(PopulateDatabaseL(KTestContactsNum)); const CContactIdArray* sortedItems = CntTest->Db()->SortedItemsL(); // first item in position 1 CContactItem* firstItem = CntTest->Db()->OpenContactL((*sortedItems)[0]); CleanupStack::PushL(firstItem); TInt fieldId=5; const TInt speedDialPositionOne=1; CntTest->Db()->SetFieldAsSpeedDialL(*firstItem, fieldId, speedDialPositionOne); CheckSpeedDialL(speedDialPositionOne,*firstItem,fieldId); // second item in position 2 CContactItem* secondItem = CntTest->Db()->OpenContactL((*sortedItems)[1]); CleanupStack::PushL(secondItem); fieldId=5; const TInt speedDialPositionNine=9; CntTest->Db()->SetFieldAsSpeedDialL(*secondItem, fieldId, speedDialPositionNine); CheckSpeedDialL(speedDialPositionNine,*secondItem,fieldId); // wrong answers..... CheckSpeedDialL(speedDialPositionOne,*firstItem,5); // check persistance CntTest->CloseDatabase(); CntTest->OpenDatabaseL(); CheckSpeedDialL(speedDialPositionOne,*firstItem,5); CheckSpeedDialL(speedDialPositionNine,*secondItem,5); // check overwriting old speed dial (third contact, speed dial 1) const CContactIdArray* newSortedItems = CntTest->Db()->SortedItemsL(); CContactItem* thirdItem = CntTest->Db()->OpenContactL((*newSortedItems)[2]); CleanupStack::PushL(thirdItem); fieldId=5; CntTest->Db()->SetFieldAsSpeedDialL(*thirdItem, fieldId, speedDialPositionOne); CheckSpeedDialL(speedDialPositionOne,*thirdItem,5); // delete contact and check that speed dials have been removed CntTest->Db()->DeleteContactL((*newSortedItems)[2]); HBufC* temp8=HBufC::NewLC(100); TPtr testText8=temp8->Des(); TContactItemId eightId = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionOne, testText8); test(eightId==KNullContactId); test(testText8==KNullDesC); // modify a contact with a speed dial - but do not change the relavent field. CContactItem* fourthItem = CntTest->Db()->OpenContactL((*newSortedItems)[2]); CleanupStack::PushL(fourthItem); fieldId=5; CntTest->Db()->SetFieldAsSpeedDialL(*fourthItem, fieldId, speedDialPositionOne); TInt fieldPosOfSpeedDial = fourthItem->CardFields().Find(KUidSpeedDialOne); test(fieldPosOfSpeedDial != KErrNotFound); CContactItem* fifthItem = CntTest->Db()->OpenContactL(fourthItem->Id()); CleanupStack::PushL(fifthItem); // remove the first field in the list. fieldPosOfSpeedDial = fifthItem->CardFields().Find(KUidSpeedDialOne); fifthItem->CardFields().Remove(1); CntTest->Db()->CommitContactL(*fifthItem); CleanupStack::PopAndDestroy(6); // firstItem, secondItem, thirdItem, fourthItem, fifthItem, temp8 }
LOCAL_C void CreateManyGroups() { test.Next(_L("Populate Database")); CntTest->CloseDatabase(); CntTest->DeleteDatabaseL(); CntTest->CreateDatabaseL(); // add 5 new contacts TRAP_IGNORE(PopulateDatabaseL(5,ETrue)); // test.Next(_L("Create MANY Groups")); TTime before; before.UniversalTime(); for(TInt ii=0;ii<KLargeSizeRecords;ii++) { TBuf<32> label; label.Format(KGroupLabel,ii); CContactItem* newGroup = CntTest->Db()->CreateContactGroupL(label); if (ii%100==0) test.Printf(_L(".")); // Just to show some life delete newGroup; } TTime after; after.UniversalTime(); TTimeIntervalSeconds secondsTaken; after.SecondsFrom(before,secondsTaken); test.Printf(_L(" TIME: %d Secs"),secondsTaken.Int()); test.Printf(_L("\n")); //test.Getch(); test(CntTest->Db()->GroupCount()==KLargeSizeRecords); // test.Next(_L("Add 5 Contacts to MANY Groups")); before.UniversalTime(); for(TInt jj=1;jj<6;jj++) // add cards to all groups { CContactItem* contact = CntTest->Db()->ReadContactL(jj); CleanupStack::PushL(contact); for(TInt gg=6;gg<KLargeSizeRecords+6;gg++) // assume knowledge of group ids.. { CntTest->Db()->AddContactToGroupL(jj,gg); //*contact,*group); if (gg%100==0) test.Printf(_L(".")); // Just to show some life } CleanupStack::PopAndDestroy(); // contact } after.UniversalTime(); after.SecondsFrom(before,secondsTaken); test.Printf(_L(" TIME: %d Secs"),secondsTaken.Int()); test.Printf(_L("\n")); test(TestGroupStateL(CntTest->Db(),KLargeSizeRecords,5*KLargeSizeRecords)); //test.Getch(); // test.Next(_L("Check Contacts Group membership")); before.UniversalTime(); for(TInt gg=1;gg<6;gg++) // check cards membership { CContactItem* contact = CntTest->Db()->ReadContactLC(gg); CContactIdArray* groups = STATIC_CAST(CContactCard*, contact)->GroupsJoinedLC(); test(groups->Count()==KLargeSizeRecords); CleanupStack::PopAndDestroy(2); // contact groups } after.UniversalTime(); after.SecondsFrom(before,secondsTaken); test.Printf(_L(" TIME: %d Secs"),secondsTaken.Int()); test.Printf(_L("\n")); //test.Getch(); }
LOCAL_D void ThreadFirstTestL(RTest& aTest) { aTest.Next(_L("-- Running worker thread --")); RMutex mutex; TInt errMutex = mutex.OpenGlobal(KOwnCardMutex); User::LeaveIfError(errMutex); CleanupClosePushL(mutex); aTest.Printf(_L("Replacing the database \n")); CContactDatabase* db = CContactDatabase::ReplaceL(KDatabaseFileName); CleanupStack::PushL(db); // get a second database object CContactDatabase* dbAnother = CContactDatabase::OpenL(KDatabaseFileName); CleanupStack::PushL(dbAnother); SwitchToMainThread(mutex); // 1) Back to MT-a /////////////////////////////////////////////// // Main thread has now opened the database /////////////////////////////////////////////// aTest.Printf(_L("Populating the database \n")); PopulateDatabaseL(db, KTotalContacts); WaitForNotificationsL(db); aTest.Printf(_L("Set the Own card id \n")); TestSetOwnCardL(db); WaitForNotificationsL(db); aTest.Printf(_L("Checking count value \n")); TInt count = db->CountL(); TInt countAnother = dbAnother->CountL(); aTest.Printf(_L("Count: %d \n"), count ); aTest(count == KTotalContacts && countAnother == KTotalContacts, __LINE__); aTest.Printf(_L("Checking the id \n")); TContactItemId id = db->OwnCardId(); TContactItemId idCopy = dbAnother->OwnCardId(); aTest.Printf(_L("Id: %d \n"), id); aTest(id != KNullContactId && idCopy != KNullContactId, __LINE__); SwitchToMainThread(mutex); // 2) Back to MT-b /////////////////////////////////////////////// // Main thread has now checked the added values /////////////////////////////////////////////// DeleteMultipleContactsL(db); WaitForNotificationsL(db); aTest.Printf(_L("Checking deleted count value \n")); count = db->CountL(); countAnother = dbAnother->CountL(); aTest.Printf(_L("Count: %d \n"), count ); aTest(count == 0 && countAnother == 0, __LINE__); aTest.Printf(_L("Checking the deleted id \n")); id = db->OwnCardId(); idCopy = dbAnother->OwnCardId(); aTest.Printf(_L("Id: %d \n"), id); aTest(id == KNullContactId && idCopy == KNullContactId, __LINE__); SwitchToMainThread(mutex); // 3) Back to MT-c /////////////////////////////////////////////// // Main thread has now checked the deleted values /////////////////////////////////////////////// CleanupStack::PopAndDestroy(dbAnother); CleanupStack::PopAndDestroy(db); CleanupStack::PopAndDestroy(); // close mutex handle RThread::Rendezvous(KErrNone); // Finish) back to MT-d }