landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp1.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_CPosTp1.h"
       
    23 #include <EPos_CPosLandmarkDatabase.h>
       
    24 #include <EPos_CPosLmDatabaseManager.h>
       
    25 #include "FT_LandmarkConstants.h"
       
    26            
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 
       
    30 // ---------------------------------------------------------
       
    31 // CPosTp1::StartL
       
    32 //
       
    33 // (other items were commented in a header).
       
    34 // ---------------------------------------------------------
       
    35 //
       
    36 void CPosTp1::StartL()
       
    37     {  
       
    38     _LIT(KUriErr, "Incorrect URI is returned from the API");
       
    39     _LIT(KDefaultDbUri, "file://C:eposlm.ldb");
       
    40   
       
    41     // Init test part
       
    42     RemoveAllLmDatabasesL();
       
    43     
       
    44     
       
    45     // End init test part
       
    46     
       
    47     CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL();
       
    48     iLog->Log(_L("CPosLandmarkDatabase::OpenL done"));
       
    49     CleanupStack::PushL(lmd);
       
    50 
       
    51     // Check that THAN-65NHQW has been corrected by doing a ExecuteAndDeleteLD(lmd->InitializeL()) followed by 
       
    52   
       
    53     if (lmd->IsInitializingNeeded())
       
    54         {
       
    55 	    iLog->Log(_L("IsInitializingNeeded()"));
       
    56         ExecuteAndDeleteLD(lmd->InitializeL());
       
    57 	    RunAsyncOperationLD(lmd->InitializeL());
       
    58         }
       
    59     else
       
    60  	    {
       
    61         iLog->Log(_L("IsInitializingNeeded() Not needed"));
       
    62         ExecuteAndDeleteLD(lmd->InitializeL());
       
    63         RunAsyncOperationLD(lmd->InitializeL());
       
    64         }
       
    65     
       
    66 
       
    67     CleanupStack::PopAndDestroy(lmd); 
       
    68 
       
    69     VerifyLockedDatabaseL();
       
    70   
       
    71 	}
       
    72 
       
    73 // ---------------------------------------------------------
       
    74 // CPosTp1::VerifyLockedDatabaseL
       
    75 //
       
    76 // (other items were commented in a header).
       
    77 // ---------------------------------------------------------
       
    78 //
       
    79 void CPosTp1::VerifyLockedDatabaseL()
       
    80     {
       
    81     _LIT(KTestPath, "c:\\system\\test\\testdata\\");
       
    82     // copy the test db to the private path
       
    83     CFileMan* fileMan = CFileMan::NewL(iFileSession);
       
    84     CleanupStack::PushL(fileMan);
       
    85 
       
    86     TBuf<150> srcPath;
       
    87 
       
    88     srcPath.Append(KTestPath);
       
    89     srcPath.Append(KTp1TestDb);
       
    90 
       
    91     TInt err = fileMan->Copy(srcPath, KLmTp1DefaultDbPath,
       
    92             CFileMan::EOverWrite);
       
    93     if (err != KErrNone)
       
    94         iLog->Log(_L("Error when copying file"));
       
    95 
       
    96     CleanupStack::PopAndDestroy(fileMan);
       
    97     CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL();
       
    98     CleanupStack::PushL(manager);
       
    99 
       
   100     // This db must exist
       
   101     manager->SetDefaultDatabaseUriL(KTp1TestDb);
       
   102     CleanupStack::PopAndDestroy(manager);
       
   103 
       
   104     CPosLandmarkDatabase* db1 = CPosLandmarkDatabase::OpenL(KTp1TestDb);
       
   105     CleanupStack::PushL(db1);
       
   106     if (db1->IsInitializingNeeded())
       
   107         {
       
   108         TRAPD( err, ExecuteAndDeleteLD( db1->InitializeL() ) );
       
   109         AssertTrueSecL(err == KErrNone, _L("Init db failed"));
       
   110         }
       
   111     
       
   112     
       
   113 
       
   114     // Take read lock
       
   115     RArray<TPosLmItemId> ids;
       
   116     CleanupClosePushL(ids);
       
   117     User::LeaveIfError(ids.Append(1));
       
   118     User::LeaveIfError(ids.Append(3));
       
   119     User::LeaveIfError(ids.Append(4));
       
   120     User::LeaveIfError(ids.Append(6));
       
   121     User::LeaveIfError(ids.Append(7));
       
   122     User::LeaveIfError(ids.Append(9));
       
   123     User::LeaveIfError(ids.Append(24));
       
   124     User::LeaveIfError(ids.Append(14));
       
   125     User::LeaveIfError(ids.Append(66));
       
   126     User::LeaveIfError(ids.Append(61));
       
   127     User::LeaveIfError(ids.Append(14));
       
   128     CPosLmOperation* operation = db1->PreparePartialLandmarksL(ids);
       
   129     CleanupStack::PushL(operation);
       
   130     TReal32 progress(0);
       
   131     TRequestStatus status;
       
   132     while (progress < 0.4)
       
   133         {
       
   134         operation->NextStep(status, progress);
       
   135         User::WaitForRequest(status);
       
   136         }
       
   137 
       
   138     // Try to instantiate a new db handle
       
   139     operation->NextStep(status, progress);
       
   140     CPosLandmarkDatabase* db2 = CPosLandmarkDatabase::OpenL();
       
   141     iLog->Log(_L("CPosLandmarkDatabase::OpenL done"));
       
   142     delete db2;
       
   143     User::WaitForRequest(status);
       
   144 
       
   145     // Release read lock
       
   146     CleanupStack::PopAndDestroy(operation);
       
   147     
       
   148     // Take write lock
       
   149     operation = db1->RemoveAllLandmarksL();
       
   150     CleanupStack::PushL(operation);
       
   151     progress = 0;
       
   152     while (progress < 0.4)
       
   153         {
       
   154         operation->NextStep(status, progress);
       
   155         User::WaitForRequest(status);
       
   156         }
       
   157 
       
   158     // Try to instantiate a new db handle - should result in KErrLocked
       
   159     operation->NextStep(status, progress);
       
   160     db2 = NULL;
       
   161     TRAPD(err1, db2 = CPosLandmarkDatabase::OpenL());
       
   162     delete db2;
       
   163     User::WaitForRequest(status);
       
   164     AssertTrueSecL(err1 == KErrLocked, _L("OpenL() didn't result in KErrLocked but in %d"), err1);
       
   165     
       
   166     CleanupStack::PopAndDestroy(3, db1);
       
   167     }
       
   168 
       
   169 //  End of File