Esempio n. 1
0
void CRecogStep::ConvertFileToPrivateL()
	{
	// Read source file
	RFile fromFile;	
	User::LeaveIfError(fromFile.Open(iTheFs, iFileName, EFileShareReadersOrWriters | EFileRead | EFileStream));
	CleanupClosePushL(fromFile);
	TInt size;
	User::LeaveIfError(fromFile.Size(size));
	HBufC8* memForFileContents = HBufC8::NewLC(size);
	TPtr8 fileContents(memForFileContents->Des());		
	User::LeaveIfError(fromFile.Read(fileContents, size));
	
	// Create destination path
	TDriveUnit sysDrive = RFs::GetSystemDrive();
	(void)iTheFs.CreatePrivatePath(static_cast<TInt> (sysDrive));
	TFileName newFileName;
	User::LeaveIfError(iTheFs.PrivatePath(newFileName));
	newFileName.Insert(0, sysDrive.Name());
	TParsePtr parseFrom(iFileName);
	newFileName.Append(parseFrom.NameAndExt());

	// Make sure destination does not already exist.
	(void) iTheFs.Delete(newFileName);

	// Copy file to private location
	RFile toFile;
	User::LeaveIfError(toFile.Create(iTheFs, newFileName, EFileShareExclusive | EFileWrite | EFileStream));
	CleanupClosePushL(toFile);

	User::LeaveIfError(toFile.Write(fileContents));

	// Update iFileName
	iFileName = newFileName;
	
	// Cleanup
	CleanupStack::PopAndDestroy(&toFile);
	CleanupStack::PopAndDestroy(memForFileContents);
	CleanupStack::PopAndDestroy(&fromFile);
	}
/**
* Method used to generate a file name for trace.
* If a trace file exist an index number i counted
* one step until a trace file can be created.
* Maximun number of exe client are currently hard
* coded to 10;
*/
TBuf<40> GenerateFileNameForTraceL()
{
    _LIT(KFileTrace, "c:\\logs\\execlientresult%d.txt");
    RFs fileserver;
    RFile file;
    User::LeaveIfError(fileserver.Connect());
    TBuf<40> ff;
    ff.Append(KFileTrace);

    for (TInt i = 1; i<10; i++)
    {
        ff.Format(KFileTrace,i);
        TInt err = file.Open(fileserver,ff, EFileWrite);
        if (err == KErrNotFound)
        {
            User::LeaveIfError(file.Create(fileserver,ff, EFileWrite));
            break;
        }
    }
    file.Close();
    fileserver.Close();
    return ff;
}
Esempio n. 3
0
// ----------------------------------------------------------------------------
// test the volume setting page creation api.
// ----------------------------------------------------------------------------
//
void CBCTestAknDoc::TestL()
    {
	CBCTestAppFrmApp* app = new CBCTestAppFrmApp();
	CleanupStack::PushL(app);
	CMockDocument* ptr = new (ELeave) CMockDocument(*app);
	delete ptr;
	CleanupStack::Pop();	//app;
	delete app;

    //CEikDocument subclass #CAknDocument,
    CEikDocument* doc = CEikonEnv::Static()->EikAppUi()->Document();    // doc pointer to CBCTestAppFrmDocument(which is infact a CAknDocument)

    RFs& fs = CEikonEnv::Static()->FsSession();
    _LIT(KFileName, "C:\\BCTestLog\\foo.txt");
    CFileStore* store = doc->OpenFileL(EFalse, KFileName, fs);
    //AssertNotNullL(store, _L("CFileStore* CAknDocument::OpenFileL() invoked with EFalse."));
    AssertTrueL(ETrue, _L("CAknDocument::OpenFileL() is empty in S60."));
    delete store;

    store = NULL;
    store = doc->OpenFileL(ETrue, KFileName, fs);
    //AssertNotNullL(store, _L("CFileStore* CAknDocument::OpenFileL() invoked with ETrue."));
    AssertTrueL(ETrue, _L("CAknDocument::OpenFileL() is empty in S60."));
    delete store;
    
    store = NULL;
    RFile file;
    if ( file.Open( fs, KFileName, EFileWrite | EFileShareAny ) != KErrNone ){
        file.Create( fs, KFileName, EFileWrite | EFileShareAny );
    }

    doc->OpenFileL(store, file);
    //AssertNotNullL(store, _L("void CAknDocument::OpenFileL() invoked."));
    AssertTrueL(ETrue, _L("CAknDocument::OpenFileL() is empty in S60."));
    delete store;
    file.Close();
    }
Esempio n. 4
0
/** Delete entry in directory

*/
LOCAL_C TInt DeleteEntryAccess2(TAny* )
	{
	RFs fs;
	TInt r = fs.Connect();
	TBuf<100> dirfile;
	TBuf<50> filename;
	RFile file;
	RTest test(_L("test 2")); 

	fs.SetSessionPath(gSessionPath);
	filename.Format(KDeleteMe2, gT2);
	
	dirfile = gDelEntryDir2;
	dirfile.Append(filename);
	
	client.Signal();
	
	FOREVER
		{
			if(!gKillMe)
				{
				r = file.Create(fs, dirfile, EFileShareAny|EFileWrite);
				if(r == KErrAlreadyExists) 
					r=file.Open(fs, dirfile, EFileShareAny|EFileWrite);
				file.Close();
				FailIfError(r);
				
				r = fs.Delete(dirfile);
				if((r != KErrNone) && (r != KErrInUse)) 
					{
					test.Printf(_L("error = %d\n"), r);
					}
				test(r == KErrNone || r == KErrInUse);
			}
		}
	}
Esempio n. 5
0
LOCAL_C void systemRFiletest()
//
//
//
	{
	r=TheFs.SetSessionPath(systestname);
	test_Value(r, r == KErrPermissionDenied);

	r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
	test_Value(r, r == KErrPermissionDenied);


	TBuf<25> sysfilename;
	sysfilename.Append(systestname);
	sysfilename.Append(KFileSys);

	r=file1.Create(TheFs,sysfilename,EFileWrite);
	test_Value(r, r == KErrPermissionDenied);

	r=file1.Open(TheFs,sysfilename,EFileWrite);
	test_Value(r, r == KErrPermissionDenied);
	
	r=file1.Open(TheFs,sysfilename,EFileRead);
	test_Value(r, r == KErrPermissionDenied);
	
	r=file1.Replace(TheFs,sysfilename,EFileWrite);
	test_Value(r, r == KErrPermissionDenied);

	TFindFile finder(TheFs);
	CDir* dir = NULL;
	r=finder.FindWildByDir(KWildFile, KWildPath, dir);
	if (!(r==KErrPermissionDenied))
		test.Printf(_L("T_DCNONE: test find wildcards r = %d (expected KErrPermissionDenied)\n"), r);
	test_Value(r, r == KErrPermissionDenied);
	delete dir;
	}
Esempio n. 6
0
// ==========================================================================
// METHOD:  TryToOpenFile
//
// DESIGN:  
// ==========================================================================
void CLogFileHandler::TryToOpenFile( TBool aCloseFile )
    {
    if( !iFileIsOpen )
        {        
        // Add the directory name to the start of the file name, to avoid
        // many files with the same name in different directories.
    	TFileName logFileName;
    	logFileName.Copy( KDebugLogsBaseDirectory );
    	logFileName.Append( iDirectoryName );   	
        logFileName.Append( KBackslash );
    	logFileName.Append( iDirectoryName );  
    	logFileName.Append( KUnderscore );
        logFileName.Append( iFileName );

    	TInt result = iFile.Open( iFs, logFileName, EFileWrite | EFileShareAny );
    	
    	if( result == KErrNotFound )
    	    {
        	result = iFile.Create( iFs, logFileName, EFileWrite | EFileShareAny );
    	    } // end if

        if( iFirstTime )
            {
            iFirstTime = EFalse;
            
            // Put a marker in the file.            
            if( result == KErrNone )
                {
                // Write the marker line and software version.
                TBuf<KSysUtilVersionTextLength> text;
                SysUtil::GetSWVersion(text);

                const TUint bufSize = KSysUtilVersionTextLength+30;
                TBuf8<bufSize> text8;

                _LIT8( KMarkerLine, "------------------" );
                
                text8.Copy( text );
                text8.Insert( 0, KEndOfLineCharacters8 );
                text8.Insert( 0, KMarkerLine );
                text8.Append( KEndOfLineCharacters8 );

                iFile.Write( KMaxTInt, text8 );
                }
            }

        if( aCloseFile )
            {
            iFile.Close();
            }
        else
            {            
            // Leave the file open.
            iFileIsOpen = (result == KErrNone );                    
            } // end if
            
        // Only try next time if this open succeeded.
        iTryToOpenFile = (result == KErrNone );

        } // end if
        
    } // END TryToOpenFile
Esempio n. 7
0
EXPORT_C TInt TEFparser::GetSectionData(TDesC& aScriptFilepath, TPtrC& aSectiontag, TDesC16 &aTocspTestFile, RFs& aFs)
	{
	
	TInt err = KErrNone;	
	TInt pos = 0;
	RFile file;
	
	// open the .ini file
	if (BaflUtils::FolderExists(aFs, aScriptFilepath))
		{		
		if (BaflUtils::FileExists( aFs, aScriptFilepath ))
			{	
			file.Open(aFs, aScriptFilepath, EFileRead | EFileShareAny);
			
			TFileText aLineReader;
			TBuf<256> iLine;
			TBuf<256> tempsectID;

			// create the section name to search for
			tempsectID.Copy(KOpenBrk);
			tempsectID.Append(aSectiontag);
			tempsectID.Append(KCloseBrk);
			
			// read the ini file a line at a time until you find the the section name
			aLineReader.Set(file);		
			TInt foundTag = -1;
			while (err != KErrEof && foundTag != 0)
				{
				err = aLineReader.Read(iLine);
				if (err != KErrEof)
					foundTag =  iLine.Find(tempsectID);
				}
			
			// create the next open bracket to search for		
			TBuf<2> tempopenBrk;
			tempopenBrk.Copy(KOpenBrk);
			
			RFile testfile;	
			err = KErrNone;
			foundTag = -1;

			// while not at the end of the file and not found the next open bracket
			while (err != KErrEof && foundTag != 0)
				{

				// get the next line of the .ini file
				err = aLineReader.Read(iLine);
				if (err != KErrEof)
					{

					// if the line of the file doesn't contain an open bracket, we are still in the section body
					foundTag =  iLine.Find(tempopenBrk);
					if (BaflUtils::FolderExists(aFs, aTocspTestFile) && foundTag != 0)
						{		
						// open the test file we are going to write all our section info into
						if (BaflUtils::FileExists( aFs, aTocspTestFile ))
							{	
							testfile.Open(aFs, aTocspTestFile, EFileWrite|EFileShareAny);
							testfile.Seek(ESeekEnd, pos);
							}
						else
							{	
							User::LeaveIfError(testfile.Create(aFs, aTocspTestFile, EFileWrite|EFileShareAny));
							testfile.Open(aFs, aTocspTestFile, EFileWrite|EFileShareAny);
							}
						// append to line of the file end of line characters
						iLine.Append(_L("\r\n"));

						// write line of the code out to the test file in UNICODE format 
						TPtrC8 tmpPoint((TText8*)iLine.Ptr(),iLine.Size());
						testfile.Write(tmpPoint); 
						
						testfile.Flush();							
						}
					testfile.Close();
					}
				}
			}
		}
		return KErrNone;

	}
