예제 #1
0
EXPORT_C TInt RFTokenClient::GenerateToken(const TDesC& aFileName, const TSecurityPolicy& aSecurityPolicy, TDes8& aToken) const
    {
    // unefficient, but this way we can make _easily_ sure that client is actually allowed to open a file
    // Not sure if we were allowed to just change CEikonEnv's file server session to shared, so we could acutally save
    // this extra session..
    RFs fs;
    TInt err = fs.Connect();
    if (!err) 
        {
        err = fs.ShareProtected();
        if (!err) 
            {
            RFile file;
            err = file.Open(fs, aFileName, EFileShareReadersOnly); // Todo: check the correct mode
            if (!err)
                {
                err = GenerateToken(file, aSecurityPolicy, aToken);
                }
            file.Close();
            }
        fs.Close();
        }
    
    return err;
    //return SendReceive(EGenerateTokenBasedOnName, TIpcArgs(&aFileName, aAllowedProcessUid.iUid, &aToken));
    }
예제 #2
0
void CBtMsgViewerUtils::StoreMessageMimeTypeL(TPtr aMsgPath)
    {
    RFs rfs;
    RFile file;
    
    User::LeaveIfError(rfs.Connect());
    
    User::LeaveIfError(rfs.ShareProtected());
    
    User::LeaveIfError(file.Open(rfs, aMsgPath, EFileShareReadersOrWriters | EFileRead));
    
    TDataRecognitionResult dataType;
    RApaLsSession apaSession;
    
    if(apaSession.Connect() == KErrNone)
        {
        if (apaSession.RecognizeData(file, dataType) == KErrNone)
            {
            if(iMimeType)
                {
                delete iMimeType;
                iMimeType = NULL;
                }
        
            iMimeType = dataType.iDataType.Des8().AllocL();
            
            rfs.Close();
            apaSession.Close();
            }
        }

    rfs.Close();
    }
예제 #3
0
TVerdict CTStepRestore::doTestStepL()
	{
	if (TestStepResult() != EPass)
		{
		return TestStepResult();
		}
__UHEAP_MARK;		// Check for memory leaks
	RFs fs;
	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);
	fs.ShareProtected();
	
	Swi::RRestoreSession session;
	User::LeaveIfError(session.Connect());
	CleanupClosePushL(session);
	
	while (NextPackage())
		{
		HBufC8* metadata = ReadMetaDataL();
		CleanupStack::PushL(metadata);
		session.StartPackageL(PackageUID(), *metadata);
		while (NextFile())
			{
			RFile sourcefile;
			User::LeaveIfError(sourcefile.Open(fs, BackupFileName(), EFileRead));
			TPtrC destfilename = InstalledFileName();
			session.RestoreFileL(sourcefile, destfilename);
			}
		session.CommitPackageL();
		CleanupStack::PopAndDestroy(metadata);
		}	
	CleanupStack::PopAndDestroy(2, &fs);	// session	
__UHEAP_MARKEND;
	return TestStepResult();
	}
	void ShowInViewerL(const TDesC& aFileName) 
	{
 		if ( ! iDocHandler )
			iDocHandler = CDocumentHandler::NewL();

		

		_LIT8(KImageMime, "image/jpeg");
		TDataType mimeType(KImageMime);

		//iShownFile.Close();
		RFs fs;
		User::LeaveIfError( fs.Connect() );
		CleanupClosePushL( fs );
		User::LeaveIfError( fs.ShareProtected() );
		iShownFile.Open( fs, aFileName, EFileShareAny | EFileRead );
		CleanupClosePushL( iShownFile );
		
		TDataType empty;
		iDocHandler->OpenFileL(iShownFile, empty);
		//		iDocHandler->OpenFileL(iShownFile, mimeType);

// 		iDocHandler->OpenFileL(aFileName, empty);
		CleanupStack::PopAndDestroy( &iShownFile );
		CleanupStack::PopAndDestroy( &fs );
	}
void TestMessageAddLinkedAttachmentL(const TDesC8& aMimeType)
	{
	CleanMailFolder(KMsvDraftEntryId);
	
	RFs fs;
	User::LeaveIfError(fs.Connect());
	User::LeaveIfError(fs.ShareProtected());
	// Clean up any existing attachment files and create two new ones.
	theUtils->WriteComment(_L("Create two attachment files."));
	CreateAttachmentFileL(fs, KExistingAttachmentName1);
	CreateAttachmentFileL(fs, KExistingAttachmentName2);

	// Create a message.
	RSendAsMessage message;
	theUtils->WriteComment(_L("Create a message."));
	message.CreateL(gSendAs, sendAsTestMtmUid);

	CTestActive* testActive = new(ELeave) CTestActive;
	CleanupStack::PushL(testActive);

	theUtils->WriteComment(_L("Add first created attachment file as a link."));
	if (aMimeType.Length() > 0)
		{
		message.AddLinkedAttachment(KExistingAttachmentName1, aMimeType, testActive->iStatus);
		}
	else
		{
		message.AddLinkedAttachment(KExistingAttachmentName1, testActive->iStatus);
		}
	testActive->StartL();
	CActiveScheduler::Start();
	
	theUtils->WriteComment(_L("Add second created attachment file as a link."));
	if (aMimeType.Length() > 0)
		{
		message.AddLinkedAttachment(KExistingAttachmentName2, aMimeType, testActive->iStatus);
		}
	else
		{
		message.AddLinkedAttachment(KExistingAttachmentName2, testActive->iStatus);
		}
	testActive->StartL();
	CActiveScheduler::Start();

	test(testActive->iStatus.Int() == KErrNone);
	CleanupStack::PopAndDestroy(testActive);
	theUtils->WriteComment(_L("Save and close the message."));
	message.SaveMessageAndCloseL();

	CheckNewAttachmentL(KExistingAttachmentName1, 16, aMimeType, KNoCharsetSpecifed, ETrue); // ETrue to indicate linked attachment
	CheckNewAttachmentL(KExistingAttachmentName2, 16, aMimeType, KNoCharsetSpecifed, ETrue); // ETrue to indicate linked attachment
	fs.Close();
	
	theUtils->Complete();
	}
예제 #6
0
TPolicyID RSecMgrSession::UpdatePolicy(TPolicyID aPolicyID,
		const TDesC8& aPolicyBuffer)
	{
	TInt ret(ErrInvalidParameters);
	if(0==aPolicyBuffer.CompareC(KNullDesC8))
		{
		return ret;
		}
		
		TFileName tempDirPath;
		TFileName tempPath;
	
		{
		RFs fileSession;
		if ( KErrNone==fileSession.Connect ())
			{
			fileSession.PrivatePath (tempDirPath);
			BaflUtils::EnsurePathExistsL (fileSession, tempDirPath);

			RFile secPolicyFile;
			secPolicyFile.Temp (fileSession, tempDirPath, tempPath, EFileWrite);
			secPolicyFile.Write(aPolicyBuffer);
			secPolicyFile.Close();			
			}		
		fileSession.Close();
		}
		
	RFs fileSession;
	if ( KErrNone==fileSession.Connect ())
		{
		CleanupClosePushL (fileSession);
		if ( KErrNone==fileSession.ShareProtected ())
			{
			RFile secPolicyFile;
					
			if(KErrNone == secPolicyFile.Open(fileSession,tempPath,EFileRead))
				{
				
				ret = UpdatePolicy (aPolicyID, secPolicyFile);
			
				secPolicyFile.Close();
			
				}

			fileSession.Delete (tempPath);
			}
		
		CleanupStack::PopAndDestroy (&fileSession);//fileSession
		}

	fileSession.Close();
	
	return ret;
	}
