Esempio n. 1
0
void VersitImportContactL(const TDesC& aImportFileName)
{
    RFileReadStream readStream;
		
	//Import aImportFileName
	User::LeaveIfError(readStream.Open(fsSession, aImportFileName, EFileRead));
	CleanupClosePushL(readStream);
	
	TBool success=EFalse;
	CArrayPtr<CContactItem>* contactItems=CntTest->Db()->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl),
	                                                                     readStream, success,
	                                                                     CContactDatabase::EImportSingleContact+CContactDatabase::ETTFormat);
	                                                                     
	                                                                     
    //Should be the only contact in the database at this point
	TInt count = CntTest->Db()->CountL();
	test(count == 1);
	
	//Store the id of the new contact - we need this later
	TContactItemId contactId = (*contactItems)[0]->Id();
	CntTest->Db()->SetCurrentItem(contactId);
	
	readStream.Close();                                                                
	CleanupStack::PopAndDestroy(); //readStream.Close()
    contactItems->ResetAndDestroy();
    delete contactItems;
	
}
Esempio n. 2
0
void CheckAndInitializeFileL( RFs& aFs, TBuf<KMaxFileName>& aFile, const TDesC16& aFilePath,
                                            RFileReadStream& aTempFile, CFileMan* aFileMan )
    {
    __LOG1( ELogAlways, "CheckAndInitializeFileL() - handling file %S", &aFilePath );
    const TInt err = aTempFile.Open( aFs, aFile, EFileRead | EFileShareAny );
    __LOG1( ELogAlways, "CheckAndInitializeFileL() - open file error %d", err );
    aTempFile.Close();
    if ( err != KErrNone )
        {
        if ( err == KErrNotFound )
            {
            // Path found but not schema.mde, copy schema.m
            const TInt error = aFileMan->Copy( aFilePath, aFile, CFileMan::EOverWrite );
            __LOG1( ELogAlways, "CheckAndInitializeFileL() - copy file error %d", error );
            }
        else if ( err == KErrPathNotFound)
            {
            // Create private dir
            User::LeaveIfError( aFs.CreatePrivatePath( EDriveC ) );
            
            // Copy schema.mde
            const TInt error = aFileMan->Copy( aFilePath, aFile, CFileMan::EOverWrite );
            __LOG1( ELogAlways, "CheckAndInitializeFileL() - copy file error %d", error );
            }    
        }    
    }
