omadmadapters/email/tsrc/src/dmatest.cpp
branchRCL_3
changeset 57 6757f1e2efd2
equal deleted inserted replaced
55:c4687ff85147 57:6757f1e2efd2
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation of DM adapter test component
       
    15 * 	This is part of omadmextensions/adapter test application.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 // INCLUDE FILES
       
    25 #include "dmatest.h"
       
    26 
       
    27 #include <StifParser.h>
       
    28 #include <Stiftestinterface.h>
       
    29 #include <S32FILE.H>
       
    30 #include <s32mem.h>
       
    31 #include <apgcli.h>
       
    32 #include <e32svr.h>
       
    33 #include <e32math.h>
       
    34 #include <f32file.h>
       
    35 #include <swinstapi.h>
       
    36 
       
    37 #include "TestDmDDFObject.h"
       
    38 
       
    39 _LIT8( KEmptyType, "" );
       
    40 _LIT8( KDefaultType, "text/plain" );
       
    41 _LIT( KMappingTableFile, "\\dmtestmappings.txt" );
       
    42 //_LIT8( KNSmlDMSeparator8, "/" );
       
    43 const TUint8 KNSmlDMUriSeparator = 0x2f; //forward slash
       
    44 
       
    45 #define LEAVE_IF_ERROR(x,msg) \
       
    46 	{ TInt __xres = (x); if ( __xres < 0 ) { if ( iLog ) iLog->Log( (msg), __xres ); User::Leave( __xres );	} }
       
    47 
       
    48 
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // Cdmatest::Cdmatest
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 Cdmatest::Cdmatest(CTestModuleIf& aTestModuleIf, TUid aUid ):
       
    58         CScriptBase( aTestModuleIf ), iMappingTable(2), iUid( aUid )
       
    59     {
       
    60     
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // Cdmatest::ConstructL
       
    65 // Symbian 2nd phase constructor can leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void Cdmatest::ConstructL()
       
    69     {    
       
    70     Adapter();
       
    71 	iEmptyMappingInfoArray = new ( ELeave ) CArrayFixFlat<TSmlDmMappingInfo>(1);
       
    72 	
       
    73 	TRAPD( err, LoadMappingsL() );
       
    74 	if (err != KErrEof && err != KErrNone && err != KErrNotFound)
       
    75 		{
       
    76 		User::Leave( err );
       
    77 		}
       
    78     }
       
    79     
       
    80 CNSmlDmEmailAdapter *Cdmatest::Adapter()  
       
    81 	{
       
    82 	if ( iAdapter == NULL )
       
    83 		{
       
    84 		if ( iLog )
       
    85 			{
       
    86 			iLog->Log( _L( "Loading Adapter" ) );
       
    87 			}
       
    88   		
       
    89   		TRAPD( err, iAdapter = (CNSmlDmEmailAdapter*) CSmlDmAdapter::NewL( iUid,*this ) );
       
    90 	if ( err == KErrNone )
       
    91 		{
       
    92 		if (iLog )
       
    93 			{
       
    94 			iLog->Log( _L( "Loaded" ) );	
       
    95 			}
       
    96 		}
       
    97 	else
       
    98 		{
       
    99 		if (iLog)
       
   100 			{
       
   101 			iLog->Log( _L( "Failed to load adapter: %d" ), err );
       
   102 			}
       
   103 		}
       
   104 		}
       
   105 	return iAdapter;
       
   106 	}
       
   107     
       
   108     
       
   109 void Cdmatest::LoadMappingsL()
       
   110 	{
       
   111 	TDataType type; 
       
   112 	HBufC8 *data = LoadFileLC( KMappingTableFile,  type );
       
   113 	RDesReadStream buf( *data );
       
   114 	CleanupClosePushL( buf );
       
   115 
       
   116 	TInt len( data->Length() );
       
   117 	while (buf.Source()->TellL( MStreamBuf::ERead ).Offset() < len)
       
   118 		{
       
   119 		TUint32 val = buf.ReadUint32L();
       
   120 		TBuf8<256> uri;
       
   121 		TBuf8<64> luid;
       
   122 		buf.ReadL(uri, val);
       
   123 		val = buf.ReadUint32L();
       
   124 		buf.ReadL(luid, val);
       
   125 		TMapping m( uri, luid ) ;
       
   126 		TInt err( iMappingTable.Append( m )	);
       
   127 		if ( err == KErrNone )
       
   128 			{
       
   129 			iLog->Log( _L8( "Loaded mapping: '%S' : '%S'"), &m.iURI, &m.iLuid );
       
   130 			}
       
   131 		else
       
   132 			{
       
   133 			iLog->Log( _L8( "FAILED TO Load mapping: '%d' "), err );
       
   134 			}
       
   135 		}
       
   136 	CleanupStack::PopAndDestroy( &buf); // buf
       
   137 	CleanupStack::PopAndDestroy( data ); // data
       
   138 	}
       
   139     	
       
   140 	
       
   141 
       
   142 void Cdmatest::SaveMappingsL()
       
   143     {
       
   144 	TInt c( iMappingTable.Count() );
       
   145 	if ( c > 0 )
       
   146 	{
       
   147     	RFs fs;
       
   148     	User::LeaveIfError( fs.Connect() );
       
   149     	CleanupClosePushL( fs );
       
   150     	RFileWriteStream buf;
       
   151     	User::LeaveIfError( buf.Replace( fs, KMappingTableFile, EFileWrite ) );
       
   152     	CleanupClosePushL( buf );
       
   153 		
       
   154 		TInt i( 0 ) ;
       
   155 		do 
       
   156 			{
       
   157 			buf.WriteUint32L( iMappingTable[i].iURI.Length() );
       
   158 			buf.WriteL( iMappingTable[i].iURI );
       
   159 			buf.WriteUint32L( iMappingTable[i].iLuid.Length() );
       
   160 			buf.WriteL( iMappingTable[i].iLuid );
       
   161 			}
       
   162 		while ( ++i < c )	;
       
   163 		buf.CommitL();
       
   164 		buf.Close();
       
   165 	
       
   166 		CleanupStack::PopAndDestroy(); // buf
       
   167 		CleanupStack::PopAndDestroy(); // fs
       
   168 		}
       
   169     }
       
   170     	
       
   171     
       
   172 // Destructor
       
   173 Cdmatest::~Cdmatest()
       
   174     {
       
   175     // Delete resources allocated from test methods
       
   176     TRAPD(err, SaveMappingsL() );
       
   177     if ( err != KErrNone )
       
   178     	{
       
   179     		if ( iLog )
       
   180 				{
       
   181     			iLog->Log( _L8( "Failed to save mappings!: %d"), err );
       
   182     		}
       
   183     	}
       
   184     Delete();
       
   185     
       
   186     // Delete logger
       
   187     delete iLog;  
       
   188     delete iEmptyMappingInfoArray;
       
   189     delete iAdapter;
       
   190     delete iURI;
       
   191     iMappingTable.Reset();
       
   192     REComSession::FinalClose();    
       
   193     }
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // Camatest::Delete
       
   198 // Delete here all resources allocated and opened from test methods. 
       
   199 // Called from destructor. 
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void Cdmatest::Delete() 
       
   203     {
       
   204     
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // Cdmatest::?member_function
       
   209 // ?implementation_description
       
   210 // (other items were commented in a header).
       
   211 // -----------------------------------------------------------------------------
       
   212 
       
   213 
       
   214         
       
   215 HBufC8 *Cdmatest::GetNextStringLC ( CStifItemParser& aItem, const TDesC &aName )
       
   216 	{
       
   217 	TPtrC nodename( KNullDesC );
       
   218 
       
   219     TInt i( aItem.GetNextString ( nodename ) );
       
   220     if ( i != KErrNone ) 
       
   221 	    {
       
   222 	    iLog->Log( _L( "ERROR Reading '%S' argument: 0x%X" ), &aName, i );
       
   223 	    }
       
   224 	else
       
   225 		{
       
   226 		iLog->Log( _L("%S: %S"), &aName, &nodename);
       
   227 		}
       
   228 	
       
   229 	HBufC8 *buf = HBufC8::NewLC( nodename.Length() ) ;
       
   230 	buf->Des().Copy( nodename );
       
   231 	return buf;
       
   232 	}
       
   233 	
       
   234 TInt Cdmatest::FetchNodeL( CStifItemParser& aItem )	
       
   235 	{
       
   236 
       
   237     TInt ret( KErrNone );
       
   238     // Print to UI
       
   239     TestModuleIf().Printf( 0, _L("Cdmatest"), _L("FetchNodeL") );
       
   240 
       
   241 	iResultsFunction = FetchNodeResultsL;
       
   242 	
       
   243     TPtrC8 nodename( GetNextStringLC( aItem, _L(" nodename" ) )->Des() ) ;
       
   244 		
       
   245 	SetURIL(nodename) ;//
       
   246 	HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   247 
       
   248 	Adapter()->ChildURIListL( *iURI, *luid, *iEmptyMappingInfoArray, 4, 5) ;
       
   249 
       
   250 	if ( iStatus == MSmlDmAdapter::EOk )
       
   251 		{
       
   252 		}
       
   253 	else
       
   254 		{
       
   255 		iLog->Log( _L("FetchNodeL: ChildUriList Error ! %d" ), iStatus );	
       
   256 		ret = KErrGeneral ;
       
   257 		}
       
   258 	CleanupStack::PopAndDestroy( luid ) ; 
       
   259 	CleanupStack::PopAndDestroy() ; // nodename
       
   260 	iLog->Log( _L("FetchNodeL: Test Complete with status %d" ), ret );	
       
   261 
       
   262     return ret;
       
   263 	}
       
   264 	
       
   265 TInt Cdmatest::StartAtomicL( CStifItemParser& /*aItem*/ )	
       
   266 	{
       
   267 	TRAPD( err, Adapter()->StartAtomicL() ) ;
       
   268 	iLog->Log( _L("StartAtomicL: Atomic started resulting error %d" ), err );	
       
   269     return err;
       
   270 	}
       
   271 
       
   272 TInt Cdmatest::RollbackAtomicL( CStifItemParser& /*aItem*/ )	
       
   273 	{
       
   274 	TRAPD( err, Adapter()->RollbackAtomicL() ) ;
       
   275 	iLog->Log( _L("RollbackAtomicL: Atomic rolled back resulting error %d" ), err );	
       
   276     return err;
       
   277 	}
       
   278 	
       
   279 TInt Cdmatest::CommitAtomicL( CStifItemParser& /*aItem*/ )	
       
   280 	{
       
   281 	TRAPD( err, Adapter()->CommitAtomicL() ) ;
       
   282 	iLog->Log( _L("RollbackAtomicL: Atomic commited resulting error %d" ), err );	
       
   283     return err;
       
   284 	}
       
   285 	
       
   286 
       
   287 TInt Cdmatest::DDFStructureL( CStifItemParser& /*aItem*/ )	
       
   288 	{
       
   289 	CTestDmDDFObject* ddfRoot = CTestDmDDFObject::NewLC( iLog ); //, aNodeName );
       
   290 
       
   291 	TRAPD( err, iAdapter->DDFStructureL( *ddfRoot ) ) ;
       
   292 	CleanupStack::PopAndDestroy( ddfRoot );
       
   293 	iLog->Log( _L("DDFStructureL: method called resulting error %d" ), err );	
       
   294     return err;
       
   295 	}
       
   296 		
       
   297 		
       
   298 TInt Cdmatest::AddNodeL( CStifItemParser& aItem )	
       
   299 	{
       
   300 
       
   301     TInt ret( KErrNone );
       
   302     // Print to UI
       
   303     TestModuleIf().Printf( 0, _L("Cdmatest"), _L("AddNodeL") );
       
   304 
       
   305     
       
   306     TPtrC8 nodename( GetNextStringLC ( aItem, _L("nodename" ) )->Des() ) ;
       
   307     SetURIL( nodename );
       
   308 
       
   309 	Adapter()->AddNodeObjectL( *iURI, KEmptyType, 8 ) ;
       
   310 	
       
   311 	if ( iStatus == MSmlDmAdapter::EOk )
       
   312 		{
       
   313 		iLog->Log( _L("AddNodeL: AddNodeObjectL Successful! %d" ), iStatus );	
       
   314 		}
       
   315 	else
       
   316 		{
       
   317 		iLog->Log( _L("AddNodeL: AddNodeObjectL Error ! %d" ), iStatus );	
       
   318 		ret = KErrGeneral ;
       
   319 		}
       
   320 		
       
   321 	CleanupStack::PopAndDestroy() ; // nodename
       
   322 	iLog->Log( _L("AddNodeL Test Complete with status %d" ), ret );	
       
   323 
       
   324     return ret;
       
   325 	}	
       
   326 		
       
   327 TInt Cdmatest::UpdateLeafL( CStifItemParser& aItem )	
       
   328 	{
       
   329 
       
   330     TInt ret( KErrNone );
       
   331     // Print to UI
       
   332     TestModuleIf().Printf( 0, _L("Cdmatest"), _L("UpdateLeafL") );
       
   333 
       
   334     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Node name") )->Des() ) ;
       
   335     TPtrC8 data (GetNextStringLC( aItem, _L("datafile"))->Des() );
       
   336     
       
   337 	HBufC8 *mime = GetNextStringLC( aItem, _L("mime") ) ;
       
   338     SetURIL( nodename );
       
   339     
       
   340     TPtrC8 parentURI(RemoveLastSeg(nodename));
       
   341     HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   342     
       
   343     TDataType type; 
       
   344 
       
   345 	TPtrC8 mimePtr( *mime == KNullDesC8 ? type.Des8() : mime->Des() );
       
   346 
       
   347     /**
       
   348     virtual void UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID,
       
   349 									const TDesC8& aObject, const TDesC8& aType,
       
   350 									TInt aStatusRef ) = 0;
       
   351     */
       
   352     
       
   353 	Adapter()->UpdateLeafObjectL( *iURI , *luid, data, mimePtr, 3);
       
   354 
       
   355 	if ( iStatus == MSmlDmAdapter::EOk )
       
   356 	{
       
   357 		iLog->Log( _L("UpdateLeafL: UpdateLeafObjectL Successful! %d" ), iStatus );	
       
   358 	}
       
   359 	else
       
   360 	{
       
   361 		iLog->Log( _L("UpdateLeafL UpdateLeafObjectL Error ! %d" ), iStatus );	
       
   362 		ret = KErrGeneral ;
       
   363 	}
       
   364 
       
   365 	CleanupStack::PopAndDestroy(); // loadfile
       
   366 	CleanupStack::PopAndDestroy(); // luid
       
   367 	CleanupStack::PopAndDestroy(); // mime
       
   368 	CleanupStack::PopAndDestroy(); // nodename
       
   369 
       
   370 	iLog->Log( _L("UpdateLeafL Test Complete with status %d" ), ret );	
       
   371 
       
   372     return ret;
       
   373 	}	
       
   374 	
       
   375 
       
   376 TInt Cdmatest::UpdateLeafDataURLL( CStifItemParser& aItem )	
       
   377 	{
       
   378 
       
   379     TInt ret( KErrNone );
       
   380     // Print to UI
       
   381     TestModuleIf().Printf( 0, _L("Cdmatest"), _L("UpdateLeafDataL") );
       
   382 
       
   383     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Node name") )->Des() ) ;
       
   384     TPtrC8 http (GetNextStringLC( aItem, _L("http"))->Des() );
       
   385     TPtrC8 url (GetNextStringLC( aItem, _L("rest of url"))->Des() );
       
   386 	HBufC8 *mime = GetNextStringLC( aItem, _L("mime") ) ;
       
   387     SetURIL( nodename );
       
   388     
       
   389     _LIT8( KTag, "://" );
       
   390     
       
   391     HBufC8 *fullurl = HBufC8::NewLC( http.Length() + KTag().Length() + url.Length() );
       
   392     TPtr8 pfullurl( fullurl->Des() );
       
   393     pfullurl.Copy( http ) ;
       
   394     pfullurl.Append( KTag );
       
   395     pfullurl.Append( url );
       
   396     TPtrC8 mimePtr( *mime == KNullDesC8 ? KDefaultType() : mime->Des() );
       
   397     
       
   398     HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   399     /**
       
   400     virtual void UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID,
       
   401 									const TDesC8& aObject, const TDesC8& aType,
       
   402 									TInt aStatusRef ) = 0;
       
   403     */
       
   404 	Adapter()->UpdateLeafObjectL( *iURI , *luid, pfullurl, mimePtr, 3);
       
   405 	if ( iStatus == MSmlDmAdapter::EOk )
       
   406 		{
       
   407 		iLog->Log( _L("UpdateLeafDataL: UpdateLeafObjectL Successful! %d" ), iStatus );	
       
   408 		}
       
   409 	else
       
   410 		{
       
   411 		iLog->Log( _L("UpdateLeafDataL UpdateLeafObjectL Error ! %d" ), iStatus );	
       
   412 		ret = KErrGeneral ;
       
   413 		}
       
   414 	CleanupStack::PopAndDestroy( luid ); // 
       
   415 	CleanupStack::PopAndDestroy( mime ); // mime
       
   416 	CleanupStack::PopAndDestroy(); // url
       
   417 	CleanupStack::PopAndDestroy(); // http
       
   418 	CleanupStack::PopAndDestroy(); // nodename
       
   419 	iLog->Log( _L("UpdateLeafDataL Test Complete with status %d" ), ret );	
       
   420 
       
   421     return ret;
       
   422 	}
       
   423     
       
   424 TInt Cdmatest::UpdateLeafDataL( CStifItemParser& aItem )	
       
   425 	{
       
   426 
       
   427     TInt ret( KErrNone );
       
   428     // Print to UI
       
   429    TestModuleIf().Printf( 0, _L("Camtest"), _L("UpdateLeafDataL") );
       
   430 
       
   431     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Node name") )->Des() ) ;
       
   432     TPtrC8 data (GetNextStringLC( aItem, _L("data"))->Des() );
       
   433 	HBufC8 *mime = GetNextStringLC( aItem, _L("mime") ) ;
       
   434 	
       
   435     SetURIL( nodename );
       
   436     
       
   437         
       
   438     TPtrC8 mimePtr( *mime == KNullDesC8 ? KDefaultType() : mime->Des() );
       
   439     
       
   440     TPtrC8 parentURI(RemoveLastSeg(nodename));
       
   441     HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   442      
       
   443 //    
       
   444 //    virtual void UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID,
       
   445 //									const TDesC8& aObject, const TDesC8& aType,
       
   446 //									TInt aStatusRef ) = 0;
       
   447 //   
       
   448 	Adapter()->UpdateLeafObjectL( *iURI , *luid, data, mimePtr, 3);
       
   449 	if ( iStatus == MSmlDmAdapter::EOk )
       
   450 		{
       
   451 		iLog->Log( _L("UpdateLeafDataL: UpdateLeafObjectL Successful! %d" ), iStatus );	
       
   452 		}
       
   453 	else
       
   454 		{
       
   455 		iLog->Log( _L("UpdateLeafDataL UpdateLeafObjectL Error ! %d" ), iStatus );	
       
   456 		ret = KErrGeneral ;
       
   457 		}
       
   458 	
       
   459 	CleanupStack::PopAndDestroy(); // mime
       
   460 	CleanupStack::PopAndDestroy(); // luid
       
   461 	CleanupStack::PopAndDestroy(); // data
       
   462 	CleanupStack::PopAndDestroy(); // nodename
       
   463 	iLog->Log( _L("UpdateLeafDataL Test Complete with status %d" ), ret );	
       
   464 
       
   465     return ret;
       
   466 	}	
       
   467 			
       
   468 TInt Cdmatest::FetchLeafL( CStifItemParser& aItem )	
       
   469 	{
       
   470 
       
   471     TInt ret( KErrNone );
       
   472     // Print to UI
       
   473     TestModuleIf().Printf( 0, _L("Camtest"), _L("FetchLeafL") );
       
   474 
       
   475 	iResultsFunction = NULL;
       
   476 	
       
   477     TInt i( 0 );
       
   478     TPtrC8 nodename ( GetNextStringLC( aItem, _L( "nodename" ) )->Des() ) ;
       
   479     
       
   480     //TPtrC datafile;
       
   481     TPtrC datafile( KNullDesC );
       
   482     i = aItem.GetNextString ( datafile ) ;
       
   483     if ( i != KErrNone ) 
       
   484 	    {
       
   485 	    iLog->Log(_L("FetchLeafL: ERROR Reading outfile argument: 0x%X"), i );
       
   486 	    //return i;
       
   487 	    }
       
   488 	else
       
   489 		{
       
   490 		iSaveFileName = datafile;
       
   491 		iLog->Log( _L( " Save file nameis '%S'" ), &iSaveFileName );
       
   492 		iResultsFunction = SaveDataL;
       
   493 		}
       
   494     
       
   495 	SetURIL(nodename) ;
       
   496 		
       
   497 		/*
       
   498 			void FetchLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID,
       
   499 								   const TDesC8& aType, TInt aResultsRef,
       
   500 								   TInt aStatusRef );
       
   501 		*/
       
   502     TPtrC8 parentURI(RemoveLastSeg(nodename));
       
   503     HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   504 
       
   505 	Adapter()->FetchLeafObjectL( *iURI, *luid, KEmptyType, 7, 8 ) ;
       
   506 	if ( iStatus == MSmlDmAdapter::EOk )
       
   507 		{
       
   508 		iLog->Log( _L("FetchLeafL: FetchLeafObjectL Successful! %d" ), iStatus );	
       
   509 		}
       
   510 	else
       
   511 		{
       
   512 		iLog->Log( _L("FetchLeafL: FetchLeafObjectL Error ! %d" ), iStatus );	
       
   513 		ret = KErrGeneral ;
       
   514 		}
       
   515 	CleanupStack::PopAndDestroy( luid );
       
   516 	CleanupStack::PopAndDestroy(  ); // nodename
       
   517 	iLog->Log( _L("FetchLeafL Test Complete with status %d" ), ret );	
       
   518     return ret;
       
   519 	}	
       
   520 
       
   521 
       
   522 TInt Cdmatest::ExecuteLeafL( CStifItemParser& aItem )		
       
   523 	{
       
   524 	TInt ret( KErrNone );
       
   525     // Print to UI
       
   526     TestModuleIf().Printf( 0, _L("Camtest"), _L("ExecuteLeafL") );
       
   527 
       
   528 	iResultsFunction = NULL;
       
   529 	
       
   530     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Nodename") )->Des() ) ;
       
   531     TPtrC8 data( GetNextStringLC ( aItem, _L("Input file") )->Des() ) ;
       
   532 	
       
   533 	SetURIL(nodename) ;
       
   534 
       
   535 		/*
       
   536 			virtual void ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID,
       
   537 							      const TDesC8& aArgument, const TDesC8& aType,
       
   538 								  TInt aStatusRef ) = 0;
       
   539 		*/
       
   540 	TDataType type;
       
   541 	
       
   542     TPtrC8 parentURI(RemoveLastSeg(nodename));
       
   543     HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   544 
       
   545 	Adapter()->ExecuteCommandL( *iURI, *luid, data, KEmptyType, 11 ) ;
       
   546 	if ( iStatus == MSmlDmAdapter::EOk )
       
   547 		{
       
   548 		iLog->Log( _L("ExecuteLeafL: ExecuteCommandL Successful! %d" ), iStatus );	
       
   549 		}
       
   550 	else
       
   551 		{
       
   552 		iLog->Log( _L("ExecuteLeafL: ExecuteCommandL FetchLeafObjectL Error ! %d" ), iStatus );	
       
   553 		ret = KErrGeneral ;
       
   554 		}
       
   555 	CleanupStack::PopAndDestroy( luid ); // luid
       
   556 	CleanupStack::PopAndDestroy(); // data
       
   557 	CleanupStack::PopAndDestroy(); // nodename
       
   558 	
       
   559 	iLog->Log( _L("ExecuteLeafL: Test Complete with status %d" ), ret );	
       
   560 
       
   561     return ret;
       
   562 	}
       
   563 	
       
   564 TInt Cdmatest::CompleteCommandsL( CStifItemParser& /*aItem*/ )
       
   565 	{
       
   566 	TRAPD( err, Adapter()->CompleteOutstandingCmdsL() );
       
   567 	delete iAdapter;
       
   568 	iAdapter = NULL;
       
   569 	return err;
       
   570 	}
       
   571 TInt Cdmatest::DeleteObjectL( CStifItemParser& aItem )
       
   572 {
       
   573 	TInt ret( KErrNone );
       
   574     // Print to UI
       
   575     TestModuleIf().Printf( 0, _L("Camtest"), _L("DeleteObjectL") );
       
   576 
       
   577     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Nodename") )->Des() ) ;
       
   578 
       
   579 	SetURIL(nodename) ;
       
   580 
       
   581 	HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   582 	Adapter()->DeleteObjectL( *iURI, *luid, 11 ) ;
       
   583 	if ( iStatus == MSmlDmAdapter::EOk )
       
   584 		{
       
   585 		iLog->Log( _L("DeleteNode: DeleteObjectL Successful! %d" ), iStatus );	
       
   586 		}
       
   587 	else
       
   588 		{
       
   589 		iLog->Log( _L("DeleteNode: DeleteObjectL FetchLeafObjectL Error ! %d" ), iStatus );	
       
   590 		ret = KErrGeneral ;
       
   591 		}
       
   592 	CleanupStack::PopAndDestroy( luid ); // luid
       
   593 	CleanupStack::PopAndDestroy(); // nodename	
       
   594 	iLog->Log( _L("ExecuteLeafDataL Test Complete with status %d" ), ret );	
       
   595 
       
   596     return ret;	
       
   597 }
       
   598 	
       
   599 TInt Cdmatest::ExecuteLeafDataL( CStifItemParser& aItem )		
       
   600 	{
       
   601 	TInt ret( KErrNone );
       
   602 
       
   603     // Print to UI
       
   604     TestModuleIf().Printf( 0, _L("Camtest"), _L("ExecuteLeafL") );
       
   605 
       
   606 	iResultsFunction = NULL;
       
   607 	
       
   608     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Nodename") )->Des() ) ;
       
   609     TPtrC8 data( GetNextStringLC ( aItem, _L("Input data") )->Des() ) ;
       
   610     
       
   611 	SetURIL(nodename) ;
       
   612 
       
   613 		/*
       
   614 			virtual void ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID,
       
   615 							      const TDesC8& aArgument, const TDesC8& aType,
       
   616 								  TInt aStatusRef ) = 0;
       
   617 		*/
       
   618 	HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   619 	Adapter()->ExecuteCommandL( *iURI, *luid, data, KEmptyType, 11 ) ;
       
   620 	if ( iStatus == MSmlDmAdapter::EOk )
       
   621 		{
       
   622 		iLog->Log( _L("ExecuteLeafDataL: ExecuteCommandL Successful! %d" ), iStatus );	
       
   623 		}
       
   624 	else
       
   625 		{
       
   626 		iLog->Log( _L("ExecuteLeafDataL: ExecuteCommandL FetchLeafObjectL Error ! %d" ), iStatus );	
       
   627 		ret = KErrGeneral ;
       
   628 		}
       
   629 	CleanupStack::PopAndDestroy(); // luid
       
   630 	CleanupStack::PopAndDestroy(); // data		
       
   631 	CleanupStack::PopAndDestroy(); // nodename	
       
   632 	iLog->Log( _L("ExecuteLeafDataL Test Complete with status %d" ), ret );	
       
   633 
       
   634     return ret;
       
   635 	}
       
   636 
       
   637 
       
   638 HBufC8 *Cdmatest::LoadFileLC( const TDesC &aFileName, TDataType &aType )	
       
   639 	{
       
   640 	RFs fs ;
       
   641 	LEAVE_IF_ERROR( fs.Connect(), _L( "Could not connect fileserver: %d"  ) );
       
   642 	
       
   643 	CleanupClosePushL( fs );
       
   644 	RFile file ;
       
   645 	LEAVE_IF_ERROR( file.Open(fs,aFileName,EFileRead), _L( "Could not open file: %d" ) );
       
   646 	
       
   647 	
       
   648 	
       
   649 	CleanupClosePushL( file );
       
   650 	TInt dataSize ;
       
   651 	LEAVE_IF_ERROR( file.Size( dataSize ), _L( "Could not get file size: %d" ) );
       
   652 	HBufC8 *nodedata = HBufC8::NewL ( dataSize );
       
   653 	CleanupStack::PushL( nodedata );
       
   654 	TPtr8 nodedataptr( nodedata->Des() );
       
   655 	LEAVE_IF_ERROR( file.Read( nodedataptr ), _L( "Could not read file: %d" ) );
       
   656 	TDataRecognitionResult aDataType;
       
   657 	RApaLsSession ls ;
       
   658 	TInt err( ls.Connect() );
       
   659 	if ( err == KErrNone )
       
   660 		{
       
   661 		CleanupClosePushL( ls );
       
   662 		err = ls.RecognizeData(aFileName, nodedataptr, aDataType)  ;
       
   663 		if ( err == KErrNone )
       
   664 			{
       
   665 			aType = aDataType.iDataType;
       
   666 			}
       
   667 		else
       
   668 			{
       
   669 			iLog->Log( _L("LoadFileLC: WARNING Failed to get type: %d" ), err );
       
   670 			aType = TDataType( KDefaultType );
       
   671 			}	
       
   672 		CleanupStack::PopAndDestroy( &ls ); 
       
   673 		}
       
   674 	else
       
   675 		{
       
   676 		iLog->Log( _L("LoadFileLC: WARNING Failed to connect rapalssession: %d" ), err );
       
   677 		}	
       
   678 	CleanupStack::Pop( nodedata );
       
   679 	CleanupStack::PopAndDestroy( &file ); 
       
   680 	CleanupStack::PopAndDestroy( &fs ); 
       
   681 	CleanupStack::PushL( nodedata );
       
   682 	return nodedata ;
       
   683 	}
       
   684 
       
   685 HBufC8 *Cdmatest::LoadFileLC( const TDesC8 &aFileName, TDataType &aType )	
       
   686 	{
       
   687 	TFileName fn ;
       
   688 	fn.Copy( aFileName );
       
   689 	return LoadFileLC( fn, aType );
       
   690 	}
       
   691 	
       
   692 
       
   693 void Cdmatest::SaveDataL( TInt /*aResultsRef*/, CBufBase& aObject,
       
   694 							  const TDesC8& aType ) 
       
   695 	{
       
   696 	iLog->Log( _L8( "Saving data of type: '%S'" ), &aType );
       
   697 	RFs fs;
       
   698 	User::LeaveIfError( fs.Connect() );
       
   699 	CleanupClosePushL( fs );
       
   700 	RFile file;
       
   701 	User::LeaveIfError( file.Replace ( fs, iSaveFileName, EFileWrite ) );
       
   702 	CleanupClosePushL( file );
       
   703 	TPtrC8 p( aObject.Ptr( 0 ) );
       
   704 	User::LeaveIfError( file.Write( p ) );
       
   705 	CleanupStack::PopAndDestroy( 2 ); // file, fs
       
   706 	}
       
   707 							  
       
   708 		
       
   709 	
       
   710 void Cdmatest::FetchNodeResultsL( TInt /*aResultsRef*/, CBufBase& aObject,
       
   711 							  const TDesC8& /*aType*/ )
       
   712 	{
       
   713 	TPtrC8 ptr( aObject.Ptr( 0 ) );	
       
   714 	iLog->Log( _L8("FetchNodeResultsL for '%S': '%S'" ), iURI, &ptr );
       
   715 	
       
   716 	if ( ptr.Length() > 0 )
       
   717 		{
       
   718 		TPtrC8 last( LastURISeg( ptr ) );
       
   719 		HBufC8 *oldUri = HBufC8::NewL( iURI->Length() );
       
   720 		(*oldUri) = *iURI; 
       
   721 		do 
       
   722 			{
       
   723 			iLog->Log ( _L8( " Node: '%S' "), &last );
       
   724 			HBufC8 *nUri = HBufC8::NewLC( oldUri->Length() + 1 + last.Length() );
       
   725 			nUri->Des().Copy( *oldUri ) ;
       
   726 			nUri->Des().Append( '/' );
       
   727 			nUri->Des().Append( last );
       
   728 			
       
   729 			SetURIL( nUri );
       
   730 			//iResultsFunction = FetchNodeResultsL;
       
   731 			
       
   732 		    //TPtrC8 parentURI(RemoveLastSeg(*nUri));
       
   733 		    //HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   734 		    CleanupStack::Pop( nUri );
       
   735 			
       
   736 			HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   737 			
       
   738 			Adapter()->ChildURIListL( *nUri, KNullDesC8, *iEmptyMappingInfoArray, 4, 5 );//Dipak
       
   739 			
       
   740 			CleanupStack::PopAndDestroy( luid ); 			
       
   741 			
       
   742 			ptr.Set( RemoveLastURISeg( ptr ) );
       
   743 			last.Set( LastURISeg( ptr ) );
       
   744 			
       
   745 			}
       
   746 		while (last != KNullDesC8);	
       
   747 		}
       
   748 	
       
   749 	}
       
   750 	
       
   751 
       
   752 	
       
   753 TPtrC8 Cdmatest::LastURISeg( const TDesC8& aURI )
       
   754 	{
       
   755 	TInt i;
       
   756 	for( i = aURI.Length() - 1; i >= 0; i-- ) 
       
   757 		{
       
   758 		if( aURI[i] == '/' )
       
   759 			{
       
   760 			break;
       
   761 			}
       
   762 		}
       
   763 
       
   764 	if( i == 0 )
       
   765 		{
       
   766 		return aURI;
       
   767 		}
       
   768 	else
       
   769 		{
       
   770 		return aURI.Mid( i+1 );
       
   771 		}
       
   772 	}
       
   773 TPtrC8 Cdmatest::RemoveLastSeg(const TDesC8& aURI)
       
   774 	{
       
   775 	TInt i;
       
   776 	for(i=aURI.Length()-1;i>=0;i--)
       
   777 		{
       
   778 		if(aURI[i]==KNSmlDMUriSeparator)
       
   779 			{
       
   780 			break;
       
   781 			}
       
   782 		}
       
   783 
       
   784 	if(i>0)
       
   785 		{
       
   786 		return aURI.Left(i);
       
   787 		}
       
   788 	else
       
   789 		{
       
   790 		return KNullDesC8();
       
   791 		}
       
   792 	}
       
   793 
       
   794 // ------------------------------------------------------------------------------------------------
       
   795 // TPtrC8 Cdmatest::RemoveLastURISeg(const TDesC8& aURI)
       
   796 // returns parent uri, i.e. removes last uri segment
       
   797 // ------------------------------------------------------------------------------------------------
       
   798 TPtrC8 Cdmatest::RemoveLastURISeg( const TDesC8& aURI )
       
   799 	{
       
   800 	TInt i;
       
   801 	for ( i = aURI.Length() - 1; i >= 0 ; i-- )
       
   802 		{
       
   803 		if( aURI[i] == '/' )
       
   804 			{
       
   805 			break;
       
   806 			}
       
   807 		}
       
   808 	if ( i > -1 )
       
   809 		{
       
   810 		return aURI.Left( i );	
       
   811 		}
       
   812 	else
       
   813 		{
       
   814 		return KNullDesC8();
       
   815 		}
       
   816 	}	
       
   817 	
       
   818 TPtrC Cdmatest::RemoveLastURISeg( const TDesC& aURI )
       
   819 	{
       
   820 	TInt i;
       
   821 	for ( i = aURI.Length() - 1; i >= 0 ; i-- )
       
   822 		{
       
   823 		if( aURI[i] == '/' )
       
   824 			{
       
   825 			break;
       
   826 			}
       
   827 		}
       
   828 	if ( i > -1 )
       
   829 		{
       
   830 		return aURI.Left( i );	
       
   831 		}
       
   832 	else
       
   833 
       
   834 		{
       
   835 		return KNullDesC();
       
   836 		}
       
   837 	}		
       
   838 	
       
   839 void Cdmatest::SetURIL( const TDesC& aURI )
       
   840 	{
       
   841 	if ( iURI != NULL )
       
   842 		{
       
   843 		delete iURI ;
       
   844 		iURI = NULL;
       
   845 		}
       
   846 	iURI = HBufC8::NewL( aURI.Length() ) ;
       
   847 	iURI->Des().Copy( aURI );
       
   848 	}
       
   849 	
       
   850 void Cdmatest::SetURIL( const TDesC8& aURI )
       
   851 	{
       
   852 	if ( iURI != NULL )
       
   853 		{
       
   854 		delete iURI ;
       
   855 		iURI = NULL;
       
   856 		}
       
   857 	iURI = HBufC8::NewL( aURI.Length() ) ;
       
   858 	iURI->Des().Copy( aURI );
       
   859 	}	
       
   860 
       
   861 void Cdmatest::SetURIL( HBufC8* aURI )
       
   862 	{
       
   863 	if ( iURI != NULL )
       
   864 		{
       
   865 		delete iURI ;
       
   866 		iURI = NULL;
       
   867 		}
       
   868 	iURI = aURI ;
       
   869 	}
       
   870 		
       
   871 		
       
   872 		
       
   873 void Cdmatest::SetResultsL( 
       
   874 	TInt aResultsRef, 
       
   875 	CBufBase& aObject,
       
   876 	const TDesC8& aType )
       
   877 	{
       
   878 	TPtrC8 ptr( aObject.Ptr(0) );
       
   879 	iLog->Log( _L8( "SetResults, ref=%d, object='%S', type='%S'" ), aResultsRef, &ptr, &aType );
       
   880 	if ( iResultsFunction )
       
   881 		{
       
   882 		(this->*iResultsFunction)( aResultsRef, aObject, aType );
       
   883 		iResultsFunction = NULL ;
       
   884 		}
       
   885 	
       
   886 	}
       
   887 
       
   888 
       
   889 void Cdmatest::SetStatusL( TInt aStatusRef,
       
   890 							 MSmlDmAdapter::TError aErrorCode ) 
       
   891 	{
       
   892 	iStatus = aErrorCode ;
       
   893 	iLog->Log( _L( "SetStatusL, ref=%d, code=%d" ), aStatusRef, aErrorCode );
       
   894 	
       
   895 	
       
   896 	}
       
   897 	
       
   898 void Cdmatest::SetMappingL( const TDesC8& aURI, const TDesC8& aLUID ) 
       
   899 	{
       
   900 	iLog->Log( _L8( "SetMappingL, aURI='%s', aLUID='%s'" ), aURI.Ptr(), aLUID.Ptr() );	
       
   901 	
       
   902 	iMappingTable.Append(TMapping( aURI, aLUID ) )	;
       
   903 	}
       
   904 	
       
   905 HBufC8* Cdmatest::GetLuidAllocL( const TDesC8& aURI ) 
       
   906 	{
       
   907 	iLog->Log( _L8( "GetLuidAllocL, aURI='%S'" ), &aURI );		
       
   908 	HBufC8 *res = NULL;		
       
   909 	for( TInt i(0); i < iMappingTable.Count(); i++ )	
       
   910 		{
       
   911 		if ( aURI == iMappingTable[i].iURI )
       
   912 			{
       
   913 			res = iMappingTable[i].iLuid.AllocL();
       
   914 			}
       
   915 		}
       
   916 	if ( res == NULL )
       
   917 		{
       
   918 		res = HBufC8::NewL( 0 );
       
   919 		}
       
   920 	iLog->Log( _L8( "GetLuidAllocL, response='%S'" ), res );
       
   921 	return res;
       
   922 	}	    
       
   923     
       
   924 HBufC8* Cdmatest::GetLuidAllocLC( const TDesC8& aURI ) 
       
   925 	{
       
   926 	iLog->Log( _L8( "GetLuidAllocL, aURI='%S'" ), &aURI );
       
   927 	HBufC8 *res = NULL;		
       
   928 	for( TInt i(0); i < iMappingTable.Count(); i++ )	
       
   929 		{
       
   930 		if ( aURI == iMappingTable[i].iURI )
       
   931 			{
       
   932 			res = iMappingTable[i].iLuid.AllocLC();
       
   933 			break;
       
   934 			}
       
   935 		}
       
   936 	if ( res == NULL )
       
   937 		{
       
   938 		res = HBufC8::NewLC( 0 );
       
   939 		}
       
   940 	iLog->Log( _L8( "GetLuidAllocLC, response='%S'" ), res );
       
   941 	return res ;
       
   942 	}	
       
   943     	
       
   944 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   945     
       
   946 void Cdmatest::GetMappingInfoListL( const TDesC8& /*aURI*/,
       
   947 								CArrayFix<TSmlDmMappingInfo>& /*aSegmentList*/ )
       
   948 	{
       
   949 	// do nothing
       
   950 	}								
       
   951 
       
   952 #else
       
   953 // nothing
       
   954 #endif
       
   955 //***************************************************************************
       
   956 //  End of File