os/persistentdata/persistentstorage/sqlite3api/TEST/t_sqlitedef.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
sl@0
    17
#include <e32test.h>
sl@0
    18
#include <e32uid.h>
sl@0
    19
#include <f32file.h>
sl@0
    20
#include <e32math.h>
sl@0
    21
#include <sqlite3.h>
sl@0
    22
sl@0
    23
#include "sqliteTestUtl.h"
sl@0
    24
sl@0
    25
const char* const KTestName = "t_sqlitedef";
sl@0
    26
sl@0
    27
static RFs	TheFs;
sl@0
    28
sl@0
    29
static sqlite3* TheDb = NULL;
sl@0
    30
static sqlite3* TheDb2 = NULL;
sl@0
    31
sl@0
    32
const char* KTestDir = "c:\\test\\";
sl@0
    33
const char* KTestDb  = "c:\\test\\t_sqlitedef.db";
sl@0
    34
const char* KTestDb2  = "c:\\t_sqlitedef.db";
sl@0
    35
sl@0
    36
static void DeleteFile(const char* aFileName)
sl@0
    37
	{
sl@0
    38
	TFileName fname;
sl@0
    39
	fname.Copy(TPtrC8((const TUint8*)aFileName));
sl@0
    40
	(void)TheFs.Delete(fname);
sl@0
    41
	}
sl@0
    42
sl@0
    43
/**
sl@0
    44
 * Creates the database file and the directory that the test file will be stored.
sl@0
    45
 */
sl@0
    46
static void CreateTestEnv()
sl@0
    47
    {
sl@0
    48
	TInt err = TheFs.Connect();
sl@0
    49
	TestTestLine(err == KErrNone, __LINE__);
sl@0
    50
	
sl@0
    51
	err = TheFs.ShareAuto();
sl@0
    52
	TestTestLine(err == KErrNone,__LINE__);
sl@0
    53
sl@0
    54
    TFileName testDir;
sl@0
    55
    testDir.Copy(TPtrC8((const TUint8*)KTestDir));
sl@0
    56
	err = TheFs.MkDir(testDir);
sl@0
    57
	TestTestLine(err == KErrNone || err == KErrAlreadyExists, __LINE__);
sl@0
    58
	
sl@0
    59
	TFileName fname;
sl@0
    60
	fname.Copy(TPtrC8((const TUint8*)KTestDb));
sl@0
    61
	(void)TheFs.Delete(fname);
sl@0
    62
	}
sl@0
    63
/**
sl@0
    64
 * Closes the database and erases the database file, but not the directory.
sl@0
    65
 */
sl@0
    66
static void DestroyTestEnv()
sl@0
    67
	{
sl@0
    68
	if(TheDb2)
sl@0
    69
		{
sl@0
    70
		(void)sqlite3_close(TheDb2);
sl@0
    71
		TheDb2 = 0;
sl@0
    72
		}
sl@0
    73
	if(TheDb)
sl@0
    74
		{
sl@0
    75
		(void)sqlite3_close(TheDb);
sl@0
    76
		TheDb = 0;
sl@0
    77
		}
sl@0
    78
	if(TheFs.Handle() != KNullHandle)
sl@0
    79
		{
sl@0
    80
		DeleteFile(KTestDb2);
sl@0
    81
		DeleteFile(KTestDb);
sl@0
    82
		}
sl@0
    83
	TheFs.Close();
sl@0
    84
	}
sl@0
    85
sl@0
    86
sl@0
    87
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    88
//Test macros and functions
sl@0
    89
sl@0
    90
static void PrintErrMsg()
sl@0
    91
	{
sl@0
    92
	TBuf<256> buf;
sl@0
    93
	if(TheDb)
sl@0
    94
		{
sl@0
    95
		const char* msg = sqlite3_errmsg(TheDb);	
sl@0
    96
		buf.Copy(TPtrC8((const TUint8*)msg));
sl@0
    97
		RDebug::Print(_L("*** Db1 err msg: \"%S\"\r\n"), &buf);
sl@0
    98
		}
sl@0
    99
	if(TheDb2)
sl@0
   100
		{
sl@0
   101
		const char* msg = sqlite3_errmsg(TheDb2);	
sl@0
   102
		buf.Copy(TPtrC8((const TUint8*)msg));
sl@0
   103
		RDebug::Print(_L("*** Db2 err msg: \"%S\"\r\n"), &buf);
sl@0
   104
		}
sl@0
   105
	}