/**
@SYMTestCaseID			SYSLIB-SQL-CT-1635
@SYMTestCaseDesc		RSqlSecurityPolicy test.
						Tests RSqlSecurityPolicy API.
@SYMTestPriority		High
@SYMTestActions			RSqlSecurityPolicy test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ5792
                        REQ5793
*/
void SqlSecurityPolicyTest()
{
    RSqlSecurityPolicy securityPolicy;
    TInt err = securityPolicy.Create(KDefaultPolicy);
    TEST2(err, KErrNone);

    //Empty RSqlSecurityPolicy object tests
    //Database policies
    TSecurityPolicy policy = securityPolicy.DbPolicy(RSqlSecurityPolicy::ESchemaPolicy);
    TEST(policy == KDefaultPolicy);
    policy = securityPolicy.DbPolicy(RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KDefaultPolicy);
    policy = securityPolicy.DbPolicy(RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KDefaultPolicy);
    //Table policies
    policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, _L("A-Tbl"), RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KDefaultPolicy);
    policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, _L("B-Tbl"), RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KDefaultPolicy);
    //
    securityPolicy.Close();

    //Tests with initialized RSqlSecurityPolicy object
    CreateTestSecurityPolicy(securityPolicy);
    //Check the created and initialized object
    CheckTestSecurityPolicy(securityPolicy);

    //Externalize, then internalize and check the security policy object
    RFileWriteStream out;
    err = out.Replace(TheFs, KTestFile, EFileRead | EFileWrite);
    TEST2(err, KErrNone);
    TRAP(err, securityPolicy.ExternalizeL(out));
    TEST2(err, KErrNone);
    TRAP(err, out.CommitL());
    out.Close();
    TEST2(err, KErrNone);

    securityPolicy.Close();
    err = securityPolicy.Create(KDefaultPolicy);
    TEST2(err, KErrNone);
    RFileReadStream in;
    err = in.Open(TheFs, KTestFile, EFileRead);
    TEST2(err, KErrNone);
    TRAP(err, securityPolicy.InternalizeL(in));
    in.Close();
    TEST2(err, KErrNone);
    CheckTestSecurityPolicy(securityPolicy);

    //Change some security policies and check that the RqlSecurityPolicy content was properly updated
    err = securityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName11, RSqlSecurityPolicy::EReadPolicy, KPolicy3);
    TEST2(err, KErrNone);
    policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName1, RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KPolicy3);
    policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName11, RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KPolicy2);
    //
    securityPolicy.Close();
}
/**
 Overload of the CCoeAppUi virtual method.
 The method in the base class merely returns ETrue. Overloads would normally just return EFalse.
 In this case however, we do some jiggery-pokery in order to invoke the StartSafe retry mechanism.
 ie we return EFalse on each of several invocations but don't do the Rendezvous, then 
 eventually ETrue, so the Framework Rendezvous for us. our final invocation therefore being successful.
 
 The count file is written from the test-step, and 
 if successful, deleted here.
 
 The code is nearly all parenthesised within a TRAP harness in order to preserve the integrity 
 of this function, which is called by the framework.

*/
TBool CTestAppUi::FrameworkCallsRendezvous() const
	{
	
	TBool frameworkRendezvous = EFalse;

	TRAPD( err,
		{			
		RFs fs;
		RFileReadStream readStream;
		RFileWriteStream writeStream;
						
		CleanupClosePushL( fs );
		CleanupClosePushL( readStream );
		CleanupClosePushL( writeStream );
		
			
		if( KErrNone != fs.Connect()
		 || KErrNone != readStream.Open(fs, KDontRvCountFile, EFileRead) )
			{
			User::Leave( KErrCouldNotConnect );	
			}
		

		TInt failCount = readStream.ReadInt8L();
		readStream.Close();	
		

		if( 0 == failCount )
			{
			fs.Delete( KDontRvCountFile );
			
			// We've decided to be good this time. Let the framework do it for us.
			frameworkRendezvous = ETrue;
			}
		else
			{
			// StartSafe will timeout while waiting for a Rendezvous()
			User::LeaveIfError( writeStream.Open(fs, KDontRvCountFile, EFileWrite) );
	
			writeStream.WriteInt8L( --failCount );
			writeStream.CommitL();
			writeStream.Close();
			}
			
		CleanupStack::PopAndDestroy( 3, &fs );
		} );
void CJavaDebugAgentSettings::LoadL(const TDesC& aPrefsFile)
{
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);

    RFileReadStream in;
    in.PushL();
    User::LeaveIfError(in.Open(fs, aPrefsFile, EFileRead));
    TRAPD(err, LoadL(&in));
    in.Close();
    in.Pop();

    if (err != KErrNone) {
        err = fs.Delete(aPrefsFile);
    }
    CleanupStack::PopAndDestroy(&fs);
}
/**
 Start a test application synchronously using Wait-for-Signal with timeout
 more than the time required for the application to start and which starts after the no. of retries given.
*/
void CSsTestStepAppTimeout::DoTestWaitForSignalWithMoreTimeOutAndWithRetriesL()
	{	
	INFO_PRINTF1(_L("Performing Wait-for-Signal test with timeout and retries"));

	// Write the retry number to a file to be read, updated 
	// and eventually deleted by the test-app.
	RFs fs;	
	CleanupClosePushL( fs );
	
	RFileWriteStream writeStream;
	CleanupClosePushL( writeStream );

	User::LeaveIfError(fs.Connect());
	User::LeaveIfError(writeStream.Replace(fs, KFileForFAndF, EFileWrite));

	const TInt KSsTestRequiredDelay = 0;
	const TInt KSsTestFailCount = 1;
	const TInt KSsTestRetryCount = 0;
	writeStream.WriteInt8L(KSsTestRetryCount);
	writeStream.WriteInt8L(KSsTestFailCount);
	writeStream.WriteInt8L(KSsTestRequiredDelay);
	writeStream.CommitL();
	writeStream.Close();
	
	const TInt KRetries = KSsTestFailCount + 1;
	TInt completionCode = DoTestAndStopperL(KRetries, KWaitTimeForTestAppForFAndF * 3, KTestAppForFAndF);
	TEST(completionCode == 0);
	
	INFO_PRINTF2( _L("Anticipated completion code 0. Supplied completion code %d"),completionCode);
	RFileReadStream readStream;
	CleanupClosePushL(readStream);

	User::LeaveIfError(readStream.Open(fs, KFileForFAndF, EFileRead));
	TInt retryCount = readStream.ReadInt8L();
	readStream.Close();	
	fs.Delete(KFileForFAndF);

	CleanupStack::PopAndDestroy(3, &fs);

	TEST(1 == FindAndKill(KTestAppForFAndF));
	TEST(retryCount == 1);

	INFO_PRINTF3( _L("ssmtestappsucessfulafterretry.exe is started after %d retries. anticipated retries value %d"),retryCount, 1);
	}
