sapi_logging/tsrc/dev/tloggingprovidertest/src/tdeletegenericpos.cpp
changeset 0 14df0fbfcc4e
equal deleted inserted replaced
-1:000000000000 0:14df0fbfcc4e
       
     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 the License "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 #include <StifParser.h>
       
    19 #include <Stiftestinterface.h>
       
    20 
       
    21 #include <LiwServiceHandler.h>
       
    22 #include <LiwCommon.h>
       
    23 
       
    24 
       
    25 #include "tconstants.h"
       
    26 #include "tprovidertest.h"
       
    27 #include "tprovidercallback.h"
       
    28 #include "serviceerrno.h"
       
    29 
       
    30 void Ctprovidertest :: tdeleteTestPosL(TInt aExpected)
       
    31 {
       
    32   if(aExpected != KErrNone)
       
    33   	{
       
    34   	 _LIT(KLog , "Negative test case for delete api") ;
       
    35   	 iLog->Log(KLog) ;
       
    36   tdeleteNegativePosL();
       
    37   	  
       
    38   	}
       
    39   	
       
    40   else 
       
    41   	{
       
    42   	 _LIT(KLog , "Functional test for the delete api")  ;
       
    43   	 iLog->Log(KLog)  ;	
       
    44   	 tdeleteFunctionalPosL() ;
       
    45   	}  	
       
    46 }
       
    47 
       
    48 
       
    49 //----------------------------------------------------------------------
       
    50 // internal utility function which tests the functionality of delete api
       
    51 //
       
    52 //----------------------------------------------------------------------
       
    53 
       
    54 void Ctprovidertest :: tdeleteFunctionalPosL()
       
    55 	{
       
    56 	  
       
    57 	_LIT(KOwnEventSubject, "RandomLogEvent");
       
    58 	_LIT(KOwnEventRemoteParty, "OwnContact");
       
    59 
       
    60     CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL();
       
    61      // Input and output parameter list
       
    62     CLiwGenericParamList* inputlist = &(ServiceHandler->InParamListL());
       
    63     
       
    64     CLiwGenericParamList* outputlist = &(ServiceHandler->OutParamListL());
       
    65     
       
    66     CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KDsInterfaceName , KLoggingContents) ;
       
    67     
       
    68     crit->SetServiceClass(TUid::Uid(KLiwClassBase));
       
    69 
       
    70 	RCriteriaArray a;
       
    71 	
       
    72 	a.AppendL(crit);
       
    73 	
       
    74 	ServiceHandler->AttachL(a) ;
       
    75 	
       
    76 	ServiceHandler->ExecuteServiceCmdL(*crit, *inputlist, *outputlist);
       
    77     
       
    78     TInt pos = 0;
       
    79 	
       
    80    
       
    81  
       
    82 	const TLiwGenericParam *genericparm = outputlist->FindFirst(pos  , KDsInterfaceName);
       
    83 	
       
    84 	if(!genericparm)
       
    85 	{
       
    86 	 _LIT(KLog , "Logging interface not found") ;
       
    87 	 iLog->Log(KLog) ;
       
    88 	 
       
    89 	 User :: Leave(KErrArgument) ;
       
    90 	}
       
    91 	
       
    92    MLiwInterface* LogInterface = (genericparm->Value()).AsInterface();
       
    93    
       
    94    //Add an event and then delete this added event ;
       
    95    
       
    96    CLiwDefaultMap *EventDetails = CLiwDefaultMap :: NewL() ;	
       
    97    
       
    98    EventDetails->InsertL(KEventTypeKey ,TLiwVariant((TInt32)KLogShortMessageEvent)) ;
       
    99    
       
   100    
       
   101    TBufC16<10> contentType(KContentType) ;
       
   102    
       
   103    //Insert the contenttype to inputlist
       
   104    inputlist->AppendL(TLiwGenericParam(KContentTypeKey , TLiwVariant(contentType))) ;
       
   105  
       
   106    
       
   107    inputlist->AppendL(TLiwGenericParam(KEventDetails , TLiwVariant(EventDetails))) ;
       
   108     EventDetails->DecRef();
       
   109    TBufC8<20>CmdBuf(KCmdAdd) ;
       
   110    
       
   111    LogInterface->ExecuteCmdL(CmdBuf , *inputlist , *outputlist) ;
       
   112    
       
   113    //Now get the id to deleted
       
   114    
       
   115    pos = 0 ;
       
   116    
       
   117    const TLiwGenericParam *outparm1 = outputlist->FindFirst(pos , KResponse) ; 
       
   118    
       
   119    if(!outparm1)
       
   120    	{
       
   121    	 _LIT8(KLog , "Log id of the delete item not found") ;
       
   122    	 iLog->Log(KLog) ;
       
   123    	 User :: Leave(KErrArgument) ;
       
   124    	}
       
   125   	
       
   126   //Now delete the added item
       
   127 
       
   128   
       
   129  TBufC<20> itemid= (outparm1->Value()).AsDes() ;
       
   130   
       
   131  /* if(itemid  < 0 )
       
   132    {
       
   133    _LIT(KLog , "Invalid item id ") ;
       
   134    iLog->Log(KLog) ;
       
   135    User :: Leave(KErrArgument) ;	
       
   136    }*/
       
   137    
       
   138   inputlist->Reset() ; outputlist->Reset() ;
       
   139   
       
   140    CLiwDefaultMap *Idmap = CLiwDefaultMap :: NewL() ;
       
   141    Idmap->InsertL(KLogId ,TLiwVariant(itemid)) ;
       
   142    //Insert the contenttype to inputlist
       
   143    inputlist->AppendL(TLiwGenericParam(KContentTypeKey , TLiwVariant(contentType))) ;
       
   144  
       
   145    
       
   146   inputlist->AppendL(TLiwGenericParam(KData , TLiwVariant(Idmap))) ;
       
   147   Idmap->DecRef();
       
   148   CmdBuf = KCmdDelete ;
       
   149   LogInterface->ExecuteCmdL(CmdBuf , *inputlist , *outputlist) ;
       
   150   
       
   151   pos = 0 ;
       
   152   const TLiwGenericParam *Errprm = outputlist->FindFirst(pos , KErrCode ) ;
       
   153   
       
   154   if(!Errprm)
       
   155   	{
       
   156   	 _LIT(KLog , "Generic error param missing form the outputlist of delete" ) ;
       
   157   	 iLog->Log(KLog) ;
       
   158   	 User :: Leave(KErrArgument) ;
       
   159   	}
       
   160   	
       
   161   TInt retval  = Errprm->Value().AsTInt32() ;
       
   162   
       
   163   if(retval != SErrNone )
       
   164   	{
       
   165   	 _LIT(KLog , "Functionality test of delete call failed ") ;
       
   166   	 iLog->Log(KLog) ;
       
   167   	 User :: Leave(KErrArgument) ;
       
   168   	}
       
   169   	  LogInterface->Close() ;
       
   170   	 delete ServiceHandler;
       
   171  
       
   172      
       
   173    	 a.ResetAndDestroy();
       
   174    	 a.Close();
       
   175     
       
   176    
       
   177    
       
   178      
       
   179   }
       
   180   
       
   181   
       
   182   //----------------------------------------------------------------------
       
   183 // Negative testcase for delete api
       
   184 //
       
   185 //----------------------------------------------------------------------
       
   186 
       
   187 void Ctprovidertest :: tdeleteNegativePosL()
       
   188 	{
       
   189 	
       
   190 
       
   191     CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL();
       
   192      // Input and output parameter list
       
   193     CLiwGenericParamList* inputlist = &(ServiceHandler->InParamListL());
       
   194     
       
   195     CLiwGenericParamList* outputlist = &(ServiceHandler->OutParamListL());
       
   196     
       
   197     CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KDsInterfaceName , KLoggingContents) ;
       
   198     
       
   199     crit->SetServiceClass(TUid::Uid(KLiwClassBase));
       
   200 
       
   201 	RCriteriaArray a;
       
   202 	
       
   203 	a.AppendL(crit);
       
   204 	
       
   205 	ServiceHandler->AttachL(a) ;
       
   206 	
       
   207 	TBufC16<10> contentType(KContentType) ;
       
   208    
       
   209    //Insert the contenttype to inputlist
       
   210    inputlist->AppendL(TLiwGenericParam(KContentTypeKey , TLiwVariant(contentType))) ;
       
   211  
       
   212 	
       
   213 	ServiceHandler->ExecuteServiceCmdL(*crit, *inputlist, *outputlist);
       
   214     
       
   215     TInt pos = 0;
       
   216 	
       
   217  
       
   218 	const TLiwGenericParam *genericparm = outputlist->FindFirst(pos  , KDsInterfaceName);
       
   219 	
       
   220 	if(!genericparm)
       
   221 	{
       
   222 	 _LIT(KLog , "Logging interface not found") ;
       
   223 	 iLog->Log(KLog) ;
       
   224 	 
       
   225 	 User :: Leave(KErrArgument) ;
       
   226 	}
       
   227 	
       
   228    MLiwInterface* LogInterface = (genericparm->Value()).AsInterface();
       
   229    
       
   230    
       
   231   
       
   232   	
       
   233   
       
   234   
       
   235   TInt itemid = -1;
       
   236   TBuf<8> des;
       
   237   des.Num(itemid);
       
   238    
       
   239    inputlist->Reset() ;
       
   240    outputlist->Reset() ;
       
   241    
       
   242   CLiwDefaultMap *Idmap = CLiwDefaultMap :: NewL() ;
       
   243    Idmap->InsertL(KLogId ,TLiwVariant(des)) ;
       
   244    
       
   245   inputlist->AppendL(TLiwGenericParam(KData , TLiwVariant(Idmap))) ;
       
   246   Idmap->DecRef();
       
   247    
       
   248   //inputlist->AppendL(TLiwGenericParam(KData , TLiwVariant((TInt32)itemid))) ;
       
   249   
       
   250   TBufC8<20>CmdBuf(KCmdDelete) ;
       
   251   //CmdBuf = KCmdDelete ;
       
   252   LogInterface->ExecuteCmdL(CmdBuf , *inputlist , *outputlist) ;
       
   253   
       
   254   pos = 0 ;
       
   255   const TLiwGenericParam *Errprm = outputlist->FindFirst(pos , KErrCode ) ;
       
   256   
       
   257   if(!Errprm)
       
   258   	{
       
   259   	 _LIT(KLog , "Generic error param missing form the outputlist of delete" ) ;
       
   260   	 iLog->Log(KLog) ;
       
   261   	 User :: Leave(KErrArgument) ;
       
   262   	}
       
   263   	
       
   264   TInt retval  = Errprm->Value().AsTInt32() ;
       
   265   
       
   266   if(retval != SErrNone )
       
   267   	{
       
   268   	     LogInterface->Close() ;
       
   269   	   delete ServiceHandler;
       
   270  
       
   271       
       
   272    	 a.ResetAndDestroy();
       
   273    	 a.Close();
       
   274     
       
   275   
       
   276    
       
   277   	 _LIT(KLog , "Functionality test of delete call failed ") ;
       
   278   	 iLog->Log(KLog) ;
       
   279   	 User :: Leave(KErrArgument) ;
       
   280   	}
       
   281   	
       
   282   	  LogInterface->Close() ;
       
   283     delete ServiceHandler;
       
   284  
       
   285    
       
   286    	 a.ResetAndDestroy();
       
   287    	 a.Close();
       
   288     
       
   289    
       
   290   }
       
   291 
       
   292 
       
   293 //-----------------------------------------------------------------------------
       
   294 // Functionality test for delete async call
       
   295 //-----------------------------------------------------------------------------
       
   296 void Ctprovidertest :: tdeleteTestasyncPosL(TInt aExpected)
       
   297 {
       
   298   if(aExpected != KErrNone)
       
   299   	{
       
   300   	 _LIT(KLog , "Negative test case for delete api") ;
       
   301   	 iLog->Log(KLog) ;
       
   302   	 tdeleteNegativeasyncL();
       
   303   	  
       
   304   	}
       
   305   	
       
   306   else 
       
   307   	{
       
   308   	 _LIT(KLog , "Functional test for the delete async api")  ;
       
   309   	 iLog->Log(KLog)  ;	
       
   310   	 tdeleteFunctionalAsyncL() ;
       
   311   	}  	
       
   312 }
       
   313 
       
   314 //----------------------------------------------------------------------
       
   315 // positive test case for delete async
       
   316 //
       
   317 //----------------------------------------------------------------------
       
   318 
       
   319 
       
   320 void Ctprovidertest :: tdeleteFunctionalAsyncPosL(void)
       
   321 {
       
   322 		
       
   323 	NotifyCB Callback ;
       
   324 		
       
   325 	_LIT(KOwnEventSubject, "RandomLogEvent");
       
   326 	_LIT(KOwnEventRemoteParty, "OwnContact");
       
   327 
       
   328     CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL();
       
   329      // Input and output parameter list
       
   330     CLiwGenericParamList* inputlist = &(ServiceHandler->InParamListL());
       
   331     
       
   332     CLiwGenericParamList* outputlist = &(ServiceHandler->OutParamListL());
       
   333     
       
   334     CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KDsInterfaceName , KLoggingContents) ;
       
   335     
       
   336     crit->SetServiceClass(TUid::Uid(KLiwClassBase));
       
   337 
       
   338 	RCriteriaArray a;
       
   339 	
       
   340 	a.AppendL(crit);
       
   341 	
       
   342 	ServiceHandler->AttachL(a) ;
       
   343 	
       
   344 	ServiceHandler->ExecuteServiceCmdL(*crit, *inputlist, *outputlist);
       
   345     
       
   346     TInt pos = 0;
       
   347 	
       
   348  
       
   349 	const TLiwGenericParam *genericparm = outputlist->FindFirst(pos  , KDsInterfaceName);
       
   350 	
       
   351 	if(!genericparm)
       
   352 	{
       
   353 	 _LIT(KLog , "Logging interface not found") ;
       
   354 	 iLog->Log(KLog) ;
       
   355 	 
       
   356 	 User :: Leave(KErrArgument) ;
       
   357 	}
       
   358 	
       
   359    MLiwInterface* LogInterface = (genericparm->Value()).AsInterface();
       
   360    
       
   361    //Add an event and then delete this added event ;
       
   362    
       
   363    CLiwDefaultMap *EventDetails = CLiwDefaultMap :: NewL() ;	
       
   364    
       
   365    EventDetails->InsertL(KEventTypeKey ,TLiwVariant((TInt32)KLogShortMessageEvent)) ;
       
   366    
       
   367    
       
   368    /**
       
   369     * First append content type
       
   370     */
       
   371     
       
   372     TBufC16<10> contentType(KContentType) ;
       
   373    
       
   374    //Insert the contenttype to inputlist
       
   375    inputlist->AppendL(TLiwGenericParam(KContentTypeKey , TLiwVariant(contentType))) ;
       
   376  
       
   377    
       
   378    inputlist->AppendL(TLiwGenericParam(KEventDetails , TLiwVariant(EventDetails))) ;
       
   379    EventDetails->DecRef();
       
   380    TBufC8<20>CmdBuf(KCmdAdd) ;
       
   381    
       
   382    LogInterface->ExecuteCmdL(CmdBuf , *inputlist , *outputlist) ;
       
   383    
       
   384    //Now get the id to deleted
       
   385    
       
   386    pos = 0 ;
       
   387    
       
   388    const TLiwGenericParam *outparm1 = outputlist->FindFirst(pos , KResponse) ; 
       
   389    
       
   390    if(!outparm1)
       
   391    	{
       
   392    	 _LIT8(KLog , "Log id of the delete item not found") ;
       
   393    	 iLog->Log(KLog) ;
       
   394    	 User :: Leave(KErrArgument) ;
       
   395    	}
       
   396   	
       
   397   //Now delete the added item
       
   398   
       
   399   TBufC<20> itemid = (outparm1->Value()).AsDes() ;
       
   400   
       
   401  /* if(itemid  < 0 )
       
   402    {
       
   403    _LIT(KLog , "Invalid item id ") ;
       
   404    iLog->Log(KLog) ;
       
   405    User :: Leave(KErrArgument) ;	
       
   406    }*/
       
   407    
       
   408   inputlist->Reset() ; outputlist->Reset() ;
       
   409    CLiwDefaultMap *Idmap = CLiwDefaultMap :: NewL() ;
       
   410    Idmap->InsertL(KLogId ,TLiwVariant(itemid)) ;
       
   411    //Insert the contenttype to inputlist
       
   412    inputlist->AppendL(TLiwGenericParam(KContentTypeKey , TLiwVariant(contentType))) ;
       
   413  
       
   414    
       
   415   inputlist->AppendL(TLiwGenericParam(KData , TLiwVariant(Idmap))) ;
       
   416   Idmap->DecRef();
       
   417   CmdBuf = KCmdDelete ;
       
   418   LogInterface->ExecuteCmdL(CmdBuf , *inputlist , *outputlist ,KLiwOptASyncronous , &Callback) ;
       
   419   
       
   420   pos = 0 ;
       
   421   const TLiwGenericParam *Errprm = outputlist->FindFirst(pos , KErrCode ) ;
       
   422   
       
   423   if(!Errprm)
       
   424   	{
       
   425   	 _LIT(KLog , "Generic error param missing form the outputlist of delete" ) ;
       
   426   	 iLog->Log(KLog) ;
       
   427   	 User :: Leave(KErrArgument) ;
       
   428   	}
       
   429   	
       
   430   TInt retval  = Errprm->Value().AsTInt32() ;
       
   431   
       
   432   if(retval != SErrNone )
       
   433   	{
       
   434   	 _LIT(KLog , "Functionality test of delete call failed ") ;
       
   435   	 iLog->Log(KLog) ;
       
   436   	 User :: Leave(KErrArgument) ;
       
   437   	}
       
   438   	
       
   439  Callback.Start() ;
       
   440  
       
   441  if(Callback.Status() != KErrNone) 
       
   442  	{
       
   443  	 _LIT(KLog , "Async status error ") ;
       
   444  	 iLog->Log(KLog) ;
       
   445  	 User :: Leave (Callback.Status()) ;
       
   446  	}
       
   447  	LogInterface->Close() ;
       
   448     delete ServiceHandler;
       
   449  
       
   450    
       
   451    	 a.ResetAndDestroy();
       
   452    	 a.Close();
       
   453     
       
   454     
       
   455 }
       
   456 
       
   457 //----------------------------------------------------------------------
       
   458 // negative test case for delete async
       
   459 //
       
   460 //----------------------------------------------------------------------
       
   461 
       
   462 
       
   463 
       
   464 void Ctprovidertest :: tdeleteNegativeasyncPosL(void)
       
   465 {
       
   466 		
       
   467 	NotifyCB Callback ;
       
   468 		
       
   469 	
       
   470     CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL();
       
   471      // Input and output parameter list
       
   472     CLiwGenericParamList* inputlist = &(ServiceHandler->InParamListL());
       
   473     
       
   474     CLiwGenericParamList* outputlist = &(ServiceHandler->OutParamListL());
       
   475     
       
   476     CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KDsInterfaceName , KLoggingContents) ;
       
   477     
       
   478     crit->SetServiceClass(TUid::Uid(KLiwClassBase));
       
   479 
       
   480 	RCriteriaArray a;
       
   481 	
       
   482 	a.AppendL(crit);
       
   483 	
       
   484 	ServiceHandler->AttachL(a) ;
       
   485 	
       
   486 	ServiceHandler->ExecuteServiceCmdL(*crit, *inputlist, *outputlist);
       
   487     
       
   488     TInt pos = 0;
       
   489 	
       
   490  
       
   491 	const TLiwGenericParam *genericparm = outputlist->FindFirst(pos  , KDsInterfaceName);
       
   492 	
       
   493 	if(!genericparm)
       
   494 	{
       
   495 	 _LIT(KLog , "Logging interface not found") ;
       
   496 	 iLog->Log(KLog) ;
       
   497 	 
       
   498 	 User :: Leave(KErrArgument) ;
       
   499 	}
       
   500 	
       
   501    MLiwInterface* LogInterface = (genericparm->Value()).AsInterface();
       
   502    
       
   503    
       
   504   
       
   505   
       
   506  TInt itemid = -1;
       
   507   TBuf<8> des;
       
   508   des.Num(itemid);
       
   509   
       
   510   inputlist->Reset() ; 
       
   511   outputlist->Reset() ;
       
   512    
       
   513     CLiwDefaultMap *Idmap = CLiwDefaultMap :: NewL() ;
       
   514      Idmap->InsertL(KLogId ,TLiwVariant(des)) ;
       
   515 	TBufC16<10> contentType(KContentType) ;
       
   516 
       
   517 	//Insert the contenttype to inputlist
       
   518 	inputlist->AppendL(TLiwGenericParam(KContentTypeKey , TLiwVariant(contentType))) ;
       
   519 
       
   520 	inputlist->AppendL(TLiwGenericParam(KData , TLiwVariant(Idmap))) ;
       
   521 	Idmap->DecRef();
       
   522 	TBufC8<20>CmdBuf(KCmdDelete) ;
       
   523  //CmdBuf = KCmdDelete ;
       
   524   LogInterface->ExecuteCmdL(CmdBuf , *inputlist , *outputlist ,KLiwOptASyncronous , &Callback) ;
       
   525   
       
   526   pos = 0 ;
       
   527   const TLiwGenericParam *Errprm = outputlist->FindFirst(pos , KErrCode ) ;
       
   528   
       
   529   if(!Errprm)
       
   530   	{
       
   531   	 _LIT(KLog , "Generic error param missing form the outputlist of delete" ) ;
       
   532   	 iLog->Log(KLog) ;
       
   533   	 User :: Leave(KErrArgument) ;
       
   534   	}
       
   535   	
       
   536   TInt retval  = Errprm->Value().AsTInt32() ;
       
   537   
       
   538   if(retval != SErrNone )
       
   539   	{
       
   540   	 _LIT(KLog , "Functionality test of delete call failed ") ;
       
   541   	 iLog->Log(KLog) ;
       
   542   	 User :: Leave(KErrArgument) ;
       
   543   	}
       
   544   	
       
   545  Callback.Start() ;
       
   546  
       
   547  if(Callback.Status() != KErrNone) 
       
   548  	{
       
   549  	 _LIT(KLog , "Async status error ") ;
       
   550  	 iLog->Log(KLog) ;
       
   551  	 User :: Leave (Callback.Status()) ;
       
   552  	}
       
   553  	  LogInterface->Close() ;
       
   554      delete ServiceHandler;
       
   555  
       
   556    
       
   557    	 a.ResetAndDestroy();
       
   558    	 a.Close();
       
   559     
       
   560    
       
   561 }