sl@0
   106
sl@0
   107
static void Check(TInt aValue, TInt aLine)
sl@0
   108
	{
sl@0
   109
	if(!aValue)
sl@0
   110
		{
sl@0
   111
		PrintErrMsg();
sl@0
   112
		DestroyTestEnv();
sl@0
   113
		TestTestLine(EFalse, aLine);
sl@0
   114
		}
sl@0
   115
	}
sl@0
   116
static void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
   117
	{
sl@0
   118
	if(aValue != aExpected)
sl@0
   119
		{
sl@0
   120
		PrintErrMsg();
sl@0
   121
		DestroyTestEnv();
sl@0
   122
		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
   123
		TestTestLine(EFalse, aLine);
sl@0
   124
		}
sl@0
   125
	}
sl@0
   126
#define TEST(arg) ::Check((arg), __LINE__)
sl@0
   127
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0
   128
sl@0
   129
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   130
//
sl@0
   131
sl@0
   132
TInt ThreadFunc(void*)
sl@0
   133
	{
sl@0
   134
	User::SetJustInTime(EFalse);	// disable debugger panic handling
sl@0
   135
	
sl@0
   136
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   137
	TEST(tc != NULL);
sl@0
   138
sl@0
   139
    TInt err = sqlite3_open(KTestDb, &TheDb2); 
sl@0
   140
	TEST2(err, SQLITE_OK);
sl@0
   141
sl@0
   142
    err = sqlite3_exec(TheDb2, "CREATE TABLE A(Id INTEGER,Name TEXT)", 0, 0, 0);
sl@0
   143
	TEST2(err, SQLITE_OK);
sl@0
   144
    err = sqlite3_exec(TheDb2, "INSERT INTO A VALUES(1, 'AAA')", 0, 0, 0);
sl@0
   145
	TEST2(err, SQLITE_OK);
sl@0
   146
sl@0
   147
    sqlite3_close(TheDb2);
sl@0
   148
    TheDb2 = NULL;
sl@0
   149
sl@0
   150
	delete tc;	
sl@0
   151
sl@0
   152
	return 0;
sl@0
   153
	}
sl@0
   154
sl@0
   155
/**
sl@0
   156
@SYMTestCaseID			PDS-SQLITE3-UT-4029
sl@0
   157
@SYMTestCaseDesc		Sqlite file handle test
sl@0
   158
						The test verifies that a database can be opened from different threads in the same process,
sl@0
   159
						when the shared page cache is enabled. In this case the database file handle is shared between the
sl@0
   160
						threads that open the database.
sl@0
   161
@SYMTestPriority		High
sl@0
   162
@SYMTestActions			Sqlite file handle test
sl@0
   163
@SYMTestExpectedResults Test must not fail
sl@0
   164
@SYMREQ					REQ10424
sl@0
   165
*/
sl@0
   166