// ----------------------------------------------------------------------------
// CAudioStreamEngine::LoadAudioFileL()
//
// loads the audio data from a file into the buffer
// ----------------------------------------------------------------------------
void CAudioStreamEngine::LoadAudioFileL()
    {
    RFileReadStream audiofile;

    // open file
    TFileName fileName;
    fileName.Copy(iAudioFilePath);
    fileName.Append(iAudioFile);

    TInt err = audiofile.Open(iFs, fileName, EFileRead|EFileStream);
    iStreamBuffer->Des().FillZ(iFrameCount * iFrameSize);  // Empty the stream buffer
    if (err==KErrNone) 
        {
        // file opened ok, proceed reading
        if (iUseAMR)
            {
            // Read the AMR header (the first 6 bytes). We don't need to save/use the header,
            // since while playback we already know it's an AMR-NB encoded stream.
            TBuf8<KAMRHeaderLength> temp;
            audiofile.ReadL(temp, KAMRHeaderLength);
            }

        TUint idx=0;
        while (idx < iFrameCount)
            {
            TRAPD(fstatus, audiofile.ReadL(GetFrame(idx), iFrameSize));
            if (fstatus!=KErrNone)
                break;
            idx++;
            }
        iStreamStart=0;
        iStreamEnd=idx-1;
        ShowMessage(_L("CAudioStreamEngine::LoadAudioFileL() Loading complete!"), ETrue);
        iBufferOK = ETrue;  
        }   
    else 
        {
        // failed to open file
        ShowMessage(_L("CAudioStreamEngine::LoadAudioFileL() Error loading audio sample!"), ETrue); 
        iBufferOK = EFalse;
        }
    audiofile.Close();
    }
Esempio n. 8
0
void TTcSettings::Load()
	{
	// Connect to file server
	RFs fs;
	if( fs.Connect() )
		{
		return;
		}

	// Open the settings file for reading, it might not exist yet
	RFileReadStream in;
	if( !in.Open( fs, KTcSettingsFile, EFileRead ) )
		{
		// Load actual data, ignore errors (the file might be of a previous
		// version and/or some items might be missing).
		TRAP_IGNORE( doLoadL( in ) )
		}

	in.Close();
	fs.Close();
	}
