persistentstorage/store/TSTOR/t_storbench.cpp
changeset 0 08ec8eefde2f
child 55 44f437012c90
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <s32mem.h>
       
    17 #include <s32file.h>
       
    18 #include <e32test.h>
       
    19 #include <e32base.h>
       
    20 #include <e32cons.h>
       
    21 
       
    22 static	RTest				TheTest(_L("t_storbench"));
       
    23 static	CTrapCleanup*		TheTrapCleanup;
       
    24 static	RFs					TheFs;
       
    25 
       
    26 TFileName TheDirectStoreFilePath;
       
    27 TFileName ThePermStoreFilePath;
       
    28 TFileName TheStreamsFilePath;
       
    29 
       
    30 static void DeleteDataFiles();
       
    31 
       
    32 const TInt KTestCleanupStack=0x20;
       
    33 
       
    34 class TElement
       
    35 	{
       
    36 public :
       
    37 	TElement();
       
    38 public :
       
    39 	TBuf<256> iData;
       
    40 	};
       
    41 
       
    42 TElement::TElement()
       
    43 	{
       
    44 	_LIT(KTextBase,"BASE");
       
    45 	iData = KTextBase;
       
    46 	}
       
    47 
       
    48 #include "T_BMStreams.inl"
       
    49 #include "T_BMStreamStore.inl"
       
    50 #include "T_BMDirectFileStore.inl"
       
    51 #include "T_BMPermFileStore.inl"
       
    52 
       
    53 //Tests macroses and functions.
       
    54 //If (!aValue) then the test will be panicked, the test data files will be deleted.
       
    55 static void Check(TInt aValue, TInt aLine)
       
    56 	{
       
    57 	if(!aValue)
       
    58 		{
       
    59 		DeleteDataFiles();
       
    60 		TheTest(EFalse, aLine);
       
    61 		}
       
    62 	}
       
    63 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
       
    64 static void Check(TInt aValue, TInt aExpected, TInt aLine)
       
    65 	{
       
    66 	if(aValue != aExpected)
       
    67 		{
       
    68 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    69 		DeleteDataFiles();
       
    70 		TheTest(EFalse, aLine);
       
    71 		}
       
    72 	}
       
    73 //Use these to test conditions.
       
    74 #define TEST(arg) ::Check((arg), __LINE__)
       
    75 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    76 
       
    77 LOCAL_C void PerformanceTesting()
       
    78 	{
       
    79 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-LEGACY-STOREBENCHMARK-1204 Performance Testing for STORE Component "));
       
    80 	// Call the performance tests
       
    81 	TRAPD(err, doStreamingL());
       
    82 	TEST2(err, KErrNone);
       
    83 
       
    84 	TRAP(err, doStoreStreamsL());
       
    85 	TEST2(err, KErrNone);
       
    86 
       
    87 	TRAP(err, doDirectFileStoresL());
       
    88 	TEST2(err, KErrNone);
       
    89 
       
    90 	TRAP(err, doPermanentFileStoreL());
       
    91 	TEST2(err, KErrNone);
       
    92 	}
       
    93 
       
    94 // Prepare the test directory.
       
    95 LOCAL_C void setupTestDirectory()
       
    96     {
       
    97 	TInt err=TheFs.Connect();
       
    98 	TEST2(err, KErrNone);
       
    99 
       
   100 	TPtrC testDir=_L("\\STOR-TST\\");
       
   101 	err=TheFs.MkDir(testDir);
       
   102 	TEST(err == KErrNone || err == KErrAlreadyExists);
       
   103 
       
   104 	err=TheFs.SetSessionPath(testDir);
       
   105 	TEST2(err, KErrNone);
       
   106 	}
       
   107 
       
   108 // Initialise the cleanup stack.
       
   109 LOCAL_C void setupCleanup()
       
   110     {
       
   111 	TheTrapCleanup=CTrapCleanup::New();
       
   112 	TEST(TheTrapCleanup != NULL);
       
   113 	TRAPD(err,\
       
   114 		{\
       
   115 		for (TInt i=KTestCleanupStack;i>0;i--)\
       
   116 			CleanupStack::PushL((TAny*)1);\
       
   117 		TEST(err==KErrNone);\
       
   118 		CleanupStack::Pop(KTestCleanupStack);\
       
   119 		});
       
   120 	TEST2(err, KErrNone);
       
   121 	}
       
   122 
       
   123 static void DeleteDataFile(const TDesC& aFullName)
       
   124 	{
       
   125 	RFs fsSession;
       
   126 	TInt err = fsSession.Connect();
       
   127 	if(err == KErrNone)
       
   128 		{
       
   129 		TEntry entry;
       
   130 		if(fsSession.Entry(aFullName, entry) == KErrNone)
       
   131 			{
       
   132 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
       
   133 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
       
   134 			if(err != KErrNone)
       
   135 				{
       
   136 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
       
   137 				}
       
   138 			err = fsSession.Delete(aFullName);
       
   139 			if(err != KErrNone)
       
   140 				{
       
   141 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
       
   142 				}
       
   143 			}
       
   144 		fsSession.Close();
       
   145 		}
       
   146 	else
       
   147 		{
       
   148 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
       
   149 		}
       
   150 	}
       
   151 static void DeleteDataFiles()
       
   152 	{
       
   153 	DeleteDataFile(TheDirectStoreFilePath);
       
   154 	DeleteDataFile(ThePermStoreFilePath);
       
   155 	DeleteDataFile(TheStreamsFilePath);
       
   156 	}
       
   157 
       
   158 // Test the stream and stores
       
   159 GLDEF_C TInt E32Main()
       
   160     {
       
   161 	__UHEAP_MARK;
       
   162 	TheTest.Title();
       
   163 	setupTestDirectory();
       
   164 	setupCleanup();
       
   165 
       
   166 	TRAPD(err, PerformanceTesting());
       
   167 	TEST2(err, KErrNone);
       
   168 
       
   169 	DeleteDataFiles();
       
   170 
       
   171 	TheTest.End();
       
   172 	delete TheTrapCleanup;
       
   173 	TheFs.Close();
       
   174 	TheTest.Close();
       
   175 	__UHEAP_MARKEND;
       
   176 
       
   177 	return 0;
       
   178 	}
       
   179 
       
   180 
       
   181