os/persistentdata/persistentstorage/sql/TEST/t_sqlgetfirststmt.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-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
#include <e32debug.h>
sl@0
    17
#include <e32test.h>
sl@0
    18
#include <f32file.h>
sl@0
    19
#include "sqlite3.h"
sl@0
    20
#include <stdlib.h>
sl@0
    21
#include "SqliteSymbian.h"
sl@0
    22
#include "SqlAssert.h"
sl@0
    23
sl@0
    24
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    25
sl@0
    26
RTest TheTest(_L("t_SqlGetFirstStmt test"));
sl@0
    27
RFs TheFs;
sl@0
    28
sqlite3* TheSqliteDb;
sl@0
    29
sl@0
    30
_LIT(KTestDir, "c:\\test\\");
sl@0
    31
_LIT(KTestDatabase, "c:\\test\\DEF104744.db");
sl@0
    32
_LIT8(KTestDatabaseZ, "c:\\test\\DEF104744.db\x0");
sl@0
    33
sl@0
    34
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    35
sl@0
    36
//Deletes all created test files.
sl@0
    37
void DestroyTestEnv()
sl@0
    38
	{
sl@0
    39
	if(TheSqliteDb)
sl@0
    40
		{
sl@0
    41
		sqlite3_close(TheSqliteDb);	
sl@0
    42
		TheSqliteDb = NULL;
sl@0
    43
		}
sl@0
    44
	(void)TheFs.Delete(KTestDatabase);
sl@0
    45
	TheFs.Close();
sl@0
    46
	}
sl@0
    47
sl@0
    48
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    49
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    50
//Test macros and functions
sl@0
    51
void Check1(TInt aValue, TInt aLine)
sl@0
    52
	{
sl@0
    53
	if(!aValue)
sl@0
    54
		{
sl@0
    55
		DestroyTestEnv();
sl@0
    56
		RDebug::Print(_L("*** Line %d\r\n"), aLine);
sl@0
    57
		TheTest(EFalse, aLine);
sl@0
    58
		}
sl@0
    59
	}
sl@0
    60
void Check2(TInt aValue, TInt aExpected, TInt aLine)
sl@0
    61
	{
sl@0
    62
	if(aValue != aExpected)
sl@0
    63
		{
sl@0
    64
		DestroyTestEnv();
sl@0
    65
		RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
sl@0
    66
		TheTest(EFalse, aLine);
sl@0
    67
		}
sl@0
    68
	}
sl@0
    69
#define TEST(arg) ::Check1((arg), __LINE__)
sl@0
    70
#define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
sl@0
    71
sl@0
    72
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    73
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    74
sl@0
    75
extern TPtrC GetFirstSqlStmt(TPtr& aString);
sl@0
    76
sl@0
    77
#define PTR_ARG(buf) const_cast <TUint16*> (buf.Ptr()), buf.Length(), buf.Length()
sl@0
    78
sl@0
    79
/**
sl@0
    80
@SYMTestCaseID			SYSLIB-SQL-CT-1628
sl@0
    81
@SYMTestCaseDesc		GetFirstSqlStmt() test
sl@0
    82
						Tests the GetFirstSqlStmt() behaviour with a set of various SQL statements.
sl@0
    83
@SYMTestPriority		High
sl@0
    84
@SYMTestActions			GetFirstSqlStmt() test
sl@0
    85
@SYMTestExpectedResults Test must not fail
sl@0
    86
@SYMREQ					REQ5792
sl@0
    87
                        REQ5793
sl@0
    88
*/	
sl@0
    89
