emailservices/emailstore/tsrc/message_store_test/src/ObserverTests.cpp
changeset 1 12c456ceeff2
child 13 0396474f30f5
equal deleted inserted replaced
0:8466d47a6819 1:12c456ceeff2
       
     1 /*
       
     2 * Copyright (c) 2002 - 2007 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:  Base class for all test cases class member functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // [INCLUDE FILES] - do not remove
       
    21 #include <connect/sbdefs.h>
       
    22 #include <e32property.h>
       
    23 #include "ObserverTests.h"
       
    24 //#include <ismsgstorepropertykeys.h>
       
    25 #include "messagestoreclientserver.h"
       
    26 
       
    27 const TInt32 KOwner1 = 1234;
       
    28 const TInt32 KOwner2 = 5678;
       
    29 
       
    30 _LIT( KAccount1, "my account 1");
       
    31 _LIT( KAccount2, "my account 2");
       
    32 
       
    33 //PointSec related tests. Must match ImsPointsecMonitor.h
       
    34 // KPsUidPointsec
       
    35 // The Pointsec status as defined by TPointsecStatus
       
    36 #if 0
       
    37 const TUint KUidPointsecStatus = { 0x102070e3 };
       
    38 #endif
       
    39 
       
    40 enum TPointsecStatus
       
    41     {
       
    42     EPointsecRecognizerStarted = 1,
       
    43     EPointsecInitializing,
       
    44     EPointsecLocked,
       
    45     EPointsecUnlocked,
       
    46     EPointSecUnknown,              //Do not know what 5 means, ignore it for now
       
    47     EPointSecEncryptionStarting,   //We received this while PointSec says "Encrypting Files"
       
    48                                    //encryption is done, we received EPointSecUnlocked
       
    49     EPointsecNotStarted = -1
       
    50     };
       
    51 
       
    52 
       
    53 
       
    54 // ============================ MEMBER FUNCTIONS ===============================
       
    55 
       
    56 CObserverTests* CObserverTests::NewL( CStifLogger* aLog )
       
    57     {
       
    58     CObserverTests* self = new(ELeave) CObserverTests( aLog );
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // Constructor
       
    67 // -----------------------------------------------------------------------------
       
    68 CObserverTests::CObserverTests( CStifLogger* aLog ) : CAsyncTestCaseBase( aLog ) 
       
    69     {
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // Destructor
       
    74 // -----------------------------------------------------------------------------
       
    75 CObserverTests::~CObserverTests()
       
    76     {
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // 2nd phase constructor
       
    81 // -----------------------------------------------------------------------------
       
    82 void CObserverTests::ConstructL()
       
    83     {
       
    84     CAsyncTestCaseBase::ConstructL();
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // ExecuteL : start executing the test case
       
    89 // -----------------------------------------------------------------------------
       
    90 TBool CObserverTests::ExecuteL()
       
    91     {
       
    92     LogHeader( _L("Observer") );
       
    93     
       
    94     CMsgStore* session1 = CMsgStore::NewL();
       
    95     CleanupStack::PushL( session1 );                                            //+1
       
    96     CMsgStore* session2 = CMsgStore::NewL();
       
    97     CleanupStack::PushL( session2 );                                            //+2
       
    98 
       
    99     StartRecordingObserverEvents();         
       
   100 
       
   101     session1->AddObserverL( this );
       
   102     session2->AddObserverL( this );
       
   103     
       
   104     TObserverEvent         event;
       
   105     RArray<TObserverEvent> expectedEvents;
       
   106 
       
   107     iLog->Log( _L("Case %d: Create Account events"), iCaseId++ );
       
   108     
       
   109     CMsgStoreAccount* account1 = CMsgStoreAccount::NewLC( KOwner1, KAccount1 ); //+3
       
   110     CMsgStoreMailBox* mailBox1 = session1->CreateAccountL( *account1 );
       
   111     CleanupStack::PushL( mailBox1 );                                            //+4
       
   112     
       
   113     event.iMailBoxId   = mailBox1->Id();
       
   114     event.iOperation   = EMsgStoreAccountCreated;
       
   115     event.iType        = KMsgStoreInvalidId;
       
   116     event.iFlags       = KMsgStoreFlagsNotFound;
       
   117     event.iId          = KOwner1;
       
   118     event.iParentId    = KMsgStoreInvalidId;
       
   119     event.iOtherId     = KMsgStoreInvalidId;    
       
   120     event.iName.Copy( KAccount1 );
       
   121     event.iNewName.Copy( KNullDesC );
       
   122     
       
   123     expectedEvents.AppendL( event );
       
   124     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   125     
       
   126     CMsgStoreAccount* account2 = CMsgStoreAccount::NewLC( KOwner2, KAccount2 ); //+5
       
   127     CMsgStoreMailBox* mailBox2 = session2->CreateAccountL( *account2 );
       
   128     CleanupStack::PushL( mailBox2 );                                            //+6
       
   129 
       
   130     event.iMailBoxId   = mailBox2->Id();
       
   131     event.iOperation   = EMsgStoreAccountCreated;
       
   132     event.iType        = KMsgStoreInvalidId;
       
   133     event.iFlags       = KMsgStoreFlagsNotFound;
       
   134     event.iId          = KOwner2;
       
   135     event.iParentId    = KMsgStoreInvalidId;
       
   136     event.iOtherId     = KMsgStoreInvalidId;    
       
   137     event.iName.Copy( KAccount2 );
       
   138     event.iNewName.Copy( KNullDesC );
       
   139     
       
   140     expectedEvents.AppendL( event );
       
   141     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   142     
       
   143     iLog->Log( _L("Case %d: Rename Account events"), iCaseId++ );
       
   144     
       
   145     session1->RenameAccountL( KOwner1, KAccount1, KAccount2 );
       
   146     
       
   147     event.iMailBoxId   = mailBox1->Id();
       
   148     event.iOperation   = EMsgStoreAccountRenamed;
       
   149     event.iType        = KMsgStoreInvalidId;
       
   150     event.iFlags       = KMsgStoreFlagsNotFound;
       
   151     event.iId          = KOwner1;
       
   152     event.iParentId    = KMsgStoreInvalidId;
       
   153     event.iOtherId     = KMsgStoreInvalidId;    
       
   154     event.iName.Copy( KAccount1 );
       
   155     event.iNewName.Copy( KAccount2 );
       
   156     
       
   157     expectedEvents.AppendL( event );
       
   158     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   159 
       
   160     iLog->Log( _L("Case %d: Delete Account events"), iCaseId++ );
       
   161     
       
   162     CMsgStoreAccount* newAccount = CMsgStoreAccount::NewLC( KOwner1, KAccount2 ); //+7
       
   163     session1->DeleteAccountL( *newAccount );
       
   164     
       
   165     event.iMailBoxId   = mailBox1->Id();
       
   166     event.iOperation   = EMsgStoreAccountDeleted;
       
   167     event.iType        = KMsgStoreInvalidId;
       
   168     event.iFlags       = KMsgStoreFlagsNotFound;
       
   169     event.iId          = KOwner1;
       
   170     event.iParentId    = KMsgStoreInvalidId;
       
   171     event.iOtherId     = KMsgStoreInvalidId;    
       
   172     event.iName.Copy( KAccount2 );
       
   173     event.iNewName.Copy( KNullDesC );
       
   174     
       
   175     expectedEvents.AppendL( event );
       
   176     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   177     
       
   178     iLog->Log( _L("Case %d: Create Account events"), iCaseId++ );
       
   179     
       
   180     mailBox1 = session1->CreateAccountL( *account1 );
       
   181     CleanupStack::PushL( mailBox1 );                                            //+8
       
   182     
       
   183     event.iMailBoxId   = mailBox1->Id();
       
   184     event.iOperation   = EMsgStoreAccountCreated;
       
   185     event.iType        = KMsgStoreInvalidId;
       
   186     event.iFlags       = KMsgStoreFlagsNotFound;
       
   187     event.iId          = KOwner1;
       
   188     event.iParentId    = KMsgStoreInvalidId;
       
   189     event.iOtherId     = KMsgStoreInvalidId;    
       
   190     event.iName.Copy( KAccount1 );
       
   191     event.iNewName.Copy( KNullDesC );
       
   192     
       
   193     expectedEvents.AppendL( event );
       
   194     
       
   195     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   196     
       
   197     iLog->Log( _L("Case %d: Mailbox events"), iCaseId++ );
       
   198     
       
   199     mailBox1->AddObserverL( this );
       
   200     
       
   201     //This mailbox should NOT get any notifications for events on mailBox1
       
   202     mailBox2->AddObserverL( this );  
       
   203     
       
   204     ///This mailbox should get notifications for ALL events on mailBox1
       
   205     CMsgStoreMailBox *mailBox1_too = session2->OpenAccountL( *account1 );
       
   206     CleanupStack::PushL( mailBox1_too );                                          //+9
       
   207     mailBox1_too->AddObserverL( this );
       
   208     
       
   209     CMsgStorePropertyContainer* properties = CMsgStorePropertyContainer::NewL();
       
   210     CleanupStack::PushL( properties );                                            //+10
       
   211     _LIT8( KProperty1, "PROP1" );
       
   212     _LIT8( KProperty2, "PROP2" );
       
   213     TestAddIntegerPropertyL( *properties, KProperty1, 1 );
       
   214     TestAddIntegerPropertyL( *properties, KProperty2, 1 );
       
   215     
       
   216     iLog->Log( _L("Case %d: Create Folder events"), iCaseId++ );
       
   217     
       
   218     TMsgStoreId folderId = mailBox1->CreateFolderL( mailBox1->Id(), *properties );
       
   219     event.iMailBoxId   = mailBox1->Id();
       
   220     event.iOperation   = EMsgStoreAdd;
       
   221     event.iType        = EMsgStoreFolderContainer;
       
   222     event.iFlags       = KMsgStoreFlagsNotFound;
       
   223     event.iId          = folderId;
       
   224     event.iParentId    = mailBox1->Id();
       
   225     event.iOtherId     = KMsgStoreRootMailBoxId;    
       
   226     event.iName.SetLength(0);
       
   227     event.iNewName.SetLength(0);
       
   228     
       
   229     expectedEvents.AppendL( event );
       
   230 
       
   231     TMsgStoreId folder2Id = mailBox1->CreateFolderL( mailBox1->Id(), *properties );
       
   232     event.iMailBoxId   = mailBox1->Id();
       
   233     event.iOperation   = EMsgStoreAdd;
       
   234     event.iType        = EMsgStoreFolderContainer;
       
   235     event.iFlags       = KMsgStoreFlagsNotFound;
       
   236     event.iId          = folder2Id;
       
   237     event.iParentId    = mailBox1->Id();
       
   238     event.iOtherId     = KMsgStoreRootMailBoxId;    
       
   239     event.iName.SetLength(0);
       
   240     event.iNewName.SetLength(0);
       
   241     
       
   242     expectedEvents.AppendL( event );
       
   243     
       
   244     iLog->Log( _L("Case %d: Create Message events"), iCaseId++ );
       
   245     
       
   246     CMsgStoreMessage* message1 = mailBox1->CreateMessageL( folderId, *properties );
       
   247     CleanupStack::PushL( message1 );                                                //+11
       
   248     message1->CommitL();
       
   249     event.iMailBoxId   = mailBox1->Id();
       
   250     event.iOperation   = EMsgStoreAdd;
       
   251     event.iType        = EMsgStoreMessageContainer;
       
   252     event.iFlags       = KMsgStoreFlagsNotFound;
       
   253     event.iId          = message1->Id();
       
   254     event.iParentId    = folderId;
       
   255     event.iOtherId     = mailBox1->Id();    
       
   256     event.iName.SetLength(0);
       
   257     event.iNewName.SetLength(0);
       
   258     
       
   259     expectedEvents.AppendL( event );
       
   260 
       
   261     TestAddIntegerPropertyL( *properties, KMsgStorePropertyFlags, 12345 );
       
   262 
       
   263     CMsgStoreMessage* message2 = mailBox1->CreateMessageL( folderId, *properties );
       
   264     CleanupStack::PushL( message2 );                                                //+12
       
   265     message2->CommitL();
       
   266     event.iMailBoxId   = mailBox1->Id();
       
   267     event.iOperation   = EMsgStoreAdd;
       
   268     event.iType        = EMsgStoreMessageContainer;
       
   269     event.iFlags       = 12345;
       
   270     event.iId          = message2->Id();
       
   271     event.iParentId    = folderId;
       
   272     event.iOtherId     = mailBox1->Id();    
       
   273     event.iName.SetLength(0);
       
   274     event.iNewName.SetLength(0);
       
   275     expectedEvents.AppendL( event );
       
   276     
       
   277     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   278     
       
   279     iLog->Log( _L("Case %d: Create Part events"), iCaseId++ );
       
   280     
       
   281     CMsgStoreMessagePart* part1 = message1->AddChildPartL( *properties );
       
   282     CleanupStack::PushL( part1 );                                                    //+13
       
   283     
       
   284     event.iMailBoxId   = mailBox1->Id();
       
   285     event.iOperation   = EMsgStoreAdd;
       
   286     event.iType        = EMsgStorePartContainer;
       
   287     event.iFlags       = KMsgStoreFlagsNotFound;
       
   288     event.iId          = part1->Id();
       
   289     event.iParentId    = message1->Id();
       
   290     event.iOtherId     = message1->ParentId();  
       
   291     event.iName.SetLength(0);
       
   292     event.iNewName.SetLength(0);
       
   293     expectedEvents.AppendL( event );
       
   294     
       
   295     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   296     
       
   297     _LIT( KFilename, "C:\\test_content.txt" );
       
   298     _LIT8( KContent, "THIS IS THE CONTENT FOR THIS TEST" );
       
   299     RFs   fs;
       
   300     User::LeaveIfError( fs.Connect() );
       
   301     RFile file;
       
   302     User::LeaveIfError( file.Replace( fs, KFilename, EFileWrite ) );
       
   303     file.Write( KContent );
       
   304     file.Close();
       
   305     fs.Close();
       
   306     
       
   307     part1->ReplaceContentWithFileL( KFilename  );
       
   308 
       
   309     event.iMailBoxId   = mailBox1->Id();
       
   310     event.iOperation   = EMsgStoreUpdateContent;
       
   311     event.iType        = EMsgStorePartContainer;
       
   312     event.iFlags       = KMsgStoreFlagsNotFound;
       
   313     event.iId          = part1->Id();
       
   314     event.iParentId    = message1->Id();
       
   315     event.iOtherId     = message1->ParentId();  
       
   316     event.iName.SetLength(0);
       
   317     event.iNewName.SetLength(0);
       
   318     
       
   319     expectedEvents.AppendL( event );    
       
   320     
       
   321     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   322     
       
   323     // Test message creation with operations between CreateMessageL and CommitL.
       
   324     iLog->Log( _L("Case %d: Test operations between CreateMessageL and CommitL"), iCaseId++ );
       
   325 
       
   326     TUint index;
       
   327     properties->FindProperty( KMsgStorePropertyFlags, index );
       
   328     TestUpdateIntegerPropertyL( *properties, index, 99999 );
       
   329     
       
   330     CMsgStoreMessage* message3 = mailBox1->CreateMessageL( folderId, *properties );
       
   331     CleanupStack::PushL( message3 );                                                      //+14
       
   332     message3->ReplaceContentL( _L8("CONTENT") );
       
   333     CMsgStoreMessagePart* part3 = message3->AddChildPartL( *properties );
       
   334     part3->ReplaceContentL( _L8("NEW CONTENT" ) );
       
   335     part3->AppendToContentL( _L8("MORE CONTENT" ) );
       
   336     part3->ReplaceContentWithFileL( KFilename );
       
   337     message3->CommitL();
       
   338     event.iMailBoxId   = mailBox1->Id();
       
   339     event.iOperation   = EMsgStoreAdd;
       
   340     event.iType        = EMsgStoreMessageContainer;
       
   341     event.iFlags       = 99999;
       
   342     event.iId          = message3->Id();
       
   343     event.iParentId    = folderId;
       
   344     event.iOtherId     = mailBox1->Id();    
       
   345     event.iName.SetLength(0);
       
   346     event.iNewName.SetLength(0);
       
   347     expectedEvents.AppendL( event );
       
   348     delete part3;
       
   349 
       
   350     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   351     
       
   352     iLog->Log( _L("Case %d: Move events"), iCaseId++ );
       
   353     
       
   354     mailBox1->MoveMessageL( message1->Id(), folderId, folder2Id );          
       
   355     event.iMailBoxId   = mailBox1->Id();
       
   356     event.iOperation   = EMsgStoreMove;
       
   357     event.iType        = EMsgStoreMessageContainer;
       
   358     event.iFlags       = KMsgStoreFlagsNotFound;
       
   359     event.iId          = message1->Id();
       
   360     event.iParentId    = folderId;
       
   361     event.iOtherId     = folder2Id; 
       
   362     expectedEvents.AppendL( event );
       
   363         
       
   364     mailBox1->MoveMessageL( message1->Id(), folder2Id, folderId );
       
   365     event.iMailBoxId   = mailBox1->Id();
       
   366     event.iOperation   = EMsgStoreMove;
       
   367     event.iFlags       = KMsgStoreFlagsNotFound;
       
   368     event.iType        = EMsgStoreMessageContainer;
       
   369     event.iId          = message1->Id();
       
   370     event.iParentId    = folder2Id;
       
   371     event.iOtherId     = folderId;  
       
   372     expectedEvents.AppendL( event );
       
   373         
       
   374     mailBox1->MoveMessageL( message3->Id(), folderId, folder2Id );
       
   375     event.iMailBoxId   = mailBox1->Id();
       
   376     event.iOperation   = EMsgStoreMove;
       
   377     event.iFlags       = 99999;
       
   378     event.iType        = EMsgStoreMessageContainer;
       
   379     event.iId          = message3->Id();
       
   380     event.iParentId    = folderId;
       
   381     event.iOtherId     = folder2Id; 
       
   382     expectedEvents.AppendL( event );
       
   383         
       
   384     mailBox1->MoveMessageL( message3->Id(), folder2Id, folderId );
       
   385     event.iMailBoxId   = mailBox1->Id();
       
   386     event.iOperation   = EMsgStoreMove;
       
   387     event.iFlags       = 99999;
       
   388     event.iType        = EMsgStoreMessageContainer;
       
   389     event.iId          = message3->Id();
       
   390     event.iParentId    = folder2Id;
       
   391     event.iOtherId     = folderId;  
       
   392     expectedEvents.AppendL( event );
       
   393         
       
   394     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   395     
       
   396     iLog->Log( _L("Case %d: Update properties events"), iCaseId++ );
       
   397     
       
   398     message1->StorePropertiesL();           
       
   399     event.iMailBoxId   = mailBox1->Id();
       
   400     event.iOperation   = EMsgStoreUpdateProperties;
       
   401     event.iType        = EMsgStoreMessageContainer;
       
   402     event.iFlags       = KMsgStoreFlagsNotFound;
       
   403     event.iId          = message1->Id();
       
   404     event.iParentId    = folderId;
       
   405     event.iOtherId     = mailBox1->Id();    
       
   406     expectedEvents.AppendL( event );
       
   407         
       
   408     message2->StorePropertyL( 0 );          
       
   409     event.iMailBoxId   = mailBox1->Id();
       
   410     event.iOperation   = EMsgStoreUpdateProperties;
       
   411     event.iType        = EMsgStoreMessageContainer;
       
   412     event.iFlags       = 12345;
       
   413     event.iId          = message2->Id();
       
   414     event.iParentId    = folderId;
       
   415     event.iOtherId     = mailBox1->Id();    
       
   416     expectedEvents.AppendL( event );
       
   417     
       
   418     CMsgStoreFolder* folder = mailBox1->FolderL( folderId );    
       
   419     CleanupStack::PushL( folder );                                               //+15
       
   420     folder->StorePropertiesL();         
       
   421     event.iMailBoxId   = mailBox1->Id();
       
   422     event.iOperation   = EMsgStoreUpdateProperties;
       
   423     event.iType        = EMsgStoreFolderContainer;
       
   424     event.iFlags       = KMsgStoreFlagsNotFound;
       
   425     event.iId          = folderId;
       
   426     event.iParentId    = mailBox1->Id();
       
   427     event.iOtherId     = KMsgStoreRootMailBoxId;    
       
   428     expectedEvents.AppendL( event );                
       
   429         
       
   430     folder->StorePropertyL( 0 );            
       
   431     event.iMailBoxId   = mailBox1->Id();
       
   432     event.iOperation   = EMsgStoreUpdateProperties;
       
   433     event.iType        = EMsgStoreFolderContainer;
       
   434     event.iFlags       = KMsgStoreFlagsNotFound;
       
   435     event.iId          = folderId;
       
   436     event.iParentId    = mailBox1->Id();
       
   437     event.iOtherId     = KMsgStoreRootMailBoxId;    
       
   438     expectedEvents.AppendL( event );                
       
   439         
       
   440     part1->StorePropertiesL();          
       
   441     event.iMailBoxId   = mailBox1->Id();
       
   442     event.iOperation   = EMsgStoreUpdateProperties;
       
   443     event.iType        = EMsgStorePartContainer;
       
   444     event.iFlags       = KMsgStoreFlagsNotFound;
       
   445     event.iId          = part1->Id();
       
   446     event.iParentId    = message1->Id();
       
   447     event.iOtherId     = folderId;  
       
   448     expectedEvents.AppendL( event );
       
   449     
       
   450     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   451     
       
   452     iLog->Log( _L("Case %d: Update content events"), iCaseId++ );
       
   453     
       
   454     part1->AppendToContentL( _L8("SOME MORE CONTENT") );                            
       
   455     event.iMailBoxId   = mailBox1->Id();
       
   456     event.iOperation   = EMsgStoreUpdateContent;
       
   457     event.iType        = EMsgStorePartContainer;
       
   458     event.iFlags       = KMsgStoreFlagsNotFound;
       
   459     event.iId          = part1->Id();
       
   460     event.iParentId    = message1->Id();
       
   461     event.iOtherId     = folderId;  
       
   462     expectedEvents.AppendL( event );
       
   463         
       
   464     message1->ReplaceContentL( _L8("NEW CONTENT") );                            
       
   465     event.iMailBoxId   = mailBox1->Id();
       
   466     event.iOperation   = EMsgStoreUpdateContent;
       
   467     event.iType        = EMsgStoreMessageContainer;
       
   468     event.iFlags       = KMsgStoreFlagsNotFound;
       
   469     event.iId          = message1->Id();
       
   470     event.iParentId    = folderId;
       
   471     event.iOtherId     = mailBox1->Id();    
       
   472     expectedEvents.AppendL( event );
       
   473         
       
   474     message2->ReplaceContentWithFileL( KFilename );                         
       
   475     event.iMailBoxId   = mailBox1->Id();
       
   476     event.iOperation   = EMsgStoreUpdateContent;
       
   477     event.iType        = EMsgStoreMessageContainer;
       
   478     event.iFlags       = KMsgStoreFlagsNotFound;
       
   479     event.iId          = message2->Id();
       
   480     event.iParentId    = folderId;
       
   481     event.iOtherId     = mailBox1->Id();    
       
   482     expectedEvents.AppendL( event );
       
   483         
       
   484     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   485     
       
   486     iLog->Log( _L("Case %d: Remove content events"), iCaseId++ );
       
   487     
       
   488     part1->RemoveContentL();
       
   489     event.iMailBoxId   = mailBox1->Id();
       
   490     event.iOperation   = EMsgStoreRemoveContent;
       
   491     event.iType        = EMsgStorePartContainer;
       
   492     event.iFlags       = KMsgStoreFlagsNotFound;
       
   493     event.iId          = part1->Id();
       
   494     event.iParentId    = message1->Id();
       
   495     event.iOtherId     = folderId;  
       
   496     expectedEvents.AppendL( event );
       
   497         
       
   498     message2->RemoveContentL();                         
       
   499     event.iMailBoxId   = mailBox1->Id();
       
   500     event.iOperation   = EMsgStoreRemoveContent;
       
   501     event.iType        = EMsgStoreMessageContainer;
       
   502     event.iFlags       = KMsgStoreFlagsNotFound;
       
   503     event.iId          = message2->Id();
       
   504     event.iParentId    = folderId;
       
   505     event.iOtherId     = mailBox1->Id();    
       
   506     expectedEvents.AppendL( event );
       
   507         
       
   508     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   509         
       
   510     iLog->Log( _L("Case %d: Copy events"), iCaseId++ );
       
   511     
       
   512     TMsgStoreId copyId = mailBox1_too->CopyMessageL( message1->Id(), folderId, folder2Id );
       
   513 
       
   514     event.iMailBoxId   = mailBox1->Id();
       
   515     event.iOperation   = EMsgStoreAdd;
       
   516     event.iType        = EMsgStoreMessageContainer;
       
   517     event.iFlags       = KMsgStoreFlagsNotFound;
       
   518     event.iId          = copyId;
       
   519     event.iParentId    = folder2Id;
       
   520     //Per Gypsy UI's request, when copying messages, we now send the original message id
       
   521     // in the aOtherId field of the notification ( MotificationNotify() ). 
       
   522     event.iOtherId     = message1->Id();    
       
   523     expectedEvents.AppendL( event );
       
   524         
       
   525     VerifyRecordedObserverEventsL( EFalse, expectedEvents );            
       
   526             
       
   527     iLog->Log( _L("Case %d: Delete events"), iCaseId++ );
       
   528         
       
   529     mailBox1->DeleteMessageL( message2->Id(), folderId );
       
   530     
       
   531     event.iMailBoxId   = mailBox1->Id();
       
   532     event.iOperation   = EMsgStoreDelete;
       
   533     event.iType        = EMsgStoreMessageContainer;
       
   534     event.iFlags       = 12345;
       
   535     event.iId          = message2->Id();
       
   536     event.iParentId    = folderId;
       
   537     event.iOtherId     = mailBox1->Id();    
       
   538     
       
   539     expectedEvents.AppendL( event );
       
   540     
       
   541     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   542         
       
   543     message1->RemoveChildPartL( part1->Id() );
       
   544     
       
   545     event.iMailBoxId   = mailBox1->Id();
       
   546     event.iOperation   = EMsgStoreDelete;
       
   547     event.iType        = EMsgStorePartContainer;
       
   548     event.iFlags       = KMsgStoreFlagsNotFound;
       
   549     event.iId          = part1->Id();
       
   550     event.iParentId    = message1->Id();
       
   551     event.iOtherId     = folderId;  
       
   552     expectedEvents.AppendL( event );
       
   553         
       
   554     VerifyRecordedObserverEventsL( ETrue, expectedEvents );         
       
   555     
       
   556     mailBox1->DeleteFolderL( folderId );
       
   557         
       
   558     event.iMailBoxId   = mailBox1->Id();
       
   559     event.iOperation   = EMsgStoreDelete;
       
   560     event.iType        = EMsgStoreFolderContainer;
       
   561     event.iFlags       = KMsgStoreFlagsNotFound;
       
   562     event.iId          = folderId;
       
   563     event.iParentId    = mailBox1->Id();
       
   564     event.iOtherId     = KMsgStoreRootMailBoxId;    
       
   565     expectedEvents.AppendL( event );
       
   566         
       
   567     VerifyRecordedObserverEventsL( ETrue, expectedEvents );
       
   568 
       
   569     iLog->Log( _L("Case %d: Database wiped system event"), iCaseId++ );
       
   570             
       
   571     session1->WipeEverythingL();
       
   572     
       
   573     // one per each session         
       
   574     event.iMailBoxId   = -1;
       
   575     event.iOperation   = EMsgStoreDatabaseWiped;
       
   576     event.iType        = -1;
       
   577     event.iFlags       = (TUint32)-1;
       
   578     event.iId          = -1;
       
   579     event.iParentId    = -1;
       
   580     event.iOtherId     = -1;
       
   581     
       
   582     expectedEvents.AppendL( event );
       
   583     expectedEvents.AppendL( event );
       
   584 
       
   585     VerifyRecordedObserverEventsL( EFalse, expectedEvents );            
       
   586     
       
   587     iLog->Log( _L("Case %d: Backup/restore system events"), iCaseId++ );
       
   588 
       
   589     TriggerBackupRestoreEventL( conn::EBURBackupFull );
       
   590 
       
   591     // one per each session         
       
   592     event.iMailBoxId   = -1;
       
   593     event.iOperation   = EMsgStoreBackupOrRestoreInProgress;
       
   594     event.iType        = -1;
       
   595     event.iFlags       = KMsgStoreFlagsNotFound;
       
   596     event.iId          = -1;
       
   597     event.iParentId    = -1;
       
   598     event.iOtherId     = -1;    
       
   599     
       
   600     expectedEvents.AppendL( event );
       
   601     expectedEvents.AppendL( event );
       
   602 
       
   603     VerifyRecordedObserverEventsL( EFalse, expectedEvents );            
       
   604     
       
   605     
       
   606     TriggerBackupRestoreEventL( 0 );
       
   607 
       
   608     // one per each session         
       
   609     event.iOperation   = EMsgStoreBackupOrRestoreCompleted;
       
   610     expectedEvents.AppendL( event );
       
   611     expectedEvents.AppendL( event );
       
   612 
       
   613     VerifyRecordedObserverEventsL( EFalse, expectedEvents );            
       
   614         
       
   615     iLog->Log( _L("Case %d: PointSec system lock events"), iCaseId++ );
       
   616 
       
   617     TriggerPointSecEventL( ETrue );
       
   618 
       
   619     // one per each session         
       
   620     event.iMailBoxId   = -1;
       
   621     event.iOperation   = EMsgStorePointSecLockStarted;
       
   622     event.iType        = -1;
       
   623     event.iFlags       = KMsgStoreFlagsNotFound;
       
   624     event.iId          = -1;
       
   625     event.iParentId    = -1;
       
   626     event.iOtherId     = -1;    
       
   627     
       
   628     expectedEvents.AppendL( event );
       
   629     expectedEvents.AppendL( event );
       
   630 
       
   631     VerifyRecordedObserverEventsL( EFalse, expectedEvents );            
       
   632     
       
   633     TriggerPointSecEventL( EFalse );
       
   634 
       
   635     // one per each session         
       
   636     event.iOperation   = EMsgStorePointSecLockEnded;
       
   637     expectedEvents.AppendL( event );
       
   638     expectedEvents.AppendL( event );
       
   639 
       
   640     VerifyRecordedObserverEventsL( EFalse, expectedEvents );            
       
   641         
       
   642     
       
   643     //Begin PointSec
       
   644 #if 0    
       
   645     TInt rc = RProperty::Define( KPsUidPointsec, KUidPointsecStatus, RProperty::EInt );
       
   646     rc = RProperty::Set( KPsUidPointsec, KUidPointsecStatus, EPointsecLocked );
       
   647     event.iOperation   = EMsgStorePointSecLockStarted;
       
   648     expectedEvents.AppendL( event );
       
   649     expectedEvents.AppendL( event );
       
   650 
       
   651     VerifyRecordedObserverEventsL( EFalse, expectedEvents );
       
   652     
       
   653     rc = RProperty::Set( KPsUidPointsec, KUidPointsecStatus, EPointsecUnlocked );
       
   654     event.iOperation   = EMsgStorePointSecLockEnded;
       
   655     expectedEvents.AppendL( event );
       
   656     expectedEvents.AppendL( event );
       
   657 
       
   658     VerifyRecordedObserverEventsL( EFalse, expectedEvents );
       
   659 #endif    
       
   660     //End PointSec
       
   661     
       
   662     StopRecordingObserverEvents();
       
   663     
       
   664     
       
   665     iLog->Log( _L("Case %d: Remove Mailbox Observers"), iCaseId++ );
       
   666     mailBox1->RemoveObserverL( this );
       
   667     mailBox2->RemoveObserverL( this );
       
   668     
       
   669     iLog->Log( _L("Case %d: Large number of observers on large number of sessions"), iCaseId++ );
       
   670 
       
   671     RPointerArray<CMsgStore> sessions;
       
   672     
       
   673     for( TInt i = 0; i < 20; i++ )
       
   674         {
       
   675         CMsgStore* session = CMsgStore::NewL();
       
   676         session->AddObserverL( this );
       
   677         
       
   678         sessions.AppendL( session );        
       
   679         }
       
   680 
       
   681     session1->WipeEverythingL();
       
   682     
       
   683     for( TInt i = 0; i < 20; i++ )
       
   684         {
       
   685         sessions[i]->RemoveObserverL( this );
       
   686         sessions[i]->AddObserverL( this );        
       
   687         }
       
   688 
       
   689     session1->WipeEverythingL();
       
   690     
       
   691     sessions.ResetAndDestroy();
       
   692     
       
   693     CleanupStack::PopAndDestroy( 15 );
       
   694     
       
   695     //we are done 
       
   696     return ETrue;
       
   697     }
       
   698 
       
   699 
       
   700 void CObserverTests::StartRecordingObserverEvents()
       
   701     {
       
   702     iRecordEvents = ETrue;
       
   703     }
       
   704 
       
   705 void CObserverTests::StopRecordingObserverEvents()
       
   706     {
       
   707     iRecordEvents = ETrue;
       
   708     iRecordedEvents.Reset();
       
   709     }
       
   710 
       
   711 void CObserverTests::VerifyRecordedObserverEventsL( TBool aVerifyOrder, RArray<TObserverEvent>& aExpectedEvents )
       
   712     {
       
   713     iLog->Log( _L("  >> VerifyRecordedObserverEventsL") );
       
   714     
       
   715     // Allow all events to propagate.
       
   716     TInt loopCount = 0;
       
   717     while( loopCount < 1000 && iRecordedEvents.Count() < aExpectedEvents.Count() )
       
   718         {
       
   719         Yield( 10000 );
       
   720         loopCount++;
       
   721         }
       
   722 
       
   723     TBool matched = ( aExpectedEvents.Count() == iRecordedEvents.Count() );
       
   724     
       
   725     CheckCondition( _L("correct number of recorded events"), matched );
       
   726     
       
   727     TObserverEvent expectedEvent;
       
   728     TObserverEvent recordedEvent;
       
   729     
       
   730     while( matched && (aExpectedEvents.Count() > 0 ) )
       
   731         {
       
   732         expectedEvent = aExpectedEvents[0];
       
   733         
       
   734         TUint highestCompareIndex = 0; 
       
   735         if( !aVerifyOrder )
       
   736             {
       
   737             highestCompareIndex = iRecordedEvents.Count() - 1;
       
   738             }
       
   739             
       
   740         TBool found = EFalse;
       
   741         TUint compareIndex = 0;
       
   742         while( !found && compareIndex <= highestCompareIndex )
       
   743             {
       
   744             recordedEvent = iRecordedEvents[compareIndex];
       
   745             
       
   746             if (recordedEvent.iMailBoxId   == expectedEvent.iMailBoxId &&
       
   747                 recordedEvent.iOperation   == expectedEvent.iOperation &&
       
   748                 recordedEvent.iType        == expectedEvent.iType      &&
       
   749                 recordedEvent.iFlags       == expectedEvent.iFlags     &&
       
   750                 recordedEvent.iId          == expectedEvent.iId        &&
       
   751                 recordedEvent.iParentId    == expectedEvent.iParentId  &&
       
   752                 recordedEvent.iOtherId     == expectedEvent.iOtherId   &&
       
   753                 recordedEvent.iName        == expectedEvent.iName      &&
       
   754                 recordedEvent.iNewName     == expectedEvent.iNewName )
       
   755                 {
       
   756                 found = ETrue;
       
   757                 iRecordedEvents.Remove( compareIndex );
       
   758                 }
       
   759             else
       
   760                 {                   
       
   761                 compareIndex++;                     
       
   762                 } // end if
       
   763             }
       
   764         aExpectedEvents.Remove( 0 );
       
   765         
       
   766         matched = (matched && found);
       
   767         }
       
   768     
       
   769     aExpectedEvents.Reset();
       
   770     
       
   771     CheckCondition( _L("recorded events matched"), matched );
       
   772     
       
   773     iLog->Log( _L("  << VerifyRecordedObserverEventsL") );
       
   774     }
       
   775 
       
   776 void CObserverTests::ModificationNotify( TMsgStoreId aMailBoxId, TMsgStoreOperation aOperation, TMsgStoreContainerType aType, TUint32 aFlags, TMsgStoreId aId, TMsgStoreId aParentId, TMsgStoreId aOtherId )
       
   777     {
       
   778     iLog->Log( _L("  ModificationNotify %i"), iRecordedEvents.Count()+1 );
       
   779     
       
   780     if( iRecordEvents )
       
   781         {
       
   782         TObserverEvent event;
       
   783         event.iMailBoxId   = aMailBoxId;
       
   784         event.iOperation   = aOperation;
       
   785         event.iType        = aType;
       
   786         event.iFlags       = aFlags;
       
   787         event.iId          = aId;
       
   788         event.iParentId    = aParentId;
       
   789         event.iOtherId     = aOtherId;
       
   790         event.iName.SetLength( 0 );
       
   791         event.iNewName.SetLength( 0 );
       
   792         
       
   793         iRecordedEvents.Append( event );
       
   794         }
       
   795     }
       
   796         
       
   797 void CObserverTests::SystemEventNotify( TMsgStoreSystemEvent aEvent )
       
   798     {
       
   799     iLog->Log( _L("  >> SystemEventNotify") );
       
   800     
       
   801     if( iRecordEvents )
       
   802         {
       
   803         TObserverEvent event;
       
   804         event.iMailBoxId   = -1;
       
   805         event.iOperation   = aEvent;
       
   806         event.iType        = -1;
       
   807         event.iFlags       = KMsgStoreFlagsNotFound;
       
   808         event.iId          = -1;
       
   809         event.iParentId    = -1;
       
   810         event.iOtherId     = -1;
       
   811         event.iName.SetLength( 0 );
       
   812         event.iNewName.SetLength( 0 );
       
   813         
       
   814         iRecordedEvents.Append( event );
       
   815         }
       
   816     
       
   817     iLog->Log( _L("  << SystemEventNotify") );
       
   818     }
       
   819 void CObserverTests::AccountEventNotify( TMsgStoreAccountEvent aEvent, TInt32 aOwnerId, const TDesC& aName, const TDesC& aNewName, TMsgStoreId aMailboxId )
       
   820     {
       
   821     iLog->Log( _L("  >> AccountEventNotify") );
       
   822     if( iRecordEvents )
       
   823         {
       
   824         TObserverEvent event;
       
   825         event.iMailBoxId   = aMailboxId;
       
   826         event.iOperation   = aEvent;
       
   827         event.iType        = KMsgStoreInvalidId;
       
   828         event.iFlags       = KMsgStoreFlagsNotFound;
       
   829         event.iId          = aOwnerId;
       
   830         event.iParentId    = KMsgStoreInvalidId;
       
   831         event.iOtherId     = KMsgStoreInvalidId;
       
   832         event.iName.Copy( aName );
       
   833         event.iNewName.Copy( aNewName );
       
   834         
       
   835         iRecordedEvents.Append( event );
       
   836         }
       
   837     iLog->Log( _L("  << AccountEventNotify") );
       
   838     }
       
   839 
       
   840 //  End of File