common/tools/ats/smoketest/IM/src/IMApiMTHandlers.cpp
changeset 756 736214c0060b
child 872 17498133d9ad
equal deleted inserted replaced
755:cdb4af7acafc 756:736214c0060b
       
     1 /*
       
     2 * Copyright (c) 2002 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 "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Handler class
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <apparc.h>
       
    22 #include    <e32std.h>
       
    23 #include    "IMApiMTHandlers.h"
       
    24 #include    "TestRunner.h"
       
    25 
       
    26 /******************************************************************************
       
    27 *
       
    28 * CIMApiClientHandler
       
    29 *
       
    30 ******************************************************************************/
       
    31 
       
    32 //////////////////////////////////////////////////////////////////////////
       
    33 // Handler class
       
    34 CIMApiClientHandler* CIMApiClientHandler::NewL( TRequestStatus& aStatus )
       
    35     {
       
    36     CIMApiClientHandler* self = new( ELeave ) CIMApiClientHandler( aStatus );
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop();
       
    40     return self;
       
    41     }
       
    42 
       
    43 void CIMApiClientHandler::ConstructL()
       
    44     {
       
    45     }
       
    46 
       
    47 CIMApiClientHandler::CIMApiClientHandler( TRequestStatus& aStatus )
       
    48         : iStatus( aStatus )
       
    49     {
       
    50     }
       
    51 
       
    52 CIMApiClientHandler::~CIMApiClientHandler()
       
    53     {
       
    54     }
       
    55 
       
    56 
       
    57 void CIMApiClientHandler::HandleMessageSentL( const TInt aOpCode,
       
    58                                               const TInt aErrorCode )
       
    59     {
       
    60     TRequestStatus* s = &iStatus;
       
    61     CTestLogger::Log( _L( "HandleMessageSentL Passed - aErrorCode=%d" ), aErrorCode );
       
    62 
       
    63     if ( aErrorCode == 0 || aErrorCode == KImApiErrInvalidUserId || aErrorCode == KImApiErrNotLogged || aErrorCode == KImApiErrPartialSuccess  )
       
    64         {
       
    65         if ( aErrorCode == 0 )
       
    66             {
       
    67             User::RequestComplete( s, KErrNone ); // OK
       
    68             }
       
    69         else if ( aErrorCode == KImApiErrInvalidUserId )
       
    70             {
       
    71             User::RequestComplete( s, KErrNone ); // OK
       
    72             }
       
    73         else if ( aErrorCode == KImApiErrPartialSuccess )
       
    74             {
       
    75             User::RequestComplete( s, KErrNone ); // OK
       
    76             }
       
    77         else
       
    78             {
       
    79             User::RequestComplete( s, KErrNone );
       
    80             }
       
    81         }
       
    82     else
       
    83         {
       
    84         User::RequestComplete( s, aErrorCode ); // FAILED
       
    85         }
       
    86     }
       
    87 
       
    88 void CIMApiClientHandler::HandleSendErrorL( const TInt aOpCode,
       
    89                                             const TInt aErrorCode,
       
    90                                             MImClientDetailedError* aDetailedError )
       
    91 
       
    92     {
       
    93     TRequestStatus* s = &iStatus;
       
    94     TBuf<500> buffer;
       
    95 
       
    96     CTestLogger::Log( _L( "HandleSendErrorL - aErrorCode=%d" ), aErrorCode );
       
    97     if ( aErrorCode == 0 || aErrorCode == KImApiErrInvalidUserId || aErrorCode == KImApiErrNotLogged || aErrorCode == KImApiErrPartialSuccess  )
       
    98         {
       
    99         if ( aErrorCode == 0 )
       
   100             {
       
   101             User::RequestComplete( s, KErrNone ); // OK
       
   102             }
       
   103         else if ( aErrorCode == KImApiErrInvalidUserId )
       
   104             {
       
   105             User::RequestComplete( s, KErrNone ); // OK
       
   106             }
       
   107         else if ( aErrorCode == KImApiErrPartialSuccess )
       
   108             {
       
   109             for ( TInt i = 0; i < aDetailedError->Count(); i++ )
       
   110                 {
       
   111                 buffer.Copy( aDetailedError->UserId( i ) );
       
   112                 }
       
   113             User::RequestComplete( s, KErrNone ); // OK
       
   114             }
       
   115         else
       
   116             {
       
   117             User::RequestComplete( s, KErrNone );
       
   118             }
       
   119         }
       
   120     else
       
   121         {
       
   122         User::RequestComplete( s, KErrNone ); // PASSED sad but true
       
   123         }
       
   124     }
       
   125 
       
   126 
       
   127 void CIMApiClientHandler::HandleNewPToPMessageL( const TInt aErrorCode,
       
   128                                                  const TContactItemId aContactId,
       
   129                                                  const TDesC& aUserId,
       
   130                                                  const TDesC& aMessageType,
       
   131                                                  const TDesC16& aContent )
       
   132     {
       
   133     TRequestStatus* s = &iStatus;
       
   134     CTestLogger::Log( _L( "HandleNewPToPMessageL Passed - aErrorCode=%d" ), aErrorCode );
       
   135 
       
   136     if ( aErrorCode == 0 )
       
   137         {
       
   138         User::RequestComplete( s, KErrNone );
       
   139         }
       
   140     else
       
   141         {
       
   142         User::RequestComplete( s, aErrorCode );
       
   143         }
       
   144     }
       
   145 
       
   146 void CIMApiClientHandler::HandleNewPToPMessageL( const TInt aErrorCode,
       
   147                                                  const TContactItemId aContactId,
       
   148                                                  const TDesC& aUserId,
       
   149                                                  const TDesC& aMessageType,
       
   150                                                  const TDesC8& aContent )
       
   151     {
       
   152     TRequestStatus* s = &iStatus;
       
   153     CTestLogger::Log( _L( "HandleNewPToPMessageL Passed - aErrorCode=%d" ), aErrorCode );
       
   154     if ( aErrorCode == 0 )
       
   155         {
       
   156         User::RequestComplete( s, KErrNone );
       
   157         }
       
   158     else
       
   159         {
       
   160         User::RequestComplete( s, aErrorCode );
       
   161         }
       
   162     }
       
   163 
       
   164 
       
   165 void CIMApiClientHandler::TimedOut()
       
   166     {
       
   167     TRequestStatus* s = &iStatus;
       
   168     User::RequestComplete( s, KErrTimedOut );
       
   169     }
       
   170 
       
   171 
       
   172 
       
   173 //////////////////////////////////////////////////////////////////////////
       
   174 
       
   175 CConnectionObserver* CConnectionObserver::NewL( TRequestStatus& aStatus )
       
   176     {
       
   177     CConnectionObserver* self = new( ELeave ) CConnectionObserver( aStatus );
       
   178     CleanupStack::PushL( self );
       
   179     self->ConstructL();
       
   180     CleanupStack::Pop();
       
   181     return self;
       
   182     }
       
   183 
       
   184 void CConnectionObserver::ConstructL()
       
   185     {
       
   186     }
       
   187 
       
   188 CConnectionObserver::CConnectionObserver( TRequestStatus& aStatus )
       
   189         : iStatus( aStatus )
       
   190     {
       
   191     }
       
   192 
       
   193 CConnectionObserver::~CConnectionObserver()
       
   194     {
       
   195     }
       
   196 
       
   197 
       
   198 void CConnectionObserver::HandleConnectL( const TInt aErrorCode )
       
   199     {
       
   200     TRequestStatus* s = &iStatus;
       
   201     CTestLogger::Log( _L( "HandleConnectL Passed - aErrorCode=%d" ), aErrorCode );
       
   202 
       
   203     if ( aErrorCode == 0 )
       
   204         {
       
   205         User::RequestComplete( s, KErrNone ); // OK
       
   206         }
       
   207     else if ( aErrorCode == KImApiErrInvalidUserId )
       
   208         {
       
   209         User::RequestComplete( s, KErrNone ); // OK
       
   210         }
       
   211     else if ( aErrorCode == -33 )
       
   212         {
       
   213         User::RequestComplete( s, aErrorCode ); // FAILED
       
   214         }
       
   215     else if ( aErrorCode == -4154 )
       
   216         {
       
   217         User::RequestComplete( s, aErrorCode );   // FAILED
       
   218         }
       
   219     else if ( aErrorCode == -16 )
       
   220         {
       
   221         User::RequestComplete( s, KErrNone );  // OK IN IMAPI POINT OF WIEV
       
   222         }
       
   223     else if ( aErrorCode == KImApiErrLoginInProgress )
       
   224         {
       
   225         User::RequestComplete( s, KErrNone );  // OK IN IMAPI POINT OF WIEV
       
   226         }
       
   227     else
       
   228         {
       
   229         User::RequestComplete( s, aErrorCode );// FAILED
       
   230         }
       
   231     }
       
   232 
       
   233 void CConnectionObserver::HandleDisconnectL()
       
   234     {
       
   235     TRequestStatus* s = &iStatus;
       
   236     CTestLogger::Log( _L( " HandleDisconnectL " ) );
       
   237     User::RequestComplete( s, KErrNone ); //OK
       
   238     }
       
   239 
       
   240 void CConnectionObserver::HandleLoginL( const TInt aErrorCode )
       
   241     {
       
   242     CTestLogger::Log( _L( "HandleLoginL Passed - aErrorCode=%d" ), aErrorCode );
       
   243 
       
   244     TRequestStatus* s = &iStatus;
       
   245     if ( aErrorCode == 0 )
       
   246         {
       
   247         User::RequestComplete( s, KErrNone );
       
   248         }
       
   249     else
       
   250         {
       
   251         User::RequestComplete( s, aErrorCode );
       
   252         }
       
   253     }
       
   254 
       
   255 void CConnectionObserver::HandleCancelLoginL( const TInt aErrorCode )
       
   256     {
       
   257     CTestLogger::Log( _L( "HandleCancelLoginL Passed - aErrorCode=%d" ), aErrorCode );
       
   258     TRequestStatus* s = &iStatus;
       
   259     if ( aErrorCode == 0 )
       
   260         {
       
   261         User::RequestComplete( s, KErrNone );
       
   262         }
       
   263     else
       
   264         {
       
   265         User::RequestComplete( s, aErrorCode );
       
   266         }
       
   267     }
       
   268 
       
   269 void CConnectionObserver::HandleLogoutL( const TInt aErrorCode )
       
   270     {
       
   271     CTestLogger::Log( _L( "HandleLogoutL Passed-  aErrorCode=%d" ), aErrorCode );
       
   272     CActiveScheduler::Stop();
       
   273     }
       
   274 
       
   275 
       
   276 
       
   277 //**********************************
       
   278 // CImpsClientLogger
       
   279 //**********************************
       
   280 const TInt KLogBufferLength = 256;
       
   281 _LIT( KLogDir, "impsc" );
       
   282 _LIT( KLogFile, "IMAPIHandlersLog.txt" );
       
   283 
       
   284 EXPORT_C void CTestLogger::Log( TRefByValue<const TDesC> aFmt, ... )
       
   285     {
       
   286     VA_LIST list;
       
   287     VA_START( list, aFmt );
       
   288 
       
   289     // Print to log file
       
   290     TBuf<KLogBufferLength> buf;
       
   291     buf.FormatList( aFmt, list );
       
   292 
       
   293     // Write to log file
       
   294     RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, buf );
       
   295     }
       
   296 
       
   297 void CTestScheduler::Error( TInt /*anError */ ) const
       
   298     {
       
   299     CTestLogger::Log( _L( "ClientTester RunL ERROR RECEIVED" ) );
       
   300     }