persistentstorage/sqlite3api/TEST/t_sqlitedef.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
    18 #include <e32uid.h>
    18 #include <e32uid.h>
    19 #include <f32file.h>
    19 #include <f32file.h>
    20 #include <e32math.h>
    20 #include <e32math.h>
    21 #include <sqlite3.h>
    21 #include <sqlite3.h>
    22 
    22 
    23 #include "sqliteTestUtl.h"
    23 #include "e32des16.h"
    24 
    24 
    25 const char* const KTestName = "t_sqlitedef";
    25 
    26 
    26 static RTest TheTest(_L("t_sqlitedef"));
    27 static RFs	TheFs;
    27 static RFs	TheFs;
    28 
    28 
    29 static sqlite3* TheDb = NULL;
    29 static sqlite3* TheDb = NULL;
    30 static sqlite3* TheDb2 = NULL;
    30 static sqlite3* TheDb2 = NULL;
    31 
    31 
    44  * Creates the database file and the directory that the test file will be stored.
    44  * Creates the database file and the directory that the test file will be stored.
    45  */
    45  */
    46 static void CreateTestEnv()
    46 static void CreateTestEnv()
    47     {
    47     {
    48 	TInt err = TheFs.Connect();
    48 	TInt err = TheFs.Connect();
    49 	TestTestLine(err == KErrNone, __LINE__);
    49 	TheTest(err == KErrNone);
    50 	
    50 	
    51 	err = TheFs.ShareAuto();
    51 	err = TheFs.ShareAuto();
    52 	TestTestLine(err == KErrNone,__LINE__);
    52 	TheTest(err == KErrNone);
    53 
    53 
    54     TFileName testDir;
    54     TFileName testDir;
    55     testDir.Copy(TPtrC8((const TUint8*)KTestDir));
    55     testDir.Copy(TPtrC8((const TUint8*)KTestDir));
    56 	err = TheFs.MkDir(testDir);
    56 	err = TheFs.MkDir(testDir);
    57 	TestTestLine(err == KErrNone || err == KErrAlreadyExists, __LINE__);
    57 	TheTest(err == KErrNone || err == KErrAlreadyExists);
    58 	
    58 	
    59 	TFileName fname;
    59 	TFileName fname;
    60 	fname.Copy(TPtrC8((const TUint8*)KTestDb));
    60 	fname.Copy(TPtrC8((const TUint8*)KTestDb));
    61 	(void)TheFs.Delete(fname);
    61 	(void)TheFs.Delete(fname);
    62 	}
    62 	}
   108 	{
   108 	{
   109 	if(!aValue)
   109 	if(!aValue)
   110 		{
   110 		{
   111 		PrintErrMsg();
   111 		PrintErrMsg();
   112 		DestroyTestEnv();
   112 		DestroyTestEnv();
   113 		TestTestLine(EFalse, aLine);
   113 		TheTest(EFalse, aLine);
   114 		}
   114 		}
   115 	}
   115 	}
   116 static void Check(TInt aValue, TInt aExpected, TInt aLine)
   116 static void Check(TInt aValue, TInt aExpected, TInt aLine)
   117 	{
   117 	{
   118 	if(aValue != aExpected)
   118 	if(aValue != aExpected)
   119 		{
   119 		{
   120 		PrintErrMsg();
   120 		PrintErrMsg();
   121 		DestroyTestEnv();
   121 		DestroyTestEnv();
   122 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   122 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   123 		TestTestLine(EFalse, aLine);
   123 		TheTest(EFalse, aLine);
   124 		}
   124 		}
   125 	}
   125 	}
   126 #define TEST(arg) ::Check((arg), __LINE__)
   126 #define TEST(arg) ::Check((arg), __LINE__)
   127 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   127 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   128 
   128 
   418     sqlite3_close(TheDb);
   418     sqlite3_close(TheDb);
   419     TheDb = NULL;
   419     TheDb = NULL;
   420     DeleteFile(KTestDb);
   420     DeleteFile(KTestDb);
   421     
   421     
   422     dtstr1.Format(_L("%04d-%02d-%02d,%02d:%02d:%02d"), dt.Year(), dt.Month() + 1, dt.Day() + 1, dt.Hour(), dt.Minute(), dt.Second());
   422     dtstr1.Format(_L("%04d-%02d-%02d,%02d:%02d:%02d"), dt.Year(), dt.Month() + 1, dt.Day() + 1, dt.Hour(), dt.Minute(), dt.Second());
   423 
   423     TheTest.Printf(_L("Universal date&time=\"%S\"\n"), &dtstr1);
   424     // For the C-Style printout
   424     TheTest.Printf(_L("SQLite    date&time=\"%S\"\n"), &dtstr2);
   425     _LIT8(KUniversalTimeText,"Universal date&time=");
       
   426     _LIT8(KSQLiteTimeText,   "SQLite    date&time=");
       
   427     TBuf8<96> dtstr1print;
       
   428     TBuf8<96> dtstr2print;
       
   429     dtstr1print.Copy(dtstr1);
       
   430     dtstr2print.Copy(dtstr2);
       
   431     dtstr1print.Insert(0,KUniversalTimeText);
       
   432     dtstr2print.Insert(0,KSQLiteTimeText);
       
   433     TestPrintf((const char*)(dtstr1print.PtrZ()));
       
   434     TestPrintf((const char*)(dtstr2print.PtrZ()));
       
   435     
   425     
   436     //Comapare and fail if dates are not equal (+- 1 second)
   426     //Comapare and fail if dates are not equal (+- 1 second)
   437     TLex lex;
   427     TLex lex;
   438     lex = dtstr2.Mid(0, 4);
   428     lex = dtstr2.Mid(0, 4);
   439     TInt sqlyear;
   429     TInt sqlyear;
   473     TEST(diff.Int() <= 1);
   463     TEST(diff.Int() <= 1);
   474     }
   464     }
   475 
   465 
   476 void DoTest()
   466 void DoTest()
   477 	{
   467 	{
   478 	TestStart("@SYMTestCaseID:PDS-SQLITE3-UT-4029: SQLite file handle test");
   468 	TheTest.Start(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4029: SQLite file handle test"));
   479 	FileHandleTest();
   469 	FileHandleTest();
   480 	
   470 	
   481 	TestNext("@SYMTestCaseID:PDS-SQLITE3-CT-4028: DEF121506 test");
   471 	TheTest.Next(_L("@SYMTestCaseID:PDS-SQLITE3-CT-4028: DEF121506 test"));
   482 	DEF121506();
   472 	DEF121506();
   483 
   473 
   484 	TestNext("@SYMTestCaseID:PDS-SQLITE3-CT-4046: DEF140020 test");
   474 	TheTest.Next(_L("@SYMTestCaseID:PDS-SQLITE3-CT-4046: DEF140020 test"));
   485 	DEF140020();
   475 	DEF140020();
   486 
   476 
   487     TestNext("@SYMTestCaseID:PDS-SQLITE3-CT-4047: SQLITE, \"CREATE INDEX\" sql crashes the SQLite library");
   477     TheTest.Next(_L("@SYMTestCaseID:PDS-SQLITE3-CT-4047: SQLITE, \"CREATE INDEX\" sql crashes the SQLite library"));
   488     DEF143066();
   478     DEF143066();
   489 
   479 
   490     TestNext(" @SYMTestCaseID:SYSLIB-SQL-CT-4048 DEF143151: SQLite, strftime() returns incorrect result");
   480     TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4048 DEF143151: SQLite, strftime() returns incorrect result"));
   491     DEF143151();
   481     DEF143151();
   492 	}
   482 	}
   493 
   483 
   494 ///////////////////////////////////////////////////////////////////////////////////////
   484 ///////////////////////////////////////////////////////////////////////////////////////
   495 
   485 
   496 TInt E32Main()
   486 TInt E32Main()
   497 	{
   487 	{
   498 	TestOpen(KTestName);
   488 	TheTest.Title();
   499 	TestTitle();
       
   500 	CTrapCleanup* tc = CTrapCleanup::New();
   489 	CTrapCleanup* tc = CTrapCleanup::New();
   501 
   490 
   502 	__UHEAP_MARK;
   491 	__UHEAP_MARK;
   503 	
   492 	
   504 	CreateTestEnv();
   493 	CreateTestEnv();
   505 	DoTest();
   494 	DoTest();
   506 	DestroyTestEnv();
   495 	DestroyTestEnv();
   507 	
   496 	
   508 	__UHEAP_MARKEND;
   497 	__UHEAP_MARKEND;
   509 
   498 
   510 	TestEnd();	
   499 	TheTest.End();	
   511 	TestClose();
   500 	TheTest.Close();
   512 	delete tc;
   501 	delete tc;
   513 	User::Heap().Check();
   502 	User::Heap().Check();
   514 	return KErrNone;
   503 	return KErrNone;
   515 	}
   504 	}