
// //////////////////////////////////////////////////////////////////////// 
//
// Configuration tests - try changing the values of the default encoding
// and cache_size and page_size. From an integration test we can't really
// detect an effect of the _size settings, though we can read them back
// with the 'pragma' syntax.
//
// First check the defaults. If these change it will confuse the other tests
// so we might as well detect that change and generate a failure ASAP...
[CheckDefaults]
// First open a zero length database to check the defaults.
NoOperation0=
Open1=Z:\TEF_SQL\TestData\ReadOnly.db
Function2=ScalarFullSelect
Method2=SelectTextL
Result2=UTF-16le
Use_Set2=0
Statement2=PRAGMA encoding;

Function3=ScalarFullSelect
Method3=SelectIntL
Result3=1024
Use_Set3=1
Statement3=PRAGMA page_size;

Function4=ScalarFullSelect
Method4=SelectIntL
Result4=DEFAULT_SOFT_HEAP_LIMIT
Use_Set4=1
Statement4=PRAGMA cache_size;
Close5=
EndBlock6=

// Check that gibberish in the configuration string prevents Create from
// working.
[CheckOverride1]
DefineConfig0=this is a load of old rubbish which should have no effect on settings
Delete1=C:\ConfigTest1.db
ExpectedError1=KErrNotFound
Create2=C:\ConfigTest1.db
ExpectedError2=KErrArgument
// The next line will PANIC the client because the Create will have failed due
// to the bad configuration line. That's ok, we're expecting it.
Exec3=Select * from SomeTable;
EndBlock4=

// Check that properly formatted configuration options work, but that
// page_size can't be changed for a pre-existing db, and a bad encoding
// has no effect. The cache_size is also not affected.
[CheckOverride2]
DefineConfig0=page_size=2048;cache_size=64;encoding=hatstand
// On a pre-existing database we can't change the page size, plus the
// bad encoding will have been ignored.
Open1=Z:\TEF_SQL\TestData\ReadOnly.db

// encoding will not have been changed from its default of utf-16
Function2=ScalarFullSelect
Method2=SelectTextL
Result2=UTF-16le
Use_Set2=1
Statement2=PRAGMA encoding;

// page_size will not have been changed from its default of 1024..
Function3=ScalarFullSelect
Method3=SelectIntL
Result3=1024
Use_Set3=1
Statement3=PRAGMA page_size;

// cache_size WILL NOT have changed.
Function4=ScalarFullSelect
Method4=SelectIntL
Result4=64
Use_Set4=1
Statement4=PRAGMA cache_size;

Close5=
EndBlock6=

// Try changing all three config items to legal values, and check them.
[CheckOverride3]
DefineConfig0=page_size=2048;cache_size=34;encoding=UTF-8
// On a new database we can change the page size and the encoding.
// Not the cache_size.
Delete1=C:\ConfigTest2.db
ExpectedError1=KErrNotFound

Create2=C:\ConfigTest2.db

// encoding will not have been changed from its default of utf-16
Function3=ScalarFullSelect
Method3=SelectTextL
Result3=UTF-8
Use_Set3=1
Statement3=PRAGMA encoding;

// page_size will have been changed from its default of 1024..
Function4=ScalarFullSelect
Method4=SelectIntL
Result4=2048
Use_Set4=1
Statement4=PRAGMA page_size;

// cache_size WILL have changed to 34..
Function5=ScalarFullSelect
Method5=SelectIntL
Result5=34
Use_Set5=1
Statement5=PRAGMA cache_size;

Close6=
Delete7=C:\ConfigTest2.db
EndBlock8=

// Try setting page_size to a non-power-of-two (no effect), stick in some
// properly formatted by useless extras (no effect) and attempt to set
// cache_size (works) and an unsupported encoding (doesn't work).
[CheckOverride4]
DefineConfig0=page_size=4095;x=y;i=j;cache_size=43;encoding=UTF-16be
// On a new database we can change the page size and the encoding.
// But page_size is supposed to be a power of 2.
Delete1=C:\ConfigTest3.db
ExpectedError1=KErrNotFound

Create2=C:\ConfigTest3.db

// encoding will not have been changed from its default of utf-16
Function3=ScalarFullSelect
Method3=SelectTextL
Result3=UTF-16le
Use_Set3=1
Statement3=PRAGMA encoding;

// page_size will not have been changed from its default of 1024..
Function4=ScalarFullSelect
Method4=SelectIntL
Result4=1024
Use_Set4=1
Statement4=PRAGMA page_size;

// cache_size WILL have changed.
Function5=ScalarFullSelect
Method5=SelectIntL
Result5=43
Use_Set5=1
Statement5=PRAGMA cache_size;

Close6=
Delete7=C:\ConfigTest3.db
EndBlock8=


