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