persistentstorage/sqlite3api/TEST/t_sqlitedef.cpp
changeset 55 44f437012c90
parent 40 b8bdbc8f59c7
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    87 ///////////////////////////////////////////////////////////////////////////////////////
    87 ///////////////////////////////////////////////////////////////////////////////////////
    88 //Test macros and functions
    88 //Test macros and functions
    89 
    89 
    90 static void PrintErrMsg()
    90 static void PrintErrMsg()
    91 	{
    91 	{
    92 	TBuf<256> buf;
       
    93 	if(TheDb)
    92 	if(TheDb)
    94 		{
    93 		{
    95 		const char* msg = sqlite3_errmsg(TheDb);	
    94 		const char* msg = sqlite3_errmsg(TheDb);	
    96 		buf.Copy(TPtrC8((const TUint8*)msg));
    95 		PrintS("*** Db1 err msg: \"%s\"\r\n", msg);
    97 		RDebug::Print(_L("*** Db1 err msg: \"%S\"\r\n"), &buf);
       
    98 		}
    96 		}
    99 	if(TheDb2)
    97 	if(TheDb2)
   100 		{
    98 		{
   101 		const char* msg = sqlite3_errmsg(TheDb2);	
    99 		const char* msg = sqlite3_errmsg(TheDb2);	
   102 		buf.Copy(TPtrC8((const TUint8*)msg));
   100 		PrintS("*** Db2 err msg: \"%s\"\r\n", msg);
   103 		RDebug::Print(_L("*** Db2 err msg: \"%S\"\r\n"), &buf);
       
   104 		}
   101 		}
   105 	}
   102 	}
   106 
   103 
   107 static void Check(TInt aValue, TInt aLine)
   104 static void Check(TInt aValue, TInt aLine)
   108 	{
   105 	{
   109 	if(!aValue)
   106 	if(!aValue)
   110 		{
   107 		{
   111 		PrintErrMsg();
   108 		PrintErrMsg();
   112 		DestroyTestEnv();
   109 		DestroyTestEnv();
       
   110 		Print("*** Expression evaluated to false!\r\n");
   113 		TestTestLine(EFalse, aLine);
   111 		TestTestLine(EFalse, aLine);
   114 		}
   112 		}
   115 	}
   113 	}
   116 static void Check(TInt aValue, TInt aExpected, TInt aLine)
   114 static void Check(TInt aValue, TInt aExpected, TInt aLine)
   117 	{
   115 	{
   118 	if(aValue != aExpected)
   116 	if(aValue != aExpected)
   119 		{
   117 		{
   120 		PrintErrMsg();
   118 		PrintErrMsg();
   121 		DestroyTestEnv();
   119 		DestroyTestEnv();
   122 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   120 		PrintIII("*** Expected error: %d, got: %d. Ignore: %d\r\n", aExpected, aValue, 0);
   123 		TestTestLine(EFalse, aLine);
   121 		TestTestLine(EFalse, aLine);
   124 		}
   122 		}
   125 	}
   123 	}
   126 #define TEST(arg) ::Check((arg), __LINE__)
   124 #define TEST(arg) ::Check((arg), __LINE__)
   127 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   125 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   179 	// The created thread uses the heap of the creating thread
   177 	// The created thread uses the heap of the creating thread
   180 	// The same SQLite database can be accessed from different threads in
   178 	// The same SQLite database can be accessed from different threads in
   181 	// shared page cache mode only if the threads share the same heap.
   179 	// shared page cache mode only if the threads share the same heap.
   182 	// The database file handle will be shared between threads.
   180 	// The database file handle will be shared between threads.
   183 	////////////////////////////////////////////////////////////
   181 	////////////////////////////////////////////////////////////
   184 	RDebug::Print(_L("*** Shared heap\r\n"));	
   182 	Print("*** Shared heap\r\n");	
   185 	RThread thr;
   183 	RThread thr;
   186     err = thr.Create(_L("TestThr"), &ThreadFunc, KDefaultStackSize, NULL, NULL);
   184     err = thr.Create(_L("TestThr"), &ThreadFunc, KDefaultStackSize, NULL, NULL);
   187 	TEST2(err, KErrNone);
   185 	TEST2(err, KErrNone);
   188     thr.Resume();
   186     thr.Resume();
   189 	TRequestStatus stat;
   187 	TRequestStatus stat;
   224 @SYMTestExpectedResults Test must not fail
   222 @SYMTestExpectedResults Test must not fail
   225 @SYMDEF					DEF121506
   223 @SYMDEF					DEF121506
   226 */
   224 */
   227 void DEF121506()
   225 void DEF121506()
   228 	{
   226 	{
   229 	RDebug::Print(_L("Iteration: \r\n"));
   227 	Print("Iteration: \r\n");
   230 	for (TInt it = 1;  ; ++it)
   228 	for (TInt it = 1;  ; ++it)
   231 		{
   229 		{
   232 		RDebug::Print(_L("%d "), it);
   230 		PrintI("%d ", it);
   233 		TInt c1 = User::CountAllocCells();
   231 		TInt c1 = User::CountAllocCells();
   234  		__UHEAP_SETFAIL(RHeap::EDeterministic, it);
   232  		__UHEAP_SETFAIL(RHeap::EDeterministic, it);
   235 		
   233 		
   236  		TInt err = sqlite3_open(KTestDb,&TheDb);
   234  		TInt err = sqlite3_open(KTestDb,&TheDb);
   237 
   235 
   250 		__UHEAP_RESET;
   248 		__UHEAP_RESET;
   251 		
   249 		
   252  		TInt c2 = User::CountAllocCells();
   250  		TInt c2 = User::CountAllocCells();
   253  		if (c1 != c2)
   251  		if (c1 != c2)
   254 			{	
   252 			{	
   255 			RDebug::Print(_L("\r\n*** OOM Test failed\r\n"));
   253 			Print("\r\n*** OOM Test failed\r\n");
   256 			TEST(EFalse);
   254 			TEST(EFalse);
   257 			} 		
   255 			} 		
   258  		else if (err == SQLITE_OK) 
   256  		else if (err == SQLITE_OK) 
   259  			{
   257  			{
   260  			RDebug::Print(_L("\r\n*** OOM Test passed\r\n"));
   258  			Print("\r\n*** OOM Test passed\r\n");
   261  			break; 			
   259  			break; 			
   262  			}
   260  			}
   263  		TEST2(err, SQLITE_NOMEM);
   261  		TEST2(err, SQLITE_NOMEM);
   264  		}	
   262  		}	
   265 	}
   263 	}