TVerdict CTStepRestoreExtraExecutable::doTestStepL()
	{
	if (TestStepResult() != EPass)
		{
		return TestStepResult();
		}

	RFs fs;
	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);
	fs.ShareProtected();
	
	Swi::RRestoreSession session;
	User::LeaveIfError(session.Connect());
	CleanupClosePushL(session);
	
	while (NextPackage())
		{
		HBufC8* metadata = ReadMetaDataL();
		CleanupStack::PushL(metadata);
		session.StartPackageL(PackageUID(), *metadata);
		while (NextFile())
			{
			RFile sourcefile;
			User::LeaveIfError(sourcefile.Open(fs, BackupFileName(), EFileRead));
			if (WrongInstalledFileName().Length())
				{
				TDesC destfilename(WrongInstalledFileName());
				TRAPD (err, session.RestoreFileL(sourcefile, destfilename));
				if (err != KErrNone)
					{
	    			INFO_PRINTF1(_L("Swi::MRestore::RestoreFileL unexpectedly succeeded"));
					SetTestStepResult(EFail);
					}
				}
			else
				{
				TDesC destfilename(InstalledFileName());
				session.RestoreFileL(sourcefile, destfilename);
				}
			}
		TRAPD(err,session.CommitPackageL());
		if (err != KErrNone)
			{
			INFO_PRINTF2(_L("Commit failed with error: %d"), err);
			}
		
		CleanupStack::PopAndDestroy(metadata);
		}	
	CleanupStack::PopAndDestroy(2, &fs);	// session	

	return TestStepResult();
	}
void TestMessageAddAttachmentL(TBool aUseName, const TDesC8& aMimeType, TUint aCharset)
	{
	CleanMailFolder(KMsvDraftEntryId);
	
	RFs fs;
	User::LeaveIfError(fs.Connect());
	User::LeaveIfError(fs.ShareProtected());
	// Clean up any existing attachment files and create two new ones.
	theUtils->WriteComment(_L("Create two attachment files."));
	CreateAttachmentFileL(fs, KExistingAttachmentName1);
	CreateAttachmentFileL(fs, KExistingAttachmentName2);

	// Create a message.
	RSendAsMessage message;
	theUtils->WriteComment(_L("Create a message."));
	message.CreateL(gSendAs, sendAsTestMtmUid);

	CTestActive* testActive = new(ELeave) CTestActive;
	CleanupStack::PushL(testActive);

	theUtils->WriteComment(_L("Add first created attachment file."));
	AddNewAttachmentWithCharsetL(message, fs, KExistingAttachmentName1, aMimeType, aCharset, aUseName, testActive->iStatus);
	testActive->StartL();
	CActiveScheduler::Start();
	test(testActive->iStatus.Int() == KErrNone);

	theUtils->WriteComment(_L("Add second created attachment file."));
	AddNewAttachmentWithCharsetL(message, fs, KExistingAttachmentName2, aMimeType, aCharset, aUseName, testActive->iStatus);
	testActive->StartL();
	CActiveScheduler::Start();
	test(testActive->iStatus.Int() == KErrNone);

	CleanupStack::PopAndDestroy(testActive);
	theUtils->WriteComment(_L("Save and close the message."));
	message.SaveMessageAndCloseL();

	CheckNewAttachmentL(KExistingAttachmentName1, 16, aMimeType, aCharset, EFalse);
	CheckNewAttachmentL(KExistingAttachmentName2, 16, aMimeType, aCharset, EFalse);
	fs.Close();
	
	theUtils->Complete();
	}
예제 #9
0
/**
   @SYMTestCaseID T-RApaLsSessionTestStep-TestServiceDiscovery26
  
   @SYMPREQ 538
   
   @SYMTestPriority  High
  
   @SYMTestStatus Implemented
  
   @SYMTestCaseDesc Test the functionality ofAppForDocumentAndService given a file, service uid,file server and undefined file name 
   
   @SYMTestActions  Call AppForDocumentAndService with two parameters: a filename, a service uid, an
   app uid and the datatype requested
   on z: drive.\n
   API Calls:\n	
   RApaLsSession::AppForDocumentAndService(const TDesC& aFileName, TUid aServiceUid, TUid& aAppUid, TDataType& aDataType) const
   
   @SYMTestExpectedResults Returns KErrBadHandle. The app uid is set to null, the uid of datatype is set to null
    
 */	
void CT_ServicesTestStep::TestServiceDiscovery26()
	{
	INFO_PRINTF1(_L("TestServiceDiscovery26 about to start..."));
	const TUid KUidService = {0x01020304};
	TInt ret(0);
	TUid appUid=KNullUid;
	TDataType dataType;
	RFile file;
	_LIT(KOneByteFileName, "z:\\system\\data\\imaginary_byte.txt");
	RFs fs;
	ret = fs.Connect();
	ret = fs.ShareProtected();
	ret = file.Open(fs, KOneByteFileName, EFileRead|EFileShareAny);
	TEST(ret==KErrNotFound);
	ret = iApaLsSession.AppForDocumentAndService(file, KUidService, appUid, dataType);
	TEST(appUid==KNullUid);
	TEST(dataType.Des8().Length()==0);
	TEST(ret==KErrBadHandle);	
	fs.Close();

	}
예제 #10
0
/**
   @SYMTestCaseID T-RApaLsSessionTestStep-TestServiceDiscovery27
  
   @SYMPREQ 538

   @SYMTestPriority  High
  
   @SYMTestStatus Implemented
  
   @SYMTestCaseDesc Test the functionality ofAppForDocumentAndService given a file name, a file, file server and a service uid that the app 
   does not provide  * 
   
   @SYMTestActions  Call AppForDocumentAndService with two parameters: a filename, a service uid, an
   app uid and the datatype requested
   on z: drive.\n
   API Calls:\n	
   RApaLsSession::AppForDocumentAndService(const TDesC& aFileName, TUid aServiceUid, TUid& aAppUid, TDataType& aDataType) const
   
   @SYMTestExpectedResults Returns KErrNone.The value returned for app uid is null.The datatype is set to that that 
   describes the datatype in the document 
    
 */	
