/**
    Testing the case of passing a directory name longer than KMaxFileName to the file server.
    KErrBadName shall be the result
*/
LOCAL_C void DoTestLongDirName2(void)
{
    RFs         rfs;
    TBool       bDirExisted=EFalse;

    CleanupClosePushL(rfs);    
    test(rfs.Connect() == KErrNone);
    
    //-- create a dir c:\a
    _LIT(dirName, "C:\\a\\");
    TInt err = rfs.MkDir(dirName);
    test_Value(err, err == KErrNone || err == KErrAlreadyExists);
    
    if(err == KErrAlreadyExists)
        bDirExisted = ETrue;
    
    //-- dir name longer than KMaxFileName
    _LIT(longDirName, "C:\\a\\longnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongname\\");
    //TInt nLen = dirName().Length();
    
    //-- try to create a directory with a very long name, checking that it doesn't get truncated to the "c:\a"
    err = rfs.MkDir(longDirName);
    test_Value(err, err == KErrBadName);

    //-- clean up, remove created directory, otherwise some ill-designed tests can fail
    if(!bDirExisted)
        rfs.RmDir(dirName);
    
    CleanupStack::PopAndDestroy(1); // rfs
}
void CTE_comsdbgServer::InitDir()
	{
	RFs fs;
	fs.Connect();
	fs.MkDir(KFloggerOutputDir);
	fs.MkDir(KTestResultsDir);
	fs.Close();
			
	}
//
// Prepare the test directory.
//
static void SetupTestDirectory()
    {
	TInt r=TheFsSession.MkDir(KTestDir);
	TEST(r==KErrNone || r==KErrAlreadyExists);
	r=TheFsSession.SetSessionPath(KTestDir);
	TEST2(r,KErrNone);
	}
TInt CopyDataFile::CopyToPublicL(TDesC& aFileName)
{
	TInt ret=KErrNone;
	RFs iRFs;
	
	User::LeaveIfError(iRFs.Connect());	
	CFileMan* fileMan=CFileMan::NewL(iRFs);	
	
	//get the sid and convert it to hex
	TSecureId sid = RProcess().SecureId();
	TBuf<20> hex;	
	hex.Num(sid, EHex);
	hex.Append(_L("\\"));
	
	//generate the target path - C:\\ShellPublic\\$SID
	TBuf<128> path(_L("C:\\ShellPub\\"));
	path.Append(hex);
	
	//create the target directory
	TBuf<128> file (path);			
	ret=iRFs.MkDir(path);
	
	if(ret==KErrNone || ret==KErrAlreadyExists)
		{		
		//generate the absolute path of the target file
		file.Append(aFileName);
		//copy the file 
		ret=fileMan->Copy(aFileName, file);	
		}		
	
	iRFs.Close();
	delete fileMan;
	
	return ret;
}
// ---------------------------------------------------------------------------
// ConstructL, 2nd Constructor
// ---------------------------------------------------------------------------
//
void CBCTestLogger::ConstructL()
    {
    TInt err = KErrNone;    
    
    iEikEnv = CEikonEnv::Static();
    RFs tempServer = iEikEnv->FsSession();    
    
    // \BCTestLog directory created if doesn't exist
    err = tempServer.MkDir( KPathBase );
    if ( err == KErrAlreadyExists || err == KErrNone )  
        {
        err = KErrNone; // Directory already exists - no error
        }        
    else
        {
        User::Leave(err);
        }
        
    // Read version of bc test from realease_note.txt.
    RFile vFile;
    User::LeaveIfError( 
	    vFile.Open( tempServer, KVersionFile, EFileRead | EFileShareAny ) != KErrNone );                
    
    TBuf<KMaxLength> versionLine;
	ReadLineL( vFile, versionLine);
    vFile.Close();
    	    
    // Create autotest results log filename
    iAtLogFileName = KPathBase;
    iAtLogFileName.Append( AppCaption() );
    iAtLogFileName.Append( KBCTestLogEnd );    
    
    // Open log file for autotest results.
    // If the file already exists, replace it.
    err = iAtLogFile.Replace( tempServer,
                              iAtLogFileName,
                              EFileWrite | EFileStreamText );

    if (err != KErrNone)
        {
        User::Leave( err );
        }

    iBuf.Zero();
    // Write version of bc tester in log file.
    iBuf.Append( KVersion );    
    iBuf.Append( versionLine );
    iBuf.Append( KLineEnd );
    iBuf.Append( KGeneralLogInfo );
    TTime homeTime;
    homeTime.HomeTime();
    TBuf<KTempBufferLenth> tempBuf;
    homeTime.FormatL( tempBuf, KDateTimeFormat );    
    iBuf.Append( tempBuf );    
    iBuf.Append( KLogTwoLine );          
    WriteToFileL( iAtLogFile, iBuf );
    
    CreateMainLogL();
    }
