serviceproviders/sapi_messaging/tsrc/testing/tmessagingtest/get_message_async/src/get_message_asyncBlocks.cpp
changeset 22 fc9cf246af83
child 33 50974a8b132e
equal deleted inserted replaced
19:989d2f495d90 22:fc9cf246af83
       
     1 /*
       
     2 * Copyright (c) 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 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 FILES] - do not remove
       
    19 #include <e32svr.h>
       
    20 #include <e32base.h>
       
    21 #include <StifParser.h>
       
    22 #include <Stiftestinterface.h>
       
    23 #include <CMsvAttachment.h>
       
    24 #include "get_message_async.h"
       
    25 #include "messagingservice.h"
       
    26 #include "messageheader.h"
       
    27 #include "async.h"
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 //extern  ?external_data;
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 //extern ?external_function( ?arg_type,?arg_type );
       
    34 
       
    35 // CONSTANTS
       
    36 //const ?type ?constant_var = ?constant;
       
    37 
       
    38 // MACROS
       
    39 //#define ?macro ?macro_def
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 //const ?type ?constant_var = ?constant;
       
    43 //#define ?macro_name ?macro_def
       
    44 
       
    45 // MODULE DATA STRUCTURES
       
    46 //enum ?declaration
       
    47 //typedef ?declaration
       
    48 
       
    49 // LOCAL FUNCTION PROTOTYPES
       
    50 //?type ?function_name( ?arg_type, ?arg_type );
       
    51 
       
    52 // FORWARD DECLARATIONS
       
    53 //class ?FORWARD_CLASSNAME;
       
    54 
       
    55 // ============================= LOCAL FUNCTIONS ===============================
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // ?function_name ?description.
       
    59 // ?description
       
    60 // Returns: ?value_1: ?description
       
    61 //          ?value_n: ?description_line1
       
    62 //                    ?description_line2
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 /*
       
    66 ?type ?function_name(
       
    67     ?arg_type arg,  // ?description
       
    68     ?arg_type arg)  // ?description
       
    69     {
       
    70 
       
    71     ?code  // ?comment
       
    72 
       
    73     // ?comment
       
    74     ?code
       
    75     }
       
    76 */
       
    77 
       
    78 // ============================ MEMBER FUNCTIONS ===============================
       
    79 
       
    80 TInt iResult;
       
    81 TInt iPosneg;
       
    82 
       
    83 TInt Cget_message_async::messageid_func(CStifItemParser& aItem,TInt& id)
       
    84   {
       
    85      TInt err = aItem.GetNextInt(id);
       
    86      if(err)
       
    87      {
       
    88       ////iLog->Log(_L("Failed to Get message id"));
       
    89       return KErrGeneral;
       
    90      };
       
    91      return KErrNone;
       
    92   }   
       
    93      
       
    94 TInt Cget_message_async::fromarray_func(CStifItemParser& aItem,TPtrC& fromarray)     
       
    95   {
       
    96      TInt err = aItem.GetNextString(fromarray);  
       
    97      if(err)
       
    98      {
       
    99       //iLog->Log(_L("Failed to Get from array"));
       
   100       return KErrGeneral;
       
   101      };
       
   102      return KErrNone;
       
   103   }   
       
   104   
       
   105 TInt Cget_message_async::subject_func(CStifItemParser& aItem,TPtrC& subj)     
       
   106   {
       
   107      TInt err = aItem.GetNextString(subj);  
       
   108      if(err)
       
   109      {
       
   110       //iLog->Log(_L("Failed to Get subject"));
       
   111       return KErrGeneral;
       
   112      };
       
   113      return KErrNone;
       
   114   }   
       
   115 
       
   116 TInt Cget_message_async::sort_func(CStifItemParser& aItem,TInt& sorttype)     
       
   117   {
       
   118      TInt err = aItem.GetNextInt(sorttype);  
       
   119      if(err)
       
   120      {
       
   121       //iLog->Log(_L("Failed to Get sort type"));
       
   122       return KErrGeneral;
       
   123      };
       
   124      return KErrNone;
       
   125   } 
       
   126 
       
   127 TInt Cget_message_async::mtm_func(CStifItemParser& aItem,TPtrC& mtmtype)     
       
   128   {
       
   129      TInt err = aItem.GetNextString(mtmtype);  
       
   130      if(err)
       
   131      {
       
   132       //iLog->Log(_L("Failed to Get mtm type"));
       
   133       return KErrGeneral;
       
   134      };
       
   135      return KErrNone;
       
   136   } 
       
   137     
       
   138 TInt Cget_message_async::flag_func(CStifItemParser& aItem,TInt& flag)     
       
   139   {
       
   140      TInt err = aItem.GetNextInt(flag);  
       
   141      if(err)
       
   142      {
       
   143       //iLog->Log(_L("Failed to Get date flag or err code"));
       
   144       return KErrGeneral;
       
   145      };
       
   146      return KErrNone;
       
   147   } 
       
   148   
       
   149 TInt Cget_message_async::date_func(CStifItemParser& aItem,TInt& year,TInt& month,TInt& day,TInt& hour,TInt& min,TInt& sec,TInt& microsec)
       
   150   {
       
   151     
       
   152     TInt err = aItem.GetNextInt(year);
       
   153      if(err)
       
   154      {
       
   155       //iLog->Log(_L("Failed to Get year"));
       
   156       return KErrGeneral;
       
   157      };
       
   158     
       
   159     err = aItem.GetNextInt(month);
       
   160     if(err)
       
   161      {
       
   162       //iLog->Log(_L("Failed to Get month"));
       
   163       return KErrGeneral;
       
   164      };
       
   165   
       
   166     err = aItem.GetNextInt(day);
       
   167     if(err)
       
   168      {
       
   169       //iLog->Log(_L("Failed to Get day")); 
       
   170       return KErrGeneral;
       
   171      };
       
   172 
       
   173     err = aItem.GetNextInt(hour);
       
   174     if(err)
       
   175      {
       
   176       //iLog->Log(_L("Failed to Get hour")); 
       
   177       return KErrGeneral;
       
   178      };
       
   179     
       
   180     err = aItem.GetNextInt(min);
       
   181     if(err)
       
   182      {
       
   183       //iLog->Log(_L("Failed to Get min")); 
       
   184       return KErrGeneral;
       
   185      };
       
   186     
       
   187     err = aItem.GetNextInt(sec);
       
   188     if(err)
       
   189      {
       
   190       //iLog->Log(_L("Failed to Get sec")); 
       
   191       return KErrGeneral;
       
   192      };
       
   193      
       
   194     err = aItem.GetNextInt(microsec);
       
   195     if(err)
       
   196      {
       
   197       //iLog->Log(_L("Failed to Get microsec")); 
       
   198       return KErrGeneral;
       
   199      };
       
   200    return KErrNone;
       
   201   } 
       
   202   
       
   203  TInt Cget_message_async::getsub_func(CStifItemParser& aItem,TPtrC& sub)
       
   204   {
       
   205      TInt err = aItem.GetNextString(sub);
       
   206      if(err)
       
   207      {
       
   208       //iLog->Log(_L("Failed to Get message subject to verify"));
       
   209       return KErrGeneral;
       
   210      };
       
   211      return KErrNone;
       
   212   }
       
   213  
       
   214  TInt Cget_message_async::posneg_func(CStifItemParser& aItem,TInt& posneg)     
       
   215    {
       
   216       TInt err = aItem.GetNextInt(posneg);  
       
   217       if(err)
       
   218       {
       
   219        //iLog->Log(_L("Failed to Get date flag or err code"));
       
   220        return KErrGeneral;
       
   221       };
       
   222       return KErrNone;
       
   223    } 
       
   224  
       
   225  void CMsgCallbackHeader::NotifyResultL( TInt aErrCode, TAny* aResult )
       
   226      {
       
   227      
       
   228      }
       
   229 
       
   230  void CMsgCallbackHeader::HandleGetlistL( TInt aErrCode, CMsvEntrySelection* aEntrySelection, CFilterParamInfo* aFilter )
       
   231     {
       
   232     TInt err=aErrCode;
       
   233     Cheader_test* test2 = Cheader_test::NewL();
       
   234     CFilterParamInfo* f=aFilter;
       
   235     CMsvEntrySelection* e=aEntrySelection;
       
   236     TInt index=0;
       
   237     CMessageHeader* header = NULL;
       
   238     TInt checkposneg = test2->getposneg();
       
   239    iservice->GetNextHeaderL(f, e, index, NULL, header);
       
   240    if(!iPosneg)
       
   241      {
       
   242      if(header)
       
   243          iResult=KErrGeneral;
       
   244      else
       
   245          iResult=KErrNone;
       
   246      }
       
   247        
       
   248    else if(aErrCode==KErrNone)
       
   249        iResult=KErrNone;
       
   250    else
       
   251        iResult=KErrNone;
       
   252    delete header;
       
   253    delete test2;
       
   254     delete f;
       
   255     delete e;
       
   256         
       
   257          iWaitSchedular->AsyncStop();
       
   258     }
       
   259 
       
   260  CMsgCallbackHeader* CMsgCallbackHeader::NewL(CActiveSchedulerWait* aWaitSchedular, CMessagingService* s)
       
   261      {
       
   262      CMsgCallbackHeader* self = new (ELeave) CMsgCallbackHeader(aWaitSchedular, s);
       
   263      return self;
       
   264      }
       
   265 
       
   266  
       
   267  Cheader_test* Cheader_test::NewL()
       
   268      {
       
   269      Cheader_test* self = new(ELeave)Cheader_test();
       
   270      self->ConstructL();
       
   271      return self;
       
   272      }
       
   273 
       
   274 
       
   275  Cheader_test::~Cheader_test()
       
   276      {
       
   277      Cancel();
       
   278      
       
   279      if(iWaitSchedular->IsStarted())
       
   280          iWaitSchedular->AsyncStop();
       
   281      
       
   282      if(iMessagingService)
       
   283          delete iMessagingService;
       
   284      
       
   285      if(iWaitSchedular)
       
   286          delete iWaitSchedular;
       
   287      }
       
   288 
       
   289 
       
   290  void Cheader_test::ConstructL()
       
   291      {
       
   292      CActiveScheduler::Add(this);
       
   293      iMessagingService = CMessagingService::NewL();
       
   294      iWaitSchedular = new(ELeave) CActiveSchedulerWait();
       
   295      }
       
   296 
       
   297 
       
   298  Cheader_test::Cheader_test() :
       
   299  CActive(EPriorityStandard)
       
   300      {
       
   301      }
       
   302 
       
   303 
       
   304  void Cheader_test::DoCancel()
       
   305      {
       
   306          
       
   307      }
       
   308 
       
   309 
       
   310  void Cheader_test::RunL()
       
   311      {
       
   312      TestFunc();
       
   313      }
       
   314 
       
   315 
       
   316  void Cheader_test::Start()
       
   317      {
       
   318      iCallBack = CMsgCallbackHeader::NewL(iWaitSchedular, iMessagingService);
       
   319      SetActive();
       
   320      TRequestStatus* temp = &iStatus;
       
   321      User::RequestComplete(temp, KErrNone);
       
   322      iWaitSchedular->Start();    
       
   323      }
       
   324      
       
   325 
       
   326 
       
   327  void Cheader_test::set(CFilterParamInfo* pi)
       
   328      {
       
   329       v = pi;
       
   330      } 
       
   331  
       
   332  void Cheader_test::setposneg(TInt aFlag)
       
   333      {
       
   334      posnegflag = aFlag;
       
   335      }
       
   336 
       
   337  CFilterParamInfo* Cheader_test::get(void) 
       
   338      { 
       
   339       return v;
       
   340      } 
       
   341  
       
   342  TInt Cheader_test::getposneg(void) 
       
   343      {
       
   344      return posnegflag;
       
   345      }
       
   346  /*void Cheader_test::HandleGetlistL(TInt aErrCode, CMsvEntrySelection* aEntryselection,CFilterParamInfo* aFilterParams)
       
   347      { 
       
   348        
       
   349       iResult=KErrNone;
       
   350       iWaitSchedular->AsyncStop();
       
   351      }
       
   352  void Cheader_test::NotifyResultL(TInt aErrCode,TAny* aResult)
       
   353      {
       
   354      
       
   355      }*/
       
   356      
       
   357  int memorycleanflag = 0;     
       
   358        
       
   359  void Cheader_test::TestFunc()
       
   360      {
       
   361 
       
   362      CFilterParamInfo* arg = get();
       
   363      CMsvEntrySelection* en = NULL;
       
   364      
       
   365      TRAPD(err, iMessagingService->GetIdListL(arg ,0,iCallBack,en)); 
       
   366      
       
   367      if(err!=0)
       
   368       {
       
   369       memorycleanflag = 1;
       
   370        iResult = KErrNone;
       
   371        iWaitSchedular->AsyncStop();
       
   372       }      
       
   373      delete arg;
       
   374      }
       
   375 
       
   376 
       
   377 
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // Cget_message_async::Delete
       
   381 // Delete here all resources allocated and opened from test methods. 
       
   382 // Called from destructor. 
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 void Cget_message_async::Delete() 
       
   386     {
       
   387 
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // Cget_message_async::RunMethodL
       
   392 // Run specified method. Contains also table of test mothods and their names.
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 TInt Cget_message_async::RunMethodL( 
       
   396     CStifItemParser& aItem ) 
       
   397     {
       
   398 
       
   399     static TStifFunctionInfo const KFunctions[] =
       
   400         {  
       
   401         // Copy this line for every implemented function.
       
   402         // First string is the function name used in TestScripter script file.
       
   403         // Second is the actual implementation member function. 
       
   404         ENTRY( "Example", Cget_message_async::ExampleL ),
       
   405         ENTRY( "test_1",Cget_message_async::Test1L)
       
   406         //ADD NEW ENTRY HERE
       
   407         // [test cases entries] - Do not remove
       
   408 
       
   409         };
       
   410 
       
   411     const TInt count = sizeof( KFunctions ) / 
       
   412                         sizeof( TStifFunctionInfo );
       
   413 
       
   414     return RunInternalL( KFunctions, count, aItem );
       
   415 
       
   416     }
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // Cget_message_async::ExampleL
       
   420 // Example test method function.
       
   421 // (other items were commented in a header).
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 TInt Cget_message_async::ExampleL( CStifItemParser& aItem )
       
   425     {
       
   426 
       
   427     // Print to UI
       
   428     _LIT( Kget_message_async, "get_message_async" );
       
   429     _LIT( KExample, "In Example" );
       
   430     TestModuleIf().Printf( 0, Kget_message_async, KExample );
       
   431     // Print to log file
       
   432     iLog->Log( KExample );
       
   433 
       
   434     TInt i = 0;
       
   435     TPtrC string;
       
   436     _LIT( KParam, "Param[%i]: %S" );
       
   437     while ( aItem.GetNextString ( string ) == KErrNone )
       
   438         {
       
   439         TestModuleIf().Printf( i, Kget_message_async, 
       
   440                                 KParam, i, &string );
       
   441         i++;
       
   442         }
       
   443 
       
   444     return KErrNone;
       
   445 
       
   446     }
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // Cget_message_async::?member_function
       
   450 // ?implementation_description
       
   451 // (other items were commented in a header).
       
   452 // -----------------------------------------------------------------------------
       
   453 //
       
   454 
       
   455 TInt Cget_message_async::Test1L( CStifItemParser& aItem )
       
   456     {
       
   457 
       
   458    
       
   459     
       
   460     TInt id,sorttype,flag,year,month,day,hour,min,sec,microsec,posneg;
       
   461     TPtrC subj,mtmtype,fromarray;
       
   462     bool test = TRUE;
       
   463     __UHEAP_MARK;
       
   464     CFilterParamInfo* filter = CFilterParamInfo::NewL();
       
   465 
       
   466                 
       
   467         TInt err1 = messageid_func(aItem,id); 
       
   468         if(err1)
       
   469         {
       
   470          return KErrGeneral;
       
   471         }
       
   472         
       
   473         if(id == 1)
       
   474         { 
       
   475          CMessagingService* mservice = (CMessagingService*)CMessagingService::NewL();   
       
   476          CleanupStack::PushL(mservice);
       
   477          CFilterParamInfo* mfilter = CFilterParamInfo::NewL();
       
   478          CMsvEntrySelection* marray = NULL ;
       
   479          TRAPD(err,mservice->GetIdListL(mfilter,0,NULL ,marray));
       
   480          TInt index = 0;
       
   481          CMessageHeader* headerarr = NULL;
       
   482          mservice->GetNextHeaderL(mfilter, marray, index, NULL, headerarr);  
       
   483          TMsvId message_id;
       
   484          headerarr->GetMessageId(message_id);
       
   485          filter->SetMessageIdFilter(message_id);
       
   486          delete headerarr; 
       
   487          delete marray;
       
   488          delete mfilter;           
       
   489          CleanupStack::PopAndDestroy(mservice);                  
       
   490         }
       
   491         else if(id == 0)
       
   492         {
       
   493          filter->SetMessageIdFilter(NULL);              
       
   494         } 
       
   495         else
       
   496         {
       
   497          TMsvId iD = id;
       
   498          filter->SetMessageIdFilter(iD);                  // message id filter 
       
   499         }
       
   500            
       
   501             
       
   502         err1 = fromarray_func(aItem,fromarray); 
       
   503         if(err1)
       
   504         {
       
   505          return KErrGeneral;
       
   506         }
       
   507         
       
   508         _LIT(Knull,"NULL");
       
   509         if(fromarray.CompareF(Knull))
       
   510         {    
       
   511          _LIT(Kaddr,"AddrEnd");
       
   512          while(fromarray != Kaddr)
       
   513            {       
       
   514             filter->AddFromL(fromarray);                  // from address filter 
       
   515             err1 = fromarray_func(aItem,fromarray); 
       
   516             if(err1)
       
   517              {
       
   518               return KErrGeneral;
       
   519              }             
       
   520            }         
       
   521         } 
       
   522         else
       
   523         {
       
   524     //     filter->AddFromL(NULL);
       
   525         }
       
   526         
       
   527         
       
   528         
       
   529             
       
   530         err1 = subject_func(aItem,subj); 
       
   531         if(err1)
       
   532         {
       
   533          return KErrGeneral;
       
   534         }
       
   535         if(subj.CompareF(Knull))
       
   536         {
       
   537          filter->SetSubjectL(subj);                      // subject filter
       
   538         } 
       
   539         else
       
   540         {
       
   541     //    filter->SetSubjectL(NULL); 
       
   542         }
       
   543         
       
   544         
       
   545             
       
   546         err1 = sort_func(aItem,sorttype); 
       
   547         if(err1)
       
   548         {
       
   549          return KErrGeneral;
       
   550         }
       
   551         
       
   552         TMsvSorting sort= (TMsvSorting)sorttype ;  
       
   553         filter->SetSortType(sort) ;                     // sort filter
       
   554         
       
   555         
       
   556         
       
   557             
       
   558         err1 = mtm_func(aItem,mtmtype); 
       
   559         if(err1)
       
   560         {
       
   561          return KErrGeneral;
       
   562         }
       
   563         
       
   564         if(mtmtype.CompareF(Knull))
       
   565         {        
       
   566           _LIT(Kmt,"MtmEnd");
       
   567           while(mtmtype != Kmt)
       
   568            {       
       
   569             if( filter->AddMtmL(mtmtype) == KErrNone ) //code changed by Venkat
       
   570                 {
       
   571                 err1 = mtm_func(aItem,mtmtype); 
       
   572                 if(err1)
       
   573                     {               
       
   574                     return KErrGeneral;
       
   575                     }   
       
   576                 }// message type filter 
       
   577             else   
       
   578                 {
       
   579                 delete filter;
       
   580                 return KErrNone;
       
   581                 }        
       
   582            } 
       
   583         }  
       
   584         else
       
   585         {
       
   586     //      filter.iMtmArray(NULL);     
       
   587         }  
       
   588         
       
   589         
       
   590         
       
   591         
       
   592         err1 = flag_func(aItem,flag);                   // start date as a filter(1) or not(0)
       
   593         if(err1)
       
   594          {
       
   595           return KErrGeneral;
       
   596          }  
       
   597            
       
   598         if(flag)                  
       
   599         {    
       
   600           err1 = date_func(aItem,year,month,day,hour,min,sec,microsec);
       
   601           if(err1)
       
   602           {
       
   603            return KErrGeneral;
       
   604           }
       
   605           TDateTime start(year,(TMonth)month,day,hour,min,sec,microsec);
       
   606           TTime startdate(start);
       
   607           filter->SetStartDateFilter(startdate);        // start date filter  
       
   608         }
       
   609         else
       
   610         {
       
   611     //      filter->SetStartDateFilter(NULL) ;
       
   612         }
       
   613         
       
   614         
       
   615         
       
   616         
       
   617         err1 = flag_func(aItem,flag);                  // end date as a filter(1) or not(0) 
       
   618         if(err1)
       
   619          {
       
   620           return KErrGeneral;
       
   621          }  
       
   622            
       
   623         if(flag)                  
       
   624         {    
       
   625           err1 = date_func(aItem,year,month,day,hour,min,sec,microsec);
       
   626           if(err1)
       
   627           {
       
   628            return KErrGeneral;
       
   629           }
       
   630         
       
   631           TDateTime end(year,(TMonth)month,day,hour,min,sec,microsec);
       
   632           TTime enddate(end) ;     
       
   633           filter->SetEndDate(enddate) ;                // end date filter
       
   634         }
       
   635         else
       
   636         {
       
   637     //      filter->SetEndDate(NULL) ;
       
   638         }
       
   639         err1=posneg_func(aItem,posneg);
       
   640         if(err1)
       
   641          {
       
   642          return KErrGeneral;
       
   643          }
       
   644         iPosneg=posneg;
       
   645         Cheader_test* test1 = Cheader_test::NewL();
       
   646             
       
   647             test1->set(filter);
       
   648             test1->setposneg(posneg);
       
   649             test1->Start();
       
   650         delete test1;
       
   651         __UHEAP_MARKEND;
       
   652         return iResult;
       
   653            
       
   654     }
       
   655 /*
       
   656 TInt Cget_message_async::?member_function(
       
   657    CItemParser& aItem )
       
   658    {
       
   659 
       
   660    ?code
       
   661 
       
   662    }
       
   663 */
       
   664 
       
   665 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   666 // None
       
   667 
       
   668 //  [End of File] - Do not remove