os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_defect.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) 2004-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 <d32dbms.h>
sl@0
    17
#include <e32math.h>
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <f32file.h>
sl@0
    20
#include <s32buf.h>
sl@0
    21
sl@0
    22
#include "crccheck.h"
sl@0
    23
sl@0
    24
#undef __UHEAP_MARK
sl@0
    25
#undef __UHEAP_MARKEND
sl@0
    26
#define __UHEAP_MARK
sl@0
    27
#define __UHEAP_MARKEND
sl@0
    28
sl@0
    29
LOCAL_D TDBMS_CRCChecks TheCrcChecker;
sl@0
    30
sl@0
    31
#ifndef __linux__ //No CRC test on LINUX
sl@0
    32
#ifdef __TOOLS2__
sl@0
    33
const TPtrC	KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_DEFECT.CRC");
sl@0
    34
#else
sl@0
    35
const TPtrC	KCrcRecord=_L("C:\\dbms-tst\\T_DEFECT.CRC");
sl@0
    36
#endif
sl@0
    37
#endif
sl@0
    38
sl@0
    39
sl@0
    40
LOCAL_D RTest 			TheTest (_L ("t_defect.exe"));
sl@0
    41
LOCAL_D CTrapCleanup*	TheTrapCleanup = NULL;
sl@0
    42
#ifndef __TOOLS2__
sl@0
    43
LOCAL_D RSemaphore 		TheWaitToStartSem;
sl@0
    44
LOCAL_D RSemaphore 		TheWaitForThreadsReadySem;
sl@0
    45
#endif
sl@0
    46
LOCAL_D RFs 			TheFs;
sl@0
    47
LOCAL_D RDbs			TheDbs1, TheDbs2;
sl@0
    48
LOCAL_D RDbNamedDatabase TheDb1, TheDb2;
sl@0
    49
sl@0
    50
_LIT (KName,			"ConnectTestThread_");
sl@0
    51
_LIT (KStart,			"Starting thread %x.\n");
sl@0
    52
_LIT (KConnect,			"Thread %x: Waiting to connect...\n");
sl@0
    53
_LIT (KConSuccess,		"Thread %x: Connection succeeded.\n");
sl@0
    54
_LIT (KConFailed,		"Thread %x: Connection failed. Error %d.\n");
sl@0
    55
_LIT (KStatus,			"Status of thread %x is %d.\n");
sl@0
    56
 
sl@0
    57
 
sl@0
    58
_LIT(KTable, 			"TABLE");
sl@0
    59
_LIT(KColName,			"Fld");
sl@0
    60
_LIT(KCol2Name, 		"Fld2");
sl@0
    61
sl@0
    62
#ifndef __TOOLS2__
sl@0
    63
const TPtrC KDbName=_L("C:\\dbms-tst\\TESTDB22.DB");
sl@0
    64
#else
sl@0
    65
const TPtrC KDbName=_L(".\\dbms-tst\\TESTDB22.DB");
sl@0
    66
#endif
sl@0
    67
sl@0
    68
_LIT(KSQLInsert1, 		"INSERT INTO TABLE (Fld, Fld2) VALUES ('ACDC\\','BLAH')");
sl@0
    69
_LIT(KSQLInsert2, 		"INSERT INTO TABLE   (Fld) VALUES ('ABCDEFGH')");
sl@0
    70
_LIT(KSQLInsert3, 		"INSERT INTO TABLE   (Fld) VALUES ('A?CDEFGH')");
sl@0
    71
_LIT(KSQLInsert4, 		"INSERT INTO TABLE   (Fld) VALUES ('A?*?CDEFGH')");
sl@0
    72
_LIT(KSQLInsert5, 		"INSERT INTO TABLE   (Fld) VALUES ('A*CDEFGH')");
sl@0
    73
_LIT(KSQLInsert6, 		"INSERT INTO TABLE   (Fld, Fld2) VALUES ('ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP','ADCB')");
sl@0
    74
_LIT(KSQLInsert7, 		"INSERT INTO TABLE   (Fld) VALUES ('XZD\\FZX')");
sl@0
    75
sl@0
    76
_LIT(KSqlRequestGranularity, "SELECT Fld FROM test WHERE (Fld LIKE '1' AND Fld LIKE '2') AND Fld LIKE '3'  AND Fld LIKE '4'  AND Fld LIKE '5'  AND Fld LIKE '6'");
sl@0
    77
sl@0
    78
_LIT(KText16Name, 		"text16");
sl@0
    79
_LIT(KTableName, 		"test");
sl@0
    80
_LIT(KIndexName, 		"test_index");
sl@0
    81
_LIT(KMaxStringFormat, 	"%0256d");
sl@0
    82
sl@0
    83
void TestCleanup()
sl@0
    84
	{
sl@0
    85
	TheDb2.Close();
sl@0
    86
	TheDb1.Close();
sl@0
    87
#ifndef __TOOLS2__
sl@0
    88
	TheDbs2.Close();
sl@0
    89
	TheDbs1.Close();
sl@0
    90
#endif
sl@0
    91
	(void)TheFs.Delete(KDbName);
sl@0
    92
	TheFs.Close();
sl@0
    93
	TheCrcChecker.GenerateCrcL(KDbName);
sl@0
    94
	}
sl@0
    95
sl@0
    96
//-----------------------------------------------------------------------------
sl@0
    97
//
sl@0
    98
// Test macros and functions.
sl@0
    99
//
sl@0
   100
//-----------------------------------------------------------------------------
sl@0
   101
// If (!aValue) then the test will be panicked, the test data files will be 
sl@0
   102
// deleted.
sl@0
   103
LOCAL_C void Check(TInt aValue, TInt aLine)
sl@0
   104
	{
sl@0
   105
	if(!aValue)
sl@0
   106
		{
sl@0
   107
		TestCleanup();
sl@0
   108
		TheTest(EFalse, aLine);
sl@0
   109
		}
sl@0
   110
	}
sl@0
   111
sl@0
   112
sl@0
   113
// If (aValue != aExpected) then the test will be panicked, the test data files
sl@0
   114
// will be deleted.
sl@0
   115
LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
   116
	{
sl@0
   117
	if(aValue != aExpected)
sl@0
   118
		{
sl@0
   119
		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
   120
		TestCleanup();
sl@0
   121
		TheTest(EFalse, aLine);
sl@0
   122
		}
sl@0
   123
	}
sl@0
   124
		
sl@0
   125
	
sl@0
   126
//Use these to test conditions.
sl@0
   127
#define TEST(arg)                ::Check((arg), __LINE__)
sl@0
   128
#define TEST2(aValue, aExpected) ::Check((aValue), (aExpected), __LINE__)
sl@0
   129
//-----------------------------------------------------------------------------
sl@0
   130
//-----------------------------------------------------------------------------
sl@0
   131
sl@0
   132
struct TTest
sl@0
   133
	{
sl@0
   134
	const TText* result;
sl@0
   135
	const TText* query;
sl@0
   136
	};
sl@0
   137
		
sl@0
   138
const TTest KQuery[]=
sl@0
   139
	{
sl@0
   140
	{_S("ACDC\\"),_S("SELECT Fld FROM TABLE WHERE  Fld LIKE 'ACDC\\' AND Fld2 LIKE '*BL*'")},
sl@0
   141
	{_S("A*CDEFGH"),_S("SELECT * FROM TABLE WHERE  Fld LIKE '*A\\*C*' ESCAPE '\\'")},
sl@0
   142
	{_S("A?CDEFGH"),_S("SELECT * FROM TABLE WHERE  Fld LIKE '*A\\?C*' ESCAPE '\\'")},
sl@0
   143
	{_S("A?*?CDEFGH"),_S("SELECT * FROM TABLE WHERE  Fld LIKE '*A\\?\\*\\?C*' ESCAPE '\\'")},
sl@0
   144
	{_S("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP"),_S("SELECT * FROM TABLE WHERE  Fld LIKE '*1234*'")},	
sl@0
   145
	{_S("BLAH"),_S("SELECT Fld2 FROM TABLE WHERE  Fld LIKE '*AC*' AND Fld2 LIKE '?LA?'")},
sl@0
   146
	{_S("BLAH"),_S("SELECT Fld2 FROM TABLE WHERE  Fld LIKE 'NOTINTABLE' OR Fld2 LIKE '?LA?'")},
sl@0
   147
	{_S("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP"),_S("SELECT * FROM TABLE WHERE  Fld LIKE '*ADC*' AND Fld2 LIKE 'ADC?'")},	
sl@0
   148
	{_S("A*CDEFGH"),_S("SELECT Fld FROM TABLE WHERE Fld LIKE '*\\*C*' ESCAPE '\\'")},
sl@0
   149
	{_S("XZD\\FZX"),_S("SELECT Fld FROM TABLE WHERE Fld LIKE '*D\\\\*' ESCAPE '\\'")}
sl@0
   150
	};
sl@0
   151
sl@0
   152
const TTest KBadQuery[]=
sl@0
   153
	{
sl@0
   154
	{_S(""),_S("SELECT * FROM TABLE WHERE  Fld LIKE 'A?C' ESCAPE '\\'")},
sl@0
   155
	{_S(""),_S("SELECT * FROM TABLE WHERE  Fld LIKE 'A*C' ESCAPE '\\'")},
sl@0
   156
	{_S(""),_S("SELECT * FROM TABLE WHERE  Fld LIKE '?A\\?C' ESCAPE '\\'")},
sl@0
   157
	{_S(""),_S("SELECT * FROM TABLE WHERE  Fld LIKE '?A\\?C?' ESCAPE '\\'")},
sl@0
   158
	{_S(""),_S("SELECT * FROM TABLE WHERE  Fld LIKE '*A\\??\\?C*' ESCAPE '\\'")},
sl@0
   159
	{_S(""),_S("SELECT * FROM TABLE WHERE  Fld LIKE '*A*\\*C*' ESCAPE '\\'")},
sl@0
   160
	{_S(""),_S("SELECT * FROM TABLE WHERE  Fld LIKE 'ABC' ESCAPE '\\'")},
sl@0
   161
	{_S(""),_S("SELECT * FROM TABLE WHERE  Fld LIKE 'ABC*' ESCAPE '\\'")},
sl@0
   162
	{_S(""),_S("SELECT * FROM TABLE WHERE  Fld LIKE '*ABC' ESCAPE '\\'")}
sl@0
   163
	};	
