landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp111.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_CPosTp111.h"
       
    23 #include <f32file.h>
       
    24 #include <CentralRepository.h>
       
    25 #include <EPos_CPosLmDatabaseManager.h>
       
    26 
       
    27 // CONSTANTS
       
    28 const TUid KCRUidLandmarks = {0x101FE99B}; 
       
    29 const TUint32 KLandmarkDefaultUri = 0x00000001;
       
    30 _LIT(KFactoryDbUri, "file://c:eposlm.ldb");
       
    31 //_LIT(KRepositoryFile, "c:\\private\\10202BE9\\[101FE99B].txt"); // 10202BE9 = SID for Central repository
       
    32 _LIT(KRepositoryFile, "c:\\private\\10202BE9\\101FE99B.txt"); // 10202BE9 = SID for Central repository
       
    33 
       
    34 // Resource files
       
    35 //_LIT(KDefaultDbNameRsc, "eposlmdefaultdbname.rsc");
       
    36 //_LIT(KDefaultDbRsc, "eposlmdefaultdb.rsc");
       
    37 _LIT(KCompactDbLevelRsc, "eposlmcompactdblevel.rsc");
       
    38 //_LIT(KInternalServicesRsc, "eposlmintservices.rsc");
       
    39 _LIT(KGlobalCategoriesRsc, "eposlmglobalcategories.r01");
       
    40 _LIT(KAsynchOperationsRsc, "eposlmasyncops.rsc");
       
    41 
       
    42 // Resource files owned by process
       
    43 _LIT(KLmServerRsc, "eposlmserver.rsc");
       
    44 
       
    45 // ECom plugins
       
    46 //_LIT(KConverterRsc, "101FDF85.rsc");
       
    47 //_LIT(KLocalAccessProvRsc, "101FDF89.rsc");
       
    48 //_LIT(KLocalDbManagerProvRsc, "101FE977.rsc");
       
    49 //_LIT(KLocalSearchProvRsc, "101FDF86.rsc");
       
    50 
       
    51 // Libraries
       
    52 _LIT(KLandmarksDll, "eposlandmarks.dll");
       
    53 _LIT(KLocalSearchDll, "eposlmsearchlib.dll");
       
    54 _LIT(KXmlConverterDll, "eposlmconverter.dll");
       
    55 _LIT(KDbManagerDll, "eposlmdbmanlib.dll");
       
    56 _LIT(KIntServicesDll, "eposlmintservices.dll");
       
    57 _LIT(KLocalAccessDll, "eposlmlocalaccess.dll");
       
    58 _LIT(KLocalAccessProvDll, "eposlmlocalaccessprovider.dll");
       
    59 _LIT(KLocalDbManProvDll, "eposlmlocaldbmanprovider.dll");
       
    60 _LIT(KLocalSearchProvDll, "eposlmlocalsearchprovider.dll");
       
    61 _LIT(KMultiDbSearchDll, "eposlmmultidbsearch.dll");
       
    62 _LIT(KRecognizer, "eposlmrecognizer.dll");
       
    63 _LIT(KLmServer, "eposlmserver.exe");
       
    64 // KDummyDll should not be found! Only used to generate language sensitive 
       
    65 // resource file for global categories. Removed during build process.
       
    66 // _LIT(KDummyDll, "eposlandmarks_dummy.dll");
       
    67 
       
    68 // ================= MEMBER FUNCTIONS =======================
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // CPosTp111::GetName
       
    72 //
       
    73 // (other items were commented in a header).
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 void CPosTp111::GetName(TDes& aName) const
       
    77     {
       
    78     _LIT(KTestName, "TP111 - Data caging and central repository");
       
    79     aName = KTestName;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------
       
    83 // CPosTp111::StartL
       
    84 //
       
    85 // (other items were commented in a header).
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 void CPosTp111::StartL()
       
    89     {
       
    90 #ifdef __WINS__
       
    91     LogErrorAndLeave(_L("This is a target test! Emulator execution is not supported."), KErrNotSupported);
       
    92 #endif
       
    93     
       
    94     // TC step 1
       
    95     iLog->Put(_L("TC step 1"));
       
    96     TBool testSuccessful = FindResourceFilesL();
       
    97     
       
    98     // TC step 2
       
    99     iLog->Put(_L("TC step 2"));
       
   100     TBool subTestSuccessful = FindServerResourceFilesL();
       
   101     if (testSuccessful)
       
   102         {
       
   103         testSuccessful = subTestSuccessful;
       
   104         }
       
   105     
       
   106     // TC step 3
       
   107     /*
       
   108     iLog->Put(_L("TC step 3"));
       
   109     subTestSuccessful = FindEcomPluginsL();
       
   110     if (testSuccessful)
       
   111         {
       
   112         testSuccessful = subTestSuccessful;
       
   113         }
       
   114     */
       
   115     
       
   116     // TC step 4
       
   117     iLog->Put(_L("TC step 4"));
       
   118     subTestSuccessful = FindLibrariesL();
       
   119     if (testSuccessful)
       
   120         {
       
   121         testSuccessful = subTestSuccessful;
       
   122         }
       
   123         
       
   124     // TC steps 5-13
       
   125     iLog->Put(_L("TC step 5-13"));
       
   126     TestCentralRepositoryL();    
       
   127     
       
   128     // Summarize
       
   129     if (!testSuccessful)
       
   130         {
       
   131         LogErrorAndLeave(_L("Test failed with errors"));
       
   132         }
       
   133 	}
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CPosTp111::FindResourceFilesL
       
   137 //
       
   138 // (other items were commented in a header).
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 TBool CPosTp111::FindResourceFilesL()
       
   142     {
       
   143     iLog->Put(_L("FindResourceFilesL"));
       
   144     CDesCArray* rscFiles = new (ELeave) CDesCArrayFlat(8);
       
   145     CleanupStack::PushL(rscFiles);
       
   146     //rscFiles->AppendL(KDefaultDbNameRsc);
       
   147     //rscFiles->AppendL(KDefaultDbRsc);
       
   148     rscFiles->AppendL(KCompactDbLevelRsc);
       
   149     //rscFiles->AppendL(KInternalServicesRsc);
       
   150     rscFiles->AppendL(KGlobalCategoriesRsc);
       
   151     rscFiles->AppendL(KAsynchOperationsRsc);
       
   152    
       
   153     _LIT(KExpectedPath, "\\resource\\");
       
   154     
       
   155     TBool result = FindFilesAndVerifyPathL(*rscFiles, KExpectedPath);
       
   156 
       
   157     CleanupStack::PopAndDestroy(rscFiles);
       
   158     return result;
       
   159     }
       
   160     
       
   161 // ---------------------------------------------------------
       
   162 // CPosTp111::FindServerResourceFilesL
       
   163 //
       
   164 // (other items were commented in a header).
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 TBool CPosTp111::FindServerResourceFilesL()
       
   168     {
       
   169     iLog->Put(_L("FindServerResourceFilesL"));
       
   170     CDesCArray* rscFiles = new (ELeave) CDesCArrayFlat(8);
       
   171     CleanupStack::PushL(rscFiles);
       
   172     rscFiles->AppendL(KLmServerRsc);
       
   173    
       
   174     // To be updated when SID is known
       
   175     _LIT(KExpectedPath, "\\private\\101FDF81\\");
       
   176     
       
   177     TBool result = FindFilesAndVerifyPathL(*rscFiles, KExpectedPath);
       
   178 
       
   179     CleanupStack::PopAndDestroy(rscFiles);
       
   180     return result;
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------
       
   184 // CPosTp111::FindEcomPluginsL
       
   185 //
       
   186 // (other items were commented in a header).
       
   187 // ---------------------------------------------------------
       
   188 //
       
   189 TBool CPosTp111::FindEcomPluginsL()
       
   190     {
       
   191     iLog->Put(_L("FindEcomPluginsL"));
       
   192     CDesCArray* ecomPlugins = new (ELeave) CDesCArrayFlat(8);
       
   193     CleanupStack::PushL(ecomPlugins);
       
   194     //ecomPlugins->AppendL(KConverterRsc);
       
   195     //ecomPlugins->AppendL(KLocalAccessProvRsc);
       
   196     //ecomPlugins->AppendL(KLocalDbManagerProvRsc);
       
   197     //ecomPlugins->AppendL(KLocalSearchProvRsc);
       
   198     
       
   199     // To be updated with correct SID
       
   200     _LIT(KExpectedPath, "\\private\\101FDF81\\import\\"); // 101FDF81 = SID for LM srv
       
   201     
       
   202     TBool result = FindFilesAndVerifyPathL(*ecomPlugins, KExpectedPath);
       
   203 
       
   204     CleanupStack::PopAndDestroy(ecomPlugins);
       
   205     return result;
       
   206     }    
       
   207 
       
   208 
       
   209 // ---------------------------------------------------------
       
   210 // CPosTp111::FindLibrariesL
       
   211 //
       
   212 // (other items were commented in a header).
       
   213 // ---------------------------------------------------------
       
   214 //
       
   215 TBool CPosTp111::FindLibrariesL()
       
   216     {
       
   217     iLog->Put(_L("FindLibrariesL"));
       
   218     CDesCArray* libraries = new (ELeave) CDesCArrayFlat(8);
       
   219     CleanupStack::PushL(libraries);
       
   220     libraries->AppendL(KLandmarksDll);
       
   221     libraries->AppendL(KLocalSearchDll);
       
   222     libraries->AppendL(KXmlConverterDll);
       
   223     libraries->AppendL(KDbManagerDll);
       
   224     libraries->AppendL(KIntServicesDll);
       
   225     libraries->AppendL(KLocalAccessDll);
       
   226     libraries->AppendL(KLocalAccessProvDll);
       
   227     libraries->AppendL(KLocalDbManProvDll);
       
   228     libraries->AppendL(KLocalSearchProvDll);
       
   229     libraries->AppendL(KMultiDbSearchDll);
       
   230     libraries->AppendL(KRecognizer);
       
   231     libraries->AppendL(KLmServer);
       
   232     
       
   233     _LIT(KExpectedPath, "\\sys\\bin\\");
       
   234     
       
   235     TBool result = FindFilesAndVerifyPathL(*libraries, KExpectedPath);
       
   236 
       
   237     CleanupStack::PopAndDestroy(libraries);
       
   238     return result;
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------
       
   242 // CPosTp111::TestCentralRepositoryL
       
   243 //
       
   244 // (other items were commented in a header).
       
   245 // ---------------------------------------------------------
       
   246 //
       
   247 void CPosTp111::TestCentralRepositoryL()
       
   248     {
       
   249     iLog->Put(_L("TestCentralRepositoryL"));
       
   250     _LIT(KDbUri, "file://c:landmarks.ldb");
       
   251     CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
   252     CleanupStack::PushL(dbMan);
       
   253     
       
   254     // 5. Set default database
       
   255     HPosLmDatabaseInfo* dbInfo = HPosLmDatabaseInfo::NewLC(KDbUri);
       
   256     TRAPD(err, dbMan->CreateDatabaseL(*dbInfo));
       
   257     CleanupStack::PopAndDestroy(dbInfo);
       
   258     if (err != KErrNone && err != KErrAlreadyExists)
       
   259         {
       
   260         LogErrorAndLeave(_L("Creating db failed"), err);
       
   261         }
       
   262     dbMan->SetDefaultDatabaseUriL(KDbUri);
       
   263     
       
   264     // 6. Retrieve default db using LMFW
       
   265     VerifyDefaultDbUriL(KDbUri, dbMan);
       
   266     
       
   267     // 7. Retrieve default db using central repository
       
   268     CRepository* repository = CRepository::NewLC(KCRUidLandmarks);    
       
   269     VerifyDefaultDbUriL(KDbUri, repository);
       
   270 
       
   271     // 8. Reset central repository
       
   272     User::LeaveIfError(repository->Reset(KLandmarkDefaultUri));
       
   273     
       
   274     // 9. Retrieve default db using LMFW
       
   275     VerifyDefaultDbUriL(KFactoryDbUri, dbMan);
       
   276     
       
   277     // 10. Retrieve default db using central repository
       
   278     VerifyDefaultDbUriL(KFactoryDbUri, repository);
       
   279     
       
   280     // 11. Remove central repository file on c:
       
   281     RFs fileServer;
       
   282     User::LeaveIfError(fileServer.Connect());
       
   283     CleanupClosePushL(fileServer);
       
   284     CFileMan* fileMan = CFileMan::NewL(fileServer);
       
   285     CleanupStack::PushL(fileMan);    
       
   286     err = fileMan->Delete(KRepositoryFile);
       
   287     if (err != KErrNone && err != KErrNotFound)
       
   288         {
       
   289         LogErrorAndLeave(_L("Unable to delete repository file"), err);
       
   290         }
       
   291     CleanupStack::PopAndDestroy(2, &fileServer);
       
   292     
       
   293     // 12. Retrieve default db using LMFW
       
   294     VerifyDefaultDbUriL(KFactoryDbUri, dbMan);
       
   295     
       
   296     // 13. Retrieve default db using central repository
       
   297     VerifyDefaultDbUriL(KFactoryDbUri, repository);
       
   298     
       
   299     CleanupStack::PopAndDestroy(2, dbMan);
       
   300     }
       
   301     
       
   302 // ---------------------------------------------------------
       
   303 // CPosTp111::FindFileL
       
   304 //
       
   305 // (other items were commented in a header).
       
   306 // ---------------------------------------------------------
       
   307 //
       
   308 void CPosTp111::FindFileL(const TDesC& aFile, TInt& aNrOfMatches, TDes& aPath)
       
   309     {
       
   310     iLog->Put(_L("FindFileL"));
       
   311     TBuf<200> msg;
       
   312     RFs fileServer;
       
   313     User::LeaveIfError(fileServer.Connect());
       
   314     CleanupClosePushL(fileServer);
       
   315     TDriveList driveList;
       
   316     fileServer.DriveList(driveList);
       
   317     CDirScan* scanner = CDirScan::NewLC(fileServer);
       
   318 
       
   319     // Search all drives for the file.    
       
   320     aNrOfMatches = 0;
       
   321     aPath = KNullDesC;
       
   322     for (TInt i = EDriveA; i <= EDriveZ; i++)
       
   323         {
       
   324         // Investigate if drive exists on this terminal.
       
   325         if (driveList[i])
       
   326             {
       
   327             TChar driveLetter;
       
   328             RFs::DriveToChar(i, driveLetter);
       
   329             TBuf<4> root;
       
   330             root.Append(driveLetter);
       
   331             root.Append(_L(":\\"));
       
   332             scanner->SetScanDataL(root, KEntryAttNormal, ESortByName|EAscending);
       
   333             
       
   334             // List all files in each folder on the drive
       
   335             CFileList* files = NULL;
       
   336             scanner->NextL(files);
       
   337             while (files)
       
   338                 {
       
   339                 CleanupStack::PushL(files);
       
   340                 TPtrC currentFolder = scanner->FullPath();
       
   341                 _LIT(KSearching, "Searching for file %S in folder %S");
       
   342                 msg.Format(KSearching, &aFile, &currentFolder);
       
   343                 iLog->Put(msg);                
       
   344                 
       
   345                 // Search the currentFolder for the specified file
       
   346                 TFindFile fileSearcher(fileServer);
       
   347                 TInt res = fileSearcher.FindByDir(aFile, currentFolder);
       
   348                 if (res == KErrNone)
       
   349                     {
       
   350                     _LIT(KFileFound, "Found file %S in %S");
       
   351                     msg.Format(KFileFound, &aFile, &currentFolder);
       
   352                     iLog->Put(msg);
       
   353                     
       
   354                     aNrOfMatches++;
       
   355                     aPath = currentFolder;
       
   356                     }
       
   357                 
       
   358                 CleanupStack::PopAndDestroy(files);
       
   359                 files = NULL;
       
   360                 scanner->NextL(files);
       
   361                 }          
       
   362             }
       
   363         }
       
   364         
       
   365     CleanupStack::PopAndDestroy(2, &fileServer);
       
   366     }
       
   367     
       
   368 // ---------------------------------------------------------
       
   369 // CPosTp111::FindFilesAndVerifyPathL
       
   370 //
       
   371 // (other items were commented in a header).
       
   372 // ---------------------------------------------------------
       
   373 //
       
   374 TBool CPosTp111::FindFilesAndVerifyPathL(
       
   375     const CDesCArray& aFileNames, 
       
   376     const TDesC& aExpectedPath)
       
   377     {
       
   378     iLog->Put(_L("FindFileL"));
       
   379     TBool successful = ETrue;
       
   380     TBuf<100> msg;
       
   381     TBool nrOfMatches = 0;
       
   382     TBuf<200> path;
       
   383     
       
   384     for (TInt i = 0; i < aFileNames.Count(); i++)
       
   385         {
       
   386         TPtrC fileName = aFileNames[i];
       
   387         FindFileL(fileName, nrOfMatches, path);
       
   388         if (path.Length() == 0)
       
   389             {
       
   390             _LIT(KFormat, "File %S not found.");
       
   391             msg.Format(KFormat, &fileName);
       
   392             iLog->PutError(msg);
       
   393             successful = EFalse;
       
   394             }
       
   395         else
       
   396             {
       
   397             if (nrOfMatches > 1)
       
   398                 {
       
   399                 _LIT(KFormat, "Found %d copies of file %S.");
       
   400                 msg.Format(KFormat, nrOfMatches, &fileName);
       
   401                 iLog->PutError(msg);
       
   402                 successful = EFalse;
       
   403                 }
       
   404             else
       
   405                 {
       
   406                 if (aExpectedPath != path)
       
   407                     {
       
   408                     _LIT(KFormat, "Found file %S at the wrong place, %S");
       
   409                     msg.Format(KFormat, &fileName, &path);
       
   410                     iLog->PutError(msg);
       
   411                     successful = EFalse;
       
   412                     }
       
   413                 }
       
   414             }
       
   415         }
       
   416         
       
   417     return successful;    
       
   418     }
       
   419     
       
   420 // ---------------------------------------------------------
       
   421 // CPosTp111::VerifyDefaultDbUriL
       
   422 //
       
   423 // (other items were commented in a header).
       
   424 // ---------------------------------------------------------
       
   425 //
       
   426 void CPosTp111::VerifyDefaultDbUriL(
       
   427     const TDesC& aExpectedUri, 
       
   428     CPosLmDatabaseManager* aDbMan)
       
   429     {
       
   430     HBufC* dbUriFromLMFW = aDbMan->DefaultDatabaseUriLC();
       
   431     if (*dbUriFromLMFW != aExpectedUri)
       
   432         {
       
   433         TBuf<100> msg;
       
   434         _LIT(KFormat, "Unexpected db uri from LMFW, %S != %S");
       
   435         msg.Format(KFormat, dbUriFromLMFW, &aExpectedUri);
       
   436         LogErrorAndLeave(msg);
       
   437         }
       
   438     CleanupStack::PopAndDestroy(dbUriFromLMFW);
       
   439     }
       
   440 
       
   441 // ---------------------------------------------------------
       
   442 // CPosTp111::VerifyDefaultDbUriL
       
   443 //
       
   444 // (other items were commented in a header).
       
   445 // ---------------------------------------------------------
       
   446 //
       
   447 void CPosTp111::VerifyDefaultDbUriL(
       
   448     const TDesC& aExpectedUri, 
       
   449     CRepository* aRepository)
       
   450     {
       
   451     TBuf16<NCentralRepositoryConstants::KMaxUnicodeStringLength> dbUriFromRep;
       
   452     User::LeaveIfError(aRepository->Get(KLandmarkDefaultUri, dbUriFromRep));
       
   453     if (dbUriFromRep != aExpectedUri)
       
   454         {
       
   455         TBuf<100> msg;
       
   456         _LIT(KFormat, "Unexpected db uri from repository, %S != %S");
       
   457         msg.Format(KFormat, dbUriFromRep, &aExpectedUri);
       
   458         LogErrorAndLeave(msg);
       
   459         }
       
   460     }
       
   461 
       
   462 //  End of File