//Creates file session instance and the test directory
void CreateTestEnv()
    {
	TInt err = TheFs.Connect();
	TheTest(err == KErrNone);

	err = TheFs.MkDir(KTestDir);
	TEST(err == KErrNone || err == KErrAlreadyExists);
	}
void TestEnvInit()
    {
	TInt err = TheFs.Connect();
	TEST2(err, KErrNone);

	err = TheFs.MkDir(KTestDir);
	TEST(err == KErrNone || err == KErrAlreadyExists);
	}
Exemple #8
0
//Prepares the test directory.
//TheFs.Connect() has to be called already.
static void SetupTestDirectory()
    {
	TInt err = TheFs.MkDir(KTestDatabase);
	if(err != KErrNone)
	    {
	    RDebug::Print(_L("*** SetupTestDirectory(), RFs::MkDir(), err=%d\r\n"), err);
	    }
	TEST(err == KErrNone || err == KErrAlreadyExists);
	}
void CSqlSrvTestBurInterface::Construct()
	{
	TInt err = iFs.Connect();
	TEST2(err, KErrNone);

	err = iFs.MkDir(KTestDir);
	TEST(err == KErrNone || err == KErrAlreadyExists);

	err = iFs.CreatePrivatePath(KTestDrive);
	TEST(err == KErrNone || err == KErrAlreadyExists);
	}
void CreateTestDir()
    {
    RFs fs;
	TInt err = fs.Connect();
	TEST2(err, KErrNone);

	err = fs.MkDir(KTestDir);
	TEST(err == KErrNone || err == KErrAlreadyExists);
	
	fs.Close();
	}
void CreateTestEnv()
{
    TInt err = TheFs.Connect();
    TEST2(err, KErrNone);

    err = TheFs.MkDir(KTestDir);
    TEST(err == KErrNone || err == KErrAlreadyExists);

    err = TheFs.CreatePrivatePath(EDriveC);
    TEST(err == KErrNone || err == KErrAlreadyExists);
}
// Prepare the test directory.
LOCAL_C void setupTestDirectory()
    {
	TInt err=TheFs.Connect();
	TEST2(err, KErrNone);

	TPtrC testDir=_L("\\STOR-TST\\");
	err=TheFs.MkDir(testDir);
	TEST(err == KErrNone || err == KErrAlreadyExists);

	err=TheFs.SetSessionPath(testDir);
	TEST2(err, KErrNone);
	}
Exemple #13
0
int PosixFilesystem::mkdir (RFs& aFs, const wchar_t* aPath, int perms, int& anErrno)
{
    TParse name;
    TInt err=GetFullPath(name,(const TText16 *)aPath,aFs,NULL);
    if (!err)
    {
        TPtrC path=name.DriveAndPath();
        err=aFs.MkDir(path);
        if (!err)
        {
            if ((perms&S_IWUSR)==0)
                err=aFs.SetAtt(path,KEntryAttReadOnly,0);
        }
    }
    return MapError(err,anErrno);
}
void CreateTestEnv()
    {
    RFs fs;
	TInt err = fs.Connect();
	TEST2(err, KErrNone);

	err = fs.MkDir(KTestDir);
	TEST(err == KErrNone || err == KErrAlreadyExists);

	err = fs.CreatePrivatePath(EDriveC);
	TEST(err == KErrNone || err == KErrAlreadyExists);

	fs.Close();

	sqlite3SymbianLibInit();
	}