void FileHandleTest()
sl@0
   167
	{
sl@0
   168
	DeleteFile(KTestDb);
sl@0
   169
    sqlite3_enable_shared_cache(1);//this is a per-process setting (was per-thread in SQLite 3.3.17)
sl@0
   170
    TInt err = sqlite3_open(KTestDb, &TheDb); 
sl@0
   171
	TEST2(err, SQLITE_OK);
sl@0
   172
    
sl@0
   173
    err = sqlite3_exec(TheDb, "CREATE TABLE B(Id INTEGER,Name TEXT)", 0, 0, 0);
sl@0
   174
	TEST2(err, SQLITE_OK);
sl@0
   175
    err = sqlite3_exec(TheDb, "INSERT INTO B VALUES(1, 'BBB')", 0, 0, 0);
sl@0
   176
	TEST2(err, SQLITE_OK);
sl@0
   177
	
sl@0
   178
	////////////////////////////////////////////////////////////
sl@0
   179
	// The created thread uses the heap of the creating thread
sl@0
   180
	// The same SQLite database can be accessed from different threads in
sl@0
   181
	// shared page cache mode only if the threads share the same heap.
sl@0
   182
	// The database file handle will be shared between threads.
sl@0
   183
	////////////////////////////////////////////////////////////
sl@0
   184
	RDebug::Print(_L("*** Shared heap\r\n"));	
sl@0
   185
	RThread thr;
sl@0
   186
    err = thr.Create(_L("TestThr"), &ThreadFunc, KDefaultStackSize, NULL, NULL);
sl@0
   187
	TEST2(err, KErrNone);
sl@0
   188
    thr.Resume();
sl@0
   189
	TRequestStatus stat;
sl@0
   190
	thr.Logon(stat);
sl@0
   191
	User::WaitForRequest(stat);
sl@0
   192
	User::SetJustInTime(ETrue);	// enable debugger panic handling
sl@0
   193
	
sl@0
   194
	TInt exitType = thr.ExitType();
sl@0
   195
	TInt exitReason = thr.ExitReason();
sl@0
   196
	thr.Close();
sl@0
   197
	TEST2(exitReason, 0);
sl@0
   198
	TEST2(exitType, EExitKill);
sl@0
   199
	////////////////////////////////////////////////////////////
sl@0
   200
	
sl@0
   201
    sqlite3_close(TheDb);
sl@0
   202
    TheDb = NULL;
sl@0
   203
	}
sl@0
   204
sl@0
   205
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   206
///////////////         Sqlite3 DLL OOM test         ////////////////////////////////
sl@0
   207
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   208
sl@0
   209
/**
sl@0
   210
@SYMTestCaseID			PDS-SQLITE3-CT-4028
sl@0
   211
@SYMTestCaseDesc		Sqlite OOM test 
sl@0
   212
						Precondition: none
sl@0
   213
						A standard OOM test checks the sqlite3 DLL for memory leaks documented 
sl@0
   214
						on the raised defect, to check if the applied fix is working. Before 
sl@0
   215
						the fix the test was failing with PANIC USER:84 on the second iteration 
sl@0
   216
						loop on DoTest()
sl@0
   217
@SYMTestPriority		Medium
sl@0
   218
@SYMTestActions			Sqlite OOM test - 
sl@0
   219
						Opens the database file.						
sl@0
   220
						Calls sqlite3_prepare16_v2()
sl@0
   221
						Closes database
sl@0
   222
						Checks memory leaks
sl@0
   223
						Repeats the above indefinitely until SQLITE_OK
sl@0
   224
@SYMTestExpectedResults Test must not fail
sl@0
   225
@SYMDEF					DEF121506
sl@0
   226
*/
sl@0
   227
void DEF121506()
sl@0
   228
	{
sl@0
   229
	RDebug::Print(_L("Iteration: \r\n"));
sl@0
   230
	for (TInt it = 1;  ; ++it)
sl@0
   231
		{
sl@0
   232
		RDebug::Print(_L("%d "), it);
sl@0
   233
		TInt c1 = User::CountAllocCells();
sl@0
   234
 		__UHEAP_SETFAIL(RHeap::EDeterministic, it);
sl@0
   235
		
sl@0
   236
 		TInt err = sqlite3_open(KTestDb,&TheDb);
sl@0
   237
sl@0
   238
		if(err == SQLITE_OK)
sl@0
   239
			{
sl@0
   240
	 		sqlite3_stmt* stmt = 0; 
sl@0
   241
	 		const void* tail = 0;	
sl@0
   242
			err = sqlite3_prepare16_v2(TheDb, 
sl@0
   243
						L"CREATE TABLE Sample(Id INTEGER PRIMARY KEY NOT NULL, Name TEXT NOT NULL UNIQUE COLLATE NOCASE);", 
sl@0
   244
						-1, &stmt, &tail);	
sl@0
   245
			(void)sqlite3_finalize(stmt);
sl@0
   246
			}
sl@0
   247
 		
sl@0
   248
		(void)sqlite3_close(TheDb);
sl@0
   249
		TheDb = NULL;
sl@0
   250
		__UHEAP_RESET;
sl@0
   251
		
sl@0
   252
 		TInt c2 = User::CountAllocCells();
sl@0
   253
 		if (c1 != c2)
sl@0
   254
			{	
sl@0
   255
			RDebug::Print(_L("\r\n*** OOM Test failed\r\n"));
sl@0
   256
			TEST(EFalse);
sl@0
   257
			} 		
sl@0
   258
 		else if (err == SQLITE_OK) 
sl@0
   259
 			{
sl@0
   260
 			RDebug::Print(_L("\r\n*** OOM Test passed\r\n"));
sl@0
   261
 			break; 			
sl@0
   262
 			}
sl@0
   263
 		TEST2(err, SQLITE_NOMEM);
sl@0
   264
 		}	
sl@0
   265
	}
