예제 #1
0
/**
@SYMTestCaseID			PDS-SQL-UT-4197
@SYMTestCaseDesc		RFileBuf64::Temp() file I/O error simulation test.
						The test calls RFileBuf64:Temp() in a file I/O error simulation loop.
@SYMTestActions			RFileBuf64::temp() file I/O error simulation test.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMDEF					DEF145198
*/
void TempFileIoErrTest()
	{
    TInt err = KErrGeneral;
    TInt cnt = 0;
    for(;err<KErrNone;++cnt)
        {
        TheTest.Printf(_L("===Iteration %d. Simulated error:\r\n"), cnt);       
        for (TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
            {
            TheTest.Printf(_L("%d "), fsError);
        	__UHEAP_MARK;
            (void)TheFs.SetErrorCondition(fsError, cnt);
        	RFileBuf64 fbuf(1024);//buffer capacity = 1024 bytes
        	TFileName tmpFileName;
			err = fbuf.Temp(TheFs, KTestDir, tmpFileName, EFileWrite | EFileRead);
            (void)TheFs.SetErrorCondition(KErrNone);
            fbuf.Close();
            __UHEAP_MARKEND;
			TInt err2 = TheFs.Delete(tmpFileName);
			TInt expectedErr = err == KErrNone ? KErrNone : KErrNotFound;
			TEST2(err2, expectedErr);
            }
        TheTest.Printf(_L("\r\n"));
        }
    TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt);
	}
예제 #2
0
	virtual void operator()()
		{
		RFileBuf64 fbuf(8192);
		RFs fs;
		TFileName fname;
		fbuf.Temp(fs, _L("c:\\test"), fname, EFileRead);//panic here - invalid file handle
		}
예제 #3
0
/**
@SYMTestCaseID			PDS-SQL-UT-4135
@SYMTestCaseDesc		RFileBuf64 write test 4.
						The test performs file write operations using RFileBuf64 class and verifies that
						that the pending write data will be stored in the file when the buffer is closed.
						The purpose of the test: to verify the logic of RFileBuf64::Write().
@SYMTestActions			RFileBuf64 write test 4.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void WriteTest4()
	{
	RFileBuf64 fbuf(1024);
	TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
	TEST2(err, KErrNone); 
    fbuf.ProfilerReset();

	// Data length: 10;
	err = fbuf.Write(0, _L8("A123456789"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 1);

	// Data length: 0;
	err = fbuf.Write(10, _L8(""));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 1);

	fbuf.Close();
	
	VerifyFileContent(_L8("A123456789"));
	
	(void)TheFs.Delete(KTestFile);
	}
예제 #4
0
/**
@SYMTestCaseID			PDS-SQL-UT-4196
@SYMTestCaseDesc		RFileBuf64::Open() file I/O error simulation test.
						The test calls RFileBuf64:Open() in a file I/O error simulation loop.
@SYMTestActions			RFileBuf64::Open() file I/O error simulation test.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMDEF					DEF145198
*/
void OpenFileIoErrTest()
	{
	RFileBuf64 fbuf(1024);//buffer capacity = 1024 bytes
	TInt err = fbuf.Create(TheFs, KTestFile3, EFileRead | EFileWrite);
	fbuf.Close();
	TEST2(err, KErrNone);
    err = KErrGeneral;
    TInt cnt = 0;
    for(;err<KErrNone;++cnt)
        {
        TheTest.Printf(_L("===Iteration %d. Simulated error:\r\n"), cnt);       
        for (TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
            {
            TheTest.Printf(_L("%d "), fsError);
        	__UHEAP_MARK;
            (void)TheFs.SetErrorCondition(fsError, cnt);
        	err = fbuf.Open(TheFs, KTestFile3, EFileRead | EFileWrite);
            (void)TheFs.SetErrorCondition(KErrNone);
            fbuf.Close();
            __UHEAP_MARKEND;
            }
        TheTest.Printf(_L("\r\n"));
        }
    TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt);
	(void)TheFs.Delete(KTestFile3);
	}
