1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sql/TEST/t_sqlconfigfile.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1013 @@
1.4 +// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32test.h>
1.20 +#include <sqldb.h>
1.21 +//#include "SqlUtil.h"
1.22 +#include "SqlSrvConfig.h"
1.23 +#include "SqlResourceTester.h"
1.24 +
1.25 +/////////////////////////////////////////////////////////////////////////////////////////////////
1.26 +/// This test works only if the whole SQL component is built with SYSLIBS_TEST macro defined! ///
1.27 +/////////////////////////////////////////////////////////////////////////////////////////////////
1.28 +
1.29 +RTest TheTest(_L("t_sqlconfigfile test"));
1.30 +
1.31 +#ifdef SYSLIBS_TEST
1.32 +
1.33 +RFs TheFs;
1.34 +RSqlDatabase TheDb;
1.35 +
1.36 +_LIT(KTestDir, "c:\\test\\");
1.37 +_LIT(KTestDbName, "c:\\test\\t_sqlconfigfile.db");
1.38 +_LIT(KSqlSrvConfigFile, "c:\\test\\t_sqlserver.cfg");
1.39 +_LIT(KSqlSrvName, "sqlsrv.exe");
1.40 +
1.41 +enum TConfigParamType {EPrmCacheSize, EPrmPageSize, EPrmDbEncoding};
1.42 +
1.43 +//Default configuration parameter values, defined in ../test/sqlserver.cfg file
1.44 +//(the same as the build-time configuration parameter values)
1.45 +const TInt KDefaultPageSize = 1024;
1.46 +const TInt KDefaultCacheSize = (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / KDefaultPageSize;
1.47 +const TSqlSrvConfigParams::TDbEncoding KDefaultEncoding = TSqlSrvConfigParams::EEncUtf16;
1.48 +
1.49 +TInt KillProcess(const TDesC& aProcessName);
1.50 +
1.51 +///////////////////////////////////////////////////////////////////////////////////////
1.52 +// Destroy functions
1.53 +
1.54 +TInt KillProcess(const TDesC& aProcessName)
1.55 + {
1.56 + TFullName name;
1.57 + //RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName);
1.58 + TBuf<64> pattern(aProcessName);
1.59 + TInt length = pattern.Length();
1.60 + pattern += _L("*");
1.61 + TFindProcess procFinder(pattern);
1.62 +
1.63 + while (procFinder.Next(name) == KErrNone)
1.64 + {
1.65 + if (name.Length() > length)
1.66 + {//If found name is a string containing aProcessName string.
1.67 + TChar c(name[length]);
1.68 + if (c.IsAlphaDigit() ||
1.69 + c == TChar('_') ||
1.70 + c == TChar('-'))
1.71 + {
1.72 + // If the found name is other valid application name
1.73 + // starting with aProcessName string.
1.74 + //RDebug::Print(_L(":: Process name: \"%S\".\n"), &name);
1.75 + continue;
1.76 + }
1.77 + }
1.78 + RProcess proc;
1.79 + if (proc.Open(name) == KErrNone)
1.80 + {
1.81 + proc.Kill(0);
1.82 + //RDebug::Print(_L("\"%S\" process killed.\n"), &name);
1.83 + }
1.84 + proc.Close();
1.85 + }
1.86 + return KErrNone;
1.87 + }
1.88 +
1.89 +void DestroyTestEnv()
1.90 + {
1.91 + TheDb.Close();
1.92 + (void)KillProcess(KSqlSrvName);
1.93 + (void)TheFs.Delete(KTestDbName);
1.94 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.95 + TheFs.Close();
1.96 + }
1.97 +
1.98 +///////////////////////////////////////////////////////////////////////////////////////
1.99 +// Test macros and functions
1.100 +
1.101 +void Check(TInt aValue, TInt aLine)
1.102 + {
1.103 + if(!aValue)
1.104 + {
1.105 + DestroyTestEnv();
1.106 + TheTest(EFalse, aLine);
1.107 + }
1.108 + }
1.109 +void Check(TInt aValue, TInt aExpected, TInt aLine)
1.110 + {
1.111 + if(aValue != aExpected)
1.112 + {
1.113 + DestroyTestEnv();
1.114 + RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.115 + TheTest(EFalse, aLine);
1.116 + }
1.117 + }
1.118 +#define TEST(arg) ::Check((arg), __LINE__)
1.119 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.120 +
1.121 +// OOM test functions
1.122 +
1.123 +static TInt TheHandleCount1;
1.124 +static TInt TheHandleCount2;
1.125 +static TInt TheAllocatedCellsCount;
1.126 +
1.127 +void MarkHandles()
1.128 + {
1.129 + RThread().HandleCount(TheHandleCount1, TheHandleCount2);
1.130 + }
1.131 +
1.132 +void CheckHandles()
1.133 + {
1.134 + TInt endHandleCount1;
1.135 + TInt endHandleCount2;
1.136 +
1.137 + RThread().HandleCount(endHandleCount1, endHandleCount2);
1.138 +
1.139 + TEST(TheHandleCount1 == endHandleCount1);
1.140 + TEST(TheHandleCount2 == endHandleCount2);
1.141 + }
1.142 +
1.143 +void MarkAllocatedCells()
1.144 + {
1.145 + TheAllocatedCellsCount = User::CountAllocCells();
1.146 + }
1.147 +
1.148 +void CheckAllocatedCells()
1.149 + {
1.150 + TInt allocatedCellsCount = User::CountAllocCells();
1.151 + TEST(allocatedCellsCount == TheAllocatedCellsCount);
1.152 + }
1.153 +
1.154 +///////////////////////////////////////////////////////////////////////////////////////
1.155 +// Set up functions
1.156 +
1.157 +TInt DoCreateSecurityPolicy(RSqlSecurityPolicy& securityPolicy)
1.158 + {
1.159 + const TSecurityPolicy KDefaultPolicy(TSecurityPolicy::EAlwaysPass);
1.160 + if((KErrNone != securityPolicy.Create(KDefaultPolicy))
1.161 + ||
1.162 + (KErrNone != securityPolicy.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, KDefaultPolicy))
1.163 + ||
1.164 + (KErrNone != securityPolicy.SetDbPolicy(RSqlSecurityPolicy::EWritePolicy, KDefaultPolicy))
1.165 + ||
1.166 + (KErrNone != securityPolicy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, KDefaultPolicy)))
1.167 + {
1.168 + return KErrGeneral;
1.169 + }
1.170 +
1.171 + return KErrNone;
1.172 + }
1.173 +
1.174 +void SetupTestEnv()
1.175 + {
1.176 + TInt err = TheFs.Connect();
1.177 + TEST2(err, KErrNone);
1.178 +
1.179 + err = TheFs.MkDir(KTestDir);
1.180 + TEST(err == KErrNone || err == KErrAlreadyExists);
1.181 +
1.182 + err = TheFs.CreatePrivatePath(EDriveC);
1.183 + TEST(err == KErrNone || err == KErrAlreadyExists);
1.184 +
1.185 + (void)TheFs.Delete(KTestDbName);
1.186 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.187 + }
1.188 +
1.189 +///////////////////////////////////////////////////////////////////////////////////////
1.190 +// Parameter check functions
1.191 +
1.192 +TInt DoGetConfigParamValueL(RSqlDatabase& aDb, TConfigParamType aPrmType)
1.193 + {
1.194 + TSqlScalarFullSelectQuery q(aDb);
1.195 + TInt res = 0;
1.196 + switch(aPrmType)
1.197 + {
1.198 + case EPrmCacheSize:
1.199 + res = q.SelectIntL(_L8("PRAGMA cache_size"));
1.200 + break;
1.201 + case EPrmPageSize:
1.202 + res = q.SelectIntL(_L8("PRAGMA page_size"));
1.203 + break;
1.204 + case EPrmDbEncoding:
1.205 + {
1.206 + TBuf<20> dbEncodingText;
1.207 + res = q.SelectTextL(_L8("PRAGMA encoding"), dbEncodingText);
1.208 + TEST2(res, KErrNone);
1.209 + if(dbEncodingText.FindF(_L("UTF-16")) >= 0)
1.210 + {
1.211 + res = TSqlSrvConfigParams::EEncUtf16;
1.212 + }
1.213 + else if(dbEncodingText.FindF(_L("UTF-8")) >= 0)
1.214 + {
1.215 + res = TSqlSrvConfigParams::EEncUtf8;
1.216 + }
1.217 + else
1.218 + {
1.219 + TEST2(0, 1);
1.220 + }
1.221 + }
1.222 + break;
1.223 + default:
1.224 + TEST2(0, 1);
1.225 + break;
1.226 + }
1.227 + return res;
1.228 + }
1.229 +
1.230 +TInt GetConfigParamValue(RSqlDatabase& aDb, TConfigParamType aPrmType)
1.231 + {
1.232 + TInt res = 0;
1.233 + TRAPD(err, res = DoGetConfigParamValueL(aDb, aPrmType));
1.234 + TEST2(err, KErrNone);
1.235 + return res;
1.236 + }
1.237 +
1.238 +void AssertConfigPrmValues(RSqlDatabase& aDb, TInt aExpectedCacheSize, TInt aExpectedPageSize, TInt aExpectedDbEncoding)
1.239 + {
1.240 + TInt cacheSize = GetConfigParamValue(aDb, EPrmCacheSize);
1.241 + TInt pageSize = GetConfigParamValue(aDb, EPrmPageSize);
1.242 + TInt dbEncoding = GetConfigParamValue(aDb, EPrmDbEncoding);
1.243 + TEST2(cacheSize, aExpectedCacheSize);
1.244 + TEST2(pageSize, aExpectedPageSize);
1.245 + TEST2(dbEncoding, aExpectedDbEncoding);
1.246 + }
1.247 +
1.248 +///////////////////////////////////////////////////////////////////////////////////////
1.249 +// Config file replacement functions
1.250 +
1.251 +// File config strings are 16-bit.
1.252 +void ReplaceConfigFile(const TDesC16& aConfig)
1.253 + {
1.254 + (void)KillProcess(KSqlSrvName);
1.255 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.256 + RFile file;
1.257 + TInt err = file.Create(TheFs, KSqlSrvConfigFile, EFileRead | EFileWrite);
1.258 + TEST2(err, KErrNone);
1.259 + TPtrC8 p((const TUint8*)aConfig.Ptr(), aConfig.Length() * sizeof(TUint16));
1.260 + err = file.Write(p);
1.261 + file.Close();
1.262 + TEST2(err, KErrNone);
1.263 + }
1.264 +
1.265 +///////////////////////////////////////////////////////////////////////////////////////
1.266 +//
1.267 +
1.268 +/**
1.269 +@SYMTestCaseID SYSLIB-SQL-UT-3603
1.270 +@SYMTestCaseDesc Bad config file test
1.271 + The test creates bad config files like:
1.272 + - empty config file;
1.273 + - "\n" config file;
1.274 + - "\r\n" config file;
1.275 + - config file with comment lines only;
1.276 + Then the test restarts the SQL server and checks that the bad config file is detected and
1.277 + appropriate error code - returned to the caller (during "database create" operation).
1.278 +@SYMTestPriority High
1.279 +@SYMTestActions Bad config file test
1.280 +@SYMTestExpectedResults The test must not fail
1.281 +@SYMREQ REQ8162
1.282 +*/
1.283 +void BadCfgFileTest()
1.284 + {
1.285 + //Empty config file
1.286 + ReplaceConfigFile(_L(""));
1.287 + TInt err = TheDb.Create(KTestDbName);
1.288 + TEST2(err, KErrEof);//BC kept - an empty config file is treated as invalid
1.289 + TheDb.Close();
1.290 + (void)RSqlDatabase::Delete(KTestDbName);
1.291 + //"\n" config file
1.292 + ReplaceConfigFile(_L("\n"));
1.293 + err = TheDb.Create(KTestDbName);
1.294 + TEST2(err, KErrEof);//BC compatible
1.295 + TheDb.Close();
1.296 + (void)RSqlDatabase::Delete(KTestDbName);
1.297 + //"\r\n" config file
1.298 + ReplaceConfigFile(_L("\r\n"));
1.299 + err = TheDb.Create(KTestDbName);
1.300 + TEST2(err, KErrEof);//BC compatible
1.301 + TheDb.Close();
1.302 + (void)RSqlDatabase::Delete(KTestDbName);
1.303 + //" \r\n" config file
1.304 + ReplaceConfigFile(_L(" \r\n"));
1.305 + err = TheDb.Create(KTestDbName);
1.306 + TEST2(err, KErrEof);//BC compatible
1.307 + TheDb.Close();
1.308 + (void)RSqlDatabase::Delete(KTestDbName);
1.309 + //" # \r\n" config file
1.310 + ReplaceConfigFile(_L(" # \r\n"));
1.311 + err = TheDb.Create(KTestDbName);
1.312 + TEST2(err, KErrEof);//BC compatible
1.313 + TheDb.Close();
1.314 + (void)RSqlDatabase::Delete(KTestDbName);
1.315 + //" # \r\na=b\r\n" config file
1.316 + ReplaceConfigFile(_L(" # \r\na=b\r\n"));
1.317 + err = TheDb.Create(KTestDbName);
1.318 + TEST2(err, KErrNone);
1.319 + AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
1.320 + TheDb.Close();
1.321 + (void)RSqlDatabase::Delete(KTestDbName);
1.322 + //" # \r\n a=b \r\n" config file
1.323 + ReplaceConfigFile(_L(" # \r\n a=b \r\n"));
1.324 + err = TheDb.Create(KTestDbName);
1.325 + TEST2(err, KErrNone);
1.326 + AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
1.327 + TheDb.Close();
1.328 + (void)RSqlDatabase::Delete(KTestDbName);
1.329 + //" # \r\n a=b " config file
1.330 + ReplaceConfigFile(_L(" # \r\n a=b "));
1.331 + err = TheDb.Create(KTestDbName);
1.332 + TEST2(err, KErrNone);
1.333 + AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
1.334 + TheDb.Close();
1.335 + (void)RSqlDatabase::Delete(KTestDbName);
1.336 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.337 + }
1.338 +
1.339 +/**
1.340 +@SYMTestCaseID SYSLIB-SQL-UT-3604
1.341 +@SYMTestCaseDesc Config file with bad parameters test
1.342 + The test creates config files with bad parameters like:
1.343 + - negative cache size;
1.344 + - non-numeric cache size value;
1.345 + - empty cache size value;
1.346 + - negative page size;
1.347 + - non-numeric page size value;
1.348 + - empty page size value;
1.349 + - negative soft heap limit size;
1.350 + - non-numeric soft heap limit value;
1.351 + - empty soft heap limit value;
1.352 + - too small soft heap limit value;
1.353 + - too big soft heap limit value;
1.354 + - negative free page threshold value;
1.355 + - empty free page threshold value;
1.356 + - non-numeric free page threshold value;
1.357 + Then the test restarts the SQL server and checks that the bad config file is detected and
1.358 + appropriate error code - returned to the caller (during "database create" operation).
1.359 +@SYMTestPriority High
1.360 +@SYMTestActions Config file with bad parameters test
1.361 +@SYMTestExpectedResults The test must not fail
1.362 +@SYMREQ REQ8162
1.363 + REQ10271
1.364 +*/
1.365 +void BadCfgFileParametersTest()
1.366 + {
1.367 + /////////////// cache_size ////////////////
1.368 + //"cache_size=-20;" config file
1.369 + ReplaceConfigFile(_L("cache_size=-20;"));
1.370 + TInt err = TheDb.Create(KTestDbName);
1.371 + TEST2(err, KErrArgument);
1.372 + TheDb.Close();
1.373 + (void)RSqlDatabase::Delete(KTestDbName);
1.374 + //"cache_size=456.90" config file
1.375 + ReplaceConfigFile(_L("cache_size=456.90"));
1.376 + err = TheDb.Create(KTestDbName);
1.377 + TEST2(err, KErrNone);
1.378 + TheDb.Close();
1.379 + (void)RSqlDatabase::Delete(KTestDbName);
1.380 + //"cache_size='dfjkhdfjk';" config file
1.381 + ReplaceConfigFile(_L("cache_size='dfjkhdfjk';"));
1.382 + err = TheDb.Create(KTestDbName);
1.383 + TEST2(err, KErrArgument);
1.384 + TheDb.Close();
1.385 + (void)RSqlDatabase::Delete(KTestDbName);
1.386 + //"cache_size=;" config file
1.387 + ReplaceConfigFile(_L("cache_size=;"));
1.388 + err = TheDb.Create(KTestDbName);
1.389 + TEST2(err, KErrArgument);
1.390 + TheDb.Close();
1.391 + (void)RSqlDatabase::Delete(KTestDbName);
1.392 + /////////////// page_size ////////////////
1.393 + //"page_size=-55" config file
1.394 + ReplaceConfigFile(_L("page_size=-55"));
1.395 + err = TheDb.Create(KTestDbName);
1.396 + TEST2(err, KErrArgument);
1.397 + TheDb.Close();
1.398 + (void)RSqlDatabase::Delete(KTestDbName);
1.399 + //"page_size=25.89" config file
1.400 + ReplaceConfigFile(_L("page_size=25.89"));
1.401 + err = TheDb.Create(KTestDbName);
1.402 + TEST2(err, KErrNone);//BC compatible
1.403 + TheDb.Close();
1.404 + (void)RSqlDatabase::Delete(KTestDbName);
1.405 + //"page_size=gffgrtj" config file
1.406 + ReplaceConfigFile(_L("page_size=gffgrtj"));
1.407 + err = TheDb.Create(KTestDbName);
1.408 + TEST2(err, KErrArgument);
1.409 + TheDb.Close();
1.410 + (void)RSqlDatabase::Delete(KTestDbName);
1.411 + //"page_size=" config file
1.412 + ReplaceConfigFile(_L("page_size="));
1.413 + err = TheDb.Create(KTestDbName);
1.414 + TEST2(err, KErrArgument);
1.415 + TheDb.Close();
1.416 + (void)RSqlDatabase::Delete(KTestDbName);
1.417 + //////// soft_heap_limit_kb ///////////
1.418 + //"soft_heap_limit_kb=-10" config file
1.419 + ReplaceConfigFile(_L("soft_heap_limit_kb=-10"));
1.420 + err = TheDb.Create(KTestDbName);
1.421 + TEST2(err, KErrArgument);
1.422 + TheDb.Close();
1.423 + (void)RSqlDatabase::Delete(KTestDbName);
1.424 + //"soft_heap_limit_kb=5" config file (bellow min limit - 8Kb when SYSLIBS_TEST macro is defined)
1.425 + ReplaceConfigFile(_L("soft_heap_limit_kb=5"));
1.426 + err = TheDb.Create(KTestDbName);
1.427 + TEST2(err, KErrArgument);
1.428 + TheDb.Close();
1.429 + (void)RSqlDatabase::Delete(KTestDbName);
1.430 + //"soft_heap_limit_kb=8" config file (the min limit - 8Kb when SYSLIBS_TEST macro is defined)
1.431 + ReplaceConfigFile(_L("soft_heap_limit_kb=8"));
1.432 + err = TheDb.Create(KTestDbName);
1.433 + TEST2(err, KErrNone);
1.434 + TheDb.Close();
1.435 + (void)RSqlDatabase::Delete(KTestDbName);
1.436 + //"soft_heap_limit_kb=2000000000" config file (above max limit)
1.437 + ReplaceConfigFile(_L("soft_heap_limit_kb=2000000000"));
1.438 + err = TheDb.Create(KTestDbName);
1.439 + TEST2(err, KErrArgument);
1.440 + TheDb.Close();
1.441 + (void)RSqlDatabase::Delete(KTestDbName);
1.442 + //"soft_heap_limit_kb=KMaxTInt/1024" config file (the max limit)
1.443 + TBuf<32> configBuf;
1.444 + configBuf.Copy(_L("soft_heap_limit_kb="));
1.445 + TInt maxSoftHeapLimit = KMaxTInt / 1024;
1.446 + configBuf.AppendNum(maxSoftHeapLimit);
1.447 + ReplaceConfigFile(configBuf);
1.448 + err = TheDb.Create(KTestDbName);
1.449 + TEST2(err, KErrNone);
1.450 + TheDb.Close();
1.451 + (void)RSqlDatabase::Delete(KTestDbName);
1.452 + //"soft_heap_limit_kb=sdfcvyua" config file
1.453 + ReplaceConfigFile(_L("soft_heap_limit_kb=sdfcvyua"));
1.454 + err = TheDb.Create(KTestDbName);
1.455 + TEST2(err, KErrArgument);
1.456 + TheDb.Close();
1.457 + (void)RSqlDatabase::Delete(KTestDbName);
1.458 + //"soft_heap_limit_kb=" config file
1.459 + ReplaceConfigFile(_L("soft_heap_limit_kb="));
1.460 + err = TheDb.Create(KTestDbName);
1.461 + TEST2(err, KErrArgument);
1.462 + TheDb.Close();
1.463 + (void)RSqlDatabase::Delete(KTestDbName);
1.464 + //"soft_heap_limit_kb=1023.456" config file
1.465 + ReplaceConfigFile(_L("soft_heap_limit_kb=1023.456"));
1.466 + err = TheDb.Create(KTestDbName);
1.467 + TEST2(err, KErrNone);
1.468 + TheDb.Close();
1.469 + (void)RSqlDatabase::Delete(KTestDbName);
1.470 + //////// free_space_threshold_kb ///////////
1.471 + //"free_space_threshold_kb=-10" config file
1.472 + ReplaceConfigFile(_L("free_space_threshold_kb=-10"));
1.473 + err = TheDb.Create(KTestDbName);
1.474 + TEST2(err, KErrArgument);
1.475 + TheDb.Close();
1.476 + (void)RSqlDatabase::Delete(KTestDbName);
1.477 + //"free_space_threshold_kb=0" config file
1.478 + ReplaceConfigFile(_L("free_space_threshold_kb=0"));
1.479 + err = TheDb.Create(KTestDbName);
1.480 + TEST2(err, KErrNone);
1.481 + TheDb.Close();
1.482 + (void)RSqlDatabase::Delete(KTestDbName);
1.483 + //"free_space_threshold_kb=" config file
1.484 + ReplaceConfigFile(_L("free_space_threshold_kb="));
1.485 + err = TheDb.Create(KTestDbName);
1.486 + TEST2(err, KErrArgument);
1.487 + TheDb.Close();
1.488 + (void)RSqlDatabase::Delete(KTestDbName);
1.489 + //"free_space_threshold_kb=34.56" config file
1.490 + ReplaceConfigFile(_L("free_space_threshold_kb=34.56"));
1.491 + err = TheDb.Create(KTestDbName);
1.492 + TEST2(err, KErrNone);
1.493 + TheDb.Close();
1.494 + (void)RSqlDatabase::Delete(KTestDbName);
1.495 + //"free_space_threshold_kb=gfghfg" config file
1.496 + ReplaceConfigFile(_L("free_space_threshold_kb=gfghfg"));
1.497 + err = TheDb.Create(KTestDbName);
1.498 + TEST2(err, KErrArgument);
1.499 + TheDb.Close();
1.500 + (void)RSqlDatabase::Delete(KTestDbName);
1.501 + /////////////////////////////////////////////
1.502 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.503 + }
1.504 +
1.505 +/**
1.506 +@SYMTestCaseID SYSLIB-SQL-UT-3605
1.507 +@SYMTestCaseDesc Config parameters conflict test.
1.508 + 1) The test creates a database with cache size parameter value specified in both the config file and the
1.509 + config string. The expectation is that the config string parameter will be used.
1.510 + 2) The test creates a database with page size parameter value specified in both the config file and the
1.511 + config string. The expectation is that the config string parameter will be used.
1.512 + 3) The test creates a database with encoding parameter value specified in both the config file and the
1.513 + config string. The expectation is that the config string parameter will be used.
1.514 + 4) The test creates a database with soft heap limit value specified in both the config file and the
1.515 + config string. The expectation is that the database creation will fail (the soft heap limit
1.516 + cannot be configured using a config string).
1.517 + 5) The test creates a database with free page threshold value specified in both the config file and the
1.518 + config string. The expectation is that the database creation will succeeds. The free page threshold
1.519 + value from the config file will be used.
1.520 +@SYMTestPriority High
1.521 +@SYMTestActions Config parameters conflict test
1.522 +@SYMTestExpectedResults The test must not fail
1.523 +@SYMREQ REQ8162
1.524 + REQ10271
1.525 +*/
1.526 +void CfgFileConflictTest()
1.527 + {
1.528 + //"cache_size=200" config file
1.529 + //"cache_size=100" client config string
1.530 + ReplaceConfigFile(_L("cache_size=200"));
1.531 + _LIT8(KConfigStr1, "cache_size=100");
1.532 + TInt err = TheDb.Create(KTestDbName, &KConfigStr1);
1.533 + TEST2(err, KErrNone);
1.534 + AssertConfigPrmValues(TheDb, 100, KDefaultPageSize, KDefaultEncoding);
1.535 + TheDb.Close();
1.536 + (void)RSqlDatabase::Delete(KTestDbName);
1.537 + //"page_size=512" config file
1.538 + //"page_size=8192" client config string
1.539 + ReplaceConfigFile(_L("page_size=512"));
1.540 + _LIT8(KConfigStr2, "page_size=8192");
1.541 + err = TheDb.Create(KTestDbName, &KConfigStr2);
1.542 + TEST2(err, KErrNone);
1.543 + AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 8192, 8192, KDefaultEncoding);
1.544 + TheDb.Close();
1.545 + (void)RSqlDatabase::Delete(KTestDbName);
1.546 + //"encoding=UTF-16" config file
1.547 + //"encoding=UTF-8" client config string
1.548 + ReplaceConfigFile(_L("encoding=UTF-16"));
1.549 + _LIT8(KConfigStr3, "encoding=UTF-8");
1.550 + err = TheDb.Create(KTestDbName, &KConfigStr3);
1.551 + TEST2(err, KErrNone);
1.552 + AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, TSqlSrvConfigParams::EEncUtf8);
1.553 + TheDb.Close();
1.554 + (void)RSqlDatabase::Delete(KTestDbName);
1.555 + //"soft_heap_limit_kb=900" config file
1.556 + //"soft_heap_limit_kb=800" client config string
1.557 + ReplaceConfigFile(_L("soft_heap_limit_kb=900"));
1.558 + _LIT8(KConfigStr4, "soft_heap_limit_kb=800");
1.559 + err = TheDb.Create(KTestDbName, &KConfigStr4);
1.560 + TEST2(err, KErrArgument);
1.561 + TheDb.Close();
1.562 + (void)RSqlDatabase::Delete(KTestDbName);
1.563 + //"free_space_threshold_kb=100" config file
1.564 + //"free_space_threshold_kb=200" client config string
1.565 + ReplaceConfigFile(_L("free_space_threshold_kb=100"));
1.566 + _LIT8(KConfigStr5, "free_space_threshold_kb=200");
1.567 + err = TheDb.Create(KTestDbName, &KConfigStr5);
1.568 + TEST2(err, KErrArgument);
1.569 + TheDb.Close();
1.570 + (void)RSqlDatabase::Delete(KTestDbName);
1.571 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.572 + }
1.573 +
1.574 +/**
1.575 +@SYMTestCaseID SYSLIB-SQL-UT-3606
1.576 +@SYMTestCaseDesc Soft Heap Limit - functional test.
1.577 + The test attempts to create a database with the soft heap limit value specified in the config file
1.578 + and different combinations of the page size and cache size parameters in both config file and client
1.579 + config string. The expectation is that when the cache size parameter value is not specified explicitly
1.580 + in the config file or in the config string, the cache size value will be calculated, using the soft
1.581 + heap limit and the database page size.
1.582 +@SYMTestPriority High
1.583 +@SYMTestActions Soft Heap Limit - functional test.
1.584 +@SYMTestExpectedResults The test must not fail
1.585 +@SYMREQ REQ8162
1.586 +*/
1.587 +void SoftHeapLimitFunctionalTest1()
1.588 + {
1.589 + ///////////////////// CREATE DATABASE /////////////////////////////////////////////////////////
1.590 + //"soft_heap_limit_kb=512" config file. (512 is the min soft heap limit value)
1.591 + //Expected result: the database cache size will be (512 * 1024)/page_size;
1.592 + ReplaceConfigFile(_L("soft_heap_limit_kb=512"));
1.593 + TInt err = TheDb.Create(KTestDbName);
1.594 + TEST2(err, KErrNone);
1.595 + AssertConfigPrmValues(TheDb, (512 * 1024) / KDefaultPageSize, KDefaultPageSize, KDefaultEncoding);
1.596 + TheDb.Close();
1.597 + (void)RSqlDatabase::Delete(KTestDbName);
1.598 + //"soft_heap_limit_kb=KMaxTInt/1024" config file. (KMaxTInt / 1024 is the max soft heap limit value)
1.599 + //Expected result: the database cache size will be KMaxTInt/page_size;
1.600 + TBuf<32> configBuf;
1.601 + configBuf.Copy(_L("soft_heap_limit_kb="));
1.602 + TInt maxSoftHeapLimit = KMaxTInt / 1024;
1.603 + configBuf.AppendNum(maxSoftHeapLimit);
1.604 + ReplaceConfigFile(configBuf);
1.605 + err = TheDb.Create(KTestDbName);
1.606 + TEST2(err, KErrNone);
1.607 + AssertConfigPrmValues(TheDb, KMaxTInt / KDefaultPageSize, KDefaultPageSize, KDefaultEncoding);
1.608 + TheDb.Close();
1.609 + (void)RSqlDatabase::Delete(KTestDbName);
1.610 + //"soft_heap_limit_kb=512;page_size=2048" config file.
1.611 + //Expected result: the database cache size will be (512 * 1024)/2048. The page size value from the config file is used.
1.612 + ReplaceConfigFile(_L("soft_heap_limit_kb=512;page_size=2048"));
1.613 + err = TheDb.Create(KTestDbName);
1.614 + TEST2(err, KErrNone);
1.615 + AssertConfigPrmValues(TheDb, (512 * 1024) / 2048, 2048, KDefaultEncoding);
1.616 + TheDb.Close();
1.617 + (void)RSqlDatabase::Delete(KTestDbName);
1.618 + //"soft_heap_limit_kb=512" config file.
1.619 + //"page_size=4096" client config string.
1.620 + //Expected result: the database cache size will be (512 * 1024)/4096. The page size value from the client config string is used.
1.621 + ReplaceConfigFile(_L("soft_heap_limit_kb=512;"));
1.622 + _LIT8(KConfigStr1, "page_size=4096");
1.623 + err = TheDb.Create(KTestDbName, &KConfigStr1);
1.624 + TEST2(err, KErrNone);
1.625 + AssertConfigPrmValues(TheDb, (512 * 1024) / 4096, 4096, KDefaultEncoding);
1.626 + TheDb.Close();
1.627 + (void)RSqlDatabase::Delete(KTestDbName);
1.628 + //"soft_heap_limit_kb=512;page_size=8192" config file.
1.629 + //"page_size=2048" client config string.
1.630 + //Expected result: the database cache size will be (512 * 1024)/2048. The page size value from the client config string is used.
1.631 + ReplaceConfigFile(_L("soft_heap_limit_kb=512;page_size=8192"));
1.632 + _LIT8(KConfigStr2, "page_size=2048");
1.633 + err = TheDb.Create(KTestDbName, &KConfigStr2);
1.634 + TEST2(err, KErrNone);
1.635 + AssertConfigPrmValues(TheDb, (512 * 1024) / 2048, 2048, KDefaultEncoding);
1.636 + TheDb.Close();
1.637 + (void)RSqlDatabase::Delete(KTestDbName);
1.638 + //"soft_heap_limit_kb=512;page_size=2048;encoding=UTF-8" config file.
1.639 + //"cache_size=100" client config string.
1.640 + //Expected result: the database cache size will be 100. The soft heap limit is not used for the cache size calculation.
1.641 + ReplaceConfigFile(_L("soft_heap_limit_kb=512;page_size=2048;encoding=UTF-8"));
1.642 + _LIT8(KConfigStr3, "cache_size=100");
1.643 + err = TheDb.Create(KTestDbName, &KConfigStr3);
1.644 + TEST2(err, KErrNone);
1.645 + AssertConfigPrmValues(TheDb, 100, 2048, TSqlSrvConfigParams::EEncUtf8);
1.646 + TheDb.Close();
1.647 + (void)RSqlDatabase::Delete(KTestDbName);
1.648 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.649 + }
1.650 +
1.651 +/**
1.652 +@SYMTestCaseID SYSLIB-SQL-UT-3607
1.653 +@SYMTestCaseDesc Soft Heap Limit - functional test.
1.654 + The test attempts to open a database with the soft heap limit value specified in the config file
1.655 + and different combinations of the page size and cache size parameters in both config file and client
1.656 + config string. The expectation is that when the cache size parameter value is not specified explicitly
1.657 + in the config file or in the config string, the cache size value will be calculated, using the soft
1.658 + heap limit and the database page size (read from the database, not from the config file or string).
1.659 +@SYMTestPriority High
1.660 +@SYMTestActions Soft Heap Limit - functional test.
1.661 +@SYMTestExpectedResults The test must not fail
1.662 +@SYMREQ REQ8162
1.663 +*/
1.664 +void SoftHeapLimitFunctionalTest2()
1.665 + {
1.666 + ///////////////////// OPEN DATABASE /////////////////////////////////////////////////////////
1.667 + //"soft_heap_limit_kb=512;page_size=2048" config file.
1.668 + //Expected result: the database cache size will be (512 * 1024)/2048. The database page size value is used (not the built-time one).
1.669 + ReplaceConfigFile(_L("soft_heap_limit_kb=512;page_size=2048"));
1.670 + TInt err = TheDb.Create(KTestDbName);
1.671 + TEST2(err, KErrNone);
1.672 + AssertConfigPrmValues(TheDb, (512 * 1024) / 2048, 2048, KDefaultEncoding);
1.673 + TheDb.Close();
1.674 + ReplaceConfigFile(_L("soft_heap_limit_kb=1024;page_size=8192"));
1.675 + err = TheDb.Open(KTestDbName);
1.676 + TEST2(err, KErrNone);
1.677 + AssertConfigPrmValues(TheDb, (1024 * 1024) / 2048, 2048, KDefaultEncoding);
1.678 + TheDb.Close();
1.679 + (void)RSqlDatabase::Delete(KTestDbName);
1.680 + //"soft_heap_limit_kb=512" config file.
1.681 + //"page_size=4096" client config string.
1.682 + //Expected result: the database cache size will be (512 * 1024)/4096. The database page size value is used (not the built-time one).
1.683 + ReplaceConfigFile(_L("soft_heap_limit_kb=512"));
1.684 + _LIT8(KConfigStr1, "page_size=4096");
1.685 + err = TheDb.Create(KTestDbName, &KConfigStr1);
1.686 + TEST2(err, KErrNone);
1.687 + AssertConfigPrmValues(TheDb, (512 * 1024) / 4096, 4096, KDefaultEncoding);
1.688 + TheDb.Close();
1.689 + ReplaceConfigFile(_L("soft_heap_limit_kb=1024;page_size=8192"));
1.690 + err = TheDb.Open(KTestDbName);
1.691 + TEST2(err, KErrNone);
1.692 + AssertConfigPrmValues(TheDb, (1024 * 1024) / 4096, 4096, KDefaultEncoding);
1.693 + TheDb.Close();
1.694 + (void)RSqlDatabase::Delete(KTestDbName);
1.695 + //"soft_heap_limit_kb=512" config file.
1.696 + //"page_size=4096" client config string when openning the database.
1.697 + //Expected result: the database cache size will be 512. The database page size value is used (the built-time one).
1.698 + ReplaceConfigFile(_L("soft_heap_limit_kb=512"));
1.699 + err = TheDb.Create(KTestDbName);
1.700 + TEST2(err, KErrNone);
1.701 + AssertConfigPrmValues(TheDb, 512, KDefaultPageSize, KDefaultEncoding);
1.702 + TheDb.Close();
1.703 + ReplaceConfigFile(_L("soft_heap_limit_kb=1024;page_size=512"));
1.704 + _LIT8(KConfigStr2, "page_size=4096");
1.705 + err = TheDb.Open(KTestDbName, &KConfigStr2);
1.706 + TEST2(err, KErrNone);
1.707 + AssertConfigPrmValues(TheDb, 1024, KDefaultPageSize, KDefaultEncoding);
1.708 + TheDb.Close();
1.709 + (void)RSqlDatabase::Delete(KTestDbName);
1.710 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.711 + }
1.712 +
1.713 +/**
1.714 +@SYMTestCaseID SYSLIB-SQL-UT-3608
1.715 +@SYMTestCaseDesc Soft Heap Limit - file I/O failure simulation test.
1.716 + The test creates a database with very small soft heap limit value (8Kb).
1.717 + Then the test attempts to insert a record in an explicit transaction while doing
1.718 + file I/O failure simulation.
1.719 +@SYMTestPriority High
1.720 +@SYMTestActions Soft Heap Limit - file I/O failure simulation test.
1.721 +@SYMTestExpectedResults The test must not fail
1.722 +@SYMREQ REQ8162
1.723 + REQ10271
1.724 +*/
1.725 +void FileIOFailureTest()
1.726 + {
1.727 + (void)RSqlDatabase::Delete(KTestDbName);
1.728 + ReplaceConfigFile(_L("soft_heap_limit_kb=8;cache_size=16;page_size=512;free_space_threshold_kb=100"));
1.729 + TInt err = TheDb.Create(KTestDbName);
1.730 + TEST2(err, KErrNone);
1.731 + err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER,Name TEXT)"));
1.732 + TEST(err >= 0);
1.733 + TheDb.Close();
1.734 + err = -1;
1.735 + const TInt KTestRecCnt = 100;
1.736 + for(TInt cnt=0;err<KErrNone;++cnt)
1.737 + {
1.738 + TheTest.Printf(_L("%d \r"), cnt);
1.739 + err = TheDb.Open(KTestDbName);
1.740 + TEST2(err, KErrNone);
1.741 + TInt recCntBegin = 0;
1.742 + TSqlScalarFullSelectQuery q1(TheDb);
1.743 + TRAP(err, recCntBegin = q1.SelectIntL(_L("SELECT COUNT (*) FROM A")));
1.744 + TEST2(err, KErrNone);
1.745 + (void)TheFs.SetErrorCondition(KErrGeneral, cnt);
1.746 + err = TheDb.Exec(_L("BEGIN TRANSACTION"));
1.747 + if(err == KErrNone)
1.748 + {
1.749 + for(TInt i=0;i<KTestRecCnt;++i)
1.750 + {
1.751 + TBuf<300> sql;
1.752 + sql.Format(_L("INSERT INTO A(Id,Name) VALUES(%d, 'A1234567890B1234567890C1234567890D1234567890E1234567890F1234567890G1234567890H1234567890I1234567890J1234567890K1234567890L1234567890M1234567890N1234567890O1234567890P1234567890Q1234567890R1234567890')"), cnt);
1.753 + err = TheDb.Exec(sql);
1.754 + TEST(err == 1 || err < 0);
1.755 + if(err < 0)
1.756 + {
1.757 + break;
1.758 + }
1.759 + }
1.760 + if(err == 1)
1.761 + {
1.762 + err = TheDb.Exec(_L("COMMIT TRANSACTION"));
1.763 + }
1.764 + else if(TheDb.InTransaction()) //the transaction may have been rolled back automatically
1.765 + {
1.766 + err = TheDb.Exec(_L("ROLLBACK TRANSACTION"));
1.767 + }
1.768 + if(err == 0)
1.769 + {
1.770 + err = 1;
1.771 + }
1.772 + }
1.773 + (void)TheFs.SetErrorCondition(KErrNone);
1.774 + if(err < 1)
1.775 + {
1.776 + TheDb.Close();//close the database to recover from the last error
1.777 + TInt err2 = TheDb.Open(KTestDbName);
1.778 + TEST2(err2, KErrNone);
1.779 + }
1.780 + TSqlScalarFullSelectQuery q2(TheDb);
1.781 + TInt recCntEnd = 0;
1.782 + TRAPD(err3, recCntEnd = q2.SelectIntL(_L("SELECT COUNT (*) FROM A")));
1.783 + TheDb.Close();
1.784 + TEST2(err3, KErrNone);
1.785 + //check the database content - all bets are off in a case of an I/O error.
1.786 + //The new records may have actually been inserted.
1.787 + TEST(recCntEnd == recCntBegin || recCntEnd == (recCntBegin + KTestRecCnt));
1.788 + }
1.789 + (void)TheFs.SetErrorCondition(KErrNone);
1.790 + (void)RSqlDatabase::Delete(KTestDbName);
1.791 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.792 + }
1.793 +
1.794 +/**
1.795 +@SYMTestCaseID SYSLIB-SQL-UT-3609
1.796 +@SYMTestCaseDesc Soft Heap Limit - OOM test.
1.797 + The test creates a database with very small soft heap limit value (8Kb).
1.798 + The the test attempts to insert a record in an explicit transaction while doing
1.799 + OOM simulation.
1.800 +@SYMTestPriority High
1.801 +@SYMTestActions Soft Heap Limit - OOM test.
1.802 +@SYMTestExpectedResults The test must not fail
1.803 +@SYMREQ REQ8162
1.804 + REQ10271
1.805 +*/
1.806 +void OOMtest()
1.807 + {
1.808 + (void)RSqlDatabase::Delete(KTestDbName);
1.809 + ReplaceConfigFile(_L("soft_heap_limit_kb=8;cache_size=16;page_size=512;free_space_threshold_kb=150"));
1.810 + TInt err = TheDb.Create(KTestDbName);
1.811 + TEST2(err, KErrNone);
1.812 + err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER,Name TEXT)"));
1.813 + TEST(err >= 0);
1.814 + TheDb.Close();
1.815 +
1.816 + const TInt KOomIterationCount = 1000;//Instead fo doing the OOM test while "err == KErrNoMemory", the test is
1.817 + //performed KOomIterationCount times, because the "soft heap limit" will
1.818 + //force the SQLite library to reuse some of the already allocated but not used pages.
1.819 + TInt failingAllocationNo = 0;
1.820 + while(failingAllocationNo < KOomIterationCount)
1.821 + {
1.822 + __UHEAP_MARK;
1.823 +
1.824 + const TInt KDelayedDbHeapFailureMask = 0x1000;
1.825 + TSqlResourceTester::SetDbHeapFailure(RHeap::EFailNext | KDelayedDbHeapFailureMask, ++failingAllocationNo);
1.826 +
1.827 + err = TheDb.Open(KTestDbName);
1.828 + TEST2(err, KErrNone);
1.829 +
1.830 + err = TheDb.Exec(_L("BEGIN TRANSACTION"));
1.831 + if(err == KErrNone)
1.832 + {
1.833 + const TInt KTestRecCnt = 4;
1.834 + for(TInt i=0;i<KTestRecCnt;++i)
1.835 + {
1.836 + err = TheDb.Exec(_L("INSERT INTO A(Id,Name) VALUES(1, 'A1234567890B1234567890C1234567890D1234567890E1234567890F1234567890G1234567890H1234567890I1234567890J1234567890K1234567890L1234567890M1234567890N1234567890O1234567890P1234567890Q1234567890R1234567890')"));
1.837 + if(err < 1)
1.838 + {
1.839 + break;
1.840 + }
1.841 + }
1.842 + if(err == 1)
1.843 + {
1.844 + err = TheDb.Exec(_L("COMMIT TRANSACTION"));
1.845 + }
1.846 + else if(TheDb.InTransaction()) //the transaction may have been rolled back automatically
1.847 + {
1.848 + err = TheDb.Exec(_L("ROLLBACK TRANSACTION"));
1.849 + }
1.850 + }
1.851 +
1.852 + TSqlResourceTester::SetDbHeapFailure(RHeap::ENone, 0);
1.853 +
1.854 + TheDb.Close();
1.855 +
1.856 + TheTest.Printf(_L("%d/%d \r"), failingAllocationNo, err);
1.857 +
1.858 + __UHEAP_MARKEND;
1.859 +
1.860 + TEST(err >= 0 || err == KErrNoMemory);
1.861 + }
1.862 + TEST(err >= 0);
1.863 + (void)RSqlDatabase::Delete(KTestDbName);
1.864 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.865 + }
1.866 +
1.867 +/**
1.868 +@SYMTestCaseID SYSLIB-SQL-UT-4081
1.869 +@SYMTestCaseDesc Background compaction, free page threshold - functional test.
1.870 + The test creates a server config file, where the free page threshold is set to be 20 Kb.
1.871 + Then the test creates a database. The test inserts 40 pages (40 Kb) into the database, closes and
1.872 + reopens the database. Then the test deletes some records from the database.
1.873 + But the space in the free pages is not big enough to kick-off the background compaction.
1.874 + The test checks that no compaction has occurred after the deletions.
1.875 + The test deletes more records and the free page threshold is reached.
1.876 + The test checks that after the last deletion the database really has been compacted.
1.877 +@SYMTestPriority Medium
1.878 +@SYMTestActions Background compaction, free page threshold - functional test.
1.879 +@SYMTestExpectedResults Test must not fail
1.880 +@SYMREQ REQ10271
1.881 +*/
1.882 +void FreePageThresholdTest()
1.883 + {
1.884 + const TInt KFreePageThresholdSrvCfgKb = 20;
1.885 + TBuf<50> cfgBuf1;
1.886 + cfgBuf1.Format(_L("free_space_threshold_kb=%d"), KFreePageThresholdSrvCfgKb);
1.887 + ReplaceConfigFile(cfgBuf1);
1.888 +
1.889 + const TInt KPageSize = 1024;
1.890 + TBuf8<50> cfgBuf2;
1.891 + cfgBuf2.Format(_L8("page_size=%d;"), KPageSize);
1.892 + //Create a database and insert some records. At the end the database size is bigger than the free pages threshold.
1.893 + (void)RSqlDatabase::Delete(KTestDbName);
1.894 + TInt err = TheDb.Create(KTestDbName, &cfgBuf2);
1.895 + TEST2(err, KErrNone);
1.896 + err = TheDb.Exec(_L("CREATE TABLE A(B BLOB)"));
1.897 + TEST2(err, 1);
1.898 + TBuf8<(KPageSize - 150) * 2> blob;
1.899 + blob.SetLength((KPageSize - 150) * 2);
1.900 + blob.Fill(TChar('A'));
1.901 + for(TInt i=0;i<KFreePageThresholdSrvCfgKb*2;++i)
1.902 + {
1.903 + TBuf8<KPageSize * 2> sql;
1.904 + sql.Format(_L8("INSERT INTO A VALUES(x'%S')"), &blob);
1.905 + err = TheDb.Exec(sql);
1.906 + TEST2(err, 1);
1.907 + }
1.908 + TheDb.Close();
1.909 + //Reopen the database and delete some records. The free spave is not big enough to kick-off the background compaction.
1.910 + err = TheDb.Open(KTestDbName);
1.911 + TEST2(err, KErrNone);
1.912 + for(TInt i=0;i<10;++i)
1.913 + {
1.914 + TBuf8<50> sql;
1.915 + sql.Format(_L8("DELETE FROM A WHERE ROWID=%d"), i + 1);
1.916 + err = TheDb.Exec(sql);
1.917 + TEST2(err, 1);
1.918 + }
1.919 + User::After(1000000);
1.920 + RSqlDatabase::TSize size;
1.921 + err = TheDb.Size(size);
1.922 + TEST2(err, KErrNone);
1.923 + TEST(size.iFree > 0);
1.924 + //Delete more records, the free page threshold is reached, the background compaction - kicked-off.
1.925 + for(TInt i=10;i<20;++i)
1.926 + {
1.927 + TBuf8<50> sql;
1.928 + sql.Format(_L8("DELETE FROM A WHERE ROWID=%d"), i + 1);
1.929 + err = TheDb.Exec(sql);
1.930 + TEST2(err, 1);
1.931 + }
1.932 + User::After(1000000);
1.933 + err = TheDb.Size(size);
1.934 + TEST2(err, KErrNone);
1.935 + TEST2(size.iFree, 0);
1.936 + //
1.937 + TheDb.Close();
1.938 + (void)RSqlDatabase::Delete(KTestDbName);
1.939 + (void)TheFs.Delete(KSqlSrvConfigFile);
1.940 + }
1.941 +
1.942 +/**
1.943 +@SYMTestCaseID SYSLIB-SQL-UT-4075
1.944 +@SYMTestCaseDesc Server configuration file, large string test.
1.945 + The test creates a server config file, where all parameters are used
1.946 + and checks the the parameter values are processed normally.
1.947 +@SYMTestPriority Medium
1.948 +@SYMTestActions Server configuration file, large string test.
1.949 +@SYMTestExpectedResults Test must not fail
1.950 +@SYMREQ REQ10271
1.951 +*/
1.952 +void LargeStringTest()
1.953 + {
1.954 + ReplaceConfigFile(_L("page_size=32768;cache_size=2048;encoding=UTF-16;soft_heap_limit_kb=2048;free_space_threshold_kb=100000000;compaction=background"));
1.955 + TInt err = TheDb.Create(KTestDbName);
1.956 + TEST2(err, KErrNone);
1.957 + AssertConfigPrmValues(TheDb, (2048 * 1024) / 32768, 32768, TSqlSrvConfigParams::EEncUtf16);
1.958 + TheDb.Close();
1.959 + (void)RSqlDatabase::Delete(KTestDbName);
1.960 + }
1.961 +
1.962 +void DoTests()
1.963 + {
1.964 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3603 Bad config file "));
1.965 + BadCfgFileTest();
1.966 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3604 Config file - bad parameters "));
1.967 + BadCfgFileParametersTest();
1.968 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3605 Config file - conflict test "));
1.969 + CfgFileConflictTest();
1.970 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3606 Soft heap limit - functional test (\"create database\") "));
1.971 + SoftHeapLimitFunctionalTest1();
1.972 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3607 Soft heap limit - functional test (\"open database\") "));
1.973 + SoftHeapLimitFunctionalTest2();
1.974 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3608 Soft heap limit - file I/O failure "));
1.975 + FileIOFailureTest();
1.976 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3609 Soft heap limit - OOM failure "));
1.977 + OOMtest();
1.978 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4081 SQL server configuration file + free page threshold - functional test "));
1.979 + FreePageThresholdTest();
1.980 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4075 SQL server configuration file + large string "));
1.981 + LargeStringTest();
1.982 + }
1.983 +
1.984 +#endif //SYSLIBS_TEST
1.985 +
1.986 +TInt E32Main()
1.987 + {
1.988 + TheTest.Title();
1.989 +
1.990 + CTrapCleanup* tc = CTrapCleanup::New();
1.991 + TheTest(tc != NULL);
1.992 +
1.993 + __UHEAP_MARK;
1.994 +
1.995 +#ifdef SYSLIBS_TEST
1.996 + TheTest.Start(_L("t_sqlconfigfile tests"));
1.997 +
1.998 + SetupTestEnv();
1.999 + DoTests();
1.1000 + DestroyTestEnv();
1.1001 +
1.1002 + TheTest.End();
1.1003 +#else
1.1004 + TheTest.Start(_L("This test works only if the whole SQL component is built with SYSLIBS_TEST macro defined!"));
1.1005 + TheTest.End();
1.1006 +#endif
1.1007 +
1.1008 + __UHEAP_MARKEND;
1.1009 +
1.1010 + TheTest.Close();
1.1011 +
1.1012 + delete tc;
1.1013 +
1.1014 + User::Heap().Check();
1.1015 + return KErrNone;
1.1016 + }