sl@0
   266
sl@0
   267
/**
sl@0
   268
@SYMTestCaseID			PDS-SQLITE3-CT-4046
sl@0
   269
@SYMTestCaseDesc		[sqlite3] can't execute sql sequence in transcation. 
sl@0
   270
@SYMTestPriority		High
sl@0
   271
@SYMTestActions			The test deletes the test application private data cage.
sl@0
   272
						Then the test creates a database and attempts to execute a set
sl@0
   273
						of SQL statements, some of them will need a temporary file to be created.
sl@0
   274
						Since the test application private data cage (so the session path) does not exist,
sl@0
   275
						the SQLite OS porting layer will fail to create the requested temporary file and
sl@0
   276
						will fail with KErrPathNotFound error. 
sl@0
   277
						The OS porting layer was fixed to create the session path if the temporary file creation error
sl@0
   278
						is KErrPathNotFound. 
sl@0
   279
@SYMTestExpectedResults Test must not fail
sl@0
   280
@SYMDEF					DEF140020
sl@0
   281
*/
sl@0
   282
void DEF140020()
sl@0
   283
	{
sl@0
   284
	//Remove the private data cage
sl@0
   285
	CFileMan* fm = 0;
sl@0
   286
	TRAPD(err, fm = CFileMan::NewL(TheFs));
sl@0
   287
	TEST(fm != 0);
sl@0
   288
	
sl@0
   289
	TFileName privatePath;
sl@0
   290
	err = TheFs.SessionPath(privatePath);
sl@0
   291
	TEST2(err, KErrNone);
sl@0
   292
	err = fm->RmDir(privatePath);
sl@0
   293
	TEST(err == KErrNone || err == KErrPathNotFound);
sl@0
   294
	
sl@0
   295
	delete fm;
sl@0
   296
	fm = 0;
sl@0
   297
sl@0
   298
	TEST2((TUint)TheDb, 0);
sl@0
   299
	err = sqlite3_open(KTestDb2, &TheDb);
sl@0
   300
	TEST2(err, SQLITE_OK);
sl@0
   301
	
sl@0
   302
    const char * stmt[] ={
sl@0
   303
            "CREATE TABLE fortest (id  INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, intcol INTEGER NOT NULL, charcol CHAR(255) ) ",
sl@0
   304
            "INSERT INTO fortest(intcol, charcol) VALUES(1,'111');",
sl@0
   305
            "BEGIN TRANSACTION;",
sl@0
   306
            "CREATE TABLE t1_backup(id INTEGER, intcol INTEGER NOT NULL);",
sl@0
   307
            "INSERT INTO t1_backup SELECT id, intcol FROM fortest;",
sl@0
   308
            "DROP TABLE fortest;",
sl@0
   309
            "CREATE TABLE fortest (id  INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, intcol INTEGER NOT NULL);",
sl@0
   310
            "INSERT INTO fortest(id, intcol) SELECT id,intcol FROM t1_backup;",
sl@0
   311
            "DROP TABLE t1_backup;",
sl@0
   312
            "select count(*) from fortest;",
sl@0
   313
            "COMMIT;",
sl@0
   314
            "select count(*) from fortest;",
sl@0
   315
            "CREATE TABLE t1_backup(id INTEGER, intcol INTEGER NOT NULL);",
sl@0
   316
            "INSERT INTO t1_backup SELECT id, intcol FROM fortest;",
sl@0
   317
            "DROP TABLE fortest;",
sl@0
   318
            "CREATE TABLE fortest (id  INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, intcol INTEGER NOT NULL);",
sl@0
   319
            "INSERT INTO fortest(id, intcol) SELECT id,intcol FROM t1_backup;",
sl@0
   320
            "DROP TABLE t1_backup;",
sl@0
   321
            };
sl@0
   322
sl@0
   323
    char* msg = NULL;
sl@0
   324
    int i = 0;
sl@0
   325
    for (i = 0; i < sizeof(stmt) / sizeof(*stmt); i++)
sl@0
   326
        {
sl@0
   327
        err = sqlite3_exec(TheDb, stmt[i], NULL, NULL, &msg);
sl@0
   328
        TEST2(err, SQLITE_OK);
sl@0
   329
        }
sl@0
   330
sl@0
   331
    sqlite3_close(TheDb);
sl@0
   332
    TheDb = 0;
sl@0
   333
    DeleteFile(KTestDb2);
sl@0
   334
	}