Esempio n. 8
0
void CPixelMetricsMapperAppUi::CreateHeaderFileL() const
    {
    // Open/create resulting file.
    RFile file;
    HBufC* layoutFile = HBufC::NewLC( KMaxFileName );
    *layoutFile = KLayoutSourceFileAndPath;
    TFileName fileName = *layoutFile;
    CleanupStack::PopAndDestroy(layoutFile);
    RFs& fs = CEikonEnv::Static()->FsSession();
    TInt error = file.Open(fs,fileName, EFileWrite|EFileShareAny|EFileStreamText );
    if (error==KErrNotFound)
        {
       file.Create(fs,fileName, EFileWrite|EFileShareAny|EFileStreamText);
        }
    CleanupClosePushL( file );
    file.SetSize( 0 );

    // Make all writes as from textfile.
    TFileText textFile;
    textFile.Set( file );
    textFile.Seek( ESeekStart );

    // Take all layout files from private folder.
    CDir* dirList;
    User::LeaveIfError(fs.GetDir(
        KPixelMetricsDataFiles,
        KEntryAttMaskSupported,
        ESortByName,
        dirList));

    TMySmallBuffer bufferLayoutHdr;
    TMyBigBuffer bufferPMData;
    TInt fileCount = dirList->Count();
    for (TInt i=0;i<fileCount;i++)
        {
        // open sourcefile
        RFile sourceFile;
        TFileName layoutFile = (*dirList)[i].iName;
        User::LeaveIfError( sourceFile.Open(
            fs,layoutFile, EFileRead|EFileShareAny|EFileStreamText ));
        CleanupClosePushL( sourceFile );

        // Make all reads as from textfile.
        TFileText textSourceFile;
        textSourceFile.Set( sourceFile );
        TFileName layoutName = CreateLayoutNameL( textSourceFile );

        // rewind - just in case.
        textSourceFile.Seek( ESeekStart );
        TFileName oneline;
        bufferLayoutHdr.Append(KOpenBrace);
        bufferPMData.Append(KOpenBrace);
        TInt loop = 0;
        FOREVER
            {
            if( textSourceFile.Read(oneline) != KErrNone )
                {
                break;
                }
            // Add commas for all but first line
            if (loop != 0)
                {
                if ( loop <= KHeaderValues-1)
                    {
                    bufferLayoutHdr.Append(KComma);
                    }
                else
                    {
                    if (loop != KHeaderValues)
                        {
                        bufferPMData.Append(KComma);
                        }
                    }
                if (loop==KHeaderValues)
                    {
                    bufferLayoutHdr.Append(_L(",QLatin1String(\""));
                    bufferLayoutHdr.Append(layoutName);
                    bufferLayoutHdr.Append(_L("\")"));
                    }
                }
            // Remove pixel metrics name and ":"
            oneline = oneline.Mid(oneline.Find(KColon)+1);
            // Remove tab
            oneline = oneline.Mid(oneline.Find(KTab)+1);
            // remove crap from the end of line
            TLex lex(oneline);
            TInt nextValue = -666;
            User::LeaveIfError( lex.Val(nextValue) );
            if ( loop <= KHeaderValues-1)
                {
                bufferLayoutHdr.AppendNum(nextValue);
                }
            else
                {
                if (nextValue == -909)
                    bufferPMData.Append(_L("ECommonStyleValue"));
                else
                    bufferPMData.AppendNum(nextValue);
                }
            oneline.Zero();
            loop++;
            }
        file.Flush();
        bufferLayoutHdr.Append(KEndBraceWithCommaAndCRLF);
        bufferPMData.Append(KEndBraceWithCommaAndCRLF);
        CleanupStack::PopAndDestroy(); //sourceFile
        }

    if (fileCount > 0)
        {
        bufferLayoutHdr = bufferLayoutHdr.Left(bufferLayoutHdr.Length()-2);
        bufferPMData = bufferPMData.Left(bufferPMData.Length()-2);
        textFile.Write(bufferLayoutHdr);
        textFile.Write(KCRLF);
        textFile.Write(bufferPMData);
        }
    delete dirList;

    CleanupStack::PopAndDestroy(); //file
    }
Esempio n. 9
0
/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
TBool CMgAppUi::ShowDisclaimerL(void)
{
	TBool OkToContinue(EFalse);

	if(KAppIsTrial){
        TFindFile AppFile(CCoeEnv::Static()->FsSession());
        if(KErrNone != AppFile.FindByDir(KtxDisclaimerFileName, KNullDesC))
        {
            HBufC* Abbout = KtxDisclaimer().AllocLC();
            TPtr Pointter(Abbout->Des());
            CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL(Pointter);
            dlg->PrepareLC(R_DDD_HEADING_PANE);
            dlg->SetHeaderTextL(KtxDisclaimerTitle);  
            if(dlg->RunLD())
            {
                TFileName ShortFil;
                if(KErrNone ==CCoeEnv::Static()->FsSession().PrivatePath(ShortFil))
                {
                    TFindFile privFile(CCoeEnv::Static()->FsSession());
                    if(KErrNone == privFile.FindByDir(ShortFil, KNullDesC))
                    {
                        TParsePtrC hjelp(privFile.File());
                        ShortFil.Copy(hjelp.Drive());
                        ShortFil.Append(KtxDisclaimerFileName);
                    }
                }
    
            
                BaflUtils::EnsurePathExistsL(CCoeEnv::Static()->FsSession(),ShortFil);
            
                RFile MyFile;
                if(KErrNone == MyFile.Create(CCoeEnv::Static()->FsSession(),ShortFil,EFileWrite))
                {
                    TTime NowTime;
                    NowTime.HomeTime();
                    
                    TBuf8<255> InfoLine;
                    InfoLine.Copy(_L8("Accepted on Date\t"));
                        
                    InfoLine.AppendNum(NowTime.DateTime().Day() + 1);
                    InfoLine.Append(_L8("."));
                    InfoLine.AppendNum((NowTime.DateTime().Month() + 1));
                    InfoLine.Append(_L8("."));
                    InfoLine.AppendNum(NowTime.DateTime().Year());
                    InfoLine.Append(_L8(" "));
                    InfoLine.Append(_L8("--"));
                    InfoLine.AppendNum(NowTime.DateTime().Hour());
                    InfoLine.Append(_L8(":"));		
                    TInt HelperInt = NowTime.DateTime().Minute();
                    if(HelperInt < 10)
                        InfoLine.AppendNum(0);
                    InfoLine.AppendNum(HelperInt);
                    InfoLine.Append(_L8(":"));
                    HelperInt = NowTime.DateTime().Second();
                    if(HelperInt < 10)
                        InfoLine.AppendNum(0);
                    InfoLine.AppendNum(HelperInt);
                    InfoLine.Append(_L8(" "));
                    
                    MyFile.Write(InfoLine);
                    MyFile.Close();
                }
                
                OkToContinue = ETrue;
            }
            
            CleanupStack::PopAndDestroy(Abbout);
        }
        else
        {
            OkToContinue = ETrue;
        }
	}
    else
    {
        OkToContinue = ETrue;
    }
	
	return OkToContinue;
}
void TestVFATCase1()
	{
	test.Next(_L("Test Without VFAT entry, but DOS entry uses CP932 Japanese file's access"));
	__UHEAP_MARK;
	
	// logging for failure
	gTCType = ESymbianFATSpecific;
	RBuf failedOnBuf;
	failedOnBuf.CreateL(gLogFailureData.iFuncName);
	gTCId = 0;
	RBuf tcUniquePath;
	tcUniquePath.CreateL(KNone());

	QuickFormat();
	CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));

	GetBootInfo();

   	RFile file;
  	TFileName fn = _L("\\ABCD");
  	
  	TInt r=file.Create(TheFs,fn,EFileRead);
  	testAndLog(r==KErrNone);
  	file.Close();
  
  	//	Assume this file is the first entry in the root directory
  	r=TheDisk.Open(TheFs,CurrentDrive());
  	testAndLog(r==KErrNone);

    //-- read the 1st dir entry, it should be a DOS entry 
    const TInt posEntry1=gBootSector.RootDirStartSector() << KDefaultSectorLog2; //-- dir entry1 position
      
    TFatDirEntry fatEntry1;
 	TPtr8 ptrEntry1((TUint8*)&fatEntry1,sizeof(TFatDirEntry));
	testAndLog(TheDisk.Read(posEntry1, ptrEntry1)==KErrNone); 
	testAndLog(!fatEntry1.IsVFatEntry());

	// Manually modify the short name into unicode characters
	// 	Unicode: 	0x(798F 5C71 96C5 6CBB)
	//	Shift-JIS: 	0x(959F 8E52 89EB 8EA1)

	TBuf8<8> unicodeSN = _L8("ABCD1234");
	unicodeSN[0] = 0x95;
	unicodeSN[1] = 0x9F;
	unicodeSN[2] = 0x8E;
	unicodeSN[3] = 0x52;
	unicodeSN[4] = 0x89;
	unicodeSN[5] = 0xEB;
	unicodeSN[6] = 0x8E;
	unicodeSN[7] = 0xA1;

	fatEntry1.SetName(unicodeSN);
	testAndLog(TheDisk.Write(posEntry1, ptrEntry1)==KErrNone);
	TheDisk.Close();

  	// The Unicode file name of the file that is created
  	fn = _L("\\ABCD");
  	fn[1] = 0x798F;
  	fn[2] = 0x5C71;
  	fn[3] = 0x96C5;
  	fn[4] = 0x6CBB;
  	
  	// Access the file using its unicode file name without the DLL loaded.
      r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
  	test_KErrNone(r);
  	
  	TEntry entry;
  	TInt err = TheFs.Entry(fn, entry);
  	testAndLog(err==KErrNotFound);
  	
      // Access the file using its unicode file name with the DLL loaded.
      r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);  	
	test_KErrNone(r);
 	r = UserSvr::ChangeLocale(KTestLocale);  	
	test_KErrNone(r);
  
  	err = TheFs.Entry(fn, entry);
  	testAndLog(err==KErrNone);
  	
  	//file is no more required,delete it.
  	err = TheFs.Delete(fn);
  	testAndLog(err==KErrNone);
  	
      r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
  	test_KErrNone(r);
  	
 	r=TheFs.SessionPath(gSessionPath);
  	test_KErrNone(r);
	failedOnBuf.Close();
	tcUniquePath.Close();
	__UHEAP_MARKEND;
	}
Esempio n. 11
0
LOCAL_C void privateSIDRFstest()
//
//
//
	{
	theprivatepath[0]=(TText)gDriveToTest;	
	test.Printf(_L("the Private Path = %S"),&theprivatepath);

	mkdirname.Zero();
	mkdirname.Append(theprivatepath);
	mkdirname.Append(KMkDirSub);
	r=TheFs.MkDirAll(mkdirname);	
	test_KErrNone(r);

	r=TheFs.RmDir(mkdirname);	
	test_KErrNone(r);

	r=TheFs.SetSubst(theprivatepath,EDriveP);	
	test_Value(r, r == KErrPermissionDenied);

	r=TheFs.RealName(_L("P:\\File.XXX"),realName);
	test_KErrNone(r);
	
	r=TheFs.SetSessionPath(theprivatepath);
	test_KErrNone(r);

	TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
	test(aStat3==KRequestPending);


	pritestfile=theprivatepath;
	pritestfile[0]=(TText)('A' + gTheDriveNum);
	pritestfile1=pritestfile;
	pritestfile.Append(KFilePri2);
	pritestfile1.Append(KFilePri3);
	
	oldName=KOldFile;
	oldName[0]=(TText)gDriveToTest;

	r=TheFs.GetShortName(pritestfile, shortfilename);
//	test_Value(r, r == KErrNone || r == KErrPathNotFound);
	test(r == KErrNone || KErrPathNotFound);

	r=TheFs.GetLongName(pritestfile1, longfilename);
//	test_Value(r, r == KErrNone || r == KErrPathNotFound);
	test(r == KErrNone || KErrPathNotFound);

	r=file1.Create(TheFs,oldName,EFileWrite);
	test_Value(r, r == KErrNone || r==KErrAlreadyExists);
	file1.Close();

	r=TheFs.Replace(oldName,pritestfile);
	test_KErrNone(r);
	
	r=TheFs.Rename(pritestfile,pritestfile1);
	test_Value(r, r == KErrNone || r==KErrAlreadyExists);
	
	r=TheFs.Entry(pritestfile1,entry);
	test_KErrNone(r);

	//Test Entry with correct SID
	r=TheFs.Entry(theprivatepath,entry);
	test_KErrNone(r);
	
	//Test Entry with correct SID and without "//" appended
	r=TheFs.Entry(KPrivatePathTest1,entry);
	test_KErrNone(r);
	
	//Test Entry with invalid SID, without // appended
	r=TheFs.Entry(KPrivatePathTest2,entry);
	test_Value(r, r == KErrPermissionDenied);
	
	//Test Entry with invalid SID
	r=TheFs.Entry(KPrivatePathTest3,entry);
	test_Value(r, r == KErrPermissionDenied);

	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
	test_KErrNone(r);

	r=TheFs.Delete(pritestfile1);
	test_KErrNone(r);

	}