void TestGetFirstSqlStmt()
sl@0
    90
	{
sl@0
    91
	TPtrC res;
sl@0
    92
sl@0
    93
	TBuf<1> b2; b2.Append(TChar(0));
sl@0
    94
	TPtr p2(PTR_ARG(b2));
sl@0
    95
	res.Set(GetFirstSqlStmt(p2));
sl@0
    96
	//Expected result: res = "\x0", p2 is NULL
sl@0
    97
	TEST(res == b2);
sl@0
    98
	TEST(!p2.Ptr());
sl@0
    99
		
sl@0
   100
	TBuf<2> b3; b3.Append(TChar(' ')); b3.Append(TChar(0));
sl@0
   101
	TPtr p3(PTR_ARG(b3));
sl@0
   102
	res.Set(GetFirstSqlStmt(p3));
sl@0
   103
	//Expected result: res = " \x0", p3 is NULL
sl@0
   104
	TEST(res == b3);
sl@0
   105
	TEST(!p3.Ptr());
sl@0
   106
	
sl@0
   107
	TBuf<7> b4(_L(";; ;  ")); b4.Append(TChar(0));
sl@0
   108
	TPtr p4(PTR_ARG(b4));
sl@0
   109
	res.Set(GetFirstSqlStmt(p4));
sl@0
   110
	//Expected result: res = "\x0", p4 = "; ;  \x0"
sl@0
   111
	TEST(res.Length() == 1 && (TInt)res[0] == 0);
sl@0
   112
	TInt accLen = res.Length();
sl@0
   113
	TEST(p4 == b4.Right(b4.Length() - accLen));
sl@0
   114
sl@0
   115
	res.Set(GetFirstSqlStmt(p4));
sl@0
   116
	//Expected result: res = "\x0", p4 = " ;  \x0"
sl@0
   117
	TEST(res.Length() == 1 && (TInt)res[0] == 0);
sl@0
   118
	accLen += res.Length();
sl@0
   119
	TEST(p4 == b4.Right(b4.Length() - accLen));
sl@0
   120
	
sl@0
   121
	res.Set(GetFirstSqlStmt(p4));
sl@0
   122
	//Expected result: res = " \x0", p4 = "  \x0"
sl@0
   123
	TEST((TInt)res[0] == (TInt)TChar(' ') && (TInt)res[1] == 0);
sl@0
   124
	accLen += res.Length();
sl@0
   125
	TEST(p4 == b4.Right(b4.Length() - accLen));
sl@0
   126
	
sl@0
   127
	res.Set(GetFirstSqlStmt(p4));
sl@0
   128
	//Expected result: res = "  \x0", p4 is NULL
sl@0
   129
	TEST((TInt)res[0] == (TInt)TChar(' ') && (TInt)res[1] == (TInt)TChar(' ') && (TInt)res[2] == 0);
sl@0
   130
	TEST(!p4.Ptr());
sl@0
   131
	
sl@0
   132
	TBuf<20> b5(_L("SELECT * FROM A")); b5.Append(TChar(0));
sl@0
   133
	TPtr p5(PTR_ARG(b5));
sl@0
   134
	res.Set(GetFirstSqlStmt(p5));
sl@0
   135
	//Expected result: res = "SELECT * FROM A\x0", p5 is NULL
sl@0
   136
	TEST(res == b5);
sl@0
   137
	TEST(!p5.Ptr());
sl@0
   138
	
sl@0
   139
	TBuf<20> b6(_L("SELECT * FROM A;")); b6.Append(TChar(0));
sl@0
   140
	TPtr p6(PTR_ARG(b6));
sl@0
   141
	res.Set(GetFirstSqlStmt(p6));
sl@0
   142
	//Expected result: res = "SELECT * FROM A\x0", p6 = "\x0"
sl@0
   143
	TEST(res == b6.Left(b6.Length() - 1));
sl@0
   144
	TEST(p6.Length() == 1 && p6[0] == 0);
sl@0
   145
sl@0
   146
	TBuf<40> b7(_L("/** Comment */ SELECT * FROM A;")); b7.Append(TChar(0));
sl@0
   147
	TPtr p7(PTR_ARG(b7));
sl@0
   148
	res.Set(GetFirstSqlStmt(p7));
sl@0
   149
	//Expected result: res = "/** Comment */ SELECT * FROM A\x0", p7 = "\x0"
sl@0
   150
	TEST(res == b7.Left(b7.Length() - 1));
sl@0
   151
	TEST(p7.Length() == 1 && p7[0] == 0);
sl@0
   152
sl@0
   153
	TBuf<40> b8(_L(" SELECT * FROM --Comment \r\n A;")); b8.Append(TChar(0));
sl@0
   154
	TPtr p8(PTR_ARG(b8));
sl@0
   155
	res.Set(GetFirstSqlStmt(p8));
sl@0
   156
	//Expected result: res = " SELECT * FROM --Comment \r\n A\x0", p8 = "\x0"
sl@0
   157
	TEST(res == b8.Left(b8.Length() - 1));
sl@0
   158
	TEST(p8.Length() == 1 && p8[0] == 0);
sl@0
   159
sl@0
   160
	TBuf<40> b9(_L("SELECT * FROM A; SELECT * FROM B")); b9.Append(TChar(0));
sl@0
   161
	TPtr p9(PTR_ARG(b9));
sl@0
   162
	res.Set(GetFirstSqlStmt(p9));
sl@0
   163
	//Expected result: res = "SELECT * FROM A\x0", p9 = " SELECT * FROM B\x0"
sl@0
   164
	TEST(res.Left(res.Length() - 1) == b9.Left(res.Length() - 1) && (TInt)res[res.Length() - 1] == 0);
sl@0
   165
	accLen = res.Length();
sl@0
   166
	TEST(p9 == b9.Right(b9.Length() - accLen));
sl@0
   167
sl@0
   168
	res.Set(GetFirstSqlStmt(p9));
sl@0
   169
	//Expected result: res = " SELECT * FROM B\x0", p9 is NULL
sl@0
   170
	TEST(res == b9.Right(b9.Length() - accLen));
sl@0
   171
	TEST(!p9.Ptr());
sl@0
   172
sl@0
   173
	//Defect INC113060	
sl@0
   174
	TBuf<255> b10(_L("UPDATE Playlist SET Name=';',Time='2007-09-20 12:31:33' WHERE UniqueId=640397473"));
sl@0
   175
	TPtr p10(PTR_ARG(b10));
sl@0
   176
	res.Set(GetFirstSqlStmt(p10));
sl@0
   177
	//Expected results: res= original string
sl@0
   178
	TEST(res.Compare(b10)==0);
sl@0
   179
	TEST(!p10.Ptr());
sl@0
   180
	
sl@0
   181
	TBuf<255> firstStmt(_L("SELECT * FROM PlayList"));firstStmt.Append(TChar(0));
sl@0
   182
	TBuf<255> b11(_L("SELECT * FROM PlayList;UPDATE Playlist SET Name=';',Time='2007-09-20 12:31:33' WHERE UniqueId=640397473"));
sl@0
   183
	TPtr p11(PTR_ARG(b11));
sl@0
   184
	res.Set(GetFirstSqlStmt(p11));
sl@0
   185
	TEST(res.Compare(firstStmt)==0);
sl@0
   186
	TEST(p11.Compare(b10)==0);
sl@0
   187
	}
