persistentstorage/sql/TEST/t_sqlsecurity2.cpp
changeset 55 44f437012c90
parent 15 3eacc0623088
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
    57 void Check1(TInt aValue, TInt aLine)
    57 void Check1(TInt aValue, TInt aLine)
    58 	{
    58 	{
    59 	if(!aValue)
    59 	if(!aValue)
    60 		{
    60 		{
    61 		DeleteTestDb();
    61 		DeleteTestDb();
    62 		RDebug::Print(_L("*** Line %d\r\n"), aLine);
    62 		TheTest.Printf(_L("*** Line %d. Expression evaluated to false\r\n"), aLine);
    63 		TheTest(EFalse, aLine);
    63 		TheTest(EFalse, aLine);
    64 		}
    64 		}
    65 	}
    65 	}
    66 void Check2(TInt aValue, TInt aExpected, TInt aLine)
    66 void Check2(TInt aValue, TInt aExpected, TInt aLine)
    67 	{
    67 	{
    68 	if(aValue != aExpected)
    68 	if(aValue != aExpected)
    69 		{
    69 		{
    70 		DeleteTestDb();
    70 		DeleteTestDb();
    71 		RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
    71 		TheTest.Printf(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
    72 		TheTest(EFalse, aLine);
    72 		TheTest(EFalse, aLine);
    73 		}
    73 		}
    74 	}
    74 	}
    75 #define TEST(arg) ::Check1((arg), __LINE__)
    75 #define TEST(arg) ::Check1((arg), __LINE__)
    76 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
    76 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
   125 	err = stmt.DeclaredColumnType(0, colType);
   125 	err = stmt.DeclaredColumnType(0, colType);
   126 	TEST2(err, KErrNone);
   126 	TEST2(err, KErrNone);
   127 	TEST2(colType, ESqlInt);
   127 	TEST2(colType, ESqlInt);
   128 	err = stmt.Next();
   128 	err = stmt.Next();
   129 	TEST2(err, KSqlAtRow);
   129 	TEST2(err, KSqlAtRow);
   130 	RDebug::Print(_L("Value=%d\r\n"), stmt.ColumnInt(0));
   130 	TheTest.Printf(_L("Value=%d\r\n"), stmt.ColumnInt(0));
   131 	err = stmt.Next();
   131 	err = stmt.Next();
   132 	TEST2(err, KSqlAtRow);
   132 	TEST2(err, KSqlAtRow);
   133 	RDebug::Print(_L("Value=%d\r\n"), stmt.ColumnInt(0));
   133 	TheTest.Printf(_L("Value=%d\r\n"), stmt.ColumnInt(0));
   134 	stmt.Close();
   134 	stmt.Close();
   135 	//Attempt to read the system data
   135 	//Attempt to read the system data
   136 	err = stmt.Prepare(TheDb, _L("SELECT * FROM SQLITE_MASTER"));
   136 	err = stmt.Prepare(TheDb, _L("SELECT * FROM SQLITE_MASTER"));
   137 	TEST2(err, KErrNone);
   137 	TEST2(err, KErrNone);
   138 	err = stmt.Next();
   138 	err = stmt.Next();
   139 	TEST2(err, KSqlAtRow);
   139 	TEST2(err, KSqlAtRow);
   140 	TPtrC p;
   140 	TPtrC p;
   141 	err = stmt.ColumnText(0, p);
   141 	err = stmt.ColumnText(0, p);
   142 	TEST2(err, KErrNone);
   142 	TEST2(err, KErrNone);
   143 	RDebug::Print(_L("Value=%S\r\n"), &p);
   143 	TheTest.Printf(_L("Value=%S\r\n"), &p);
   144 	stmt.Close();
   144 	stmt.Close();
   145 
   145 
   146 	//Attempt to execute PRAGMA statement directly
   146 	//Attempt to execute PRAGMA statement directly
   147 	err = TheDb.Exec(_L("PRAGMA encoding = \"UTF-8\""));
   147 	err = TheDb.Exec(_L("PRAGMA encoding = \"UTF-8\""));
   148 	TEST2(err, KErrPermissionDenied);
   148 	TEST2(err, KErrPermissionDenied);