tsrc/public/basic/obexservapitest/src/ObexServAPItestBlocks.cpp
branchRCL_3
changeset 13 b6f55cd40afd
parent 11 a42ed326b458
child 14 f7fbeaeb166a
equal deleted inserted replaced
11:a42ed326b458 13:b6f55cd40afd
     1 /*
       
     2 * Copyright (c) 2002 - 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 "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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32svr.h>
       
    22 #include <StifParser.h>
       
    23 #include <Stiftestinterface.h>
       
    24 #include <UiklafInternalCRKeys.h>
       
    25 #include <UikonInternalPSKeys.h>
       
    26 #include <obexutils.rsg>
       
    27 #include <obex.h>
       
    28 #include "testlogger.h"
       
    29 #include "ObexServAPItest.h"
       
    30 
       
    31 
       
    32 // Defined to coincide with the definition in btmsgtypeuid.h 
       
    33 const TUid KUidMsgTypeBt                 = {0x10009ED5};
       
    34 
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CObexServAPItest::Delete
       
    40 // Delete here all resources allocated and opened from test methods. 
       
    41 // Called from destructor. 
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CObexServAPItest::Delete() 
       
    45     {
       
    46     delete iObexObject;
       
    47     iObexObject = NULL;
       
    48     delete iBuf;
       
    49     iBuf = NULL;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CObexServAPItest::RunMethodL
       
    54 // Run specified method. Contains also table of test mothods and their names.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 TInt CObexServAPItest::RunMethodL( 
       
    58     CStifItemParser& aItem ) 
       
    59     {
       
    60 
       
    61     static TStifFunctionInfo const KFunctions[] =
       
    62         {  
       
    63         // Copy this line for every implemented function.
       
    64         // First string is the function name used in TestScripter script file.
       
    65         // Second is the actual implementation member function. 
       
    66         ENTRY( "GetFileSystemStatus", CObexServAPItest::GetFileSystemStatusL ),
       
    67         ENTRY( "GetMmcFileSystemStatus", CObexServAPItest::GetMmcFileSystemStatusL ),
       
    68         ENTRY( "GetMessageCentreDriveL", CObexServAPItest::GetMessageCentreDriveL ),
       
    69         ENTRY( "CreateDefaultMtmServiceL", CObexServAPItest::CreateDefaultMtmServiceL ),
       
    70         ENTRY( "GetCenRepKeyIntValueL", CObexServAPItest::GetCenRepKeyIntValueL ),
       
    71         ENTRY( "GetPubSubKeyIntValue", CObexServAPItest::GetPubSubKeyIntValueL ),
       
    72         ENTRY( "CreateOutBoxEntry", CObexServAPItest::CreateOutBoxEntryL ),
       
    73         ENTRY( "RemoveOutBoxEntry", CObexServAPItest::RemoveOutBoxEntryL ),
       
    74         ENTRY( "SaveObjToInbox", CObexServAPItest::SaveObjToInboxL ),
       
    75         ENTRY( "CreateEntryToInbox", CObexServAPItest::CreateEntryToInboxL ),
       
    76         ENTRY( "SaveRFileObjectToInbox", CObexServAPItest::SaveRFileObjectToInboxL ),
       
    77         ENTRY( "RemoveObjectFromInbox", CObexServAPItest::RemoveObjectL ),
       
    78         };
       
    79 
       
    80     const TInt count = sizeof( KFunctions ) / 
       
    81                         sizeof( TStifFunctionInfo );
       
    82 
       
    83     return RunInternalL( KFunctions, count, aItem );
       
    84 
       
    85     }
       
    86     
       
    87  // -----------------------------------------------------------------------------
       
    88 // CBtApiTest::TestCompleted
       
    89 // -----------------------------------------------------------------------------
       
    90 //  
       
    91 void CObexServAPItest::TestCompleted( TInt aErr, const TUint8* aFunc, const TDesC& aArg )
       
    92     {
       
    93     iTestLogger->LogResult( (TPtrC8( aFunc )), aArg, aErr );
       
    94     Signal( aErr );
       
    95     }
       
    96        
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CObexServAPItest::GetFileSystemStatusL
       
   100 // Test code for getting file system status.
       
   101 // (other items were commented in a header).
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 TInt CObexServAPItest::GetFileSystemStatusL( CStifItemParser& /*aItem*/ )
       
   105     {
       
   106     // Print to log file
       
   107     TInt retVal=TObexUtilsMessageHandler::GetFileSystemStatus();
       
   108     if (retVal == 0 || retVal == KErrDiskFull)
       
   109         {
       
   110         TestCompleted( KErrNone, TLFUNCLOG, _L("GetFileSystemStatusL"));
       
   111         }
       
   112     else
       
   113         {
       
   114         TestCompleted( retVal, TLFUNCLOG, _L("Error getting files ystem status"));    
       
   115         }    
       
   116     return KErrNone;
       
   117 
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CObexServAPItest::GetMmcFileSystemStatusL
       
   122 // Test code for getting mmc file system status.
       
   123 // (other items were commented in a header).
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 TInt CObexServAPItest::GetMmcFileSystemStatusL( CStifItemParser& /*aItem*/ )
       
   127     {
       
   128     TInt retVal=TObexUtilsMessageHandler::GetMmcFileSystemStatus();
       
   129     if (retVal == 0 || retVal == KErrDiskFull)
       
   130         {
       
   131         TestCompleted( KErrNone, TLFUNCLOG, _L("GetFileSystemStatusL"));
       
   132         }
       
   133     else
       
   134         {
       
   135         TestCompleted( retVal, TLFUNCLOG, _L("Error getting files ystem status"));    
       
   136         }    
       
   137 
       
   138     return KErrNone;
       
   139 
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CObexServAPItest::GetMessageCentreDriveL
       
   144 // Test code for getting message center drive. 
       
   145 // (other items were commented in a header).
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 TInt CObexServAPItest::GetMessageCentreDriveL( CStifItemParser& /*aItem*/ )
       
   149     {
       
   150     
       
   151     TInt retVal = TObexUtilsMessageHandler::GetMessageCentreDriveL();
       
   152     if (retVal >= 0 )
       
   153         {
       
   154         TestCompleted( KErrNone, TLFUNCLOG, _L("GetMessageCentreDrive"));
       
   155         }
       
   156     else
       
   157         {
       
   158         TestCompleted( retVal, TLFUNCLOG, _L("GetMessageCentreDrive failed"));    
       
   159         }    
       
   160 
       
   161     return KErrNone;
       
   162 
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CObexServAPItest::CreateDefaultMtmServiceL
       
   167 // Test code for creating Default MTM services.
       
   168 // (other items were commented in a header).
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TInt CObexServAPItest::CreateDefaultMtmServiceL( CStifItemParser& /*aItem*/ )
       
   172     {
       
   173 
       
   174     TRAPD(error, TObexUtilsMessageHandler::CreateDefaultMtmServiceL(KUidMsgTypeBt) );
       
   175     if (error == KErrNone)
       
   176         {
       
   177         TestCompleted( KErrNone, TLFUNCLOG, _L("CreateDefaultMtmServiceL"));        
       
   178         }
       
   179     else
       
   180         {
       
   181         TestCompleted( error, TLFUNCLOG, _L("CreateDefaultMtmServiceL"));                       
       
   182         }
       
   183     return KErrNone;
       
   184 
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CObexServAPItest::GetCenRepKeyIntValueL
       
   189 // Test code for Getting CenRep key.    
       
   190 // (other items were commented in a header).
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 TInt CObexServAPItest::GetCenRepKeyIntValueL( CStifItemParser&  /*aItem*/ )
       
   194     {
       
   195     TInt limit=0;    
       
   196     TInt error=0;
       
   197     TRAPD(leaveVal, error = TObexUtilsMessageHandler::GetCenRepKeyIntValueL(KCRUidUiklaf,
       
   198                                                                 KUikOODDiskCriticalThreshold,
       
   199                                                                 limit));
       
   200     if( leaveVal != KErrNone ) 
       
   201         {
       
   202         TestCompleted( leaveVal, TLFUNCLOG, _L("GetCenRepKeyIntValueL leaves"));                       
       
   203         }    
       
   204     else if (error == KErrNone)
       
   205         {
       
   206         TestCompleted( leaveVal, TLFUNCLOG, _L("GetCenRepKeyIntValue return error"));                       
       
   207         }   
       
   208     else
       
   209         {
       
   210         TestCompleted( KErrNone, TLFUNCLOG, _L("GetCenRepKeyIntValueL"));                           
       
   211         }    
       
   212     
       
   213     return KErrNone;
       
   214 
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CObexServAPItest::GetPubSubKeyIntValueL
       
   219 // Test code for Getting PubSub key.    
       
   220 // (other items were commented in a header).
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 TInt CObexServAPItest::GetPubSubKeyIntValueL( CStifItemParser& /*aItem*/ )
       
   224     {
       
   225     TInt status = KErrNone;
       
   226     TInt retVal = KErrNone;
       
   227     
       
   228     TRAPD(leaveVal, retVal = TObexUtilsMessageHandler::GetPubSubKeyIntValue(KPSUidUikon, KUikFFSFreeLevel, status));
       
   229     
       
   230     if( leaveVal != KErrNone ) 
       
   231         {
       
   232         TestCompleted( leaveVal, TLFUNCLOG, _L("GetPubSubKeyIntValueL leaves"));                       
       
   233         }    
       
   234     else if (retVal == KErrNone)
       
   235         {
       
   236         TestCompleted( retVal, TLFUNCLOG, _L("GetPubSubKeyIntValueL return error"));                       
       
   237         }   
       
   238     else
       
   239         {
       
   240         TestCompleted( KErrNone, TLFUNCLOG, _L("GetPubSubKeyIntValue"));                           
       
   241         }  
       
   242 
       
   243     return KErrNone;
       
   244 
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CObexServAPItest::OutBoxEntryL
       
   249 // Test code for Creating outbox entry.
       
   250 // (other items were commented in a header).
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 TInt CObexServAPItest::CreateOutBoxEntryL( CStifItemParser& /*aItem*/ )
       
   254     {    
       
   255     TRAPD(error, iMessageServerIndex = TObexUtilsMessageHandler::CreateOutboxEntryL( KUidMsgTypeBt, R_BT_SEND_OUTBOX_SENDING ));  
       
   256     if( error != KErrNone)
       
   257         {
       
   258         TestCompleted( error, TLFUNCLOG, _L("CreateOutBoxEntryL leaves")); 
       
   259         }
       
   260     else     
       
   261         {
       
   262         TestCompleted( KErrNone, TLFUNCLOG, _L("CreateOutBoxEntryL"));     
       
   263         }
       
   264 
       
   265     return KErrNone;
       
   266 
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CObexServAPItest::OutBoxEntryL
       
   271 // Test code for removing outbox entry.
       
   272 // (other items were commented in a header).
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 TInt CObexServAPItest::RemoveOutBoxEntryL( CStifItemParser& /*aItem*/ )
       
   276     {   
       
   277     
       
   278     TRAPD(error, TObexUtilsMessageHandler::DeleteOutboxEntryL( iMessageServerIndex ));
       
   279     if( error != KErrNone)
       
   280         {
       
   281         TestCompleted( error, TLFUNCLOG, _L("RemoveOutBoxEntryL leaves")); 
       
   282         }
       
   283     else     
       
   284         {
       
   285         TestCompleted( KErrNone, TLFUNCLOG, _L("RemoveOutBoxEntryL"));     
       
   286         }
       
   287     return KErrNone;
       
   288 
       
   289     }
       
   290     
       
   291 // -----------------------------------------------------------------------------
       
   292 // CObexServAPItest::SaveObjToInboxL
       
   293 // Test code for save received file to inbox. 
       
   294 // (other items were commented in a header).
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 TInt CObexServAPItest::SaveObjToInboxL( CStifItemParser& /*aItem*/ )
       
   298     {   
       
   299     
       
   300     CObexBufObject* obexobject = CObexBufObject::NewL( NULL );
       
   301     CleanupStack::PushL(obexobject);    
       
   302     
       
   303     TRAP_IGNORE(TObexUtilsMessageHandler::SaveObjToInboxL(obexobject ,
       
   304                                               KNullDesC, 
       
   305                                               KUidMsgTypeBt ));
       
   306     TestCompleted( KErrNone, TLFUNCLOG, _L("SaveObjToInboxL leaves")); 
       
   307     
       
   308     CleanupStack::PopAndDestroy(obexobject);
       
   309     return KErrNone;
       
   310 
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CObexServAPItest::CreateAndSaveObjectL
       
   315 // Test code for creating entry to inbox.
       
   316 // (other items were commented in a header).
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 TInt CObexServAPItest::CreateEntryToInboxL( CStifItemParser& /*aItem*/ )
       
   320     {
       
   321     iFile = RFile();
       
   322     
       
   323     if ( iObexObject)
       
   324         {
       
   325         delete iObexObject;
       
   326         iObexObject = NULL;
       
   327         }
       
   328         
       
   329     iObexObject = CObexBufObject::NewL( NULL );
       
   330     
       
   331     TRAPD( error, TObexUtilsMessageHandler::CreateInboxAttachmentL( iObexObject,
       
   332                                                       KUidMsgTypeBt,
       
   333                                                       iMessageServerIndex,
       
   334                                                       iFile));
       
   335                                                       
       
   336                                                       
       
   337     iBuf = CBufFlat::NewL(1024);
       
   338     iBuf->ResizeL(1024);
       
   339     
       
   340     TObexRFileBackedBuffer bufferdetails(*iBuf,iFile,CObexBufObject::EDoubleBuffering);    
       
   341     
       
   342     TRAP_IGNORE( iObexObject->SetDataBufL( bufferdetails) );
       
   343     
       
   344                                                       
       
   345                                                       
       
   346     iFile.Write(_L8("test"));    
       
   347     iObexObject->SetNameL(_L("test.txt"));        
       
   348     
       
   349     if( error != KErrNone)
       
   350         {
       
   351         TestCompleted( error, TLFUNCLOG, _L("CreateEntryToInboxL leaves")); 
       
   352         }    
       
   353     else     
       
   354         {
       
   355         TestCompleted( error, TLFUNCLOG, _L("CreateEntryToInboxL"));     
       
   356         }         
       
   357     return KErrNone;
       
   358     }
       
   359 
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // CObexServAPItest::CreateAndSaveObjectL
       
   363 // Test code for creating entry to inbox.
       
   364 // (other items were commented in a header).
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 TInt CObexServAPItest::SaveRFileObjectToInboxL( CStifItemParser& /*aItem*/ )
       
   368     {
       
   369     TRAPD( error, TObexUtilsMessageHandler::SaveObjToInboxL(
       
   370             iObexObject,
       
   371             iFile,
       
   372             iMessageServerIndex));
       
   373     
       
   374     delete iBuf;
       
   375     iBuf = NULL;
       
   376     if( error != KErrNone)
       
   377         {
       
   378         TestCompleted( error, TLFUNCLOG, _L("SaveObjToInboxL leaves")); 
       
   379         }
       
   380     else     
       
   381         {
       
   382         TestCompleted( error, TLFUNCLOG, _L("SaveObjToInboxL"));     
       
   383         }                                          
       
   384     
       
   385     return KErrNone;
       
   386     }
       
   387     
       
   388 // -----------------------------------------------------------------------------
       
   389 // CObexServAPItest::RemoveObjectL
       
   390 // Test code for removing entry to inbox.
       
   391 // (other items were commented in a header).
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 TInt CObexServAPItest::RemoveObjectL( CStifItemParser& /*aItem*/ )
       
   395     {
       
   396     TRAPD(error,TObexUtilsMessageHandler::RemoveInboxEntriesL(iObexObject, iMessageServerIndex));    
       
   397     delete iBuf;
       
   398     iBuf = NULL;
       
   399     if( error != KErrNone)
       
   400         {
       
   401         TestCompleted( error, TLFUNCLOG, _L("SaveObjToInboxL leaves")); 
       
   402         }
       
   403     else     
       
   404         {
       
   405         TestCompleted( error, TLFUNCLOG, _L("SaveObjToInboxL"));     
       
   406         }                                              
       
   407     return KErrNone;
       
   408     }
       
   409 
       
   410 
       
   411 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   412 // None
       
   413 
       
   414 //  End of File