예제 #5
0
void labscale::LogPenetratorExperiment()
{
    // Let's do this without worrying about minimizing access to disk - it will be so much easier!
    ofstream fbuf(gRun.outFile.c_str(),ios::app);
    if (!fbuf.is_open()) {
        ncc__warning("Could not open log. Nothing written!\a\n");
        return;
    }

    // Collect
    PxReal t = gSim.codeTime;
    PxReal x = labscale::VIPs.ball1->getGlobalPose().p.x;
    PxReal y = labscale::VIPs.ball1->getGlobalPose().p.y;
    PxReal z = labscale::VIPs.ball1->getGlobalPose().p.z;
    PxReal d = y - labscale::impactor.diameter/2.0 - labscale::impactor.iniSurface;
    PxReal v = labscale::VIPs.ball1->getLinearVelocity().y;

    // Write
    fbuf.setf(ios::fixed);
    fbuf << setw(8) << t << "    ";
    fbuf << setw(8) << showpos << v << "    ";
    fbuf << setw(8) << showpos << d << "    ";
    fbuf << setw(8) << showpos << x << "    ";
    fbuf << setw(8) << showpos << y << "    ";
    fbuf << setw(8) << showpos << z << endl;
    fbuf.close();
}
예제 #6
0
	virtual void operator()()
		{
		RFileBuf64 fbuf(8192);
		RFs fs;
		TInt err = fs.Connect();
		TEST2(err, KErrNone);
		fbuf.Open(fs, KNullDesC, EFileRead);//panic here - invalid file name
		fs.Close();
		}
예제 #7
0
/**
@SYMTestCaseID			PDS-SQL-UT-4138
@SYMTestCaseDesc		RFileBuf64 read test 1.
						The test performs file read operations using RFileBuf64 class.
						Tested "read" operations:
							- Zero max length request;
							- Too big read request;
							- Read beyond the end of the file;
						The purpose of the test: to verify the logic of RFileBuf64::Read().
@SYMTestActions			RFileBuf64 read test 1.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void ReadTest1()
	{
	const TInt KBufMaxSize = 20;// This is half the file size
	RFileBuf64 fbuf(KBufMaxSize);
	TInt err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead | EFileShareReadersOrWriters);
	TEST2(err, KErrNone);
    fbuf.ProfilerReset();
    
	//Zero max length request
    TUint8 buf1[1];
	TPtr8 ptr1(buf1, 0);
	err = fbuf.Read(0, ptr1);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 0);
	TEST2(fbuf.iFileReadAmount, 0);
	TEST2(fbuf.iFileSizeCount, 0);

	//Too big request
	TBuf8<KBufMaxSize * 2> buf2;
	err = fbuf.Read(0, buf2);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 1);
	TEST2(fbuf.iFileReadAmount, (KBufMaxSize * 2));
	TEST2(fbuf.iFileSizeCount, 1);
	VerifyFileContent(buf2);
	
	//Read beyond the end of the file
	err = fbuf.Read(2000, buf2);
	TEST2(err, KErrNone); 
	TEST2(buf2.Length(), 0); 

	//Write "5678" in the buffer, pos [4..8)
	err = fbuf.Write(4, _L8("5678"));
	TEST2(err, KErrNone); 

	//Too big request. There are pending data in the buffer.
	TBuf8<KBufMaxSize + 2> buf3;
	err = fbuf.Read(1, buf3);
	TEST2(err, KErrNone); 
	VerifyFileContent(buf3, 1);

	//Read from a non-zero file position to move the buffer start pos. The cached file pos will be 35 at the end.
	TBuf8<5> buf4;
	err = fbuf.Read(30, buf4);
	TEST2(err, KErrNone); 
	VerifyFileContent(buf4, 30);
	err = fbuf.Read(35, buf4);
	TEST2(err, KErrNone); 
	VerifyFileContent(buf4, 35);

	//Too big request. No pending data in the buffer. The file read pos is before the position of the cached data in the buffer.  
	err = fbuf.Read(10, buf3);
	TEST2(err, KErrNone); 
	VerifyFileContent(buf3, 10);
	
	fbuf.Close();
	}
예제 #8
0
/**
@SYMTestCaseID          PDS-SQL-CT-4212
@SYMTestCaseDesc        RFileBuf64::Write() test.
                        The test performs file write operations using RFileBuf64 class.
                        Teh test sumilates the write operation at the conditions:
                        
                        1. There are 8 pages to be writted to the file.
                        2. Each page is 16 bytes
                        3. The size of RFileBuf64 is 4 pages, i.e. 64 bytes.
                        4. The order of write is not sequential.
 
@SYMTestActions         Write database pages.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority        High
*/
void TestSetSizeCounter()
    {
    const TInt KPageSize = 16;
    const TInt KBufSize = 4 * KPageSize;
    RFileBuf64 fbuf(KBufSize);
    (void)TheFs.Delete(KTestFile);
    TInt err = fbuf.Create(TheFs, KTestFile, EFileRead | EFileWrite);
    TEST2(err, KErrNone); 
    const TInt KMaxPage = 8;
    TUint8 fileData[KMaxPage][KPageSize];
    TPtrC8 pageData[KMaxPage];
    for(TInt i = 0;i <KMaxPage;++i)
        {
        Mem::Fill(fileData[i], KPageSize, TChar('a' + i));
        const TUint8* p = fileData[i]; 
        pageData[i].Set(p, KPageSize);
        }
    //
    fbuf.ProfilerReset();
    //Write the first 4 pages
    for (TInt ii = 0; ii < 4; ii++)
        {
        err = fbuf.Write(ii * KPageSize, pageData[ii]);
        TEST2(err, KErrNone);
        }
    //Write page #2
    err = fbuf.Write(2 * KPageSize, pageData[2]);
    TEST2(err, KErrNone);
    //
    TEST2(fbuf.iFileWriteCount, 0);
    TEST2(fbuf.iFileSetSizeCount, 0);
    //Write pages 5, 4, 6, 7
    err = fbuf.Write(5 * KPageSize, pageData[5]);
    TEST2(err, KErrNone);
    //
    TEST2(fbuf.iFileWriteCount, 1);
    TEST2(fbuf.iFileSetSizeCount, 0);
    //
    err = fbuf.Write(4 * KPageSize, pageData[4]);
    TEST2(err, KErrNone);
    err = fbuf.Write(6 * KPageSize, pageData[6]);
    TEST2(err, KErrNone);
    err = fbuf.Write(7 * KPageSize, pageData[7]);
    TEST2(err, KErrNone);
    //
    TEST2(fbuf.iFileWriteCount, 1);
    TEST2(fbuf.iFileSetSizeCount, 0);
    //
    err = fbuf.Flush();
    TEST2(err, KErrNone);
    //
    TEST2(fbuf.iFileWriteCount, 2);
    TEST2(fbuf.iFileSetSizeCount, 0);
    //
    fbuf.Close();
    (void)TheFs.Delete(KTestFile);
    }
