landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp103.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 
       
    22 #include "FT_CPosTp103.h"
       
    23 #include <EPos_CPosLandmarkDatabase.h>
       
    24 #include <EPos_CPosLmDatabaseManager.h>
       
    25 #include <EPos_CPosLmTextCriteria.h>
       
    26            
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ---------------------------------------------------------
       
    30 // CPosTp103::CloseTest
       
    31 //
       
    32 // (other items were commented in a header).
       
    33 // ---------------------------------------------------------
       
    34 //
       
    35 void CPosTp103::CloseTest()
       
    36     {
       
    37 	iLog->Log(_L("CloseTest"));
       
    38 	
       
    39     TRAPD(err, RemoveAllLmDatabasesL());
       
    40     if (err != KErrNone) iLog->Log(_L("RemoveAllLmDatabasesL() leaved"));
       
    41     }
       
    42     
       
    43 // ---------------------------------------------------------
       
    44 // CPosTp103::StartL
       
    45 //
       
    46 // (other items were commented in a header).
       
    47 // ---------------------------------------------------------
       
    48 //
       
    49 void CPosTp103::StartL()
       
    50     {
       
    51     // TInt expNrOfDbs = 0;
       
    52 
       
    53     RemoveAllLmDatabasesL();
       
    54 
       
    55     TestPartCopyDatabasesL();
       
    56 	}
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CPosTp103::TestPartCopyDatabasesL
       
    60 //
       
    61 // (other items were commented in a header).
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 void CPosTp103::TestPartCopyDatabasesL()
       
    65     {
       
    66     iLog->Log(_L("TestPartCopyDatabasesL"));
       
    67 
       
    68     _LIT(KDbName1, "TP103_Database1.ldb");
       
    69     _LIT(KDbNameNonExisting, "NonExisting_TP103_Database1.ldb");
       
    70     _LIT(KDbNameCopy1, "file://C:TP103_DATABASE1COPY1.LDB");
       
    71     _LIT(KDbNameCopy5, "file://C:TP103_DATABASE2COPY5.LDB");
       
    72     _LIT(KDbNameCopy6, "file://C:TP103_DATABASE2COPY6.LDB");
       
    73     
       
    74     _LIT(KDbName7MissingDrive, "file://TP103_DATABASE7.LDB");
       
    75     _LIT(KDbName7, "file://C:TP103_DATABASE7.LDB");
       
    76     
       
    77     // DB on drive that does no exist
       
    78     _LIT(KDbName8, "file://R:TP103_DATABASE8.LDB");
       
    79     _LIT(KDbName8_1, "file://C:TP103_DATABASE8_1.LDB");
       
    80     
       
    81     _LIT(KDefaultCopyDb, "CopyOfDefaultDb.ldb");
       
    82     _LIT(KDefaultCopyDbUri, "file://C:CopyOfDefaultDb.ldb");
       
    83     
       
    84     _LIT(KDbSourceNameMissingExtension, "file://C:TP103_DATABASE2COPY6");
       
    85     _LIT(KDbTargetNameMissingExtension, "file://C:TP103_DATABASE2COPY_666");
       
    86     
       
    87     _LIT(KRemoteDatabaseUri, "http://RemoteLmDb.ldb");
       
    88     
       
    89 #ifdef __WINS__
       
    90 	// D on wins
       
    91 	_LIT(KDbNameCopy2, "file://D:TP103_DATABASE1COPY2.LDB");
       
    92 	_LIT(KDbNameCopy2MissingDrive, "file://TP103_DATABASE1COPY2.LDB");
       
    93     _LIT(KDbNameCopy3, "file://D:TP103_DATABASE1COPY3.LDB");
       
    94 #else	
       
    95     _LIT(KDbNameCopy2, "file://F:TP103_DATABASE1COPY2.LDB");
       
    96     _LIT(KDbNameCopy2MissingDrive, "file://TP103_DATABASE1COPY2.LDB");
       
    97     _LIT(KDbNameCopy3, "file://F:TP103_DATABASE1COPY3.LDB");
       
    98 #endif
       
    99     _LIT(KDbNameCopy4, "file://C:TP103_DATABASE1COPY4.LDB");
       
   100 
       
   101     _LIT(KDbNameEmptyUri1, "");
       
   102     _LIT(KDbNameEmptyUri2, "file://c");
       
   103 
       
   104     _LIT(KDummyDb, "file://SomeDummyDbName.ldb");
       
   105     TInt err = KErrNone;
       
   106 
       
   107     iLog->Log(_L("Warning: this test case requires E: drive"));
       
   108     
       
   109     CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL();
       
   110     CleanupStack::PushL(dbManager);
       
   111 
       
   112     // check the count of databases that could not be delted since they were in use
       
   113     CDesCArray* dbList = dbManager->ListDatabasesLC();
       
   114     TInt count = dbList->Count();
       
   115     TInt verifyDbcount;
       
   116     
       
   117     // 1) Create a new database
       
   118     HPosLmDatabaseInfo* dbInfo1 = HPosLmDatabaseInfo::NewLC(KDbName1);
       
   119     dbManager->CreateDatabaseL(*dbInfo1);
       
   120     CPosLandmarkDatabase* db1 = CPosLandmarkDatabase::OpenL(KDbName1);
       
   121     CleanupStack::PopAndDestroy(dbInfo1);
       
   122     CleanupStack::PushL(db1);
       
   123     if (db1->IsInitializingNeeded())
       
   124         {
       
   125         iLog->Log(_L("db1->InitializeL"));
       
   126         ExecuteAndDeleteLD(db1->InitializeL());
       
   127         }
       
   128     CleanupStack::PopAndDestroy(db1);
       
   129     
       
   130     // 2) Copy db to file system, include file:// in URI
       
   131     dbManager->CopyDatabaseL(KDbName1, KDbNameCopy1);
       
   132 
       
   133     // 3) Copy db to removable media, include file:// in URI
       
   134     dbManager->CopyDatabaseL(KDbName1, KDbNameCopy2);
       
   135 
       
   136     // 4) Copy the db on removable media to removable media
       
   137     dbManager->CopyDatabaseL(KDbNameCopy2, KDbNameCopy3);
       
   138 
       
   139     // 5) Copy the db from removable media to c drive
       
   140     dbManager->CopyDatabaseL(KDbNameCopy2, KDbNameCopy4);
       
   141 
       
   142     // 6) Verify that the four databases (copied in step 2-5) exists
       
   143     if (!dbManager->DatabaseExistsL(KDbNameCopy1)) 
       
   144     {
       
   145     	iLog->Log(_L("DatabaseCopy1 should exist"));
       
   146     	User::Leave(-1);
       
   147     }
       
   148     if (!dbManager->DatabaseExistsL(KDbNameCopy2))
       
   149     {
       
   150     	iLog->Log(_L("DatabaseCopy2 should exist"));
       
   151     	User::Leave(-1);
       
   152     }
       
   153     if (!dbManager->DatabaseExistsL(KDbNameCopy3))
       
   154     {
       
   155     	iLog->Log(_L("DatabaseCopy3 should exist"));
       
   156     	User::Leave(-1);
       
   157     }
       
   158     if (!dbManager->DatabaseExistsL(KDbNameCopy4))
       
   159     {
       
   160     	iLog->Log(_L("DatabaseCopy4 should exist"));
       
   161     	User::Leave(-1);
       
   162     }
       
   163 
       
   164     // 7) Repat step 5, but this time should the target of the copy operation exist
       
   165     TRAP(err, dbManager->CopyDatabaseL(KDbNameCopy2, KDbNameCopy4));
       
   166     if (err != KErrAlreadyExists) 
       
   167     {
       
   168     	iLog->Log(_L("CopyDatabaseL should leave with KErrAlreadyExists"));
       
   169     	User::Leave(err);
       
   170     }
       
   171 
       
   172     // 8) Take a read lock (using a search operation) on db and try to copy it
       
   173     CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(KDbNameCopy2);
       
   174     CleanupStack::PushL(lmd);
       
   175     
       
   176     if (lmd->IsInitializingNeeded())
       
   177         {
       
   178         ExecuteAndDeleteLD(lmd->InitializeL()); 
       
   179         }
       
   180         
       
   181     CPosLandmarkSearch* landmarkSearch = CPosLandmarkSearch::NewL(*lmd);
       
   182     CleanupStack::PushL(landmarkSearch);
       
   183     
       
   184     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   185     textCriteria->SetTextL(_L("*"));
       
   186     iOperation = landmarkSearch->StartLandmarkSearchL(*textCriteria, EFalse);
       
   187     
       
   188     // Try to copy db with read lock
       
   189     TRAP(err, dbManager->CopyDatabaseL(KDbNameCopy2, KDbNameCopy5));
       
   190     if (err != KErrInUse)
       
   191     {
       
   192     	iLog->Log(_L("8) Copy should leave with KErrInUse"));
       
   193     	User::Leave(err);
       
   194     }
       
   195     ExecuteAndDeleteLD(iOperation);
       
   196         
       
   197     // 9) Take a write lock on db and try to copy it
       
   198     iOperation = lmd->RemoveAllLandmarksL();
       
   199     TRAP(err, dbManager->CopyDatabaseL(KDbNameCopy2, KDbNameCopy6));
       
   200     if (err != KErrLocked) iLog->Log(_L("9) Copy should leave with KErrLocked"));
       
   201     ExecuteAndDeleteLD(iOperation);
       
   202     
       
   203     CleanupStack::PopAndDestroy(textCriteria);
       
   204     CleanupStack::PopAndDestroy(landmarkSearch);
       
   205     CleanupStack::PopAndDestroy(lmd);
       
   206 
       
   207     // 10) Try to copy a database that does not exist
       
   208     TRAP(err, dbManager->CopyDatabaseL(KDbNameNonExisting, _L("DummyTarget.ldb")));
       
   209     if (err != KErrNotFound) 
       
   210     {
       
   211     	iLog->Log(_L("10) CopyDatabaseL should leave with KErrNotFound"));
       
   212     	User::Leave(err);
       
   213     }
       
   214     
       
   215     // 11) Try to copy an existing db to a nonexisting path/target
       
   216     TRAP(err, dbManager->CopyDatabaseL(KDbName1, _L("c://pelle//DummyTarget.ldb")));
       
   217     if (err != KErrArgument)
       
   218     {
       
   219     	iLog->Log(_L("11) CopyDatabaseL should leave with KErrNotFound"));
       
   220     	User::Leave(err);
       
   221     }
       
   222 
       
   223     // 12) Try to copy an existing db to remote path/target
       
   224     TRAP(err, dbManager->CopyDatabaseL(KDbName1, KRemoteDatabaseUri));
       
   225     if (err != KErrArgument) //LogErrorAndLeave(_L("12) CopyDatabaseL should leave with KErrBadName"));
       
   226     {
       
   227     	iLog->Log(_L("12) CopyDatabaseL should leave with KErrBadName"));
       
   228     	User::Leave(err);
       
   229     }
       
   230     
       
   231     // 13) Try to copy a db on c drive without specifying a drive in the source uri
       
   232     dbManager->CopyDatabaseL(KDbName1, KDbNameCopy5);
       
   233     verifyDbcount = count +6;
       
   234     VerifyNrOfDatabasesL(verifyDbcount, KDbNameCopy5);
       
   235 
       
   236     // 14) Try to copy a db on removable media drive without specifying the drive in the source uri
       
   237     TRAP(err, dbManager->CopyDatabaseL(KDbNameCopy2MissingDrive, KDummyDb));
       
   238     if (err != KErrNotFound)
       
   239     {
       
   240     	iLog->Log(_L(" CopyDatabaseL should leave with KErrNotFound"));
       
   241     	User::Leave(err);
       
   242     }
       
   243 
       
   244     // 15) Try to copy a db on removable media drive without specifying the drive in the target uri
       
   245     if (!dbManager->DatabaseExistsL(KDbNameCopy2)) 
       
   246     {
       
   247     	iLog->Log(_L("DatabaseCopy2 should exist"));
       
   248     	User::Leave(KErrNone);	
       
   249     }
       
   250     TRAP(err, dbManager->CopyDatabaseL(KDbNameCopy2, KDbName7MissingDrive));
       
   251     if (err != KErrNone) 
       
   252     {
       
   253     	iLog->Log(_L("KDbNameCopy2 should be copied"));
       
   254     	User::Leave(err);
       
   255     }
       
   256     verifyDbcount = count + 7;
       
   257     VerifyNrOfDatabasesL(verifyDbcount, KDbName7);
       
   258 
       
   259     // 16) Try to copy without .ldb in source URI
       
   260     TRAP(err, dbManager->CopyDatabaseL(KDbSourceNameMissingExtension,  _L("DummyTarget.ldb")));
       
   261     if (err != KErrArgument) 
       
   262     {
       
   263     	iLog->Log(_L("CopyDatabaseL should leave with KErrArgument"));
       
   264     	User::Leave(err);	
       
   265     }
       
   266 
       
   267     // 17) Try to copy without .ldb in target URI
       
   268     TRAP(err, dbManager->CopyDatabaseL(KDbName1, KDbTargetNameMissingExtension));
       
   269     if (err != KErrArgument) 
       
   270     {
       
   271     	iLog->Log(_L("CopyDatabaseL should leave with XXX"));
       
   272     	User::Leave(err);
       
   273     }
       
   274 
       
   275     // 18) Try to copy db to itself
       
   276     TRAP(err, dbManager->CopyDatabaseL(KDbName1, KDbName1));
       
   277     if (err != KErrAlreadyExists) 
       
   278     {
       
   279     	iLog->Log(_L("CopyDatabaseL should leave with KErrAlreadyExists"));
       
   280     	User::Leave(err);
       
   281     }
       
   282 
       
   283     // 19) Try to copy db to itself XXX Should be removed, same as step18
       
   284     TRAP(err, dbManager->CopyDatabaseL(KDbName1, KDbName1));
       
   285     if (err != KErrAlreadyExists) 
       
   286     {
       
   287     	iLog->Log(_L("CopyDatabaseL should leave with KErrAlreadyExists"));
       
   288     	User::Leave(err);
       
   289     }
       
   290 
       
   291     // 20) Try to copy db with empty target URI
       
   292     TRAP(err, dbManager->CopyDatabaseL(KDbName1, KDbNameEmptyUri1));
       
   293     if (err != KErrArgument)
       
   294     {
       
   295     	iLog->Log(_L("20a) CopyDatabaseL should leave with KErrArgument"));
       
   296     	User::Leave(err);
       
   297     }
       
   298     TRAP(err, dbManager->CopyDatabaseL(KDbName1, KDbNameEmptyUri2));
       
   299     if (err != KErrArgument)
       
   300     {
       
   301     	iLog->Log(_L("20b) CopyDatabaseL should leave with KErrArgument"));
       
   302     	User::Leave(err);
       
   303     }
       
   304 
       
   305     // 21) Try to copy db with empty source URI
       
   306     TRAP(err, dbManager->CopyDatabaseL(KDbNameEmptyUri1, KDummyDb));
       
   307     if (err != KErrArgument)
       
   308     {
       
   309     	iLog->Log(_L("21a) CopyDatabaseL should leave with KErrArgument"));
       
   310     	User::Leave(err);
       
   311     }
       
   312     TRAP(err, dbManager->CopyDatabaseL(KDbNameEmptyUri2, KDummyDb));
       
   313     if (err != KErrArgument)
       
   314     {
       
   315     	iLog->Log(_L("21b) CopyDatabaseL should leave with KErrArgument"));
       
   316     	User::Leave(err);
       
   317     }
       
   318 
       
   319     // 22) Try to copy db with target URI that is longer than allowed
       
   320     TRAP(err, dbManager->CopyDatabaseL(_L("c:\\SomeVeryLongFilename1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.ldb"), KDummyDb));
       
   321     if (err != KErrArgument)
       
   322     {
       
   323     	iLog->Log(_L("22) CopyDatabaseL should leave with KErrArgument"));
       
   324     	User::Leave(err);
       
   325     }
       
   326 
       
   327     // 23) Try to copy db with source URI that is longer than allowed
       
   328 	TRAP(err, dbManager->CopyDatabaseL(KDbName1, _L("c:\\SomeVeryLongFilename1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.ldb")));
       
   329     if (err != KErrArgument) 
       
   330     {
       
   331     	iLog->Log(_L("23) CopyDatabaseL should leave with KErrArgument"));
       
   332     	User::Leave(err);
       
   333     }
       
   334 
       
   335     // 24) Try to copy the default db
       
   336     dbManager->SetDefaultDatabaseUriL(KDbName7);
       
   337     HBufC* defaultDbUri;
       
   338     defaultDbUri = dbManager->DefaultDatabaseUriLC();    
       
   339     dbManager->CopyDatabaseL(*defaultDbUri, KDefaultCopyDb);
       
   340 
       
   341     verifyDbcount = count + 8;
       
   342     VerifyNrOfDatabasesL(verifyDbcount, KDefaultCopyDbUri);
       
   343     
       
   344     // 25) Delete default db and then copy a new db to its location
       
   345     dbManager->DeleteDatabaseL(*defaultDbUri);
       
   346     dbManager->CopyDatabaseL(KDefaultCopyDbUri, *defaultDbUri);
       
   347     verifyDbcount = count + 8;
       
   348     VerifyNrOfDatabasesL(verifyDbcount , KDefaultCopyDbUri);
       
   349     VerifyNrOfDatabasesL(verifyDbcount , *defaultDbUri);
       
   350     
       
   351     // 26) Try to copy a db on a drive that does not exist
       
   352     TRAP(err, dbManager->CopyDatabaseL(KDbName8, KDbName8_1));
       
   353     if (err != KErrNotReady)
       
   354     {
       
   355     	iLog->Log(_L("26) CopyDatabaseL should leave with KErrNotReady"));
       
   356     	User::Leave(err);
       
   357     }
       
   358     VerifyNrOfDatabasesL(verifyDbcount, KDefaultCopyDbUri);
       
   359         
       
   360     // 27) Try to copy defaultdb to db with long filenames
       
   361     _LIT(KLongFileName, "file://C:ABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRST.ldb");
       
   362     
       
   363     TRAP(err, dbManager->CopyDatabaseL(KDefaultCopyDbUri, KLongFileName));
       
   364     if (err != KErrArgument) 
       
   365     {
       
   366     	iLog->Log(_L("27) CopyDatabaseL should leave"));
       
   367     	User::Leave(err);
       
   368     }
       
   369     
       
   370     VerifyNrOfDatabasesL(verifyDbcount);
       
   371     
       
   372     // 28) Try to copy db with long file name
       
   373     TRAP(err, dbManager->CopyDatabaseL(KLongFileName, _L("SomeDummyFile.ldb")));
       
   374     if (err != KErrArgument)
       
   375     {
       
   376     	iLog->Log(_L("28) CopyDatabaseL should leave "));
       
   377     	User::Leave(err);
       
   378     }
       
   379     VerifyNrOfDatabasesL(verifyDbcount);
       
   380     
       
   381 	CleanupStack::PopAndDestroy(defaultDbUri);
       
   382 	CleanupStack::PopAndDestroy(dbList);
       
   383 	CleanupStack::PopAndDestroy(dbManager);
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------
       
   387 // CPosTp103::VerifyNrOfDatabasesL
       
   388 //
       
   389 // (other items were commented in a header).
       
   390 // ---------------------------------------------------------
       
   391 //
       
   392 void CPosTp103::VerifyNrOfDatabasesL(TInt aExpNrOfDatabases, const TDesC&  aDatabaseUri)
       
   393     {
       
   394     iLog->Log(_L("VerifyNrOfDatabasesL"));
       
   395     CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL();
       
   396     CleanupStack::PushL(dbManager);
       
   397 
       
   398     CDesCArray* dbArray = dbManager->ListDatabasesLC();
       
   399     TInt nr = dbArray->Count();
       
   400     if (nr != aExpNrOfDatabases) 
       
   401         {
       
   402         CleanupStack::PopAndDestroy(dbArray);
       
   403     	CleanupStack::PopAndDestroy(dbManager);
       
   404     
       
   405         TBuf<100> buf;
       
   406         buf.Format(_L("Wrong number of databases, was %d, should be %d"), nr, aExpNrOfDatabases);
       
   407        
       
   408         iLog->Log(buf);
       
   409     	User::Leave(-1);
       
   410         }
       
   411         
       
   412     TBool found = EFalse;
       
   413     if (aDatabaseUri != KNullDesC)
       
   414     	{
       
   415     	for (TInt i=0;i<nr;i++)
       
   416     		{
       
   417     		iLog->Log((*dbArray)[i]);
       
   418     		if ((*dbArray)[i].Compare(aDatabaseUri) == KErrNone) 
       
   419     		{
       
   420     		found = ETrue;
       
   421     		}
       
   422     		}
       
   423     	}
       
   424 
       
   425 	CleanupStack::PopAndDestroy(dbArray);
       
   426     CleanupStack::PopAndDestroy(dbManager);
       
   427     
       
   428     if (aDatabaseUri != KNullDesC && !found) 
       
   429     {
       
   430     	iLog->Log(_L("Database was not found"));
       
   431     	User::Leave(KErrNotFound);
       
   432     }
       
   433     }
       
   434     
       
   435 //  End of File