// Static functions that do the whole process in one go: EXPORT_C void CObexMtmFileNameExternaliser::ExternaliseAndCommit1FileNameL(CMsvEntry* aEntry, const TDesC16* aFileName) /** * Static function to write one and only one filename to the message store, then finalise and commit it. This function * should be called ONCE ONLY. To externalise more than one filename, instantiate this class and use ExternaliseFileNameL() * followed by CommitStoreL(). * @param aEntry the entry whose store is to be written to * @param aFileName The filename to write to the store * @leave KErrXXX system-wide error codes */ { CMsvStore* messageStore = aEntry->EditStoreL(); CleanupStack::PushL(messageStore); RMsvWriteStream messageWriteStream; CleanupClosePushL(messageWriteStream); messageWriteStream.AssignL(*messageStore, KObexFileNameStreamUid); // write the identifier so we know we are internalizing a stream later #ifndef TEST_INC042468 messageWriteStream.WriteInt32L(KObexFileNameStreamFileNameUid); #endif messageWriteStream.WriteInt32L(aFileName->Length()); messageWriteStream.WriteL(*aFileName); #ifndef TEST_INC042468 messageWriteStream.WriteInt32L(KObexFileNameStreamFileNameUid); #endif messageWriteStream.WriteInt32L(0); //Mark the end of the filename list messageWriteStream.CommitL(); CleanupStack::PopAndDestroy(); // trigger a call to Close(); on messageWriteStream as well as removing from the stack messageStore->CommitL(); CleanupStack::PopAndDestroy(messageStore); }
/* Test to check the new API ** CopyStoreL(TInt aDrive, TMsvOp aOperationId, TRequestStatus& aStatus) */ LOCAL_C void TestCopyStoreOperationL() { CMsgsTestUtils::SetDriveL(EDriveC); CSessionObserver* ob = new(ELeave)CSessionObserver; CleanupStack::PushL(ob); // Set session in observer CMsvSession* session = CMsvSession::OpenAsyncL(*ob); ob->iSession = session; CleanupStack::PushL(session); CActiveScheduler::Start(); test(ob->iType==MMsvSessionObserver::EMsvServerReady); //Create an entry in the mail CMsvEntry* entry=session->GetEntryL(KMsvDraftEntryId); CleanupStack::PushL(entry); // create entry to work under TMsvEntry folder; folder.iType = KUidMsvFolderEntry; folder.iMtm = KUidMsvLocalServiceMtm; folder.iServiceId = KMsvLocalServiceIndexEntryId; _LIT(KTestDescription,"A Description"); _LIT(KTestDetails,"A Details"); folder.iDescription.Set(KTestDescription); folder.iDetails.Set(KTestDetails); entry->CreateL(folder); entry->SetEntryL(folder.Id()); CMsvStore* store=entry->EditStoreL(); CleanupStack::PushL(store); RMsvWriteStream stream; stream.AssignLC(*store,TUid::Uid(0x1000)); stream.WriteL(KTestDescription); stream.CommitL(); store->CommitL(); CleanupStack::PopAndDestroy(3); CTestActive* active = new(ELeave)CTestActive; CleanupStack::PushL(active); // Test Copy MailStore active->StartL(); CMsvOperation* operation = NULL; TDriveUnit unit =(EDriveD); operation = session->CopyStoreL(unit, active->iStatus); test(operation->Mtm() == KUidMsvServerMtm); CleanupStack::PushL(operation); CActiveScheduler::Start(); //Retrieve progress TPckgBuf<TMsvCopyProgress> package; package.Copy(operation->ProgressL()); test(package().iError == KErrNone); //delete session; CleanupStack::PopAndDestroy(4); //Check that both the source and destination //MailStore directory structure is same CMsgsTestUtils::WaitForServerClose(); CDir *srcDir; CDir *destDir; _LIT(intro, "Testing the directory structure"); _LIT(KEntryname,"%S"); theUtils->Printf(intro); TFileName dest = unit.Name(); dest.Append(KMsvDefaultFolder2); User::LeaveIfError(theUtils->FileSession().GetDir(dest, KEntryAttDir|KEntryAttNormal, ESortByName, destDir)); unit =EDriveC; TFileName src = unit.Name(); src.Append(KMsvDefaultFolder2); User::LeaveIfError(theUtils->FileSession().GetDir(src, KEntryAttDir|KEntryAttNormal, ESortByName, srcDir)); TInt counter=0; TEntry srcEntry; TEntry destEntry; while (counter<srcDir->Count()) { srcEntry = (*srcDir)[counter]; destEntry = (*destDir)[counter]; //Check the sizes test(srcEntry.iSize == destEntry.iSize); //Check the names test(srcEntry.iName == destEntry.iName); //Print out the names on the log theUtils->Printf(KEntryname,&(srcEntry.iName)); counter++; } delete srcDir; delete destDir; }