sl@0
   164
sl@0
   165
const TInt KNumQueries = 10;
sl@0
   166
const TInt KNumBadQueries = 9;
sl@0
   167
const TInt KThreadCount	= 3;
sl@0
   168
const TInt KOneSecond 	= 1000000;
sl@0
   169
const TInt KDbNameLen   = 255;
sl@0
   170
const TInt KMaxColName = 32;
sl@0
   171
sl@0
   172
#ifndef __TOOLS2__
sl@0
   173
static void DoDbmsConnectThreadSubFunctionL (TInt aThreadNumber)
sl@0
   174
	{
sl@0
   175
	// The session	
sl@0
   176
	RDbs TheDbSession;
sl@0
   177
	CleanupClosePushL (TheDbSession);
sl@0
   178
sl@0
   179
	RDebug::Print (KStart (), aThreadNumber);
sl@0
   180
	RDebug::Print (KConnect (), aThreadNumber);
sl@0
   181
	
sl@0
   182
 	// Signal the main thread to continue
sl@0
   183
 	TheWaitForThreadsReadySem.Signal (1);
sl@0
   184
sl@0
   185
	// Wait until we are signalled
sl@0
   186
	TheWaitToStartSem.Wait ();	
sl@0
   187
sl@0
   188
	// Connect to Dbms
sl@0
   189
	TInt r = TheDbSession.Connect ();
sl@0
   190
sl@0
   191
	if (r == KErrNone)
sl@0
   192
		{
sl@0
   193
		RDebug::Print (KConSuccess (), aThreadNumber);
sl@0
   194
		TheDbSession.Close ();
sl@0
   195
		}
sl@0
   196
	else
sl@0
   197
		{
sl@0
   198
		RDebug::Print (KConFailed (), aThreadNumber, r);
sl@0
   199
		User::Leave (r);
sl@0
   200
		}
sl@0
   201
sl@0
   202
	CleanupStack::PopAndDestroy (1); // session
sl@0
   203
	}
sl@0
   204
sl@0
   205
static TInt DoDbmsConnectThread (TAny* aThreadNumber)
sl@0
   206
	{
sl@0
   207
	__UHEAP_MARK;
sl@0
   208
sl@0
   209
	CTrapCleanup* trapCleanup = CTrapCleanup::New ();
sl@0
   210
	__ASSERT_ALWAYS (trapCleanup!=NULL, User::Invariant ());
sl@0
   211
sl@0
   212
	TInt* threadNumber = static_cast <TInt*> (aThreadNumber);
sl@0
   213
	TRAPD (err, DoDbmsConnectThreadSubFunctionL (*threadNumber));
sl@0
   214
	
sl@0
   215
	delete trapCleanup;
sl@0
   216
	
sl@0
   217
	__UHEAP_MARKEND;
sl@0
   218
sl@0
   219
	return err;		
sl@0
   220
	}
sl@0
   221
#endif
sl@0
   222
sl@0
   223
#ifndef TOOLS2_VARIANT
sl@0
   224
/**
sl@0
   225
@SYMTestCaseID          SYSLIB-DBMS-CT-0644
sl@0
   226
@SYMTestCaseDesc        Test for defect no 44697
sl@0
   227
@SYMTestPriority        Medium
sl@0
   228
@SYMTestActions         Test for defect fixes
sl@0
   229
@SYMTestExpectedResults Test must not fail
sl@0
   230
@SYMREQ                 REQ0000
sl@0
   231
*/
sl@0
   232
LOCAL_C void Defect_DEF44697L ()
sl@0
   233
	{
sl@0
   234
	TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-DBMS-CT-0644 Defect_DEF44697L "));
sl@0
   235
sl@0
   236
	__UHEAP_MARK;
sl@0
   237
	
sl@0
   238
  	// find out the number of open handles
sl@0
   239
	TInt startProcessHandleCount;
sl@0
   240
	TInt startThreadHandleCount;
sl@0
   241
	RThread ().HandleCount (startProcessHandleCount, startThreadHandleCount);
sl@0
   242
sl@0
   243
	/////////////////////
sl@0
   244
	// The Test Begins...
sl@0
   245
	
sl@0
   246
 	// Create semaphores
sl@0
   247
 	::CleanupClosePushL (::TheWaitForThreadsReadySem);
sl@0
   248
 	User::LeaveIfError (::TheWaitForThreadsReadySem.CreateLocal (0));
sl@0
   249
sl@0
   250
 	::CleanupClosePushL (::TheWaitToStartSem);
sl@0
   251
 	User::LeaveIfError (::TheWaitToStartSem.CreateLocal (0));
sl@0
   252
sl@0
   253
 	// Create the threads.
sl@0
   254
 	RThread createTestThread_1;
sl@0
   255
 	RThread createTestThread_2;
sl@0
   256
 	RThread createTestThread_3;
sl@0
   257
 	
sl@0
   258
 	TBuf<100> thread_name;
sl@0
   259
	TInt KThreadNumber1 = 1;
sl@0
   260
	TInt KThreadNumber2 = 2;
sl@0
   261
	TInt KThreadNumber3 = 3;
sl@0
   262
 	
sl@0
   263
 	// Create the first test thread______________________________
sl@0
   264
	thread_name = KName ();
sl@0
   265
	thread_name.AppendNum (KThreadNumber1);
sl@0
   266
 		
sl@0
   267
 	User::LeaveIfError (
sl@0
   268
 		createTestThread_1.Create (thread_name, 
sl@0
   269
								   (TThreadFunction) DoDbmsConnectThread,
sl@0
   270
								   KDefaultStackSize,
sl@0
   271
								   KMinHeapSize,
sl@0
   272
								   KMinHeapSize,
sl@0
   273
								   &KThreadNumber1));
sl@0
   274
 	
sl@0
   275
 	// Default priority of Main thread is EPriorityNormal								   
sl@0
   276
 	createTestThread_1.SetPriority(EPriorityMore);
sl@0
   277
 	
sl@0
   278
 	TheTest.Printf (_L ("%S thread started\n"), &thread_name);
sl@0
   279
	 	
sl@0
   280
 	// Request notification when the thread dies.
sl@0
   281
 	TRequestStatus threadStatus_1;
sl@0
   282
 	createTestThread_1.Logon (threadStatus_1);
sl@0
   283
sl@0
   284
	//___________________________________________________________
sl@0
   285
sl@0
   286
 	// Create the second test thread______________________________
sl@0
   287
	thread_name = KName ();
sl@0
   288
	thread_name.AppendNum (KThreadNumber2);
sl@0
   289
 		
sl@0
   290
 	User::LeaveIfError (
sl@0
   291
 		createTestThread_2.Create (thread_name, 
sl@0
   292
								   (TThreadFunction) DoDbmsConnectThread,
sl@0
   293
								   KDefaultStackSize,
sl@0
   294
								   KMinHeapSize,
sl@0
   295
								   KMinHeapSize,
sl@0
   296
								   &KThreadNumber2));
sl@0
   297
 					
sl@0
   298
  	// Default priority of Main thread is EPriorityNormal								   
sl@0
   299
 	createTestThread_2.SetPriority(EPriorityMore);
sl@0
   300
				   
sl@0
   301
 	TheTest.Printf (_L ("%S thread started\n"), &thread_name);
sl@0
   302
	 	
sl@0
   303
 	// Request notification when the tread dies.
sl@0
   304
 	TRequestStatus threadStatus_2;
sl@0
   305
 	createTestThread_2.Logon (threadStatus_2);
sl@0
   306
sl@0
   307
	//___________________________________________________________
sl@0
   308
sl@0
   309
 	// Create the third test thread______________________________
sl@0
   310
	thread_name = KName ();
sl@0
   311
	thread_name.AppendNum (KThreadNumber3);
sl@0
   312
 		
sl@0
   313
 	User::LeaveIfError (
sl@0
   314
 		createTestThread_3.Create (thread_name, 
sl@0
   315
								   (TThreadFunction) DoDbmsConnectThread,
sl@0
   316
								   KDefaultStackSize,
sl@0
   317
								   KMinHeapSize,
sl@0
   318
								   KMinHeapSize,
sl@0
   319
								   &KThreadNumber3));
sl@0
   320
 		
sl@0
   321
  	// Default priority of Main thread is EPriorityNormal								   
sl@0
   322
 	createTestThread_3.SetPriority(EPriorityMore);
sl@0
   323
							   
sl@0
   324
 	TheTest.Printf (_L ("%S thread started\n"), &thread_name);
sl@0
   325
	 	
sl@0
   326
 	// Request notification when the tread dies.
sl@0
   327
 	TRequestStatus threadStatus_3;
sl@0
   328
 	createTestThread_3.Logon (threadStatus_3);
sl@0
   329
sl@0
   330
	//___________________________________________________________
sl@0
   331
sl@0
   332
	TheTest (threadStatus_1.Int () == KRequestPending);
sl@0
   333
	TheTest (threadStatus_2.Int () == KRequestPending);
sl@0
   334
	TheTest (threadStatus_3.Int () == KRequestPending);
sl@0
   335
sl@0
   336
 	// Make threads eligible for execution
sl@0
   337
 	createTestThread_1.Resume ();
sl@0
   338
 	createTestThread_2.Resume ();
sl@0
   339
 	createTestThread_3.Resume ();
sl@0
   340
sl@0
   341
	// The way this works is that the main thread blocks until all
sl@0
   342
	// the test threads are ready (semaphore 1) and then signals them
sl@0
   343
	// (semaphore 2).
sl@0
   344
	//
sl@0
   345
	// 1: Main thread Waits for ALL test threads to become ready.
sl@0
   346
	// 2: Main thread Signals ALL test threads to run.
sl@0
   347
	//
sl@0
   348
	// 1: Test thread Signals Main thread
sl@0
   349
	// 2: Test thread Waits for Main thread
sl@0
   350
	//
sl@0
   351
	// There is still a slight race condition between the 
sl@0
   352
	// test thread signalling (semaphore 1) and then waiting 
sl@0
   353
	// (semaphore 2) which is why we use both higher priority test
sl@0
   354
	// threads and a timer.
sl@0
   355
	//
sl@0
   356
	// The problems come with the way Time slicing works due to
sl@0
   357
	// other threads of higher priority being run.
sl@0
   358
	//
sl@0
   359
	// Higher priority: Ensures the test thread runs before the 
sl@0
   360
	// the main thread.
sl@0
   361
	//
sl@0
   362
	// Timer: Safeguards when multiple core processors are being used.
sl@0
   363
	//
sl@0
   364
	// The Higher priority fixes the problem on single core processors
sl@0
   365
	// and multiple cores processors (SMP) where each core can run a
sl@0
   366
	// thread.
sl@0
   367
	// 
sl@0
   368
	// It should also ensure that if the system is so busy that it 
sl@0
   369
	// affects the test thread execution, the test thread will still
sl@0
   370
	// get to the Wait state before the Main thread can Signal.
sl@0
   371
	// 
sl@0
   372
	// However, on multiple cores the Main thread may run at the same 
sl@0
   373
	// time as the test thread, so we need to make sure that when the
sl@0
   374
	// test thread Signals it can acheive its Wait state before the 
sl@0
   375
	// Main thread Signals. For example, if the timer has elapsed on the
sl@0
   376
	// Main thread and the sytem is busy, the test thread should still
sl@0
   377
	// run before the Main thread due to it higher priority.
sl@0
   378
	//
sl@0
   379
	// We also have to think about things like priority inheritance
sl@0
   380
	// where a thread that has a handle on a Mutex inherits the same 
sl@0
   381
	// priority as a thread Waiting on it. This shouldn't happen for 
sl@0
   382
	// Semaphores as there is no one handle, i.e. no critical section.
sl@0
   383
	//
sl@0
   384
	// This higher priority inheritance will take affect when a low 
sl@0
   385
	// priority thread that has a handle on the Mutex blocks because of
sl@0
   386
	// another medium priority running thread. So in effect a high 
sl@0
   387
	// priority thread Waiting on this Mutex is also blocked.
sl@0
   388
	//
sl@0
   389
	// It is also worth noting that on EKA1 emulator, scheduling is
sl@0
   390
	// performed by windows. On EKA2 emulator scheduling is performed
sl@0
   391
	// by Symbian so that it is the same as hardware.
sl@0
   392
	
sl@0
   393
	TheWaitForThreadsReadySem.Wait();			
sl@0
   394
	TheWaitForThreadsReadySem.Wait();			
sl@0
   395
	TheWaitForThreadsReadySem.Wait();			
sl@0
   396
	
sl@0
   397
  	// Sleep for a while to allow threads to block on the semaphore
sl@0
   398
  	User::After (KOneSecond<<2); // 4 seconds
sl@0
   399
	
sl@0
   400
 	// Signal all the threads to continue
sl@0
   401
 	TheWaitToStartSem.Signal (KThreadCount);
sl@0
   402
 	
sl@0
   403
 	// Wait for all threads to complete, don't care on the order.
sl@0
   404
	User::WaitForRequest (threadStatus_1);
sl@0
   405
	User::WaitForRequest (threadStatus_2);
sl@0
   406
	User::WaitForRequest (threadStatus_3);
sl@0
   407
	
sl@0
   408
	TheTest.Printf (KStatus, KThreadNumber1, threadStatus_1.Int ());
sl@0
   409
	TheTest.Printf (KStatus, KThreadNumber2, threadStatus_2.Int ());
sl@0
   410
	TheTest.Printf (KStatus, KThreadNumber3, threadStatus_3.Int ());
sl@0
   411
	
sl@0
   412
	TheTest (threadStatus_1.Int () == KErrNone);
sl@0
   413
	TheTest (threadStatus_2.Int () == KErrNone);
sl@0
   414
	TheTest (threadStatus_3.Int () == KErrNone);
sl@0
   415
	
sl@0
   416
	CleanupStack::PopAndDestroy (&::TheWaitToStartSem);
sl@0
   417
	CleanupStack::PopAndDestroy (&::TheWaitForThreadsReadySem);
sl@0
   418
	
sl@0
   419
	// The Test Ends...
sl@0
   420
	/////////////////////
sl@0
   421
sl@0
   422
	// check that no handles have leaked
sl@0
   423
	TInt endProcessHandleCount;
sl@0
   424
	TInt endThreadHandleCount;
sl@0
   425
	RThread ().HandleCount (endProcessHandleCount, endThreadHandleCount);
sl@0
   426
sl@0
   427
	TheTest (startThreadHandleCount == endThreadHandleCount);
sl@0
   428
sl@0
   429
	__UHEAP_MARKEND;
sl@0
   430
	}