sl@0
   335
sl@0
   336
/**
sl@0
   337
@SYMTestCaseID          PDS-SQLITE3-CT-4047
sl@0
   338
@SYMTestCaseDesc        Test for DEF143066: SQLITE, "CREATE INDEX" sql crashes the SQLite library.
sl@0
   339
                        The test creates a database with one empty table and establishes two connections
sl@0
   340
                        to that database. Then, while the first connection is at the middle of a read
sl@0
   341
                        transaction, the second connection attempts to create an index.
sl@0
   342
                        If the defect is not fixed, the SQLite library will crash.
sl@0
   343
@SYMTestPriority        High
sl@0
   344
@SYMTestActions         DEF143066: SQLITE, "CREATE INDEX" sql crashes the SQLite library.
sl@0
   345
@SYMTestExpectedResults Test must not fail
sl@0
   346
@SYMDEF                 DEF143066
sl@0
   347
*/
sl@0
   348
void DEF143066()
sl@0
   349
    {
sl@0
   350
    DeleteFile(KTestDb);
sl@0
   351
    sqlite3_enable_shared_cache(1);
sl@0
   352
    int err = sqlite3_open(KTestDb, &TheDb); 
sl@0
   353
    TEST2(err, SQLITE_OK);
sl@0
   354
    
sl@0
   355
    err = sqlite3_exec(TheDb, "CREATE TABLE T0(Thread INTEGER, LocalIndex INTEGER, Inserts INTEGER, Updates INTEGER, IndexMod8 INTEGER)", 0, 0, 0);
sl@0
   356
    TEST2(err, SQLITE_OK);
sl@0
   357
    
sl@0
   358
    err = sqlite3_open(KTestDb, &TheDb2); 
sl@0
   359
    TEST2(err, SQLITE_OK);
sl@0
   360
sl@0
   361
    sqlite3_stmt* stmt = 0; 
sl@0
   362
    const char* tail = 0;   
sl@0
   363
    err = sqlite3_prepare_v2(TheDb, "SELECT COUNT(Thread) FROM T0 WHERE Thread = 0", -1, &stmt, &tail);
sl@0
   364
    TEST2(err, SQLITE_OK);
sl@0
   365
    
sl@0
   366
    err = sqlite3_step(stmt);
sl@0
   367
    TEST2(err, SQLITE_ROW);
sl@0
   368
sl@0
   369
    err = sqlite3_exec(TheDb2, "CREATE INDEX T0INDEX ON T0(Thread,IndexMod8)", 0, 0, 0);
sl@0
   370
    TEST2(err, SQLITE_LOCKED);
sl@0
   371
    
sl@0
   372
    (void)sqlite3_finalize(stmt);
sl@0
   373
    sqlite3_close(TheDb2);
sl@0
   374
    TheDb2 = NULL;
sl@0
   375
    sqlite3_close(TheDb);
sl@0
   376
    TheDb = NULL;
sl@0
   377
    DeleteFile(KTestDb);
sl@0
   378
    }
