persistentstorage/sql/TEST/t_sqlapi.cpp
changeset 55 44f437012c90
parent 28 7a522c0700d3
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
    75 void Check(TInt aValue, TInt aLine)
    75 void Check(TInt aValue, TInt aLine)
    76 	{
    76 	{
    77 	if(!aValue)
    77 	if(!aValue)
    78 		{
    78 		{
    79 		DeleteTestFiles();
    79 		DeleteTestFiles();
       
    80 		TheTest.Printf(_L("*** Expression evaluated to false\r\n"));
    80 		TheTest(EFalse, aLine);
    81 		TheTest(EFalse, aLine);
    81 		}
    82 		}
    82 	}
    83 	}
    83 void Check(TInt aValue, TInt aExpected, TInt aLine)
    84 void Check(TInt aValue, TInt aExpected, TInt aLine)
    84 	{
    85 	{
    85 	if(aValue != aExpected)
    86 	if(aValue != aExpected)
    86 		{
    87 		{
    87 		DeleteTestFiles();
    88 		DeleteTestFiles();
    88 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    89 		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    89 		TheTest(EFalse, aLine);
    90 		TheTest(EFalse, aLine);
    90 		}
    91 		}
    91 	}
    92 	}
    92 #define TEST(arg) ::Check((arg), __LINE__)
    93 #define TEST(arg) ::Check((arg), __LINE__)
    93 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    94 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   119 	
   120 	
   120 	TInt rc = aDb.Exec(sqlBuf);
   121 	TInt rc = aDb.Exec(sqlBuf);
   121 	if(rc < 0 && SqlRetCodeClass(rc) == ESqlDbError)
   122 	if(rc < 0 && SqlRetCodeClass(rc) == ESqlDbError)
   122 		{
   123 		{
   123 		TPtrC msg = aDb.LastErrorMessage();
   124 		TPtrC msg = aDb.LastErrorMessage();
   124 		RDebug::Print(_L("Execute SQL error - '%S'\r\n"), &msg);
   125 		TheTest.Printf(_L("Execute SQL error - '%S'\r\n"), &msg);
   125 		}
   126 		}
   126 	if(aExpectedError < 0)
   127 	if(aExpectedError < 0)
   127 		{
   128 		{
   128 		TEST2(rc, aExpectedError);
   129 		TEST2(rc, aExpectedError);
   129 		}
   130 		}
   142 	RSqlStatement stmt;
   143 	RSqlStatement stmt;
   143 	TInt rc = stmt.Prepare(aDb, sqlBuf);
   144 	TInt rc = stmt.Prepare(aDb, sqlBuf);
   144 	if(rc != KErrNone && SqlRetCodeClass(rc) == ESqlDbError)
   145 	if(rc != KErrNone && SqlRetCodeClass(rc) == ESqlDbError)
   145 		{
   146 		{
   146 		TPtrC msg = aDb.LastErrorMessage();
   147 		TPtrC msg = aDb.LastErrorMessage();
   147 		RDebug::Print(_L("Execute SQL error - '%S'\r\n"), &msg);
   148 		TheTest.Printf(_L("Execute SQL error - '%S'\r\n"), &msg);
   148 		}
   149 		}
   149 	TEST2(rc, aExpectedError);
   150 	TEST2(rc, aExpectedError);
   150 	return stmt;
   151 	return stmt;
   151 	}
   152 	}
   152 
   153 
   154 	{
   155 	{
   155 	TInt rc = aStmt.Exec();
   156 	TInt rc = aStmt.Exec();
   156 	if(rc < 0 && SqlRetCodeClass(rc) == ESqlDbError)
   157 	if(rc < 0 && SqlRetCodeClass(rc) == ESqlDbError)
   157 		{
   158 		{
   158 		TPtrC msg = aDb.LastErrorMessage();
   159 		TPtrC msg = aDb.LastErrorMessage();
   159 		RDebug::Print(_L("Execute SQL error - '%S'\r\n"), &msg);
   160 		TheTest.Printf(_L("Execute SQL error - '%S'\r\n"), &msg);
   160 		}
   161 		}
   161 	if(aExpectedError < 0)
   162 	if(aExpectedError < 0)
   162 		{
   163 		{
   163 		TEST2(rc, aExpectedError);
   164 		TEST2(rc, aExpectedError);
   164 		}
   165 		}
   285 	//Very long database file name.
   286 	//Very long database file name.
   286 	TBuf<50>filesysname;
   287 	TBuf<50>filesysname;
   287 	fs.FileSystemName(filesysname,(TInt) EDriveC);
   288 	fs.FileSystemName(filesysname,(TInt) EDriveC);
   288     fs.Close();
   289     fs.Close();
   289 
   290 
   290 	RDebug::Print(_L("file system name = %S"), &filesysname);
   291     TheTest.Printf(_L("file system name = %S"), &filesysname);
   291 	TInt maxFileName = KMaxFileName -40;//"-40" because the SQLITE engine creates a journal file if begins
   292 	TInt maxFileName = KMaxFileName -40;//"-40" because the SQLITE engine creates a journal file if begins
   292 	                                                 //a transaction. The name of the journal file is 
   293 	                                                 //a transaction. The name of the journal file is 
   293 	                                                 //"<dbFileName>-journal.<ext>". It is obvious that if the 
   294 	                                                 //"<dbFileName>-journal.<ext>". It is obvious that if the 
   294 	                                                 //database file name is too long but still valid and its creation
   295 	                                                 //database file name is too long but still valid and its creation
   295 	                                                 //succeeds, the journal file creation may fail because the journal
   296 	                                                 //succeeds, the journal file creation may fail because the journal