sl@0
   188
sl@0
   189
/**
sl@0
   190
@SYMTestCaseID			SYSLIB-SQL-UT-3433
sl@0
   191
@SYMTestCaseDesc		Test for DEF104744 - RSqlStatement::Next() SQL Server crashes on ORDER BY clause.
sl@0
   192
						The test creates a database with a table with 30 integer columns, then inserts 100
sl@0
   193
						records. After that, sets the soft heap limit to be very low - 10K 
sl@0
   194
						(to get sqlite3_release_memory() called by SQLITE ), creates a statement object 
sl@0
   195
						and attempts to retrieve the inserted records in descending order.
sl@0
   196
@SYMTestPriority		High
sl@0
   197
@SYMTestActions			Test for DEF104744 - RSqlStatement::Next() SQL Server crashes on ORDER BY clause.
sl@0
   198
@SYMTestExpectedResults Test must not fail
sl@0
   199
@SYMDEF					DEF104744
sl@0
   200
*/
sl@0
   201
void DEF104744()
sl@0
   202
	{
sl@0
   203
	(void)TheFs.Delete(KTestDatabase);
sl@0
   204
	TheSqliteDb = NULL;
sl@0
   205
	TInt err = sqlite3_open((const char*)KTestDatabaseZ().Ptr(), &TheSqliteDb);
sl@0
   206
	TEST2(err, SQLITE_OK);
sl@0
   207
	
sl@0
   208
	_LIT8(KCreateTblSqlZ, "CREATE TABLE A1(F1 INTEGER,F2 INTEGER,F3 INTEGER,F4 INTEGER,F5 INTEGER,F6 INTEGER,F7 INTEGER,F8 INTEGER,F9 INTEGER,F10 INTEGER,F11 INTEGER,F12 INTEGER,F13 INTEGER,F14 INTEGER,F15 INTEGER,F16 INTEGER,F17 INTEGER,F18 INTEGER,F19 INTEGER,F20 INTEGER,F21 INTEGER,F22 INTEGER,F23 INTEGER,F24 INTEGER,F25 INTEGER,F26 INTEGER,F27 INTEGER,F28 INTEGER,F29 INTEGER,F30 INTEGER)\x0");
sl@0
   209
	err = sqlite3_exec(TheSqliteDb, (const char*)KCreateTblSqlZ().Ptr(), 0, 0, 0);
sl@0
   210
	TEST2(err, SQLITE_OK);
sl@0
   211
sl@0
   212
	//Insert a 100 records
sl@0
   213
	const TInt KTestRecCnt = 100;
sl@0
   214
	_LIT8(KInsertSqlZ, "INSERT INTO A1(F1,F2 ,F3 ,F4 ,F5 ,F6 ,F7 ,F8 ,F9 ,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22,F23,F24,F25,F26,F27,F28,F29,F30) VALUES(:Prm1,:Prm2,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296,4294967296)\x0");
sl@0
   215
	sqlite3_stmt* stmt1 = NULL;
sl@0
   216
	err = sqlite3_prepare_v2(TheSqliteDb, (const char*)(KInsertSqlZ().Ptr()), -1, &stmt1, NULL);
sl@0
   217
	TEST2(err, SQLITE_OK);
sl@0
   218
	
sl@0
   219
	_LIT8(KBeginSqlZ, "BEGIN\x0");
sl@0
   220
	err = sqlite3_exec(TheSqliteDb, (const char*)KBeginSqlZ().Ptr(), 0, 0, 0);
sl@0
   221
	TEST2(err, SQLITE_OK);
sl@0
   222
	
sl@0
   223
	for(TInt i=0;i<KTestRecCnt;++i)
sl@0
   224
		{ 
sl@0
   225
		err = sqlite3_bind_int(stmt1, 1, i);
sl@0
   226
		TEST2(err, SQLITE_OK);
sl@0
   227
		err = sqlite3_bind_int(stmt1, 2, i + 1);
sl@0
   228
		TEST2(err, SQLITE_OK);
sl@0
   229
		err = sqlite3_step(stmt1);
sl@0
   230
		TEST2(err, SQLITE_DONE);
sl@0
   231
		err = sqlite3_reset(stmt1);
sl@0
   232
		TEST2(err, SQLITE_OK);
sl@0
   233
		TInt cnt = sqlite3_changes(TheSqliteDb);
sl@0
   234
		TEST2(cnt, 1);
sl@0
   235
		}
sl@0
   236
		
sl@0
   237
	_LIT8(KCommitSqlZ, "COMMIT\x0");
sl@0
   238
	err = sqlite3_exec(TheSqliteDb, (const char*)KCommitSqlZ().Ptr(), 0, 0, 0);
sl@0
   239
	TEST2(err, SQLITE_OK);
sl@0
   240
	sqlite3_finalize(stmt1);
sl@0
   241
sl@0
   242
	sqlite3_soft_heap_limit(10 * 1024);//Setting very low soft heap limit - 10K
sl@0
   243
sl@0
   244
	// Get the inserted record data in descending order.
sl@0
   245
	sqlite3_stmt* stmt2 = NULL;
sl@0
   246
	_LIT8(KSelectSqlZ,"SELECT * FROM A1 ORDER BY F1 DESC");
sl@0
   247
	err = sqlite3_prepare_v2(TheSqliteDb, (const char*)(KSelectSqlZ().Ptr()), -1, &stmt2, NULL);
sl@0
   248
	TEST2(err, SQLITE_OK);
sl@0
   249
	err = sqlite3_step(stmt2);
sl@0
   250
	TEST2(err, SQLITE_ROW);
sl@0
   251
	sqlite3_finalize(stmt2);
sl@0
   252
sl@0
   253
	sqlite3_close(TheSqliteDb); 
sl@0
   254
	TheSqliteDb = NULL;
sl@0
   255
	(void)TheFs.Delete(KTestDatabase);
sl@0
   256
	}
