landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp118.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *   ?description_line
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //  INCLUDES
       
    21 #include "FT_CPosTp118.h"
       
    22 #include <EPos_CPosLandmarkDatabase.h>
       
    23 #include <EPos_CPosLmDatabaseManager.h>
       
    24 #include <d32dbms.h>
       
    25 #include "FT_DatabaseUtility.h"
       
    26 
       
    27 //  CONSTANTS
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // ---------------------------------------------------------
       
    32 // CPosTp118::CloseTest
       
    33 //
       
    34 // (other items were commented in a header).
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 void CPosTp118::CloseTest()
       
    38     {
       
    39 	iLog->Log(_L("CloseTest"));
       
    40 	
       
    41     TRAPD(err, RemoveAllLmDatabasesL());
       
    42     if (err != KErrNone) iLog->Log(_L("RemoveAllLmDatabasesL() leaved"));
       
    43     
       
    44     TRAP(err, DeleteTp118FilesL());
       
    45     if (err != KErrNone) iLog->Log(_L("DeleteTp118FilesL() leaved"));
       
    46     
       
    47     delete iDatabases;
       
    48     iDatabases=NULL;
       
    49     }
       
    50        
       
    51 // ---------------------------------------------------------
       
    52 // CPosTp118::StartL
       
    53 //
       
    54 // (other items were commented in a header).
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 void CPosTp118::StartL()
       
    58     {
       
    59     TInt err = KErrNone;
       
    60     // Remove all databases
       
    61     RemoveAllLmDatabasesL();
       
    62     
       
    63     DeleteTp118FilesL();
       
    64     TBuf<100> buf;
       
    65     
       
    66     CPosLandmarkDatabase* lmd = NULL;
       
    67     	
       
    68     iLog->Log(_L("1) Create a valid landmark db"));
       
    69     // 1) Create a valid landmark db, it should be listed
       
    70 	FTDatabaseUtility::CreateDatabaseL(_L("c:TP118.ldb"));
       
    71 	
       
    72 	// 2) List an verify that db created in step 1 is listed
       
    73 	iLog->Log(_L("2) Verify that db created in step1 is listed:"));
       
    74 	CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL();
       
    75     CleanupStack::PushL(dbManager);
       
    76 	iDatabases = dbManager->ListDatabasesLC();
       
    77 	CleanupStack::Pop(iDatabases);
       
    78 
       
    79 	TInt res = VerifyList(iDatabases, _L("file://C:TP118.ldb"));
       
    80 	AssertTrueSecL(res, _L("file://C:TP118.LDB was not found"));
       
    81 	CleanupStack::PopAndDestroy(dbManager);
       
    82 
       
    83 	// 3) Create a valid landmark db, but without correct file extension
       
    84 	iLog->Log(_L("3) Create a valid landmark db, but without correct file extension"));
       
    85 	FTDatabaseUtility::CreateDatabaseL(_L("c:TP118_NoExtension"), EFalse);
       
    86 	dbManager = CPosLmDatabaseManager::NewL();
       
    87     CleanupStack::PushL(dbManager);
       
    88 	
       
    89 	// 4) List all databases and verify that db created in step 3 is not listed
       
    90 	iLog->Log(_L("List all databases and verify that db created in step 3 is not listed"));
       
    91 	delete iDatabases; iDatabases=NULL;
       
    92 	iDatabases = dbManager->ListDatabasesLC();
       
    93 	CleanupStack::Pop(iDatabases);
       
    94 
       
    95 	res = VerifyList(iDatabases, _L("file://c:TP118_NoExtension"));
       
    96 	AssertTrueSecL(!res, _L("file://c:TP118_NoExtension should not have been found"));
       
    97 	CleanupStack::PopAndDestroy(dbManager);
       
    98 
       
    99 	// 5) Create lm db without correct secure id
       
   100 	iLog->Log(_L("5) Create lm db without correct secure id"));
       
   101 	FTDatabaseUtility::CreateDatabaseL(_L("c:TP118_WrongId.ldb"), ETrue, ETrue);
       
   102 	dbManager = CPosLmDatabaseManager::NewL();
       
   103     CleanupStack::PushL(dbManager);
       
   104     
       
   105     // 6) List all databases and verify that db created in step 5 is not listed
       
   106     iLog->Log(_L("6) List all databases and verify that db created in step 5 is not listed"));
       
   107     delete iDatabases; iDatabases=NULL;
       
   108 	iDatabases = dbManager->ListDatabasesLC();
       
   109 	CleanupStack::Pop(iDatabases);
       
   110 	
       
   111 	res = VerifyList(iDatabases, _L("c:TP118_WrongId.ldb"));
       
   112 	AssertTrueSecL(!res, _L("file://c:TP118_WrongId.ldb should not have been found"));
       
   113 	CleanupStack::PopAndDestroy(dbManager);
       
   114 	
       
   115 	// 7 Create lm db with invalid landmarks tables
       
   116 	iLog->Log(_L("7) Create lm db with invalid landmarks tables"));
       
   117 	FTDatabaseUtility::CreateDatabaseL(_L("C:TP118_INVALIDTABLES.ldb"), ETrue, EFalse, ETrue);
       
   118 	dbManager = CPosLmDatabaseManager::NewL();
       
   119     CleanupStack::PushL(dbManager);
       
   120     
       
   121     // 8) List all databases and verify that db created in step 7 is listed
       
   122     iLog->Log(_L("8) List all databases and verify that db created in step 7 is listed"));
       
   123     delete iDatabases; iDatabases=NULL;
       
   124 	iDatabases = dbManager->ListDatabasesLC();
       
   125 	CleanupStack::Pop(iDatabases);
       
   126 	res = VerifyList(iDatabases, _L("file://C:TP118_INVALIDTABLES.ldb"));
       
   127 	AssertTrueSecL(res, _L("file://C:TP118_INVALIDTABLES.ldb should have been found"));
       
   128 	CleanupStack::PopAndDestroy(dbManager);
       
   129 	
       
   130 	// CleanupStack::PopAndDestroy(dbManager);
       
   131 	// This causes DBMS to panic UTFW (this TestProgram)
       
   132 	// Adds landmarks but needed tables are already removed
       
   133 	// CreateLandmarksInDbL(_L("C:TP118_INVALIDTABLES.LDB"));
       
   134 	
       
   135 	/*
       
   136 	/////////////////////////////////////////////
       
   137 	// Add extra test here, set this db to default
       
   138 	iLog->Log(_L("SetDefaultDatabaseL"));
       
   139     dbManager->SetDefaultDatabaseL(_L("C:TP118_INVALIDTABLES.LDB"));
       
   140 	CleanupStack::PopAndDestroy(dbManager);
       
   141     
       
   142     //  Try to open defaultdb which is the db created in step18
       
   143     // Check that the default db is re-created when it is corrupt
       
   144     CPosLandmarkDatabase* lmdb = NULL;
       
   145     TRAP(err, lmdb = CPosLandmarkDatabase::OpenL());
       
   146     if (err == KErrNone)
       
   147     	{
       
   148     	CleanupStack::PushL(lmdb);
       
   149         CheckLandmarkDbL(lmdb);
       
   150         CleanupStack::PopAndDestroy(lmdb);
       
   151         //This causes DBMS to panic UTFW (this TestProgram)
       
   152 	    // Adds landmarks but needed tables are already removed
       
   153         CreateLandmarksInDbL(_L("C:TP118_INVALIDTABLES.LDB"));
       
   154     	}
       
   155     else
       
   156     	{
       
   157     	LogErrorAndLeave(_L("OpenL should not leave with err"), err);
       
   158     	}
       
   159     */
       
   160 	/////////////////////////////////////////////
       
   161 
       
   162 	// 9) Try to open db created in step7
       
   163 	iLog->Log(_L("9) Open db created in step 7"));
       
   164 	lmd = CPosLandmarkDatabase::OpenL(_L("file://C:TP118_INVALIDTABLES.ldb"));
       
   165 	CleanupStack::PushL(lmd);
       
   166 	CheckLandmarkDbL(lmd);
       
   167 	CleanupStack::PopAndDestroy(lmd);
       
   168 
       
   169     // 10) Drop table in db
       
   170     iLog->Log(_L("10) Create db and then drop tables in db"));
       
   171     dbManager=CPosLmDatabaseManager::NewL();
       
   172     CleanupStack::PushL(dbManager);
       
   173     
       
   174     _LIT(KDropTableLmDb, "C:TP118_DROPTABLELMDB.ldb");
       
   175     HPosLmDatabaseInfo* dbInfo = HPosLmDatabaseInfo::NewLC(KDropTableLmDb);
       
   176     dbManager->CreateDatabaseL(*dbInfo);
       
   177     CleanupStack::PopAndDestroy(dbInfo);
       
   178     
       
   179     CreateLandmarksInDbL(KDropTableLmDb);
       
   180     DropTableL(KDropTableLmDb, KPosLmLandmarkTable);
       
   181     
       
   182     delete iDatabases; iDatabases=NULL;
       
   183     iDatabases = dbManager->ListDatabasesLC();
       
   184     CleanupStack::Pop(iDatabases);
       
   185     res = VerifyList(iDatabases, _L("file://C:TP118_DROPTABLELMDB.ldb"));
       
   186     AssertTrueSecL(res, _L("C:TP118_DropTableLmDb.ldb was not found"));
       
   187     CleanupStack::PopAndDestroy(dbManager);
       
   188 
       
   189     // 11) Try to open db created in step10
       
   190 	iLog->Log(_L("11) Open db created in step 10"));
       
   191 	lmd = CPosLandmarkDatabase::OpenL(_L("file://C:TP118_DROPTABLELMDB.ldb"));
       
   192 
       
   193 	// Error when opening db
       
   194 	CleanupStack::PushL(lmd);
       
   195 	TRAP(err, CheckLandmarkDbL(lmd));
       
   196 	AssertTrueSecL(err == KErrNotFound, _L("11) CheckLandmarkDbL did not leave with KErrNotFound"));
       
   197 
       
   198 	CleanupStack::PopAndDestroy(lmd);
       
   199 	// Try to add landmarks to this db
       
   200 	// Leaves with KErrNotFound
       
   201 	//CreateLandmarksInDbL(_L("C:TP118_DROPTABLELMDB.LDB"),1);
       
   202     
       
   203     // 12) DropIndexL
       
   204     iLog->Log(_L("Step12: DropIndexL"));
       
   205     dbManager=CPosLmDatabaseManager::NewL();
       
   206     CleanupStack::PushL(dbManager);
       
   207     
       
   208     _LIT(KTP118_DROPINDEXLMDB_LDB, "C:TP118_DROPINDEXLMDB.ldb");
       
   209     HPosLmDatabaseInfo* dbInfoDrop = HPosLmDatabaseInfo::NewLC(KTP118_DROPINDEXLMDB_LDB);
       
   210     dbManager->CreateDatabaseL(*dbInfoDrop);
       
   211     CleanupStack::PopAndDestroy(dbInfoDrop);
       
   212     
       
   213     CreateLandmarksInDbL(_L("C:TP118_DROPINDEXLMDB.ldb"));
       
   214     iLog->Log(_L("12) DropIndex"));
       
   215     DropIndexL(_L("C:TP118_DROPINDEXLMDB.LDB"), KPosLmCategoryTable, KPosLmGlobalCategoryIdIndex);   
       
   216     CleanupStack::PopAndDestroy(dbManager);
       
   217     
       
   218     // 13) Try to open db created in step12
       
   219 	iLog->Log(_L("13) Open db created in step 12"));
       
   220 	lmd = CPosLandmarkDatabase::OpenL(_L("C:TP118_DROPINDEXLMDB.ldb"));
       
   221 	
       
   222     CleanupStack::PushL(lmd);
       
   223 	CheckLandmarkDbL(lmd);
       
   224 	CleanupStack::PopAndDestroy(lmd);
       
   225     // Try to add landmarks to this db
       
   226 	CreateLandmarksInDbL(_L("C:TP118_DROPINDEXLMDB.LDB"), 1);
       
   227 	
       
   228 	// 14)
       
   229     iLog->Log(_L("14) DropIndex"));
       
   230     dbManager=CPosLmDatabaseManager::NewL();
       
   231     CleanupStack::PushL(dbManager);
       
   232     
       
   233     _LIT(KTP118_DROPINDEXLMDB2_LDB, "C:TP118_DROPINDEXLMDB2.ldb");
       
   234     HPosLmDatabaseInfo* dbInfoDrop2 = HPosLmDatabaseInfo::NewLC(KTP118_DROPINDEXLMDB2_LDB);
       
   235     dbManager->CreateDatabaseL(*dbInfoDrop2);
       
   236     CleanupStack::PopAndDestroy(dbInfoDrop2);
       
   237     
       
   238     CreateLandmarksInDbL(_L("C:TP118_DROPINDEXLMDB2.ldb"));
       
   239     DropIndexL(_L("C:TP118_DROPINDEXLMDB2.LDB"), KPosLmLandmarkTable, KPosLmLandmarkIdIndex);
       
   240     CleanupStack::PopAndDestroy(dbManager);
       
   241     
       
   242     // 15) Try to open db created in step13
       
   243 	iLog->Log(_L("15) Open db created in step 14"));
       
   244 	lmd = CPosLandmarkDatabase::OpenL(_L("C:TP118_DROPINDEXLMDB2.ldb"));
       
   245 	
       
   246     CleanupStack::PushL(lmd);
       
   247 	CheckLandmarkDbL(lmd);
       
   248 	CleanupStack::PopAndDestroy(lmd);
       
   249 	// Try to add landmarks to this db
       
   250 	CreateLandmarksInDbL(_L("C:TP118_DROPINDEXLMDB2.ldb"), 1);
       
   251 	
       
   252 	////////////
       
   253     // 16) Create an ordinary database with some landmarks and then remove some parts of the binary file
       
   254     // Create db by manually removing some parts with notepad
       
   255     /*
       
   256     //Use this part to create db "TP118HalfLmDb.ldb" containing some landmarks, then use notepad to remove
       
   257     // some parts from physical file 
       
   258     dbManager=CPosLmDatabaseManager::NewL();
       
   259     CleanupStack::PushL(dbManager);
       
   260     dbManager->CreateDatabaseL(_L("TP118HalfLmDb.ldb"));
       
   261     CreateLandmarksInDbL(_L("TP118HalfLmDb.ldb"));
       
   262     CleanupStack::PopAndDestroy(dbManager);
       
   263     */
       
   264     // Use corrupted file
       
   265     iLog->Log(_L("16) Use corrupted file"));
       
   266     CopyTestDbFileL(_L("TP118HALFLMDB_2.ldb"));
       
   267     
       
   268     dbManager = CPosLmDatabaseManager::NewL();
       
   269     CleanupStack::PushL(dbManager);
       
   270     delete iDatabases; iDatabases = NULL;
       
   271     iDatabases = dbManager->ListDatabasesLC();
       
   272     CleanupStack::Pop(iDatabases);
       
   273 
       
   274     res = VerifyList(iDatabases, _L("file://C:TP118HALFLMDB_2.ldb"));
       
   275 	AssertTrueSecL(res, _L("file://C:TP118HALFLMDB_2.LDB should have been found"));
       
   276     CleanupStack::PopAndDestroy(dbManager);
       
   277     
       
   278     // 17) Try to open db created in step16m it should not be possible
       
   279     // Before it returned KErrCorrupt(?) but now with Mars wk21 SDK it returns KErrNotSupported
       
   280     CPosLandmarkDatabase* someLmDb = NULL;
       
   281     TRAP(err, someLmDb = CPosLandmarkDatabase::OpenL(_L("TP118HalfLmDb_2.ldb")));
       
   282     if (err == KErrNone)
       
   283     	{
       
   284     	CleanupStack::PushL(someLmDb);
       
   285     	ExecuteAndDeleteLD(someLmDb->InitializeL());
       
   286     	CleanupStack::PopAndDestroy(someLmDb);
       
   287         AssertTrueSecL(EFalse,_L("OpenL should leave with error"));
       
   288     	}
       
   289     else
       
   290         {
       
   291         buf.Format(_L("OpenL leaved with %d"), err);
       
   292         iLog->Log(buf);
       
   293         }
       
   294     
       
   295     // 18) Use same file as in 16 and set this file to default db
       
   296     iLog->Log(_L("Use same file as in 16 and set this file to default db"));
       
   297     CopyTestDbFileL(_L("TP118HALFLMDB_2.LDB"));
       
   298     dbManager = CPosLmDatabaseManager::NewL();
       
   299     CleanupStack::PushL(dbManager);
       
   300     
       
   301     iLog->Log(_L("SetDefaultDatabaseL"));
       
   302     dbManager->SetDefaultDatabaseUriL(_L("Tp118HALFLMDB_2.ldb"));
       
   303 	CleanupStack::PopAndDestroy(dbManager);
       
   304     
       
   305     // 19) Try to open defaultdb which is the db created in step18
       
   306     // Before Mars wk21 SDK the default db is re-created when it is corrupt
       
   307     // but now instead KErrNotSUpported is returned
       
   308     iLog->Log(_L("Try to open defaultdb which is the db created in step18"));
       
   309     TRAP(err, someLmDb = CPosLandmarkDatabase::OpenL());
       
   310     
       
   311     if (err == KErrNone)
       
   312     	{
       
   313     	CleanupStack::PushL(someLmDb);
       
   314         CheckLandmarkDbL(someLmDb);
       
   315         CleanupStack::PopAndDestroy(someLmDb);
       
   316         // Try to add landmarks to this db
       
   317 	    CreateLandmarksInDbL(_L("Tp118HALFLMDB_2.ldb"));
       
   318     	}
       
   319     else
       
   320     	{
       
   321     	//LogErrorAndLeave(_L("OpenL should not leave with err"), err);
       
   322     	buf.Format(_L("open defaultdb leaved with %d"), err);
       
   323     	iLog->Log(buf);
       
   324     	}
       
   325 	}
       
   326 
       
   327 // ---------------------------------------------------------
       
   328 // CPosTp118::CheckLandmarkDbL
       
   329 //
       
   330 // (other items were commented in a header).
       
   331 // ---------------------------------------------------------
       
   332 //
       
   333 void CPosTp118::CheckLandmarkDbL(CPosLandmarkDatabase* aDb)
       
   334     {
       
   335     iLog->Log(_L("CheckLandmarkDbL"));
       
   336     
       
   337     if (aDb->IsInitializingNeeded()) ExecuteAndDeleteLD(aDb->InitializeL());
       
   338     
       
   339     CPosLmItemIterator* iter = aDb->LandmarkIteratorL();
       
   340     CleanupStack::PushL(iter);
       
   341     
       
   342     TInt size = iter->NumOfItemsL();
       
   343     TBuf<100> buf;
       
   344     buf.Format(_L("DB contains %d nr of landmarks"), size);
       
   345     iLog->Log(buf);
       
   346     
       
   347     TPosLmItemId id = iter->NextL();
       
   348 
       
   349     while (id != KPosLmNullItemId)
       
   350         {
       
   351         CPosLandmark* lm = aDb->ReadLandmarkLC(id);
       
   352         TPtrC name;
       
   353         lm->GetLandmarkName(name);
       
   354         // Debugging iLog->Log(name);
       
   355         id = iter->NextL();
       
   356         CleanupStack::PopAndDestroy(lm);
       
   357         }
       
   358         
       
   359     // Try to get an non existing landmark
       
   360     CPosLandmark* lm = NULL;
       
   361     TRAPD(err, lm = aDb->ReadLandmarkLC(123456));
       
   362     if (err != KErrNotFound) 
       
   363         {
       
   364         CleanupStack::PopAndDestroy(lm);
       
   365         CleanupStack::PopAndDestroy(iter);
       
   366         AssertTrueSecL(EFalse,_L("ReadLandmarkLC should leave with KErrNotFound"));
       
   367         }
       
   368     
       
   369     CleanupStack::PopAndDestroy(iter);
       
   370     
       
   371     // Check categories
       
   372     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*aDb);
       
   373     CleanupStack::PushL(categoryManager);
       
   374 	CPosLmItemIterator* catIter = categoryManager->CategoryIteratorL();
       
   375 	CleanupStack::PushL(catIter);
       
   376 	
       
   377 	TInt catCount = catIter->NumOfItemsL();
       
   378 
       
   379 	buf.Format(_L("Found %d nr of categories items in db"), catCount);
       
   380 	iLog->Log(buf);
       
   381 
       
   382 	id = catIter->NextL();
       
   383 	while (id != KPosLmNullItemId)
       
   384     	{
       
   385     	CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(id);
       
   386     	TPtrC name;
       
   387     	cat->GetCategoryName(name);
       
   388     	// Debugging iLog->Log(name);
       
   389     	CleanupStack::PopAndDestroy(cat);
       
   390     	id = catIter->NextL();
       
   391     	}
       
   392     
       
   393     CleanupStack::PopAndDestroy(catIter);
       
   394     CleanupStack::PopAndDestroy(categoryManager);
       
   395     }
       
   396     
       
   397 // ---------------------------------------------------------
       
   398 // CPosTp118::DeleteTp118FilesL
       
   399 //
       
   400 // (other items were commented in a header).
       
   401 // ---------------------------------------------------------
       
   402 //
       
   403 void CPosTp118::DeleteTp118FilesL()
       
   404 	{
       
   405 	iLog->Log(_L("DeleteTp118FilesL"));
       
   406     RFs fs;
       
   407     TInt err = fs.Connect();
       
   408     AssertTrueSecL(err == KErrNone, _L("fs.Connect returned with error"), err);
       
   409     CleanupClosePushL(fs);
       
   410 
       
   411     CFileMan* fileMan = CFileMan::NewL(fs);
       
   412     CleanupStack::PushL(fileMan);
       
   413     
       
   414     // delete all TP118 files
       
   415     err = fileMan->Delete(_L("c:\\private\\100012a5\\*TP118*.*"));
       
   416     AssertTrueSecL(err == KErrNone || err == KErrNotFound, _L("CFileMan could not delete files1"), err);
       
   417     
       
   418     err = fileMan->Delete(_L("c:\\private\\100012a5\\*TP118*"));
       
   419     AssertTrueSecL(err == KErrNone || err == KErrNotFound, _L("CFileMan could not delete files2"), err);
       
   420         
       
   421     CleanupStack::PopAndDestroy(1); //fileMan
       
   422     CleanupStack::PopAndDestroy(1); //fs
       
   423     iLog->Log(_L("DeleteTp118FilesL Done"));
       
   424     
       
   425 	}
       
   426 	
       
   427 // ---------------------------------------------------------
       
   428 // CPosTp118::CreateLandmarksInDbL
       
   429 //
       
   430 // (other items were commented in a header).
       
   431 // ---------------------------------------------------------
       
   432 //
       
   433 void CPosTp118::CreateLandmarksInDbL(const TDesC& aDbName, TInt aIndex)
       
   434 	{
       
   435 	iLog->Log(_L("CreateLandmarksInDbL"));
       
   436 	const TInt KNrOfLandmarks = 50;
       
   437 	const TInt KNrOfCategories = 10;
       
   438 	
       
   439 	CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(aDbName);
       
   440 	CleanupStack::PushL(lmd);
       
   441 	
       
   442     ExecuteAndDeleteLD(lmd->InitializeL());
       
   443     
       
   444     CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*lmd);
       
   445     CleanupStack::PushL(cm);
       
   446     
       
   447     RArray<TPosLmItemId> arr;
       
   448    	CleanupClosePushL(arr);
       
   449     TInt i=0;
       
   450     TBuf<150> buf;
       
   451     
       
   452     // Create categories
       
   453    	for (i=0; i<KNrOfCategories; i++)
       
   454    		{
       
   455     	CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC();
       
   456     	buf.Zero();
       
   457     	buf.Format(_L("VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongCategoryName%d_%d"), i, aIndex);
       
   458     	
       
   459     	category->SetCategoryNameL(buf);
       
   460     	TPosLmItemId id=0;
       
   461     	TInt err = KErrLocked;
       
   462     	while (err == KErrLocked)
       
   463     	    {
       
   464     	    TRAP(err, id = cm->AddCategoryL(*category));
       
   465     	    }
       
   466     	arr.Append(id);
       
   467     	CleanupStack::PopAndDestroy(category);
       
   468    		}
       
   469 
       
   470 	// Create landmarks and attach every category to every landmark
       
   471     for (i=0;i<KNrOfLandmarks;i++)
       
   472     	{
       
   473     	buf.Zero();
       
   474     	buf.Format(_L("VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongLandmarkName%d_%d"), i, aIndex);
       
   475     	CPosLandmark* lm1 = CPosLandmark::NewLC();
       
   476     	lm1->SetLandmarkNameL(buf);
       
   477     	lm1->SetLandmarkDescriptionL(_L("SomeVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription"));
       
   478     	for (TInt j=0;j<arr.Count();j++)
       
   479     		{
       
   480     		lm1->AddCategoryL(arr[j]);
       
   481     		}
       
   482    		TInt err = KErrLocked;
       
   483    		while (err==KErrLocked)
       
   484    		    {
       
   485    		    TRAP(err, lmd->AddLandmarkL(*lm1));
       
   486    		    }
       
   487    		
       
   488    		CleanupStack::PopAndDestroy(lm1);
       
   489    		}
       
   490    		   	
       
   491     CleanupStack::PopAndDestroy(&arr);
       
   492     
       
   493     CleanupStack::PopAndDestroy(cm);
       
   494     
       
   495     ExecuteAndDeleteLD(lmd->CompactL());
       
   496     CleanupStack::PopAndDestroy(lmd);
       
   497     
       
   498 	}
       
   499 	
       
   500 // ---------------------------------------------------------
       
   501 // CPosTp118::VerifyList
       
   502 //
       
   503 // (other items were commented in a header).
       
   504 // ---------------------------------------------------------
       
   505 //
       
   506 TBool CPosTp118::VerifyList(CDesCArray* aList, const TDesC& aDbName)
       
   507 	{
       
   508 	TBool found = EFalse;
       
   509 	TInt count = aList->Count();
       
   510 	TBuf<100> buf;
       
   511 	buf.Format(_L("Found %d nr of dbs"), count);
       
   512 	iLog->Log(buf);
       
   513 	for (TInt i=0;i<count;i++)
       
   514 		{
       
   515 		iLog->Log((*aList)[i]);
       
   516 		if ((*aList)[i].Compare(aDbName) == KErrNone)
       
   517 			{
       
   518 			found = ETrue;
       
   519 			}
       
   520 		}
       
   521 		return found;
       
   522 	}
       
   523     
       
   524 // ---------------------------------------------------------
       
   525 // CPosTp118::DropTableL
       
   526 //
       
   527 // (other items were commented in a header).
       
   528 // ---------------------------------------------------------
       
   529 //
       
   530 void CPosTp118::DropTableL(const TDesC& aDbName, const TDesC& aTable)
       
   531     {
       
   532     /*
       
   533     // Incremental
       
   534     iLog->Log(_L("DropTableL"));
       
   535     RDbs dbSession;
       
   536     CleanupClosePushL(dbSession);
       
   537     User::LeaveIfError(dbSession.Connect());
       
   538 
       
   539     RDbNamedDatabase db;
       
   540     CleanupClosePushL(db);
       
   541     TBuf<100> buf;
       
   542     
       
   543     TInt err = db.Open(dbSession, aDbName ,KPosLmDbSecureFormat);
       
   544     if (err != KErrNone) LogErrorAndLeave(_L("Database could not be opened"), err);
       
   545 
       
   546 	RDbIncremental dbInc;
       
   547 	CleanupClosePushL(dbInc);
       
   548 
       
   549     TInt step = 100;
       
   550     err = dbInc.DropTable(db, aTable, step);
       
   551     if (err != KErrNone) LogErrorAndLeave(_L("DropTable could not be performed"), err);
       
   552     
       
   553     while (step > 50)
       
   554     	{
       
   555     	buf.Format(_L("ProgressStep %d "), step);
       
   556     	iLog->Log(buf);
       
   557     	dbInc.Next(step);
       
   558     	}
       
   559     	
       
   560     dbInc.Close();
       
   561     db.Close();
       
   562     	
       
   563     CleanupStack::PopAndDestroy(&dbInc);
       
   564     CleanupStack::PopAndDestroy(&db);
       
   565     CleanupStack::PopAndDestroy(&dbSession);
       
   566     */
       
   567     
       
   568     iLog->Log(_L("DropTableL"));
       
   569     RDbs dbSession;
       
   570     CleanupClosePushL(dbSession);
       
   571     User::LeaveIfError(dbSession.Connect());
       
   572 
       
   573     RDbNamedDatabase db;
       
   574     CleanupClosePushL(db);
       
   575     TBuf<100> buf;
       
   576     
       
   577     TInt err = db.Open(dbSession, aDbName ,KPosLmDbSecureFormat);
       
   578     AssertTrueSecL(err == KErrNone, _L("Database could not be opened"), err);
       
   579     err = db.DropTable(aTable);
       
   580     AssertTrueSecL(err == KErrNone, _L("DropTable could not be performed"), err);
       
   581     db.Close();
       
   582     	
       
   583     CleanupStack::PopAndDestroy(&db);
       
   584     CleanupStack::PopAndDestroy(&dbSession);
       
   585 
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------
       
   589 // CPosTp118::AlterTableL
       
   590 //
       
   591 // (other items were commented in a header).
       
   592 // ---------------------------------------------------------
       
   593 //
       
   594 void CPosTp118::AlterTableL(const TDesC& aDbName)
       
   595     {
       
   596     iLog->Log(_L("AlterTableL"));
       
   597     // Incremental
       
   598     RDbs dbSession;
       
   599     CleanupClosePushL(dbSession);
       
   600     User::LeaveIfError(dbSession.Connect());
       
   601 
       
   602     RDbNamedDatabase db;
       
   603     CleanupClosePushL(db);
       
   604     
       
   605     TBuf<100> buf;
       
   606     
       
   607     TInt err = db.Open(dbSession, aDbName ,KPosLmDbSecureFormat);
       
   608     AssertTrueSecL(err == KErrNone, _L("Database could not be opened"), err);
       
   609 
       
   610 	RDbIncremental dbInc;
       
   611 	CleanupClosePushL(dbInc);
       
   612 	    
       
   613     
       
   614     CDbColSet* newColumns = CDbColSet::NewLC();
       
   615 
       
   616     TDbCol col(KPosLmIconIdCol, EDbColUint32);
       
   617     col.iAttributes = col.EAutoIncrement;
       
   618     newColumns->AddL(col);
       
   619 
       
   620     newColumns->AddL(TDbCol(KPosLmIconPathCol, EDbColLongText, KMaxFileName));
       
   621     //User::LeaveIfError(aDb.CreateTable(KPosLmIconTable, *columns));
       
   622     
       
   623     TInt step = 100;
       
   624     err = dbInc.AlterTable(db, KPosLmIconTable, *newColumns, step);
       
   625     if (err != KErrNone) 
       
   626     {
       
   627     TBuf<100> buf;
       
   628     buf.Format(_L("AlterTable could not be performed, err %d"), err);
       
   629     iLog->Log(buf);
       
   630     }
       
   631     else
       
   632     {
       
   633     
       
   634     while (step > 1)
       
   635     	{
       
   636     	buf.Format(_L("ProgressStep %d "), step);
       
   637     	iLog->Log(buf);
       
   638     	dbInc.Next(step);
       
   639     	}
       
   640     }	
       
   641     dbInc.Close();
       
   642     db.Close();
       
   643     
       
   644     CleanupStack::PopAndDestroy(newColumns);	
       
   645     CleanupStack::PopAndDestroy(&dbInc);
       
   646     CleanupStack::PopAndDestroy(&db);
       
   647     CleanupStack::PopAndDestroy(&dbSession);
       
   648     /*
       
   649     
       
   650     RDbs dbSession;
       
   651     CleanupClosePushL(dbSession);
       
   652     User::LeaveIfError(dbSession.Connect());
       
   653 
       
   654     RDbNamedDatabase db;
       
   655     CleanupClosePushL(db);
       
   656     
       
   657     TBuf<100> buf;
       
   658     
       
   659     TInt err = db.Open(dbSession, aDbName ,KPosLmDbSecureFormat);
       
   660     if (err != KErrNone) LogErrorAndLeave(_L("Database could not be opened"), err);
       
   661     
       
   662     
       
   663     CDbColSet* newColumns = CDbColSet::NewLC();
       
   664 
       
   665     TDbCol col(KPosLmIconIdCol, EDbColUint32);
       
   666     col.iAttributes = col.EAutoIncrement;
       
   667     newColumns->AddL(col);
       
   668 
       
   669     newColumns->AddL(TDbCol(KPosLmIconPathCol, EDbColLongText, KMaxFileName));
       
   670     //User::LeaveIfError(aDb.CreateTable(KPosLmIconTable, *columns));
       
   671     
       
   672     TInt step = 100;
       
   673     err = db.AlterTable(KPosLmIconTable, *newColumns);
       
   674     if (err != KErrNone) 
       
   675         {
       
   676         TBuf<100> buf;
       
   677         buf.Format(_L("AlterTable could not be performed, err %d"), err);
       
   678         iLog->Log(buf);
       
   679         }
       
   680 
       
   681     db.Close();
       
   682     
       
   683     CleanupStack::PopAndDestroy(newColumns);	
       
   684     CleanupStack::PopAndDestroy(&db);
       
   685     CleanupStack::PopAndDestroy(&dbSession);
       
   686     */
       
   687     }
       
   688     
       
   689         
       
   690 // ---------------------------------------------------------
       
   691 // CPosTp118::DropIndexL
       
   692 //
       
   693 // (other items were commented in a header).
       
   694 // ---------------------------------------------------------
       
   695 //
       
   696 void CPosTp118::DropIndexL(const TDesC& aDbName, const TDesC& aTable, const TDesC& aIndex)
       
   697     {
       
   698     iLog->Log(_L("DropIndexL()"));
       
   699     
       
   700     //Incremental
       
   701     RDbs dbSession;
       
   702     CleanupClosePushL(dbSession);
       
   703     User::LeaveIfError(dbSession.Connect());
       
   704 
       
   705     RDbNamedDatabase db;
       
   706     CleanupClosePushL(db);
       
   707     TBuf<100> buf;
       
   708     
       
   709     TInt err = db.Open(dbSession, aDbName ,KPosLmDbSecureFormat);
       
   710     AssertTrueSecL(err == KErrNone, _L("Database could not be opened"), err);
       
   711 
       
   712 	RDbIncremental dbInc;
       
   713 	CleanupClosePushL(dbInc);
       
   714 
       
   715     TInt step = 100;
       
   716     err = dbInc.DropIndex(db, aIndex, aTable, step);
       
   717     AssertTrueSecL(err == KErrNone, _L("DropIndex could not be performed"), err);
       
   718     
       
   719     while (step  > 1)
       
   720     	{
       
   721     	buf.Format(_L("ProgressStep %d "), step);
       
   722     	iLog->Log(buf);
       
   723     	dbInc.Next(step);
       
   724     	}
       
   725     	
       
   726     CleanupStack::PopAndDestroy(&dbInc);
       
   727     CleanupStack::PopAndDestroy(&db);
       
   728     CleanupStack::PopAndDestroy(&dbSession);
       
   729     
       
   730     /*
       
   731     RDbs dbSession;
       
   732     CleanupClosePushL(dbSession);
       
   733     User::LeaveIfError(dbSession.Connect());
       
   734 
       
   735     RDbNamedDatabase db;
       
   736     CleanupClosePushL(db);
       
   737     TBuf<100> buf;
       
   738     
       
   739     TInt err = db.Open(dbSession, aDbName ,KPosLmDbSecureFormat);
       
   740     if (err != KErrNone) LogErrorAndLeave(_L("Database could not be opened"), err);
       
   741 
       
   742     TInt step = 100;
       
   743     err = db.DropIndex(aIndex, aTable);
       
   744     if (err != KErrNone) LogErrorAndLeave(_L("DropIndex could not be performed"), err);
       
   745     	
       
   746     CleanupStack::PopAndDestroy(&db);
       
   747     CleanupStack::PopAndDestroy(&dbSession);
       
   748     */
       
   749     }
       
   750 
       
   751 //  End of File