EXPORT_C void LoadIcons(CArrayPtrFlat<CGulIcon> * aIconList, const TIconID* aIconDefs, 
			TInt aNbIcons, TInt aScale)
{
	CALLSTACKITEM_N(_CL(""), _CL("LoadIcons"));

	TFileName real; TFileName prev;
	CEikonEnv* env=CEikonEnv::Static();
	RFs& fs=env->FsSession();
	CWsScreenDevice* screen=env->ScreenDevice();
	RWsSession& ws=env->WsSession();
	RArray<TInt> Offsets; RFile File; bool file_is_open=false;
	CleanupClosePushL(Offsets);
	RFileReadStream s;
	int j=0;

	bool romfile=false;
	for (int i = 0; i<aNbIcons;i++)
	{
		TPtrC file((TText16*)aIconDefs[i].iMbmFile);
#ifdef __S60V3__
		if (file.FindF(_L("avkon"))==KErrNotFound) {
#endif
			
		if (prev.Compare(file)) {
#ifndef __S60V3__
			real=file;
#else
			TParse p; p.Set(file, 0, 0);
			real=_L("c:\\resource\\");
			real.Append(p.NameAndExt());				
				
#endif

#ifdef __WINS__
			real.Replace(0, 1, _L("z"));
#else
			if (! BaflUtils::FileExists(fs, real)) {
				real.Replace(0, 1, _L("e"));
			}
#endif
			prev=file;
			if (file_is_open) {
				s.Close();
				file_is_open=false;
			}
			if (real.Left(1).CompareF(_L("z"))==0) {
				romfile=true;
			} else {
				romfile=false;
				GetIconInfo(real, fs, File, s, Offsets, j);
				file_is_open=true;
			}
			++j;
		}

		auto_ptr<CWsBitmap> bitmap(new (ELeave) CWsBitmap(ws));
		if (!romfile) {
			RFile f1=File;
			s.Attach(f1, Offsets[aIconDefs[i].iBitmap]);	
			bitmap->InternalizeL(s);
		} else {
			TInt err=bitmap->Load(real, aIconDefs[i].iBitmap);
			if (err!=KErrNone) 
				User::Leave(err);
		}
		bitmap->SetSizeInTwips(screen);
#ifdef __S60V2__
		if (aScale>1) {
			auto_ptr<CWsBitmap> scaled(new (ELeave) CWsBitmap(ws));
			ScaleFbsBitmapL(bitmap.get(), scaled.get(), aScale);
			bitmap=scaled;
		}
#endif
		
		auto_ptr<CWsBitmap> mask(NULL);
		if ( aIconDefs[i].iMask != KErrNotFound )
			{
				mask.reset(new (ELeave) CWsBitmap(ws));
				if (!romfile) {
					RFile f2=File;
					s.Attach(f2, Offsets[aIconDefs[i].iMask]);
					mask->InternalizeL(s);
				} else {
					User::LeaveIfError(mask->Load(real, aIconDefs[i].iMask));
				}
				mask->SetSizeInTwips(screen);
#ifdef __S60V2__
				if (aScale>1) {
					auto_ptr<CWsBitmap> scaled(new (ELeave) CWsBitmap(ws));
					ScaleFbsBitmapL(mask.get(), scaled.get(), aScale);
					mask=scaled;
				}
#endif
			}

		auto_ptr<CGulIcon> icon(CGulIcon::NewL(bitmap.get(), mask.get()));
		bitmap.release(); mask.release();
		aIconList->AppendL(icon.get()); icon.release();
#ifdef __S60V3__
		} else {
			auto_ptr<CFbsBitmap> bitmap(0);
			auto_ptr<CFbsBitmap> mask(0);
			if ( aIconDefs[i].iMask != KErrNotFound ) {
				CFbsBitmap *bitmapp=0, *maskp=0;
				AknIconUtils::CreateIconL(bitmapp, maskp, AknIconUtils::AvkonIconFileName(), aIconDefs[i].iBitmap, aIconDefs[i].iMask);
				bitmap.reset(bitmapp);
				mask.reset(maskp);
			} else {
				bitmap.reset(AknIconUtils::CreateIconL(AknIconUtils::AvkonIconFileName(), aIconDefs[i].iBitmap));
			}
			bitmap->SetSizeInTwips(screen);
			if (mask.get()) mask->SetSizeInTwips(screen);
			auto_ptr<CGulIcon> icon(CGulIcon::NewL(bitmap.get(), mask.get()));
			bitmap.release(); mask.release();
			aIconList->AppendL(icon.get()); icon.release();
		}
#endif
	}
	if (file_is_open) {
		s.Close();
	}
	CleanupStack::PopAndDestroy(); // Offsets
}
EXPORT_C TInt CSenLogger::CreateL(TInt aChannel, TInt aLevel, const TDesC& aLogDir, const TDesC& aLogFileName, TFileLoggingMode aMode)
    {
    TInt index(KErrNotFound);
    CSenLogger* pSenLogger = NULL;
    TWsTls* tls = (TWsTls*)Dll::Tls();
    if( !tls )
        {
        tls = new (ELeave) TWsTls();
        tls->iLogger = NULL;
        tls->iProxy = NULL;
        Dll::SetTls( tls );
        }
    pSenLogger = tls->iLogger;    
	if ( !pSenLogger )
  		{
  		pSenLogger = new (ELeave) CSenLogger();
        if ( pSenLogger )
            {
            tls->iLogger = pSenLogger;
      		pSenLogger->iCount = 0;
      		//reading the configuration file for the logging levels!!!
      		
      		/*the file has the  following format (IN ANSI)
      		* ==============================================================================
      		  * LogChannel LogLevel
      		    1000 0
      		    2000 1
      		      .
      		      .
      		      .
      		      .
      		      .
      		      ....
      		    18000 2
      		   this means first you need to write the channel followed by the corresponding logging level after a space
      		 
      		 the file has to be located under C:\Config.txt
      		 * ==============================================================================*/
      		 
      
      		TInt res;
      	    RFs fs;
      	    res=fs.Connect();
      	      if(res==KErrNone)
			{
			RFileReadStream readStream;
	      	res=readStream.Open(fs, KPath, EFileRead|EFileStreamText);
			if(res == KErrNone)
				{
				TInt error;
				TInt retVal;
				do
					{
					TBuf8<128> readLineBuf;
					TRAP(error, readStream.ReadL(readLineBuf, (TChar)'\n'));
					if(error == KErrNone)
						{      
						TInt32 length(0);
						length = readLineBuf.Length() ;
						TInt *key = new (ELeave) TInt;
						TLex8 lexBuf(readLineBuf);
						retVal = lexBuf.Val(*key);

						if(retVal!=0)
							{
							delete key;
							continue;
							}
						else
							{
							TInt *value = new (ELeave) TInt;
							lexBuf.SkipSpace();
							retVal=lexBuf.Val(*value);
							if(retVal==0)
								{
								retVal = pSenLogger->iMap.Append(key,value);
								if(retVal != KErrNone)
									{
									delete key;
									delete value;
									}
								}
							else
								{
								delete key;
								delete value;
								}
							}
						}
					}while(error == KErrNone);
				readStream.Close();
				}
			fs.Close();
			}
            }
        else
            {
            return KErrGeneral;
            }
  		}
  	else
  	    {
  	    index = pSenLogger->ChannelIndex(aChannel);
  	    }	
  	
  	if (index == KErrNotFound)
  	    {
  	    TInt channelIndex;
        TLog* pTLog = new (ELeave) TLog;
        CleanupStack::PushL(pTLog);
        pTLog->iChannel=aChannel;
        channelIndex=pSenLogger->iMap.Find(aChannel);
        if(channelIndex==KErrNotFound)
        {
        pTLog->iLevel=aLevel;
        }
        else
        {
        pTLog->iLevel=*(pSenLogger->iMap.ValueAt(channelIndex));
        }
        pTLog->iCount=1;
        pTLog->iLog.Connect();
        pTLog->iLog.CreateLog(aLogDir, aLogFileName, aMode);
        pTLog->iLog.Write(_L("SenTLSLogger - Log file opened"));
#ifdef EKA
        pSenLogger->iLogs.AppendL(pTLog);
#else
        User::LeaveIfError(pSenLogger->iLogs.Append(pTLog));
	  
#endif
        CleanupStack::Pop(pTLog);
  	    }
  	else
  	    {
  	    pSenLogger->iLogs[index]->iCount++;
  	    }
  	pSenLogger->iCount++;
    
    return KErrNone;
    }