sl@0
   431
#endif // !TOOLS2_VARIANT
sl@0
   432
	
sl@0
   433
	
sl@0
   434
	
sl@0
   435
// Test for LIKE Predicate for EDbColLongText16
sl@0
   436
LOCAL_C void LikePredicateDbColLongText16TestL()
sl@0
   437
 	{
sl@0
   438
 	TheTest.Next (_L ("LikePredicateDbColLongText16TestL"));
sl@0
   439
 	//Creating database
sl@0
   440
sl@0
   441
	RFs fsSession;
sl@0
   442
    User::LeaveIfError(fsSession.Connect());
sl@0
   443
    CleanupClosePushL(fsSession);
sl@0
   444
	RDbNamedDatabase database;
sl@0
   445
	User::LeaveIfError(database.Replace(fsSession, KDbName));
sl@0
   446
	CleanupClosePushL(database);
sl@0
   447
	
sl@0
   448
	//Create table
sl@0
   449
sl@0
   450
	CDbColSet* columns= CDbColSet::NewLC();
sl@0
   451
			
sl@0
   452
	TDbCol name(KColName,EDbColLongText16,KDbNameLen);
sl@0
   453
	name.iAttributes = TDbCol::ENotNull;
sl@0
   454
	
sl@0
   455
	TDbCol name2(KCol2Name,EDbColLongText16,KDbNameLen);
sl@0
   456
sl@0
   457
	columns->AddL(name);
sl@0
   458
	columns->AddL(name2);
sl@0
   459
   	User::LeaveIfError (database.CreateTable (KTable, *columns));
sl@0
   460
	CleanupStack::PopAndDestroy(); // columns
sl@0
   461
    
sl@0
   462
    // Insert values into table
sl@0
   463
    TInt error =	database.Execute(KSQLInsert1);
sl@0
   464
    TheTest(error>=0);
sl@0
   465
    error =database.Execute(KSQLInsert2);
sl@0
   466
    TheTest(error>=0);
sl@0
   467
    error =database.Execute(KSQLInsert3);
sl@0
   468
    TheTest(error>=0);
sl@0
   469
	error =	database.Execute(KSQLInsert4);
sl@0
   470
	TheTest(error>=0);
sl@0
   471
	error =	database.Execute(KSQLInsert5);
sl@0
   472
	TheTest(error>=0);
sl@0
   473
	error = database.Execute(KSQLInsert6);
sl@0
   474
	TheTest(error>=0);
sl@0
   475
	error = database.Execute(KSQLInsert7);
sl@0
   476
	TheTest(error>=0);
sl@0
   477
	
sl@0
   478
		
sl@0
   479
	TheTest.Next(_L("Test for valid LIKE predicate queries"));
sl@0
   480
	
sl@0
   481
	
sl@0
   482
	for(TInt i =0;i<KNumQueries;++i)
sl@0
   483
		{
sl@0
   484
		RDebug::Print(_L("Executing statement: %s \n"),(KQuery[i].query));
sl@0
   485
		RDbView view;
sl@0
   486
		view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly);
sl@0
   487
		view.EvaluateAll();
sl@0
   488
		view.FirstL();      
sl@0
   489
		typedef TBuf<256> TScriptLine;
sl@0
   490
		TInt count =0;
sl@0
   491
		while (view.AtRow())
sl@0
   492
			{
sl@0
   493
			view.GetL();
sl@0
   494
			count++;
sl@0
   495
			RDbColReadStream rd;
sl@0
   496
			rd.OpenLC(view,1);
sl@0
   497
			TScriptLine text;
sl@0
   498
			rd.ReadL(text,view.ColLength(1));
sl@0
   499
			CleanupStack::PopAndDestroy();
sl@0
   500
			RDebug::Print(_L("Expected result: %s Actual Result: %S\n"),(KQuery[i].result),&text);
sl@0
   501
			TInt err = text.Compare(TPtrC(KQuery[i].result));
sl@0
   502
			TheTest(err ==0);
sl@0
   503
			view.NextL();
sl@0
   504
			}
sl@0
   505
		view.Close();		
sl@0
   506
		}
sl@0
   507
	
sl@0
   508
	
sl@0
   509
	// test for illegal statements, check they return KErrArgument
sl@0
   510
	TheTest.Next(_L("Test that illegal queries return KErrArgument"));	
sl@0
   511
	
sl@0
   512
		
sl@0
   513
	for(TInt j =0;j<KNumBadQueries;++j)
sl@0
   514
		{
sl@0
   515
		RDebug::Print(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query));
sl@0
   516
		RDbView view;
sl@0
   517
		TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly);
sl@0
   518
		TheTest(prepErr==KErrArgument);
sl@0
   519
		view.Close();		
sl@0
   520
		}