void SetupTestEnv()
    {
	TInt err = TheFs.Connect();
	TEST2(err, KErrNone);

	err = TheFs.MkDir(KTestDir);
	TEST(err == KErrNone || err == KErrAlreadyExists);

	err = TheFs.CreatePrivatePath(EDriveC);
	TEST(err == KErrNone || err == KErrAlreadyExists);

	(void)RSqlDatabase::Delete(KTestDbName3);
	(void)RSqlDatabase::Delete(KTestDbName2);
	(void)RSqlDatabase::Delete(KTestDbName);
	(void)TheFs.Delete(KSqlSrvConfigFile);//The test does not work if there is a test config file.
	}
void CMtfTestActionSaveMsvIdParamToFile::ExecuteActionL()
	{
	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSaveMsvIdParamToFile);
		
	TMsvId messageId = ObtainValueParameterL<TMsvId>( TestCase(), ActionParameters().Parameter(0) );										
	HBufC* paramFilePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(1));
 
 	
 	RFs fs;
 	User::LeaveIfError( fs.Connect() );
 	CleanupClosePushL( fs );
 	
	TInt err = fs.MkDir( *paramFilePath ); 
	
	if ( ! ( (err == KErrNone ) || ( err == KErrAlreadyExists ) ) )
	{	
		User::LeaveIfError( err );
	}
	// else dir created successfully or already created.
	
	RFileWriteStream rf;
	err = rf.Open( fs , *paramFilePath , EFileWrite );
	if ( err == KErrNotFound )
	{
		err = rf.Create( fs, *paramFilePath , EFileWrite );
	}	
	User::LeaveIfError(err);
	
	rf.PushL();
		// Writes may leave.
		
	rf << messageId; 

	rf.CommitL();
	rf.Pop();
	rf.Release();
			
 	CleanupStack::PopAndDestroy(); // fs

	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSaveMsvIdParamToFile);
	TestCase().ActionCompletedL(*this);	
	
	
	}
void CreateNewTestFileL(TDesC& aFileName)
	{
	RFs fs;
	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);	
	if (aFileName.Length() > 0 && aFileName[aFileName.Length() - 1] == KPathDelimiter)
		{  // A new test directory is created
		User::LeaveIfError(fs.MkDir(aFileName));
		}
	else
		{  // A new test file is created
		RFile newFile;
		CleanupClosePushL(newFile);
		CIntegrityServices::SimulatePowerFailureL(CIntegrityServices::EFailAddingNewFile, CIntegrityServices::EBeforeAction, aFileName);
		User::LeaveIfError(newFile.Create(fs, aFileName, EFileWrite));
		CIntegrityServices::SimulatePowerFailureL(CIntegrityServices::EFailAddingNewFile, CIntegrityServices::EAfterAction, aFileName);
		CleanupStack::PopAndDestroy(&newFile);		
		}
	CleanupStack::PopAndDestroy(&fs);	
	}
//Usage: "t_dbperf3 [<drive letter>:]"
TInt E32Main()
    {
	TheTest.Title();
	
	TheTrapCleanup = CTrapCleanup::New();
	TEST(TheTrapCleanup != NULL);
	
	//Construct test database file name
	_LIT(KTestDatabase, "c:\\dbms-tst\\t_dbperf3.db");
	TFileName fname;
	User::CommandLine(fname);
	TParse parse;
	parse.Set(fname, &KTestDatabase, 0);
	const TDesC& dbFilePath = parse.FullName();
	TheDatabaseFileName.Copy(dbFilePath);
	TheTest.Printf(_L("Test database: %S\r\n"), &TheDatabaseFileName);

	__UHEAP_MARK;

	TInt err = TheFs.Connect();
	TEST2(err, KErrNone);
	err = TheFs.MkDir(TheDatabaseFileName);
	TheTest.Printf(_L("MkDir(): err=%d\r\n"), err);
	TEST(err == KErrNone || err == KErrAlreadyExists);

	DeleteFile(TheDatabaseFileName);

	TRAP(err, DoTestL());
	TEST2(err, KErrNone);

	CloseAll();
	DeleteFile(TheDatabaseFileName);

	__UHEAP_MARKEND;

	TheTest.End();
	TheTest.Close();
	
	delete TheTrapCleanup;
	return KErrNone;
    }
