void T_CntImageRescaler::testRescaleImageSuccefully() { test.Next(_L("Rescale image")); TPath dest; dest.Append(KDestDir()); dest.Append(_L("test.jpg")); TTime time; time.UniversalTime(); TRAPD(err, iRescaler->ResizeImageL(KSrcImage(), dest)); TTime time2; time2.UniversalTime(); TInt seconds = time2.MicroSecondsFrom( time ).Int64() / 1000000; test.Printf(_L("rescaled in %d seconds\n"), seconds); test(err == KErrNone); test(BaflUtils::FileExists(iFs, dest)); TEntry file; if (iFs.Entry(dest, file) == KErrNone) { test(file.iSize <= KMaxImageSize); } }
LOCAL_C void TestUpdateContactL() { test.Next(_L("TestUpdateContactL")); SETUP; CContactItem* contact = CContactItem::NewLC(KUidContactCard); TContactItemId id = cntClient.CreateContactL(*contact); CleanupStack::PopAndDestroy(contact); // View definition to read image field CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); imageViewDef->AddL(KUidContactFieldMatchAll); contact = cntClient.OpenContactLX(imageViewDef ,id); CleanupStack::PushL(contact); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage); newField->SetMapping(KUidContactFieldVCardMapUnknown); newField->TextStorage()->SetTextL(KSrcImage()); contact->AddFieldL(*newField); // Takes ownership CleanupStack::Pop(newField); cntClient.CommitContactL(*contact, EFalse); CleanupStack::PopAndDestroy(2); // contact, imageViewDef // View definition to read image field imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); imageViewDef->AddL(KUidContactFieldCodImage); contact = cntClient.ReadContactL(imageViewDef ,id); TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown); // Test image field found test(index != KErrNotFound); CContactItemField& field = contact->CardFields()[index]; TPtrC imagePtr = field.TextStorage()->Text(); // Image should exist test(BaflUtils::FileExists(fs, imagePtr)); // Test for GUID TPtrC guid = contact->Guid(); test(imagePtr.Find(guid)); cntClient.CloseContact(id); CleanupStack::PopAndDestroy(2); // contact, imageViewDef TEAR_DOWN; }
LOCAL_C void TestDeleteContactL() { test.Next(_L("TestDeleteContactL")); SETUP; CContactItem* contact = CContactItem::NewLC(KUidContactCard); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage); newField->SetMapping(KUidContactFieldVCardMapUnknown); newField->TextStorage()->SetTextL(KSrcImage()); contact->AddFieldL(*newField); // Takes ownership CleanupStack::Pop(newField); TContactItemId id = cntClient.CreateContactL(*contact); CleanupStack::PopAndDestroy(contact); // View definition to read image field CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); imageViewDef->AddL(KUidContactFieldCodImage); contact = cntClient.ReadContactL(imageViewDef ,id); CleanupStack::PopAndDestroy(imageViewDef); // imageViewDef TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown); // Test image field found test(index != KErrNotFound); CContactItemField& field = contact->CardFields()[index]; TPtrC imagePtr = field.TextStorage()->Text(); test(BaflUtils::FileExists(fs, imagePtr)); cntClient.DeleteContactL(id, EDeferEvent, ETrue); test(!BaflUtils::FileExists(fs, imagePtr)); cntClient.CloseContact(id); delete contact; TEAR_DOWN; }
LOCAL_C void TestCreateContactWithoutImagesFoldeL() { test.Next(_L("TestCreateContactWithoutImagesFoldeL")); SETUP; // Delete the images folder and all contents TInt drive; #ifdef __WINS__ TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive); #else TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, drive); #endif // Do not leave with this error. The phone does not have to have this support if (err == KErrNone) { // Get the root path in this drive to create // to create the images directory TPath dir; User::LeaveIfError(PathInfo::GetRootPath(dir, drive)); dir.Append(KImagesFolder); CFileMan* fileMan = CFileMan::NewL(fs); err = fileMan->RmDir(dir); // err not used delete fileMan; } else { test.Printf(_L("Could not remove the images folder\n")); return; } // Create an image and store an image without the images dir available CContactItem *contact = CContactItem::NewLC(KUidContactCard); CContactItemField *newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage); newField->SetMapping(KUidContactFieldVCardMapUnknown); newField->TextStorage()->SetTextL(KSrcImage()); contact->AddFieldL(*newField); // Takes ownership CleanupStack::Pop(newField); TContactItemId id = cntClient.CreateContactL(*contact); CleanupStack::PopAndDestroy(contact); // View definition to read image field CContactItemViewDef *imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); imageViewDef->AddL(KUidContactFieldCodImage); contact = cntClient.ReadContactL(imageViewDef ,id); CleanupStack::PopAndDestroy(imageViewDef); // imageViewDef TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown); // Test image field found test(index != KErrNotFound); CContactItemField& field = contact->CardFields()[index]; TPtrC imagePtr = field.TextStorage()->Text(); // Image path should not change test(imagePtr.Compare(KSrcImage()) == 0); cntClient.CloseContact(id); delete contact; TEAR_DOWN; }