Esempio n. 12
0
static void DoTestFileRead(TInt aBlockSize, TInt aFileSize = KMaxFileSize, TBool aReRead = EFalse)
//
// Do Read Test
//
{
    // Create test data
//	test.Printf(_L("Creating test file..."));
    TInt writeBlockLen = aFileSize > DataBuf.MaxSize() ? DataBuf.MaxSize() : aFileSize;
    DataBuf.SetLength(writeBlockLen);
#if defined(_DEBUG)
    for (TInt m = 0; m < DataBuf.Length(); m++)
        DataBuf[m] = TText8(m % 256);
#endif
    // To allow this test to run on a non-preq914 branch :
    enum {EFileWriteDirectIO = 0x00001000};
    TInt r = File.Create(TheFs, _L("READTEST"), EFileStream | EFileWriteDirectIO);
    test_KErrNone(r);
    TInt count = aFileSize / DataBuf.Length();
    while (count--)
        File.Write(DataBuf);
//	test.Printf(_L("done\n"));
    File.Close();

    enum {EFileReadBuffered = 0x00002000, EFileReadDirectIO = 0x00004000};
    r = File.Open(TheFs, _L("READTEST"), EFileStream | (gReadCachingOn ? EFileReadBuffered : EFileReadDirectIO));
    test_KErrNone(r);

//	const TInt maxReadCount = aFileSize / aBlockSize;
    TUint functionCalls = 0;

#if defined SYMBIAN_TEST_COPY
    // To allow this test to run on a non-preq914 branch :
    enum {EFileWriteDirectIO = 0x00001000};
    TInt r = File2.Replace(TheFs, _L("WRITETEST"), EFileStream | EFileWriteDirectIO);
    test_KErrNone(r);
#endif

    TTime startTime(0);
    TTime endTime(0);

    // we stop after the entire file has been read or after 10 seconds, whichever happens sooner
    RTimer timer;
    timer.CreateLocal();
    TRequestStatus reqStat;


    TUint initTicks = 0;
    TUint finalTicks = 0;

    // if aReRead file is set, then read file twice
    for (TInt n=0; n<(aReRead?2:1); n++)
    {
        functionCalls = 0;

        const TInt readLen = (aReRead && n == 0) ? writeBlockLen : aBlockSize;
        const TInt maxReadCount = aFileSize / readLen;

        TInt pos = 0;
        File.Seek(ESeekStart, pos);

        timer.After(reqStat, 10000000); // After 10 secs
        startTime.HomeTime();
        initTicks = User::FastCounter();

        for (TInt i = 0; i<maxReadCount && reqStat==KRequestPending; i++)
        {
//			test.Printf(_L("Read %d\n"),i);
//			for (TInt a = 0; a < 512; a++)
//				test.Printf(_L("%d"),DataBuf[a]);

            TInt r = File.Read(DataBuf, readLen);
            test_KErrNone(r);

            if (DataBuf.Length() == 0)
                break;

#if defined SYMBIAN_TEST_COPY
            r = File2.Write(DataBuf, readLen);
            test_KErrNone(r);
#endif
            functionCalls++;

#if defined(_DEBUG)
//			for (TInt a = 0; a < 512; a++)
//				test.Printf(_L("%d"),DataBuf[a]);

            for (TInt j = 0; j < DataBuf.Size(); j++)
                test(DataBuf[j] == (j + i * readLen) % 256);
#endif

        }

        finalTicks = User::FastCounter();
        endTime.HomeTime();
        timer.Cancel();
    }

    TInt dataTransferred = functionCalls * aBlockSize;

//	TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(startTime);
    TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;

    TReal transferRate =
        TReal32(dataTransferred) /
        TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
    test.Printf(_L("Read %7d bytes in %7d byte blocks:\t%11.3f KBytes/s (%d microsecs)\n"),
                dataTransferred, aBlockSize, transferRate, endTime.MicroSecondsFrom(startTime).Int64());


    timer.Close();
#if defined SYMBIAN_TEST_COPY
    File2.Close();
#endif

    File.Close();
    r = TheFs.Delete(_L("READTEST"));
    test_KErrNone(r);
    return;
}
Esempio n. 13
0
EXPORT_C void CMsvTestUtils::FindChildrenL(TMsvId aFolderToTraverse, TBool aReplace, TBool aOtherFiles)
	{
	iFileCount=0;

	CDir* rfcFileList;
	// Loads the any test files into an EntryList
	iFs.GetDir(iRfc822Dir, KEntryAttNormal, ESortByName, rfcFileList);
		
	TMsvSelectionOrdering ordering;
	ordering.SetShowInvisibleEntries(ETrue);

	TMsvId entryId;
	if (iClientServer==EClientSide)
		{
		entryId=iMsvEntry->Entry().Id();
		iMsvEntry->SetEntryL(aFolderToTraverse);
		iMsvEntry->SetSortTypeL(ordering);
		}
	else
		{
		entryId=iServerEntry->Entry().Id();
		iServerEntry->SetEntry(aFolderToTraverse);
		iServerEntry->SetSort(ordering);
		}


	RFile file;
	TFileName filename(iLogsDir);
	filename.Append(KFileNameEntryStructure);

	// Print out Hierarchy - Save to file
		
	if (aReplace)
		{
		// replace both Entry_Structure.txt and Entry_RichTextBodies.txt
		TInt err1 = file.Replace(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
		if (err1==KErrNotFound) // file does not exist - create it
			err1=file.Create(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
		if (err1 == KErrNone)
			ListChildrenL(aReplace, aOtherFiles, file, *rfcFileList);
		}
	else
		{
		TInt err1 = file.Open(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
		if (err1==KErrNotFound)
			file.Create(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
		else if (err1 != KErrNone)
			User::Leave(err1);
		TInt position=1;
		User::LeaveIfError(file.Seek(ESeekEnd, position));
		ListChildrenL(aReplace, aOtherFiles, file, *rfcFileList);
		}

	file.Close();
	
	if (iClientServer==EClientSide)
		iMsvEntry->SetEntryL(entryId);
	else
		iServerEntry->SetEntry(entryId);
	delete rfcFileList;
	}
Esempio n. 14
0
/**
@SYMTestCaseID          SYSLIB-BAFL-CT-0487
@SYMTestCaseDesc        Tests for defect number INC045169L
@SYMTestPriority        High
@SYMTestActions         Tests for creation of files
@SYMTestExpectedResults Tests must not fail
@SYMREQ                 REQ0000
*/
void Defect_INC045169L()
	{
	TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-BAFL-CT-0487 Defect_INC045169L "));

	__UHEAP_MARK;

  	// find out the number of open handles
	TInt startProcessHandleCount;
	TInt startThreadHandleCount;
	RThread ().HandleCount (startProcessHandleCount, startThreadHandleCount);

	//
	// The Test Setup

	User::LeaveIfError (TheFs.Connect ());
	::CleanupClosePushL (TheFs);

	//
	// The Test Begins...


	// Our test diectory and files...
	_LIT (KDirectory, "C:\\System\\Data\\");

	// ++++++++++++++

	// When creating test file names be careful to use different
	// combinations of charaters as you may get ambiguity!
	// i.e. '.aaa' will find files '.a' or 'a' if on disk.
	// similarly, 'abc158' will find files 'abc' or 'abc.'.
	// Also, file name ending in a period will have them
	// stripped off by the Fs, so 'abcd.' will give you 'abcd'
	// Finally, don't have like names like 'abc.rsc' and 'abc.r'

	// Failure cases
	_LIT (KFilename1, "c:"); // not supported
	_LIT (KFilename2, "x"); // not supported
	_LIT (KFilename3, "C:\\System\\Data\\a"); // not supported
	_LIT (KFilename4, "C:\\System\\Data\\ab"); // not supported
	_LIT (KFilename5, "C:\\System\\Data\\i.j"); // no 'i.01' available
	_LIT (KFilename6, "C:\\System\\Data\\abc.r12345678901234567890"); // suffix too large
	_LIT (KFilename7, "C:\\System\\Data\\"); // not supported

	// Successful cases
	_LIT (KFilename10, "C:\\System\\Data\\cde");
	_LIT (KFilename11, "C:\\System\\Data\\abc158");
	_LIT (KFilename12, "C:\\System\\Data\\C01abc001");
	_LIT (KFilename13, "C:\\System\\Data\\0123456789.012");
	_LIT (KFilename14, "C:\\System\\Data\\0123");
	_LIT (KFilename15, "C:\\System\\Data\\0123456789012");
	_LIT (KFilename16, "C:\\System\\Data\\C.01a1");
	_LIT (KFilename17, "C:\\System\\Data\\C.a0a1");
	_LIT (KFilename18, "C:\\System\\Data\\.b");
	_LIT (KFilename19, "C:\\System\\Data\\.ccc");
	_LIT (KFilename20, "C:\\System\\Data\\rfg.3a");
	_LIT (KFilename21, "C:\\System\\Data\\abc.r158");
	_LIT (KFilename22, "C:\\System\\Data\\abc.rsc");
	_LIT (KFilename23, "C:\\System\\Data\\efg.r");
	_LIT (KFilename24, "C:\\System\\Data\\klmn.");
	_LIT (KFilename25, "C:\\System\\Data\\jhgdfgd.123456789abc");
	_LIT (KFilename26, "\\abc.r158");
	_LIT (KFilename27, "abc.r158");
	_LIT (KFilename28, "c:abc.r158");

	// ++++++++++++++

	// ELangAmerican
	_LIT (KLocale, "ELOCL.10");
	_LIT (KNearestLang, "C:\\System\\Data\\abc.r10");

	// Tidy the files if there...
	// KFilename1 can't be created
	BaflUtils::DeleteFile (TheFs, KFilename2);
	BaflUtils::DeleteFile (TheFs, KFilename3);
	BaflUtils::DeleteFile (TheFs, KFilename4);
	BaflUtils::DeleteFile (TheFs, KFilename5);
	BaflUtils::DeleteFile (TheFs, KFilename6);

 	// Do not delete KFileName7, there may be other
 	// files in this directory unrelated to this test
 	// which are required by other tests.
 	// See defect DEF108808
 	// BaflUtils::DeleteFile (TheFs, KFilename7);

	BaflUtils::DeleteFile (TheFs, KFilename10);
	BaflUtils::DeleteFile (TheFs, KFilename11);
	BaflUtils::DeleteFile (TheFs, KFilename12);
	BaflUtils::DeleteFile (TheFs, KFilename13);
	BaflUtils::DeleteFile (TheFs, KFilename14);
	BaflUtils::DeleteFile (TheFs, KFilename15);
	BaflUtils::DeleteFile (TheFs, KFilename16);
	BaflUtils::DeleteFile (TheFs, KFilename17);
	BaflUtils::DeleteFile (TheFs, KFilename18);
	BaflUtils::DeleteFile (TheFs, KFilename19);
	BaflUtils::DeleteFile (TheFs, KFilename20);
	BaflUtils::DeleteFile (TheFs, KFilename21);
	BaflUtils::DeleteFile (TheFs, KFilename22);
	BaflUtils::DeleteFile (TheFs, KFilename23);
#ifdef __EPOC32__
	BaflUtils::DeleteFile (TheFs, KFilename24);
#else
	// Windows strips off trailing periods
	BaflUtils::DeleteFile (TheFs, _L("C:\\System\\Data\\klmn"));
#endif
	BaflUtils::DeleteFile (TheFs, KFilename25);
	BaflUtils::DeleteFile (TheFs, KFilename26);
	BaflUtils::DeleteFile (TheFs, KFilename27);
	BaflUtils::DeleteFile (TheFs, KFilename28);
	BaflUtils::DeleteFile (TheFs, KNearestLang);

	// Confirm the prerequisites for this test...
	if (!BaflUtils::PathExists (TheFs, KDirectory))
		{
		BaflUtils::EnsurePathExistsL(TheFs, KDirectory);
		}

	// KFilename1 can't be created
	TheTest (BaflUtils::FileExists (TheFs, KFilename2) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename3) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename4) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename5) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename6) == EFalse);
	// KFilename7 can't be created, not a file

	TheTest (BaflUtils::FileExists (TheFs, KFilename10) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename11) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename12) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename13) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename14) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename15) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename16) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename17) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename18) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename19) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename20) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename21) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename22) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename23) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename24) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename25) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename26) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename27) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KFilename28) == EFalse);
	TheTest (BaflUtils::FileExists (TheFs, KNearestLang) == EFalse);

	// Create the files...
	RFile rFile;
	// KFilename1 can't be created
	rFile.Create (TheFs, KFilename2, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename3, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename4, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename5, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename6, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename7, EFileRead);
	rFile.Close ();

	rFile.Create (TheFs, KFilename10, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename11, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename12, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename13, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename14, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename15, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename16, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename17, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename18, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename19, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename20, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename21, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename22, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename23, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename24, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename25, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename26, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename27, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KFilename28, EFileRead);
	rFile.Close ();
	rFile.Create (TheFs, KNearestLang, EFileRead);
	rFile.Close ();

	TBuf <256> filename (KFilename1);

	// Test the defect...
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename1, &filename);
	TheTest(filename == KFilename1);

	filename.Copy (KFilename2);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename2, &filename);
	TheTest(filename == _L("x"));

	filename.Copy (KFilename3);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename3, &filename);
	TheTest(filename == KFilename3);

	filename.Copy (KFilename4);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename4, &filename);
	TheTest(filename == KFilename4);

	filename.Copy (KFilename5);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename5, &filename);
	TheTest(filename == KFilename5);

	filename.Copy (KFilename6);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename6, &filename);
	TheTest(filename == KFilename6);

	filename.Copy (KFilename7);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename7, &filename);
	TheTest(filename == KFilename7);



	filename.Copy (KFilename10);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename10, &filename);
	TheTest(filename == KFilename10);

	filename.Copy (KFilename11);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename11, &filename);
	TheTest(filename == KFilename11);

	filename.Copy (KFilename12);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename12, &filename);
	TheTest(filename == KFilename12);

	filename.Copy (KFilename13);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename13, &filename);
	TheTest(filename == KFilename13);

	filename.Copy (KFilename14);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename14, &filename);
	TheTest(filename == KFilename14);

	filename.Copy (KFilename15);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename15, &filename);
	TheTest(filename == KFilename15);

	filename.Copy (KFilename16);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename16, &filename);
	TheTest(filename == KFilename16);

	filename.Copy (KFilename17);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename17, &filename);
	TheTest(filename == KFilename17);

	filename.Copy (KFilename18);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename18, &filename);
	TheTest(filename == KFilename18);

	filename.Copy (KFilename19);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename19, &filename);
	TheTest(filename == KFilename19);

	filename.Copy (KFilename20);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename20, &filename);
	TheTest(filename == KFilename20);

	filename.Copy (KFilename21);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename21, &filename);
	TheTest(filename == KFilename21);

	filename.Copy (KFilename22);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename22, &filename);
	TheTest(filename == KFilename22);

	filename.Copy (KFilename23);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename23, &filename);
	TheTest(filename == KFilename23);

	filename.Copy (KFilename24);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename24, &filename);
	TheTest(filename == KFilename24);

	filename.Copy (KFilename25);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename25, &filename);
	TheTest(filename == KFilename25);

	filename.Copy (KFilename26);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename26, &filename);
	TheTest(filename == KFilename26);

	filename.Copy (KFilename27);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename27, &filename);
	TheTest(filename == KFilename27);

	filename.Copy (KFilename28);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename28, &filename);
	TheTest(filename == KFilename28);


	// Store the original locale settings so they can be restored at the
	// end of the test.

	TExtendedLocale originalLocale;
	originalLocale.LoadSystemSettings();

	// Change locale
	TExtendedLocale newLocale;
	TBuf<50> libraryName;

	libraryName.Format(KLocale);

	TInt err = newLocale.LoadLocale(libraryName);
	User::LeaveIfError (err);

	newLocale.SaveSystemSettings();
	User::After (5000000);

	filename.Copy (KFilename1);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename1, &filename);
	TheTest(filename == KFilename1);

	filename.Copy (KFilename2);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename2, &filename);
	TheTest(filename == _L("x"));

	filename.Copy (KFilename3);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename3, &filename);
	TheTest(filename == KFilename3);

	filename.Copy (KFilename4);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename4, &filename);
	TheTest(filename == KFilename4);

	filename.Copy (KFilename5);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename5, &filename);
	TheTest(filename == KFilename5);

	filename.Copy (KFilename6);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename6, &filename);
	TheTest(filename == KFilename6);

	filename.Copy (KFilename7);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename7, &filename);
	TheTest(filename == KFilename7);



	filename.Copy (KFilename10);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename10, &filename);
	TheTest(filename == KFilename10);

	filename.Copy (KFilename11);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename11, &filename);
	TheTest(filename == KFilename11);

	filename.Copy (KFilename12);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename12, &filename);
	TheTest(filename == KFilename12);

	filename.Copy (KFilename13);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename13, &filename);
	TheTest(filename == KFilename13);

	filename.Copy (KFilename14);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename14, &filename);
	TheTest(filename == KFilename14);

	filename.Copy (KFilename15);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename15, &filename);
	TheTest(filename == KFilename15);

	filename.Copy (KFilename16);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename16, &filename);
	TheTest(filename == KFilename16);

	filename.Copy (KFilename17);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename17, &filename);
	TheTest(filename == KFilename17);

	filename.Copy (KFilename18);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename18, &filename);
	TheTest(filename == KFilename18);

	filename.Copy (KFilename19);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename19, &filename);
	TheTest(filename == KFilename19);

	filename.Copy (KFilename20);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename20, &filename);
	TheTest(filename == KFilename20);

	filename.Copy (KFilename21);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename21, &filename);
	TheTest(filename == KNearestLang);

	filename.Copy (KFilename22);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename22, &filename);
	TheTest(filename == KNearestLang);

	filename.Copy (KFilename23);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename23, &filename);
	TheTest(filename == KFilename23);

	filename.Copy (KFilename24);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename24, &filename);
	TheTest(filename == KFilename24);

	filename.Copy (KFilename25);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename25, &filename);
	TheTest(filename == KFilename25);

	filename.Copy (KFilename26);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename26, &filename);
	TheTest(filename == KFilename26);

	filename.Copy (KFilename27);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename27, &filename);
	TheTest(filename == KFilename27);

	filename.Copy (KFilename28);
	BaflUtils::NearestLanguageFile (TheFs, filename);
	TheTest.Printf (_L ("The NearestLanguageFile for %S is %S\n"), &KFilename28, &filename);
	TheTest(filename == KFilename28);

	// Tidy the files...
	// KFilename1 can't be created
	BaflUtils::DeleteFile (TheFs, KFilename2);
	BaflUtils::DeleteFile (TheFs, KFilename3);
	BaflUtils::DeleteFile (TheFs, KFilename4);
	BaflUtils::DeleteFile (TheFs, KFilename5);
	BaflUtils::DeleteFile (TheFs, KFilename6);

	// Do not delete KFileName7, there may be other
 	// files in this directory unrelated to this test
 	// which are required by other tests.
 	// See defect DEF108808
 	// BaflUtils::DeleteFile (TheFs, KFilename7);

	BaflUtils::DeleteFile (TheFs, KFilename10);
	BaflUtils::DeleteFile (TheFs, KFilename11);
	BaflUtils::DeleteFile (TheFs, KFilename12);
	BaflUtils::DeleteFile (TheFs, KFilename13);
	BaflUtils::DeleteFile (TheFs, KFilename14);
	BaflUtils::DeleteFile (TheFs, KFilename15);
	BaflUtils::DeleteFile (TheFs, KFilename16);
	BaflUtils::DeleteFile (TheFs, KFilename17);
	BaflUtils::DeleteFile (TheFs, KFilename18);
	BaflUtils::DeleteFile (TheFs, KFilename19);
	BaflUtils::DeleteFile (TheFs, KFilename20);
	BaflUtils::DeleteFile (TheFs, KFilename21);
	BaflUtils::DeleteFile (TheFs, KFilename22);
	BaflUtils::DeleteFile (TheFs, KFilename23);