void CT_ServicesTestStep::TestServiceDiscovery27()
	{
	INFO_PRINTF1(_L("TestServiceDiscovery27 about to start..."));
	const TUid KUidService = {0x01000300};
	TInt ret(0);
	TUid appUid=KNullUid;
	TDataType dataType;
	RFile file;
	_LIT(KOneByteFileName, "z:\\system\\data\\one_byte.txt");
	RFs fs;
	ret = fs.Connect();
	ret = fs.ShareProtected();
	ret = file.Open(fs, KOneByteFileName, EFileRead|EFileShareAny);
	TEST(ret==KErrNone);
	ret = iApaLsSession.AppForDocumentAndService(file, KUidService, appUid, dataType);
	TEST(appUid==KNullUid);
	_LIT8(KLitMimeTypeServerData,"text/plain");
	TEST(dataType==TDataType(KLitMimeTypeServerData));
	TEST(ret==KErrNone);	
	fs.Close();
	}
void CNcdNodePreview::OpenPreviewFileL( MCatalogsBaseMessage& aMessage )
    {
    DLTRACEIN((""));
    RBuf8 buf;
    buf.CreateL( aMessage.InputLength() );
    CleanupClosePushL( buf );
    User::LeaveIfError( aMessage.ReadInput( buf ) );
    
    // Read the requested file index    
    TInt fileIndex = Des8ToInt( buf );

    // Open a new file server session because using the same session
    // for shared and non-shared files is a security risk     
    RFs fs;
    CleanupClosePushL( fs );
    User::LeaveIfError( fs.Connect() );

    // Share the file server session
    User::LeaveIfError( fs.ShareProtected() );

    DLTRACE(("Open preview file"));
    RFile openFile = iNodeManager.PreviewManager().PreviewL( 
            fs,
            iParentMetaData.Identifier(), 
            *iUris[fileIndex] );
            
    CleanupClosePushL( openFile );    
    
    DLINFO(("File open, transferring to client"));
    aMessage.CompleteAndReleaseL( fs, 
                                  openFile );

    // a shared file must be closed on the server side too
    // also the shared file session must be closed 
    CleanupStack::PopAndDestroy( 2, &fs ); // openFile, fs
    
    CleanupStack::PopAndDestroy( &buf );                    
    
    DLTRACEOUT((""));
    }
예제 #12
0
// ---------------------------------------------------------------------------
// To get the mime type of the file
//
// ---------------------------------------------------------------------------
//
QString MsgViewUtils::mimeTypeL(QString aFileName)
{
    RFs rfs;
    RFile file;

    HBufC* fileName = XQConversions::qStringToS60Desc(aFileName);

    //TODO: The RFs and RApaLsSession has to be connected 1's, not for every mms

    if(rfs.Connect() != KErrNone)
        return QString();

    if(rfs.ShareProtected() != KErrNone )
        return QString();

    if(file.Open(rfs, *fileName, EFileShareReadersOrWriters | EFileRead) != KErrNone )
        return QString();

    TDataRecognitionResult dataType;
    RApaLsSession apaSession;

    if(apaSession.Connect() == KErrNone)
        {
        if (apaSession.RecognizeData(file, dataType) == KErrNone)
            {
            TPtrC8 fileType = dataType.iDataType.Des8();

            rfs.Close();
            apaSession.Close();

            return XQConversions::s60Desc8ToQString(fileType);
            }
        }

    rfs.Close();
    return QString();
}
/**
 * Load and initialise an audio file.
 */
TVerdict CTestMmfVclntOpenFile0522::DoTestStepL()
	{
	TVerdict ret = EFail;

	INFO_PRINTF1(_L("Test : Video Recorder - OpenFileL(RFile&)"));

	RFs		fs;
	RFile	file;

	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);
	User::LeaveIfError(fs.ShareProtected());

	iError = KErrTimedOut;

	TPtrC filename;
	if(!GetStringFromConfig(iSectName,iKeyName,filename))
		{
		return EInconclusive;
		}

	User::LeaveIfError(file.Open(fs,filename,EFileWrite));
	CleanupClosePushL(file);
	CVideoRecorderUtility* rec = CVideoRecorderUtility::NewL(*this);
	CleanupStack::PushL(rec);

	const TUid KVidTstControllerUid = {KMmfVideoTestControllerUid};
	TRAP(iError,rec->OpenFileL(file, NULL, KVidTstControllerUid, KUidMdaBmpClipFormat));

	if(iError == KErrNone)
		{
		INFO_PRINTF1(_L("CVideoRecorderUtility: Open file"));
		// Wait for initialisation callback
		CActiveScheduler::Start();
		}

	if(iError == KErrNotSupported)
		{
		ret = EPass;
		}

	// Check for errors.
	if ((iError == KErrNone) && (rec != NULL))
		{
		rec->Prepare();
		CActiveScheduler::Start();
		if(iError != KErrNone)
			{
			INFO_PRINTF2(_L("Prepare callback : error %d"), iError);
			return EInconclusive;
			}

		if(iRec)
			{
			iError = KErrTimedOut;
			rec->Record();
			INFO_PRINTF1(_L("CVideoRecorderUtility: Record"));
			// Wait for init callback
			CActiveScheduler::Start();
			if(iError == KErrNone)
				{
				ret = EPass;
				}
			User::After(1000000);
			rec->Stop();
			}
		else
			{
			ret = EPass;
			}
		}

	rec->Close();
	
	INFO_PRINTF1(_L("CVideoRecorderUtility: Destroy"));
	CleanupStack::PopAndDestroy(rec);
	User::After(KOneSecond); // wait for deletion to shut down devsound
	if(iError != KErrNone)
		{
		ERR_PRINTF2( _L("CVideoRecorderUtility failed with error %d"),iError );
		}

	CleanupStack::PopAndDestroy(2,&fs);
	
	return	ret;
	}