sl@0
   521
        
sl@0
   522
    CleanupStack::PopAndDestroy(&database); // database
sl@0
   523
    CleanupStack::PopAndDestroy(&fsSession); // fsSession
sl@0
   524
 	}
sl@0
   525
 	
sl@0
   526
 	
sl@0
   527
 	
sl@0
   528
 //  for LIKE Predicate for EDbColLongText8	
sl@0
   529
LOCAL_C void LikePredicateDbColLongText8TestL()
sl@0
   530
 	{
sl@0
   531
	TheTest.Next (_L ("LikePredicate DbColLongText8 TestL"));
sl@0
   532
sl@0
   533
 	//Creating database
sl@0
   534
sl@0
   535
	RFs      fsSession;
sl@0
   536
    User::LeaveIfError(fsSession.Connect());
sl@0
   537
    CleanupClosePushL(fsSession);
sl@0
   538
	RDbNamedDatabase database;
sl@0
   539
	User::LeaveIfError(database.Replace(fsSession, KDbName));
sl@0
   540
	CleanupClosePushL(database);
sl@0
   541
		
sl@0
   542
	//Create table
sl@0
   543
sl@0
   544
	CDbColSet* columns= CDbColSet::NewLC();
sl@0
   545
			
sl@0
   546
	TDbCol name(KColName,EDbColLongText8,KDbNameLen);
sl@0
   547
	name.iAttributes = TDbCol::ENotNull;
sl@0
   548
		
sl@0
   549
	TDbCol name2(KCol2Name,EDbColLongText8,KDbNameLen);
sl@0
   550
sl@0
   551
	columns->AddL(name);
sl@0
   552
	columns->AddL(name2);
sl@0
   553
   	
sl@0
   554
	User::LeaveIfError (database.CreateTable (KTable, *columns));
sl@0
   555
	CleanupStack::PopAndDestroy(); // columns
sl@0
   556
    
sl@0
   557
	// Insert values into the table    
sl@0
   558
 	TInt error =	database.Execute(KSQLInsert1);
sl@0
   559
    TheTest(error>=0);
sl@0
   560
    error =database.Execute(KSQLInsert2);
sl@0
   561
    TheTest(error>=0);
sl@0
   562
    error =database.Execute(KSQLInsert3);
sl@0
   563
    TheTest(error>=0);
sl@0
   564
	error =	database.Execute(KSQLInsert4);
sl@0
   565
	TheTest(error>=0);
sl@0
   566
	error =	database.Execute(KSQLInsert5);
sl@0
   567
	TheTest(error>=0);
sl@0
   568
	error = database.Execute(KSQLInsert6);
sl@0
   569
	TheTest(error>=0);
sl@0
   570
	error = database.Execute(KSQLInsert7);
sl@0
   571
	TheTest(error>=0);
sl@0
   572
			
sl@0
   573
	TheTest.Next(_L("Test for valid LIKE predicate queries"));
sl@0
   574
	
sl@0
   575
		
sl@0
   576
	for(TInt i =0;i<KNumQueries;++i)
sl@0
   577
		{
sl@0
   578
		RDebug::Print(_L("Executing statement: %s \n"),(KQuery[i].query));
sl@0
   579
		RDbView view;
sl@0
   580
		TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly);
sl@0
   581
		TheTest(prepErr>=0);
sl@0
   582
		TInt evErr = view.EvaluateAll();
sl@0
   583
		TheTest(evErr==0);
sl@0
   584
		TBuf8<256> result;
sl@0
   585
		TBuf8<256> colname;
sl@0
   586
		result.Copy(TPtrC(KQuery[i].result));
sl@0
   587
		view.FirstL(); 
sl@0
   588
		
sl@0
   589
		while (view.AtRow())
sl@0
   590
			{
sl@0
   591
			view.GetL();
sl@0
   592
			RDbColReadStream rd;
sl@0
   593
			rd.OpenLC(view,1);
sl@0
   594
			rd.ReadL(colname,view.ColLength(1));
sl@0
   595
			CleanupStack::PopAndDestroy();
sl@0
   596
			RDebug::Print(_L("Expected result: %S Actual Result: %S\n"),&result,&colname);
sl@0
   597
			TInt err = colname.CompareF(result);
sl@0
   598
			TheTest(err ==0);
sl@0
   599
				
sl@0
   600
			view.NextL();
sl@0
   601
			}
sl@0
   602
					
sl@0
   603
		view.Close();		
sl@0
   604
		}
sl@0
   605
		
sl@0
   606
		// test for illegal statements, check they return KErrArgument
sl@0
   607
	TheTest.Next(_L("Test that illegal queries return KErrArgument"));	
sl@0
   608
	
sl@0
   609
	
sl@0
   610
		
sl@0
   611
	for(TInt j =0;j<KNumBadQueries;++j)
sl@0
   612
		{
sl@0
   613
		RDebug::Print(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query));	
sl@0
   614
		RDbView view;
sl@0
   615
		TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly);
sl@0
   616
		TheTest(prepErr==KErrArgument);
sl@0
   617
	
sl@0
   618
		view.Close();		
sl@0
   619
		}
sl@0
   620
	       
sl@0
   621
   	CleanupStack::PopAndDestroy(&database); // database
sl@0
   622
    CleanupStack::PopAndDestroy(&fsSession); // fsSession
sl@0
   623
 	}
sl@0
   624
sl@0
   625
sl@0
   626
sl@0
   627
// Test for LIKE Predicate for EDbColText
sl@0
   628
LOCAL_C void LikePredicateDbColTextTestL()
sl@0
   629
 	{
sl@0
   630
 	TheTest.Next (_L ("LikePredicate DbColText TestL"));
sl@0
   631
 	//Creating database
sl@0
   632
	
sl@0
   633
	RFs      fsSession;
sl@0
   634
    User::LeaveIfError(fsSession.Connect());
sl@0
   635
    CleanupClosePushL(fsSession);
sl@0
   636
	RDbNamedDatabase database;
sl@0
   637
	User::LeaveIfError(database.Replace(fsSession, KDbName));
sl@0
   638
	CleanupClosePushL(database);
sl@0
   639
	
sl@0
   640
	//Create table
sl@0
   641
sl@0
   642
	CDbColSet* columns= CDbColSet::NewLC();
sl@0
   643
			
sl@0
   644
	TDbCol name(KColName,EDbColText,KDbNameLen);
sl@0
   645
	name.iAttributes = TDbCol::ENotNull;
sl@0
   646
	
sl@0
   647
	TDbCol name2(KCol2Name,EDbColText,KDbNameLen);
sl@0
   648
sl@0
   649
	columns->AddL(name);
sl@0
   650
	columns->AddL(name2);
sl@0
   651
		
sl@0
   652
	User::LeaveIfError (database.CreateTable (KTable, *columns));
sl@0
   653
	CleanupStack::PopAndDestroy(); // columns
sl@0
   654
   
sl@0
   655
 	// Insert values into the table
sl@0
   656
    TInt error =	database.Execute(KSQLInsert1);
sl@0
   657
    TheTest(error>=0);
sl@0
   658
    error =database.Execute(KSQLInsert2);
sl@0
   659
    TheTest(error>=0);
sl@0
   660
    error =database.Execute(KSQLInsert3);
sl@0
   661
    TheTest(error>=0);
sl@0
   662
	error =	database.Execute(KSQLInsert4);
sl@0
   663
	TheTest(error>=0);
sl@0
   664
	error =	database.Execute(KSQLInsert5);
sl@0
   665
	TheTest(error>=0);
sl@0
   666
	error = database.Execute(KSQLInsert6);
sl@0
   667
	TheTest(error>=0);
sl@0
   668
	error = database.Execute(KSQLInsert7);
sl@0
   669
	TheTest(error>=0);
sl@0
   670
		
sl@0
   671
sl@0
   672
	TheTest.Next(_L("Test for valid LIKE predicate queries"));
sl@0
   673
	
sl@0
   674
		
sl@0
   675
	for(TInt i =0;i<KNumQueries;++i)
sl@0
   676
		{
sl@0
   677
		RDebug::Print(_L("Executing statement: %s \n"),(KQuery[i].query));
sl@0
   678
		RDbView view;
sl@0
   679
		TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly);
sl@0
   680
		if(TPtrC(KQuery[i].result).Length() == 0)
sl@0
   681
			{
sl@0
   682
			TheTest(prepErr != KErrNone);
sl@0
   683
			continue;	
sl@0
   684
			}
sl@0
   685
				
sl@0
   686
		view.EvaluateAll();
sl@0
   687
		TBufC<256> colname;
sl@0
   688
		TBufC<256> res;
sl@0
   689
		view.FirstL();      
sl@0
   690
		while (view.AtRow())
sl@0
   691
			{
sl@0
   692
			view.GetL();
sl@0
   693
			colname = view.ColDes(1);
sl@0
   694
			res= KQuery[i].result;
sl@0
   695
			RDebug::Print(_L("Expected result: %s Actual Result: %S\n"),(KQuery[i].result),&colname);
sl@0
   696
			TInt err =	colname.Compare(TPtrC(KQuery[i].result));	
sl@0
   697
			TheTest(err ==0);
sl@0
   698
			view.NextL();
sl@0
   699
			}
sl@0
   700
		view.Close();		
sl@0
   701
		}
sl@0
   702
	
sl@0
   703
	// test for illegal statements, check they return KErrArgument
sl@0
   704
	TheTest.Next(_L("Test that illegal queries return KErrArgument"));	
sl@0
   705
	
sl@0
   706
	for(TInt j =0;j<KNumBadQueries;++j)
sl@0
   707
		{
sl@0
   708
		RDebug::Print(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query));
sl@0
   709
		RDbView view;
sl@0
   710
		TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly);
sl@0
   711
		TheTest(prepErr==KErrArgument);
sl@0
   712
		view.Close();		
sl@0
   713
		}
sl@0
   714
        