// ---------------------------------------------------------------------------
// CLbtCleanupHandler::ReadCleanupDataFromFileL
// ---------------------------------------------------------------------------
//
void CLbtCleanupHandler::ReadCleanupDataFromFileL()
	{
	FUNC_ENTER("CLbtCleanupHandler::ReadCleanupDataFromFileL");
	
	// First reset the cleanup data 
	iCleanupItems.ResetAndDestroy();
	
	// Open handle to file system
	RFs fs;
	User::LeaveIfError(fs.Connect());
	
	CleanupClosePushL(fs);
	
	// Obtain the file path
    TFileName file;
    
    // Gets the path in which the file can be created
    fs.SessionPath(file);

    // Create the file Directory ie the private directory of the process
    fs.MkDirAll(file);
    
    // Append the name of the file
    file.Append(KLbtAppCleanupFileName);
    
    // Open read stream
    RFileReadStream readStream;
    
    TInt error = readStream.Open( fs, file, EFileRead );
    if( error != KErrNone )
    	{
    	// File may not exists
    	ERROR("Opening of cleanup file failed with : %d", error);
    	readStream.Close();
    	CleanupStack::PopAndDestroy(); //fs
    	return;
    	}
    CleanupClosePushL( readStream );
    
    // Get the count in the cleanup array
    TInt count = readStream.ReadInt16L();    
    for(TInt i=0; i<count; ++i)
    	{
    	RArray<TLbtTriggerId> triggers;
    	CleanupClosePushL(triggers);
    	
    	// Read the trigger ids
    	TInt triggerCount = readStream.ReadInt16L();
    	for(TInt j=0;j<triggerCount;++j)
    		{
    		triggers.Append( readStream.ReadUint32L() );
    		}
    	
    	// Read the universal time
    	TInt year = readStream.ReadInt32L();
    	TMonth month = static_cast<TMonth>( readStream.ReadInt32L() );
    	TInt day = readStream.ReadInt32L();
    	
    	TDateTime dateTime( year,
    						month,
    						day,
    						0,
    						0,
    						0,
    						0 );
    	TTime time( dateTime );
    	
    	CLbtCleanupItem* cleanupItem = new (ELeave) CLbtCleanupItem();
    	cleanupItem->AddCleanupItem( triggers, time );
    	
    	CleanupStack::Pop(); // triggers
    	triggers.Close();
    	
    	// Append cleanup item to the cleaup items array
    	iCleanupItems.Append( cleanupItem );
    	}

    CleanupStack::PopAndDestroy(2); // fs and readStream
	}