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