sl@0
   715
    CleanupStack::PopAndDestroy(&database); // database
sl@0
   716
    CleanupStack::PopAndDestroy(&fsSession); // fsSession
sl@0
   717
    }
sl@0
   718
 	
sl@0
   719
 	
sl@0
   720
 	
sl@0
   721
 /**
sl@0
   722
@SYMTestCaseID 			SYSLIB-DBMS-UT-1592
sl@0
   723
@SYMTestCaseDesc     	Testing limited-ESCAPE-clause
sl@0
   724
@SYMTestPriority     	High
sl@0
   725
@SYMTestActions      	Execute DBMS query with ESCAPE-clause
sl@0
   726
@SYMTestExpectedResults The test should not fail.
sl@0
   727
@SYMDEF INC076370 
sl@0
   728
*/ 	
sl@0
   729
LOCAL_C void Defect_INC076370 ()
sl@0
   730
	{
sl@0
   731
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-1592 Defect INC076370 "));
sl@0
   732
	LikePredicateDbColTextTestL(); //EDbColText
sl@0
   733
	LikePredicateDbColLongText16TestL(); //EDbColLongText16
sl@0
   734
	LikePredicateDbColLongText8TestL();	//EDbColLongText8	
sl@0
   735
	}
sl@0
   736
	
sl@0
   737
 /**
sl@0
   738
@SYMTestCaseID 			SYSLIB-DBMS-UT-1667
sl@0
   739
@SYMTestCaseDesc     	Testing RdbRowSet::DeleteL() with EDbColLongText16 type columns
sl@0
   740
@SYMTestPriority     	High
sl@0
   741
@SYMTestActions      	Create a table with a EDbColLongText16 type column and then use
sl@0
   742
						RdbRowSet::DeleteL() to delete the current row.
sl@0
   743
@SYMTestExpectedResults The test should not fail.
sl@0
   744
@SYMDEF INC083027
sl@0
   745
*/ 	
sl@0
   746
LOCAL_C void Defect_INC083027 ()
sl@0
   747
	{
sl@0
   748
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-1667 Defect INC083027 "));
sl@0
   749
	RFs fs;
sl@0
   750
	CleanupClosePushL(fs);
sl@0
   751
	User::LeaveIfError(fs.Connect());
sl@0
   752
sl@0
   753
	// create database
sl@0
   754
	RDbNamedDatabase database;
sl@0
   755
	CleanupClosePushL(database);
sl@0
   756
	User::LeaveIfError(database.Replace(fs, _L("c:\\test.db")));
sl@0
   757
sl@0
   758
	CDbColSet* columns = CDbColSet::NewLC();
sl@0
   759
	const TInt maxTextLength = 256;
sl@0
   760
	TDbCol text16Col(KText16Name, EDbColLongText16, maxTextLength);
sl@0
   761
	columns->AddL(text16Col);
sl@0
   762
sl@0
   763
	TBuf<KMaxColName> targetColName;
sl@0
   764
	targetColName = KText16Name;
sl@0
   765
	
sl@0
   766
	// create table
sl@0
   767
	User::LeaveIfError(database.CreateTable(KTableName, *columns));
sl@0
   768
	
sl@0
   769
	//create index
sl@0
   770
	CDbKey* key = CDbKey::NewLC();
sl@0
   771
	TInt keyLength = 122;
sl@0
   772
	TDbKeyCol keyCol(targetColName, keyLength);
sl@0
   773
	key->AddL(keyCol);
sl@0
   774
	User::LeaveIfError(database.CreateIndex(KIndexName, KTableName, *key));
sl@0
   775
	CleanupStack::PopAndDestroy(2);		// key and columns
sl@0
   776
	
sl@0
   777
	//insert rows
sl@0
   778
	HBufC* sqlQueryBuf = HBufC::NewLC(512);
sl@0
   779
	TPtr sqlQuery(sqlQueryBuf->Des());
sl@0
   780
	_LIT(KSQLInsertFormat, "SELECT %S FROM %S");
sl@0
   781
	sqlQuery.Format(KSQLInsertFormat, &targetColName, &KTableName);
sl@0
   782
	
sl@0
   783
	RDbView insertview;
sl@0
   784
	User::LeaveIfError(insertview.Prepare(database, TDbQuery(sqlQuery), RDbView::EInsertOnly));
sl@0
   785
	
sl@0
   786
	HBufC* tmpBuf = HBufC::NewLC(maxTextLength);
sl@0
   787
	TPtr maxString(tmpBuf->Des());
sl@0
   788
	maxString.Format(KMaxStringFormat, 0);
sl@0
   789
	insertview.InsertL();
sl@0
   790
	insertview.SetColL(1, maxString);
sl@0
   791
	insertview.PutL();
sl@0
   792
	insertview.Close();
sl@0
   793
	
sl@0
   794
	//delete the row
sl@0
   795
	RDbView deleteview;
sl@0
   796
	User::LeaveIfError(deleteview.Prepare(database, TDbQuery(sqlQuery), RDbView::EUpdatable));
sl@0
   797
	User::LeaveIfError(deleteview.EvaluateAll());
sl@0
   798
sl@0
   799
	while (deleteview.NextL())
sl@0
   800
		{
sl@0
   801
		deleteview.GetL();
sl@0
   802
		TRAPD(err , deleteview.DeleteL());
sl@0
   803
		TheTest(err==KErrNone);
sl@0
   804
		}
sl@0
   805
	deleteview.Close();
sl@0
   806
	
sl@0
   807
	CleanupStack::PopAndDestroy(2);  // tmpBuf, sqlQueryBuf
sl@0
   808
    CleanupStack::PopAndDestroy(&database); // database
sl@0
   809
    CleanupStack::PopAndDestroy(&fs); // fs
sl@0
   810
	}
sl@0
   811
sl@0
   812
 /**
sl@0
   813
@SYMTestCaseID          SYSLIB-DBMS-UT-1894
sl@0
   814
@SYMTestCaseDesc        Testing memory handling in CSqlMultiNode::Concatenate() 
sl@0
   815
@SYMTestPriority        Medium
sl@0
   816
@SYMTestActions         Execute a special request to a database which will trigger CSqlMultiNode::Concatenate(), and the size of one of the SQL nodes will be divisible by the CSqlMultiNode granularity
sl@0
   817
@SYMTestExpectedResults The test should not fail or panic.
sl@0
   818
@SYMDEF INC093657
sl@0
   819
*/        
sl@0
   820
LOCAL_C void Defect_INC093657L ()
sl@0
   821
   {
sl@0
   822
   TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-1894 Defect INC093657 "));
sl@0
   823
   RFs fs;
sl@0
   824
   CleanupClosePushL(fs);
sl@0
   825
   User::LeaveIfError(fs.Connect());
sl@0
   826
sl@0
   827
   // create database
sl@0
   828
   RDbNamedDatabase database;
sl@0
   829
   CleanupClosePushL(database);
sl@0
   830
   User::LeaveIfError(database.Replace(fs, _L("c:\\test.db")));
sl@0
   831
   
sl@0
   832
   CDbColSet* columns = CDbColSet::NewLC();
sl@0
   833
   const TInt maxTextLength = 256;
sl@0
   834
   TDbCol column(KColName, EDbColLongText16, maxTextLength);
sl@0
   835
   columns->AddL(column);
sl@0
   836
   
sl@0
   837
   // create table
sl@0
   838
   User::LeaveIfError(database.CreateTable(KTableName, *columns));
sl@0
   839
   CleanupStack::PopAndDestroy();  // columns
sl@0
   840
   
sl@0
   841
   //execute a pointless request that is intended to detect subtle memory corruptions in CSqlMultiNode::Concatenate
sl@0
   842
   RDbView view;   
sl@0
   843
   TInt err = view.Prepare(database, TDbQuery(KSqlRequestGranularity));   
sl@0
   844
   
sl@0
   845
   TheTest(err==KErrNone);   
sl@0
   846
   
sl@0
   847
   view.Close();
sl@0
   848
   database.Destroy();
sl@0
   849
   
sl@0
   850
   CleanupStack::PopAndDestroy(&database); // database
sl@0
   851
   CleanupStack::PopAndDestroy(&fs); // fs
sl@0
   852
   }
sl@0
   853
sl@0
   854
/**
sl@0
   855
@SYMTestCaseID			SYSLIB-DBMS-UT-3467
sl@0
   856
@SYMTestCaseDesc		Test for DEF105615 "DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory".
sl@0
   857
						The test creates a table with 3 coluumns and a multi-column key (3 columns). The column
sl@0
   858
						names length is such that when RDbRowSet::ColSetL() is called for retrieving the column
sl@0
   859
						names, the CDbColSet array data member will make just a single memory allocation, where
sl@0
   860
						all TDbCol elements will be stored. Then the test repeats 100 times, the following statements:
sl@0
   861
							<retrieve a colset>;
sl@0
   862
							<create a copy of colset's last TDbCol element using TDbCol's copy constructor>;
sl@0
   863
							<create a copy of colset's last TDbCol element using TDbCol's "=" operator>;
sl@0
   864
						If the test uses the compiler generated TDbCol's copy constructor and "=" operator,
sl@0
   865
						the test crashes at some iteration, because an invalid memory region is accessed and
sl@0
   866
						the crash is: KERN-EXEC 3.
sl@0
   867
						The same test is repeated for TDbKeyCol's copy constructor and "=" operator.
sl@0
   868
@SYMTestPriority		High
sl@0
   869
@SYMTestActions			Test for DEF105615 "DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory".
sl@0
   870
@SYMTestExpectedResults The test must not fail
sl@0
   871
@SYMDEF					DEF105615
sl@0
   872
*/
sl@0
   873