sl@0
   257
sl@0
   258
enum TStmtType {EStmt8, EStmt16};
sl@0
   259
sl@0
   260
//This function attempts to execute sqlite3_prepare_v2() or sqlite3_prepare16_v2() in an "out of memory loop".
sl@0
   261
//If the prepare call fails, the statement handle is expected to be NULL.
sl@0
   262
void StmtHandleTest(TStmtType aStmtType)
sl@0
   263
	{
sl@0
   264
	TEST(TheSqliteDb != NULL);
sl@0
   265
	for(TInt failingAllocationNo=1;;++failingAllocationNo)
sl@0
   266
		{
sl@0
   267
		__UHEAP_SETFAIL(RHeap::EFailNext, failingAllocationNo);
sl@0
   268
		sqlite3_stmt* stmt = NULL;
sl@0
   269
		TInt err = SQLITE_NOMEM;
sl@0
   270
		if(aStmtType == EStmt8)
sl@0
   271
			{
sl@0
   272
			_LIT8(KSelectSqlZ,"SELECT * FROM A\x0");
sl@0
   273
			err = sqlite3_prepare_v2(TheSqliteDb, (const char*)(KSelectSqlZ().Ptr()), -1, &stmt, NULL);
sl@0
   274
			}
sl@0
   275
		else
sl@0
   276
			{
sl@0
   277
			_LIT(KSelectSqlZ,"SELECT * FROM A\x0");
sl@0
   278
			err = sqlite3_prepare16_v2(TheSqliteDb, (const char*)(KSelectSqlZ().Ptr()), -1, &stmt, NULL);
sl@0
   279
			}
sl@0
   280
		__UHEAP_SETFAIL(RHeap::ENone, 0);
sl@0
   281
		if(err != SQLITE_OK)
sl@0
   282
			{//The statement handle should be NULL if err is not SQLITE_OK
sl@0
   283
			TEST(!stmt);
sl@0
   284
			}
sl@0
   285
		else
sl@0
   286
			{
sl@0
   287
			TEST(stmt != NULL);
sl@0
   288
			sqlite3_finalize(stmt);
sl@0
   289
			break;
sl@0
   290
			}
sl@0
   291
		}
sl@0
   292
	}