void TestAddAttachmentAndSessionCloseL(TAttachmentTestType aTest)
	{
	RFs fs;
	RFile existingAttachment;

	CleanMailFolder(KMsvDraftEntryId);
	
	CleanupClosePushL(fs);
	CleanupClosePushL(existingAttachment);
	
	User::LeaveIfError(fs.Connect());
	User::LeaveIfError(fs.ShareProtected());
	// Clean up any existing attachment file.
	TInt err = fs.Delete(KExistingAttachmentName);
	if (err != KErrNotFound)
		{
		User::LeaveIfError(err);
		}

	// Create a new attachment file
	User::LeaveIfError(existingAttachment.Create(fs, KExistingAttachmentName, EFileWrite));
	User::LeaveIfError(existingAttachment.Write(KAttachmentContent));

	// Create a message.
	RSendAsMessage message;
	message.CreateL(gSendAs, sendAsTestMtmUid);
	CleanupClosePushL(message);

	CTestActive* testActive = new(ELeave) CTestActive;
	CleanupStack::PushL(testActive);

	switch (aTest)
		{
		case EByName:
			{
			theUtils->Start(_L("Close Session During Add Attachment By Name"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddAttachment(KExistingAttachmentName, testActive->iStatus);
			break;
			}
		case EByNameWithMimeType:
			{
			theUtils->Start(_L("Close Session During Add Attachment By Name With Mime Type"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddAttachment(KExistingAttachmentName, KMimeType, testActive->iStatus);
			break;
			}
		case EByFile:
			{
			theUtils->Start(_L("Close Session During Add Attachment By File"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddAttachment(existingAttachment, testActive->iStatus);
			break;
			}

		case EByFileWithMimeType:
			{
			theUtils->Start(_L("Close Session During Add Attachment By File With Mime Type"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddAttachment(existingAttachment, KMimeType, testActive->iStatus);
			break;
			}
		case ELinked:
			{
			theUtils->Start(_L("Close Session During Add Linked Attachment"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddLinkedAttachment(KExistingAttachmentName, testActive->iStatus);
			break;
			}
		case ELinkedWithMimeType:
			{
			theUtils->Start(_L("Close Session During Add Linked Attachment With Mime Type"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddLinkedAttachment(KExistingAttachmentName, KMimeType, testActive->iStatus);
			break;
			}
		}
	testActive->StartL();
	
	// Create the object to close send-as session.
	CTestCloseSessionActive* closeSession = new(ELeave) CTestCloseSessionActive(gSendAs);
	CleanupStack::PushL(closeSession);
	closeSession->StartL();
	
	// Need to pop-off the RSendAsMessage - as session is being closed, the pop 
	// and destroy will be calling Close on an invalid session handle.
	CleanupStack::Pop(3, &message);
	
	// Push the testActive and closeSession back onto the cleanup stack.
	CleanupStack::PushL(testActive);
	CleanupStack::PushL(closeSession);

	CActiveScheduler::Start();

	CleanupStack::PopAndDestroy(4, &fs); // cancelActive, testActive, existingAttachment, fs

	// Re-establish global RSendAs connection for other tests.
	test(gSendAs.Connect() == KErrNone);
	theUtils->Complete();
	}
예제 #15
0
/**
 * Installs a component by file handle using opaque arguments/results
 */
static TInt sifByHandleAndArgsAndResultsInstallL()
{
    // Open file handle to the installation file
    RFs fs;
    TInt err = fs.Connect();
    if (KErrNone != err)
    {
        ELOG1(EJavaConverters,
              "testsifapi: sifByHandleAndArgsAndResultsInstallL: Cannot connect to RFs, err %d", err);
        User::Leave(err);
    }
    CleanupClosePushL(fs);

    // If the file server session is not shared, USIF server crashes with KERN-EXEC 44
    err = fs.ShareProtected();
    if (KErrNone != err)
    {
        ELOG1(EJavaConverters,
              "testsifapi: sifByHandleAndArgsAndResultsInstallL: Cannot share RFs, err %d", err);
        User::Leave(err);
    }

// TEMP TEST
    RFile installFile;
    err = installFile.Open(fs, KTestMIDlet3, EFileShareReadersOnly | EFileRead);
    if (KErrNone != err)
    {
        ELOG1(EJavaConverters,
              "testsifapi: sifByHandleAndArgsAndResultsInstallL: Cannot open "
              "E:\\stopwatch10midp2.jad, err %d", err);
        User::Leave(err);
    }
    CleanupClosePushL(installFile);

    LOG(EJavaConverters, EInfo,
        "testsifapi: sifByHandleAndArgsAndResultsInstallL: installFile handle opened");

    RSoftwareInstall installer;
    err = installer.Connect();
    if (KErrNone != err)
    {
        ELOG1(EJavaConverters,
              "testsifapi: sifByHandleAndArgsAndResultsInstallL: Cannot connect to RSoftwareInstall, err %d", err);
        User::Leave(err);
    }
    CleanupClosePushL(installer);

    LOG(EJavaConverters, EInfo,
        "testsifapi: sifByHandleAndArgsAndResultsInstallL: RSoftwareInstall connected");

    TRequestStatus status;
    COpaqueNamedParams *arguments = COpaqueNamedParams::NewL();
    CleanupStack::PushL(arguments);
    COpaqueNamedParams *results = COpaqueNamedParams::NewL();
    CleanupStack::PushL(results);

    // Silent installation request
    arguments->AddIntL(KSifInParam_InstallSilently, 1);

    // drive E:
    arguments->AddIntL(KSifInParam_Drive, 4);

    // 0 is TSifPolicy::EUserAllowed == Yes
    arguments->AddIntL(KSifInParam_PerformOCSP, 0);
    arguments->AddIntL(KSifInParam_IgnoreOCSPWarnings, 0);

    arguments->AddIntL(KSifInParam_AllowUpgrade, 0);
    arguments->AddIntL(KSifInParam_AllowUntrusted, 0);
    arguments->AddIntL(KSifInParam_AllowOverwrite, 0);
    arguments->AddIntL(KSifInParam_AllowDownload, 0);


// TEMP TEST prevent overflow
//    arguments->AddStringL(KSifInParam_UserName, KUserName);
//    arguments->AddStringL(KSifInParam_Password, KPassWord);

    arguments->AddStringL(KSifInParam_SourceUrl, KSourceUrl);

    arguments->AddIntL(KSifInParam_IAP, 3);

    arguments->AddStringL(KSifInParam_Charset, KEmptyString);

    arguments->AddStringL(KSifInParam_MimeType, KJadMimeType);


    LOG(EJavaConverters, EInfo,
        "testsifapi: sifByHandleAndArgsAndResultsInstallL: arguments created");

    installer.Install(installFile, *arguments, *results, status);

    User::WaitForRequest(status);

    LOG1(EJavaConverters, EInfo,
        "testsifapi: sifByHandleAndArgsAndResultsInstallL: The return status of install operation was %d", status.Int());


    TInt componentId = 0;
    TBool idExisted = results->GetIntByNameL(KSifOutParam_ComponentId, componentId);
    if ( idExisted )
    {
        LOG1(EJavaConverters, EInfo,
            "testsifapi: sifByHandleAndArgsAndResultsInstallL: Component id was %d", componentId);
    }
    else
    {
        LOG(EJavaConverters, EInfo,
            "testsifapi: sifByHandleAndArgsAndResultsInstallL: No component id was returned");
    }

    // free resources before returning
    CleanupStack::PopAndDestroy(5);

    return componentId;
}
TVerdict CTestMmfAclntOpenFile7905::DoTestStepL()
{
    INFO_PRINTF1( _L("TestRecorder : Record File"));
    TVerdict ret = EFail;
    iError = KErrTimedOut;

    RFs fs;
    RFile file;

    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);
    User::LeaveIfError(fs.ShareProtected());

    TPtrC			filename;
    if(!GetStringFromConfig(iSectName, iKeyName, filename))
    {
        return EInconclusive;
    }

    CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
    CleanupStack::PushL(recUtil);

    TUid invalidAudioController;
    invalidAudioController.iUid = KInvalidAudioController;

    User::LeaveIfError(file.Replace(fs,filename,EFileWrite));
    CleanupClosePushL(file);

    recUtil->OpenFileL(file, invalidAudioController, KNullUid, KNullUid, KFourCCNULL);

    INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
    CActiveScheduler::Start();

    if( iError == KErrNotFound )
    {
        ret = EPass;
    }

    if(iError == KErrNone)
    {
        iError = KErrTimedOut;
        recUtil->RecordL();
        INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility"));
        CActiveScheduler::Start(); // open -> record

        User::After(KFiveSeconds);
        recUtil->Stop();
    }

    CleanupStack::PopAndDestroy(2, recUtil);
    recUtil = NULL;

    // Playback the file
    if (iError == KErrNone)
    {
        if (filename.Right(4).Compare(_L(".wav"))==0)
        {
            // Wav file playback
            CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this);
            CleanupStack::PushL(playUtil);
            TRAPD(err, playUtil->OpenFileL(filename));
            if (err != KErrNone)
            {
                INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
                ret = EFail;
            }
            CActiveScheduler::Start();
            if (iError != KErrNone)
            {
                INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
                ret = EFail;
            }

            playUtil->Play();
            CActiveScheduler::Start();

            CleanupStack::PopAndDestroy(playUtil);

            if (iError != KErrNone)
            {
                INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
                ret = EFail;
            }
        }
    }

    if( iError == KErrNone )
    {
        RFile file;
        TInt size = 0;
        User::LeaveIfError(file.Open(fs,filename,EFileRead));
        CleanupClosePushL(file);
        User::LeaveIfError(file.Size(size));

        if(size > 0)
        {
            ret = EPass;
        }
        CleanupStack::PopAndDestroy(); //file
    }

    CleanupStack::PopAndDestroy();	// fs

    ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
    User::After(KOneSecond);

    return	ret;
}
bool WidgetRegistrationS60::registerAppL(const QString& appId,
                                         const QString& appTitle,
                                         const QString& appPath,
                                         const QString& dataPath,
                                         const QString& iconPath,
                                         const AttributeMap& attr,
                                         const QString& type,
                                         unsigned long size,
                                         const QString& startPath,
                                         int& widgetUid,
                                         QString& convertedIconPath, 
                                         bool hideIcon)
{
      (void)attr;
      (void)type;
      (void)size;
      (void)startPath;
      (void)hideIcon;
    LOG("WidgetRegistrationS60::registerAppL()" << " appId : " << appId << " appTitle : " << 
            appTitle << " appPath : " << appPath << " iconPath : " << iconPath << " startPath : " << 
            startPath << " hideIcon : " << hideIcon);

    if (appId.isEmpty() || appTitle.isEmpty() || appPath.isEmpty())
        return false;

    RFs rfs;
    User::LeaveIfError(rfs.Connect());
    CleanupClosePushL(rfs); // pushed 1
    User::LeaveIfError(rfs.ShareProtected());

    SwiUI::CWidgetRegistrationS60Apparc* appArc = SwiUI::CWidgetRegistrationS60Apparc::NewL(rfs);
    CleanupStack::PushL(appArc); // pushed 2

    // Generate our UID based on UIDs in the Qt WidgetRegistry
    int iUid = WebAppRegistry::instance()->nextAvailableUid();
    widgetUid = iUid;

    if (iUid == 0) {
        LOG("WidgetRegistrationS60::registerAppL() - netAvailableUid() failed");
        CleanupStack::PopAndDestroy(2);
        return false;
    }

    // convert icon to required format and sizes
    QString newIconPath = "";
    if (!processIconL(iUid, newIconPath, iconPath, QDir::toNativeSeparators(dataPath))) {
        LOG("WidgetRegistrationS60::registerAppL() - processIconL() failed");
        CleanupStack::PopAndDestroy(2);
        return false;
    }

    // FIXME this translation doesn't cover all cases, if generalized
    // must cover S60 WRT names and W3C names
    QString appPathNative = QDir::toNativeSeparators(appPath);
    // FIXME enforce canonicalization in caller
    // must end in QDir::separator()
    if (QDir::separator() != appPathNative.at(appPathNative.count()-1)) {
        appPathNative.append(QDir::separator());
    }

    convertedIconPath = newIconPath;

    // Record the used UID in the qt registry
    WebAppRegistry::instance()->setUid(appId, iUid);

    CleanupStack::PopAndDestroy(2); // appArc, rfs

    //Notify widget altered
    NotifyW3cWidgetAltered();

    return true;
}
/*
 * TVerdict CTestMmfAclntOpenFile7902::PerformTestStepL()
 *
 */
TVerdict CTestMmfAclntOpenFile7902::PerformTestStepL()
	{
	TVerdict ret = EFail;
	iError = KErrTimedOut;

	RFs fs;
	RFile file;

	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);
	User::LeaveIfError(fs.ShareProtected());

	TPtrC			filename; 
	if(!GetStringFromConfig(iSectName, iKeyName, filename))
		{
		ret = EInconclusive;
		}

	CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
	CleanupStack::PushL(recUtil);

	User::LeaveIfError(file.Replace(fs,filename,EFileWrite));
	CleanupClosePushL(file);
	
	recUtil->OpenFileL(file);

	CActiveScheduler::Start();

	if(iError == KErrNone)
		{
		iError = KErrTimedOut;
		recUtil->RecordL();
		CActiveScheduler::Start(); // open -> record

		User::After(500000);	// 0.5 sec
		recUtil->Stop();
		}

	CleanupStack::PopAndDestroy(2, recUtil);	// file, recUtil
	recUtil = NULL;

	// Playback the file
	if (iError == KErrNone)
		{
		// Wav file playback
		CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this);
		CleanupStack::PushL(playUtil);
		TRAPD(err, playUtil->OpenFileL(filename));
		if (err != KErrNone)
			{
			INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
			ret = EFail;
			}
		CActiveScheduler::Start();
		if (iError != KErrNone)
			{
			INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
			ret = EFail;
			}

		if( iError == KErrNone )
			{
			playUtil->Play();
			CActiveScheduler::Start();
			}
		CleanupStack::PopAndDestroy(playUtil);
		if (iError != KErrNone)
			{
			INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
			ret = EFail;
			}
		}

	if( iError == KErrNone ) 
		{
		RFile file;
		TInt size = 0;
		User::LeaveIfError(file.Open(fs,filename,EFileRead));
		CleanupClosePushL(file);
		User::LeaveIfError(file.Size(size));

		if(size > 0)
			{
			ret = EPass;
			}
		CleanupStack::PopAndDestroy(); //file
		}

	CleanupStack::PopAndDestroy(&fs);	// fs

	ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
	User::After(500000);

	return	ret;
	}
void TestMessageAddingAttachmentL()
	{
	RFs fs;
	RFile attachment;
	_LIT(KAttachmentName, "c:\\t_sendas2_attachment.txt");
	_LIT8(KContent, "This is a test file. Delete me.");

	theUtils->Start(_L("Message Adding Attachment Progress"));
	CleanMailFolder(KMsvDraftEntryId);
	
	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);
	User::LeaveIfError(fs.ShareProtected());

	// Clean up any existing attachment file.
	TInt err = fs.Delete(KAttachmentName);
	if (err != KErrNotFound)
		{
		User::LeaveIfError(err);
		}

	// Create a new attachment file
	theUtils->WriteComment(_L("Create an attachment file."));
	User::LeaveIfError(attachment.Create(fs, KAttachmentName, EFileWrite));
	User::LeaveIfError(attachment.Write(KContent));

	// Create a message.
	RSendAsMessage message;
	CleanupClosePushL(message);

	theUtils->WriteComment(_L("Create a message."));
	CreateSendMessageL(message);

	theUtils->WriteComment(_L("Add the created attachment file."));
	CTestActive* testActive = new(ELeave) CTestActive;
	CleanupStack::PushL(testActive);
	message.AddAttachment(attachment, testActive->iStatus);
	attachment.Close();
	testActive->StartL();
	CActiveScheduler::Start();

	TSendAsProgress progress;
	theUtils->WriteComment(_L("Get progress on message."));
	message.ProgressL(progress);

	theUtils->WriteComment(_L("Check progress."));
	test(progress.iState == CMsvSendOperation::ESendStateInPreparation);
	test(progress.iError == KErrNone);
	test(progress.iProgressMax == 0);
	test(progress.iProgress == 0);	
	
	// Clean up existing attachment file.
	err = fs.Delete(KAttachmentName);
	if (err != KErrNotFound)
		{
		User::LeaveIfError(err);
		}

	CleanupStack::PopAndDestroy(3, &fs); // testActive, message, fs

	theUtils->Complete();
	}
예제 #20
0
TVerdict CTSISHelperStepData::doTestStepL()
	{
	SetTestStepResult(EFail);
		
	// Start the SISHelper
	TPtrC sisFileName;
	GetStringFromConfig(ConfigSection(),_L("SIS"), sisFileName);
	Swi::TSisHelperStartParams params(sisFileName);
	User::LeaveIfError(startSisHelper(params));
	Swi::RSisHelper server;
	User::LeaveIfError(server.Connect());
	server.OpenDrmContentL(ContentAccess::EExecute);

	TInt dataUnit = 0;
	GetIntFromConfig(ConfigSection(),_L("DataUnit"), dataUnit);
	TInt fileNumber = 0;
	GetIntFromConfig(ConfigSection(),_L("FileNumber"), fileNumber);
	
	// Create a file handle to pass
	RFs sharedFs;
	RFile sharedFile;
	User::LeaveIfError(sharedFs.Connect());
	User::LeaveIfError(sharedFs.ShareProtected());
	_LIT(KTempFileName,"\\tsishelper.temp");
	TDriveUnit sysDrive (RFs::GetSystemDrive());
	TBuf<64> tempFileName (sysDrive.Name());
	tempFileName.Append(KTempFileName);
	
	User::LeaveIfError(sharedFile.Replace (sharedFs, tempFileName, EFileWrite));

	TInt fakeUiHandler=0;
	Swi::RUiHandler& uiHandler=reinterpret_cast<Swi::RUiHandler&>(fakeUiHandler);
	User::LeaveIfError(server.ExtractFileL(sharedFs, sharedFile, fileNumber, dataUnit, uiHandler));
	sharedFile.Close();
	sharedFs.Close();
	
	TPtrC expectedData;
	GetStringFromConfig(ConfigSection(),_L("ExpectedData"), expectedData);
	RFile oldFile;
	User::LeaveIfError(oldFile.Open(iFs, expectedData, EFileRead));
	RFile newFile;
	User::LeaveIfError(newFile.Open(iFs, tempFileName, EFileRead));  // KErrBusy means SISHelper didn't close!
	
	TInt expectedLength(0);
	oldFile.Seek(ESeekEnd,expectedLength);
	TInt actualLength(0);
	newFile.Seek(ESeekEnd,actualLength);
	
	if (expectedLength == actualLength)
		{
		TInt pos = 0;
		oldFile.Seek(ESeekStart, pos);
		newFile.Seek(ESeekStart, pos);
		SetTestStepResult(EPass);
		for (TInt i=0; i<expectedLength; i++)
			{
			TInt8 oldChar;
			TInt8 newChar;
			TPckg<TInt8> oldPkg(oldChar);
			TPckg<TInt8> newPkg(newChar);
			oldFile.Read(oldPkg);
			newFile.Read(newPkg);
			if (oldChar != newChar)
				{
				SetTestStepResult(EFail);
				break;
				}
			}
		}	
	oldFile.Close();
	newFile.Close();
	
	RFs fs;
	User::LeaveIfError(fs.Connect());
	// Delete the temp file	
	TInt error = fs.Delete(tempFileName);
	if (error != KErrNone && error != KErrNotFound)
		{
		User::Leave(error);
		} 
	fs.Close(); 
	server.Close();
	return TestStepResult();
	}
void CSifGenericBrowserInstallStep::ImplTestStepL()
/**
* @return - TVerdict code
* Override of base class pure virtual
* Our implementation only gets called if the base class doTestStepPreambleL() did
* not leave. That being the case, the current test result value will be EPass.
*/
	{
	INFO_PRINTF1(_L("I am in CSifGenericBrowserInstallStep::ImplTestStepL()."));

	TPtrC fileName;
	if(!GetStringFromConfig(ConfigSection(),KTe_PackageFile, fileName))
		{
		INFO_PRINTF1(_L("Failed to read package file name from ini file, error: KErrNotFound"));
		User::Leave(KErrNotFound);
		}
		
	TBool installByFileHandle = EFalse;
	if(!GetBoolFromConfig(ConfigSection(),KTe_OperationByFileHandle, installByFileHandle))
		{
		INFO_PRINTF1(_L("Failed to read KTe_InstallByFileHandle from ini file, error: KErrNotFound"));
		User::Leave(KErrNotFound);
		}

	RApaLsSession apa;
	User::LeaveIfError(apa.Connect());
	CleanupClosePushL(apa);

	TRequestStatus status;
	if (installByFileHandle)
		{
		RFs fs;
		RFile file;
		User::LeaveIfError(fs.Connect());
		fs.ShareProtected();
		CleanupClosePushL(fs);
		User::LeaveIfError(file.Open(fs, fileName, EFileRead | EFileShareReadersOnly));
		CleanupClosePushL(file);

		TThreadId threadId;
		TInt err = apa.StartDocument(file, threadId, &status);
		if (err != KErrNone)
			{
			INFO_PRINTF2(_L("Failed to call RApaLsSession::StartDocument(), error code: %d"), err);
			User::Leave(err);
			}
		User::WaitForRequest(status);
		CleanupStack::PopAndDestroy(2, &fs);
		}
	else
		{
		TThreadId threadId;
		TInt err = apa.StartDocument(fileName, threadId);
		if (err != KErrNone)
			{
			INFO_PRINTF2(_L("Failed to call RApaLsSession::StartDocument(), error code: %d"), err);
			User::Leave(err);
			}

		RThread thread;
		err = thread.Open(threadId);
		if (err != KErrNone)
			{
			INFO_PRINTF2(_L("Failed to call RThread::Open(), error code: %d"), err);
			User::Leave(err);
			}

		thread.Rendezvous(status);
		User::WaitForRequest(status);
		}

	CleanupStack::PopAndDestroy(&apa);

	if (status != iExpectedResult)
		{
		INFO_PRINTF3(_L("Expected result doesn't match: current: %d expected: %d"), status.Int(), iExpectedResult);
		SetTestStepResult(EFail);
		}
	else
		{
		SetTestStepResult(EPass);
		}
	}
bool WidgetRegistrationS60::registerAppL(const QString& appId,
                                         const QString& appTitle,
                                         const QString& appPath,
                                         const QString& dataPath,
                                         const QString& iconPath,
                                         const AttributeMap& attr,
                                         const QString& type,
                                         unsigned long size,
                                         const QString& startPath,
                                         int& widgetUid,
                                         QString& convertedIconPath,
                                         bool hideIcon)
{
    LOG("WidgetRegistrationS60::registerAppL()" << " appId : " << appId << " appTitle : " << 
            appTitle << " appPath : " << appPath << " iconPath : " << iconPath << " startPath : " << 
            startPath);

    if (appId.isEmpty() || appTitle.isEmpty() || appPath.isEmpty())
        return false;

    // S60 requires widgetProps as CWidgetPropertyValue
    RPointerArray<CWidgetPropertyValue> propertyValues(EWidgetPropertyIdCount);
    CleanupStack::PushL(TCleanupItem(PointerArrayCleanup, &propertyValues)); // pushed 1

    RWidgetRegistryClientSession registryClient;
    User::LeaveIfError(registryClient.Connect());
    CleanupClosePushL( registryClient ); // pushed 2

    RFs rfs;
    User::LeaveIfError(rfs.Connect());
    CleanupClosePushL(rfs); // pushed 3
    User::LeaveIfError(rfs.ShareProtected());

    // empty values
    for (TInt i = 0; i < EWidgetPropertyIdCount; ++i) {
        CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
        CleanupStack::PushL(value); // pushed 4
        propertyValues.AppendL(value);
        CleanupStack::Pop(value); // pushed 3
    }

    *(propertyValues[EWidgetPropertyListVersion]) = KWidgetPropertyListVersion71CWRT;
    *(propertyValues[EFileSize]) = size;

    SwiUI::CWidgetRegistrationS60Apparc* appArc = SwiUI::CWidgetRegistrationS60Apparc::NewL(rfs);
    CleanupStack::PushL(appArc); // pushed 4

    // get drive letter from appPath
    TUint driveLetter = appPath[0].unicode();

    // Generate our UID based on UIDs in the Qt WidgetRegistry
    int iUid = WebAppRegistry::instance()->nextAvailableUid();
    widgetUid = iUid;

    if (iUid == 0) {
        LOG("WidgetRegistrationS60::registerAppL() - registryClient.GetAvailableUidL() failed");
        CleanupStack::PopAndDestroy( 4, &propertyValues );
        return false;
    }

    // convert icon to required format and sizes
    QString newIconPath = "";
    if (!processIconL(iUid, newIconPath, iconPath, QDir::toNativeSeparators(dataPath))) {
        LOG("WidgetRegistrationS60::registerAppL() - processIconL() failed");
        CleanupStack::PopAndDestroy( 4, &propertyValues );
        return false;
        }

    // FIXME this translation doesn't cover all cases, if generalized
    // must cover S60 WRT names and W3C names
    QString appPathNative = QDir::toNativeSeparators(appPath);
    // FIXME enforce canonicalization in caller
    // must end in QDir::separator()
    if (QDir::separator() != appPathNative.at(appPathNative.count()-1)) {
        appPathNative.append(QDir::separator());
    }
    TPtrC16 basePathSymbian(reinterpret_cast<const TUint16*>
                            (appPathNative.constData()));
    *(propertyValues[EBasePath]) = basePathSymbian;

    QString driveName = appPathNative.left(2);
    TPtrC16 driveNameSymbian(reinterpret_cast<const TUint16*>
                             (driveName.constData()));
    *(propertyValues[EDriveName]) = driveNameSymbian;

    TPtrC16 mainHtmlSymbian(reinterpret_cast<const TUint16*>
                            (startPath.constData()));
    *(propertyValues[EMainHTML]) = mainHtmlSymbian;

    TPtrC16 identifierSymbian(reinterpret_cast<const TUint16*>
                              (appId.constData()));
    *(propertyValues[EBundleIdentifier]) = identifierSymbian;

    if (attr.contains(W3CSettingsKey::WIDGET_VERSION)) {
        QString ver = attr.value(W3CSettingsKey::WIDGET_VERSION).toString();
        if(!(ver.isEmpty())) {
            TPtrC16 version(reinterpret_cast<const TUint16*>
                            (attr.value(W3CSettingsKey::WIDGET_VERSION).toString().constData()));
            *(propertyValues[EBundleVersion]) = version;
        }
    }

    if (appTitle.isEmpty()) {
        // FIXME this probably should cause registration failure
        *(propertyValues[EBundleDisplayName]) = identifierSymbian;
    } else {
        TPtrC16 titleSymbian(reinterpret_cast<const TUint16*>
                             (appTitle.constData()));
        *(propertyValues[EBundleDisplayName]) = titleSymbian;
    }

    // TODO: We decided to drop BundleName and just use
    // DisplayName but the registry code has errors in it and uses
    // BundleName when it should use DisplayName so as a workaround,
    // set BundleName to DisplayName.  Should eventually remove
    // BundleName from set of registry values.
    const TDesC& name = *(propertyValues[EBundleDisplayName]);
    *(propertyValues[EBundleName]) = name;

    convertedIconPath = newIconPath;

    if (!newIconPath.isEmpty()) {
        // FIXME enforce canonicalization in caller
        // strangely icon path doesn't include icon file name
        int li = newIconPath.lastIndexOf(QDir::separator());
        if (li > 0) {
            newIconPath = newIconPath.left(li+1);
            TPtrC16 iconPathSymbian(reinterpret_cast<const TUint16*>
                                    (newIconPath.constData()));
            *(propertyValues[EIconPath]) = iconPathSymbian;
        }
    }

    *(propertyValues[EUid]) = iUid;

    *(propertyValues[EMiniViewEnable]) = 0;
    if (attr.contains(W3CSettingsKey::WIDGET_VIEWMODES)) {
        QStringList viewModeList = attr.value(W3CSettingsKey::WIDGET_VIEWMODES).toString().split(" ");
        foreach (const QString &str, viewModeList) {
            if (str.contains("minimized", Qt::CaseInsensitive)) {
                *(propertyValues[EMiniViewEnable]) = 1;
                break;
            }
        }
    }
void TestAddAttachmentCancelL(TAttachmentTestType aTest)
	{
	RFs fs;
	RFile existingAttachment;

	CleanMailFolder(KMsvDraftEntryId);
	
	CleanupClosePushL(fs);
	CleanupClosePushL(existingAttachment);
	
	User::LeaveIfError(fs.Connect());
	User::LeaveIfError(fs.ShareProtected());
	// Clean up any existing attachment file.
	TInt err = fs.Delete(KExistingAttachmentName);
	if (err != KErrNotFound)
		{
		User::LeaveIfError(err);
		}

	// Create a new attachment file
	User::LeaveIfError(existingAttachment.Create(fs, KExistingAttachmentName, EFileWrite));
	User::LeaveIfError(existingAttachment.Write(KAttachmentContent));

	// Create a message.
	RSendAsMessage message;
	
	CleanupClosePushL(message);
	message.CreateL(gSendAs, sendAsTestMtmUid);

	CTestActive* testActive = new(ELeave) CTestActive;
	CleanupStack::PushL(testActive);

	switch (aTest)
		{
		case EByName:
			{
			theUtils->Start(_L("Cancel Message Add Attachment By Name"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddAttachment(KExistingAttachmentName, testActive->iStatus);
			break;
			}
		case EByNameWithMimeType:
			{
			theUtils->Start(_L("Cancel Message Add Attachment By Name With Mime Type"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddAttachment(KExistingAttachmentName, KMimeType, testActive->iStatus);
			break;
			}
		case EByFile:
			{
			theUtils->Start(_L("Cancel Message Add Attachment By File"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddAttachment(existingAttachment, testActive->iStatus);
			break;
			}

		case EByFileWithMimeType:
			{
			theUtils->Start(_L("Cancel Message Add Attachment By File With Mime Type"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddAttachment(existingAttachment, KMimeType, testActive->iStatus);
			break;
			}
		case ELinked:
			{
			theUtils->Start(_L("Cancel Message Add Linked Attachment"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddLinkedAttachment(KExistingAttachmentName, testActive->iStatus);
			break;
			}
		case ELinkedWithMimeType:
			{
			theUtils->Start(_L("Cancel Message Add Linked Attachment With Mime Type"));
			theUtils->WriteComment(_L("Add the created attachment file."));
			message.AddLinkedAttachment(KExistingAttachmentName, KMimeType, testActive->iStatus);
			break;
			}
		}
	testActive->StartL();
	
	CTestCancelMessageActive* cancelActive = new(ELeave) CTestCancelMessageActive(message);
	CleanupStack::PushL(cancelActive);
	cancelActive->StartL();

	CActiveScheduler::Start();

	theUtils->WriteComment(_L("Check message has no attachments."));
	CheckNoAttachmentsL();

	CleanupStack::PopAndDestroy(5, &fs); // cancelActive, testActive, message, existingAttachment fs
	theUtils->Complete();
	}
예제 #24
0
QTM_BEGIN_NAMESPACE

static QString qservicemanager_resolveLibraryPath(const QString &libNameOrPath)
{
    if (QFile::exists(libNameOrPath))
        return libNameOrPath;

    QStringList paths = QCoreApplication::libraryPaths();

#ifdef Q_OS_SYMBIAN
    // try to find plug-in via QLibrary
    // Work around for QCoreApplication::libraryPaths() caching
    // paths from application startup.  On Symbian the paths can be
    // created during the lifetime of the application.
    QString pluginpaths = QLibraryInfo::location(QLibraryInfo::PluginsPath);

    // Add existing path on all drives for relative PluginsPath in Symbian
    if (pluginpaths.at(1) != QChar(QLatin1Char(':'))) {
        QString tempPath = pluginpaths;
        if (tempPath.at(tempPath.length() - 1) != QDir::separator()) {
            tempPath += QDir::separator();
        }
        RFs iFs;
        iFs.Connect();
        iFs.ShareProtected();
        TPtrC tempPathPtr(reinterpret_cast<const TText*> (tempPath.constData()));
        TFindFile finder(iFs);
        TInt err = finder.FindByDir(tempPathPtr, tempPathPtr);
        while (err == KErrNone) {
            QString foundDir(reinterpret_cast<const QChar *>(finder.File().Ptr()),
                             finder.File().Length());
            foundDir = QDir(foundDir).canonicalPath();
            if (!paths.contains(foundDir)) {
                paths << foundDir;
            }
            err = finder.Find();
        }
        iFs.Close();
    }
#endif

#ifdef QTM_PLUGIN_PATH
    paths << QLatin1String(QTM_PLUGIN_PATH)+QLatin1String("/serviceframework");
#endif
    foreach (QString path, paths) {
        QString libPath = QDir::toNativeSeparators(path) + QDir::separator() + libNameOrPath;

#ifdef Q_OS_SYMBIAN
        QFileInfo fi(libPath);
        if (fi.suffix() == QLatin1String("dll"))
            libPath = fi.completeBaseName() + QLatin1String(".qtplugin");
        else
            libPath += QLatin1String(".qtplugin");

        QLibrary lib(libPath);
        if (QFile::exists(libPath) && lib.load()) {
            lib.unload();
            return libPath;
        }
#else
        QLibrary lib(libPath);
        if (lib.load()) {
            lib.unload();
            return lib.fileName();
        }
#endif
    }
/**
 * Load and initialise an audio file.
 */
TVerdict CTestMmfAclntFileHandleSource::DoTestStepL( void )
	{
	INFO_PRINTF1( _L("TestPlayerUtils : File"));
	TVerdict ret = EFail;

	iError = KErrTimedOut;
	
	// Get the file name.
	TBuf<KSizeBuf> filename;
	TPtrC filename1;
	if(!GetStringFromConfig(iSectName,iKeyName,filename1))
		{
		return EInconclusive;
		}
	GetDriveName(filename);
	filename.Append(filename1);
	
	// Create CMdaAudioPlayerUtility Object
	CMdaAudioPlayerUtility* player = NULL;
	player = CMdaAudioPlayerUtility::NewL(*this);
	
	// Create RFs and RFile Objects
	RFs fs;
	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);
	User::LeaveIfError(fs.ShareProtected());
	
	RFile file;
	User::LeaveIfError( file.Open( fs, filename, EFileRead ) );
	CleanupClosePushL(file);
	
	// Create TMMFileSource Object
	TMMFileHandleSource filehandlesource(file);
	player->OpenFileL(filehandlesource);
	
	// Wait for initialisation callback
	INFO_PRINTF1(_L("CMdaAudioPlayerUtility->OpenFileL(TMMFileHandleSource)"));
	CActiveScheduler::Start();
	
	// Check for expected errors.
	if((iError != KErrNone) && (iExpectedError == iError))
		{
		ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Returned the Expected Error : %d"),iError);
		ret=EPass;
		}
	
	// Check for errors.
	if(iError != KErrNone)
		{
		ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Failed with Error : %d"),iError);
		ret=EFail;
		}
	
	// Check for No errors, so as to start Playback
	if (iError == KErrNone && player != NULL)
		{
		if(iPlay)
			{
			iError = KErrTimedOut;
			player->Play();
			
			// Wait for play complete callback
			INFO_PRINTF1(_L("CMdaAudioPlayerUtility->Play()"));
			CActiveScheduler::Start();
			
			// Check for Callback errors
			if(iError == KErrNone)
				{
				ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() completed successfully with return code : %d"),iError);
				ret = EPass;
				}
			else
				{
				ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() Failed with Error : %d"),iError );
				ret = EFail;
				}
			}
		else
			{
			ret = EPass;
			}
		}
	
	// Clean up activities.
	delete player;
	User::After(KOneSecond); // wait for deletion to shut down devsound
	CleanupStack::PopAndDestroy(2);

	return	ret;
	}