예제 #9
0
/**
@SYMTestCaseID			PDS-SQL-UT-4207
@SYMTestCaseDesc		RFileBuf64::Write() OOM test.
						The test calls RFileBuf64:Write() in an OOM
						simulation loop and verifies that no memory is leaked.
						The test also check that RFileBuf::DoSetCapacity() correctly operates in
						"out of memory" situation.
@SYMTestActions			RFileBuf64::Write() OOM test.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMDEF					380056
*/
void WriteOomTest()
	{
	HBufC8* databuf = HBufC8::New(KPageSize);
	TEST(databuf != NULL);
	TPtr8 dataptr = databuf->Des();
	dataptr.SetLength(KPageSize);
	dataptr.Fill(TChar(KChar));
	
	TInt err = KErrNoMemory;
	TInt failingAllocationNo = 0;
	TheTest.Printf(_L("Iteration:\r\n"));
	while(err == KErrNoMemory)
		{
		TheTest.Printf(_L(" %d"), ++failingAllocationNo);

		(void)TheFs.Delete(KTestFile);
		
		MarkHandles();
		MarkAllocatedCells();
		
		__UHEAP_MARK;
		__UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate);

		const TInt KDefaultBufCapacity = 1024;
		RFileBuf64 fbuf(KDefaultBufCapacity);
		err = fbuf.Create(TheFs, KTestFile, EFileWrite | EFileRead);
		if(err == KErrNone)
			{
			err = fbuf.Write(0LL, dataptr);
			}
		fbuf.Close();
		
		__UHEAP_RESET;
		__UHEAP_MARKEND;

		CheckAllocatedCells();
		CheckHandles();
		}
	TEST2(err, KErrNone);
	RFile64 file;
	err = file.Open(TheFs, KTestFile, EFileRead);
	TEST2(err, KErrNone);
	dataptr.Zero();
	err = file.Read(dataptr);
	TEST2(err, KErrNone);
	file.Close();
	TEST2(dataptr.Length(), KPageSize);
	for(TInt i=0;i<KPageSize;++i)
		{
		TEST(dataptr[i] == KChar);
		}
	TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
	
	//The file is left undeleted - to be used in ReadOomTest().
	delete databuf;
	}