#ifdef __EPOC32__
	BaflUtils::DeleteFile (TheFs, KFilename24);
#else
	// Windows strips off trailing periods
	BaflUtils::DeleteFile (TheFs, _L("C:\\System\\Data\\klmn"));
#endif
	BaflUtils::DeleteFile (TheFs, KFilename25);
	BaflUtils::DeleteFile (TheFs, KFilename26);
	BaflUtils::DeleteFile (TheFs, KFilename27);
	BaflUtils::DeleteFile (TheFs, KFilename28);
	BaflUtils::DeleteFile (TheFs, KNearestLang);

	// Restore the original locale settings.
  	originalLocale.SaveSystemSettings();

	CleanupStack::PopAndDestroy (&::TheFs);

	// The Test Ends...
	//

	// check that no handles have leaked
	TInt endProcessHandleCount;
	TInt endThreadHandleCount;
	RThread ().HandleCount (endProcessHandleCount, endThreadHandleCount);

	TheTest (startThreadHandleCount == endThreadHandleCount);

	__UHEAP_MARKEND;
	}
Esempio n. 15
0
TInt CTestStepFlogger::constructFloggerIniL( const TDesC8& additionalConfig )
/**
Replace the flogger.ini with a new one made up of the contents of ts_flogger.ini and additionalConfig.
@param additionalConfig string with the extra config items to be set in flogger.ini
@return KErrNone if no probs, otherwise an error code.
@note This function deletes then recreates the flogger.ini file, so during the short time between
 the delete and the recreate, if flogger server is running, it will report that there were errors in the ini file (because
 the ini file is not there).
 */
	{
	RFile theFile;
	RFile outFile;
	RFs fileServer; 
	User::LeaveIfError(fileServer.Connect());
	HBufC8 * fileContentsHeap;
	TInt fileSize;
	TInt returnCode;	

	returnCode = theFile.Open(fileServer,KFloggerTestIniMediaSourceFile,EFileRead);
	
	if (returnCode == KErrNone)
		{
		theFile.Size(fileSize);
		
		// allocate the heap space for the string given size of ts_flogger and
		// the length of the additional items string.
		TInt newFileSize = fileSize + additionalConfig.Length();  //just so we can see this during debugging

		fileContentsHeap = HBufC8::NewLC(newFileSize);

		TPtr8 fileContentsAppend(fileContentsHeap->Des());
		
		// read into the buffer the contents of ts_flogger.ini
		User::LeaveIfError(returnCode = theFile.Read(fileContentsAppend));
		
		// append addition items
		fileContentsAppend.Append(additionalConfig);

		// We must assume the flogger.ini is either there or not there,
		// If the flogger.ini is already there, and the flogger server is already running
		// and watching this file, we cannot do any of the following:
		//* Open and overwrite - if we overwrite a large file with a smaller one, it fails to overwrite the whole file
		//* Delete and create - after the delete but before the create flogger server will attempt to access
		//* use RFile::Replace - between the replace and the write flogger server will attempt access
		
		// so we must create a temporary file and then use the file system to overwrite the
		// current with our temp using "replace" which is an atomic operation as far as flogger server is concerned

		returnCode = outFile.Create(fileServer,KTempDuringCreationFloggerIniFile,EFileWrite);
		if (returnCode == KErrNone)
			{
			TInt pos = 0;
			outFile.Seek(ESeekStart,pos);
			outFile.Write(fileContentsAppend);
			
			outFile.Close();
			
			fileServer.Replace(KTempDuringCreationFloggerIniFile,KFloggerIniFile);
			}
		CleanupStack::PopAndDestroy(fileContentsHeap);
		theFile.Close();
		}
	
	fileServer.Close();

	if (returnCode != KErrNone)
		{
		return returnCode;
		}
	else
		{
		return KErrNone;
		}

	}