// --------------------------------------------------------------------------
// CUPnPFileSharingEngine::StoreSharedContainerIDsL
// Creates main containers and starts sharing them
// --------------------------------------------------------------------------
//
TInt CUpnpSelectionWriter::StoreSharedContainerIDsL() const
    {
    __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );

    // Leave if aIdArray = NULL
    if ( !iFileArray )
        {
        User::Leave(KErrArgument);
        }

    RFs fs;
    RFile file;
    User::LeaveIfError( fs.Connect() );
    CleanupClosePushL(fs);

    TFileName directory;

    // Get private directory path
    fs.SessionPath(directory);

    // Try to create directory
    TInt error = fs.MkDir(directory);
    // it's ok if directory already exists
    if (!(error != KErrNone && error != KErrAlreadyExists))
        {

        // Add file name
        if ( iMediaType == EImageAndVideo )
            {
            directory.Append( KVisualFile );
            }
        else if ( iMediaType == EPlaylist )
            {
            directory.Append( KMusicFile );
            }

        error = file.Replace(fs, directory, EFileWrite );
        if ( !error )
            {
            CleanupClosePushL( file );
            RFileWriteStream writeStream(file);
            CleanupClosePushL( writeStream );

            for (TInt index = 0; index < iFileArray->Count(); index++)
                {
                // check that sharing of the container was succesful
                if ( iOkItems.Find( index ) != KErrNotFound )
                    {
                    // Write identifiers to the file
                    writeStream << iFileArray->MdcaPoint(index);
                    }
                }

            // Clean up
            CleanupStack::PopAndDestroy(&writeStream); // Close writeStream
            CleanupStack::PopAndDestroy(&file); // Close file
            }
        }
    CleanupStack::PopAndDestroy(&fs);
    __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
    return error;
    }
/**
  Function		: ExecuteActionL
  Description	: Entry point for the this test action in the test framework
  @internalTechnology
  @param		: none
  @return		: void
  @pre none 
  @post none
*/
void CMtfTestActionSetDiskSpace::ExecuteActionL()
	{
	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSetDiskSpace );
	
	RFs fs;
	User::LeaveIfError(fs.Connect());

	TInt newFreeValue = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(0));

	TestCase().INFO_PRINTF2(_L("Setting Drive C free disk space to %ld bytes."), newFreeValue);

	//
	// Check the current disk space available level...
	//
	TVolumeInfo  volumeInfo;
	
	User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
	TestCase().INFO_PRINTF2(_L("  Drive C currently has %ld bytes free."), volumeInfo.iFree);

	//
	// Check that this is possible...
	//	
	if (volumeInfo.iFree < newFreeValue)
		{
		TestCase().INFO_PRINTF1(_L("  Drive C already has too little free space!"));
		User::Leave(KErrArgument);
		}

	//
	// Ensure the temporary directory exists...
	//
	TInt ret;
	
	ret = fs.MkDir(KTempDiskSpaceDirName);
	if (ret != KErrNone  &&  ret != KErrAlreadyExists)
		{
		User::Leave(ret);
		}

	//
	// Work out how many files to create and their sizes. A full temp file is
	// 1GB in size, the last temp file will handle the remainder. Then loop
	// through and create them all...
	//
	TInt64  maxSizeOfTempFile  = (1024*1024*1024); 
	TInt64  diskSpaceToReserve = volumeInfo.iFree - newFreeValue;
	TInt64  numOfFullTempFiles = (diskSpaceToReserve / maxSizeOfTempFile);
	TInt64  lastTempFileSize   = (diskSpaceToReserve % maxSizeOfTempFile);
	TBuf<32>  tempFileName;
	RFile  file;

	for(TInt fileNum = 1;  fileNum <= numOfFullTempFiles;  fileNum++)
		{
		tempFileName.Copy(KTempDiskSpaceDirName);
		tempFileName.AppendFormat(_L("reserved.%d"), fileNum);

		TestCase().INFO_PRINTF3(_L("  Creating %S of %ld bytes."), &tempFileName, maxSizeOfTempFile);

		User::LeaveIfError(file.Replace(fs, tempFileName, EFileWrite));
		User::LeaveIfError(file.SetSize(maxSizeOfTempFile));	
		file.Close();
		}

	if (lastTempFileSize > 0)
		{
		User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
		TestCase().INFO_PRINTF2(_L("  Drive C now has %ld bytes free."), volumeInfo.iFree);
		
		if( lastTempFileSize > volumeInfo.iFree )
			{	
			lastTempFileSize = volumeInfo.iFree;
			}
		
		
		tempFileName.Copy(KTempDiskSpaceDirName);
		tempFileName.AppendFormat(_L("reserved.%d"), numOfFullTempFiles+1);

		TestCase().INFO_PRINTF3(_L("  Creating %S of %ld bytes."), &tempFileName, lastTempFileSize);

		User::LeaveIfError(file.Replace(fs, tempFileName, EFileWrite));
		User::LeaveIfError(file.SetSize(lastTempFileSize));	
		file.Close();
		}

	//
	// Recheck the free space now...
	//	
	User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
	TestCase().INFO_PRINTF2(_L("  Drive C now has %ld bytes free."), volumeInfo.iFree);


	fs.Close();

	TestCase().INFO_PRINTF2( _L("Test Action %S completed."), &KTestActionSetDiskSpace );
	TestCase().ActionCompletedL( *this );	
	}
