imservices/xmppsettingsapi/tsrc/src/xmppsettings_apiBlocks.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     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: This file contains testclass implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // [INCLUDE FILES] - do not remove
       
    19 #include <e32svr.h>
       
    20 #include <StifParser.h>
       
    21 #include <StifTestInterface.h>
       
    22 #include "xmppsettings_api.h"
       
    23 #include <xmppservicesettingsapi.h>
       
    24 #include<centralrepository.h>
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 //extern  ?external_data;
       
    28 const TUid  KXmppSettingsApiCenRep         ={0x1020e334};
       
    29 _LIT( KParamName, "XMPP-PARAM-NUMBER-0x%08d");
       
    30 _LIT( KParamValue16, "param value - 0x%08d");
       
    31 // EXTERNAL FUNCTION PROTOTYPES  
       
    32 //extern ?external_function( ?arg_type,?arg_type );
       
    33 
       
    34 // CONSTANTS
       
    35 //const ?type ?constant_var = ?constant;
       
    36 
       
    37 // MACROS
       
    38 //#define ?macro ?macro_def
       
    39 
       
    40 // LOCAL CONSTANTS AND MACROS
       
    41 //const ?type ?constant_var = ?constant;
       
    42 //#define ?macro_name ?macro_def
       
    43 
       
    44 // MODULE DATA STRUCTURES
       
    45 //enum ?declaration
       
    46 //typedef ?declaration
       
    47 
       
    48 // LOCAL FUNCTION PROTOTYPES
       
    49 //?type ?function_name( ?arg_type, ?arg_type );
       
    50 
       
    51 // FORWARD DECLARATIONS
       
    52 //class ?FORWARD_CLASSNAME;
       
    53 
       
    54 // ============================= LOCAL FUNCTIONS ===============================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // ?function_name ?description.
       
    58 // ?description
       
    59 // Returns: ?value_1: ?description
       
    60 //          ?value_n: ?description_line1
       
    61 //                    ?description_line2
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 /*
       
    65 ?type ?function_name(
       
    66     ?arg_type arg,  // ?description
       
    67     ?arg_type arg)  // ?description
       
    68     {
       
    69 
       
    70     ?code  // ?comment
       
    71 
       
    72     // ?comment
       
    73     ?code
       
    74     }
       
    75 */
       
    76 void Cxmppsettings_api::ResetRepository()
       
    77     {
       
    78     CRepository* rep = CRepository::NewL( KXmppSettingsApiCenRep );
       
    79     User::LeaveIfError( rep->Reset() );
       
    80     delete rep;
       
    81     }
       
    82 // ============================ MEMBER FUNCTIONS ===============================
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // Cxmppsettings_api::Delete
       
    86 // Delete here all resources allocated and opened from test methods. 
       
    87 // Called from destructor. 
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void Cxmppsettings_api::Delete() 
       
    91     {
       
    92 
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // Cxmppsettings_api::RunMethodL
       
    97 // Run specified method. Contains also table of test mothods and their names.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 TInt Cxmppsettings_api::RunMethodL( 
       
   101     CStifItemParser& aItem ) 
       
   102     {
       
   103 
       
   104     static TStifFunctionInfo const KFunctions[] =
       
   105         {  
       
   106         // Copy this line for every implemented function.
       
   107         // First string is the function name used in TestScripter script file.
       
   108         // Second is the actual implementation member function. 
       
   109         ENTRY( "Test_CreateSettingsRecordL", Cxmppsettings_api::Test_CreateSettingsRecordL ),
       
   110         ENTRY( "Test_DefaultSettingsRecord", Cxmppsettings_api::Test_DefaultSettingsRecord ),
       
   111         ENTRY( "Test_GetSettingsRecordIdArray", Cxmppsettings_api::Test_GetSettingsRecordIdArray ),
       
   112         ENTRY( "Test_SetParamInt", Cxmppsettings_api::Test_SetParamInt ),
       
   113         ENTRY( "Test_SetParamLDes", Cxmppsettings_api::Test_SetParamLDes ),
       
   114         ENTRY( "Test_GetParamInt", Cxmppsettings_api::Test_GetParamInt ),
       
   115         ENTRY( "Test_GetParamLDes", Cxmppsettings_api::Test_GetParamLDes ),
       
   116         ENTRY( "Test_RemoveSettingsRecord", Cxmppsettings_api::Test_RemoveSettingsRecord ),
       
   117         ENTRY( "Test_RemoveParam", Cxmppsettings_api::Test_RemoveParam ),
       
   118 
       
   119         
       
   120         //ADD NEW ENTRY HERE
       
   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 // Cxmppsettings_api::ExampleL
       
   134 // Example test method function.
       
   135 // (other items were commented in a header).
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 TInt Cxmppsettings_api::Test_CreateSettingsRecordL( CStifItemParser& aItem )
       
   139     {
       
   140     
       
   141     ResetRepository();
       
   142      iApi->CreateSettingsRecordL( iSettingId );
       
   143      if(0==iSettingId)
       
   144          {
       
   145          return KErrGeneral;
       
   146          }
       
   147     
       
   148     RArray<TUint32> array;
       
   149 
       
   150     iApi->GetSettingsRecordIdArrayL( array );
       
   151     TInt arraycount = array.Count();
       
   152     if(0==arraycount)
       
   153         {
       
   154         return KErrGeneral;
       
   155         }
       
   156     if(iSettingId!=array[0])
       
   157         {
       
   158         return KErrGeneral;
       
   159         }
       
   160     array.Reset();
       
   161     array.Close();
       
   162     ResetRepository();
       
   163     TInt count = 5;
       
   164     for (TInt i=0; i< count; i++ )
       
   165         {
       
   166         iApi->CreateSettingsRecordL( iSettingId ) ;
       
   167         }
       
   168     iApi->GetSettingsRecordIdArrayL( array );
       
   169     arraycount = array.Count();
       
   170     if(count!=arraycount)
       
   171         {
       
   172         return KErrGeneral;
       
   173         }
       
   174     array.Reset();
       
   175     array.Close();
       
   176     ResetRepository();
       
   177     return KErrNone;
       
   178         }
       
   179 
       
   180 TInt Cxmppsettings_api::Test_DefaultSettingsRecord( CStifItemParser& aItem )
       
   181     {
       
   182     ResetRepository();
       
   183     iApi->CreateSettingsRecordL( iSettingId );
       
   184     TUint32 settingId;
       
   185     iApi->DefaultSettingsRecordL( settingId );
       
   186     if(settingId!=iSettingId)
       
   187         {
       
   188         return KErrGeneral;
       
   189         }
       
   190     ResetRepository();
       
   191     return KErrNone;
       
   192     
       
   193     }
       
   194 
       
   195 TInt Cxmppsettings_api::Test_GetSettingsRecordIdArray( CStifItemParser& aItem )
       
   196     {
       
   197     
       
   198     ResetRepository();
       
   199      iApi->CreateSettingsRecordL( iSettingId );
       
   200      if(0==iSettingId)
       
   201          {
       
   202          return KErrGeneral;
       
   203          }
       
   204     
       
   205     RArray<TUint32> array;
       
   206 
       
   207     iApi->GetSettingsRecordIdArrayL( array );
       
   208     TInt arraycount = array.Count();
       
   209     if(0==arraycount)
       
   210         {
       
   211         return KErrGeneral;
       
   212         }
       
   213     if(iSettingId!=array[0])
       
   214         {
       
   215         return KErrGeneral;
       
   216         }
       
   217     array.Reset();
       
   218     array.Close();
       
   219     ResetRepository();
       
   220     TInt count = 5;
       
   221     for (TInt i=0; i< count; i++ )
       
   222         {
       
   223         iApi->CreateSettingsRecordL( iSettingId ) ;
       
   224         }
       
   225     iApi->GetSettingsRecordIdArrayL( array );
       
   226     arraycount = array.Count();
       
   227     if(count!=arraycount)
       
   228         {
       
   229         return KErrGeneral;
       
   230         }
       
   231     array.Reset();
       
   232     array.Close();
       
   233     ResetRepository();
       
   234     return KErrNone;
       
   235         }
       
   236 TInt Cxmppsettings_api::Test_SetParamInt( CStifItemParser& aItem )
       
   237     {
       
   238     ResetRepository();
       
   239     iApi->CreateSettingsRecordL( iSettingId );
       
   240 
       
   241     _LIT( KParamName, "XMPP-PARAM-NUMBER-0x%08d");
       
   242 
       
   243     TInt count = 128; // 0xFF
       
   244     TInt err;
       
   245    for (TInt i=0; i < count; i++ )
       
   246     {
       
   247     HBufC* paramName = HBufC::NewL( KParamName().Length()+20 );
       
   248     paramName->Des().AppendFormat( KParamName(), i );
       
   249 
       
   250     TInt paramValue(i);
       
   251 
       
   252     TRAP(err,iApi->SetParamL( iSettingId, *paramName, paramValue));
       
   253     if(err!=KErrNone)
       
   254         {
       
   255         ResetRepository();
       
   256         return KErrGeneral;
       
   257         }
       
   258 
       
   259     delete paramName;
       
   260     }
       
   261     ResetRepository();
       
   262     return KErrNone;
       
   263     }
       
   264 
       
   265 TInt Cxmppsettings_api::Test_SetParamLDes( CStifItemParser& aItem )
       
   266     {
       
   267     TInt err;
       
   268     ResetRepository();
       
   269     iApi->CreateSettingsRecordL( iSettingId );
       
   270 
       
   271     TInt count = 128; // 0xFF
       
   272 
       
   273     for (TInt i=0; i < count; i++ )
       
   274         {
       
   275         HBufC* paramName = HBufC::NewL( KParamName().Length()+20 );
       
   276         paramName->Des().AppendFormat( KParamName(), i );
       
   277 
       
   278         HBufC* paramValue = HBufC::NewL( KParamValue16().Length()+20 );
       
   279         paramValue->Des().AppendFormat( KParamValue16(), i );
       
   280 
       
   281         TRAP(err,iApi->SetParamL( iSettingId, *paramName, *paramValue));
       
   282         if(err!=KErrNone)
       
   283            {
       
   284             ResetRepository();
       
   285             delete paramName;
       
   286             delete paramValue;
       
   287             return KErrGeneral;
       
   288                 }
       
   289 
       
   290         delete paramName;
       
   291         delete paramValue;
       
   292         }
       
   293     ResetRepository();
       
   294     return KErrNone;
       
   295     
       
   296     }
       
   297 
       
   298 TInt Cxmppsettings_api::Test_GetParamInt( CStifItemParser& aItem )
       
   299     {
       
   300     ResetRepository();
       
   301     iApi->CreateSettingsRecordL( iSettingId );
       
   302 
       
   303     _LIT( KParamName, "XMPP-PARAM-NUMBER-0x%08d");
       
   304 
       
   305     TInt count = 128; // 0xFF
       
   306     TInt err;
       
   307    for (TInt i=0; i < count; i++ )
       
   308     {
       
   309     HBufC* paramName = HBufC::NewL( KParamName().Length()+20 );
       
   310     paramName->Des().AppendFormat( KParamName(), i );
       
   311 
       
   312     TInt paramValue(i);
       
   313 
       
   314     TRAP(err,iApi->SetParamL( iSettingId, *paramName, paramValue));
       
   315     if(err!=KErrNone)
       
   316         {
       
   317         ResetRepository();
       
   318         return KErrGeneral;
       
   319         }
       
   320 
       
   321     delete paramName;
       
   322     }
       
   323    for ( TInt i=0; i < count; i++ )
       
   324            {
       
   325            HBufC* paramName = HBufC::NewL( KParamName().Length()+20 );
       
   326            paramName->Des().AppendFormat( KParamName(), i );
       
   327 
       
   328            TInt paramValue(0);
       
   329 
       
   330            iApi->GetParamL( iSettingId,*paramName,paramValue);
       
   331 
       
   332            if( i!= paramValue)
       
   333                {
       
   334                return KErrGeneral;
       
   335                }
       
   336 
       
   337            delete paramName;
       
   338            }
       
   339     ResetRepository();
       
   340     return KErrNone;
       
   341     }
       
   342     
       
   343 TInt Cxmppsettings_api::Test_GetParamLDes( CStifItemParser& aItem )
       
   344     {
       
   345     ResetRepository();
       
   346     iApi->CreateSettingsRecordL( iSettingId );
       
   347 
       
   348     _LIT( KParamName, "XMPP-PARAM-NUMBER-0x%08d");
       
   349 
       
   350     TInt count = 128; // 0xFF
       
   351     TInt err;
       
   352    for (TInt i=0; i < count; i++ )
       
   353     {
       
   354     HBufC* paramName = HBufC::NewL( KParamName().Length()+20 );
       
   355     paramName->Des().AppendFormat( KParamName(), i );
       
   356 
       
   357     HBufC* paramValue = HBufC::NewL( KParamValue16().Length()+20 );
       
   358     paramValue->Des().AppendFormat( KParamValue16(), i );
       
   359 
       
   360     TRAP(err,iApi->SetParamL( iSettingId, *paramName, *paramValue));
       
   361     if(err!=KErrNone)
       
   362        {
       
   363         ResetRepository();
       
   364         delete paramName;
       
   365         delete paramValue;
       
   366         return KErrGeneral;
       
   367             }
       
   368 
       
   369     delete paramName;
       
   370     delete paramValue;
       
   371     }
       
   372    for ( TInt i=0; i < count; i++ )
       
   373            {
       
   374            HBufC* paramName = HBufC::NewL( KParamName().Length()+20 );
       
   375            paramName->Des().AppendFormat( KParamName(), i );
       
   376 
       
   377            HBufC* paramValue = HBufC::NewL( KParamValue16().Length()+20 );
       
   378            paramValue->Des().AppendFormat( KParamValue16(), i );
       
   379 
       
   380            RBuf buf;
       
   381            buf.CreateL( 255 );
       
   382 
       
   383            TRAP(err,iApi->GetParamL( iSettingId,*paramName, buf) );
       
   384            
       
   385            if(err!=KErrNone)
       
   386                {
       
   387                return KErrGeneral;
       
   388                }
       
   389            //*paramValue, buf, ;
       
   390 
       
   391            delete paramName;
       
   392            delete paramValue;
       
   393 
       
   394            buf.Close();
       
   395            }
       
   396     ResetRepository();
       
   397     return KErrNone;
       
   398     }
       
   399 
       
   400 TInt Cxmppsettings_api::Test_RemoveSettingsRecord( CStifItemParser& aItem )
       
   401     {
       
   402     ResetRepository();
       
   403     iApi->CreateSettingsRecordL( iSettingId );
       
   404     iApi->RemoveSettingsRecordL( iSettingId );
       
   405 
       
   406     RArray<TUint32> array;
       
   407 
       
   408     iApi->GetSettingsRecordIdArrayL( array );
       
   409     TInt arraycount = array.Count();
       
   410     if(1==arraycount)
       
   411         {
       
   412         return KErrGeneral;
       
   413         }
       
   414 
       
   415     array.Reset();
       
   416 
       
   417     iSettingId = 0;
       
   418 
       
   419     ResetRepository();
       
   420 
       
   421     TInt count = 128;
       
   422 
       
   423     for (TInt i=1; i< count; i++ )
       
   424         {
       
   425         iApi->CreateSettingsRecordL( iSettingId);
       
   426         }
       
   427 
       
   428     // because cen rep is reseted after every test, indexes should start
       
   429     // from zero and go up to count. So its safe to assume that these
       
   430     // indexes exist :)
       
   431 
       
   432     iApi->RemoveSettingsRecordL( 1 );
       
   433     iApi->RemoveSettingsRecordL( 55 );
       
   434     iApi->RemoveSettingsRecordL( 123 );
       
   435     iApi->RemoveSettingsRecordL( 96 ) ;
       
   436     iApi->RemoveSettingsRecordL( 2 );
       
   437 
       
   438     iApi->GetSettingsRecordIdArrayL( array );
       
   439     arraycount = array.Count();
       
   440     if((count-6)!=arraycount)
       
   441         {
       
   442         return KErrGeneral;
       
   443         }
       
   444 
       
   445     for( TInt i=0; i < array.Count(); i++ )
       
   446         {
       
   447          iApi->RemoveSettingsRecordL( array[i] );
       
   448         }
       
   449 
       
   450     array.Reset();
       
   451     iApi->GetSettingsRecordIdArrayL( array );
       
   452     if( 0!=(array.Count()))
       
   453         {
       
   454         return KErrGeneral;
       
   455         }
       
   456     array.Reset();
       
   457     array.Close();
       
   458     ResetRepository();
       
   459     return KErrNone;
       
   460       
       
   461     }
       
   462 TInt Cxmppsettings_api::Test_RemoveParam( CStifItemParser& aItem )
       
   463     {
       
   464 
       
   465 
       
   466     ResetRepository();
       
   467     iApi->CreateSettingsRecordL( iSettingId );
       
   468 
       
   469     _LIT( KParamName, "XMPP-PARAM-NUMBER-0x%08d");
       
   470 
       
   471     TInt count = 128; // 0xFF
       
   472     TInt err;
       
   473    for (TInt i=0; i < count; i++ )
       
   474     {
       
   475     HBufC* paramName = HBufC::NewL( KParamName().Length()+20 );
       
   476     paramName->Des().AppendFormat( KParamName(), i );
       
   477 
       
   478     TInt paramValue(i);
       
   479 
       
   480     TRAP(err,iApi->SetParamL( iSettingId, *paramName, paramValue));
       
   481     if(err!=KErrNone)
       
   482         {
       
   483         ResetRepository();
       
   484         return KErrGeneral;
       
   485         }
       
   486 
       
   487     delete paramName;
       
   488     }
       
   489    
       
   490     count = 128; // 0xFF
       
   491 
       
   492     TInt param = 56;
       
   493 
       
   494         HBufC* paramName = HBufC::NewL( KParamName().Length()+20 );
       
   495         paramName->Des().AppendFormat( KParamName(), param );
       
   496 
       
   497         iApi->RemoveParamL( iSettingId,*paramName);
       
   498         TInt paramvalue;
       
   499         
       
   500         TRAP(err,iApi->GetParamL( iSettingId,*paramName,paramvalue));
       
   501         if(err!= -1)
       
   502             {
       
   503             return KErrGeneral;
       
   504             }
       
   505         iApi->SetParamL( iSettingId,*paramName,12345);
       
   506         delete paramName;
       
   507 
       
   508     for (TInt i=0; i < count; i++ )
       
   509         {
       
   510         HBufC* paramName = HBufC::NewL( KParamName().Length() + 20 );
       
   511         paramName->Des().AppendFormat( KParamName(), i );
       
   512 
       
   513         iApi->RemoveParamL( iSettingId,*paramName);
       
   514 
       
   515         delete paramName;
       
   516         }
       
   517 
       
   518 
       
   519     ResetRepository();
       
   520     return KErrNone;
       
   521     
       
   522     
       
   523     }
       
   524 // -----------------------------------------------------------------------------
       
   525 // Cxmppsettings_api::?member_function
       
   526 // ?implementation_description
       
   527 // (other items were commented in a header).
       
   528 // -----------------------------------------------------------------------------
       
   529 //
       
   530 /*
       
   531 TInt Cxmppsettings_api::?member_function(
       
   532    CItemParser& aItem )
       
   533    {
       
   534 
       
   535    ?code
       
   536 
       
   537    }
       
   538 */
       
   539 
       
   540 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   541 // None
       
   542 
       
   543 //  [End of File] - Do not remove