Esempio n. 16
0
void MainL()
	{
	test.Title(_L("c:\\upstest.log"));
	test.Start(_L(" @SYMTestCaseID:SEC-UPS-0001 Testing RUpsSubsession "));

	RFs fs;
	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);
	
	TBuf<21> notifierConfig(_L("!:\\upsrefnotifier.txt"));
	notifierConfig[0] = fs.GetSystemDriveChar();

	TBuf<35> database(_L("!:\\Private\\10283558\\database\\ups.db"));
	database[0] = fs.GetSystemDriveChar();

	TInt lineLength = User::CommandLineLength();
	switch(lineLength)
		{
	default:
		case 2:
			(void) fs.Delete(database);
			// Fall through to also delete notifier config file
		case 1:
			(void) fs.Delete(notifierConfig);
			break;
		case 0:
			{
			// No args so run in silent mode
			(void) fs.Delete(database);
			(void) fs.Delete(notifierConfig);
			RFile file;
			User::LeaveIfError(file.Create(fs, notifierConfig, EFileShareExclusive | EFileWrite));
			User::LeaveIfError(file.Write(_L8("Never")));
			file.Close();
			break;
			}
		}

	//RThread ourThread;
	//ourThread.SetPriority(EPriorityMore);
	//ourThread.Close();
//	User::SetProcessCritical(User::ESystemCritical);
//	User::SetCritical(User::ESystemCritical);
	TestOpenCloseSession();


	TInt r = sTestSession.Connect();
	test(r == KErrNone);
	User::LeaveIfError(r);

	TestRUpsSubsessionDeathL();

	TestOpenCloseSubsession();

	TestSwiObserverSecurityL();
	
	RThread thd;
	r = sTestSubsession.Initialise(sTestSession, thd);
	test(r == KErrNone);
	User::LeaveIfError(r);
	
	TestFlurryL();

	TestAuthoriseL();
	
	sTestSubsession.Close();

	TestRUpsSubsession();

	TestRUpsManagementL();

	sTestSession.ShutdownServer();

	// Close top level session (low level session was closed by
	// ShutdownServer, but we still need to do the RUpsSession
	// cleanup).
	sTestSession.Close();

	(void) fs.Delete(notifierConfig);
	CleanupStack::PopAndDestroy(&fs);
	
	test.End();
	test.Close();
}
Esempio n. 17
0
LOCAL_C void privateRFstest()
//
//
//
	{
	pritestname=KPrivatePath;
	pritestname[0]=(TText)('A' + gTheDriveNum);

	mkdirname.Zero();
	mkdirname.Append(pritestname);
	mkdirname.Append(KMkDirSub);

	r=TheFs.MkDirAll(mkdirname);	
	test_Value(r, r == KErrPermissionDenied);

	r=TheFs.RmDir(mkdirname);	
	test_Value(r, r == KErrPermissionDenied);

	r=TheFs.SetSubst(pritestname,EDriveP);
	test_Value(r, r == KErrPermissionDenied); 

	TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
	test(aStat2==KErrPermissionDenied);


	pritestfile=KPrivatePath;
	pritestfile[0]=(TText)('A' + gTheDriveNum);
	pritestfile1=pritestfile;
	pritestfile.Append(KFilePri2);
	pritestfile1.Append(KFilePri3);
	
	oldName=KOldFile;
	oldName[0]=(TText)gDriveToTest;

	r=TheFs.GetShortName(pritestfile, shortfilename);
	test_Value(r, r == KErrPermissionDenied);

	r=TheFs.GetLongName(pritestfile1, longfilename);
	test_Value(r, r == KErrPermissionDenied);

	r=file1.Create(TheFs,oldName,EFileWrite);
	test_Value(r, r == KErrNone || r==KErrAlreadyExists);
	file1.Close();

	r=TheFs.Replace(oldName,pritestfile);
	test_Value(r, r == KErrPermissionDenied);
	
	r=TheFs.Rename(pritestfile,pritestfile1);
	test_Value(r, r == KErrPermissionDenied);
	
	r=TheFs.Entry(pritestfile1,entry);
	test_Value(r, r == KErrPermissionDenied);

	// check that the entry for the private directory itself can be retrieved with no error
	// - with or without a slash
	TPtrC restrictedDir(pritestname.Ptr(), pritestname.Length());
	r=TheFs.Entry(restrictedDir, entry);
	test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
	test_KErrNone(r);
	test (entry.iAtt & KEntryAttDir);

	TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
	r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
	test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
	test_KErrNone(r);

	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
	test_Value(r, r == KErrPermissionDenied);

	r=TheFs.Delete(pritestfile1);
	test_Value(r, r == KErrPermissionDenied);

	}
Esempio n. 18
0
// --------------------------------------------------------------------------
// CUPnPLocalPlayer::PlayL
// Play a selected item.
// --------------------------------------------------------------------------
//
EXPORT_C void CUPnPLocalPlayer::PlayL( const CUpnpObject& aItem )
    {
    __LOG( "CUPnPLocalPlayer::PlayL" );
    
    // recreate iItem
    delete iItem; iItem = NULL;
    iItem = CUpnpItem::NewL();
    iItem->CopyL( aItem );

    if ( !IsLocallySupportedL( *iItem ) ) 
        {
        User::Leave( KErrNotSupported );
        }
    
    //in order not to get two callbacks when MS is lost, 
    // in CUPnPLocalPlayer and CUPnPBrowseDialog
    iBrowseSessionObserver = iBrowseSession->Observer();
    iBrowseSession->RemoveObserver(); 
    iFs.Close();
    
    User::LeaveIfError( iFs.Connect() );
    User::LeaveIfError( iFs.ShareProtected() );
    delete iFilePath; iFilePath = NULL;
    iExitReason = KErrNone;
    iDownloadSession->SetObserver( *this );
    
    /**
     * All the temporiarily downloaded files should go to the
     * hidden folder \data\download\media\temp
     * fix for ETLU-7LKCJB
     */
    //create a file path which should contain the absolute file path
    //e.g c:\data\download\media\temp\image.jpg
    
    iFilePath = HBufC::NewL( KMaxFileName );
    HBufC* copyLocation = HBufC::NewLC( KMaxFileName );
    CUPnPSettingsEngine* settingsEngine = CUPnPSettingsEngine::NewL();
    CleanupStack::PushL( settingsEngine );
    TBool copyLocationIsPhoneMemory = 0; // not used in this case
    TPtr copyLocationPtr( copyLocation->Des() );
    settingsEngine->GetCopyLocationL( copyLocationPtr,
        copyLocationIsPhoneMemory );
        
    CleanupStack::PopAndDestroy( settingsEngine );    
        
    iFilePath->Des().Append( *copyLocation );
    CleanupStack::PopAndDestroy( copyLocation );
    
    _LIT( KTempFolder, "temp\\");
    iFilePath->Des().Append( KTempFolder() );
    
    //check the existence of the target folder
    if( !BaflUtils::FolderExists( iFs, *iFilePath ) )
        {
        User::LeaveIfError( iFs.MkDirAll( *iFilePath ) );
        }
        
    User::LeaveIfError( iFs.SetAtt( *iFilePath, 
                                    KEntryAttHidden, 
                                    KEntryAttNormal ) );     
    
    //Get the title of the given item
    HBufC* title16 = UpnpString::ToUnicodeL( aItem.Title() );
    CleanupStack::PushL( title16 );
    HBufC* title16checked =
        UPnPCommonUtils::ReplaceIllegalFilenameCharactersL( *title16 );
    CleanupStack::PopAndDestroy( title16 );
    
    iFilePath->Des().Append( *title16checked );
    delete title16checked; title16checked = NULL;
    //Get the extension of the given item
    
    const CUpnpItem* item = (CUpnpItem*)(&aItem);
    const CUpnpElement* tmpEl = &( UPnPItemUtility::ResourceFromItemL( 
        *item ) );
    
    if( !UPnPFileUtility::FitsInMemory( *tmpEl) )
        {
        User::Leave( KErrDiskFull );
        }  
            
    const CUpnpAttribute* tmpAttInfo = UPnPItemUtility::FindAttributeByName(
        *tmpEl, KAttributeProtocolInfo );
    
    User::LeaveIfNull( const_cast<CUpnpAttribute*>(tmpAttInfo ) );
    
    CUpnpDlnaProtocolInfo* tmpProtocolInfo = CUpnpDlnaProtocolInfo::NewL(
        tmpAttInfo->Value() );
   
    CleanupStack::PushL( tmpProtocolInfo );
        
    HBufC* fileExt = NULL;
    
    fileExt = UPnPCommonUtils::FileExtensionByMimeTypeL(
        tmpProtocolInfo->ThirdField() );
    
    User::LeaveIfNull( fileExt );
    
    iFilePath->Des().Append( *fileExt );
    
    delete fileExt; fileExt = NULL;
    
    CleanupStack::PopAndDestroy( tmpProtocolInfo );
        
    TInt err = KErrNone;
    
    RFile rfile;
    err = rfile.Create(iFs, *iFilePath, EFileWrite );
    
    CleanupClosePushL( rfile );
    if( KErrAlreadyExists == err )
        {
        __LOG( "Already exists -> Delete old and create new" );
        User::LeaveIfError( iFs.Delete( *iFilePath ) );
        User::LeaveIfError( rfile.Create(iFs, *iFilePath, EFileWrite ) );
        }
    
    iDownloadSession->StartDownloadL( *tmpEl, 
                                      ( CUpnpItem& )aItem, 
                                      rfile,
                                      KDownloadPosition );
    CleanupStack::PopAndDestroy(&rfile);
    
    iWaitingNote = EFalse;    
    if( !iWaitingNote ) //if ReserveLocalMSServicesCompleted is not called
        {               //immediately
        iWaitingNote = ETrue;
        StartWaitingNoteL();
        }
    
    __LOG1( "CUPnPLocalPlayer::PlayL-END %d", iExitReason );
    if( iExitReason != KErrNone )
        {    
        User::Leave( iExitReason );
        }
    }
