void TestOneL() { g_test.Start(_L("@SYMTestCaseID:PIM-T-SPEEDDIALTEST-0001 Create Database with Speed Dials then Delete and Create database")); TestDatabaseWithSpeedDialsL(); g_test.Next(_L("Delete database")); CContactDatabase::DeleteDatabaseL(KDbFileName); g_test.Next( _L("open database should fail")); CContactDatabase* database = NULL; TRAPD(openError, database = CContactDatabase::OpenL(KDbFileName)); g_test(openError == KErrNotFound && database == NULL); g_test.Next( _L("create replacement database")); database = CContactDatabase::CreateL(KDbFileName); CleanupStack::PushL(database); CreateContactsL(*database); CContactItem* item = database->ReadContactL(KSpeedDialContact); CleanupStack::PushL(item); g_test.Next( _L("Check that Speed dial is forgotten")); g_test(item->Id() == KSpeedDialContact); // retored item should not be a SpeedDial g_test(!ContactIsASpeedDial( *item )); CleanupStack::PopAndDestroy(item); CleanupStack::PopAndDestroy(database); g_test.End(); }
void RemoveSpeedDialWhenOpenL(TInt aContact, TInt aSpeedDialID, CContactDatabase& aDatabase) { CContactItem* card1 = 0; TInt error = KErrNone; // First open the contact, which locks it: card1 = aDatabase.OpenContactL(aContact); CleanupStack::PushL(card1); // Now attempt to open the contact (must fail with in use): error = KErrNone; TRAP(error, aDatabase.OpenContactL(aContact)); g_test(error == KErrInUse); // Now remove the speed dial on that contact (must fail with in use): error = KErrNone; TRAP(error, aDatabase.RemoveSpeedDialFieldL(aContact, aSpeedDialID)); g_test(error == KErrInUse); // Now remove the speed dial on that contact again (must fail with in use): // Defect was application crash. error = KErrNone; TRAP(error, aDatabase.RemoveSpeedDialFieldL(aContact, aSpeedDialID)); g_test(error == KErrInUse); // Now attempt to open the contact (must fail with in use): // Defect was fails with wrong error/no error. error = KErrNone; TRAP(error, aDatabase.OpenContactL(aContact)); g_test(error == KErrInUse); // Cleanup and close: CleanupStack::PopAndDestroy(card1); TRAP(error, aDatabase.CloseContactL(aContact)); g_test(error == KErrNone); }
void TestFourL() { g_test.Start(_L("Check that Settings are saved - killing ContactLockSrv")); g_test.Next(_L("Setting up...")); CLockServerTester* lockSrvTester = CLockServerTester::NewL(); CleanupStack::PushL(lockSrvTester); CContactDatabase* database = SetupLC(); g_test.Next( _L("Assign Speed Dial")); TInt error = KErrNone; TRAP(error, AssignSpeedDialL( KSpeedDialContact, KSpeedDialPositionOne, *database ) ); g_test(error == KErrNone); g_test.Next( _L("Update Speed Dial")); error = KErrNone; TRAP(error, UpdateSpeedDialL( KSpeedDialContact, KSpeedDialPositionTwo, *database ) ); g_test(error == KErrNone); g_test.Next( _L("Change Database Drive")); CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveD),EFalse); CleanupStack::PopAndDestroy(database); // Kill ContactLockServer process g_test.Next( _L("Kill CntServer")); lockSrvTester->FindServerAndKillItL(); CleanupStack::PopAndDestroy( lockSrvTester ); g_test.Next( _L("Open Database")); database = CContactDatabase::OpenL(KDbFileName); CleanupStack::PushL(database); TDriveUnit driveUnit; CContactDatabase::DatabaseDrive(driveUnit); g_test.Next( _L("Check that Database Drive is changed")); g_test(driveUnit==TDriveUnit(EDriveD)); CContactItem* item = database->ReadContactL(KSpeedDialContact); CleanupStack::PushL(item); g_test.Next( _L("Check that Speed Dial is remembered")); g_test(item->Id() == KSpeedDialContact); // retored item should be a SpeedDial g_test(ContactIsASpeedDial( *item )); // reset Database Drive g_test.Next( _L("Reset Database Drive setting")); CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),EFalse); CleanupStack::PopAndDestroy(item); CleanupStack::PopAndDestroy(database); g_test.End(); }
void TestThreeL() { g_test.Start(_L("Check that Settings are saved - normal shutdown")); g_test.Next(_L("Setting up...")); CContactDatabase* database = SetupLC(); g_test.Next( _L("Assign Speed Dial")); TInt error = KErrNone; TRAP(error, AssignSpeedDialL( KSpeedDialContact, KSpeedDialPositionOne, *database ) ); g_test(error == KErrNone); g_test.Next( _L("Update Speed Dial")); error = KErrNone; TRAP(error, UpdateSpeedDialL( KSpeedDialContact, KSpeedDialPositionTwo, *database ) ); g_test(error == KErrNone); g_test.Next( _L("Change Database Drive")); CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveD),EFalse); CleanupStack::PopAndDestroy( database ); g_test.Next(_L("Wait for Contact Server to shutdown")); // wait until Contacts Lock Server shuts down // applicabale only in the case of transient server. User::After(6000000); g_test.Next( _L("Try to open Database again")); database = CContactDatabase::OpenL(KDbFileName); CleanupStack::PushL(database); TDriveUnit driveUnit; CContactDatabase::DatabaseDrive(driveUnit); g_test.Next( _L("Check that Database Drive is changed")); g_test(driveUnit==TDriveUnit(EDriveD)); CContactItem* item = database->ReadContactL(KSpeedDialContact); CleanupStack::PushL(item); g_test.Next( _L("Check that Speed Dial is remembered")); g_test(item->Id() == KSpeedDialContact); // retored item should be a SpeedDial g_test(ContactIsASpeedDial( *item )); // reset Database Drive g_test.Next( _L("Reset Database Drive setting")); CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),EFalse); CleanupStack::PopAndDestroy(item); CleanupStack::PopAndDestroy(database); g_test.End(); }
void RemoveSpeedDialL(TInt aContact, TInt aSpeedDialId, CContactDatabase& aDatabase) { TInt error = KErrNone; TRAP(error, aDatabase.RemoveSpeedDialFieldL(aContact, aSpeedDialId)); g_test(error == KErrNone); }
void AssignSpeedDialL( TInt aContact, TInt aSpeedDialID, CContactDatabase& database ) { CContactItem* item = NULL; item = database.OpenContactL( aContact ); CleanupStack::PushL( item ); if ( ContactIsASpeedDial( *item ) ) { g_test.Printf( _L("Contact is a speed dial !!! \n") ); } else { g_test.Printf( _L("Contact is NOT A SPEED DIAL \n") ); } CContactItemFieldSet &fieldSet = item->CardFields(); for(TInt index = fieldSet.Count() - 1; index > 0; --index) { if(fieldSet[index].StorageType() == KStorageTypeText) { //set the last text field from the fieldset as speeddial field. database.SetFieldAsSpeedDialL(*item, index, aSpeedDialID ); break; } } g_test.Next( _L("Contact changed to speed dial") ); g_test(ContactIsASpeedDial( *item )); CleanupStack::PopAndDestroy( item ); }
void TestDatabaseWithSpeedDialsL() { g_test.Next(_L("Setting up...")); CContactDatabase* database = SetupLC(); g_test.Next(_L("First Speed dial assignment")); // Assign First time ok ! TRAPD(error, AssignSpeedDialL( KSpeedDialContact, KSpeedDialPositionOne, *database ) ); g_test(error == KErrNone); g_test.Next(_L("Second Speed dial assignment")); // Assign Second time falls over ! TRAP(error, AssignSpeedDialL( KSpeedDialContact, KSpeedDialPositionOne, *database ) ); g_test(error == KErrNone); g_test.Next(_L("Open contact, remove from speed dial, open again")); // The remove from speed dial on the open contact should return KErrInUse. // The second open should also return KErrInUse. TRAP(error, RemoveSpeedDialWhenOpenL(KSpeedDialContact, KSpeedDialPositionOne, *database)); g_test(error == KErrNone); CleanupStack::PopAndDestroy( database ); // wait until Contacts Lock Server shuts down User::After(6000000); g_test.Next( _L("Try to open db again")); database = CContactDatabase::OpenL(KDbFileName); CleanupStack::PushL(database); CContactItem* item = database->ReadContactL(KSpeedDialContact); CleanupStack::PushL(item); g_test.Next( _L("Check that Speed dial is remembered")); g_test(item->Id() == KSpeedDialContact); // retored item should be a SpeedDial g_test(ContactIsASpeedDial( *item )); CleanupStack::PopAndDestroy(item); CleanupStack::PopAndDestroy(database); }
void TestTwoL() { g_test.Start(_L("Create Database with Speed Dials then Replace database")); TestDatabaseWithSpeedDialsL(); g_test.Next(_L("Replace database")); CContactDatabase* database = ReplaceDatabaseAndCreateContactsLC(); CContactItem* item = database->ReadContactL(KSpeedDialContact ); CleanupStack::PushL(item); g_test.Next(_L("Check that Speed dial is forgotten")); g_test(item->Id() == KSpeedDialContact); // retored item should not be a SpeedDial g_test(!ContactIsASpeedDial( *item )); CleanupStack::PopAndDestroy(item); CleanupStack::PopAndDestroy(database); g_test.End(); }
LOCAL_C void LongNumSpeedDialTestsL() { _LIT(KLongNumSpeedDialTest, "Long Phone Number Speed Dial Test"); g_test.Start(KLongNumSpeedDialTest); // create default, empty database CContactDatabase* db = CContactDatabase::ReplaceL(KLongNumSpeedDialDbName); CleanupStack::PushL(db); // create a contact and add it to the db CContactItem* contact = CContactCard::NewLC(); CContactItemField* fname = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName); _LIT(KFname, "James"); fname->TextStorage()->SetTextL(KFname() ); contact->AddFieldL(*fname); CleanupStack::Pop(fname); CContactItemField* phone = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber); _LIT(KPhoneNum, "01234567890123456789012345678901234567890123456789012345678901234567890123456789"); // 80 chars phone->TextStorage()->SetTextL(KPhoneNum() ); contact->AddFieldL(*phone); CleanupStack::Pop(phone); const TContactItemId KContactId = db->AddNewContactL(*contact); CleanupStack::PopAndDestroy(contact); contact = NULL; // retrieve contact and assign its number to speed dial #1 contact = db->OpenContactL(KContactId); CleanupStack::PushL(contact); const TInt KSpeedDial1(1); const TInt KPhoneNumIndex = contact->CardFields().Find(KUidContactFieldPhoneNumber); db->SetFieldAsSpeedDialL(*contact, KPhoneNumIndex, KSpeedDial1); TBuf<100> speedDialNumberText; TContactItemId speedDialId = db->GetSpeedDialFieldL(KSpeedDial1, speedDialNumberText); _LIT(KOutputFormat, "retrieved speed dial id: %d;\nretrieved speed dial phone number: ...\n%S\n"); g_test.Printf(KOutputFormat, speedDialId, &speedDialNumberText); db->CloseContactL(KContactId); // cleanup CleanupStack::PopAndDestroy(2, db); // and contact CContactDatabase::DeleteDatabaseL(KLongNumSpeedDialDbName); // Since PDEF121954, long phone numbers set as speed dial are truncated to // the length of KSpeedDialPhoneLength. So, we need to get the truncated // version of the phone number for comparison with the speed dial value. TPtrC phoneNum(KPhoneNum().Mid(0, KSpeedDialPhoneLength)); g_test(speedDialId == KContactId && speedDialNumberText.CompareC(phoneNum) == 0); g_test.End(); g_test.Close(); }
GLDEF_C TInt E32Main() { __UHEAP_MARK; g_test.Start(_L("Speed dial test")); CActiveScheduler* scheduler=new CActiveScheduler; if (scheduler) { CActiveScheduler::Install(scheduler); CTrapCleanup* cleanup=CTrapCleanup::New(); if (cleanup) { TRAPD(err,DoTestL() ); g_test(err == KErrNone); delete cleanup; } delete scheduler; } g_test.Close(); __UHEAP_MARKEND; return KErrNone; }
void LoadExpr (unsigned Flags, struct ExprDesc* Expr) /* Load an expression into the primary register if it is not already there. */ { if (ED_IsLVal (Expr)) { /* Dereferenced lvalue. If this is a bit field its type is unsigned. * But if the field is completely contained in the lower byte, we will * throw away the high byte anyway and may therefore load just the * low byte. */ if (ED_IsBitField (Expr)) { Flags |= (Expr->BitOffs + Expr->BitWidth <= CHAR_BITS)? CF_CHAR : CF_INT; Flags |= CF_UNSIGNED; } else { Flags |= TypeOf (Expr->Type); } if (ED_NeedsTest (Expr)) { Flags |= CF_TEST; } switch (ED_GetLoc (Expr)) { case E_LOC_ABS: /* Absolute: numeric address or const */ g_getstatic (Flags | CF_ABSOLUTE, Expr->IVal, 0); break; case E_LOC_GLOBAL: /* Global variable */ g_getstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->IVal); break; case E_LOC_STATIC: case E_LOC_LITERAL: /* Static variable or literal in the literal pool */ g_getstatic (Flags | CF_STATIC, Expr->Name, Expr->IVal); break; case E_LOC_REGISTER: /* Register variable */ g_getstatic (Flags | CF_REGVAR, Expr->Name, Expr->IVal); break; case E_LOC_STACK: /* Value on the stack */ g_getlocal (Flags, Expr->IVal); break; case E_LOC_PRIMARY: /* The primary register - just test if necessary */ if (Flags & CF_TEST) { g_test (Flags); } break; case E_LOC_EXPR: /* Reference to address in primary with offset in Expr */ g_getind (Flags, Expr->IVal); break; default: Internal ("Invalid location in LoadExpr: 0x%04X", ED_GetLoc (Expr)); } /* Handle bit fields. The actual type may have been casted or * converted, so be sure to always use unsigned ints for the * operations. */ if (ED_IsBitField (Expr)) { unsigned F = CF_INT | CF_UNSIGNED | CF_CONST | (Flags & CF_TEST); /* Shift right by the bit offset */ g_asr (F, Expr->BitOffs); /* And by the width if the field doesn't end on an int boundary */ if (Expr->BitOffs + Expr->BitWidth != CHAR_BITS && Expr->BitOffs + Expr->BitWidth != INT_BITS) { g_and (F, (0x0001U << Expr->BitWidth) - 1U); } } /* Expression was tested */ ED_TestDone (Expr); } else { /* An rvalue */ if (ED_IsLocExpr (Expr)) { if (Expr->IVal != 0) { /* We have an expression in the primary plus a constant * offset. Adjust the value in the primary accordingly. */ Flags |= TypeOf (Expr->Type); g_inc (Flags | CF_CONST, Expr->IVal); } } else { /* Constant of some sort, load it into the primary */ LoadConstant (Flags, Expr); } /* Are we testing this value? */ if (ED_NeedsTest (Expr)) { /* Yes, force a test */ Flags |= TypeOf (Expr->Type); g_test (Flags); ED_TestDone (Expr); } } }
/** @SYMTestCaseID PIM-T-SPEEDDIALTEST-INC097895-0001 @SYMTestType UT @SYMTestPriority High @SYMDEF INC097895 @SYMTestCaseDesc Pbk2 AIW: Speed dial is removed from incorrect entry @SYMTestActions 1. Add speed dials for contact A and B 2. Try to reset speed dial belonging to A by using B's id 3. Reset speed dials using the correct contacts @SYMTestExpectedResults Speed dial is still active when reset is attempted by wrong contact */ void TestFiveL() { g_test.Start(_L("@SYMTestCaseID:PIM-T-SPEEDDIALTEST-INC097895-0001 Checking that the correct contact resets the speed dial number")); g_test.Next(_L("Setting up...")); CContactDatabase* database = SetupLC(); g_test.Next(_L("First Speed dial assignment")); TRAPD(error, AssignSpeedDialL( KSpeedDialContactA, KSpeedDialPositionOne, *database ) ); g_test(error == KErrNone); // Check that a speed dial is assigned g_test(ContactIsASpeedDialL(KSpeedDialContactA, *database)); g_test.Next(_L("Second Speed dial assignment")); TRAP(error, AssignSpeedDialL( KSpeedDialContactB, KSpeedDialPositionTwo, *database ) ); g_test(error == KErrNone); // Check that a speed dial is assigned g_test(ContactIsASpeedDialL(KSpeedDialContactB, *database)); // Here, the wrong contact (B) is trying to reset the speed dial number // which is set by contact A. g_test.Next(_L("Wrong contact - should be ignored")); TRAP(error, RemoveSpeedDialL(KSpeedDialContactB, KSpeedDialPositionOne, *database)); g_test(error == KErrNone); g_test.Next(_L("The first speed dial is still active")); g_test(ContactIsASpeedDialL(KSpeedDialContactA, *database)); g_test.Next(_L("and the second speed dial is still active")); g_test(ContactIsASpeedDialL(KSpeedDialContactB, *database)); g_test.Next(_L("Reset allowed by the correct contact")); TRAP(error, RemoveSpeedDialL(KSpeedDialContactA, KSpeedDialPositionOne, *database)); g_test(error == KErrNone); g_test.Next(_L("Check speed dial One has been reset")); g_test(!ContactIsASpeedDialL(KSpeedDialContactA, *database)); TRAP(error, RemoveSpeedDialL(KSpeedDialContactB, KSpeedDialPositionTwo, *database)); g_test(error == KErrNone); g_test.Next(_L("Check speed dial Two has been reset")); g_test(!ContactIsASpeedDialL(KSpeedDialContactB, *database)); CleanupStack::PopAndDestroy(database); g_test.End(); }