void DEF105615()
sl@0
   874
	{
sl@0
   875
   	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3467 DEF105615 DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory"));
sl@0
   876
	RFs fs;
sl@0
   877
	TInt err = fs.Connect();
sl@0
   878
	TheTest(err == KErrNone);
sl@0
   879
	
sl@0
   880
	RDbNamedDatabase db;
sl@0
   881
	err = db.Replace(fs, KDbName);
sl@0
   882
	TheTest(err == KErrNone);
sl@0
   883
sl@0
   884
	const TInt KColCnt = 3;
sl@0
   885
sl@0
   886
	err = db.Execute(_L("CREATE TABLE A(A1234567890 INTEGER, B1234567890 INTEGER, C12345 INTEGER)"));
sl@0
   887
	TheTest(err == KErrNone);
sl@0
   888
	err = db.Execute(_L("CREATE INDEX I1 ON A(A1234567890, B1234567890, C12345)"));
sl@0
   889
	TheTest(err == KErrNone);
sl@0
   890
	
sl@0
   891
	RDbTable tbl;
sl@0
   892
	err = tbl.Open(db, _L("A"));
sl@0
   893
	TheTest(err == KErrNone);
sl@0
   894
sl@0
   895
	//It is very hard to reproduce the problem, because the memory region after the memory, occupied by 
sl@0
   896
	//CDbColSet's array, may be valid. That is the reason the test is repeated in a loop KTestCnt times, 
sl@0
   897
	//where every  ColSetL() call will allocate a new block of memory for its array and at some point TDbCol's 
sl@0
   898
	//copy constructor and "=" operator may try to access an invalid memory area, if the compiler generated
sl@0
   899
	//ones are used.
sl@0
   900
	const TInt KTestCnt = 100;
sl@0
   901
	TInt i;
sl@0
   902
	CDbColSet* colset[KTestCnt];
sl@0
   903
	for(i=0;i<KTestCnt;++i)
sl@0
   904
		{
sl@0
   905
		TRAP(err, colset[i] = tbl.ColSetL());
sl@0
   906
		TheTest(err == KErrNone);
sl@0
   907
		TDbCol lastCol = (*colset[i])[KColCnt];		//copy constructor
sl@0
   908
		lastCol = (*colset[i])[KColCnt];			//"=" operator
sl@0
   909
		}
sl@0
   910
	for(i=0;i<KTestCnt;++i)
sl@0
   911
		{
sl@0
   912
		delete colset[i];
sl@0
   913
		}
sl@0
   914
	
sl@0
   915
	tbl.Close();
sl@0
   916
sl@0
   917
	//The same test is repeated for TDbKeyCol's copy constructor and "=" operator
sl@0
   918
	CDbKey* key[KTestCnt];	
sl@0
   919
	for(i=0;i<KTestCnt;++i)
sl@0
   920
		{
sl@0
   921
		TRAP(err, key[i] = db.KeyL(_L("I1"), _L("A")));
sl@0
   922
		TheTest(err == KErrNone);
sl@0
   923
		TDbKeyCol lastKeyCol = (*key[i])[KColCnt - 1];	//copy constructor
sl@0
   924
		lastKeyCol = (*key[i])[KColCnt - 1];			//"=" operator
sl@0
   925
		}
sl@0
   926
	for(i=0;i<KTestCnt;++i)
sl@0
   927
		{
sl@0
   928
		delete key[i];
sl@0
   929
		}
sl@0
   930
sl@0
   931
	db.Close();
sl@0
   932
	err = fs.Delete(KDbName);
sl@0
   933
	TheTest(err == KErrNone);
sl@0
   934
	fs.Close();
sl@0
   935
	}
sl@0
   936
   
sl@0
   937
/**
sl@0
   938
@SYMTestCaseID			SYSLIB-DBMS-UT-3469
sl@0
   939
@SYMTestCaseDesc		Test for DEF105615 "DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory".
sl@0
   940
						The test creates TDbCol and TDbKeyCol objects, creates their copies using copy constructors
sl@0
   941
						and "=" operators and checks that the copies were constructed correctly,
sl@0
   942
@SYMTestPriority		High
sl@0
   943
@SYMTestActions			Test for DEF105615 "DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory".
sl@0
   944
@SYMTestExpectedResults The test must not fail
sl@0
   945
@SYMDEF					DEF105615
sl@0
   946
*/
sl@0
   947
void DEF105615_2()
sl@0
   948
	{
sl@0
   949
   	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3469 DEF105615 DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory - 2 "));
sl@0
   950
   	
sl@0
   951
   	const TDbColType KColType = EDbColText16;
sl@0
   952
   	const TInt KMaxColLen = 73;
sl@0
   953
   	const TUint KColAttributes = TDbCol::ENotNull;
sl@0
   954
   	_LIT(KColName, "Name");
sl@0
   955
   	
sl@0
   956
   	TDbCol srcDbCol(KColName, EDbColText16, KMaxColLen);
sl@0
   957
   	srcDbCol.iAttributes = KColAttributes;
sl@0
   958
sl@0
   959
	//TDbCol - copy constructor   	
sl@0
   960
   	TDbCol dbColCopy1(srcDbCol);
sl@0
   961
   	TheTest(dbColCopy1.iType == srcDbCol.iType && dbColCopy1.iType == KColType);
sl@0
   962
   	TheTest(dbColCopy1.iMaxLength == srcDbCol.iMaxLength && dbColCopy1.iMaxLength == KMaxColLen);
sl@0
   963
   	TheTest(dbColCopy1.iAttributes == srcDbCol.iAttributes && dbColCopy1.iAttributes == KColAttributes);
sl@0
   964
   	TheTest(dbColCopy1.iName == srcDbCol.iName && dbColCopy1.iName == KColName);
sl@0
   965
sl@0
   966
	//TDbCol - "=" operator
sl@0
   967
   	TDbCol dbColCopy2;
sl@0
   968
   	dbColCopy2 = srcDbCol;
sl@0
   969
   	TheTest(dbColCopy2.iType == srcDbCol.iType && dbColCopy2.iType == KColType);
sl@0
   970
   	TheTest(dbColCopy2.iMaxLength == srcDbCol.iMaxLength && dbColCopy2.iMaxLength == KMaxColLen);
sl@0
   971
   	TheTest(dbColCopy2.iAttributes == srcDbCol.iAttributes && dbColCopy2.iAttributes == KColAttributes);
sl@0
   972
   	TheTest(dbColCopy2.iName == srcDbCol.iName && dbColCopy2.iName == KColName);
sl@0
   973
sl@0
   974
	//TDbCol - self assignment
sl@0
   975
	srcDbCol = srcDbCol;
sl@0
   976
   	TheTest(srcDbCol.iType == KColType);
sl@0
   977
   	TheTest(srcDbCol.iMaxLength == KMaxColLen);
sl@0
   978
   	TheTest(srcDbCol.iAttributes == KColAttributes);
sl@0
   979
   	TheTest(srcDbCol.iName == KColName);
sl@0
   980
sl@0
   981
   	const TInt KKeyLen = 29;
sl@0
   982
   	const TDbKeyCol::TOrder KKeyOrder = TDbKeyCol::EDesc;
sl@0
   983
   	_LIT(KKeyName, "Name22");
sl@0
   984
sl@0
   985
   	TDbKeyCol srcDbKeyCol(KKeyName, KKeyLen, KKeyOrder);
sl@0
   986
   	
sl@0
   987
	//TDbKeyCol - copy constructor   	
sl@0
   988
   	TDbKeyCol dbKeyColCopy1(srcDbKeyCol);
sl@0
   989
   	TheTest(dbKeyColCopy1.iOrder == srcDbKeyCol.iOrder && dbKeyColCopy1.iOrder == KKeyOrder);
sl@0
   990
   	TheTest(dbKeyColCopy1.iLength == srcDbKeyCol.iLength && dbKeyColCopy1.iLength == KKeyLen);
sl@0
   991
   	TheTest(dbKeyColCopy1.iName == srcDbKeyCol.iName && dbKeyColCopy1.iName == KKeyName);
sl@0
   992
   	
sl@0
   993
	//TDbKeyCol - "=" operator
sl@0
   994
   	TDbKeyCol dbKeyColCopy2;
sl@0
   995
   	dbKeyColCopy2 = srcDbKeyCol;
sl@0
   996
   	TheTest(dbKeyColCopy2.iOrder == srcDbKeyCol.iOrder && dbKeyColCopy2.iOrder == KKeyOrder);
sl@0
   997
   	TheTest(dbKeyColCopy2.iLength == srcDbKeyCol.iLength && dbKeyColCopy2.iLength == KKeyLen);
sl@0
   998
   	TheTest(dbKeyColCopy2.iName == srcDbKeyCol.iName && dbKeyColCopy2.iName == KKeyName);
sl@0
   999
sl@0
  1000
	//TDbKeyCol - self assignment
sl@0
  1001
	srcDbKeyCol = srcDbKeyCol;
sl@0
  1002
   	TheTest(srcDbKeyCol.iOrder == KKeyOrder);
sl@0
  1003
   	TheTest(srcDbKeyCol.iLength == KKeyLen);
sl@0
  1004
   	TheTest(srcDbKeyCol.iName == KKeyName);
sl@0
  1005
   	}
sl@0
  1006
   
sl@0
  1007
/**
sl@0
  1008
@SYMTestCaseID          SYSLIB-DBMS-UT-3413
sl@0
  1009
@SYMTestCaseDesc        Testing that "incremental update" operations running in one connection does not 
sl@0
  1010
						interfere with database operations executed from a second connection
sl@0
  1011
@SYMTestPriority        High
sl@0
  1012
@SYMTestActions         Create a test database with one table and insert some records there (> 100).
sl@0
  1013
						Create 2 database connections.
sl@0
  1014
						Open that database from connection 1 and execute an incremental update operation
sl@0
  1015
						in a transaction. At the same time try to open and close the same table from 
sl@0
  1016
						connection 2, mixing these operations with the RDbUpdate::Next() calls from 
sl@0
  1017
						connection 1. So the call pattern should be:
sl@0
  1018
						@code
sl@0
  1019
						RDbUpdate dbUpdate;
sl@0
  1020
						....
sl@0
  1021
						while((err = dbUpdate.Next()) > 0)		//from "Conenction 1"
sl@0
  1022
							{
sl@0
  1023
							RDbTable tbl;
sl@0
  1024
							err = tbl.Open(TheDb2, _L("A"));	//from "Conenction 2"
sl@0
  1025
							...
sl@0
  1026
							}
sl@0
  1027
						@endcode						
sl@0
  1028
@SYMTestExpectedResults The test should not fail or panic.
sl@0
  1029
@SYMDEF INC101720
sl@0
  1030
*/
sl@0
  1031