void ScrShotsGenUtils::DumpJsFileL(CScrShotsSettings* scrShotsSettings)
{
    CGetImei* getImei = CGetImei::NewL();
    CleanupStack::PushL(getImei);
    RBuf8 formatBuf;
    formatBuf.Create(256);
    formatBuf.CleanupClosePushL();
    TFileName infoFile;
    
    User::LeaveIfError(CEikonEnv::Static()->FsSession().PrivatePath(infoFile));
    infoFile.Append( KDeviceJSFile );
    TParsePtrC parse((CEikonEnv::Static()->EikAppUi()->Application())->AppFullName());
    infoFile.Insert(0, KCDriveWithColon);
    
    RFs fsConn;
    User::LeaveIfError(fsConn.Connect());
    CleanupClosePushL(fsConn);
    RFile jsFile;
    if(BaflUtils::FileExists(fsConn, infoFile)){
        BaflUtils::DeleteFile(fsConn, infoFile);
    }
    //now create the file
    User::LeaveIfError(jsFile.Create(fsConn, infoFile, EFileWrite));
    CleanupClosePushL(jsFile);
    
//    User::LeaveIfError(jsFile.Write(KFunctionBlockStart));
    RBuf8 values;
    values.Create(256);
    for(int i = 0; i < KDeviceParamsCount ; i++){
        formatBuf.Zero();
        TInt sizeOfItem = User::StringLength((TText8 *)DeviceParams [i]);
        TPtr8 item((unsigned char*)DeviceParams [i],sizeOfItem ,sizeOfItem );
        switch(i){
            //device_model
            case 0:{
                CDeviceTypeInformation* devInfo = SysUtil::GetDeviceTypeInfoL();
                CleanupStack::PushL(devInfo);
                TPtrC manufName, modelCode, modelName;
                devInfo->GetManufacturerName(manufName);
                devInfo->GetModelCode(modelCode);
                devInfo->GetModelName(modelName);
                RBuf8 manufName8, modelName8, modelCode8;
                manufName8.Create(128); modelName8.Create(128); modelCode8.Create(128);
                manufName8.CleanupClosePushL(); modelName8.CleanupClosePushL(); modelCode8.CleanupClosePushL();
                manufName8.Copy(manufName);
                modelName8.Copy(modelName);
                modelCode8.Copy(modelCode);
                values.Format(KModelNameFormatString, &manufName8, &modelName8, &modelCode8);
                CleanupStack::PopAndDestroy(4);
                break;
            }
            //firmware_version
            case 1:{
                RBuf swVersion;
                swVersion.Create(128);
                SysUtil::GetSWVersion(swVersion);
                values.Copy(swVersion);
                TInt pos = 0;
                while((pos = values.Find(_L8("\n"))) != KErrNotFound){
                    //values.Delete(pos,1);
                    values.Replace(pos,1,_L8("_"));
                }
                swVersion.Close();
                break;
            }
            
            //ram_info
            case 2:{
                TInt totalram= 0;
                HAL::Get(HALData::EMemoryRAM, totalram);
                totalram /= 1024;
                values.Num(totalram);
                break;
            }
            
            //uptime
            case 3:{
                TTimeIntervalMicroSeconds32 iTickPeriod;
                UserHal::TickPeriod(iTickPeriod);
                TUint tickCount = User::TickCount();
                TUint noOfTicksPerSecond = (1000 * 1000) / iTickPeriod.Int();
                TInt noOfSecsSinceStartUp = tickCount / noOfTicksPerSecond;//noOfMicroSecsSinceStartup / (1000 * 1000);
                values.Num(noOfSecsSinceStartUp);
                break;
            }
            
            //scrshot count
            case 4:{
                values.Num(scrShotsSettings->TotalScrShotCount());
                break;
            }
            
            //symbian version
            case 5:{
                TVersion epocver = User::Version();
                values.Copy(epocver.Name());            
                break;
            }
            
            //series 60 version
            case 6:{
                VersionInfo::TPlatformVersion platformVersion;
                VersionInfo::GetVersion(platformVersion);
                TInt aMajor = platformVersion.iMajorVersion;
                TInt aMinor = platformVersion.iMinorVersion;
                values.Format(_L8("%d.%d"),aMajor, aMinor);
                break;
            }
            //country code
            case 7:{
            
                TLocale loc;
                int code = loc.CountryCode();
                values.Num(code);
                break;
            }
            //imei hash
            case 8:{
                TBuf8<256> inputimei;
                TBuf8<256> outimeihash;
                if(getImei->IsImeiFetched()){
                    getImei->GetImei(inputimei);
                    GetWhirlPoolHash(outimeihash,inputimei);
                    values.Copy(outimeihash);
                }
            }
            break;

        }
        
        formatBuf.Format(KStringVariableDeclaration, 
                &item, 
                &values);
        TRACE_ON(RDebug::Printf((const char*)formatBuf.PtrZ()));
        jsFile.Write(formatBuf);
    }
    values.Close();
    CleanupStack::PopAndDestroy(4);
    //TODO: This code should be commented in final release build
#if BRAHMA_DEBUG
    //code to copy the js file just created to the c:\ so that it can be analyzed
    _LIT(KTargetFileName, "c:\\device_info.js");
    BaflUtils::CopyFile(CEikonEnv::Static()->FsSession(),infoFile, KTargetFileName);
#endif
}
Esempio n. 20
0
/**
@SYMTestCaseID          SYSLIB-STORE-CT-1149
@SYMTestCaseDesc	    Tests writing using a direct file store
@SYMTestPriority 	    High
@SYMTestActions  	    Tests for memory and end of file error while creating the store.
                        Tests for writing to replaced,temporary,opened,created file.
						Tests for creating an already existing file.
						Tests for panic while deleting a file.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void testWriteL()
	{
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1149 Creating and failing to open 'ghost' file "));
	
	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
	TParse parse;
	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
	
	TheFs.Delete(parse.NameAndExt());
	CFileStore* store=CDirectFileStore::CreateLC(TheFs,parse.NameAndExt(),EFileWrite);
	CleanupStack::PopAndDestroy();
	store=NULL;
	TRAPD(r,store=CDirectFileStore::OpenL(TheFs,parse.NameAndExt(),EFileRead|EFileWrite));
	test(store==NULL&&r==KErrEof);
//
	test.Next(_L("Writing to replaced file"));
	store=CDirectFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileWrite);
	store->SetTypeL(TUidType(KDirectFileStoreLayoutUid,KDirectFileStoreLayoutUid));
	testWriteL(*store);
	CleanupStack::PopAndDestroy();
//
	test.Next(_L("Writing to replaced file - 2"));
	store=CDirectFileStore::ReplaceL(TheFs,parse.NameAndExt(),EFileWrite);
	CleanupStack::PushL(store);
	store->SetTypeL(TUidType(KDirectFileStoreLayoutUid,KDirectFileStoreLayoutUid));
	testWriteL(*store);
	CleanupStack::PopAndDestroy();
//
	test.Next(_L("Writing to temp file"));
	store=CDirectFileStore::TempLC(TheFs,parse.DriveAndPath(),TheTempFile,EFileWrite);
	store->SetTypeL(TUidType(store->Layout(),KNullUid,KDirectFileStoreLayoutUid));
	testWriteL(*store);
	store->CommitL();
	CleanupStack::PopAndDestroy();
	(void)TheFs.Delete(TheTempFile);
//	
	test.Next(_L("Writing to temp file - 2"));
	store=CDirectFileStore::TempL(TheFs,parse.DriveAndPath(),TheTempFile,EFileWrite);
	CleanupStack::PushL(store);
	store->SetTypeL(TUidType(store->Layout(),KNullUid,KDirectFileStoreLayoutUid));
	testWriteL(*store);
	store->CommitL();
	CleanupStack::PopAndDestroy();
//
	test.Next(_L("Writing to opened file"));
	store=CDirectFileStore::OpenLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
	testWriteL(*store);
	store->CommitL();
	CleanupStack::PopAndDestroy();
//
	test.Next(_L("Failing to create existing file"));
	store=NULL;
	TRAP(r,store=CDirectFileStore::CreateL(TheFs,TheTempFile,EFileWrite));
	test(store==NULL&&r==KErrAlreadyExists);
	if (TheFs.Delete(parse.NameAndExt())!=KErrNone)
		test.Panic(_L("Deleting file"));
//
	test.Next(_L("Writing to created file"));
	RFile file;
	test(file.Create(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone);
	store=CDirectFileStore::NewLC(file);
	CleanupStack::PopAndDestroy();
	test(file.Open(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone);
	store=CDirectFileStore::NewL(file);
	CleanupStack::PushL(store);
	store->SetTypeL(KDirectFileStoreLayoutUid);
	testWriteL(*store);
	store->CommitL();
	CleanupStack::PopAndDestroy();
	}
void TestVFATCase2()
	{
	test.Next(_L("Test With VFAT entry, and DOS entry using CP932 Japanese file's access"));
	__UHEAP_MARK;
	
	// logging for failure
	gTCType = ESymbianFATSpecific;
	RBuf failedOnBuf;
	failedOnBuf.CreateL(gLogFailureData.iFuncName);
	gTCId = 0;
	RBuf tcUniquePath;
	tcUniquePath.CreateL(KNone());

	QuickFormat();
	CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));

	TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
	test_KErrNone(r);
		
	r = UserSvr::ChangeLocale(KTestLocale);
	test_KErrNone(r);
	r=TheFs.SetSessionPath(gSessionPath);
	testAndLog(r==KErrNone);
	
	_LIT(KTestNormalFileName, 		"\x65B0\x6587\x4EF6.TXT");	
	_LIT(KTestNormalFileShortName, 	"\x65B0\x6587\x4EF6.TXT");
	
	test.Printf(_L("Create a file with the DLL installed, and get the shortname"));
	r=TheFile.Create(TheFs,KTestNormalFileName,EFileRead|EFileWrite);
	testAndLog(r==KErrNone);
	TFileName sn;
	r = TheFs.GetShortName(KTestNormalFileName, sn);
	testAndLog(r==KErrNone);
	r = sn.Compare(KTestNormalFileShortName);
	testAndLog(r==0);
	TheFile.Close();
	
	test.Printf(_L("Access the file with the DLL installed"));
	r=TheFile.Open(TheFs,KTestNormalFileName,EFileWrite);
	testAndLog(r==KErrNone);
	
	TBuf<50> name;	
	r=TheFile.FullName(name);
	testAndLog(r==KErrNone);
	TheFile.Close();
	
	r=TheFile.Open(TheFs,KTestNormalFileShortName,EFileWrite);
	testAndLog(r==KErrNone);
	TheFile.Close();
	
	r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
	testAndLog(r==KErrNone);
	
	test.Printf(_L("Access the file without the DLL installed"));
	
	r=TheFile.Open(TheFs,KTestNormalFileName,EFileWrite);
	testAndLog(r==KErrNone);

	r=TheFile.FullName(name);
	testAndLog(r==KErrNone);
	TheFile.Close();
	
	r=TheFile.Open(TheFs,KTestNormalFileShortName,EFileWrite);
	testAndLog(r==KErrNone);
	TheFile.Close();
	
	r=TheFs.Delete(KTestNormalFileName);
	failedOnBuf.Close();
	tcUniquePath.Close();
	__UHEAP_MARKEND;
	}
Esempio n. 22
0
void CCmdYmodem::DoRunL()
	{
	PrepareConsoleToTransferL();

	if (iMode == EReceive)
		{
		TPtrC receiveDir;
		if (iFileNames.Count() > 1)
			{
			PrintError(KErrArgument, _L("Too many arguments - only the receive directory may be specified in receive mode."));
			User::Leave(KErrArgument);
			}
		else if (iFileNames.Count() == 1)
			{
			TFileName2 fileName(iFileNames[0]);
			receiveDir.Set(iFileNames[0]);

			if ((fileName.Exists(FsL()) && !fileName.IsDirL(FsL())) || (!fileName.Exists(FsL()) && !iOverwrite))
				{
				LeaveIfErr(KErrArgument, _L("\"%S\" is not a directory"), &fileName);
				}
			}
		else
			{
			receiveDir.Set(Env().Pwd());
			}

		Progress(_L("YMODEM receive to \"%S\"\r\n"), &receiveDir);
		RArray<TFileName2> receivedFiles;
		CleanupClosePushL(receivedFiles);
		TFailedFile failedFile;
		TBool finished(EFalse);
		while (!finished)
			{
			TSyncResult syncResult = SendSyncL();
			if (syncResult == EEot)
				{
				finished = ETrue;
				}
			else
				{
				iPacketNumber = 0;
				TBool isFinalBlock(EFalse);
				TPtrC block(ReceiveBlockL(ETrue, isFinalBlock));
				TPtrC fileName(block.Ptr()); // filename is the first null terminated string in the block.
				if (fileName.Length() > 0)
					{
					TFileName2 fileName2(fileName);
					fileName2.MakeAbsoluteL(receiveDir);
					TLex lex(block.Mid(fileName.Length() + 1));
					TInt size;
					User::LeaveIfError(lex.Val(size));
					TInt err = KErrNone;
					if (!iOverwrite && fileName2.Exists(FsL()))
						{
						err = KErrAlreadyExists;
						}
					RFile file;
					if (err == KErrNone)
						{
						if (size == 0)
							{
							if (iOverwrite)
								{
								err = file.Replace(FsL(), fileName2, EFileWrite);
								}
							else
								{
								err = file.Create(FsL(), fileName2, EFileWrite);
								}
							}
						else
							{
							Progress(_L("Starting receive of \"%S\" (%d bytes)\r\n"), &fileName, size);
							SendSyncL();
							TRAP(err, ReceiveToFileL(fileName2));
							if (err == KErrNone)
								{
								err = file.Open(FsL(), fileName2, EFileWrite);
								if (err == KErrNone)
									{
									err = file.SetSize(size);
									}
								}
							else
								{
								Fs().Delete(fileName2);
								}
							}
						}
					else
						{
						TRAP_IGNORE(ReceiveToNullL());
						}
					file.Close();
					if (err)
						{
						failedFile.iError = err;
						failedFile.iFileName = fileName2;
						finished = ETrue;
						}
					else
						{
						receivedFiles.Append(fileName2); // Ignore error.
						}
					}
				else
					{
					finished = ETrue;
					}
				}
			}

		CleanupClonsoleAfterTransferL();

		const TInt numFilesReceived = receivedFiles.Count();
		if (numFilesReceived == 0)
			{
			if (failedFile.iError == KErrNone)
				{
				Printf(_L("No files to receive.\r\n"));
				}
			}
		else if (numFilesReceived == 1)
			{
			const TFileName2& fileName = receivedFiles[0];
			Printf(_L("Successfully received \"%S\".\r\n"), &fileName);
			}
		else
			{
			Printf(_L("Successfully received:\r\n"));
			for (TInt i = 0; i < numFilesReceived; ++i)
				{
				const TFileName2& fileName = receivedFiles[i];
				Printf(_L("\t\"%S\"\r\n"), &fileName);
				}
			}

		if (failedFile.iError)
			{
			PrintError(failedFile.iError, _L("Failed to receive \"%S\""), &failedFile.iFileName);
			}
		CleanupStack::PopAndDestroy(&receivedFiles);
		}
	else if (iMode == ESend)
		{
		const TInt numFiles = iFileNames.Count();
		if (numFiles == 0)
			{
			PrintError(KErrArgument, _L("No files to send specified"));
			User::Leave(KErrArgument);
			}
		for (TInt i = 0; i < numFiles; ++i)
			{
			const TFileName2& fileName = iFileNames[i];
			if (fileName.Exists(FsL()))
				{
				if (fileName.IsDirL(FsL()))
					{
					LeaveIfErr(KErrArgument, _L("\"%S\" is not a file"), &fileName);
					}
				}
			else
				{
				LeaveIfErr(KErrArgument, _L("\"%S\" does not exist"), &fileName);
				}
			}
		WaitForSyncL();
		HBufC* buf = HBufC::NewLC(iBlockSize);
		TPtr bufPtr(buf->Des());
		for (TInt i = 0; i < numFiles; ++i)
			{
			const TFileName2& fileName = iFileNames[i];
			LeaveIfFileNotFound(fileName);
			TEntry entry;
			User::LeaveIfError(FsL().Entry(fileName, entry));
			bufPtr.SetLength(bufPtr.MaxLength());
			bufPtr.FillZ();
			bufPtr.Copy(fileName.NameAndExt());
			bufPtr.SetLength(buf->Length() + 1); // To leave a terminating null after the file name.
			bufPtr.AppendNum(entry.iSize);
			if (bufPtr.Length() < iBlockSize)
				{
				// There's not enough data to fill this block, so pad with NULL.
				bufPtr.AppendFill(0, iBlockSize - bufPtr.Length());
				}
			iPacketNumber = 0;
			SendBlockL(*buf);
			WaitForSyncL();
			SendFileL(fileName);
			}
		iPacketNumber = 0;
		bufPtr.SetLength(bufPtr.MaxLength());
		bufPtr.FillZ();
		SendBlockL(*buf);
		CleanupStack::PopAndDestroy(buf);
		CleanupClonsoleAfterTransferL();

		if (numFiles == 1)
			{
			Printf(_L("Successfully sent \"%S\".\r\n"), &iFileNames[0]);
			}
		else
			{
			Printf(_L("Successfully sent:\r\n"));
			for (TInt i = 0; i < numFiles; ++i)
				{
				const TFileName2& fileName = iFileNames[i];
				Printf(_L("\t\"%S\"\r\n"), &fileName);
				}
			}
		}
	User::LeaveIfError(Stdin().CancelCaptureAllKeys());
	}
Esempio n. 23
0
void DoLog(const TDesC& aText)
{
    static const TInt KLogEntryMaxLength = 128;
    _LIT(KLineFeed, "\n");



    /**
     *  Log time format (see TTime) is
     *  Day-Month-Year Hours:Minutes:Seconds:Milliseconds
     *
     *  Example: 30-12-2004 23:00:55:990
     */
    _LIT(KLogTimeFormat, "%F%D-%M-%Y %H:%T:%S:%*C3");

    TBuf8<KLogEntryMaxLength> writeBuffer;
    RFs FileServer;
    RFile File;

    if(FileServer.Connect() != KErrNone)
    {
        FileServer.Close(); // just in case
        User::Panic(KLogPanicCategory(), KPanicFsConnectFailed);
        return;
    }

    // Open file for writing, if exists. Othervise create new file.
    if(File.Open(FileServer, KLogFileName(), EFileWrite) != KErrNone)
    {
        if(File.Create(FileServer, KLogFileName(), EFileWrite) != KErrNone)
        {
            FileServer.Close();
            User::Panic(KLogPanicCategory(), KPanicFileCreateFailed);
        }
    }

    TTime currentTime;
    currentTime.UniversalTime();
    TBuf<32> timeString;

    // currentTime is now in universal time. Convert it to home time.
    TLocale locale;
    TTimeIntervalSeconds universalTimeOffset(locale.UniversalTimeOffset());
    TTimeIntervalHours daylightSaving(0);
    if(locale.QueryHomeHasDaylightSavingOn())
    {
        daylightSaving = 1;
    }
    currentTime = currentTime + universalTimeOffset + daylightSaving;
    TInt leaveCode(KErrNone);
    TRAP(leaveCode, currentTime.FormatL(timeString, KLogTimeFormat));
    leaveCode = 0; // not used
    // Add LogString to the end of file and close the file
    TInt currentSize = 0, returnCode;
    writeBuffer.Append(timeString);
    writeBuffer.Append(_L(": "));
    writeBuffer.Append(aText.Left(KLogEntryMaxLength-timeString.Length()));
    writeBuffer.Append(KLineFeed);
    File.Size(currentSize);
    returnCode = File.Write(currentSize,
                            writeBuffer,
                            writeBuffer.Length());
    File.Close();
    // Close file server session
    FileServer.Close();

    if(returnCode != KErrNone)
    {
        User::Panic(KLogPanicCategory(), KPanicFileWriteFailed);
    }
}
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();
	}
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();
	}
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();
	}
