persistentstorage/centralrepository/test/t_cenrep_pma_array.cpp
changeset 55 44f437012c90
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <f32file.h>
       
    18 #include <badesca.h>
       
    19 
       
    20 #include "srvrepos_noc.h"
       
    21 #include "srvres.h"
       
    22 #include "t_cenrep_helper.h"
       
    23 
       
    24 RTest TheTest(_L("t_cenrep_pma_array.exe"));
       
    25 
       
    26 _LIT(KPMAKeyspace1Src, "z:\\private\\10202be9\\f1000001.pma");
       
    27 _LIT(KPMAKeyspace2Src, "z:\\private\\10202be9\\f1000002.pma");
       
    28 _LIT(KPMAKeyspace3Src, "z:\\private\\10202be9\\f1000003.pma");
       
    29 _LIT(KPMAKeyspace4Src, "z:\\private\\10202be9\\f1000004.pma"); //Non-PMA keyspace in PMA drive
       
    30 _LIT(KPMAKeyspace5Src, "z:\\private\\10202be9\\f1000006.txp");
       
    31 
       
    32 _LIT(KPMAKeyspace1Dst, "c:\\private\\10202be9\\persists\\protected\\f1000001.cre");
       
    33 _LIT(KPMAKeyspace2Dst, "c:\\private\\10202be9\\persists\\protected\\f1000002.cre");
       
    34 _LIT(KPMAKeyspace3Dst, "c:\\private\\10202be9\\persists\\protected\\f1000003.cre");
       
    35 _LIT(KPMAKeyspace4Dst, "c:\\private\\10202be9\\persists\\protected\\f1000004.cre");
       
    36 _LIT(KPMAKeyspace5Dst, "c:\\private\\10202be9\\persists\\protected\\f1000006.txt");
       
    37 
       
    38 
       
    39 const TUid KPMATestUid = {0xf1000005};
       
    40 const TUid KNonPMATestUid = {0xf1000004};
       
    41 
       
    42 ///////////////////////////////////////////////////////////////////////////////////////
       
    43 ///////////////////////////////////////////////////////////////////////////////////////
       
    44 //Test macros and functions
       
    45 
       
    46 LOCAL_C void Check( TInt aValue, TInt aExpected, TInt aLine )
       
    47     {
       
    48     if ( aValue != aExpected )
       
    49         {
       
    50         RDebug::Print( _L( "*** Expected error: %d, got: %d\r\n"), aExpected, aValue );
       
    51         TRAPD(err, CleanupCDriveL());
       
    52         if (err != KErrNone)
       
    53             {
       
    54             RDebug::Print( _L( "*** CleanupCDriveL also failed with error %d expecting KErrNone\r\n"), err );
       
    55             }
       
    56         TheTest( EFalse, aLine );
       
    57         }
       
    58     }
       
    59 
       
    60 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    61 
       
    62 ///////////////////////////////////////////////////////////////////////////////////////
       
    63 ///////////////////////////////////////////////////////////////////////////////////////
       
    64 static void CloseTServerResources(TAny*)
       
    65     {
       
    66     TServerResources::Close();
       
    67     }
       
    68 
       
    69 //////////////////////////////////////////////////////////////////////////////////////////////////
       
    70 class CenrepPMAArrayTest :public CBase
       
    71 {
       
    72 public:
       
    73     void SetL(TUint32 aKey, TInt aValue);
       
    74     void GetL(TUint32 aKey, TInt& aValue);
       
    75     CenrepPMAArrayTest();
       
    76     ~CenrepPMAArrayTest();
       
    77     static CenrepPMAArrayTest* NewL(TUid aReposUid);
       
    78 private:
       
    79     void ConstructL(TUid aReposUid);
       
    80 public:
       
    81     CServerRepository* iServerRepo;
       
    82     CSessionNotifier* iSessionNotif;
       
    83 };
       
    84 
       
    85 
       
    86 CenrepPMAArrayTest::CenrepPMAArrayTest(){}
       
    87 
       
    88 CenrepPMAArrayTest::~CenrepPMAArrayTest()
       
    89     {
       
    90     if (iServerRepo)
       
    91         {
       
    92         if (iSessionNotif)
       
    93             {
       
    94             iServerRepo->Close();
       
    95             }
       
    96         delete iServerRepo;
       
    97         }
       
    98     if (iSessionNotif)
       
    99         delete iSessionNotif;
       
   100     }
       
   101 
       
   102 CenrepPMAArrayTest* CenrepPMAArrayTest::NewL(TUid aReposUid)
       
   103     {
       
   104     CenrepPMAArrayTest* self=new (ELeave)CenrepPMAArrayTest;
       
   105     CleanupStack::PushL(self);
       
   106     self->ConstructL(aReposUid);
       
   107     CleanupStack::Pop(self);
       
   108     return self;
       
   109     }
       
   110 
       
   111 void CenrepPMAArrayTest::ConstructL(TUid aReposUid)
       
   112     {
       
   113     iServerRepo=new (ELeave)CServerRepository();
       
   114     iSessionNotif=new (ELeave) CSessionNotifier();
       
   115 
       
   116     iServerRepo->OpenL(aReposUid,*iSessionNotif);
       
   117     }
       
   118 
       
   119 void CenrepPMAArrayTest::SetL(TUint32 aKey, TInt aValue)
       
   120     {
       
   121     iServerRepo->StartTransaction(EConcurrentReadWriteTransaction);
       
   122     iServerRepo->CleanupCancelTransactionPushL();
       
   123     iServerRepo->TransactionSetL(aKey, aValue);
       
   124     CleanupStack::Pop();
       
   125     TUint32 keyInfo;
       
   126     User::LeaveIfError(iServerRepo->CommitTransaction(keyInfo));
       
   127     }
       
   128 
       
   129 void CenrepPMAArrayTest::GetL(TUint32 aKey, TInt& aValue)
       
   130     {
       
   131     User::LeaveIfError(iServerRepo->Get(aKey, aValue));
       
   132     }
       
   133 
       
   134 /**
       
   135 @SYMTestCaseID          PDS-CENTRALREPOSITORY-CT-4120
       
   136 @SYMTestCaseDesc        PMA repositories array test on pre-loaded PMA drive 
       
   137 @SYMTestPriority        High
       
   138 @SYMTestActions         - Cleanup PMA drive and copy 5 test repositories to the 
       
   139                           PMA drive. 1 of them is .txt and should be ignored on 
       
   140                           initialisation and another 1 is a non-PMA keyspace 
       
   141                           which is counted as a not supported keyspace if found in the 
       
   142                           PMA drive.
       
   143                         - Initialise server resource
       
   144                         - Check the preloaded repositories count in the array
       
   145                         - Modify a PMA repository that only exist in ROM (not persisted yet), 
       
   146                           check the count should increase by 1 after successful modification
       
   147                         - Modify the same PMA repository array again, the count 
       
   148                           should not be increased again
       
   149 @SYMTestExpectedResults - On initialise count should be 4 (including the Non-PMA keyspace in PMA drive)
       
   150                         - On modification of  a PMA repository that only exist in ROM (not persisted yet),
       
   151                           the array should be 5 after successful modification
       
   152                         - On the 2nd modification of the same repository, the 
       
   153                           array should still be 5
       
   154 @SYMREQ                 REQ42876
       
   155 */
       
   156 LOCAL_C void ArrayPreLoadedAndSetTestL()
       
   157     {
       
   158     TheTest.Next( _L( " @SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4120 PMA Repositories Array test on pre-loaded PMA drive" ) );
       
   159     CleanupCDriveL();
       
   160     
       
   161     RFs rfs;
       
   162     User::LeaveIfError(rfs.Connect());
       
   163     CleanupClosePushL(rfs);
       
   164     
       
   165     CFileMan* fm = CFileMan::NewL( rfs );
       
   166     CleanupStack::PushL( fm );
       
   167     
       
   168     //copying test files to PMA drive for the server startup simulation
       
   169     CopyTestFilesL(*fm, KPMAKeyspace1Src, KPMAKeyspace1Dst);
       
   170     CopyTestFilesL(*fm, KPMAKeyspace2Src, KPMAKeyspace2Dst);
       
   171     CopyTestFilesL(*fm, KPMAKeyspace3Src, KPMAKeyspace3Dst);
       
   172     CopyTestFilesL(*fm, KPMAKeyspace4Src, KPMAKeyspace4Dst); //Non-PMA keyspace
       
   173     CopyTestFilesL(*fm, KPMAKeyspace5Src, KPMAKeyspace5Dst); //Txt keyspace
       
   174     
       
   175     CleanupStack::PopAndDestroy(2, &rfs);
       
   176     
       
   177     
       
   178     TUint32 pmaIntKey = {0x01};
       
   179     TInt currentVal = 0;
       
   180     TInt pmaCount = 0;
       
   181     
       
   182     TServerResources::InitialiseL();
       
   183     CleanupStack::PushL(TCleanupItem(CloseTServerResources, 0));
       
   184     
       
   185     pmaCount = TServerResources::iPMADriveRepositories.Count();
       
   186     TEST2(pmaCount, 4); //Initial load, there should be 4 repositories in PMA array    
       
   187     
       
   188     CenrepPMAArrayTest* theTest=CenrepPMAArrayTest::NewL(KPMATestUid);
       
   189     CleanupStack::PushL(theTest);
       
   190     
       
   191     // Part 1. Persist a repository
       
   192     theTest->SetL(pmaIntKey, 25); //Setting a value will trigger persist on the ROM repository to PMA Drive
       
   193     theTest->GetL(pmaIntKey, currentVal); //Double check that the value has indeed changed
       
   194     TEST2(currentVal, 25);
       
   195     pmaCount = TServerResources::iPMADriveRepositories.Count();
       
   196     TEST2(pmaCount, 5); //The array count should be 5 now 
       
   197     
       
   198     // Part 2. Persist the same repository
       
   199     theTest->SetL(pmaIntKey, 30); //Calling set on the same repository 
       
   200     theTest->GetL(pmaIntKey, currentVal); //Double check that the value has indeed changed
       
   201     TEST2(currentVal, 30);
       
   202     pmaCount = TServerResources::iPMADriveRepositories.Count();
       
   203     TEST2(pmaCount, 5); //The array count should stay the same
       
   204     
       
   205     CleanupStack::PopAndDestroy(theTest);
       
   206     
       
   207     TRAPD(err, theTest = CenrepPMAArrayTest::NewL(KNonPMATestUid)); 
       
   208     TEST2(err, KErrNotSupported);
       
   209     
       
   210     pmaCount = TServerResources::iPMADriveRepositories.Count();
       
   211     //The array count should be less by 1 to 4 because the non-PMA 
       
   212     // keyspace should be deleted and removed from the array.
       
   213     TEST2(pmaCount, 4);
       
   214     
       
   215     CleanupStack::Pop(); // CloseTServerResources
       
   216     
       
   217     TServerResources::Close();
       
   218     
       
   219     }
       
   220 
       
   221 /**
       
   222 @SYMTestCaseID          PDS-CENTRALREPOSITORY-CT-4121
       
   223 @SYMTestCaseDesc        PMA repositories array test on empty PMA drive 
       
   224 @SYMTestPriority        High
       
   225 @SYMTestActions         - Cleanup PMA drive
       
   226                         - Initialise server resource
       
   227                         - Check the preloaded repositories count in the array
       
   228                         - Modify a ROM-only PMA repository, check the count should increase by 1
       
   229                         - Modify the same PMA repository array again, the count should not be increased again.
       
   230 @SYMTestExpectedResults - On initialise count should be 0
       
   231                         - On modification of a ROM-only PMA repository, the array should be 1
       
   232 @SYMREQ                 REQ42876
       
   233 */
       
   234 LOCAL_C void ArraySetTestL()
       
   235     {
       
   236     TheTest.Next( _L( " @SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4121 PMA Repositories Array test on empty PMA drive" ) );
       
   237     CleanupCDriveL();
       
   238     TServerResources::InitialiseL();
       
   239     CleanupStack::PushL(TCleanupItem(CloseTServerResources, 0));
       
   240     
       
   241     TInt pmaCount = TServerResources::iPMADriveRepositories.Count();
       
   242     TEST2(pmaCount, 0);
       
   243     
       
   244     CenrepPMAArrayTest* theTest=CenrepPMAArrayTest::NewL(KPMATestUid);
       
   245     CleanupStack::PushL(theTest);
       
   246     
       
   247     TUint32 pmaIntKey = {0x01};
       
   248     theTest->SetL(pmaIntKey, 40);
       
   249 
       
   250     pmaCount = TServerResources::iPMADriveRepositories.Count();
       
   251     
       
   252     TEST2(pmaCount, 1);
       
   253     
       
   254     CleanupStack::PopAndDestroy(theTest);
       
   255     CleanupStack::Pop(); // CloseTServerResources
       
   256     
       
   257     TServerResources::Close();
       
   258     
       
   259     }
       
   260 
       
   261 LOCAL_C void MainL()
       
   262     {
       
   263     CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
       
   264     CActiveScheduler::Install(scheduler);
       
   265     
       
   266     CleanupStack::PushL(scheduler);
       
   267 
       
   268     //Array was preloaded during startup
       
   269     ArrayPreLoadedAndSetTestL();
       
   270     
       
   271     //Array was not preloaded during startup
       
   272     ArraySetTestL();
       
   273     
       
   274     CleanupCDriveL();
       
   275 
       
   276     CleanupStack::PopAndDestroy(scheduler);
       
   277     }
       
   278 
       
   279 
       
   280 TInt E32Main()
       
   281     {
       
   282     TheTest.Title ();
       
   283     TheTest.Start( _L( "PMA Array Tests" ) );
       
   284     
       
   285     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   286     TheTest(cleanup != NULL);
       
   287     
       
   288     __UHEAP_MARK;
       
   289         
       
   290     TRAPD(err, MainL());
       
   291     TEST2(err, KErrNone);
       
   292     
       
   293     __UHEAP_MARKEND;
       
   294     
       
   295     TheTest.End ();
       
   296     TheTest.Close ();
       
   297     
       
   298     delete cleanup;
       
   299         
       
   300     User::Heap().Check();
       
   301     return KErrNone;
       
   302     }
       
   303