void Defect_INC101720()
sl@0
  1032
	{
sl@0
  1033
    TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3413 "));
sl@0
  1034
	//Create the test database
sl@0
  1035
	TInt err = TheDb1.Replace(TheFs, KDbName);
sl@0
  1036
	TEST2(err, KErrNone);
sl@0
  1037
	TheDb1.Close();
sl@0
  1038
	TheCrcChecker.GenerateCrcL(KDbName);
sl@0
  1039
sl@0
  1040
	//Establish the first database connection
sl@0
  1041
#ifndef __TOOLS2__
sl@0
  1042
	err = TheDbs1.Connect();
sl@0
  1043
	TEST2(err, KErrNone);
sl@0
  1044
#endif
sl@0
  1045
	err = TheDb1.Open(TheDbs1, KDbName);
sl@0
  1046
	TEST2(err, KErrNone);
sl@0
  1047
	//Create a test table and fill the table with enough test records (> 100)
sl@0
  1048
	err = TheDb1.Execute(_L("CREATE TABLE A(Id COUNTER, Id2 INTEGER, Name LONG VARCHAR)"));	
sl@0
  1049
	TEST2(err, KErrNone);
sl@0
  1050
	const TInt KTestRecCount = 200;
sl@0
  1051
	err = TheDb1.Begin();	
sl@0
  1052
	TEST2(err, KErrNone);
sl@0
  1053
	for(TInt i=0;i<KTestRecCount;++i)
sl@0
  1054
		{
sl@0
  1055
		_LIT(KSqlFmtStr, "INSERT INTO A(Id2, Name) VALUES(%d, 'TestNameString')");
sl@0
  1056
		TBuf<100> sql;
sl@0
  1057
		// We can't use this because Math::Random() may return different numbers on 
sl@0
  1058
		// different platform, which will lead to different output that result in 
sl@0
  1059
		// CRC test failing.
sl@0
  1060
		// TUint32 id = Math::Random() % KTestRecCount;
sl@0
  1061
		TUint32 id = (i^0x55555555) % KTestRecCount;
sl@0
  1062
sl@0
  1063
		sql.Format(KSqlFmtStr, id + 1);
sl@0
  1064
		err = TheDb1.Execute(sql);
sl@0
  1065
		TEST2(err, 1);
sl@0
  1066
		}
sl@0
  1067
	err = TheDb1.Commit();	
sl@0
  1068
	TEST2(err, KErrNone);
sl@0
  1069
	//Establish a second connection with the same test database
sl@0
  1070
#ifndef __TOOLS2__
sl@0
  1071
	err = TheDbs2.Connect();
sl@0
  1072
	TEST2(err, KErrNone);
sl@0
  1073
#endif
sl@0
  1074
	err = TheDb2.Open(TheDbs2, KDbName);
sl@0
  1075
	TEST2(err, KErrNone);
sl@0
  1076
	//The test: Conenction 1 - "incremental update" operation.
sl@0
  1077
	//			Connection 2 - "open table/close table" operations mixed with the incremental Next-s.
sl@0
  1078
	//Expectation: The test must not fail.
sl@0
  1079
	err = TheDb1.Begin();
sl@0
  1080
	TEST2(err, KErrNone);
sl@0
  1081
	RDbUpdate dbUpdate;
sl@0
  1082
	err = dbUpdate.Execute(TheDb1, _L("UPDATE A SET Name = 'ModifiedNameString' WHERE Id2 > 10"));
sl@0
  1083
	TEST2(err, KErrNone);
sl@0
  1084
	TInt step = 0;
sl@0
  1085
	while((err = dbUpdate.Next()) > 0)
sl@0
  1086
		{
sl@0
  1087
		++step;
sl@0
  1088
		RDbTable tbl;
sl@0
  1089
		err = tbl.Open(TheDb2, _L("A"));
sl@0
  1090
		TEST2(err, KErrNone);
sl@0
  1091
		tbl.Close();
sl@0
  1092
		}
sl@0
  1093
	TEST(step > 1);//just to be sure that the test executes dbUpdate.Next() more than once
sl@0
  1094
	TEST2(err, KErrNone);
sl@0
  1095
	dbUpdate.Close();
sl@0
  1096
	err = TheDb1.Commit();
sl@0
  1097
	TEST2(err, KErrNone);
sl@0
  1098
	//Cleanup
sl@0
  1099
	TheDb2.Close();
sl@0
  1100
#ifndef __TOOLS2__
sl@0
  1101
	TheDbs2.Close();
sl@0
  1102
#endif
sl@0
  1103
	TheDb1.Close();
sl@0
  1104
#ifndef __TOOLS2__
sl@0
  1105
	TheDbs1.Close();
sl@0
  1106
#endif
sl@0
  1107
	TheCrcChecker.GenerateCrcL(KDbName);
sl@0
  1108
	}
sl@0
  1109
sl@0
  1110
/**
sl@0
  1111
@SYMTestCaseID          SYSLIB-DBMS-UT-3484
sl@0
  1112
@SYMTestCaseDesc        DBMS Hindi collation doesn't work on long text fields.  
sl@0
  1113
@SYMTestPriority        Medium
sl@0
  1114
@SYMTestActions         This test is to check that DBMS correctly sorts columns using Collation, when 
sl@0
  1115
						the columns are of type EDbColLongText16.  Previous implementations split the 
sl@0
  1116
						strings to be compared into chunks, however this could cause it to be sorted 
sl@0
  1117
						incorrectly if it was split on a combining or accent character.  This fault
sl@0
  1118
						occurs on the default locale as well as Hindi.  Test steps:
sl@0
  1119
						* Create a database table and adds several unicode strings to EDbColLongText16 
sl@0
  1120
						  column in table.  One set of strings have an ascii character followed by 
sl@0
  1121
						  an accent (e + ') and the other set have the combined equivilant ascii 
sl@0
  1122
						  character (è).  These should have the same sort order,however if are split 
sl@0
  1123
						  then will compare differently.
sl@0
  1124
						* Sort the columns using EDbCompareCollated
sl@0
  1125
						* Check that the columns were sorted in the correct order
sl@0
  1126
@SYMTestExpectedResults The columns should get sorted into ascending order correctly
sl@0
  1127
@SYMDEF INC107268
sl@0
  1128
*/
sl@0
  1129