Esempio n. 27
0
void LogTestFailureData(TTCType tcType, TFileName failedOn, 
					TUint tcId, TFileName tcUniquePath, TInt line)
	{
	if(tcType == EUnitaryTest)
		gLogFailureData.iTCTypeName = KUnitary;
	else if(tcType == EBinaryTest)
		gLogFailureData.iTCTypeName = KBinary;
	gLogFailureData.iTCFailureOn = failedOn;
	gLogFailureData.iTCId = tcId;
	gLogFailureData.iTCUniquePath.Copy(tcUniquePath);
	gLogFailureData.iLineNum = line;
	gLogFailureData.iFileName.Copy(gFileName);

	RFile file;
	TBuf8<256>	tempBuf;

	TFileName logFileName;
	if(gIOTesting)
		{
		if(failedOn == KExecution)
			{
			logFileName.Append(KExeLogFileName);
			}
		else
			{
			logFileName.Append(KVerLogFileName);
			}
		}
	else
		{
		logFileName.Append(KLogFileName);
		}

	logFileName.Append(KUnderScore);
	logFileName.Append(gDriveToTest);
	logFileName.Append(KExtension);

	TInt r = file.Create(TheFs, logFileName, EFileRead|EFileWrite);
	test_Value(r, r == KErrNone || r == KErrAlreadyExists);

	if (r == KErrNone)
		{
		tempBuf.Append(KLogFileHeader);
		file.Write(tempBuf);
		}

	if (r == KErrAlreadyExists)
		{
		r = file.Open(TheFs, logFileName, EFileRead|EFileWrite);
		test_KErrNone(r);
		TInt start = 0;
		r=file.Seek(ESeekEnd,start);
		test_KErrNone(r);
		}
	
	tempBuf.SetLength(0);
	tempBuf.Append(KNewLine);
	if(gIOTesting)
		tempBuf.Append(KYes);
	else
		tempBuf.Append(KNo);
	tempBuf.Append(KComma);
	file.Write(tempBuf);

	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iTCTypeName);
	tempBuf.Append(KComma);
	file.Write(tempBuf);

	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iTCFailureOn);
	tempBuf.Append(KComma);
	file.Write(tempBuf);

	tempBuf.SetLength(0);
	tempBuf.AppendNum(gLogFailureData.iTCId);
	tempBuf.Append(KComma);
	file.Write(tempBuf);
		
	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iTCUniquePath);
	tempBuf.Append(KComma);
	file.Write(tempBuf);
			
	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iFSName);
	tempBuf.Append(KComma);
	file.Write(tempBuf);
	
	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iExeOsName);
	tempBuf.Append(KComma);
	file.Write(tempBuf);

	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iExeDrive);
	tempBuf.Append(KComma);
	file.Write(tempBuf);
	
	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iVerOsName);
	tempBuf.Append(KComma);
	file.Write(tempBuf);
			
	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iVerDrive);
	tempBuf.Append(KComma);
	file.Write(tempBuf);
			
	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iAPIName);
	tempBuf.Append(KComma);
	file.Write(tempBuf);
	
	tempBuf.SetLength(0);
	tempBuf.AppendNum(gLogFailureData.iLineNum);
	tempBuf.Append(KComma);
	file.Write(tempBuf);
	
	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iFuncName);
	tempBuf.Append(KComma);
	file.Write(tempBuf);

	tempBuf.SetLength(0);
	tempBuf.Append(gLogFailureData.iFileName);
	file.Write(tempBuf);

	file.Close();
	}