TUid CDeploymentComponentData::ResolveUidL(RFs& aFs)
    {
    RDEBUG("CDeploymentComponentData::ResolveUidL()");

    TUid ret(TUid::Null() );
    HBufC* buf = HBufC::NewLC(KMaxFileName);
    TPtr16 ptr = buf->Des();
    ptr.Copy(iDataFileName);

    // if PIP/DRM package, we need to use license manager to extract the sis file
    if (iMimeType == KPipMimeType || iMimeType == KDrmMessageMimeType
            || iMimeType == KDrmContentMimeType)
        {
        RDEBUG8_2("	-> mime: %S", &iMimeType );

        RFile originalFile;
        RFile decryptedFile;
        TFileName decryptedTempFileName;

        RDEBUG_2("	-> opening original file: %S", &ptr );
        // leave if can not open the original file
        User::LeaveIfError(originalFile.Open(aFs, ptr, EFileWrite) );
        RDEBUG("	-> done");

        // First construct the temp path
        User::LeaveIfError(aFs.PrivatePath(decryptedTempFileName) );
        // set drive letter into the path
        decryptedTempFileName.Insert( 0, TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive() );
        // append "piptemp\\"	
        decryptedTempFileName.Append(KTempDir);
        // create the folder
        aFs.MkDir(decryptedTempFileName);

        // Use license manager to extract files from the pip package
        CDRMLicenseManager* licenseMgr = CDRMLicenseManager::NewL();
        CleanupStack::PushL(licenseMgr);
        // decryp from the original file into the temp file   
        RDEBUG_2("	-> extracting SIS file into: %S", &decryptedTempFileName);
        User::LeaveIfError(licenseMgr->ExtractSISFileL(originalFile,
                decryptedTempFileName) );
        RDEBUG("	-> done");

        // Get the sis file name 
        decryptedTempFileName.Append( *(licenseMgr->GetSISMemberL()->Name() ));
        // open temporary handle to it.
        RDEBUG_2("	-> opening decrypted file: %S", &decryptedTempFileName );
        User::LeaveIfError(decryptedFile.Open(aFs, decryptedTempFileName,
                EFileShareAny) );
        RDEBUG("	-> done");
        // parse the uid from the file
        ret = ParseUidFromSisFileL(decryptedFile);

        // no use anymore for the decrypted file
        decryptedFile.Close();
        // delete the temp file
        TInt err = aFs.Delete(decryptedTempFileName);
        if (err != KErrNone)
            {
            RDEBUG_2("**** ERROR, unable to delete temporary file: %S", &decryptedTempFileName );
            }

        CleanupStack::PopAndDestroy(licenseMgr);
        decryptedFile.Close();
        originalFile.Close();
        }
    else
        if (iMimeType == KSisxMimeType || iMimeType == KSisMimeType )
            {
            RDEBUG("	-> mime: x-epoc/x-sisx-app");
            RFile originalFile;
            RDEBUG_2("	-> opening file: %S", &ptr );
            User::LeaveIfError(originalFile.Open(aFs, ptr, EFileRead) );
            RDEBUG("	-> opened ok");
            ret = ParseUidFromSisFileL(originalFile);
            originalFile.Close();
            }

        else
            {
            RDEBUG8_2( "**** ERROR - CDeploymentComponentData::ResolveUidL( ) - cannot get uid from mime type: %S", &iMimeType );
            }

    CleanupStack::PopAndDestroy(buf);
    return ret;
    }