persistentstorage/sql/SRC/Server/SqlSrvMain.cpp
branchRCL_3
changeset 8 fa9941cf3867
parent 0 08ec8eefde2f
child 9 667e88a979d7
--- a/persistentstorage/sql/SRC/Server/SqlSrvMain.cpp	Sat Feb 20 00:33:55 2010 +0200
+++ b/persistentstorage/sql/SRC/Server/SqlSrvMain.cpp	Fri Mar 12 15:51:02 2010 +0200
@@ -233,6 +233,9 @@
 
 /**
 Creates new CSqlSrvSession instance.
+If SQLSRV_STARTUP_TEST macro is defined, then the function returns NULL.
+The "real" implementation of the function is not used in this case because the used unit test will require 
+a lot of cpp files to be included into the test build (t_sqlstartup).
 
 @return A pointer to the created CSqlSrvSession instance.
 
@@ -241,15 +244,20 @@
        
 @see CSqlSrvSession
 */
-CSession2* CSqlServer::NewSessionL(const TVersion &aVersion, const RMessage2&) const
-	{
-	if(!User::QueryVersionSupported(::SqlSrvVersion(), aVersion))
-		{
-		User::Leave(KErrNotSupported);
-		}
-	CSqlSrvSession* sess = CSqlSrvSession::NewL();
-	return sess;
-	}
+CSession2* CSqlServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const
+    {
+#ifdef SQLSRV_STARTUP_TEST
+    aVersion.Name();//to prevent the compiler warning ("unused parameter").
+    return NULL;
+#else
+    if(!User::QueryVersionSupported(::SqlSrvVersion(), aVersion))
+        {
+        User::Leave(KErrNotSupported);
+        }
+    CSqlSrvSession* sess = CSqlSrvSession::NewL();
+    return sess;
+#endif //SQLSRV_STARTUP_TEST
+    }
 
 /**
 CSqlServer's active object priority.
@@ -283,7 +291,11 @@
 */
 void CSqlServer::ConstructL()
 	{
+#ifndef SQLSRV_STARTUP_TEST
+	//Start the server only in "normal" builds, not in the case where t_sqlstartup unit test tests directly
+	//the SQL server startup code.
 	StartL(KSqlSrvName);
+#endif	
 #ifdef _SQLPROFILER 
     TheSqlSrvStartTime.UniversalTime();
     SQLPROFILER_SERVER_START();
@@ -329,18 +341,24 @@
 	//Compactor
 	iCompactor = CSqlCompactor::NewL(&SqlCreateCompactConnL, KSqlCompactStepIntervalMs);
 #ifdef _DEBUG
-	/*
-	 The following statements exist to prevent the failure of the resource allocation 
-	 checking for debug mode. 
-	 They allocate some memory when the server object is constructed so avoid these memory 
-	 allocations during debug mode. 
-	 */
-const TInt KAnyNumber	= 0xAA55; 
-const TInt KGreatSize = 1024; 
+    //The following statements exist to prevent the failure of the OOM testing in debug mode.
+	//The standard C library allocates some memory at the startup and stores a pointer to the allocated memory
+	//in the TLS. During normal API OOM testing the SQL server is not restarted, it never goes down.
+	//Then the TLS and the allocated memory are not released. In which case the OOM testing will fail
+	//(because the standard C library performs a lazy initialization and the allocation and TLS usage will be made
+	//at the point of first use of some C function. This is out of the control of the test code).
+	//In order to avoid that, during the SQL server startup here, before the OOM test goes and checks what 
+	//is the allocated memory at the beginning, a fake sprintf() call is made in order to force the mentioned above  
+	//allocation in the standard C library.
+	//All explanations above are true, except one case when the SQl server startup code is tested directly.
+    #ifndef SQLSRV_STARTUP_TEST
+	const TInt KAnyNumber	= 0xAA55; 
  	char tmp[32]; 
  	sprintf(tmp, "%04X", KAnyNumber);
+    const TInt KGreatSize = 1024; 
  	__SQLLEAVE_IF_ERROR(ReAllocBuf(KGreatSize));
-#endif 	
+    #endif //SQLSRV_STARTUP_TEST 	
+#endif //_DEBUG 	
 	}
 
 /**
@@ -436,6 +454,7 @@
 */
 void CSqlServer::GetBackUpListL(TSecureId aUid, RArray<TParse>& aFileList)
 	{
+	aFileList.Reset();
 	TFindFile findFile(iFileData.Fs());
 	CDir* fileNameCol = NULL;
 	TUidName uidName = (static_cast <TUid> (aUid)).Name();
@@ -479,6 +498,9 @@
 			fileNameCol = NULL;
 			} while((err = findFile.FindWild(fileNameCol)) == KErrNone);//Get the next set of files
 		}//end of "if(err == KErrNone)"
+	//TODO: once DEF144134 gets fixed, the next 2 lines shall be removed
+	delete fileNameCol;
+	fileNameCol = NULL;
 	__SQLASSERT(!fileNameCol, ESqlPanicInternalError);
 	if(err != KErrNotFound && err != KErrNone)
 		{
@@ -490,6 +512,8 @@
 ////////////////////////////////////////   SQL server startup   //////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
+#ifndef SQLSRV_STARTUP_TEST
+
 //Run the SQL server
 static void RunServerL()
 	{
@@ -526,3 +550,4 @@
 	return err;
 	}
 
+#endif //SQLSRV_STARTUP_TEST