// Try setting a legal page_size (works), a cache_size (doesn't work) and
// a legal character encoding (works).
[CheckOverride5]
DefineConfig0=page_size=512;cache_size=432;encoding=UTF-8
// On a new database we can change the page size, cache size and the
// encoding.
Delete1=C:\ConfigTest4.db
ExpectedError1=KErrNotFound

Create2=C:\ConfigTest4.db

// encoding will not have been changed from its default of utf-16
Function3=ScalarFullSelect
Method3=SelectTextL
Result3=UTF-8
Use_Set3=1
Statement3=PRAGMA encoding;

// page_size will not have been changed from its default of 1024..
Function4=ScalarFullSelect
Method4=SelectIntL
Result4=512
Use_Set4=1
Statement4=PRAGMA page_size;

// cache_size WILL have changed.
Function5=ScalarFullSelect
Method5=SelectIntL
Result5=432
Use_Set5=1
Statement5=PRAGMA cache_size;

Close6=
Delete7=C:\ConfigTest4.db
EndBlock8=

// /////////////////////////////////////////////////////////////////////////

// The following tests create two functionally identical databases but one
// block uses UTF-8. Then check that the file sizes differ.

// Create a database with a single table containing a single cell containing
// the text content of the reference1.txt text file. Set UTF-16.
[WriteTextDB-16bit]
Delete0=C:\ConfigTest5.db
ExpectedError0=KErrNotFound
Create1=C:\ConfigTest5.db

// First check for our expected defaults.
Function2=ScalarFullSelect
Method2=SelectTextL
Result2=UTF-16le
Use_Set2=1
Statement2=PRAGMA encoding;

Function3=ScalarFullSelect
Method3=SelectIntL
Result3=1024
Use_Set3=1
Statement3=PRAGMA page_size;

Function4=ScalarFullSelect
Method4=SelectIntL
Result4=DEFAULT_SOFT_HEAP_LIMIT
Use_Set4=1
Statement4=PRAGMA cache_size;

Exec5=Create Table Sometable(f1 text);
Prepare6=Insert into Sometable values(:val);
ParameterIndex7=:val
StreamWriteBindText8=0,Z:\TEF_SQL\TestData\reference1.txt
St_Exec9=
Reset10=
St_Close11=

Prepare12=select f1 from Sometable;
ColumnIndex13=f1
Next14=KSqlAtRow
ColumnSize15=0,3626
St_Close16=
Close17=
EndBlock18=

// Create a database with a single table containing a single cell containing
// the text content of the reference1.txt text file. Set UTF-8.
[WriteTextDB-8bit]
Delete0=C:\ConfigTest6.db
ExpectedError0=KErrNotFound
DefineConfig1=encoding=UTF-8
Create2=C:\ConfigTest6.db

// Check the defaults (plus our changed character encoding)
Function3=ScalarFullSelect
Method3=SelectTextL
Result3=UTF-8
Use_Set3=1
Statement3=PRAGMA encoding;

Function4=ScalarFullSelect
Method4=SelectIntL
Result4=1024
Use_Set4=1
Statement4=PRAGMA page_size;

Function5=ScalarFullSelect
Method5=SelectIntL
Result5=DEFAULT_SOFT_HEAP_LIMIT
Use_Set5=1
Statement5=PRAGMA cache_size;

Exec6=Create Table Sometable(f1 text);
Prepare7=Insert into Sometable values(:val);
ParameterIndex8=:val
StreamWriteBindText9=0,Z:\TEF_SQL\TestData\reference1.txt
St_Exec10=
Reset11=
St_Close12=

Prepare13=select f1 from Sometable;
ColumnIndex14=f1
Next15=KSqlAtRow
ColumnSize16=0,3626
St_Close17=
Close18=
EndBlock19=

// Check that the two databases created above (which are exactly equivalent)
// differ in size. That will suggest that the UTF-8/UTF-16
// encoding options have done their work. Through the SQLite APIs they generate
// identical output. It seems kind of overkill to have a whole code-driven
// test function to do this but I see no other way..
// Attempt an attach of UTF-16 to UTF-8 database - it will fail, that's an
// illegal operation.
[FilesDiffer]
Function0=FilesDifferBySize
FileA0=C:\ConfigTest5.db
FileB0=C:\ConfigTest6.db
Open1=C:\ConfigTest5.db
Exec2=Attach "C:\ConfigTest6.db" as ThatOne;
ExpectedError2=KSqlErrGeneral
LastErrorMessage3=attached databases must use the same text encoding as main database
// Delete will succeed because the attach didn't.
Delete4=C:\ConfigTest6.db
Close5=
Delete6=C:\ConfigTest5.db
EndBlock7=