sl@0
   379
sl@0
   380
/**
sl@0
   381
@SYMTestCaseID          PDS-SQL-CT-4048
sl@0
   382
@SYMTestCaseDesc        Test for DEF143151: SQLite, strftime() returns incorrect result.
sl@0
   383
                        The test takes the current universal time (using TTime) 
sl@0
   384
                        and the current time retrieved from the SQLite library.
sl@0
   385
                        The test compares the times and expects the difference to be no more than
sl@0
   386
                        1 second. 
sl@0
   387
@SYMTestPriority        High
sl@0
   388
@SYMTestActions         DEF143151: SQLite, strftime() returns incorrect result
sl@0
   389
@SYMTestExpectedResults Test must not fail
sl@0
   390
@SYMDEF                 DEF143151
sl@0
   391
*/
sl@0
   392
void DEF143151()
sl@0
   393
    {
sl@0
   394
    DeleteFile(KTestDb);
sl@0
   395
    int err = sqlite3_open(KTestDb, &TheDb); 
sl@0
   396
    TEST2(err, SQLITE_OK);
sl@0
   397
sl@0
   398
    //Home date & time
sl@0
   399
    TBuf<50> dtstr1;
sl@0
   400
    TTime time;
sl@0
   401
    time.UniversalTime();
sl@0
   402
    TDateTime dt = time.DateTime();
sl@0
   403
    
sl@0
   404
    sqlite3_stmt* stmt = 0; 
sl@0
   405
    const char* tail = 0;   
sl@0
   406
    err = sqlite3_prepare_v2(TheDb, "SELECT strftime('%Y-%m-%d,%H:%M:%S','now')", -1, &stmt, &tail);
sl@0
   407
    TEST2(err, SQLITE_OK);
sl@0
   408
    err = sqlite3_step(stmt);
sl@0
   409
    TEST2(err, SQLITE_ROW);
sl@0
   410
    
sl@0
   411
    //SQLite date & time
sl@0
   412
    const unsigned char* s = sqlite3_column_text(stmt, 0);
sl@0
   413
    TEST(s != NULL);
sl@0
   414
    TBuf<50> dtstr2;
sl@0
   415
    dtstr2.Copy(TPtrC8(s));
sl@0
   416
    sqlite3_finalize(stmt);
sl@0
   417
sl@0
   418
    sqlite3_close(TheDb);
sl@0
   419
    TheDb = NULL;
sl@0
   420
    DeleteFile(KTestDb);
sl@0
   421
    
sl@0
   422
    dtstr1.Format(_L("%04d-%02d-%02d,%02d:%02d:%02d"), dt.Year(), dt.Month() + 1, dt.Day() + 1, dt.Hour(), dt.Minute(), dt.Second());
sl@0
   423
sl@0
   424
    // For the C-Style printout
sl@0
   425
    _LIT8(KUniversalTimeText,"Universal date&time=");
sl@0
   426
    _LIT8(KSQLiteTimeText,   "SQLite    date&time=");
sl@0
   427
    TBuf8<96> dtstr1print;
sl@0
   428
    TBuf8<96> dtstr2print;
sl@0
   429
    dtstr1print.Copy(dtstr1);
sl@0
   430
    dtstr2print.Copy(dtstr2);
sl@0
   431
    dtstr1print.Insert(0,KUniversalTimeText);
sl@0
   432
    dtstr2print.Insert(0,KSQLiteTimeText);
sl@0
   433
    TestPrintf((const char*)(dtstr1print.PtrZ()));
sl@0
   434
    TestPrintf((const char*)(dtstr2print.PtrZ()));
sl@0
   435
    
sl@0
   436
    //Comapare and fail if dates are not equal (+- 1 second)
sl@0
   437
    TLex lex;
sl@0
   438
    lex = dtstr2.Mid(0, 4);
sl@0
   439
    TInt sqlyear;
sl@0
   440
    err = lex.Val(sqlyear);
sl@0
   441
    TEST2(err, KErrNone);
sl@0
   442
    
sl@0
   443
    lex = dtstr2.Mid(5, 2);
sl@0
   444
    TInt sqlmonth;
sl@0
   445
    err = lex.Val(sqlmonth);
sl@0
   446
    TEST2(err, KErrNone);
sl@0
   447
    
sl@0
   448
    lex = dtstr2.Mid(8, 2);
sl@0
   449
    TInt sqlday;
sl@0
   450
    err = lex.Val(sqlday);
sl@0
   451
    TEST2(err, KErrNone);
sl@0
   452
    
sl@0
   453
    lex = dtstr2.Mid(11, 2);
sl@0
   454
    TInt sqlhour;
sl@0
   455
    err = lex.Val(sqlhour);
sl@0
   456
    TEST2(err, KErrNone);
sl@0
   457
    
sl@0
   458
    lex = dtstr2.Mid(14, 2);
sl@0
   459
    TInt sqlminute;
sl@0
   460
    err = lex.Val(sqlminute);
sl@0
   461
    TEST2(err, KErrNone);
sl@0
   462
    
sl@0
   463
    lex = dtstr2.Mid(17, 2);
sl@0
   464
    TInt sqlsecond;
sl@0
   465
    err = lex.Val(sqlsecond);
sl@0
   466
    TEST2(err, KErrNone);
sl@0
   467
    
sl@0
   468
    TDateTime sqldt(sqlyear, (TMonth)(sqlmonth - 1), sqlday - 1, sqlhour, sqlminute, sqlsecond, 0);
sl@0
   469
    TTime sqltime(sqldt);
sl@0
   470
    TTimeIntervalSeconds diff;
sl@0
   471
    err = sqltime.SecondsFrom(time, diff);
sl@0
   472
    TEST2(err, KErrNone);
sl@0
   473
    TEST(diff.Int() <= 1);
sl@0
   474
    }
