lowlevellibsandfws/apputils/tsrc/t_strings/T_StringpoolDefect.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2004-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 // Test code for stringpool defects that have been fixed, to help prevent regression
       
    15 // 
       
    16 //
       
    17 
       
    18 /* this fixes a MSVC link warning */
       
    19 #ifdef __VC32__
       
    20 #pragma comment (linker, "/opt:noref") 
       
    21 #endif
       
    22 
       
    23 #include <stringpool.h>
       
    24 #include <f32file.h>
       
    25 #include <e32test.h>
       
    26 
       
    27 #include <stringpoolerr.h>
       
    28 
       
    29 #define UNUSED_VAR(a) a = a
       
    30 
       
    31 LOCAL_D CTrapCleanup*		TheTrapCleanup=NULL;
       
    32 
       
    33 LOCAL_D CActiveScheduler*	TheActiveScheduler=NULL;
       
    34 
       
    35 LOCAL_D RTest				test(_L("T_StringpoolDefect"));
       
    36 
       
    37 _LIT8(KDummyString,			"Dummy String For Test");
       
    38 
       
    39 //
       
    40 
       
    41 class RStringPoolPanicTest
       
    42 	{
       
    43 public:
       
    44 	RStringPoolPanicTest();
       
    45 	~RStringPoolPanicTest();
       
    46 	
       
    47 	void DEF043985L();
       
    48 	
       
    49 private:
       
    50 	// Functions to pass Thread creation process that invokes the defect
       
    51 	static TInt DEF043985_StringTest_ThreadL(TAny*); 
       
    52 	static TInt DEF043985_StringFTest_ThreadL(TAny*);
       
    53 	static TInt DEF043985_IndexTest_Thread(TAny*);
       
    54 	
       
    55 	static void DEF043985_IndexTest_SubFunctionL();
       
    56 	};
       
    57 
       
    58 RStringPoolPanicTest::RStringPoolPanicTest()
       
    59 	{
       
    60 	// do nothing
       
    61 	}
       
    62 
       
    63 RStringPoolPanicTest::~RStringPoolPanicTest()
       
    64 	{
       
    65 	// do nothing
       
    66 	}
       
    67 
       
    68 /**
       
    69 @SYMTestCaseID          SYSLIB-BAFL-CT-0488
       
    70 @SYMTestCaseDesc        Tests for defect number DEF043985
       
    71 @SYMTestPriority        High
       
    72 @SYMTestActions         Tests that the table is invalid when creating an RString
       
    73                         Check for panic    
       
    74 @SYMTestExpectedResults Tests must not fail
       
    75 @SYMREQ                 REQ0000
       
    76 */
       
    77 TInt RStringPoolPanicTest::DEF043985_StringTest_ThreadL(TAny*)
       
    78 	{
       
    79 	__UHEAP_MARK;
       
    80 
       
    81 	RStringPool stringPool;
       
    82 	stringPool.OpenL();
       
    83 
       
    84 	// Create a table and make it so it passes some internal tests
       
    85 	// for validity as we are testing a particular internal test
       
    86 	TStringTable testTable;
       
    87 	testTable.iCaseSensitive = ETrue;
       
    88 	testTable.iCount = 1;
       
    89 
       
    90 	// Test for Panic
       
    91 	RString testString = stringPool.String(0, testTable);
       
    92 
       
    93 	// Test should never get this far as it Panics
       
    94 
       
    95 	testString.Close();
       
    96 	stringPool.Close();
       
    97 
       
    98 	__UHEAP_MARKEND;
       
    99 
       
   100 	return KErrNone;		
       
   101 	}
       
   102 
       
   103 /**
       
   104 @SYMTestCaseID          SYSLIB-BAFL-CT-0489
       
   105 @SYMTestCaseDesc        Tests for defect number DEF043985
       
   106 @SYMTestPriority        High
       
   107 @SYMTestActions         Check for Panic
       
   108 @SYMTestExpectedResults Tests must not fail
       
   109 @SYMREQ                 REQ0000
       
   110 */
       
   111 TInt RStringPoolPanicTest::DEF043985_StringFTest_ThreadL(TAny*)
       
   112 	{
       
   113 	__UHEAP_MARK;
       
   114 
       
   115 	RStringPool stringPool;
       
   116 	stringPool.OpenL();
       
   117 
       
   118 	// Create a table and make it so it passes some internal tests
       
   119 	// for validity as we are testing a particular internal test
       
   120 	TStringTable testTable;
       
   121 	testTable.iCaseSensitive = EFalse;
       
   122 	testTable.iCount = 1;
       
   123 
       
   124 	// Test for Panic
       
   125 	RStringF testString = stringPool.StringF(0, testTable);
       
   126 	
       
   127 	// Test should never get this far as it Panics
       
   128 
       
   129 	testString.Close();
       
   130 	stringPool.Close();
       
   131 
       
   132 	__UHEAP_MARKEND;
       
   133 
       
   134 	return KErrNone;		
       
   135 	}
       
   136 
       
   137 /**
       
   138 Subtest function
       
   139 
       
   140 @SYMTestCaseID          SYSLIB-BAFL-CT-0490
       
   141 @SYMTestCaseDesc        Tests for defect number DEF043985
       
   142 @SYMTestPriority        High
       
   143 @SYMTestActions         Tests that the table is invalid when creating a folded RString
       
   144 @SYMTestExpectedResults Tests must not fail
       
   145 @SYMREQ                 REQ0000
       
   146 */
       
   147 void RStringPoolPanicTest::DEF043985_IndexTest_SubFunctionL()
       
   148 	{
       
   149 	__UHEAP_MARK;
       
   150 
       
   151 	RStringPool stringPool;
       
   152 	stringPool.OpenL();
       
   153 
       
   154 	// Create a table and make it so it passes some internal tests
       
   155 	// for validity as we are testing a particular internal test
       
   156 	TStringTable testTable;
       
   157 	testTable.iCaseSensitive = ETrue;
       
   158 	testTable.iCount = 1;
       
   159 
       
   160 	RString testString = stringPool.OpenStringL(KDummyString());
       
   161 	CleanupClosePushL(testString);
       
   162 	
       
   163 	// Test for Panic
       
   164 	testString.Index(testTable);
       
   165 	
       
   166 	// Test should never get this far as it Panics
       
   167 	
       
   168 	CleanupStack::PopAndDestroy(&testString);
       
   169 	stringPool.Close();
       
   170 	
       
   171 	__UHEAP_MARKEND;
       
   172 	}
       
   173 /**
       
   174 @SYMTestCaseID          SYSLIB-BAFL-CT-0491
       
   175 @SYMTestCaseDesc        Tests for the functionality of RStringPool
       
   176 @SYMTestPriority        High
       
   177 @SYMTestActions         Tests that the table is invalid when accessing an RStrings index
       
   178 @SYMTestExpectedResults Tests must not fail
       
   179 @SYMREQ                 REQ0000
       
   180 */
       
   181 TInt RStringPoolPanicTest::DEF043985_IndexTest_Thread(TAny*)
       
   182 	{
       
   183 	__UHEAP_MARK;
       
   184 
       
   185 	CTrapCleanup* trapCleanup = CTrapCleanup::New();
       
   186 	__ASSERT_ALWAYS(trapCleanup!=NULL, User::Invariant());
       
   187 
       
   188 	TRAPD(err, DEF043985_IndexTest_SubFunctionL());
       
   189     UNUSED_VAR(err);
       
   190 	
       
   191 	delete trapCleanup;
       
   192 	
       
   193 	__UHEAP_MARKEND;
       
   194 
       
   195 	return KErrNone;		
       
   196 	}
       
   197 
       
   198 /**
       
   199 Unfound TStringTable in Bafl StringPool not treated correctly.
       
   200 Check that the function panics when the specified table is not present.
       
   201 
       
   202 @SYMTestCaseID          SYSLIB-BAFL-CT-0492
       
   203 @SYMTestCaseDesc        Tests for the functionality of RStringPool
       
   204 @SYMTestPriority        High
       
   205 @SYMTestActions         Tests for panic when the specified table is not present
       
   206 @SYMTestExpectedResults Tests must not fail
       
   207 @SYMREQ                 REQ0000
       
   208 */
       
   209 void RStringPoolPanicTest::DEF043985L()
       
   210 	{
       
   211 	test.Next(_L("DEF043985L"));
       
   212 	
       
   213 #ifdef _DEBUG
       
   214 	__UHEAP_MARK;
       
   215 
       
   216 	TRequestStatus threadStatus;
       
   217 	RThread thread;
       
   218 	TInt rc;
       
   219 	TBool jit;
       
   220 	jit = User::JustInTime();
       
   221 	User::SetJustInTime(EFalse);
       
   222 	
       
   223 	// Test the Panics for this defect
       
   224 	
       
   225 	// RString Test
       
   226 	rc = thread.Create(_L("DEF043985_StringTest_Thread Panic Test"), 
       
   227 					   RStringPoolPanicTest::DEF043985_StringTest_ThreadL,
       
   228 					   KDefaultStackSize, KMinHeapSize, KMinHeapSize<<2, this);
       
   229 	test(KErrNone == rc);
       
   230 	thread.Logon(threadStatus);
       
   231 	thread.Resume();
       
   232 	User::WaitForRequest(threadStatus);
       
   233 	test (thread.ExitType() == EExitPanic);
       
   234 	test (thread.ExitReason() == StringPoolPanic::EStringTableNotFound);
       
   235 	thread.Close();
       
   236 
       
   237 	// RStringF Test
       
   238 	rc = thread.Create(_L("DEF043985_StringFTest_Thread Panic Test"), 
       
   239 					   RStringPoolPanicTest::DEF043985_StringFTest_ThreadL,
       
   240 					   KDefaultStackSize, KMinHeapSize, KMinHeapSize<<2, this);
       
   241 	test(KErrNone == rc);
       
   242 	thread.Logon(threadStatus);
       
   243 	thread.Resume();
       
   244 	User::WaitForRequest(threadStatus);
       
   245 	test (thread.ExitType() == EExitPanic);
       
   246 	test (thread.ExitReason() == StringPoolPanic::EStringTableNotFound);
       
   247 	thread.Close();
       
   248 
       
   249 	// Index Test
       
   250 	rc = thread.Create(_L("DEF043985_IndexTest_Thread Panic Test"), 
       
   251 					   RStringPoolPanicTest::DEF043985_IndexTest_Thread,
       
   252 					   KDefaultStackSize, KMinHeapSize, KMinHeapSize<<2, this);
       
   253 	test(KErrNone == rc);
       
   254 	thread.Logon(threadStatus);
       
   255 	thread.Resume();
       
   256 	User::WaitForRequest(threadStatus);
       
   257 	test (thread.ExitType() == EExitPanic);
       
   258 	test (thread.ExitReason() == StringPoolPanic::EStringTableNotFound);
       
   259 	thread.Close();
       
   260 
       
   261 
       
   262 	User::SetJustInTime(jit);
       
   263 
       
   264 	__UHEAP_MARKEND;
       
   265 	
       
   266 #else
       
   267 	test.Printf(_L("This test is valid for debug builds only, behaviour for release builds is undefined (DEF050908)\n"));
       
   268 #endif
       
   269 	}
       
   270 
       
   271 //===============================================================================
       
   272 
       
   273 /**
       
   274 Initialise the cleanup stack and active scheduler
       
   275 */
       
   276 LOCAL_C void SetupL()
       
   277     {    
       
   278 	TheTrapCleanup = CTrapCleanup::New();
       
   279 	User::LeaveIfNull(TheTrapCleanup);
       
   280 
       
   281 	// Construct and install the active scheduler
       
   282 	TheActiveScheduler = new(ELeave)CActiveScheduler;
       
   283 	CActiveScheduler::Install(TheActiveScheduler);
       
   284 	}
       
   285 
       
   286 /**
       
   287 Cleanup
       
   288 */
       
   289 LOCAL_C void CleanupL()
       
   290     {
       
   291 	delete TheActiveScheduler;
       
   292 	delete TheTrapCleanup;
       
   293 	}
       
   294 
       
   295 /**
       
   296 Invoke the tests
       
   297 */
       
   298 LOCAL_C void DoTestsL()
       
   299     {
       
   300 	RStringPoolPanicTest mytest;	
       
   301 	mytest.DEF043985L();
       
   302 	}
       
   303 
       
   304 
       
   305 GLDEF_C TInt E32Main()
       
   306 	{
       
   307 	__UHEAP_MARK;
       
   308 
       
   309 	test.Printf(_L("\n"));
       
   310 	test.Title();
       
   311 	test.Start(_L("Defect Tests"));
       
   312 	
       
   313 	TRAPD(err, SetupL()); 
       
   314 	test(err == KErrNone);
       
   315 	
       
   316 	TRAP(err, DoTestsL());
       
   317 	test(err == KErrNone);
       
   318 
       
   319 	CleanupL();
       
   320 	
       
   321 	test.End();
       
   322 	test.Close();
       
   323 
       
   324 	__UHEAP_MARKEND;
       
   325 	return(KErrNone);
       
   326 	}