Esempio n. 28
0
TInt CMusicPlayerImgEngine::GetAlbumArtFilename(const CMetadata &aMetadata, const TSize &aSize, TFileName &aCoverFilename, CImageDecoder **aDecoder) 
{
	/* Function returns KErrNotFound if we find nothing, it returns 0 if we find a file, and it returns 1 if the elemnt is in cache
	 * In aCacheIndex returns the cache index, if found there, or -1. If found in cache, the cache is updated.
	 * If NOT found in cache, aCoverFilename contains the cover filename. If aMetadata.iCover is valid (non-NULL)
	 * then the aCoverFilename is non-existent, e.g. e:\\Music\\Something\\Else.mp3_360.jpg The purpose in this case
	 * would be to identify the image in the cache.
	 * 
	 * The algorithm for finding the album art:
	 * 1. Check if there is aMetadata.iCover. If it does, check the cache, update aCoverFilename, return.
	 * 2. Check for KAlbumCoverNameGeneric (cover.jpg) in song's folder.
	 * 3. Check for KAlbumCoverNameGeneric2 (folder.jpg) in song's folder.
	 * 4. If aMetadata artist and album are non-NULL, check the Source/__Covers/Artist-Album.jpg
	 * 5. If enabled in Preferences, create a "hint" Source/__Covers/Artist-Album.hint having 0 bytes
	 * 6. If here, return KErrNotFound
	 */
	
	aMetadata.iFileDirEntry->GetFullPath(aCoverFilename,ETrue);
	LOG(ELogGeneral,1,"GetAlbumArtFilename++ (%S), iCover=%x",&aCoverFilename,aMetadata.iCover);

	TInt r,err;
	TEntry entry;
	
	*aDecoder=NULL;
	if(aMetadata.iCover) {
		aMetadata.iFileDirEntry->GetFullPath(aCoverFilename);
		//check if we have this in cache
		if(IsInCache(aCoverFilename,aSize)) {
			LOG(ELogGeneral,-1,"GetAlbumArtFilename-- (we have embedded cover, in cache)");
			return 1; 
		}
		else {
			TRAP(err,*aDecoder=CImageDecoder::DataNewL(iEikEnv->FsSession(),*aMetadata.iCover));
			if(!err) {
				LOG(ELogGeneral,-1,"GetAlbumArtFilename-- (we have embedded cover)");
				return 0; 
			}
			else LOG0("Instantiating a CImageDecoder for the embedded cover failed. Checking other options.");
		}
	}
	
	//check for KAlbumCoverNameGeneric
	aMetadata.iFileDirEntry->iParent->GetFullPath(aCoverFilename,ETrue);
	TInt pathLength=aCoverFilename.Length();
	aCoverFilename.Append(KAlbumCoverNameGeneric);
	if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
		return r;
	
	//check for KAlbumCoverNameGeneric2
	aCoverFilename.SetLength(pathLength);
	aCoverFilename.Append(KAlbumCoverNameGeneric2);
	if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
		return r;
	
	//if we are here, we need to check if we have valid Artist and Album metadata
	if(aMetadata.iAlbum && aMetadata.iArtist)
	{
		//we can construct Source/__Covers/Artist-Album.jpg
		aMetadata.iFileDirEntry->GetSource()->GetFullPath(aCoverFilename,ETrue);
		aCoverFilename.Append(KCoversFolderName);
		pathLength=aCoverFilename.Length();
		if(pathLength+aMetadata.iArtist->Length()+aMetadata.iAlbum->Length()+6<=KMaxFileName) //6= the dash + length of .jpg or .jpeg or .hint
		{
			//check for __Covers/Artist-Album.jpg
			aCoverFilename.Append(*aMetadata.iArtist);
			aCoverFilename.Append('-');
			aCoverFilename.Append(*aMetadata.iAlbum);
			aCoverFilename.Append(KAlbumCoverExtension);
			if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
				return r;
			
			//if we are here, the file does not exist!
			if((iPreferences->iPFlags&CMLauncherPreferences::EPreferencesCreateCoverHintFiles) &&
					(pathLength+KIgnoreFolderName().Length()+aMetadata.iArtist->Length()+aMetadata.iAlbum->Length()+6<=KMaxFileName)) //filename size requirements
			{
				//check first if the hint file is in the "IGNORE" folder
				aCoverFilename.SetLength(pathLength);
				aCoverFilename.Append(KIgnoreFolderName);
				aCoverFilename.Append(*aMetadata.iArtist);
				aCoverFilename.Append('-');
				aCoverFilename.Append(*aMetadata.iAlbum);
				aCoverFilename.Append(KHintFileExtension);
				if(iEikEnv->FsSession().Entry(aCoverFilename,entry)){
					//the hint file was not found in the IGNORE folder
					//we should create a hint file
					aCoverFilename.SetLength(pathLength);
					aCoverFilename.Append(*aMetadata.iArtist);
					aCoverFilename.Append('-');
					aCoverFilename.Append(*aMetadata.iAlbum);
					aCoverFilename.Append(KHintFileExtension);
					LOG0("Creating hint file for %S",&aCoverFilename);
					//first, we try to make the folder
					if(!iEikEnv->FsSession().MkDir(aCoverFilename.Left(pathLength))){
						//set the entry as hidden
						TTime modifTime;
						modifTime.UniversalTime();
						iEikEnv->FsSession().SetEntry(aCoverFilename.Left(pathLength),modifTime,KEntryAttHidden,0);
					}
					//now we create the file, IF it does not exist
					if(iEikEnv->FsSession().Entry(aCoverFilename,entry)){
						RFile f;
						if((err=f.Create(iEikEnv->FsSession(),aCoverFilename,EFileWrite))){
							LOG0("Creating %S hint file failed with error %d",&aCoverFilename,err);
						}
						else {
							LOG0("Hint file %S created successfully!",&aCoverFilename);
							f.Close();
						};
					}
				}
			}
			
			//check __Covers/Album.jpg
			aCoverFilename.SetLength(pathLength);
			aCoverFilename.Append(*aMetadata.iAlbum);
			aCoverFilename.Append(KAlbumCoverExtension);
			if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
				return r;
						
			//check __Covers/Artist.jpg
			aCoverFilename.SetLength(pathLength);
			aCoverFilename.Append(*aMetadata.iArtist);
			aCoverFilename.Append(KAlbumCoverExtension);
			if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
				return r;
			
		}//if(pathLength+ ...
	}//if(aMetadata.iAlbum && aMetadata.iArtist)
	
	//if we are here, we did not find a cover art anywhere, so we will use the generic cover art
	//first, check if the user has specified their own album art, and try to decode that
	aCoverFilename.Copy(KAlternateGenericAlbumArtName);
	if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
		return r;
	
	//if we are here, we will use generic album art
	LOG(ELogGeneral,-1,"GetAlbumArtFilename-- (no match found, use generic)");
	*aDecoder=NULL;
	return KErrNotFound;
}
Esempio n. 29
0
LOCAL_C void DoTestName(const TDesC& aName,TInt anError)
//
// Check errors returned
//
	{

	TBuf<32> goodName=_L("\\GOODNAME.TXT");
	TBuf<32> badName=_L("\\< > : \" / |");
	TParse parser;
	TInt r=parser.Set(aName,NULL,NULL);
	test_Value(r, r == KErrNone || r==anError);
	goodName.Insert(0,parser.Drive());
	badName.Insert(0,parser.Drive());
	
	
	TBuf<KMaxFileName> name;	//	We need an 8-bit name to test RFs::GetLongName() in 
	name.Copy(aName);			//	both builds

	TFileName dummy;			//	To use as an argument to RFs::GetLongName() will store the 
	TBuf<12> dummyShortName;	//	To use as an argument to RFs::GetShortName()
	TUint dumVal;
	TTime dumTime;
	TBool dumAnswer;
	TEntry dumEntry;
	CDir* dumDir;
	TUidType dumUid;
	TInt dumInt=0;
	TFileName badPath=aName;
	badPath.Append(_L("\\"));

//	Test MKDIR with filename containing \000
	TBuf<32> emptyName;
	emptyName.Format(_L("\\%c\\"),0);
	emptyName.Insert(0,parser.Drive());
	r=TheFs.MkDir(emptyName);
	TestReturnValue(r, anError);
	emptyName.Format(_L("\\Big%cGreen\\"),0);
	emptyName.Insert(0,parser.Drive());
	r=TheFs.MkDir(emptyName);
	TestReturnValue(r, anError);
	r=TheFs.SetSessionPath(badPath);
	TestReturnValue(r,KErrBadName); // Do not check drives
	r=TheFs.MkDir(badPath);
	TestReturnValue(r,anError);
	r=TheFs.MkDirAll(badPath);
	TestReturnValue(r,anError);
	r=TheFs.RmDir(badPath);
	TestReturnValue(r,anError);
	r=TheFs.GetDir(aName,dumInt,dumInt,dumDir);
	TestReturnValue(r,anError);
	r=TheFs.GetDir(aName,dumInt,dumInt,dumDir,dumDir);
	TestReturnValue(r,anError);
	r=TheFs.GetDir(aName,dumUid,dumInt,dumDir);
	TestReturnValue(r,anError);
	r=TheFs.Delete(aName);
	TestReturnValue(r,anError);

	r=TheFs.Rename(aName,goodName);
	TestReturnValue(r,anError);
	r=TheFs.Rename(aName,badName);
	TestReturnValue(r,anError);
	r=TheFs.Rename(goodName,aName);
	TestReturnValue(r,anError);
	r=TheFs.Rename(badName,aName);
	TestReturnValue(r,anError);

	r=TheFs.Replace(aName,goodName);
	TestReturnValue(r,anError);
	r=TheFs.Replace(aName,badName);
	TestReturnValue(r,anError);
	r=TheFs.Replace(goodName,aName);
	TestReturnValue(r,anError);
	r=TheFs.Replace(badName,aName);
	TestReturnValue(r,anError);

	r=TheFs.Att(aName,dumVal);
	TestReturnValue(r,anError);
	r=TheFs.SetAtt(aName,dumInt,dumInt);
	TestReturnValue(r,anError);
	r=TheFs.Modified(aName,dumTime);
	TestReturnValue(r,anError);
	r=TheFs.SetModified(aName,dumTime);
	TestReturnValue(r,anError);
	r=TheFs.Entry(aName,dumEntry);
	TestReturnValue(r,anError);
	r=TheFs.SetEntry(aName,dumTime,dumInt,dumInt);
	TestReturnValue(r,anError);
	r=TheFs.IsFileOpen(aName,dumAnswer);
	TestReturnValue(r,anError);

	r=TheFs.GetShortName(aName,dummyShortName);
	TestReturnValue(r,anError);
	r=TheFs.GetLongName(name,dummy);
	TestReturnValue(r,anError);
	
	RFile f;
	r=f.Open(TheFs,aName,EFileWrite);
	TestReturnValue(r,anError);
	r=f.Create(TheFs,aName,EFileWrite);
	TestReturnValue(r,anError);
	r=f.Replace(TheFs,aName,EFileWrite);
	TestReturnValue(r,anError);
	RDir d;
	r=d.Open(TheFs,aName,KEntryAttNormal);
	TestReturnValue(r,anError);
	r=d.Open(TheFs,aName,dumUid);
	TestReturnValue(r,anError);
	}
Esempio n. 30
0
void T_CntImageRescaler::testRescaleUtility()
{
    // delete the possible image directory, it must not leave
    // even if the folder was not found. 
    TRAPD( err, TCntImageRescaleUtility::DeleteImageDirectoryL() );
    test( err == KErrNone );
    
    // path for image directory, existense of the directory is not
    // checked
    TPath path = TCntImageRescaleUtility::ImageDirectoryL();
    test( path.Length() > 0 );
    test( path.Find(KImagesFolder) != KErrNotFound );
    
    TPath dir = TCntImageRescaleUtility::CreateImageDirectoryL();
    test( dir.Length() > 0 );
    test( dir.Find( KImagesFolder) != KErrNotFound );
  
    // make a test image file (empty file) 
    RFs fs;
    CleanupClosePushL( fs );
    User::LeaveIfError( fs.Connect() );
    
    TPath imagePath;
    imagePath.Append( dir );
    imagePath.Append( KImageName );
    
    RFile file;
    CleanupClosePushL(file);
    User::LeaveIfError(file.Create( fs, imagePath, EFileWrite ));
    CleanupStack::PopAndDestroy();
    
    CContactItem* item  = CContactItem::NewLC(KUidContactCard);
    CContactItemField* field = CContactItemField::NewL( KStorageTypeText, KUidContactFieldCodImage );
    field->SetMapping( KUidContactFieldVCardMapUnknown );
    item->AddFieldL( *field );

    // add image without GUID
    TRAPD( err2, TCntImageRescaleUtility::StoreImageFieldL( *item, imagePath ) );
    test( err2 == KErrNone );
    
    // then update with GUID value
    _LIT(KGuid, "guid");
    TBufC<4> buffer ( KGuid );
    item->SetUidStringL( buffer );
    
    TRAPD( err3, TCntImageRescaleUtility::UpdateImageNameL( *item ) );
    test( err3 == KErrNone );
    
    CContactItemFieldSet& fields = item->CardFields();
    TInt privateImageIndex = fields.Find( KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown );
    test( privateImageIndex != KErrNotFound );
    
    TPtrC fieldText = fields[privateImageIndex].TextStorage()->Text();
    
    // how it should look like
    TPath newPath;
    newPath.Append( TCntImageRescaleUtility::ImageDirectoryL() );
    newPath.Append( buffer );
    newPath.Append( KImageName );
    RDebug::Print( _L("%S"), &newPath );
    RDebug::Print( _L("%S"), &fieldText );
    
    test( newPath.Compare(fieldText) == 0 );
    BaflUtils::DeleteFile( fs, newPath );
    CleanupStack::PopAndDestroy(2); // item, RFs
}