sl@0
   293
sl@0
   294
/**
sl@0
   295
@SYMTestCaseID			SYSLIB-SQL-UT-3466
sl@0
   296
@SYMTestCaseDesc		Test for DEF105444 SQL, sqlite3_prepare_v2() demonstrates non-atomic behaviour (handle leak).
sl@0
   297
						The test creates a database with a table and inserts one record.
sl@0
   298
						After that the test attempts to prepare a SELECT statement handle inside an "ouut of memory"
sl@0
   299
						loop. If the prepare operation fails, the statement handle should be NULL.
sl@0
   300
@SYMTestPriority		High
sl@0
   301
@SYMTestActions			DEF105444 SQL, sqlite3_prepare_v2() demonstrates non-atomic behaviour (handle leak) 
sl@0
   302
@SYMTestExpectedResults Test must not fail
sl@0
   303
@SYMDEF					DEF105444
sl@0
   304
*/
sl@0
   305
void DEF105444()
sl@0
   306
	{
sl@0
   307
	(void)TheFs.Delete(KTestDatabase);
sl@0
   308
	TheSqliteDb = NULL;
sl@0
   309
	TInt err = sqlite3_open((const char*)KTestDatabaseZ().Ptr(), &TheSqliteDb);
sl@0
   310
	TEST2(err, SQLITE_OK);
sl@0
   311
	
sl@0
   312
	_LIT8(KCreateTblSqlZ, "CREATE TABLE A(Id INTEGER)\x0");
sl@0
   313
	err = sqlite3_exec(TheSqliteDb, (const char*)KCreateTblSqlZ().Ptr(), 0, 0, 0);
sl@0
   314
	TEST2(err, SQLITE_OK);
sl@0
   315
sl@0
   316
	_LIT8(KInsertSqlZ, "INSERT INTO A(Id) VALUES(1)\x0");
sl@0
   317
	err = sqlite3_exec(TheSqliteDb, (const char*)KInsertSqlZ().Ptr(), 0, 0, 0);
sl@0
   318
	TEST2(err, SQLITE_OK);
sl@0
   319
sl@0
   320
	StmtHandleTest(EStmt8);
sl@0
   321
	StmtHandleTest(EStmt16);
sl@0
   322
	
sl@0
   323
	sqlite3_close(TheSqliteDb); 
sl@0
   324
	TheSqliteDb = NULL;
sl@0
   325
	(void)TheFs.Delete(KTestDatabase);
sl@0
   326
	}
