/**
@SYMTestCaseID          SYSLIB-STORE-CT-1184
@SYMTestCaseDesc	    Tests for CDictionaryFileStore::IsPresentL() function
@SYMTestPriority 	    High
@SYMTestActions  	    Tests for the specified UID's has an associated stream within the dictionary store.
						Tests for KErrNone error flag while opening a dictionary file for read,test the value read from the file.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void Test2L(CDictionaryFileStore* aDict)
	{
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1184 "));
	test(!aDict->IsPresentL(testUid1));
	test(aDict->IsPresentL(testUid2));
	test(!aDict->IsPresentL(testUid3));
	RDictionaryReadStream readStream;
	TRAPD(ret, readStream.OpenL(*aDict,testUid2));
		test(ret==KErrNone);
	TInt val=0;
	TRAP(ret, val = readStream.ReadInt32L());
		test(ret==KErrNone);
		test(val==value2);
	readStream.Close();
	//
	//
	test.Next(_L("Close the store without commiting"));
	// add a stream, close the store (no commit)
	RDictionaryWriteStream writeStream;
	TRAP(ret, writeStream.AssignL(*aDict,testUid3));
		test(ret==KErrNone);
	TRAP(ret, writeStream.WriteInt32L(value3));
		test(ret==KErrNone);
	TRAP(ret, writeStream.CommitL());
		test(ret==KErrNone);
	writeStream.Close();
	delete aDict;
	}
/**
@SYMTestCaseID          SYSLIB-STORE-CT-1183
@SYMTestCaseDesc	    Tests for CDictionaryFileStore::IsPresentL(),CDictionaryFileStore::Remove() functions
@SYMTestPriority 	    High
@SYMTestActions  	    Tests for writing an entry and commit it.
                        Tests for reading the entry back.
						Tests for rewriting and reading back using LC functions.
						Tests for adding one more entry and check for the content.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void Test1L(CDictionaryFileStore* aDict)
	{
	// write an entry and commit it
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1183 "));
	RDictionaryWriteStream writeStream;
	TRAPD(ret, writeStream.AssignL(*aDict,testUid1));
		test(ret==KErrNone);
	TRAP(ret, writeStream.WriteInt32L(value1));
		test(ret==KErrNone);
	TRAP(ret, writeStream.CommitL());
		test(ret==KErrNone);
	writeStream.Close();
	// read that entry back
	RDictionaryReadStream readStream;
	TRAP(ret, readStream.OpenL(*aDict,testUid1));
		test(ret==KErrNone);
	TInt val=0;
	TRAP(ret, val = readStream.ReadInt32L());
		test(ret==KErrNone);
		test(val==value1);
	readStream.Close();
	//
	test.Next(_L("Test the stream LC methods"));
	// read that entry back using the LC method
	readStream.OpenLC(*aDict,testUid1);
	TRAP(ret, val = readStream.ReadInt32L());
		test(ret==KErrNone);
		test(val==value1);
	//readStream.Close();
	CleanupStack::PopAndDestroy(); // readStream
	//
	// rewrite that entry using the LC method
	writeStream.AssignLC(*aDict,testUid1);
	
	//do some rading
	MStreamBuf* sbuf = writeStream.Sink();
	HBufC8* buffer = HBufC8::NewLC(400);
	TUint8* buffptr = const_cast<TUint8*>(buffer->Ptr());
	sbuf->ReadL(buffptr, 100);
	TPtr8 buffDes(buffer->Des());
	TRequestStatus rstatus;
	sbuf->ReadL(buffDes, 100, rstatus);
	User::WaitForRequest(rstatus);
	CleanupStack::PopAndDestroy(); //buffer
	
	TRAP(ret, writeStream.WriteInt32L(value1));
		test(ret==KErrNone);
	TRAP(ret, writeStream.CommitL());
		test(ret==KErrNone);
	//writeStream.Close();
	CleanupStack::PopAndDestroy(); // writestream
	//
	test.Next(_L("Test reverting the store"));
	// commit the store
	TRAP(ret, aDict->CommitL());
		test(ret==KErrNone);
	// replace the 1st entry, commit it, then revert the store
	TRAP(ret, writeStream.AssignL(*aDict,testUid1));
		test(ret==KErrNone);
	TRAP(ret, writeStream.WriteInt32L(value2));
		test(ret==KErrNone);
	TRAP(ret, writeStream.CommitL());
		test(ret==KErrNone);
	writeStream.Close();
	TRAP(ret, aDict->RevertL());
		test(ret==KErrNone);
	// check the value of the entry
	TRAP(ret, readStream.OpenL(*aDict,testUid1));
		test(ret==KErrNone);
	TRAP(ret, val = readStream.ReadInt32L());
		test(ret==KErrNone);
		test(val==value1);
	readStream.Close();
	
	test.Next(_L("Test reverting the store using alternative Revert method"));
	// replace the 1st entry, commit it, then revert the store
	TRAP(ret, writeStream.AssignL(*aDict,testUid1));
		test(ret==KErrNone);
	TRAP(ret, writeStream.WriteInt32L(value2));
		test(ret==KErrNone);
	TRAP(ret, writeStream.CommitL());
		test(ret==KErrNone);
	writeStream.Close();
	aDict->Revert();
	// check the value of the entry
	TRAP(ret, readStream.OpenL(*aDict,testUid1));
		test(ret==KErrNone);
	TRAP(ret, val = readStream.ReadInt32L());
		test(ret==KErrNone);
		test(val==value1);
	readStream.Close();
	//
	//
	test.Next(_L("Test IsPresentL() and Remove()"));
	// add another entry
	TRAP(ret, writeStream.AssignL(*aDict,testUid2));
		test(ret==KErrNone);
	TRAP(ret, writeStream.WriteInt32L(value2));
		test(ret==KErrNone);
	test(!aDict->IsPresentL(testUid2));
	TRAP(ret, writeStream.CommitL());
		test(ret==KErrNone);
	writeStream.Close();
	// test IsPresentL()
	test(aDict->IsPresentL(testUid1));
	test(aDict->IsPresentL(testUid2));
	test(!aDict->IsPresentL(testUid3));
	// test Remove()
	TRAP(ret, aDict->RemoveL(testUid1));
		test(!aDict->IsPresentL(testUid1));
	//
	//
	test.Next(_L("Close the store and re-open it"));
	// commit the store and close it
	TRAP(ret, aDict->CommitL());
		test(ret==KErrNone);
	//
	delete aDict;
	}
/**
@SYMTestCaseID          SYSLIB-STORE-CT-1189
@SYMTestCaseDesc	    Repeatedly opening a dictionary file test
@SYMTestPriority 	    High
@SYMTestActions  	    Attempt for creating a new dictionary file,write an entry an commit it.
                        Attempt for repeatedly opening the dictionary file,interogate it,and delete it without commiting
                        Attempt for repeatedly opening the dictionary file and interogate it,commit the file after each read
						Attempt for repeatedly opening the dictionary file and re-write a stream, commiting the file after each write
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void repeatedUseTestsL()
	{
	// set things up...
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1189 "));

	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
	TParse dicFilePath;
	dicFilePath.Set(drive.Name(), &KDicFilePath, NULL);
	
	TInt ret = TheFs.MkDirAll(dicFilePath.DriveAndPath());
		test((ret==KErrNone)||(ret==KErrAlreadyExists));
	TheFs.Delete(dicFilePath.FullName()); // delete the file if it already exists
	//
	// create a new dictionary file
	CDictionaryFileStore* dicFile=NULL;
	TRAP(ret, dicFile = CDictionaryFileStore::OpenL(TheFs,dicFilePath.FullName(),dicFileUid));
		test(ret==KErrNone);
	// write an entry and commit it
	RDictionaryWriteStream writeStream;
	TRAP(ret, writeStream.AssignL(*dicFile,testUid1));
		test(ret==KErrNone);
	TRAP(ret, writeStream.WriteInt32L(value1));
		test(ret==KErrNone);
	TRAP(ret, writeStream.CommitL());
		test(ret==KErrNone);
	writeStream.Close();
	// close the file
	TRAP(ret, dicFile->CommitL());
		test(ret==KErrNone);
	delete dicFile;
	dicFile = NULL;
	//
	//
	test.Next(_L("Repeatedly open a file and interogate it without commiting"));
	// repeatedly open the dic file, interogate it, and delete it without commiting
	TEntry fileEntry;
	ret = TheFs.Entry(dicFilePath.FullName(),fileEntry);
		test(ret==KErrNone);
	TInt sizeBefore=fileEntry.iSize;
	//
	TInt i;
	for (i=0 ; i<10 ; i++)
		{
		TRAP(ret, dicFile = CDictionaryFileStore::OpenL(TheFs,dicFilePath.FullName(),dicFileUid));
			test(ret==KErrNone);
		RDictionaryReadStream readStream;
		TRAP(ret, readStream.OpenL(*dicFile,testUid1));
			test(ret==KErrNone);
		readStream.Close();
		delete dicFile;
		dicFile = NULL;
		}
	//
	ret = TheFs.Entry(dicFilePath.FullName(),fileEntry);
		test(ret==KErrNone);
	TInt sizeAfter=fileEntry.iSize;
		test(sizeAfter==sizeBefore);
	//
	//
	test.Next(_L("Repeatedly open a file, commiting after each read"));
	// repeatedly open the dic file and interogate it, commiting the file after each read
	ret = TheFs.Entry(dicFilePath.FullName(),fileEntry);
		test(ret==KErrNone);
	sizeBefore=fileEntry.iSize;
	//
	for (i=0 ; i<10 ; i++)
		{
		TRAP(ret, dicFile = CDictionaryFileStore::OpenL(TheFs,dicFilePath.FullName(),dicFileUid));
			test(ret==KErrNone);
		RDictionaryReadStream readStream;
		TRAP(ret, readStream.OpenL(*dicFile,testUid1));
			test(ret==KErrNone);
		readStream.Close();
		TRAP(ret, dicFile->CommitL());
			test(ret==KErrNone);
		delete dicFile;
		dicFile = NULL;
		}
	//
	ret = TheFs.Entry(dicFilePath.FullName(),fileEntry);
		test(ret==KErrNone);
	sizeAfter=fileEntry.iSize;
		test(sizeAfter==sizeBefore);
	//
	//
	test.Next(_L("Repeatedly open a file and re-write a stream"));
	// repeatedly open the dic file and re-write a stream, commiting the file after each write
	ret = TheFs.Entry(dicFilePath.FullName(),fileEntry);
		test(ret==KErrNone);
	sizeBefore=fileEntry.iSize;
	//
	for (i=0 ; i<10 ; i++)
		{
		TRAP(ret, dicFile = CDictionaryFileStore::OpenL(TheFs,dicFilePath.FullName(),dicFileUid));
			test(ret==KErrNone);
		// write an entry and commit it
		RDictionaryWriteStream writeStream;
		TRAP(ret, writeStream.AssignL(*dicFile,testUid1));
			test(ret==KErrNone);
		TRAP(ret, writeStream.WriteInt32L(i));
			test(ret==KErrNone);
		TRAP(ret, writeStream.CommitL());
			test(ret==KErrNone);
		writeStream.Close();
		// close the file
		TRAP(ret, dicFile->CommitL());
			test(ret==KErrNone);
		delete dicFile;
		dicFile = NULL;
		}
	//
	ret = TheFs.Entry(dicFilePath.FullName(),fileEntry);
		test(ret==KErrNone);
	sizeAfter=fileEntry.iSize;
		test.Printf(_L("  Size before: %d\n  Size after:  %d\n"),sizeBefore,sizeAfter);
	//
	//
	// tidy up
	}
Example #4
0
/**
@SYMTestCaseID          SYSLIB-LOGENG-CT-1010
@SYMTestCaseDesc	    Tests for CLogEvent::NewL(),CLogEvent::SetDataL() functions
@SYMTestPriority 	    High
@SYMTestActions  	    Tests for setting event specific data read from the file and try to read the data back from the event.
                        Check for memory errors
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void TestEventWithFileFailL()
	{
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1010 "));
	CLogEvent* event = CLogEvent::NewL();
	CleanupStack::PushL(event);

	// streaming
	TFileName storename = _L("c:\\T_BASIC_DATA");
	TUid uid={0x12345678};

	// create a store
	theFs.Delete(storename);
	CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(theFs, storename, uid);
	
	RDictionaryWriteStream write;
	RDictionaryReadStream read;

	uid.iUid++;
	write.AssignL(*store, uid);
	write << KNullDesC8;
	write.CommitL();
	write.Close();

	read.OpenL(*store, uid);

	TInt failCount = 0;
	TBool finished = EFalse;
	TInt error;

	theFs.SetErrorCondition(KErrGeneral, 0);
	event->SetDataL(read, 0);
	theFs.SetErrorCondition(KErrNone, 10000);

	read.Close();
	TEST(event->Data() == KNullDesC8);

	HBufC8* buf8 = TestUtils::CreateBuf8LC(100);

	uid.iUid++;
	write.AssignL(*store, uid);
	write.WriteL(buf8->Des());
	write.CommitL();
	write.Close();

	while(!finished)
		{
		read.OpenL(*store, uid);
		theFs.SetErrorCondition(KErrGeneral, failCount++);

		TRAP(error, event->SetDataL(read, 100));

		theFs.SetErrorCondition(KErrGeneral, 10000);

		read.Close();

		if (error == KErrNone)
			{
			TEST(event->Data() == buf8->Des());
			finished = ETrue;
			}
		else
			{
			TEST2(error, KErrGeneral);
			TEST(event->Data() == KNullDesC8);
			}
		}

	CleanupStack::PopAndDestroy(3); // buf8, store, event
	::DeleteDataFile(storename);
	}
Example #5
0
/**
@SYMTestCaseID          SYSLIB-LOGENG-CT-1008
@SYMTestCaseDesc	    Tests for writing different events to a store
@SYMTestPriority 	    High
@SYMTestActions  	    Calls up TestStoreL() function
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void TestEventL()
	{
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1008 "));
	CLogEvent* event1 = CLogEvent::NewL();
	CleanupStack::PushL(event1);

	// Event Id
	TEST(event1->Id() == KLogNullId);
	TestStoreL(*event1);

	event1->SetId(0x12345678);
	TEST(event1->Id() == 0x12345678);
	TestStoreL(*event1);

	event1->SetId(KMaxTInt32);
	TEST(event1->Id() == KMaxTInt32);
	TestStoreL(*event1);

	event1->SetId(0);
	TEST(event1->Id() == 0);
	TestStoreL(*event1);

	// Event type
	event1->SetEventType(TUid::Null());
	TestStoreL(*event1);

	event1->SetEventType(TUid::Uid(0x12345678));
	TEST(event1->EventType() == TUid::Uid(0x12345678));
	TestStoreL(*event1);

	event1->SetEventType(TUid::Uid(KMaxTInt32));
	TEST(event1->EventType() == TUid::Uid(KMaxTInt32));
	TestStoreL(*event1);

	event1->SetEventType(TUid::Null());
	TEST(event1->EventType() == TUid::Null());
	TestStoreL(*event1);

	// Remote Party
	TEST(event1->RemoteParty() == KNullDesC);
	TestStoreL(*event1);

	HBufC* buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength / 2);
	event1->SetRemoteParty(buf->Des());
	TEST(event1->RemoteParty() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength);
	event1->SetRemoteParty(buf->Des());
	TEST(event1->RemoteParty() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength * 2);
	event1->SetRemoteParty(buf->Des());
	TEST(event1->RemoteParty() == buf->Des().Left(KLogMaxRemotePartyLength));
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	event1->SetRemoteParty(KNullDesC);
	TEST(event1->RemoteParty() == KNullDesC);
	TestStoreL(*event1);

	// Direction
	TEST(event1->Direction() == KNullDesC);
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength / 2);
	event1->SetDirection(buf->Des());
	TEST(event1->Direction() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength);
	event1->SetDirection(buf->Des());
	TEST(event1->Direction() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength * 2);
	event1->SetDirection(buf->Des());
	TEST(event1->Direction() == buf->Des().Left(KLogMaxDirectionLength));
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	event1->SetDirection(KNullDesC);
	TEST(event1->Direction() == KNullDesC);
	TestStoreL(*event1);

	// Time
	TTime time;

	time.UniversalTime();
	event1->SetTime(time);
	TEST(event1->Time() == time);
	TestStoreL(*event1);

	time.HomeTime();
	event1->SetTime(time);
	TEST(event1->Time() == time);
	TestStoreL(*event1);

	// Duration Type
	TEST(event1->DurationType() == KLogNullDurationType);

	event1->SetDurationType(0xf);
	TEST(event1->DurationType() == 0xf);
	TestStoreL(*event1);

	event1->SetDurationType(KMaxTInt8);
	TEST(event1->DurationType() == KMaxTInt8);
	TestStoreL(*event1);

	event1->SetDurationType(KLogNullDurationType);
	TEST(event1->DurationType() == KLogNullDurationType);
	TestStoreL(*event1);

	// Duration
	TEST(event1->Duration() == KLogNullDuration);

	event1->SetDuration(0x12345678);
	TEST(event1->Duration() == 0x12345678);
	TestStoreL(*event1);

	event1->SetDuration(KMaxTUint32);
	TEST(event1->Duration() == KMaxTUint32);
	TestStoreL(*event1);

	event1->SetDuration(KLogNullDuration);
	TEST(event1->Duration() == KLogNullDuration);
	TestStoreL(*event1);

	// Status
	TEST(event1->Status() == KNullDesC);

	buf = TestUtils::CreateBufLC(KLogMaxStatusLength / 2);
	event1->SetStatus(buf->Des());
	TEST(event1->Status() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxStatusLength);
	event1->SetStatus(buf->Des());
	TEST(event1->Status() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxStatusLength * 2);
	event1->SetStatus(buf->Des());
	TEST(event1->Status() == buf->Des().Left(KLogMaxStatusLength));
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	event1->SetStatus(KNullDesC);
	TEST(event1->Status() == KNullDesC);
	TestStoreL(*event1);

	// Subject
	TEST(event1->Subject() == KNullDesC);

	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength / 2);
	event1->SetSubject(buf->Des());
	TEST(event1->Subject() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength);
	event1->SetSubject(buf->Des());
	TEST(event1->Subject() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength * 2);
	event1->SetSubject(buf->Des());
	TEST(event1->Subject() == buf->Des().Left(KLogMaxSubjectLength));
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	event1->SetSubject(KNullDesC);
	TEST(event1->Subject() == KNullDesC);
	TestStoreL(*event1);

	// Number
	TEST(event1->Number() == KNullDesC);

	buf = TestUtils::CreateBufLC(KLogMaxNumberLength / 2);
	event1->SetNumber(buf->Des());
	TEST(event1->Number() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxNumberLength);
	event1->SetNumber(buf->Des());
	TEST(event1->Number() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxNumberLength * 2);
	event1->SetNumber(buf->Des());
	TEST(event1->Number() == buf->Des().Left(KLogMaxNumberLength));
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	event1->SetNumber(KNullDesC);
	TEST(event1->Number() == KNullDesC);
	TestStoreL(*event1);

	// Contact
	TEST(event1->Contact() == KLogNullContactId);

	event1->SetContact(0x12345678);
	TEST(event1->Contact() == 0x12345678);
	TestStoreL(*event1);

	event1->SetContact(KMaxTInt32);
	TEST(event1->Contact() == KMaxTInt32);
	TestStoreL(*event1);

	event1->SetContact(KLogNullContactId);
	TEST(event1->Contact() == KLogNullContactId);
	TestStoreL(*event1);

	event1->SetContact(KMinTInt32);
	TEST(event1->Contact() == KMinTInt32);
	TestStoreL(*event1);

	// Link
	TEST(event1->Link() == KLogNullLink);

	event1->SetLink(0x12345678);
	TEST(event1->Link() == 0x12345678);
	TestStoreL(*event1);

	event1->SetLink(KMaxTUint32);
	TEST(event1->Link() == KMaxTUint32);
	TestStoreL(*event1);

	event1->SetLink(KLogNullLink);
	TEST(event1->Link() == KLogNullLink);

	// Description
	TEST(event1->Description() == KNullDesC);

	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength / 2);
	event1->SetDescription(buf->Des());
	TEST(event1->Description() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength);
	event1->SetDescription(buf->Des());
	TEST(event1->Description() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength * 2);
	event1->SetDescription(buf->Des());
	TEST(event1->Description() == buf->Des().Left(KLogMaxDescriptionLength));
	CleanupStack::PopAndDestroy(); // buf
	TestStoreL(*event1);

	event1->SetDescription(KNullDesC);
	TEST(event1->Description() == KNullDesC);

	// Flags
	TEST(event1->Flags() == KLogNullFlags);
	event1->SetFlags(1);
	TEST(event1->Flags() == 1);
	TestStoreL(*event1);
	event1->SetFlags(2);
	TEST(event1->Flags() == 3);
	event1->SetFlags(4);
	TEST(event1->Flags() == 7);
	event1->SetFlags(8);
	TEST(event1->Flags() == KLogFlagsMask);
	event1->ClearFlags(8);
	TEST(event1->Flags() == 7);
	event1->ClearFlags(4);
	TEST(event1->Flags() == 3);
	event1->ClearFlags(2);
	TEST(event1->Flags() == 1);
	event1->ClearFlags(1);
	TEST(event1->Flags() == KLogNullFlags);

	event1->SetFlags(1);
	TEST(event1->Flags() == 1);
	event1->SetFlags(3);
	TEST(event1->Flags() == 3);
	event1->SetFlags(7);
	TEST(event1->Flags() == 7);
	event1->SetFlags(15);
	event1->SetFlags(KLogFlagsMask);
	TEST(event1->Flags() == KLogFlagsMask);
	event1->ClearFlags(KLogFlagsMask);
	TEST(event1->Flags() == KLogNullFlags);

	event1->SetFlags(0x5);
	TEST(event1->Flags() == 0x5);
	event1->SetFlags(0xA);
	TEST(event1->Flags() == KLogFlagsMask);
	event1->ClearFlags(0x5);
	TEST(event1->Flags() == 0xA);
	event1->ClearFlags(0xA);
	TEST(event1->Flags() == KLogNullFlags);

	// Data
	TEST(event1->Data() == KNullDesC8);

	HBufC8* buf8;

	buf8 = TestUtils::CreateBuf8LC(100);
	event1->SetDataL(buf8->Des());
	TEST(event1->Data() == buf8->Des());
	CleanupStack::PopAndDestroy();
	TestStoreL(*event1);

	buf8 = TestUtils::CreateBuf8LC(200);
	event1->SetDataL(buf8->Des());
	TEST(event1->Data() == buf8->Des());
	CleanupStack::PopAndDestroy();
	TestStoreL(*event1);

	buf8 = TestUtils::CreateBuf8LC(400);
	event1->SetDataL(buf8->Des());
	TEST(event1->Data() == buf8->Des());
	CleanupStack::PopAndDestroy();
	TestStoreL(*event1);

	event1->SetDataL(KNullDesC8);
	TEST(event1->Data() == KNullDesC8);

	// streaming
	TFileName storename = _L("c:\\T_LOGEVENT_DATA");
	TUid uid={0x12345678};

	// create a store
	theFs.Delete(storename);
	CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(theFs, storename, uid);
	
	RDictionaryWriteStream write;
	RDictionaryReadStream read;

	event1->SetDataL(KNullDesC8);

	uid.iUid++;
	write.AssignL(*store, uid);
	write << event1->Data();
	write.CommitL();
	write.Close();

	read.OpenL(*store, uid);
	event1->SetDataL(read, 0);
	read.Close();

	TEST(event1->Data() == KNullDesC8);

	buf8 = TestUtils::CreateBuf8LC(100);
	event1->SetDataL(buf8->Des());

	uid.iUid++;
	write.AssignL(*store, uid);
	write.WriteL(event1->Data());
	write.CommitL();
	write.Close();

	read.OpenL(*store, uid);
	event1->SetDataL(read, 100);
	read.Close();

	TEST(event1->Data() == buf8->Des());
	CleanupStack::PopAndDestroy(); // buf8

	buf8 = TestUtils::CreateBuf8LC(200);
	event1->SetDataL(buf8->Des());

	uid.iUid++;
	write.AssignL(*store, uid);
	write.WriteL(event1->Data());
	write.CommitL();
	write.Close();

	read.OpenL(*store, uid);
	event1->SetDataL(read, 200);
	read.Close();

	TEST(event1->Data() == buf8->Des());
	CleanupStack::PopAndDestroy(); // buf8

	buf8 = TestUtils::CreateBuf8LC(400);
	event1->SetDataL(buf8->Des());

	uid.iUid++;
	write.AssignL(*store, uid);
	write.WriteL(event1->Data());
	write.CommitL();
	write.Close();

	read.OpenL(*store, uid);
	event1->SetDataL(read, 400);
	read.Close();

	TEST(event1->Data() == buf8->Des());
	CleanupStack::PopAndDestroy(2); // buf8, store

	// Copying
	event1->SetId(0x12345678);
	event1->SetEventType(TUid::Uid(0x12345678));

	buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength / 2);
	event1->SetRemoteParty(buf->Des());
	TEST(event1->RemoteParty() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength / 2);
	event1->SetDirection(buf->Des());
	TEST(event1->Direction() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	event1->SetDurationType(0xf);
	TEST(event1->DurationType() == 0xf);

	event1->SetDuration(0x12345678);
	TEST(event1->Duration() == 0x12345678);

	buf = TestUtils::CreateBufLC(KLogMaxStatusLength / 2);
	event1->SetStatus(buf->Des());
	TEST(event1->Status() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength / 2);
	event1->SetSubject(buf->Des());
	TEST(event1->Subject() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf = TestUtils::CreateBufLC(KLogMaxNumberLength / 2);
	event1->SetNumber(buf->Des());
	TEST(event1->Number() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	event1->SetContact(0x12345678);
	TEST(event1->Contact() == 0x12345678);

	event1->SetLink(0x12345678);
	TEST(event1->Link() == 0x12345678);

	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength / 2);
	event1->SetDescription(buf->Des());
	TEST(event1->Description() == buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf8 = TestUtils::CreateBuf8LC(200);
	event1->SetDataL(buf8->Des());
	TEST(event1->Data() == buf8->Des());
	CleanupStack::PopAndDestroy();

	CLogEvent* event2 = CLogEvent::NewL();
	CleanupStack::PushL(event2);
	TEST(!TestUtils::EventsEqual(*event1, *event2));

	event2->CopyL(*event1);
	TEST(TestUtils::EventsEqual(*event1, *event2));
	
	CleanupStack::PopAndDestroy(); // event2;

	event2 = CLogEvent::NewL();
	CleanupStack::PushL(event2);
	TEST(!TestUtils::EventsEqual(*event1, *event2));

	event1->CopyL(*event2);
	TEST(TestUtils::EventsEqual(*event1, *event2));

	CleanupStack::PopAndDestroy(2); // event1, event2;

	::DeleteDataFile(storename);
	}
Example #6
0
/**
@SYMTestCaseID          SYSLIB-LOGENG-CT-1009
@SYMTestCaseDesc	    Tests for CLogEvent::NewL(),SetDataL() functions
@SYMTestPriority 	    High
@SYMTestActions  	    Tests for creation of log event on heap and 
                        test for setting  event specific data from the specified stream and try to read the data back.
                        Check for memory errors
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void TestEventWithHeapFailL()
	{
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1009 "));
#ifdef _DEBUG
	TInt failCount = 0;
#endif
	TInt error;
	TBool finished = EFalse;

	CLogEvent* event = NULL;

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event = CLogEvent::NewL());
		
		__UHEAP_RESET;

		if (error == KErrNone)
			{
			finished = ETrue;
			CleanupStack::PushL(event);
			}
		else
			TEST2(error, KErrNoMemory);
		}

	_LIT8(KDataTest1, "01234567890123456789");
	_LIT8(KDataTest2, "012345678901234567890123456789");

	finished = EFalse;
#ifdef _DEBUG
	failCount = 0;
#endif
	event->SetDataL(KNullDesC8);

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event->SetDataL(KDataTest1));

		__UHEAP_RESET;

		if (error == KErrNone)
			{
			finished = ETrue;
			TEST(event->Data() == KDataTest1);
			}
		else
			{
			TEST2(error, KErrNoMemory);
			TEST(event->Data() == KNullDesC8);
			}
		}

	finished = EFalse;
#ifdef _DEBUG
	failCount = 0;
#endif
	event->SetDataL(KNullDesC8);

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event->SetDataL(KDataTest2));

		__UHEAP_RESET;

		if (error == KErrNone)
			{
			finished = ETrue;
			TEST(event->Data() == KDataTest2);
			}
		else
			{
			TEST2(error, KErrNoMemory);
			TEST(event->Data() == KNullDesC8);
			}
		}

	finished = EFalse;
#ifdef _DEBUG
	failCount = 0;
#endif
	event->SetDataL(KNullDesC8);

	// Check we don't get any more failures
	__UHEAP_FAILNEXT(0);
	event->SetDataL(KDataTest2);
	TEST(event->Data() == KDataTest2);
	event->SetDataL(KDataTest1);
	TEST(event->Data() == KDataTest1);
	event->SetDataL(KNullDesC8);
	TEST(event->Data() == KNullDesC8);
	__UHEAP_RESET;

	// streaming
	TFileName storename = _L("c:\\T_BASIC_DATA");
	TUid uid={0x12345678};

	// create a store
	theFs.Delete(storename);
	CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(theFs, storename, uid);
	
	RDictionaryWriteStream write;
	RDictionaryReadStream read;

	uid.iUid++;
	write.AssignL(*store, uid);
	write << KNullDesC8;
	write.CommitL();
	write.Close();

	read.OpenL(*store, uid);

#ifdef _DEBUG
	failCount = 0;
#endif
	finished = EFalse;

	__UHEAP_FAILNEXT(0);
	event->SetDataL(read, 0);
	__UHEAP_RESET;

	read.Close();	
	TEST(event->Data() == KNullDesC8);

	HBufC8* buf8 = TestUtils::CreateBuf8LC(100);

	uid.iUid++;
	write.AssignL(*store, uid);
	write.WriteL(buf8->Des());
	write.CommitL();
	write.Close();

	read.OpenL(*store, uid);

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event->SetDataL(read, 100));

		__UHEAP_RESET;

		if (error == KErrNone)
			{
			TEST(event->Data() == buf8->Des());
			read.Close();
			finished = ETrue;
			}
		else
			{
			TEST2(error, KErrNoMemory);
			TEST(event->Data() == KNullDesC8);
			}
		}

	event->SetId(0x12345678);
	event->SetEventType(TUid::Uid(0x12345678));

	HBufC* buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength / 2);
	event->SetRemoteParty(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength / 2);
	event->SetDirection(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	TTime time;

	time.UniversalTime();
	event->SetTime(time);
	TEST(event->Time() == time);

	event->SetDurationType(0xf);
	event->SetDuration(0x12345678);

	buf = TestUtils::CreateBufLC(KLogMaxStatusLength / 2);
	event->SetStatus(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength / 2);
	event->SetSubject(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf = TestUtils::CreateBufLC(KLogMaxNumberLength / 2);
	event->SetNumber(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	event->SetContact(0x12345678);
	event->SetLink(0x12345678);

	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength / 2);
	event->SetDescription(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	event->SetFlags(0xA);

	buf8 = TestUtils::CreateBuf8LC(100);
	event->SetDataL(buf8->Des());
	TEST(event->Data() == buf8->Des());
	CleanupStack::PopAndDestroy(); // buf8

	CLogEvent* event1 = CLogEvent::NewL();
	CleanupStack::PushL(event1);

	CLogEvent* event2 = CLogEvent::NewL();
	CleanupStack::PushL(event2);

	TEST(TestUtils::EventsEqual(*event1, *event2));

	finished = EFalse;
#ifdef _DEBUG
	failCount = 0;
#endif

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event1->CopyL(*event));

		__UHEAP_RESET;

		if (error == KErrNone)
			{
			TEST(!TestUtils::EventsEqual(*event1, *event2));
			TEST(TestUtils::EventsEqual(*event1, *event));
			finished = ETrue;
			}
		else
			{
			TEST2(error, KErrNoMemory);
			TEST(TestUtils::EventsEqual(*event1, *event2));
			TEST(!TestUtils::EventsEqual(*event1, *event));
			}
		}

	CleanupStack::PopAndDestroy(5); // buf8, store, event, event1, event2
	::DeleteDataFile(storename);
	}