omadm/omadmextensions/adapters/email/tsrc/src/dmatest.cpp
changeset 18 7d11f9a6646f
parent 4 75a71fdb4c92
child 21 c707676bf59f
equal deleted inserted replaced
4:75a71fdb4c92 18:7d11f9a6646f
     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     	iLog->Log( _L8( "Failed to save mappings!: %d"), err );
       
   180     	}
       
   181     Delete();
       
   182     
       
   183     // Delete logger
       
   184     delete iLog;  
       
   185     delete iEmptyMappingInfoArray;
       
   186     delete iAdapter;
       
   187     delete iURI;
       
   188     iMappingTable.Reset();
       
   189     REComSession::FinalClose();    
       
   190     }
       
   191 
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // Camatest::Delete
       
   195 // Delete here all resources allocated and opened from test methods. 
       
   196 // Called from destructor. 
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void Cdmatest::Delete() 
       
   200     {
       
   201     
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // Cdmatest::?member_function
       
   206 // ?implementation_description
       
   207 // (other items were commented in a header).
       
   208 // -----------------------------------------------------------------------------
       
   209 
       
   210 
       
   211         
       
   212 HBufC8 *Cdmatest::GetNextStringLC ( CStifItemParser& aItem, const TDesC &aName )
       
   213 	{
       
   214 	TPtrC nodename( KNullDesC );
       
   215 
       
   216     TInt i( aItem.GetNextString ( nodename ) );
       
   217     if ( i != KErrNone ) 
       
   218 	    {
       
   219 	    iLog->Log( _L( "ERROR Reading '%S' argument: 0x%X" ), &aName, i );
       
   220 	    }
       
   221 	else
       
   222 		{
       
   223 		iLog->Log( _L("%S: %S"), &aName, &nodename);
       
   224 		}
       
   225 	
       
   226 	HBufC8 *buf = HBufC8::NewLC( nodename.Length() ) ;
       
   227 	buf->Des().Copy( nodename );
       
   228 	return buf;
       
   229 	}
       
   230 	
       
   231 TInt Cdmatest::FetchNodeL( CStifItemParser& aItem )	
       
   232 	{
       
   233 
       
   234     TInt ret( KErrNone );
       
   235     // Print to UI
       
   236     TestModuleIf().Printf( 0, _L("Cdmatest"), _L("FetchNodeL") );
       
   237 
       
   238 	iResultsFunction = FetchNodeResultsL;
       
   239 	
       
   240     TPtrC8 nodename( GetNextStringLC( aItem, _L(" nodename" ) )->Des() ) ;
       
   241 		
       
   242 	SetURIL(nodename) ;//
       
   243 	HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   244 
       
   245 	Adapter()->ChildURIListL( *iURI, *luid, *iEmptyMappingInfoArray, 4, 5) ;
       
   246 
       
   247 	if ( iStatus == MSmlDmAdapter::EOk )
       
   248 		{
       
   249 		}
       
   250 	else
       
   251 		{
       
   252 		iLog->Log( _L("FetchNodeL: ChildUriList Error ! %d" ), iStatus );	
       
   253 		ret = KErrGeneral ;
       
   254 		}
       
   255 	CleanupStack::PopAndDestroy( luid ) ; 
       
   256 	CleanupStack::PopAndDestroy() ; // nodename
       
   257 	iLog->Log( _L("FetchNodeL: Test Complete with status %d" ), ret );	
       
   258 
       
   259     return ret;
       
   260 	}
       
   261 	
       
   262 TInt Cdmatest::StartAtomicL( CStifItemParser& /*aItem*/ )	
       
   263 	{
       
   264 	TRAPD( err, Adapter()->StartAtomicL() ) ;
       
   265 	iLog->Log( _L("StartAtomicL: Atomic started resulting error %d" ), err );	
       
   266     return err;
       
   267 	}
       
   268 
       
   269 TInt Cdmatest::RollbackAtomicL( CStifItemParser& /*aItem*/ )	
       
   270 	{
       
   271 	TRAPD( err, Adapter()->RollbackAtomicL() ) ;
       
   272 	iLog->Log( _L("RollbackAtomicL: Atomic rolled back resulting error %d" ), err );	
       
   273     return err;
       
   274 	}
       
   275 	
       
   276 TInt Cdmatest::CommitAtomicL( CStifItemParser& /*aItem*/ )	
       
   277 	{
       
   278 	TRAPD( err, Adapter()->CommitAtomicL() ) ;
       
   279 	iLog->Log( _L("RollbackAtomicL: Atomic commited resulting error %d" ), err );	
       
   280     return err;
       
   281 	}
       
   282 	
       
   283 
       
   284 TInt Cdmatest::DDFStructureL( CStifItemParser& /*aItem*/ )	
       
   285 	{
       
   286 	CTestDmDDFObject* ddfRoot = CTestDmDDFObject::NewLC( iLog ); //, aNodeName );
       
   287 
       
   288 	TRAPD( err, iAdapter->DDFStructureL( *ddfRoot ) ) ;
       
   289 	CleanupStack::PopAndDestroy( ddfRoot );
       
   290 	iLog->Log( _L("DDFStructureL: method called resulting error %d" ), err );	
       
   291     return err;
       
   292 	}
       
   293 		
       
   294 		
       
   295 TInt Cdmatest::AddNodeL( CStifItemParser& aItem )	
       
   296 	{
       
   297 
       
   298     TInt ret( KErrNone );
       
   299     // Print to UI
       
   300     TestModuleIf().Printf( 0, _L("Cdmatest"), _L("AddNodeL") );
       
   301 
       
   302     
       
   303     TPtrC8 nodename( GetNextStringLC ( aItem, _L("nodename" ) )->Des() ) ;
       
   304     SetURIL( nodename );
       
   305 
       
   306 	Adapter()->AddNodeObjectL( *iURI, KEmptyType, 8 ) ;
       
   307 	
       
   308 	if ( iStatus == MSmlDmAdapter::EOk )
       
   309 		{
       
   310 		iLog->Log( _L("AddNodeL: AddNodeObjectL Successful! %d" ), iStatus );	
       
   311 		}
       
   312 	else
       
   313 		{
       
   314 		iLog->Log( _L("AddNodeL: AddNodeObjectL Error ! %d" ), iStatus );	
       
   315 		ret = KErrGeneral ;
       
   316 		}
       
   317 		
       
   318 	CleanupStack::PopAndDestroy() ; // nodename
       
   319 	iLog->Log( _L("AddNodeL Test Complete with status %d" ), ret );	
       
   320 
       
   321     return ret;
       
   322 	}	
       
   323 		
       
   324 TInt Cdmatest::UpdateLeafL( CStifItemParser& aItem )	
       
   325 	{
       
   326 
       
   327     TInt ret( KErrNone );
       
   328     // Print to UI
       
   329     TestModuleIf().Printf( 0, _L("Cdmatest"), _L("UpdateLeafL") );
       
   330 
       
   331     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Node name") )->Des() ) ;
       
   332     TPtrC8 data (GetNextStringLC( aItem, _L("datafile"))->Des() );
       
   333     
       
   334 	HBufC8 *mime = GetNextStringLC( aItem, _L("mime") ) ;
       
   335     SetURIL( nodename );
       
   336     
       
   337     TPtrC8 parentURI(RemoveLastSeg(nodename));
       
   338     HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   339     
       
   340     TDataType type; 
       
   341 
       
   342 	TPtrC8 mimePtr( *mime == KNullDesC8 ? type.Des8() : mime->Des() );
       
   343 
       
   344     /**
       
   345     virtual void UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID,
       
   346 									const TDesC8& aObject, const TDesC8& aType,
       
   347 									TInt aStatusRef ) = 0;
       
   348     */
       
   349     
       
   350 	Adapter()->UpdateLeafObjectL( *iURI , *luid, data, mimePtr, 3);
       
   351 
       
   352 	if ( iStatus == MSmlDmAdapter::EOk )
       
   353 	{
       
   354 		iLog->Log( _L("UpdateLeafL: UpdateLeafObjectL Successful! %d" ), iStatus );	
       
   355 	}
       
   356 	else
       
   357 	{
       
   358 		iLog->Log( _L("UpdateLeafL UpdateLeafObjectL Error ! %d" ), iStatus );	
       
   359 		ret = KErrGeneral ;
       
   360 	}
       
   361 
       
   362 	CleanupStack::PopAndDestroy(); // loadfile
       
   363 	CleanupStack::PopAndDestroy(); // luid
       
   364 	CleanupStack::PopAndDestroy(); // mime
       
   365 	CleanupStack::PopAndDestroy(); // nodename
       
   366 
       
   367 	iLog->Log( _L("UpdateLeafL Test Complete with status %d" ), ret );	
       
   368 
       
   369     return ret;
       
   370 	}	
       
   371 	
       
   372 
       
   373 TInt Cdmatest::UpdateLeafDataURLL( CStifItemParser& aItem )	
       
   374 	{
       
   375 
       
   376     TInt ret( KErrNone );
       
   377     // Print to UI
       
   378     TestModuleIf().Printf( 0, _L("Cdmatest"), _L("UpdateLeafDataL") );
       
   379 
       
   380     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Node name") )->Des() ) ;
       
   381     TPtrC8 http (GetNextStringLC( aItem, _L("http"))->Des() );
       
   382     TPtrC8 url (GetNextStringLC( aItem, _L("rest of url"))->Des() );
       
   383 	HBufC8 *mime = GetNextStringLC( aItem, _L("mime") ) ;
       
   384     SetURIL( nodename );
       
   385     
       
   386     _LIT8( KTag, "://" );
       
   387     
       
   388     HBufC8 *fullurl = HBufC8::NewLC( http.Length() + KTag().Length() + url.Length() );
       
   389     TPtr8 pfullurl( fullurl->Des() );
       
   390     pfullurl.Copy( http ) ;
       
   391     pfullurl.Append( KTag );
       
   392     pfullurl.Append( url );
       
   393     TPtrC8 mimePtr( *mime == KNullDesC8 ? KDefaultType() : mime->Des() );
       
   394     
       
   395     HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   396     /**
       
   397     virtual void UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID,
       
   398 									const TDesC8& aObject, const TDesC8& aType,
       
   399 									TInt aStatusRef ) = 0;
       
   400     */
       
   401 	Adapter()->UpdateLeafObjectL( *iURI , *luid, pfullurl, mimePtr, 3);
       
   402 	if ( iStatus == MSmlDmAdapter::EOk )
       
   403 		{
       
   404 		iLog->Log( _L("UpdateLeafDataL: UpdateLeafObjectL Successful! %d" ), iStatus );	
       
   405 		}
       
   406 	else
       
   407 		{
       
   408 		iLog->Log( _L("UpdateLeafDataL UpdateLeafObjectL Error ! %d" ), iStatus );	
       
   409 		ret = KErrGeneral ;
       
   410 		}
       
   411 	CleanupStack::PopAndDestroy( luid ); // 
       
   412 	CleanupStack::PopAndDestroy( mime ); // mime
       
   413 	CleanupStack::PopAndDestroy(); // url
       
   414 	CleanupStack::PopAndDestroy(); // http
       
   415 	CleanupStack::PopAndDestroy(); // nodename
       
   416 	iLog->Log( _L("UpdateLeafDataL Test Complete with status %d" ), ret );	
       
   417 
       
   418     return ret;
       
   419 	}
       
   420     
       
   421 TInt Cdmatest::UpdateLeafDataL( CStifItemParser& aItem )	
       
   422 	{
       
   423 
       
   424     TInt ret( KErrNone );
       
   425     // Print to UI
       
   426    TestModuleIf().Printf( 0, _L("Camtest"), _L("UpdateLeafDataL") );
       
   427 
       
   428     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Node name") )->Des() ) ;
       
   429     TPtrC8 data (GetNextStringLC( aItem, _L("data"))->Des() );
       
   430 	HBufC8 *mime = GetNextStringLC( aItem, _L("mime") ) ;
       
   431 	
       
   432     SetURIL( nodename );
       
   433     
       
   434         
       
   435     TPtrC8 mimePtr( *mime == KNullDesC8 ? KDefaultType() : mime->Des() );
       
   436     
       
   437     TPtrC8 parentURI(RemoveLastSeg(nodename));
       
   438     HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   439      
       
   440 //    
       
   441 //    virtual void UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID,
       
   442 //									const TDesC8& aObject, const TDesC8& aType,
       
   443 //									TInt aStatusRef ) = 0;
       
   444 //   
       
   445 	Adapter()->UpdateLeafObjectL( *iURI , *luid, data, mimePtr, 3);
       
   446 	if ( iStatus == MSmlDmAdapter::EOk )
       
   447 		{
       
   448 		iLog->Log( _L("UpdateLeafDataL: UpdateLeafObjectL Successful! %d" ), iStatus );	
       
   449 		}
       
   450 	else
       
   451 		{
       
   452 		iLog->Log( _L("UpdateLeafDataL UpdateLeafObjectL Error ! %d" ), iStatus );	
       
   453 		ret = KErrGeneral ;
       
   454 		}
       
   455 	
       
   456 	CleanupStack::PopAndDestroy(); // mime
       
   457 	CleanupStack::PopAndDestroy(); // luid
       
   458 	CleanupStack::PopAndDestroy(); // data
       
   459 	CleanupStack::PopAndDestroy(); // nodename
       
   460 	iLog->Log( _L("UpdateLeafDataL Test Complete with status %d" ), ret );	
       
   461 
       
   462     return ret;
       
   463 	}	
       
   464 			
       
   465 TInt Cdmatest::FetchLeafL( CStifItemParser& aItem )	
       
   466 	{
       
   467 
       
   468     TInt ret( KErrNone );
       
   469     // Print to UI
       
   470     TestModuleIf().Printf( 0, _L("Camtest"), _L("FetchLeafL") );
       
   471 
       
   472 	iResultsFunction = NULL;
       
   473 	
       
   474     TInt i( 0 );
       
   475     TPtrC8 nodename ( GetNextStringLC( aItem, _L( "nodename" ) )->Des() ) ;
       
   476     
       
   477     //TPtrC datafile;
       
   478     TPtrC datafile( KNullDesC );
       
   479     i = aItem.GetNextString ( datafile ) ;
       
   480     if ( i != KErrNone ) 
       
   481 	    {
       
   482 	    iLog->Log(_L("FetchLeafL: ERROR Reading outfile argument: 0x%X"), i );
       
   483 	    //return i;
       
   484 	    }
       
   485 	else
       
   486 		{
       
   487 		iSaveFileName = datafile;
       
   488 		iLog->Log( _L( " Save file nameis '%S'" ), &iSaveFileName );
       
   489 		iResultsFunction = SaveDataL;
       
   490 		}
       
   491     
       
   492 	SetURIL(nodename) ;
       
   493 		
       
   494 		/*
       
   495 			void FetchLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID,
       
   496 								   const TDesC8& aType, TInt aResultsRef,
       
   497 								   TInt aStatusRef );
       
   498 		*/
       
   499     TPtrC8 parentURI(RemoveLastSeg(nodename));
       
   500     HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   501 
       
   502 	Adapter()->FetchLeafObjectL( *iURI, *luid, KEmptyType, 7, 8 ) ;
       
   503 	if ( iStatus == MSmlDmAdapter::EOk )
       
   504 		{
       
   505 		iLog->Log( _L("FetchLeafL: FetchLeafObjectL Successful! %d" ), iStatus );	
       
   506 		}
       
   507 	else
       
   508 		{
       
   509 		iLog->Log( _L("FetchLeafL: FetchLeafObjectL Error ! %d" ), iStatus );	
       
   510 		ret = KErrGeneral ;
       
   511 		}
       
   512 	CleanupStack::PopAndDestroy( luid );
       
   513 	CleanupStack::PopAndDestroy(  ); // nodename
       
   514 	iLog->Log( _L("FetchLeafL Test Complete with status %d" ), ret );	
       
   515     return ret;
       
   516 	}	
       
   517 
       
   518 
       
   519 TInt Cdmatest::ExecuteLeafL( CStifItemParser& aItem )		
       
   520 	{
       
   521 	TInt ret( KErrNone );
       
   522     // Print to UI
       
   523     TestModuleIf().Printf( 0, _L("Camtest"), _L("ExecuteLeafL") );
       
   524 
       
   525 	iResultsFunction = NULL;
       
   526 	
       
   527     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Nodename") )->Des() ) ;
       
   528     TPtrC8 data( GetNextStringLC ( aItem, _L("Input file") )->Des() ) ;
       
   529 	
       
   530 	SetURIL(nodename) ;
       
   531 
       
   532 		/*
       
   533 			virtual void ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID,
       
   534 							      const TDesC8& aArgument, const TDesC8& aType,
       
   535 								  TInt aStatusRef ) = 0;
       
   536 		*/
       
   537 	TDataType type;
       
   538 	
       
   539     TPtrC8 parentURI(RemoveLastSeg(nodename));
       
   540     HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   541 
       
   542 	Adapter()->ExecuteCommandL( *iURI, *luid, data, KEmptyType, 11 ) ;
       
   543 	if ( iStatus == MSmlDmAdapter::EOk )
       
   544 		{
       
   545 		iLog->Log( _L("ExecuteLeafL: ExecuteCommandL Successful! %d" ), iStatus );	
       
   546 		}
       
   547 	else
       
   548 		{
       
   549 		iLog->Log( _L("ExecuteLeafL: ExecuteCommandL FetchLeafObjectL Error ! %d" ), iStatus );	
       
   550 		ret = KErrGeneral ;
       
   551 		}
       
   552 	CleanupStack::PopAndDestroy( luid ); // luid
       
   553 	CleanupStack::PopAndDestroy(); // data
       
   554 	CleanupStack::PopAndDestroy(); // nodename
       
   555 	
       
   556 	iLog->Log( _L("ExecuteLeafL: Test Complete with status %d" ), ret );	
       
   557 
       
   558     return ret;
       
   559 	}
       
   560 	
       
   561 TInt Cdmatest::CompleteCommandsL( CStifItemParser& /*aItem*/ )
       
   562 	{
       
   563 	TRAPD( err, Adapter()->CompleteOutstandingCmdsL() );
       
   564 	delete iAdapter;
       
   565 	iAdapter = NULL;
       
   566 	return err;
       
   567 	}
       
   568 TInt Cdmatest::DeleteObjectL( CStifItemParser& aItem )
       
   569 {
       
   570 	TInt ret( KErrNone );
       
   571     // Print to UI
       
   572     TestModuleIf().Printf( 0, _L("Camtest"), _L("DeleteObjectL") );
       
   573 
       
   574     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Nodename") )->Des() ) ;
       
   575 
       
   576 	SetURIL(nodename) ;
       
   577 
       
   578 	HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   579 	Adapter()->DeleteObjectL( *iURI, *luid, 11 ) ;
       
   580 	if ( iStatus == MSmlDmAdapter::EOk )
       
   581 		{
       
   582 		iLog->Log( _L("DeleteNode: DeleteObjectL Successful! %d" ), iStatus );	
       
   583 		}
       
   584 	else
       
   585 		{
       
   586 		iLog->Log( _L("DeleteNode: DeleteObjectL FetchLeafObjectL Error ! %d" ), iStatus );	
       
   587 		ret = KErrGeneral ;
       
   588 		}
       
   589 	CleanupStack::PopAndDestroy( luid ); // luid
       
   590 	CleanupStack::PopAndDestroy(); // nodename	
       
   591 	iLog->Log( _L("ExecuteLeafDataL Test Complete with status %d" ), ret );	
       
   592 
       
   593     return ret;	
       
   594 }
       
   595 	
       
   596 TInt Cdmatest::ExecuteLeafDataL( CStifItemParser& aItem )		
       
   597 	{
       
   598 	TInt ret( KErrNone );
       
   599 
       
   600     // Print to UI
       
   601     TestModuleIf().Printf( 0, _L("Camtest"), _L("ExecuteLeafL") );
       
   602 
       
   603 	iResultsFunction = NULL;
       
   604 	
       
   605     TPtrC8 nodename( GetNextStringLC ( aItem, _L("Nodename") )->Des() ) ;
       
   606     TPtrC8 data( GetNextStringLC ( aItem, _L("Input data") )->Des() ) ;
       
   607     
       
   608 	SetURIL(nodename) ;
       
   609 
       
   610 		/*
       
   611 			virtual void ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID,
       
   612 							      const TDesC8& aArgument, const TDesC8& aType,
       
   613 								  TInt aStatusRef ) = 0;
       
   614 		*/
       
   615 	HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   616 	Adapter()->ExecuteCommandL( *iURI, *luid, data, KEmptyType, 11 ) ;
       
   617 	if ( iStatus == MSmlDmAdapter::EOk )
       
   618 		{
       
   619 		iLog->Log( _L("ExecuteLeafDataL: ExecuteCommandL Successful! %d" ), iStatus );	
       
   620 		}
       
   621 	else
       
   622 		{
       
   623 		iLog->Log( _L("ExecuteLeafDataL: ExecuteCommandL FetchLeafObjectL Error ! %d" ), iStatus );	
       
   624 		ret = KErrGeneral ;
       
   625 		}
       
   626 	CleanupStack::PopAndDestroy(); // luid
       
   627 	CleanupStack::PopAndDestroy(); // data		
       
   628 	CleanupStack::PopAndDestroy(); // nodename	
       
   629 	iLog->Log( _L("ExecuteLeafDataL Test Complete with status %d" ), ret );	
       
   630 
       
   631     return ret;
       
   632 	}
       
   633 
       
   634 
       
   635 HBufC8 *Cdmatest::LoadFileLC( const TDesC &aFileName, TDataType &aType )	
       
   636 	{
       
   637 	RFs fs ;
       
   638 	LEAVE_IF_ERROR( fs.Connect(), _L( "Could not connect fileserver: %d"  ) );
       
   639 	
       
   640 	CleanupClosePushL( fs );
       
   641 	RFile file ;
       
   642 	LEAVE_IF_ERROR( file.Open(fs,aFileName,EFileRead), _L( "Could not open file: %d" ) );
       
   643 	
       
   644 	
       
   645 	
       
   646 	CleanupClosePushL( file );
       
   647 	TInt dataSize ;
       
   648 	LEAVE_IF_ERROR( file.Size( dataSize ), _L( "Could not get file size: %d" ) );
       
   649 	HBufC8 *nodedata = HBufC8::NewL ( dataSize );
       
   650 	CleanupStack::PushL( nodedata );
       
   651 	TPtr8 nodedataptr( nodedata->Des() );
       
   652 	LEAVE_IF_ERROR( file.Read( nodedataptr ), _L( "Could not read file: %d" ) );
       
   653 	TDataRecognitionResult aDataType;
       
   654 	RApaLsSession ls ;
       
   655 	TInt err( ls.Connect() );
       
   656 	if ( err == KErrNone )
       
   657 		{
       
   658 		CleanupClosePushL( ls );
       
   659 		err = ls.RecognizeData(aFileName, nodedataptr, aDataType)  ;
       
   660 		if ( err == KErrNone )
       
   661 			{
       
   662 			aType = aDataType.iDataType;
       
   663 			}
       
   664 		else
       
   665 			{
       
   666 			iLog->Log( _L("LoadFileLC: WARNING Failed to get type: %d" ), err );
       
   667 			aType = TDataType( KDefaultType );
       
   668 			}	
       
   669 		CleanupStack::PopAndDestroy( &ls ); 
       
   670 		}
       
   671 	else
       
   672 		{
       
   673 		iLog->Log( _L("LoadFileLC: WARNING Failed to connect rapalssession: %d" ), err );
       
   674 		}	
       
   675 	CleanupStack::Pop( nodedata );
       
   676 	CleanupStack::PopAndDestroy( &file ); 
       
   677 	CleanupStack::PopAndDestroy( &fs ); 
       
   678 	CleanupStack::PushL( nodedata );
       
   679 	return nodedata ;
       
   680 	}
       
   681 
       
   682 HBufC8 *Cdmatest::LoadFileLC( const TDesC8 &aFileName, TDataType &aType )	
       
   683 	{
       
   684 	TFileName fn ;
       
   685 	fn.Copy( aFileName );
       
   686 	return LoadFileLC( fn, aType );
       
   687 	}
       
   688 	
       
   689 
       
   690 void Cdmatest::SaveDataL( TInt /*aResultsRef*/, CBufBase& aObject,
       
   691 							  const TDesC8& aType ) 
       
   692 	{
       
   693 	iLog->Log( _L8( "Saving data of type: '%S'" ), &aType );
       
   694 	RFs fs;
       
   695 	User::LeaveIfError( fs.Connect() );
       
   696 	CleanupClosePushL( fs );
       
   697 	RFile file;
       
   698 	User::LeaveIfError( file.Replace ( fs, iSaveFileName, EFileWrite ) );
       
   699 	CleanupClosePushL( file );
       
   700 	TPtrC8 p( aObject.Ptr( 0 ) );
       
   701 	User::LeaveIfError( file.Write( p ) );
       
   702 	CleanupStack::PopAndDestroy( 2 ); // file, fs
       
   703 	}
       
   704 							  
       
   705 		
       
   706 	
       
   707 void Cdmatest::FetchNodeResultsL( TInt /*aResultsRef*/, CBufBase& aObject,
       
   708 							  const TDesC8& /*aType*/ )
       
   709 	{
       
   710 	TPtrC8 ptr( aObject.Ptr( 0 ) );	
       
   711 	iLog->Log( _L8("FetchNodeResultsL for '%S': '%S'" ), iURI, &ptr );
       
   712 	
       
   713 	if ( ptr.Length() > 0 )
       
   714 		{
       
   715 		TPtrC8 last( LastURISeg( ptr ) );
       
   716 		HBufC8 *oldUri = HBufC8::NewL( iURI->Length() );
       
   717 		(*oldUri) = *iURI; 
       
   718 		do 
       
   719 			{
       
   720 			iLog->Log ( _L8( " Node: '%S' "), &last );
       
   721 			HBufC8 *nUri = HBufC8::NewLC( oldUri->Length() + 1 + last.Length() );
       
   722 			nUri->Des().Copy( *oldUri ) ;
       
   723 			nUri->Des().Append( '/' );
       
   724 			nUri->Des().Append( last );
       
   725 			
       
   726 			SetURIL( nUri );
       
   727 			//iResultsFunction = FetchNodeResultsL;
       
   728 			
       
   729 		    //TPtrC8 parentURI(RemoveLastSeg(*nUri));
       
   730 		    //HBufC8 *luid = GetLuidAllocLC( parentURI );
       
   731 		    CleanupStack::Pop( nUri );
       
   732 			
       
   733 			HBufC8 *luid = GetLuidAllocLC( *iURI );
       
   734 			
       
   735 			Adapter()->ChildURIListL( *nUri, KNullDesC8, *iEmptyMappingInfoArray, 4, 5 );//Dipak
       
   736 			
       
   737 			CleanupStack::PopAndDestroy( luid ); 			
       
   738 			
       
   739 			ptr.Set( RemoveLastURISeg( ptr ) );
       
   740 			last.Set( LastURISeg( ptr ) );
       
   741 			
       
   742 			}
       
   743 		while (last != KNullDesC8);	
       
   744 		}
       
   745 	
       
   746 	}
       
   747 	
       
   748 
       
   749 	
       
   750 TPtrC8 Cdmatest::LastURISeg( const TDesC8& aURI )
       
   751 	{
       
   752 	TInt i;
       
   753 	for( i = aURI.Length() - 1; i >= 0; i-- ) 
       
   754 		{
       
   755 		if( aURI[i] == '/' )
       
   756 			{
       
   757 			break;
       
   758 			}
       
   759 		}
       
   760 
       
   761 	if( i == 0 )
       
   762 		{
       
   763 		return aURI;
       
   764 		}
       
   765 	else
       
   766 		{
       
   767 		return aURI.Mid( i+1 );
       
   768 		}
       
   769 	}
       
   770 TPtrC8 Cdmatest::RemoveLastSeg(const TDesC8& aURI)
       
   771 	{
       
   772 	TInt i;
       
   773 	for(i=aURI.Length()-1;i>=0;i--)
       
   774 		{
       
   775 		if(aURI[i]==KNSmlDMUriSeparator)
       
   776 			{
       
   777 			break;
       
   778 			}
       
   779 		}
       
   780 
       
   781 	if(i>0)
       
   782 		{
       
   783 		return aURI.Left(i);
       
   784 		}
       
   785 	else
       
   786 		{
       
   787 		return KNullDesC8();
       
   788 		}
       
   789 	}
       
   790 
       
   791 // ------------------------------------------------------------------------------------------------
       
   792 // TPtrC8 Cdmatest::RemoveLastURISeg(const TDesC8& aURI)
       
   793 // returns parent uri, i.e. removes last uri segment
       
   794 // ------------------------------------------------------------------------------------------------
       
   795 TPtrC8 Cdmatest::RemoveLastURISeg( const TDesC8& aURI )
       
   796 	{
       
   797 	TInt i;
       
   798 	for ( i = aURI.Length() - 1; i >= 0 ; i-- )
       
   799 		{
       
   800 		if( aURI[i] == '/' )
       
   801 			{
       
   802 			break;
       
   803 			}
       
   804 		}
       
   805 	if ( i > -1 )
       
   806 		{
       
   807 		return aURI.Left( i );	
       
   808 		}
       
   809 	else
       
   810 		{
       
   811 		return KNullDesC8();
       
   812 		}
       
   813 	}	
       
   814 	
       
   815 TPtrC Cdmatest::RemoveLastURISeg( const TDesC& aURI )
       
   816 	{
       
   817 	TInt i;
       
   818 	for ( i = aURI.Length() - 1; i >= 0 ; i-- )
       
   819 		{
       
   820 		if( aURI[i] == '/' )
       
   821 			{
       
   822 			break;
       
   823 			}
       
   824 		}
       
   825 	if ( i > -1 )
       
   826 		{
       
   827 		return aURI.Left( i );	
       
   828 		}
       
   829 	else
       
   830 
       
   831 		{
       
   832 		return KNullDesC();
       
   833 		}
       
   834 	}		
       
   835 	
       
   836 void Cdmatest::SetURIL( const TDesC& aURI )
       
   837 	{
       
   838 	if ( iURI != NULL )
       
   839 		{
       
   840 		delete iURI ;
       
   841 		iURI = NULL;
       
   842 		}
       
   843 	iURI = HBufC8::NewL( aURI.Length() ) ;
       
   844 	iURI->Des().Copy( aURI );
       
   845 	}
       
   846 	
       
   847 void Cdmatest::SetURIL( const TDesC8& aURI )
       
   848 	{
       
   849 	if ( iURI != NULL )
       
   850 		{
       
   851 		delete iURI ;
       
   852 		iURI = NULL;
       
   853 		}
       
   854 	iURI = HBufC8::NewL( aURI.Length() ) ;
       
   855 	iURI->Des().Copy( aURI );
       
   856 	}	
       
   857 
       
   858 void Cdmatest::SetURIL( HBufC8* aURI )
       
   859 	{
       
   860 	if ( iURI != NULL )
       
   861 		{
       
   862 		delete iURI ;
       
   863 		iURI = NULL;
       
   864 		}
       
   865 	iURI = aURI ;
       
   866 	}
       
   867 		
       
   868 		
       
   869 		
       
   870 void Cdmatest::SetResultsL( 
       
   871 	TInt aResultsRef, 
       
   872 	CBufBase& aObject,
       
   873 	const TDesC8& aType )
       
   874 	{
       
   875 	TPtrC8 ptr( aObject.Ptr(0) );
       
   876 	iLog->Log( _L8( "SetResults, ref=%d, object='%S', type='%S'" ), aResultsRef, &ptr, &aType );
       
   877 	if ( iResultsFunction )
       
   878 		{
       
   879 		(this->*iResultsFunction)( aResultsRef, aObject, aType );
       
   880 		iResultsFunction = NULL ;
       
   881 		}
       
   882 	
       
   883 	}
       
   884 
       
   885 
       
   886 void Cdmatest::SetStatusL( TInt aStatusRef,
       
   887 							 MSmlDmAdapter::TError aErrorCode ) 
       
   888 	{
       
   889 	iStatus = aErrorCode ;
       
   890 	iLog->Log( _L( "SetStatusL, ref=%d, code=%d" ), aStatusRef, aErrorCode );
       
   891 	
       
   892 	
       
   893 	}
       
   894 	
       
   895 void Cdmatest::SetMappingL( const TDesC8& aURI, const TDesC8& aLUID ) 
       
   896 	{
       
   897 	iLog->Log( _L8( "SetMappingL, aURI='%s', aLUID='%s'" ), aURI.Ptr(), aLUID.Ptr() );	
       
   898 	
       
   899 	iMappingTable.Append(TMapping( aURI, aLUID ) )	;
       
   900 	}
       
   901 	
       
   902 HBufC8* Cdmatest::GetLuidAllocL( const TDesC8& aURI ) 
       
   903 	{
       
   904 	iLog->Log( _L8( "GetLuidAllocL, aURI='%S'" ), &aURI );		
       
   905 	HBufC8 *res = NULL;		
       
   906 	for( TInt i(0); i < iMappingTable.Count(); i++ )	
       
   907 		{
       
   908 		if ( aURI == iMappingTable[i].iURI )
       
   909 			{
       
   910 			res = iMappingTable[i].iLuid.AllocL();
       
   911 			}
       
   912 		}
       
   913 	if ( res == NULL )
       
   914 		{
       
   915 		res = HBufC8::NewL( 0 );
       
   916 		}
       
   917 	iLog->Log( _L8( "GetLuidAllocL, response='%S'" ), res );
       
   918 	return res;
       
   919 	}	    
       
   920     
       
   921 HBufC8* Cdmatest::GetLuidAllocLC( const TDesC8& aURI ) 
       
   922 	{
       
   923 	iLog->Log( _L8( "GetLuidAllocL, aURI='%S'" ), &aURI );
       
   924 	HBufC8 *res = NULL;		
       
   925 	for( TInt i(0); i < iMappingTable.Count(); i++ )	
       
   926 		{
       
   927 		if ( aURI == iMappingTable[i].iURI )
       
   928 			{
       
   929 			res = iMappingTable[i].iLuid.AllocLC();
       
   930 			break;
       
   931 			}
       
   932 		}
       
   933 	if ( res == NULL )
       
   934 		{
       
   935 		res = HBufC8::NewLC( 0 );
       
   936 		}
       
   937 	iLog->Log( _L8( "GetLuidAllocLC, response='%S'" ), res );
       
   938 	return res ;
       
   939 	}	
       
   940     	
       
   941 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   942     
       
   943 void Cdmatest::GetMappingInfoListL( const TDesC8& /*aURI*/,
       
   944 								CArrayFix<TSmlDmMappingInfo>& /*aSegmentList*/ )
       
   945 	{
       
   946 	// do nothing
       
   947 	}								
       
   948 
       
   949 #else
       
   950 // nothing
       
   951 #endif
       
   952 //***************************************************************************
       
   953 //  End of File