예제 #10
0
/**
@SYMTestCaseID			PDS-SQL-UT-4132
@SYMTestCaseDesc		RFileBuf64 write test 1.
						The test performs file write operations using RFileBuf64 class.
						The write positions are inside the buffer or right at the end of the buffer.
						The purpose of the test: to verify the logic of RFileBuf64::Write().
@SYMTestActions			RFileBuf64 write test 1.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void WriteTest1()
	{
	RFileBuf64 fbuf(1024);
	TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
	TEST2(err, KErrNone); 
    fbuf.ProfilerReset();
    
    //Zero write request
	err = fbuf.Write(0, _L8(""));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 0);

	//First write operation. After the operation the file buffer must countain 10 bytes.
	err = fbuf.Write(0, _L8("A123456789"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 1);

	//Second write operation. The offset is at the middle of the buffer.  Data length: 10;
	err = fbuf.Write(5, _L8("ZZZZZEEEEE"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);

	//Third write operation. The offset is at the end of the buffer.  Data length: 5;
	err = fbuf.Write(15, _L8("CCCCC"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);

	err = fbuf.Flush();
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 1);
	TEST2(fbuf.iFileFlushCount, 1);
	TEST2(fbuf.iFileWriteAmount, 20);
	TEST2(fbuf.iFileSizeCount, 1);

	fbuf.Close();
	
	VerifyFileContent(_L8("A1234ZZZZZEEEEECCCCC"));

	(void)TheFs.Delete(KTestFile);
	}
예제 #11
0
/**
@SYMTestCaseID			PDS-SQL-UT-4137
@SYMTestCaseDesc		RFileBuf64 write test 6.
						The test performs file write operations using RFileBuf64 class.
						The data is written before the start of the file buffer and is too big to fit in the buffer.
						The purpose of the test: to verify the logic of RFileBuf64::Write().
@SYMTestActions			RFileBuf64 write test 6.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void WriteTest6()
	{
	RFileBuf64 fbuf(20);
	TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
	TEST2(err, KErrNone); 

	err = fbuf.Write(0, _L8("A123456789B123456789C123456789"));
	TEST2(err, KErrNone); 
	err = fbuf.Flush();
	TEST2(err, KErrNone); 
	fbuf.Close();
	VerifyFileContent(_L8("A123456789B123456789C123456789"));

	err = fbuf.Open(TheFs, KTestFile, EFileWrite);
	TEST2(err, KErrNone); 
    fbuf.ProfilerReset();

	//First write operation. The offset is not 0. Data length: 10;
	err = fbuf.Write(15, _L8("OOOOOOOOOO"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 1);

	//Second write operation. The offset is 0. Data length: 15;
	err = fbuf.Write(0, _L8("TTTTTTTTTTTTTTT"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 1);
	TEST2(fbuf.iFileWriteAmount, 10);
	TEST2(fbuf.iFileSizeCount, 1);

	err = fbuf.Flush();
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 2);
	TEST2(fbuf.iFileFlushCount, 1);
	TEST2(fbuf.iFileWriteAmount, 15 + 10);
	TEST2(fbuf.iFileSizeCount, 1);

	fbuf.Close();

	VerifyFileContent(_L8("TTTTTTTTTTTTTTTOOOOOOOOOO56789"));
	
	(void)TheFs.Delete(KTestFile);
	}
예제 #12
0
/**
@SYMTestCaseID			PDS-SQL-UT-4136
@SYMTestCaseDesc		RFileBuf64 write test 5.
						The test performs file write operations using RFileBuf64 class.
						The data is written before the start of the file buffer and is too big to fit in the buffer.
						The purpose of the test: to verify the logic of RFileBuf64::Write().
@SYMTestActions			RFileBuf64 write test 5.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void WriteTest5()
	{
	RFileBuf64 fbuf(20);
	TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
	TEST2(err, KErrNone); 
    fbuf.ProfilerReset();

	//First write operation. The offset is not 0.  Data length: 10;
	err = fbuf.Write(10, _L8("A123456789"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 1);

	//Second write operation. The offset is 0.  Data length: 12, i.e. within the buffer - should have no write to the disk.
	err = fbuf.Write(0, _L8("ZZXXCCVVBBNN"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 1);
	
	//Third write operation. The offet is 18. Data length: 5. The buffer should be written out to the file
	// after "ab" is appended to the buffer. The new buffe after being emptied should have data "cde".
	err = fbuf.Write(18, _L8("abcde"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 1);
	TEST2(fbuf.iFileWriteAmount, 20);
	TEST2(fbuf.iFileSizeCount, 1);

	err = fbuf.Flush();
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 2);
	TEST2(fbuf.iFileFlushCount, 1);
	TEST2(fbuf.iFileWriteAmount, 23);
	TEST2(fbuf.iFileSizeCount, 1);

	fbuf.Close();

	VerifyFileContent(_L8("ZZXXCCVVBBNN234567abcde"));
	
	(void)TheFs.Delete(KTestFile);
	}
예제 #13
0
/**
@SYMTestCaseID			PDS-SQL-UT-4134
@SYMTestCaseDesc		RFileBuf64 write test 3.
						The test performs file write operations using RFileBuf64 class.
						The write position is before the start of the buffer but there is room for move.
						The purpose of the test: to verify the logic of RFileBuf64::Write().
@SYMTestActions			RFileBuf64 write test 3.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void WriteTest3()
	{
	//Iteration 1: The file length is 0, the first operation is "write beyond the end"
	//Iteration 2: The file length is 30, the first write operation is within the file.
	for(TInt i=0;i<2;++i)
		{
		RFileBuf64 fbuf(1024);
		TInt err = i == 0 ? fbuf.Create(TheFs, KTestFile, EFileWrite) : fbuf.Open(TheFs, KTestFile, EFileWrite);
		TEST2(err, KErrNone); 
	    fbuf.ProfilerReset();

		//First write operation. The offset is not 0.  Data length: 10;
		err = fbuf.Write(20, _L8("A123456789"));
		TEST2(err, KErrNone); 
		TEST2(fbuf.iFileWriteCount, 0);
		TEST2(fbuf.iFileWriteAmount, 0);
		TEST2(fbuf.iFileSizeCount, 1);
		
		//Second write operation. The offset is 0.  Data length: 20;
		err = fbuf.Write(0, _L8("AASSDDFFRR**********"));
		TEST2(err, KErrNone); 
		TEST2(fbuf.iFileWriteCount, 0);
		TEST2(fbuf.iFileWriteAmount, 0);
		TEST2(fbuf.iFileSizeCount, 1);

		err = fbuf.Flush();
		TEST2(err, KErrNone); 
		TEST2(fbuf.iFileWriteCount, 1);
		TEST2(fbuf.iFileFlushCount, 1);
		TEST2(fbuf.iFileWriteAmount, 30);
		TEST2(fbuf.iFileSizeCount, 1);

		fbuf.Close();

		VerifyFileContent(_L8("AASSDDFFRR**********A123456789"));
		}
	(void)TheFs.Delete(KTestFile);
	}	
예제 #14
0
/**
@SYMTestCaseID			PDS-SQL-UT-4133
@SYMTestCaseDesc		RFileBuf64 write test 2.
						The test performs file write operations using RFileBuf64 class.
						The write positions are beyound the end of the file but within the buffer capacity.
						The purpose of the test: to verify the logic of RFileBuf64::Write().
@SYMTestActions			RFileBuf64 write test 2.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void WriteTest2()
	{
	RFileBuf64 fbuf(1024);
	TInt err = fbuf.Create(TheFs, KTestFile, EFileWrite);
	TEST2(err, KErrNone); 
    fbuf.ProfilerReset();

	//First write operation. After the operation the file buffer must countain 10 bytes.
	err = fbuf.Write(0, _L8("A123456789"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 1);

	//Second write operation. After the operation the file buffer must countain 10 + 10 zeros + 10 bytes.
	err = fbuf.Write(20, _L8("FFGGHHJJKK"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 1);

	err = fbuf.Flush();
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileWriteCount, 1);
	TEST2(fbuf.iFileFlushCount, 1);
	TEST2(fbuf.iFileWriteAmount, 30);
	TEST2(fbuf.iFileSizeCount, 1);

	fbuf.Close();
	
	TBuf8<30> pattern;
	pattern.Append(_L8("A123456789"));
	pattern.AppendFill(TChar(0), 10);
	pattern.Append(_L8("FFGGHHJJKK"));
	VerifyFileContent(pattern);
	
	(void)TheFs.Delete(KTestFile);
	}
예제 #15
0
void PostFixFunc::execute() {
    // print everything on the stack for this function
#if __GNUC__<3
    filebuf fbuf;
    if (comterp()->handler()) {
        int fd = Math::max(1, comterp()->handler()->get_handle());
        fbuf.attach(fd);
    } else
        fbuf.attach(fileno(stdout));
#else
    fileptr_filebuf fbuf(comterp()->handler() && comterp()->handler()->wrfptr()
                         ? comterp()->handler()->wrfptr() : stdout, ios_base::out);
#endif
    ostream out(&fbuf);

    boolean oldbrief = comterp()->brief();
    comterp()->brief(true);
    int numargs = nargspost();

    ComValue argoff(comterp()->stack_top());
    int topptr = argoff.int_val()-(comterp()->pfnum()-1);
    for (int i=topptr-numargs; i<=topptr-1; i++) {
        ComValue& val = comterp()->expr_top(i);
        val.comterp(comterp());
        out << val;
        if (val.is_type(AttributeValue::CommandType) ||
                (_detail_matched_delims && val.is_type(AttributeValue::SymbolType) &&
                 val.nids() >= TOK_RPAREN )) {
            if (!_detail_matched_delims) {
                out << "[" << val.narg() << "|" << val.nkey() << "]";
                ComFunc* func = (ComFunc*)val.obj_val();
                if (func->post_eval()) out << "*";
            } else {
                char ldelim, rdelim;
                boolean dbldelim = 0;
                if (val.nids()==TOK_RPAREN) {
                    ldelim = '(';
                    rdelim = ')';
                }
                else if (val.nids()==TOK_RBRACKET) {
                    ldelim = '[';
                    rdelim = ']';
                }
                else if (val.nids()==TOK_RBRACE) {
                    ldelim = '{';
                    rdelim = '}';
                }
                else if (val.nids()==TOK_RANGBRACK) {
                    ldelim = '<';
                    rdelim = '>';
                }
                else if (val.nids()==TOK_RANGBRACK2) {
                    ldelim = '<';
                    rdelim = '>';
                    dbldelim=1;
                }
                else {
                    ldelim = ':';
                    rdelim = 0x0;
                };
                out << ldelim;
                if(dbldelim) out << ldelim;
                out << val.narg();
                if (rdelim) {
                    out << rdelim;
                    if(dbldelim) out << rdelim;
                }
            }
        }
        else if (val.is_type(AttributeValue::SymbolType) &&
                 (val.narg() || val.nkey()))
            out << "{" << val.narg() << "|" << val.nkey() << "}";
        else if (val.is_type(AttributeValue::KeywordType))
            out << "(" << val.keynarg_val() << ")";
        out << ((i+1>topptr) ? "\n" : " ");
    }
    comterp()->brief(oldbrief);
    reset_stack();
}
예제 #16
0
// Project namespace functions
void labscale::CreatePenetratorExperiment()
/* Throw a steel ball at glass regolith; measure penetration depth.*/
{
    // Load pre-settled regolith or create empty container
    if (gRun.loadSceneFromFile.empty())
        labscale::CreateRegolithContainer();
    else
    {
        if(!LoadSceneFromFile(gRun.loadSceneFromFile)) ncc__error("Failed to load partially filed box.\a\n");
        PxActor* theBox = FindNamedActor("the_box");
        if (theBox)
        {
            ColorActor(theBox, ncc::rgb::rRed);
            labscale::VIPs.container = theBox->isRigidDynamic();
        }
    }

    // Create impactor material (steel, for now)
    PxMaterial* steel = gPhysX.mPhysics->createMaterial(0.5, 0.5, 0.5);
    if (!steel)
        ncc__error("\aPxPhysics::createMaterial() failed!");
    PxReal rho = labscale::impactor.materialDensity;

    // Ready, aim impactor (will fire manually)
    PxReal radius = labscale::impactor.diameter/2;
    labscale::impactor.iniSurface = getRegolithSurface(); // target surface in global frame
    PxReal hLaunch = labscale::impactor.iniSurface + 4*radius;
    labscale::VIPs.ball1 = CreateRubbleGrain(PxVec3(0,hLaunch,0),eSPHERE_GRAIN,radius,*steel,rho);
    labscale::VIPs.ball1->setName("impactor");
    labscale::VIPs.ball1->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC, true);
    ColorActor(labscale::VIPs.ball1, ncc::rgb::gDarkOlive);

    // Adjust camera, grid, display
    gCamera.pos.x = 0.0;
    gCamera.pos.y = labscale::reg_box.fillHeight*1.4;
    gCamera.pos.z = labscale::reg_box.diameter*1.6;
    gDebug.bXYGridOn = true;

    // Start a log
    if (gRun.outputFrequency)
    {
        ostringstream header;
        header << "# This is the run log of " << gRun.baseName << endl;
        header << "# Experiment type: HOLSAPPLE1 (" << labscale::eExperimentType << ")" << endl;
        header << "# Time step used = " << gSim.timeStep << endl;
        header << "# Top of regolith surface = " << labscale::impactor.iniSurface << endl;
        header << "# Impactor launch speed = " << labscale::impactor.speed << endl;
        header << "# Columns are (values in code units, d is penetration depth):" << endl;
        header << "# [t]    [v_y]    [d]    [x]    [y]    [z]" << endl;
        ofstream fbuf(gRun.outFile.c_str(),ios::trunc);
        if (!fbuf.is_open())
            ncc__error("Could not start a log. Experiment aborted.\a\n");
        fbuf << header.str() << endl;
    }

    // Start the action
    gSim.isRunning=true;
    gSim.bPause=false;
    gSim.codeTime = 0.0f;
    RefreshHUD();
}
예제 #17
0
/**
@SYMTestCaseID			PDS-SQL-UT-4142
@SYMTestCaseDesc		RFileBuf64 OOM test.
						The test calls RFileBuf64:Create(), RFileBuf64:Open() and RFileBuf64:Temp() in an OOM
						simulation loop and verifies that no memory is leaked.
@SYMTestActions			RFileBuf64 OOM test.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void OomTest(TOomTestType aOomTestType)
	{
	(void)TheFs.Delete(KTestFile);
	
	if(aOomTestType == EOomOpenTest)
		{
		RFile64 file;
		TInt err2 = file.Create(TheFs, KTestFile, EFileWrite | EFileRead);	
		file.Close();
		TEST2(err2, KErrNone);
		}
	
	TFileName tmpFileName;
	TInt err = KErrNoMemory;
	TInt failingAllocationNo = 0;
	RFileBuf64 fbuf(1024);
	TheTest.Printf(_L("Iteration:\r\n"));
	while(err == KErrNoMemory)
		{
		TheTest.Printf(_L(" %d"), ++failingAllocationNo);
		
		MarkHandles();
		MarkAllocatedCells();
		
		__UHEAP_MARK;
		__UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate);
		
		switch(aOomTestType)
			{
			case EOomCreateTest:
				err = fbuf.Create(TheFs, KTestFile, EFileWrite | EFileRead);
				break;
			case EOomOpenTest:
				err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead);
				break;
			case EOomTempTest:
				{
				err = fbuf.Temp(TheFs, KTestDir, tmpFileName, EFileWrite | EFileRead);
				}
				break;
			default:
				TEST(0);
				break;
			}
		fbuf.Close();
		
		__UHEAP_RESET;
		__UHEAP_MARKEND;

		CheckAllocatedCells();
		CheckHandles();
		
		TEntry entry;
		if(err != KErrNoMemory)
			{
			TEST2(err, KErrNone);	
			}
		else if(aOomTestType == EOomCreateTest)
			{
			TInt err2 = TheFs.Entry(KTestFile, entry);
			TEST2(err2, KErrNotFound);
			}
		else if(aOomTestType == EOomTempTest)
			{
			if(tmpFileName.Size() > 0)
				{
				TInt err2 = TheFs.Entry(tmpFileName, entry);
				TEST2(err2, KErrNotFound);
				}
			}
		}
	TEST2(err, KErrNone);
	TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
	
	if(aOomTestType == EOomTempTest)
		{
		(void)TheFs.Delete(tmpFileName);
		}
	(void)TheFs.Delete(KTestFile);
	}
예제 #18
0
/**
@SYMTestCaseID			PDS-SQL-UT-4140
@SYMTestCaseDesc		RFileBuf64 read test 3.
						The test performs file read operations using RFileBuf64 class.
						Tested operations:
							- Non-buffered reads;
							- Buffered reads;
							- Part- buffered reads;
						The purpose of the test: to verify the logic of RFileBuf64::Read().
@SYMTestActions			RFileBuf64 read test 3.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void ReadTest3()
	{
	RFileBuf64 fbuf(1024);
	TInt err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead | EFileShareReadersOrWriters);
	TEST2(err, KErrNone); 
    fbuf.ProfilerReset();
    
    //1. Read bytes [0..10]. Non buffered.
    TBuf8<10> buf1;
	err = fbuf.Read(0, buf1);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 1);
	TEST2(fbuf.iFileReadAmount, 10);
	TEST2(fbuf.iFileSizeCount, 1);
    fbuf.ProfilerReset();
	VerifyFileContent(buf1, 0);

    //2. Read bytes [10..20]. Non buffered. But the file buffer is populated, bytes [10..40].
	err = fbuf.Read(10, buf1);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 1);
	TEST2(fbuf.iFileReadAmount, 30);
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();
	VerifyFileContent(buf1, 10);
	
    //3. Read bytes [25..35]. Buffered. Because the previous operation [2] performed a read-ahead operation.
	err = fbuf.Read(25, buf1);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 0);
	TEST2(fbuf.iFileReadAmount, 0);
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();
	VerifyFileContent(buf1, 25);

    //4. Write bytes [20..30]. Buffered. Read buffer is gone, the file buffer contains the [20..30] file area.
	err = fbuf.Write(20, _L8("IIIIIQQQQQ"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 0);
	TEST2(fbuf.iFileReadAmount, 0);
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();

    //5. Read bytes [25..35]. Part-buffered. Part of pending writes picked up. Then the buffer is flushed.
	err = fbuf.Read(25, buf1);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 1);
	TEST2(fbuf.iFileReadAmount, 5);
	TEST2(fbuf.iFileWriteCount, 1);
	TEST2(fbuf.iFileWriteAmount, 10);
	TEST2(fbuf.iFileSizeCount, 0);
	
    fbuf.ProfilerReset();
    err = fbuf.Flush();
    TEST2(err, KErrNone);
    
    //All cached data should have been written to the file before the Flush() call.
	TEST2(fbuf.iFileReadCount, 0);
	TEST2(fbuf.iFileReadAmount, 0);
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 0);
	TEST2(fbuf.iFileFlushCount, 1);
    
    fbuf.ProfilerReset();
	VerifyFileContent(buf1, 25);

    //6. The buffer is empty after the last flush. Write bytes [0..10]. The file buffer contains the [0..10] file area.
	err = fbuf.Write(0, _L8("PPOOIIUUYY"));
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 0);
	TEST2(fbuf.iFileReadAmount, 0);
	TEST2(fbuf.iFileWriteCount, 0);
	TEST2(fbuf.iFileWriteAmount, 0);
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();
	
    //7. Read bytes [5..15]. Part buffered. Pending writes picked up. The content is written to the file.
	err = fbuf.Read(5, buf1);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 1);
	TEST2(fbuf.iFileReadAmount, 5);
	TEST2(fbuf.iFileWriteCount, 1);
	TEST2(fbuf.iFileWriteAmount, 10);
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();
	VerifyFileContent(buf1, 5);
	
	fbuf.Close();
	}
예제 #19
0
/**
@SYMTestCaseID			PDS-SQL-UT-4139
@SYMTestCaseDesc		RFileBuf64 read test 2.
						The test performs file read operations using RFileBuf64 class.
						Tested operations:
							- Non-buffered reads;
							- Buffered reads;
						The purpose of the test: to verify the logic of RFileBuf64::Read().
@SYMTestActions			RFileBuf64 read test 2.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void ReadTest2()
	{
	RFileBuf64 fbuf(1024);
	TInt err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead | EFileShareReadersOrWriters);
	TEST2(err, KErrNone); 
    fbuf.ProfilerReset();
    
    //1. Read bytes [0..20]
    TBuf8<20> buf1;
	err = fbuf.Read(0, buf1);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 1);
	TEST2(fbuf.iFileReadAmount, 20);
	TEST2(fbuf.iFileSizeCount, 1);
    fbuf.ProfilerReset();
	VerifyFileContent(buf1, 0);
    
    //2. Read again, bytes [10..20]. They are not buffered.
    TBuf8<10> buf2;
	err = fbuf.Read(10, buf2);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 1);
	TEST2(fbuf.iFileReadAmount, 10);
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();
	VerifyFileContent(buf2, 10);

    //3. Read again, bytes [20..30]. They are not buffered. But the file buffer will be populated, 
    //   because the file read position matches the guessed file read position from step 2.
	err = fbuf.Read(20, buf2);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 1);
	TEST2(fbuf.iFileReadAmount, (10 * 2));
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();
	VerifyFileContent(buf2, 20);

	//4. Read again, bytes [25..35]. This is a buffered read operation.
	err = fbuf.Read(25, buf2);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 0);
	TEST2(fbuf.iFileReadAmount, 0);
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();
	VerifyFileContent(buf2, 25);
	
	//5. Read again, bytes [15..25]. This is a non buffered read operation.
	err = fbuf.Read(15, buf2);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 1);
	TEST2(fbuf.iFileReadAmount, 10);
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();
	VerifyFileContent(buf2, 15);

    //6. Read again, bytes [25..35]. This is a buffered read operation. The buffer from step 3 is still there.
	err = fbuf.Read(25, buf2);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 0);
	TEST2(fbuf.iFileReadAmount, 0);
	TEST2(fbuf.iFileSizeCount, 0);
    fbuf.ProfilerReset();
	VerifyFileContent(buf2, 25);
	
    //7. Read again, bytes [35..45] - beyond the end of the file. 
    //   This is a buffered read operation. The buffer from step 3 is still there.
	err = fbuf.Read(35, buf2);
	TEST2(err, KErrNone); 
	TEST2(fbuf.iFileReadCount, 0);
	TEST2(fbuf.iFileReadAmount, 0);
	TEST2(fbuf.iFileSizeCount, 0);
	TEST2(buf2.Size(), 5);
    fbuf.ProfilerReset();
	VerifyFileContent(buf2, 35);
	
	fbuf.Close();
	}
예제 #20
0
	virtual void operator()()
		{
		RFileBuf64 fbuf(-8192);//panic here - "-8192" - negative buffer capacity
		}
예제 #21
0
	virtual void operator()()
		{
		RFileBuf64 fbuf(8192);
		RFs fs;
		fbuf.Open(fs, _L("aaa.db"), EFileRead);//panic here - invalid file handle
		}
예제 #22
0
	virtual void operator()()
		{
		RFileBuf64 fbuf(8192);
		RMessage2 msg;
		fbuf.AdoptFromClient(msg, 0, 1);//panic here - invalid message handle
		}
예제 #23
0
	virtual void operator()()
		{
		RFileBuf64 fbuf(8192);
		TBuf8<50> buf;
		fbuf.SetSize(-1024);//panic here - invalid file size
		}
예제 #24
0
	virtual void operator()()
		{
		RFileBuf64 fbuf(8192);
		TBuf8<50> buf;
		fbuf.Write(-1024, buf);//panic here - invalid file position
		}