sl@0
   327
sl@0
   328
void UtilFileNameTest()
sl@0
   329
	{
sl@0
   330
#ifdef _ASSERTIONS	
sl@0
   331
	_LIT(KFileName, "bbb.db");
sl@0
   332
	
sl@0
   333
	_LIT(KFileName1, "c:\\aaa\\bbb.db\x0");
sl@0
   334
	TPtrC p1 = Util::Filename(KFileName1().Ptr());
sl@0
   335
	TEST(p1 == KFileName);
sl@0
   336
	
sl@0
   337
	_LIT(KFileName2, "c:/aaa/bbb.db\x0");
sl@0
   338
	TPtrC p2 = Util::Filename(KFileName2().Ptr());
sl@0
   339
	TEST(p2 == KFileName);
sl@0
   340
	
sl@0
   341
	_LIT(KFileName3, "bbb.db\x0");
sl@0
   342
	TPtrC p3 = Util::Filename(KFileName3().Ptr());
sl@0
   343
	TEST(p3 == KFileName);
sl@0
   344
#else
sl@0
   345
	TheTest.Printf(_L(" === This test case works only if the test is built with the _ASSERTIONS macro defined!\r\n"));
sl@0
   346
#endif	
sl@0
   347
	}
sl@0
   348
sl@0
   349
void DoTests()
sl@0
   350
	{
sl@0
   351
	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1628 GetFirstSqlStmt() test "));
sl@0
   352
	TestGetFirstSqlStmt();
sl@0
   353
	
sl@0
   354
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3433 DEF104744 SQL Server crashes on ORDER BY clause "));
sl@0
   355
	DEF104744();
sl@0
   356
sl@0
   357
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3466 DEF105444 SQL, sqlite3_prepare_v2() demonstrates non-atomic behaviour (handle leak) "));
sl@0
   358
	DEF105444();
sl@0
   359
sl@0
   360
	TheTest.Next(_L(" Util::Filename() test"));
sl@0
   361
	UtilFileNameTest();
sl@0
   362
	}
sl@0
   363
sl@0
   364
//Creates file session instance and the test directory
sl@0
   365
void CreateTestEnv()
sl@0
   366
    {
sl@0
   367
	TInt err = TheFs.Connect();
sl@0
   368
	TheTest(err == KErrNone);
sl@0
   369
sl@0
   370
	err = TheFs.MkDir(KTestDir);
sl@0
   371
	TEST(err == KErrNone || err == KErrAlreadyExists);
sl@0
   372
	}
sl@0
   373
sl@0
   374
TInt E32Main()
sl@0
   375
	{
sl@0
   376
	TheSqliteDb = NULL;
sl@0
   377
	
sl@0
   378
	TheTest.Title();
sl@0
   379
	
sl@0
   380
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   381
	
sl@0
   382
	__UHEAP_MARK;
sl@0
   383
sl@0
   384
	CreateTestEnv();
sl@0
   385
	TInt err = sqlite3SymbianLibInit();
sl@0
   386
	TEST2(err, KErrNone);
sl@0
   387
	DoTests();
sl@0
   388
	sqlite3SymbianLibFinalize();
sl@0
   389
	DestroyTestEnv();
sl@0
   390
sl@0
   391
	CloseSTDLIB();
sl@0
   392
sl@0
   393
	__UHEAP_MARKEND;
sl@0
   394
	
sl@0
   395
	TheTest.End();
sl@0
   396
	TheTest.Close();
sl@0
   397
	
sl@0
   398
	delete tc;
sl@0
   399
sl@0
   400
	User::Heap().Check();
sl@0
   401
	return KErrNone;
sl@0
   402
	}