persistentstorage/dbms/tdbms/t_dbstrcmp.cpp
changeset 55 44f437012c90
parent 0 08ec8eefde2f
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
    81 		{
    81 		{
    82 		TEntry entry;
    82 		TEntry entry;
    83 		err = fsSession.Entry(aFullName, entry);
    83 		err = fsSession.Entry(aFullName, entry);
    84 		if(err == KErrNone)
    84 		if(err == KErrNone)
    85 			{
    85 			{
    86 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
    86 			TheTest.Printf(_L("Deleting \"%S\" file.\n"), &aFullName);
    87 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
    87 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
    88 			if(err != KErrNone)
    88 			if(err != KErrNone)
    89 				{
    89 				{
    90 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
    90 				TheTest.Printf(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
    91 				}
    91 				}
    92 			err = fsSession.Delete(aFullName);
    92 			err = fsSession.Delete(aFullName);
    93 			if(err != KErrNone)
    93 			if(err != KErrNone)
    94 				{
    94 				{
    95 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
    95 				TheTest.Printf(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
    96 				}
    96 				}
    97 			}
    97 			}
    98 		fsSession.Close();
    98 		fsSession.Close();
    99 		}
    99 		}
   100 	else
   100 	else
   101 		{
   101 		{
   102 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   102 		TheTest.Printf(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   103 		}
   103 		}
   104 	return err;
   104 	return err;
   105 	}
   105 	}
   106 
   106 
   107 ///////////////////////////////////////////////////////////////////////////////////////
   107 ///////////////////////////////////////////////////////////////////////////////////////
   111 static void Check(TInt aValue, TInt aLine)
   111 static void Check(TInt aValue, TInt aLine)
   112 	{
   112 	{
   113 	if(!aValue)
   113 	if(!aValue)
   114 		{
   114 		{
   115 		::DeleteDataFile(KTestDatabase);
   115 		::DeleteDataFile(KTestDatabase);
       
   116 		TheTest.Printf(_L("*** Expression evaluated to false\r\n"));
   116 		TheTest(EFalse, aLine);
   117 		TheTest(EFalse, aLine);
   117 		}
   118 		}
   118 	}
   119 	}
   119 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
   120 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
   120 static void Check(TInt aValue, TInt aExpected, TInt aLine)
   121 static void Check(TInt aValue, TInt aExpected, TInt aLine)
   121 	{
   122 	{
   122 	if(aValue != aExpected)
   123 	if(aValue != aExpected)
   123 		{
   124 		{
   124 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   125 		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   125 		::DeleteDataFile(KTestDatabase);
   126 		::DeleteDataFile(KTestDatabase);
   126 		TheTest(EFalse, aLine);
   127 		TheTest(EFalse, aLine);
   127 		}
   128 		}
   128 	}
   129 	}
   129 //Use these to test conditions.
   130 //Use these to test conditions.
   143 	}
   144 	}
   144 
   145 
   145 //Leaves with info message printed out
   146 //Leaves with info message printed out
   146 static void LeaveL(TInt aError, TInt aLine)
   147 static void LeaveL(TInt aError, TInt aLine)
   147 	{
   148 	{
   148 	RDebug::Print(_L("*** Leave. Error: %d, Line: %d\r\n"), aError, aLine);
   149 	TheTest.Printf(_L("*** Leave. Error: %d, Line: %d\r\n"), aError, aLine);
   149 	User::Leave(aError);
   150 	User::Leave(aError);
   150 	}
   151 	}
   151 
   152 
   152 //Leaves if aError < 0 with info message printed out
   153 //Leaves if aError < 0 with info message printed out
   153 static void LeaveIfErrorL(TInt aError, TInt aLine)
   154 static void LeaveIfErrorL(TInt aError, TInt aLine)
   164 #define LEAVE_IF_ERROR(aError) ::LeaveIfErrorL(aError, __LINE__)
   165 #define LEAVE_IF_ERROR(aError) ::LeaveIfErrorL(aError, __LINE__)
   165 
   166 
   166 //Creates the test DBMS session
   167 //Creates the test DBMS session
   167 static void CreateTestDbSession()
   168 static void CreateTestDbSession()
   168 	{
   169 	{
   169 	RDebug::Print(_L("Create DBMS session\n"));
   170 	TheTest.Printf(_L("Create DBMS session\n"));
   170 	TInt err = TheDbSession.Connect();
   171 	TInt err = TheDbSession.Connect();
   171 	TEST2(err, KErrNone);
   172 	TEST2(err, KErrNone);
   172 	}
   173 	}
   173 
   174 
   174 
   175 
   175 //Creates the test database
   176 //Creates the test database
   176 //TheDbSession instance has to be connected already.
   177 //TheDbSession instance has to be connected already.
   177 //TheFs.Connect() has to be called already.
   178 //TheFs.Connect() has to be called already.
   178 static void CreateTestDatabase(RDbs& aDbs, RDbNamedDatabase& aDb)
   179 static void CreateTestDatabase(RDbs& aDbs, RDbNamedDatabase& aDb)
   179 	{
   180 	{
   180 	RDebug::Print(_L("Create test database\n"));
   181 	TheTest.Printf(_L("Create test database\n"));
   181 	TInt err = aDb.Replace(TheFs, KTestDatabase);
   182 	TInt err = aDb.Replace(TheFs, KTestDatabase);
   182 	TEST2(err, KErrNone);
   183 	TEST2(err, KErrNone);
   183 	TheDb.Close();
   184 	TheDb.Close();
   184 	err = aDb.Open(aDbs, KTestDatabase);
   185 	err = aDb.Open(aDbs, KTestDatabase);
   185 	TEST2(err, KErrNone);
   186 	TEST2(err, KErrNone);
   200 	}
   201 	}
   201 
   202 
   202 //Creates test tables
   203 //Creates test tables
   203 static void CreateTestTablesL(RDbNamedDatabase& aDb)
   204 static void CreateTestTablesL(RDbNamedDatabase& aDb)
   204 	{
   205 	{
   205 	RDebug::Print(_L("Create test tables\n"));
   206 	TheTest.Printf(_L("Create test tables\n"));
   206 	::DoCreateTestTableL(aDb, KTestTableName1, KColDefs1);
   207 	::DoCreateTestTableL(aDb, KTestTableName1, KColDefs1);
   207 	::DoCreateTestTableL(aDb, KTestTableName2, KColDefs2);
   208 	::DoCreateTestTableL(aDb, KTestTableName2, KColDefs2);
   208 	}
   209 	}
   209 
   210 
   210 //Gets the value of the string field, which type may be EDbColText16 or EDbColLongText16
   211 //Gets the value of the string field, which type may be EDbColText16 or EDbColLongText16
   224 	}
   225 	}
   225 
   226 
   226 //Prints all table records
   227 //Prints all table records
   227 static TInt PrintRecordsL(RDbRowSet& aTbl, const TDesC& aTblName)
   228 static TInt PrintRecordsL(RDbRowSet& aTbl, const TDesC& aTblName)
   228 	{
   229 	{
   229 	RDebug::Print(_L("Table: %S\n"), &aTblName);
   230 	TheTest.Printf(_L("Table: %S\n"), &aTblName);
   230     aTbl.FirstL();
   231     aTbl.FirstL();
   231 	TInt rec = 0;
   232 	TInt rec = 0;
   232     while(aTbl.AtRow())
   233     while(aTbl.AtRow())
   233         {
   234         {
   234         aTbl.GetL();
   235         aTbl.GetL();
   235 		TNameBuf strFldVal;
   236 		TNameBuf strFldVal;
   236 		GetStrFieldValueL(aTbl, aTblName, strFldVal);
   237 		GetStrFieldValueL(aTbl, aTblName, strFldVal);
   237 		TUint32 v = aTbl.ColUint32(2);
   238 		TUint32 v = aTbl.ColUint32(2);
   238 		RDebug::Print(_L("   Record %d, Str: %S, Val: %d\n"), ++rec, &strFldVal, v);
   239 		TheTest.Printf(_L("   Record %d, Str: %S, Val: %d\n"), ++rec, &strFldVal, v);
   239         aTbl.NextL();
   240         aTbl.NextL();
   240         }
   241         }
   241 	return rec;
   242 	return rec;
   242 	}
   243 	}
   243 
   244 
   278 	}
   279 	}
   279 
   280 
   280 //Adds the test data to test tables
   281 //Adds the test data to test tables
   281 static void AddTestDataL(RDbNamedDatabase& aDb)
   282 static void AddTestDataL(RDbNamedDatabase& aDb)
   282 	{
   283 	{
   283 	RDebug::Print(_L("Add data to test tables\n"));
   284 	TheTest.Printf(_L("Add data to test tables\n"));
   284 	::AddTestDataL(aDb, KTestTableName1);
   285 	::AddTestDataL(aDb, KTestTableName1);
   285 	::AddTestDataL(aDb, KTestTableName2);
   286 	::AddTestDataL(aDb, KTestTableName2);
   286 	}
   287 	}
   287 
   288 
   288 //Init test environment
   289 //Init test environment
   310 		}
   311 		}
   311 	}
   312 	}
   312 
   313 
   313 static void CreateIndexL(RDbNamedDatabase& aDb, const TDesC& aTblName, const TDesC& aColumnName)
   314 static void CreateIndexL(RDbNamedDatabase& aDb, const TDesC& aTblName, const TDesC& aColumnName)
   314 	{
   315 	{
   315 	RDebug::Print(_L("Create index. Table: %S, column: %S\n"), &aTblName, &aColumnName);
   316 	TheTest.Printf(_L("Create index. Table: %S, column: %S\n"), &aTblName, &aColumnName);
   316 	CDbKey* key = CDbKey::NewLC();
   317 	CDbKey* key = CDbKey::NewLC();
   317 	key->AddL(aColumnName);
   318 	key->AddL(aColumnName);
   318 	key->MakeUnique();
   319 	key->MakeUnique();
   319 	key->SetComparison(EDbCompareCollated);
   320 	key->SetComparison(EDbCompareCollated);
   320 	LEAVE_IF_ERROR(aDb.CreateIndex(aColumnName, aTblName, *key));
   321 	LEAVE_IF_ERROR(aDb.CreateIndex(aColumnName, aTblName, *key));