sl@0
   475
sl@0
   476
void DoTest()
sl@0
   477
	{
sl@0
   478
	TestStart("@SYMTestCaseID:PDS-SQLITE3-UT-4029: SQLite file handle test");
sl@0
   479
	FileHandleTest();
sl@0
   480
	
sl@0
   481
	TestNext("@SYMTestCaseID:PDS-SQLITE3-CT-4028: DEF121506 test");
sl@0
   482
	DEF121506();
sl@0
   483
sl@0
   484
	TestNext("@SYMTestCaseID:PDS-SQLITE3-CT-4046: DEF140020 test");
sl@0
   485
	DEF140020();
sl@0
   486
sl@0
   487
    TestNext("@SYMTestCaseID:PDS-SQLITE3-CT-4047: SQLITE, \"CREATE INDEX\" sql crashes the SQLite library");
sl@0
   488
    DEF143066();
sl@0
   489
sl@0
   490
    TestNext(" @SYMTestCaseID:SYSLIB-SQL-CT-4048 DEF143151: SQLite, strftime() returns incorrect result");
sl@0
   491
    DEF143151();
sl@0
   492
	}
sl@0
   493
sl@0
   494
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   495
sl@0
   496
TInt E32Main()
sl@0
   497
	{
sl@0
   498
	TestOpen(KTestName);
sl@0
   499
	TestTitle();
sl@0
   500
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   501
sl@0
   502
	__UHEAP_MARK;
sl@0
   503
	
sl@0
   504
	CreateTestEnv();
sl@0
   505
	DoTest();
sl@0
   506
	DestroyTestEnv();
sl@0
   507
	
sl@0
   508
	__UHEAP_MARKEND;
sl@0
   509
sl@0
   510
	TestEnd();	
sl@0
   511
	TestClose();
sl@0
   512
	delete tc;
sl@0
   513
	User::Heap().Check();
sl@0
   514
	return KErrNone;
sl@0
   515
	}