void Defect_INC107268L()
sl@0
  1130
	{
sl@0
  1131
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3484 Defect INC107268 - DBMS Hindi collation doesn't work on long text fields"));
sl@0
  1132
     
sl@0
  1133
     // some unicode characters
sl@0
  1134
     const TChar Ka(0x0061); 		// a    
sl@0
  1135
     const TChar Kb(0x0062); 		// b
sl@0
  1136
     const TChar Ke(0x0065);			// e
sl@0
  1137
     const TChar Kgrave(0x0060); 	// ' (grave)
sl@0
  1138
     const TChar Kegrave(0x00e8);  	// e with grave
sl@0
  1139
     const TChar K1(0x0031);			// 1
sl@0
  1140
     const TChar K2(0x0032);			// 2
sl@0
  1141
 
sl@0
  1142
  	// the maximum characters in a EDbColLongText16 string before dbms stops storing
sl@0
  1143
  	// the string inline, and we need to read it from a stream (see TBlobKey).
sl@0
  1144
  	const TInt KInlineLimit = 127;
sl@0
  1145
  	
sl@0
  1146
  	// maximum number of characters buffered in TBlobKey when string stored out of line.
sl@0
  1147
  	// (see TBlobKey::ETruncSize which is in bytes)
sl@0
  1148
  	const TInt KTruncLimit = 16; 
sl@0
  1149
 
sl@0
  1150
  	const TInt KMaxStringSize = 256;
sl@0
  1151
  	
sl@0
  1152
  	TBuf<KMaxStringSize> inLineBoundryA;
sl@0
  1153
  	TBuf<KMaxStringSize> inLineBoundryB;
sl@0
  1154
  	TBuf<KMaxStringSize> truncBoundryA;
sl@0
  1155
  	TBuf<KMaxStringSize> truncBoundryB;
sl@0
  1156
  	TBuf<KMaxStringSize> padding;
sl@0
  1157
     
sl@0
  1158
     // this string will be stored inline.  It should sort to be < stringB
sl@0
  1159
     inLineBoundryA.Fill(Ka, KInlineLimit-2);
sl@0
  1160
     inLineBoundryA.Append(Kegrave);
sl@0
  1161
     inLineBoundryA.Append(K1);
sl@0
  1162
     
sl@0
  1163
     // this string is just over the break point, so *is* truncated. 
sl@0
  1164
     // this is expected to get sorted incorrecly as combining character is split off (negative test case)
sl@0
  1165
     inLineBoundryB.Fill(Ka, KInlineLimit-2);
sl@0
  1166
     inLineBoundryB.Append(Ke);
sl@0
  1167
     inLineBoundryB.Append(Kgrave);
sl@0
  1168
     inLineBoundryB.Append(K2);
sl@0
  1169
         
sl@0
  1170
     padding.Fill(Kb, KInlineLimit);
sl@0
  1171
     
sl@0
  1172
     // this string is longger that KInlineLimit so is stored out of line
sl@0
  1173
     truncBoundryA.Fill(Kb, KTruncLimit-2);
sl@0
  1174
     truncBoundryA.Append(Kegrave);
sl@0
  1175
     truncBoundryA.Append(K1);
sl@0
  1176
     truncBoundryA.Append(padding);
sl@0
  1177
     
sl@0
  1178
     // this string has combining characters that fall on boundry of ETruncSize value (32 bytes)
sl@0
  1179
     truncBoundryB.Fill(Kb, KTruncLimit-2);
sl@0
  1180
     truncBoundryB.Append(Ke);
sl@0
  1181
     truncBoundryB.Append(Kgrave);
sl@0
  1182
     truncBoundryB.Append(K2);
sl@0
  1183
     truncBoundryB.Append(padding);
sl@0
  1184
     
sl@0
  1185
     
sl@0
  1186
     // e and '(grave) characters seperately
sl@0
  1187
     TBuf<3> e_grave; 
sl@0
  1188
     e_grave.Append( Ke );
sl@0
  1189
     e_grave.Append( Kgrave );    
sl@0
  1190
     
sl@0
  1191
     // e with grave character - this should sort the same as e_grave
sl@0
  1192
     TBuf<3> egrave; 
sl@0
  1193
     egrave.Append( Kegrave );
sl@0
  1194
     
sl@0
  1195
     TBuf<1> nullString;
sl@0
  1196
     
sl@0
  1197
 	e_grave.Append(K2); // make e_grave sort second
sl@0
  1198
     egrave.Append(K1);  // make egrave sort first
sl@0
  1199
     
sl@0
  1200
     // Check with database
sl@0
  1201
     _LIT(KPosLmLandmarkTable, "lmt_landmark");
sl@0
  1202
     _LIT(KPosLmLandmarkIdCol, "lmc_lmid");
sl@0
  1203
     _LIT(KPosLmNameCol, "lmc_name");
sl@0
  1204
         
sl@0
  1205
     TInt err = TheDb1.Replace( TheFs, KDbName );
sl@0
  1206
     TEST2 (err, KErrNone);
sl@0
  1207
 	CleanupClosePushL(TheDb1);
sl@0
  1208
         
sl@0
  1209
     CDbColSet* columns = CDbColSet::NewLC();
sl@0
  1210
     TDbCol idField( KPosLmLandmarkIdCol, EDbColUint32 );
sl@0
  1211
     idField.iAttributes |= TDbCol::EAutoIncrement;
sl@0
  1212
     columns->AddL( idField );
sl@0
  1213
     columns->AddL( TDbCol( KPosLmNameCol, EDbColLongText16 ) ); // Works with EDbColText16.  Defect only for EDbColLongText16.
sl@0
  1214
     
sl@0
  1215
     err = TheDb1.CreateTable( KPosLmLandmarkTable, *columns );
sl@0
  1216
     TEST2 (err, KErrNone);   
sl@0
  1217
     CleanupStack::PopAndDestroy(columns);
sl@0
  1218
     
sl@0
  1219
     RDbTable table;
sl@0
  1220
     err = table.Open( TheDb1, KPosLmLandmarkTable );
sl@0
  1221
     TEST2 (err, KErrNone);
sl@0
  1222
     CleanupClosePushL(table);
sl@0
  1223
 	
sl@0
  1224
 	// add rows to table
sl@0
  1225
   	table.InsertL();
sl@0
  1226
     table.SetColL( 2, egrave); // row 0 - sorted 8th
sl@0
  1227
     table.PutL();
sl@0
  1228
 
sl@0
  1229
 	table.InsertL();
sl@0
  1230
     table.SetColL( 2, e_grave ); // row 1 - sorted 9th
sl@0
  1231
     table.PutL();
sl@0
  1232
    
sl@0
  1233
     table.InsertL();
sl@0
  1234
     table.SetColL( 2, inLineBoundryA ); // row 2 - sorted 3rd (incorrectly - negative test case)
sl@0
  1235
     table.PutL();
sl@0
  1236
     
sl@0
  1237
     table.InsertL();
sl@0
  1238
     table.SetColL( 2, inLineBoundryB ); // row 3 - sorted 2nd (incorrectly - negative test case)
sl@0
  1239
     table.PutL();
sl@0
  1240
     
sl@0
  1241
     table.InsertL();
sl@0
  1242
     table.SetColL( 2, nullString ); // row 4 - sorted 1st
sl@0
  1243
     table.PutL();
sl@0
  1244
   
sl@0
  1245
   	table.InsertL();
sl@0
  1246
     table.SetColL( 2, truncBoundryB ); // row 5 - sorted 5th
sl@0
  1247
     table.PutL();
sl@0
  1248
     
sl@0
  1249
     table.InsertL();
sl@0
  1250
     table.SetColL( 2, truncBoundryA ); // row 6 - sorted 4th
sl@0
  1251
     table.PutL();
sl@0
  1252
     
sl@0
  1253
 
sl@0
  1254
     CleanupStack::PopAndDestroy(); // table.close()
sl@0
  1255
 
sl@0
  1256
 	// do an sql select with Order By to sort columns
sl@0
  1257
     _LIT(KPosLmSqlSelectOrderByString, "SELECT %S, %S FROM %S ORDER BY %S");
sl@0
  1258
     TBuf<200> sql;
sl@0
  1259
     sql.Format( KPosLmSqlSelectOrderByString, 
sl@0
  1260
                 &KPosLmLandmarkIdCol,
sl@0
  1261
                 &KPosLmNameCol,
sl@0
  1262
                 &KPosLmLandmarkTable,
sl@0
  1263
                 &KPosLmNameCol);
sl@0
  1264
     
sl@0
  1265
     RDbView view;
sl@0
  1266
     CleanupClosePushL(view);
sl@0
  1267
     err = view.Prepare( TheDb1, TDbQuery( sql, EDbCompareCollated ) );
sl@0
  1268
     TEST2 (err, KErrNone);
sl@0
  1269
     err = view.EvaluateAll();
sl@0
  1270
     TEST2 (err, KErrNone);
sl@0
  1271
         
sl@0
  1272
     // Now check that view is ordered correctly  
sl@0
  1273
     const TUint32 ExpectedOrder[] = {4,3,2,6,5,0,1};
sl@0
  1274
     TInt x = 0;
sl@0
  1275
     while (view.NextL())
sl@0
  1276
         {
sl@0
  1277
         view.GetL();
sl@0
  1278
         TEST2(view.ColUint32(1), ExpectedOrder[x]); // check we got the expected order
sl@0
  1279
         x++;          
sl@0
  1280
         }
sl@0
  1281
     TEST2(x, 7); // check we got the right number of values
sl@0
  1282
     CleanupStack::PopAndDestroy(2); // TheDb1.Close(); view.Close()
sl@0
  1283
	TheCrcChecker.GenerateCrcL(KDbName);
sl@0
  1284
sl@0
  1285
 	}
sl@0
  1286
 
sl@0
  1287
   
sl@0
  1288
LOCAL_C void DoTestsL ()
sl@0
  1289
	{
sl@0
  1290
	__UHEAP_MARK;
sl@0
  1291
	CleanupClosePushL(TheFs);
sl@0
  1292
	Defect_INC076370();
sl@0
  1293
	Defect_INC083027();
sl@0
  1294
sl@0
  1295
//	Defect_DEF44697L ();  // Use of three RThreads, not possible for tools2.
sl@0
  1296
sl@0
  1297
	Defect_INC093657L(); 
sl@0
  1298
	Defect_INC101720(); 
sl@0
  1299
// These two tests don't work on 9.3.
sl@0
  1300
	DEF105615();
sl@0
  1301
	DEF105615_2();
sl@0
  1302
sl@0
  1303
	Defect_INC107268L();
sl@0
  1304
	CleanupStack::PopAndDestroy(); // TheFs.Close()
sl@0
  1305
	__UHEAP_MARKEND;
sl@0
  1306
	}
sl@0
  1307
sl@0
  1308
GLDEF_C TInt E32Main ()
sl@0
  1309
	{
sl@0
  1310
	__UHEAP_MARK;
sl@0
  1311
	TheTest.Title ();
sl@0
  1312
	TheTest.Start (_L ("Verify Defect Fixes"));
sl@0
  1313
	
sl@0
  1314
	TheTrapCleanup = CTrapCleanup::New ();
sl@0
  1315
	__ASSERT_ALWAYS (TheTrapCleanup!=NULL, User::Invariant ());
sl@0
  1316
sl@0
  1317
	TInt err = TheFs.Connect();
sl@0
  1318
	TheTest(err == KErrNone);
sl@0
  1319
	
sl@0
  1320
	TRAP (err,DoTestsL ());
sl@0
  1321
	TheTest (err==KErrNone);
sl@0
  1322
sl@0
  1323
	//Wait some time, because DBMS server won't be destroyed right after the last DBMS session
sl@0
  1324
	//being clossed.
sl@0
  1325
	TheTest.Printf(_L("Wait DBMS server shutdown...\n"));
sl@0
  1326
	User::After(7000000);
sl@0
  1327
sl@0
  1328
#ifndef __linux__
sl@0
  1329
#ifndef __TOOLS2__
sl@0
  1330
	TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
sl@0
  1331
	TheTest(err==KErrNone);
sl@0
  1332
	TheTest(lc==KErrNone);
sl@0
  1333
#else
sl@0
  1334
	TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
sl@0
  1335
	TPtrC errmsg;
sl@0
  1336
	TheCrcChecker.ErrorReportL(err, errmsg);
sl@0
  1337
	RDebug::Print(errmsg);
sl@0
  1338
	TheTest(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
sl@0
  1339
#endif
sl@0
  1340
#endif
sl@0
  1341
sl@0
  1342
	delete TheTrapCleanup;
sl@0
  1343
sl@0
  1344
	TheTest.End ();
sl@0
  1345
	TheTest.Close ();
sl@0
  1346
sl@0
  1347
	__UHEAP_MARKEND;
sl@0
  1348
	return (0);
sl@0
  1349
	}