uiservicetab/vimpststorage/tsrc/vimpststorage_ut/cvimpststoragecontact_ut/src/CVIMPSTStorageContact_UTBlocks.cpp
changeset 0 5e5d6b214f4f
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 2009 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 :                
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // [INCLUDE FILES] - do not remove
       
    22 #include <e32svr.h>
       
    23 #include <StifParser.h>
       
    24 #include <StifTestInterface.h>
       
    25 #include "CVIMPSTStorageContact_UT.h"
       
    26 #include "mvimpststoragecontact.h"
       
    27 #include "cvimpststoragecontact.h"
       
    28 //#include <MVPbkContactLink.h>
       
    29 #include "s_MVPbkContactLinkstub.h"
       
    30 
       
    31 _LIT( KUserName, "nokia@nokia.com" );
       
    32 _LIT( KDisplayName, "connectingpeople" );
       
    33 _LIT( KUserName1, "sonyericsson@sony.com" );
       
    34 
       
    35 // EXTERNAL DATA STRUCTURES
       
    36 //extern  ?external_data;
       
    37 
       
    38 // EXTERNAL FUNCTION PROTOTYPES  
       
    39 //extern ?external_function( ?arg_type,?arg_type );
       
    40 
       
    41 // CONSTANTS
       
    42 //const ?type ?constant_var = ?constant;
       
    43 
       
    44 // MACROS
       
    45 //#define ?macro ?macro_def
       
    46 
       
    47 // LOCAL CONSTANTS AND MACROS
       
    48 //const ?type ?constant_var = ?constant;
       
    49 //#define ?macro_name ?macro_def
       
    50 
       
    51 // MODULE DATA STRUCTURES
       
    52 //enum ?declaration
       
    53 //typedef ?declaration
       
    54 
       
    55 // LOCAL FUNCTION PROTOTYPES
       
    56 //?type ?function_name( ?arg_type, ?arg_type );
       
    57 
       
    58 // FORWARD DECLARATIONS
       
    59 //class ?FORWARD_CLASSNAME;
       
    60 
       
    61 // ============================= LOCAL FUNCTIONS ===============================
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // ?function_name ?description.
       
    65 // ?description
       
    66 // Returns: ?value_1: ?description
       
    67 //          ?value_n: ?description_line1
       
    68 //                    ?description_line2
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 /*
       
    72 ?type ?function_name(
       
    73     ?arg_type arg,  // ?description
       
    74     ?arg_type arg)  // ?description
       
    75     {
       
    76 
       
    77     ?code  // ?comment
       
    78 
       
    79     // ?comment
       
    80     ?code
       
    81     }
       
    82 */
       
    83 
       
    84 // ============================ MEMBER FUNCTIONS ===============================
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CCVIMPSTStorageContact_UT::Delete
       
    88 // Delete here all resources allocated and opened from test methods. 
       
    89 // Called from destructor. 
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CCVIMPSTStorageContact_UT::Delete() 
       
    93     {
       
    94 
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CCVIMPSTStorageContact_UT::RunMethodL
       
    99 // Run specified method. Contains also table of test mothods and their names.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 TInt CCVIMPSTStorageContact_UT::RunMethodL( 
       
   103     CStifItemParser& aItem ) 
       
   104     {
       
   105 
       
   106     static TStifFunctionInfo const KFunctions[] =
       
   107         {  
       
   108         // Copy this line for every implemented function.
       
   109         // First string is the function name used in TestScripter script file.
       
   110         // Second is the actual implementation member function. 
       
   111         //ENTRY( "Example", CCVIMPSTStorageContact_UT::ExampleL ),
       
   112         ENTRY( "CreateStorageContact", CCVIMPSTStorageContact_UT::Test_NewL ),
       
   113         ENTRY( "SetGetUserId", CCVIMPSTStorageContact_UT::Test_SetUserId_UserIdL ),
       
   114         ENTRY( "SetAvatarContent", CCVIMPSTStorageContact_UT::Test_AvatarContentL ),
       
   115         ENTRY( "SetGetDisplayName", CCVIMPSTStorageContact_UT::Test_DisplayNameL ),
       
   116         ENTRY( "SetGetPresenceStatus", CCVIMPSTStorageContact_UT::Test_PresenceStatusL ),
       
   117         ENTRY( "SetGetStatusText", CCVIMPSTStorageContact_UT::Test_StatusTextL ),
       
   118         ENTRY( "SetGetAvatarIndex", CCVIMPSTStorageContact_UT::Test_AvatarIndexL ),
       
   119         ENTRY( "ContactLink", CCVIMPSTStorageContact_UT::Test_ContactLinkL ),
       
   120         //ADD NEW ENTRY HERE SetGetAvatarIndex
       
   121         // [test cases entries] - Do not remove
       
   122 
       
   123         };
       
   124 
       
   125     const TInt count = sizeof( KFunctions ) / 
       
   126                         sizeof( TStifFunctionInfo );
       
   127 
       
   128     return RunInternalL( KFunctions, count, aItem );
       
   129 
       
   130     }
       
   131 
       
   132 
       
   133 // -- -- -- -- -------------------------------------------------
       
   134 // @ see CVIMPSTStorageContact_UT.h for description.
       
   135 // -- -- -- -- -------------------------------------------------
       
   136 //
       
   137 TInt CCVIMPSTStorageContact_UT::Test_NewL( CStifItemParser& aItem )
       
   138     {
       
   139     TInt result = KErrGeneral;
       
   140     TPtrC userId;
       
   141     aItem.GetNextString( userId );
       
   142     
       
   143     if( userId.Compare( _L("null") ) == 0 )
       
   144         {
       
   145         userId.Set( KNullDesC );
       
   146         }
       
   147     
       
   148     TPtrC displayName;
       
   149     aItem.GetNextString( displayName );
       
   150     if( displayName.Compare( _L("null") ) == 0 )
       
   151         {
       
   152         displayName.Set( KNullDesC );
       
   153         }
       
   154     
       
   155     TPtrC contactLinkFlag;
       
   156     aItem.GetNextString( contactLinkFlag );
       
   157     CVIMPSTStorageContact* contact = NULL;
       
   158     MVPbkContactLink* contactLink = NULL;
       
   159     HBufC8* aAvatarContent = NULL;
       
   160     if( contactLinkFlag.Compare( _L("CLINK")) == 0)
       
   161         {
       
   162         contact = CVIMPSTStorageContact::NewL( userId, displayName, *contactLink,*aAvatarContent );
       
   163         }
       
   164     else
       
   165         {
       
   166         contact = CVIMPSTStorageContact::NewL( userId, displayName );
       
   167         }
       
   168     if( contact )
       
   169         {
       
   170         result = KErrNone;
       
   171         }
       
   172     
       
   173     return result;
       
   174     
       
   175     }
       
   176 
       
   177 // -- -- -- -- -------------------------------------------------
       
   178 // @ see CVIMPSTStorageContact_UT.h for description.
       
   179 // -- -- -- -- -------------------------------------------------
       
   180 //
       
   181 TInt CCVIMPSTStorageContact_UT::Test_SetUserId_UserIdL( CStifItemParser& aItem )
       
   182     {
       
   183     
       
   184     TInt result = KErrGeneral;
       
   185     
       
   186     TBuf<64> userId;
       
   187     userId.Copy( KUserName );
       
   188     
       
   189     TBuf<64> displayName;
       
   190     displayName.Copy( KDisplayName );
       
   191     
       
   192     TPtrC input;
       
   193     TPtrC output;
       
   194     
       
   195     CVIMPSTStorageContact* contact = NULL;
       
   196     
       
   197     contact = CVIMPSTStorageContact::NewL( userId, displayName );
       
   198     
       
   199     if( contact )
       
   200         {
       
   201 
       
   202         aItem.GetNextString( input );
       
   203         
       
   204         if( input.Compare(_L("null")) == 0 )
       
   205             {
       
   206             input.Set( KNullDesC );
       
   207             contact->SetUserIdL( KNullDesC );
       
   208             }
       
   209         else
       
   210             {
       
   211             contact->SetUserIdL( input );
       
   212             }
       
   213 
       
   214         output.Set(contact->UserId());
       
   215 
       
   216         if( input.Compare( output ) == 0 )
       
   217             {
       
   218             result = KErrNone;
       
   219             }
       
   220 
       
   221         }
       
   222     
       
   223     return result;
       
   224     
       
   225     }
       
   226 
       
   227 // -- -- -- -- -------------------------------------------------
       
   228 // @ see CVIMPSTStorageContact_UT.h for description.
       
   229 // -- -- -- -- -------------------------------------------------
       
   230 //
       
   231 TInt CCVIMPSTStorageContact_UT::Test_AvatarContentL( CStifItemParser& aItem )
       
   232     {
       
   233     TInt result = KErrGeneral;
       
   234     
       
   235     TBuf<64> userId;
       
   236     userId.Copy( KUserName );
       
   237     
       
   238     TBuf<64> displayName;
       
   239     displayName.Copy( KDisplayName );
       
   240     
       
   241     TPtrC tempInput;
       
   242     
       
   243     TBuf8<256> input;
       
   244     
       
   245     TPtrC8 output;
       
   246     
       
   247     CVIMPSTStorageContact* contact = NULL;
       
   248     MVIMPSTStorageVPbkContactStore* VPbkContactStore = NULL;
       
   249     contact = CVIMPSTStorageContact::NewL( userId, displayName );
       
   250 
       
   251     if( contact )
       
   252         {
       
   253         aItem.GetNextString( tempInput );
       
   254         
       
   255         input.Copy( tempInput );
       
   256         
       
   257         if( input.Compare(_L8("null")) == 0 )
       
   258             {
       
   259             input.Copy( KNullDesC );
       
   260             }
       
   261         else
       
   262             {
       
   263             contact->SetAvatarContentL( input, *VPbkContactStore );
       
   264             }
       
   265 
       
   266         output.Set( contact->AvatarContent() );
       
   267 
       
   268         if( input.Compare( output ) == 0 )
       
   269             {
       
   270             result = KErrNone;
       
   271             }
       
   272         
       
   273         }
       
   274     return result;
       
   275     }
       
   276 
       
   277 // -- -- -- -- -------------------------------------------------
       
   278 // @ see CVIMPSTStorageContact_UT.h for description.
       
   279 // -- -- -- -- -------------------------------------------------
       
   280 //
       
   281 TInt CCVIMPSTStorageContact_UT::Test_DisplayNameL( CStifItemParser& aItem)
       
   282     {
       
   283     TInt result = KErrGeneral;
       
   284     
       
   285     TBuf<64> userId;
       
   286     userId.Copy( KUserName );
       
   287     
       
   288     TBuf<64> displayName;
       
   289     displayName.Copy( KDisplayName );
       
   290     
       
   291     TPtrC input;
       
   292     TPtrC output;
       
   293     
       
   294     CVIMPSTStorageContact* contact = NULL;
       
   295     
       
   296     contact = CVIMPSTStorageContact::NewL( userId, displayName );
       
   297     
       
   298     if( contact )
       
   299         {
       
   300 
       
   301         aItem.GetNextString( input );
       
   302         
       
   303         if( input.Compare(_L("null")) == 0 )
       
   304             {
       
   305             input.Set( KNullDesC );
       
   306             }
       
   307         contact->SetNameL( input );
       
   308         output.Set(contact->Name());
       
   309 
       
   310         if( input.Compare( output ) == 0 )
       
   311             {
       
   312             result = KErrNone;
       
   313             }
       
   314 
       
   315         }
       
   316     
       
   317     return result;
       
   318     }
       
   319 
       
   320 // -- -- -- -- -------------------------------------------------
       
   321 // @ see CVIMPSTStorageContact_UT.h for description.
       
   322 // -- -- -- -- -------------------------------------------------
       
   323 //
       
   324 TInt CCVIMPSTStorageContact_UT::Test_PresenceStatusL( CStifItemParser& aItem )
       
   325     {
       
   326     TInt result = KErrGeneral;
       
   327     
       
   328     TBuf<64> userId;
       
   329     userId.Copy( KUserName );
       
   330     
       
   331     TBuf<64> displayName;
       
   332     displayName.Copy( KDisplayName );
       
   333     
       
   334     TPtrC input;
       
   335     TVIMPSTEnums::TOnlineStatus inputState,outputState;
       
   336 
       
   337     CVIMPSTStorageContact* contact = NULL;
       
   338     
       
   339     contact = CVIMPSTStorageContact::NewL( userId, displayName );
       
   340     
       
   341     if( contact )
       
   342         {
       
   343         aItem.GetNextString( input );
       
   344 
       
   345         if( input.Compare( _L("EOnPhone") ) == 0 )
       
   346             {
       
   347             inputState = TVIMPSTEnums::EOnPhone;
       
   348             contact->SetOnlineStatus( inputState );
       
   349             }
       
   350         else
       
   351             {
       
   352             inputState = TVIMPSTEnums::EUnknown;
       
   353             }
       
   354         outputState = contact->OnlineStatus();
       
   355 
       
   356         if( inputState == outputState )
       
   357             {
       
   358             result = KErrNone;
       
   359             }
       
   360         }
       
   361     return result;
       
   362     }
       
   363 
       
   364 // -- -- -- -- -------------------------------------------------
       
   365 // @ see CVIMPSTStorageContact_UT.h for description.
       
   366 // -- -- -- -- -------------------------------------------------
       
   367 //
       
   368 TInt CCVIMPSTStorageContact_UT::Test_StatusTextL( CStifItemParser& aItem )
       
   369     {
       
   370     TInt result = KErrGeneral;
       
   371     
       
   372     TBuf<64> userId;
       
   373     userId.Copy( KUserName );
       
   374     
       
   375     TBuf<64> displayName;
       
   376     displayName.Copy( KDisplayName );
       
   377     
       
   378     TPtrC input;
       
   379     TPtrC output;
       
   380     
       
   381     CVIMPSTStorageContact* contact = NULL;
       
   382     
       
   383     contact = CVIMPSTStorageContact::NewL( userId, displayName );
       
   384     
       
   385     if( contact )
       
   386         {
       
   387 
       
   388         aItem.GetNextString( input );
       
   389         
       
   390         if( input.Compare(_L("null")) == 0 )
       
   391             {
       
   392             input.Set( KNullDesC );
       
   393             }
       
   394         else
       
   395             {
       
   396             contact->SetStatusTextL( input );
       
   397             }
       
   398         
       
   399         output.Set(contact->StatusText());
       
   400 
       
   401         if( input.Compare( output ) == 0 )
       
   402             {
       
   403             result = KErrNone;
       
   404             }
       
   405 
       
   406         }
       
   407     
       
   408     return result;
       
   409     
       
   410     
       
   411     }
       
   412 
       
   413 // -- -- -- -- -------------------------------------------------
       
   414 // @ see CVIMPSTStorageContact_UT.h for description.
       
   415 // -- -- -- -- -------------------------------------------------
       
   416 //
       
   417 TInt CCVIMPSTStorageContact_UT::Test_AvatarIndexL( CStifItemParser& aItem )
       
   418     {
       
   419     TInt result = KErrGeneral;
       
   420     
       
   421     TBuf<64> userId;
       
   422     userId.Copy( KUserName );
       
   423     
       
   424     TBuf<64> displayName;
       
   425     displayName.Copy( KDisplayName );
       
   426     
       
   427     TInt input;
       
   428     TInt output;
       
   429     
       
   430     CVIMPSTStorageContact* contact = NULL;
       
   431     
       
   432     contact = CVIMPSTStorageContact::NewL( userId, displayName );
       
   433 
       
   434     
       
   435     if( contact )
       
   436         {
       
   437 
       
   438         aItem.GetNextInt( input );
       
   439         
       
   440         if( input != -1 )
       
   441         contact->SetAvatarIndex( input );
       
   442         
       
   443         output = contact->AvatarIndex();
       
   444 
       
   445         if( input == output )
       
   446             {
       
   447             result = KErrNone;
       
   448             }
       
   449 
       
   450         }
       
   451     
       
   452     return result;
       
   453     
       
   454     }
       
   455 
       
   456 // -- -- -- -- -------------------------------------------------
       
   457 // @ see CVIMPSTStorageContact_UT.h for description.
       
   458 // -- -- -- -- -------------------------------------------------
       
   459 //
       
   460 TInt CCVIMPSTStorageContact_UT::Test_ContactLinkL( CStifItemParser& aItem )
       
   461     {
       
   462     TInt result = KErrGeneral;
       
   463     
       
   464     TBuf<64> userId;
       
   465     userId.Copy( KUserName );
       
   466     
       
   467     TBuf<64> displayName;
       
   468     displayName.Copy( KDisplayName );
       
   469     
       
   470     TInt output;
       
   471     
       
   472     CVIMPSTStorageContact* contact = NULL;
       
   473     
       
   474     contact = CVIMPSTStorageContact::NewL( userId, displayName );
       
   475 
       
   476     
       
   477     if( contact )
       
   478         {
       
   479         
       
   480         MVPbkContactLink * link = contact->ContactLink();
       
   481         
       
   482         if( link == NULL )
       
   483         result = KErrNone;
       
   484         
       
   485         }    
       
   486     
       
   487     return result;
       
   488     
       
   489     }
       
   490 
       
   491 
       
   492 //  [End of File] - Do not remove