emailservices/emailstore/tsrc/message_store_test/src/PropertyTests.cpp
changeset 1 12c456ceeff2
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 <tz.h>
       
    22 #include "PropertyTests.h"
       
    23 #include <msgstoreapi.h>
       
    24 //#include <ismsgstorepropertykeys.h>
       
    25 #include "messagestoreclientserver.h"
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 CPropertyTests* CPropertyTests::NewL( CStifLogger* aLog )
       
    30     {
       
    31     CPropertyTests* self = new(ELeave) CPropertyTests( aLog );
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop( self );
       
    35     return self;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // Constructor
       
    40 // -----------------------------------------------------------------------------
       
    41 CPropertyTests::CPropertyTests( CStifLogger* aLog ) : CAsyncTestCaseBase( aLog ) 
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // Destructor
       
    47 // -----------------------------------------------------------------------------
       
    48 CPropertyTests::~CPropertyTests()
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // 2nd phase constructor
       
    54 // -----------------------------------------------------------------------------
       
    55 void CPropertyTests::ConstructL()
       
    56     {
       
    57     CAsyncTestCaseBase::ConstructL();
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // ExecuteL : start executing the test case
       
    62 // -----------------------------------------------------------------------------
       
    63 TBool CPropertyTests::ExecuteL()
       
    64     {
       
    65     LogHeader( _L("Property") );
       
    66     
       
    67     iLog->Log( _L("Case %d: Manipulation of properties in RAM."), iCaseId++ );
       
    68     
       
    69     CMsgStorePropertyContainer* properties = CMsgStorePropertyContainer::NewL();
       
    70 
       
    71     CheckCondition( _L("default IDs"), properties->Id() == KMsgStoreInvalidId && properties->ParentId() == KMsgStoreInvalidId );
       
    72 
       
    73     // "quick" properties
       
    74     iLog->Log( _L("Case %d: Add integer properties"), iCaseId++ );
       
    75     TUint flagsIndex = TestAddIntegerPropertyL( *properties, KMsgStorePropertyFlags, EMsgStoreFlag_Read_Locally );
       
    76     TestAddIntegerPropertyL( *properties, KMsgStorePropertyReplyBy, 1 );
       
    77     TestAddIntegerPropertyL( *properties, KMsgStorePropertyCompletedAt, 2 );
       
    78     TestAddIntegerPropertyL( *properties, KMsgStorePropertyReceivedAt, 3, ETrue );
       
    79     
       
    80     // integer
       
    81     TUint intIndex1 = TestAddIntegerPropertyL( *properties, _L8("TOTALCONTENTSIZE"), 1000 );
       
    82     TUint intIndex2 = TestAddIntegerPropertyL( *properties, _L8("RETRIEVEMORE"), ETrue );
       
    83     TUint intIndex3 = TestAddIntegerPropertyL( *properties, _L8("ABC"), 1500 );
       
    84 
       
    85     // bool
       
    86     iLog->Log( _L("Case %d: Add boolean properties"), iCaseId++ );
       
    87     TUint boolIndex1 = TestAddBoolPropertyL( *properties, _L8("BOOL1"), ETrue );
       
    88     TUint boolIndex2 = TestAddBoolPropertyL( *properties, _L8("BOOL2"), EFalse, ETrue );
       
    89     
       
    90     
       
    91     // 8-bit descriptor
       
    92     iLog->Log( _L("Case %d: Add 8-bit descriptor properties"), iCaseId++ );
       
    93     TUint stringIndex1 = TestAddDes8PropertyL( *properties, _L8("SOME OTHER PROPERTY"), _L8("SOME VALUE") );
       
    94     TUint stringIndex2 = TestAddDes8PropertyL( *properties, _L8("YET ANOTHER PROPERTY"), _L8("YET ANOTHER VALUE"), ETrue );
       
    95     
       
    96     // 16-bit descriptor            
       
    97     iLog->Log( _L("Case %d: Add 16-bit descriptor properties"), iCaseId++ );
       
    98     TUint stringIndex3 = TestAddDesPropertyL( *properties, _L8("XYZ"), _L("sdfhsdgjg") );
       
    99     TestAddDesPropertyL( *properties, _L8("XYZ1"), _L("sdfhsdgjg1"), ETrue );
       
   100 
       
   101     // container            
       
   102     iLog->Log( _L("Case %d: Add container properties"), iCaseId++ );
       
   103     CMsgStorePropertyContainer* subproperties = CMsgStorePropertyContainer::NewL();
       
   104     TestAddIntegerPropertyL( *subproperties, _L8("TOTALCONTENTSIZE"), 1000 );
       
   105     TestAddDes8PropertyL( *subproperties, _L8("SOME OTHER PROPERTY"), _L8("SOME VALUE") );          
       
   106     TestAddDesPropertyL( *subproperties, _L8("XYZ"), _L("sdfhsdgjg") );
       
   107     
       
   108     TUint containerIndex1 = TestAddContainerPropertyL( *properties, _L8("container 1"), *subproperties );
       
   109     TUint containerIndex2 = TestAddContainerPropertyL( *properties, _L8("container 2"), *subproperties );
       
   110     
       
   111     delete subproperties;
       
   112     
       
   113     // time
       
   114     iLog->Log( _L("Case %d: Add TTime properties"), iCaseId++ );
       
   115     TTime time1;
       
   116     time1.HomeTime();
       
   117     TTime time2( 1000 );
       
   118     
       
   119     TUint timeIndex1 = TestAddTimePropertyL( *properties, _L8("TIME PROPERTY 1"), time1);
       
   120     TUint timeIndex2 = TestAddTimePropertyL( *properties, _L8("TIME PROPERTY 2"), time2);
       
   121     
       
   122     //Address
       
   123     iLog->Log( _L("Case %d: Add Address properties"), iCaseId++ );
       
   124     RMsgStoreAddress address1, address2;
       
   125     CleanupClosePushL( address1 );
       
   126     CleanupClosePushL( address2 );
       
   127     address1.iEmailAddress.Create(_L("myAddres1@nokia.com"));
       
   128     address1.iDisplayName.Create(_L("My Name 1"));
       
   129     address2.iEmailAddress.Create(_L("myAddres2@nokia.com"));
       
   130     address2.iDisplayName.Create(_L("My Name 2"));
       
   131     
       
   132     TUint addressIndex1 = TestAddAddressPropertyL( *properties, _L8("ADDRESS PROPERTY 1"), address1);
       
   133     TUint addressIndex2 = TestAddAddressPropertyL( *properties, _L8("ADDRESS PROPERTY 2"), address2);
       
   134     
       
   135     CleanupStack::PopAndDestroy(2);
       
   136     
       
   137     // Test long property names and values.
       
   138     iLog->Log( _L("Case %d: Test long property names and values"), iCaseId++ );
       
   139     TBuf8<255> longName;
       
   140     RBuf8 longValue;
       
   141     longValue.CreateL( 65535 );  // boundary case
       
   142     
       
   143     longName.Fill( 'N', 255 );
       
   144     longValue.Fill( 'V', 65535 );
       
   145     
       
   146     TUint longIndex = TestAddDes8PropertyL( *properties, longName, longValue );
       
   147     
       
   148     longValue.Close();
       
   149     
       
   150     // Test shrinking the size of a property from long to short.
       
   151     iLog->Log( _L("Case %d: Test shrinking the size of a property from long to short"), iCaseId++ );
       
   152     TestUpdateDes8PropertyL( *properties, longIndex, _L8("ASDFGHJKL:") );   
       
   153     
       
   154     // Test growing short property back to long property.
       
   155     iLog->Log( _L("Case %d: Test growing short property back to long property"), iCaseId++ );
       
   156     longValue.CreateL( 70000 );
       
   157     longValue.Fill( 'V', 70000 );
       
   158     
       
   159     TestUpdateDes8PropertyL( *properties, longIndex, longValue );   
       
   160     
       
   161     longValue.Close();      
       
   162     
       
   163     // Test update.         
       
   164     subproperties = CMsgStorePropertyContainer::NewL();
       
   165     TestAddIntegerPropertyL( *subproperties, _L8("X"), 1 );
       
   166     
       
   167     iLog->Log( _L("Case %d: Update boolean property"), iCaseId++ );
       
   168     TestUpdateBoolPropertyL( *properties, boolIndex1, EFalse );
       
   169     TestUpdateBoolPropertyL( *properties, boolIndex1, ETrue, ETrue );
       
   170     
       
   171     iLog->Log( _L("Case %d: Update integer property"), iCaseId++ );
       
   172     TestUpdateIntegerPropertyL( *properties, intIndex1, 987 );
       
   173     TestUpdateIntegerPropertyL( *properties, intIndex1, 986, ETrue );
       
   174     
       
   175     iLog->Log( _L("Case %d: Update 8-bit descriptor property"), iCaseId++ );
       
   176     TestUpdateDes8PropertyL( *properties, stringIndex1, _L8("ASDFGHJKL:") );
       
   177     TestUpdateDes8PropertyL( *properties, stringIndex1, _L8("ASDFGHJKL:1"), ETrue );
       
   178     
       
   179     iLog->Log( _L("Case %d: Update 16-bit descriptor property"), iCaseId++ );
       
   180     TestUpdateDesPropertyL( *properties, stringIndex3, _L(",mxcn,mxbxcbmbnxv") );
       
   181     TestUpdateDesPropertyL( *properties, stringIndex3, _L(",mxcn,mxbxcbmbnxv"), ETrue );
       
   182     
       
   183     iLog->Log( _L("Case %d: Update container property"), iCaseId++ );
       
   184     TestUpdateContainerPropertyL( *properties, containerIndex2, *subproperties );
       
   185 
       
   186     TestAddIntegerPropertyL( *subproperties, _L8("Y"), 2 );
       
   187     TestUpdateContainerPropertyL( *properties, containerIndex2, *subproperties, ETrue );
       
   188 
       
   189     delete subproperties;
       
   190     
       
   191     iLog->Log( _L("Case %d: Update TTime property"), iCaseId++ );
       
   192     time2 = 1000000;
       
   193     TestUpdateTimePropertyL( *properties, timeIndex1, time2 );
       
   194     time2 = 1000000;
       
   195     TestUpdateTimePropertyL( *properties, timeIndex1, time2, ETrue );
       
   196 
       
   197     iLog->Log( _L("Case %d: Update address property"), iCaseId++ );
       
   198     RMsgStoreAddress address3;
       
   199     
       
   200     CleanupClosePushL(address3);
       
   201     
       
   202     address3.iDisplayName.Create(_L("new name"));  
       
   203     TestUpdateAddressPropertyL( *properties, addressIndex1, address3 );
       
   204     address3.iEmailAddress.Create( _L("mail@com")); 
       
   205     TestUpdateAddressPropertyL( *properties, addressIndex1, address3, ETrue );
       
   206     
       
   207     CleanupStack::PopAndDestroy( &address3 );
       
   208                 
       
   209     // Test remove.
       
   210     iLog->Log( _L("Case %d: Remove property"), iCaseId++ );
       
   211     TestRemovePropertyL( *properties, intIndex3 );
       
   212     TestRemovePropertyL( *properties, stringIndex3 );
       
   213     
       
   214     iLog->Log( _L("Case %d: Store properties as a message and verify stored message"), iCaseId++ );
       
   215 
       
   216     CMsgStoreAccount* account = CMsgStoreAccount::NewLC(1234, _L("my account") );  //+1
       
   217     CMsgStoreMailBox* mailBox1 = iMsgStore->CreateAccountL( *account );
       
   218     CleanupStack::PushL( mailBox1 );                                               //+2
       
   219     
       
   220     TMsgStoreId folderId = mailBox1->CreateFolderL( mailBox1->Id(), *properties);
       
   221 
       
   222     CMsgStoreMessage* message = mailBox1->CreateMessageL( folderId, *properties );
       
   223     CleanupStack::PushL( message );                                               //+3
       
   224     message->CommitL();
       
   225     TMsgStoreId messageId = message->Id();
       
   226     
       
   227     ComparePropertiesL( *message, *properties );
       
   228     CheckCondition( _L("IDs"), message->Id() != KMsgStoreInvalidId && message->ParentId() == folderId );
       
   229 
       
   230     // fetch message
       
   231     CMsgStoreMessage* message2 = mailBox1->FetchMessageL( messageId, folderId );
       
   232     CleanupStack::PushL( message2 );                                                //+4
       
   233     ComparePropertiesL( *message2, *message );
       
   234     CheckCondition( _L("IDs"), message2->Id() == message->Id() && message2->ParentId() == message->ParentId() );
       
   235 
       
   236     // fetch message without specifying parent ID
       
   237     CMsgStoreMessage* message3 = mailBox1->FetchMessageL( messageId, KMsgStoreInvalidId );
       
   238     CleanupStack::PushL( message3 );                                                //+5
       
   239     ComparePropertiesL( *message3, *message );
       
   240     CheckCondition( _L("IDs"), message3->Id() == message->Id() && message3->ParentId() == message->ParentId() );
       
   241 
       
   242     iLog->Log( _L("Case %d: Test FetchPropertiesL"), iCaseId++ );
       
   243     //create another message that has the same properties as message1
       
   244     CMsgStoreMessage* message4 = mailBox1->CreateMessageL( folderId, *properties );
       
   245     CleanupStack::PushL( message4 );                                               //+6
       
   246     message4->CommitL();
       
   247     RArray<TMsgStoreId> ids;
       
   248     ids.Append( message->Id() );
       
   249     ids.Append( message4->Id() );
       
   250     RPointerArray<TDesC8> propNames;
       
   251     _LIT8( KAddProp1, "ADDRESS PROPERTY 1" );
       
   252     _LIT8( KAddProp2, "ADDRESS PROPERTY 2" );
       
   253     propNames.Append( &KAddProp1 );
       
   254     propNames.Append( &KAddProp2 );
       
   255     RPointerArray<CMsgStorePropertyContainer> propArray;
       
   256     mailBox1->FetchPropertiesL( ids, propNames, propArray );
       
   257     CheckCondition( _L("PropertyCounts match"), ids.Count() == propArray.Count() );
       
   258     ComparePropertiesL( *propArray[0], *propArray[1] );
       
   259     ids.Reset();
       
   260     propNames.Reset();
       
   261     propArray.ResetAndDestroy();
       
   262     
       
   263     iLog->Log( _L("Case %d: Update message properties and store"), iCaseId++ );
       
   264     TestAddIntegerPropertyL( *message, _L8("NEW INT PROPERTY"), 135  );         
       
   265     TestAddDes8PropertyL( *message, _L8("NEW STRING PROPERTY"), _L8("NEW VALUE") );
       
   266     TestUpdateIntegerPropertyL( *message, intIndex1, 17475 );
       
   267     TestUpdateDes8PropertyL( *message, stringIndex1, _L8("zxxcvb") );
       
   268     TestRemovePropertyL( *message, intIndex2 );
       
   269     TestRemovePropertyL( *message, stringIndex2 );
       
   270     
       
   271     message->StorePropertiesL();
       
   272 
       
   273     // fetch message
       
   274     message2 = mailBox1->FetchMessageL( messageId, folderId );
       
   275     ComparePropertiesL( *message2, *message );
       
   276     CheckCondition( _L("IDs"), message2->Id() == message->Id() && message2->ParentId() == message->ParentId() );
       
   277     delete message2;
       
   278 
       
   279     iLog->Log( _L("Case %d: Update individual message property and store"), iCaseId++ );
       
   280     TestUpdateIntegerPropertyL( *message, flagsIndex, 0 );
       
   281 
       
   282     message->StorePropertyL( flagsIndex );
       
   283     
       
   284     // fetch message
       
   285     message2 = mailBox1->FetchMessageL( messageId, folderId );
       
   286     ComparePropertiesL( *message2, *message );
       
   287     CheckCondition( _L("IDs"), message2->Id() == message->Id() && message2->ParentId() == message->ParentId() );
       
   288     delete message2;
       
   289 
       
   290     iLog->Log( _L("Case %d: Add property and store individually"), iCaseId++ );
       
   291     TMsgStoreId newPropertyIndex = TestAddIntegerPropertyL( *message, _L8("A NEW INTEGER PROPERTY"), 50 );
       
   292 
       
   293     message->StorePropertyL( newPropertyIndex );
       
   294     
       
   295     // fetch message
       
   296     message2 = mailBox1->FetchMessageL( messageId, folderId );
       
   297     ComparePropertiesL( *message2, *message );
       
   298     CheckCondition( _L("IDs"), message2->Id() == message->Id() && message2->ParentId() == message->ParentId() );
       
   299     delete message2;
       
   300 
       
   301     iLog->Log( _L("Case %d: Update individual message property 64K value to short value"), iCaseId++ );
       
   302     message->FindProperty( longName, longIndex );
       
   303     
       
   304     TestUpdateDes8PropertyL( *message, longIndex, _L8("SHORT VALUE AGAIN") );
       
   305 
       
   306     message->StorePropertyL( longIndex );
       
   307     
       
   308     // fetch message
       
   309     message2 = mailBox1->FetchMessageL( messageId, folderId );
       
   310     ComparePropertiesL( *message2, *message );
       
   311     CheckCondition( _L("IDs"), message2->Id() == message->Id() && message2->ParentId() == message->ParentId() );
       
   312     delete message2;
       
   313 
       
   314     iLog->Log( _L("Case %d: Update individual message property from short value to >64K value"), iCaseId++ );
       
   315     longValue.CreateL( 70000 );
       
   316     longValue.Fill( 'V', 70000 );
       
   317     TestUpdateDes8PropertyL( *message, longIndex, longValue );
       
   318 
       
   319     message->StorePropertyL( longIndex );
       
   320     
       
   321     longValue.Close();      
       
   322 
       
   323     // fetch message
       
   324     message2 = mailBox1->FetchMessageL( messageId, folderId );
       
   325     ComparePropertiesL( *message2, *message );
       
   326     CheckCondition( _L("IDs"), message2->Id() == message->Id() && message2->ParentId() == message->ParentId() );
       
   327     delete message2;
       
   328 
       
   329     // ERROR PATH TESTS
       
   330     iLog->Log( _L("Case %d: Error - Find property that does not exist"), iCaseId++ );
       
   331     TUint index = 500;
       
   332     TBool found = properties->FindProperty( _L8("SOME PROPERTY THAT DOES NOT EXIST"), index );
       
   333     CheckCondition( _L("property not found"), !found && (index == 500) );
       
   334 
       
   335     iLog->Log( _L("Case %d: Error - PropertyNameL with an invalid index"), iCaseId++ );
       
   336     TRAPD( result, properties->PropertyNameL( 5000 ) );
       
   337     CheckCondition( _L("property not found"), result == KErrNotFound );
       
   338 
       
   339     iLog->Log( _L("Case %d: Error - PropertyValueDes8L with an invalid index"), iCaseId++ );
       
   340     TRAP( result, properties->PropertyValueDes8L( 5000 ) );
       
   341     CheckCondition( _L("property not found"), result == KErrNotFound );
       
   342 
       
   343     iLog->Log( _L("Case %d: Error - PropertyValueUint32L with an invalid index"), iCaseId++ );
       
   344     TRAP( result, properties->PropertyValueUint32L( 5000 ) );
       
   345     CheckCondition( _L("property not found"), result == KErrNotFound );
       
   346 
       
   347     iLog->Log( _L("Case %d: Error - UpdatePropertyL (string) with an invalid index"), iCaseId++ );
       
   348     TRAP( result, properties->UpdatePropertyL( 5000, _L8("abc") ) );
       
   349     CheckCondition( _L("property not found"), result == KErrNotFound );
       
   350 
       
   351     iLog->Log( _L("Case %d: Error - UpdatePropertyL (integer) with an invalid index"), iCaseId++ );
       
   352     TRAP( result, properties->UpdatePropertyL( 5000, (TUint32)123 ) );
       
   353     CheckCondition( _L("property not found"), result == KErrNotFound );
       
   354 
       
   355     iLog->Log( _L("Case %d: Error - UpdatePropertyL (bool) with an invalid index"), iCaseId++ );
       
   356     TRAP( result, properties->UpdatePropertyL( 5000, (TBool)123 ) );
       
   357     CheckCondition( _L("property not found"), result == KErrNotFound );
       
   358 
       
   359     iLog->Log( _L("Case %d: Error - RemovePropertyL with an invalid index"), iCaseId++ );
       
   360     TRAP( result, properties->RemovePropertyL( 5000 ) );
       
   361     CheckCondition( _L("property not found"), result == KErrNotFound );
       
   362 
       
   363     iLog->Log( _L("Case %d: Error - Fetch message that does not exist"), iCaseId++ );
       
   364     TRAP( result, message2 = mailBox1->FetchMessageL( EMsgStoreMessageBits | 50, folderId ) );
       
   365     CheckCondition( _L("message not found"), result == KErrNotFound );
       
   366     
       
   367     iLog->Log( _L("Case %d: Error - Fetch message exists but is in a different folder"), iCaseId++ );
       
   368     TRAP( result, message2 = mailBox1->FetchMessageL( messageId, folderId + 1 ) );
       
   369     CheckCondition( _L("message not found"), result == KErrNotFound );
       
   370     
       
   371     iLog->Log( _L("Case %d: Error - StoreProperty with an invalid property index"), iCaseId++ );
       
   372     TRAP( result, message->StorePropertyL( 5000 ) );
       
   373     CheckCondition( _L("property not found"), result == KErrNotFound );
       
   374 
       
   375     // OUT OF MEMORY ERROR PATH TESTS
       
   376     iLog->Log( _L("Case %d: Error - Out of memory, CreateMessageL"), iCaseId++ );
       
   377     for( TInt i = 0; i < 2; i++ )
       
   378         {        
       
   379         SimulateLowDiskSpaceL( i );
       
   380         TRAP( result,
       
   381             CMsgStoreMessage* msg = mailBox1->CreateMessageL( folderId, *properties );
       
   382             CleanupStack::PushL( msg );
       
   383             msg->CommitL();
       
   384             CleanupStack::PopAndDestroy( msg );
       
   385         );
       
   386         CheckCondition( _L("out of memory"), result == KErrNoMemory );
       
   387         }
       
   388         
       
   389     iLog->Log( _L("Case %d: Error - Out of memory, StorePropertiesL"), iCaseId++ );
       
   390     for( TInt i = 0; i < 2; i++ )
       
   391         {        
       
   392         SimulateLowDiskSpaceL( i );
       
   393         TRAP( result, message->StorePropertiesL() );
       
   394         CheckCondition( _L("out of memory"), result == KErrNoMemory );
       
   395         }
       
   396         
       
   397     iLog->Log( _L("Case %d: Error - Out of memory, StorePropertyL"), iCaseId++ );
       
   398     for( TInt i = 0; i < 2; i++ )
       
   399         {        
       
   400         SimulateLowDiskSpaceL( i );
       
   401         TRAP( result, message->StorePropertyL( 0 ) );
       
   402         CheckCondition( _L("out of memory"), result == KErrNoMemory );
       
   403         }
       
   404     
       
   405     CleanupStack::PopAndDestroy(6);
       
   406     
       
   407     delete properties;
       
   408     
       
   409     //we are done 
       
   410     return ETrue;
       
   411     }
       
   412 
       
   413 //  End of File