uifw/AvKon/tsrc/bc/bctestlauncher/src/bctestconf.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 0 2f259fa3e83a
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Test case.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32cmn.h>
       
    20 #include "bctestconf.h"
       
    21 #include "bcteststrmlogger.h"
       
    22 
       
    23 const int KMaxLength = 255;
       
    24 
       
    25 _LIT( KConfFile, "c:\\bctestlog\\config.xml" );
       
    26 _LIT( KTag, "ITEM");
       
    27 _LIT( KName, "NAME");
       
    28 _LIT( KAppUID, "APPUID");
       
    29 _LIT( KViewUID, "VIEWUID");
       
    30 _LIT( KTimeout, "TIMEOUT");
       
    31 _LIT( KVersion, "VER");
       
    32 
       
    33 _LIT( KLess, "<");
       
    34 _LIT( KLessSlash, "</");
       
    35 _LIT( KGreater, ">");
       
    36 
       
    37 _LIT( KCDataBegin, "<![CDATA[" );
       
    38 _LIT( KCDataEnd, "]]>" );
       
    39 
       
    40 //
       
    41 // helper class
       
    42 //
       
    43 struct XMLUtil
       
    44     {
       
    45 	static TPtrC ExtractField( const TDesC& aLine, const TDesC& aName );
       
    46 	static TPtrC ExtractCData( const TDesC& aLine );
       
    47 
       
    48 	static TPtrC StartField( const TDesC& aName );
       
    49 	static TPtrC EndField( const TDesC& aName );
       
    50 
       
    51 	static TInt  StringToHex( const TDesC& aStr );
       
    52 	static TInt  StringToDec( const TDesC& aStr );
       
    53     };
       
    54 
       
    55 // ======== MEMBER FUNCTIONS ========
       
    56 
       
    57 TInt XMLUtil::StringToHex( const TDesC& aStr )
       
    58     {
       
    59 	//ex. 0x101F84E0
       
    60 	_LIT( KHexPrefix, "0X" );
       
    61 	TBuf < KMaxLength > str( aStr );
       
    62 	str.UpperCase();
       
    63 	TInt res = 0;
       
    64 	
       
    65 	if( str.Find( KHexPrefix ) == KErrNotFound )
       
    66 		return 0;
       
    67 
       
    68 	for( TInt i = 2; i < str.Length(); ++i )
       
    69 	    {
       
    70 		if( TChar( str[i] ).IsDigit() )
       
    71 		    {
       
    72 			res = ( res << 4 ) + str[i] - '0';
       
    73 		    }
       
    74 		else
       
    75 		    {
       
    76 			res = ( res << 4 ) + str[i] - 'A' + 10;
       
    77 		    }
       
    78 	    }
       
    79 	return res;
       
    80     }
       
    81 
       
    82 TInt XMLUtil::StringToDec( const TDesC& aStr )
       
    83     {
       
    84 	//ex. 127
       
    85 	TLex lex(aStr);
       
    86 	TInt res=0;
       
    87 	return lex.Val( res )==KErrNone ? res : 0;
       
    88     }
       
    89 
       
    90 TPtrC XMLUtil::ExtractField( const TDesC& aLine, const TDesC& aName )
       
    91     {
       
    92 	TBuf<KMaxLength> endTag( KLessSlash );	// endTag := </aName>
       
    93 	endTag += aName;
       
    94 	endTag += KGreater;
       
    95 
       
    96 	TInt posBegin = aName.Length()+2;			//"<aName>" length
       
    97 	TInt posEnd   = aLine.Find( endTag );
       
    98 	return ExtractCData( aLine.Mid( posBegin, ( posEnd-posBegin ) ) );
       
    99     }
       
   100 
       
   101 TPtrC XMLUtil::ExtractCData( const TDesC& aLine )
       
   102     {
       
   103 	TInt posBegin = KCDataBegin().Length();
       
   104 	TInt posEnd   = aLine.Find( KCDataEnd );
       
   105 	return aLine.Mid( posBegin, ( posEnd - posBegin ) );
       
   106     }
       
   107 
       
   108 TPtrC XMLUtil::StartField( const TDesC& aName ) 
       
   109     {
       
   110 	TBuf<KMaxLength> res( KLess );
       
   111 	res += aName;
       
   112 	res += KGreater;
       
   113 	return res;		//res := <aName>
       
   114     }
       
   115 
       
   116 TPtrC XMLUtil::EndField( const TDesC& aName )
       
   117     {
       
   118 	TBuf<KMaxLength> res( KLessSlash );
       
   119 	res += aName;
       
   120 	res += KGreater;
       
   121 	return res;		//res := </aName>
       
   122     }
       
   123 
       
   124 // ======== MEMBER FUNCTIONS ========
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // Constructor
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 CBCTestConf::CBCTestConf()
       
   131     {
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // Destructor
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 CBCTestConf::~CBCTestConf()
       
   139     {
       
   140 	CloseConfig();
       
   141     }
       
   142 
       
   143 //static 
       
   144 CBCTestConf* CBCTestConf::NewLC()
       
   145 {
       
   146     CBCTestConf* self= new ( ELeave) CBCTestConf();
       
   147 	CleanupStack::PushL(self);
       
   148 	self->ConstructL();
       
   149     return self;
       
   150 }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CBCTestConf::ConstructL. 
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CBCTestConf::ConstructL()
       
   157     {
       
   158     OpenConfigL();
       
   159     }
       
   160 
       
   161 void CBCTestConf::OpenConfigL()
       
   162     {
       
   163     RFs& fs = CEikonEnv::Static()->FsSession();
       
   164 	User::LeaveIfError( 
       
   165 	    iFile.Open( fs, KConfFile, EFileRead | EFileShareAny ) != KErrNone );
       
   166     }
       
   167 
       
   168 void CBCTestConf::CloseConfig()
       
   169 	{
       
   170 	iFile.Close();
       
   171 	}
       
   172 
       
   173 TBool CBCTestConf::ReadLineL(TDes& aLine)
       
   174     {	
       
   175  	TBuf8<1> atom;
       
   176 	TBuf8<1> enter;
       
   177 	HBufC16* text = HBufC16::NewL( 1 );
       
   178 
       
   179  	for( TInt err = iFile.Read(atom); err == KErrNone 
       
   180  	    && atom.Length() > 0; err = iFile.Read( atom ) )
       
   181  	    {
       
   182  		if(atom[0] == 10 && enter[0] == 13)
       
   183  		    {
       
   184  			break;
       
   185  		    }
       
   186  		text->Des().Copy(atom);
       
   187 		aLine.Append(*text);
       
   188 		enter = atom;
       
   189  	    }
       
   190 
       
   191  	delete text;
       
   192 	return atom.Length()>0;
       
   193     }
       
   194 
       
   195 TBool CBCTestConf::ReadBlockDataL()
       
   196     {
       
   197     while( ETrue )
       
   198         {
       
   199 		TBuf<KMaxLength> line;
       
   200 		if(!ReadLineL(line))
       
   201 		    {
       
   202 			break;
       
   203 		    }
       
   204 
       
   205 		if( line.Find( XMLUtil::StartField( KTag ) ) != KErrNotFound )
       
   206 		    {
       
   207 			iName = _L("");
       
   208 			iAppUID = iViewUID = iTimeout =0;
       
   209 		    }
       
   210 		else if( line.Find( XMLUtil::EndField( KTag ) ) != KErrNotFound )
       
   211 		    {
       
   212 			return ETrue;
       
   213 		    }
       
   214 		else if( line.Find( XMLUtil::StartField( KName ) ) != KErrNotFound )
       
   215 		    {
       
   216 			iName = XMLUtil::ExtractField( line, KName );
       
   217 	    	}
       
   218 		else if( line.Find( XMLUtil::StartField( KAppUID ) ) != KErrNotFound )
       
   219 		    {
       
   220 			iAppUID = XMLUtil::StringToHex( 
       
   221 			    XMLUtil::ExtractField( line, KAppUID ) );
       
   222 		    }
       
   223 		else if( line.Find( XMLUtil::StartField( KViewUID ) ) != KErrNotFound )
       
   224 		    {
       
   225 			iViewUID = XMLUtil::StringToDec( 
       
   226 			    XMLUtil::ExtractField( line, KViewUID ) );
       
   227 		    }
       
   228 		else if( line.Find( XMLUtil::StartField( KTimeout ) ) != KErrNotFound )
       
   229 		    {
       
   230 			iTimeout = XMLUtil::StringToDec( 
       
   231 			    XMLUtil::ExtractField( line, KTimeout ) );
       
   232 		    }
       
   233 		else if( line.Find( XMLUtil::StartField( KVersion ) ) != KErrNotFound )
       
   234 		    {
       
   235 			iVersion = XMLUtil::StringToDec( 
       
   236 			    XMLUtil::ExtractField( line, KVersion ) );
       
   237 		    }
       
   238 	    }
       
   239 	return EFalse;
       
   240     }
       
   241 
       
   242 TBool CBCTestConf::NextL()
       
   243 	{
       
   244 	return ReadBlockDataL();
       
   245 	}
       
   246 
       
   247 const TDesC& CBCTestConf::Name()
       
   248 	{
       
   249     return iName;
       
   250 	}
       
   251 
       
   252 TInt CBCTestConf::AppUID()
       
   253     {
       
   254     return iAppUID;
       
   255     }
       
   256 
       
   257 TInt CBCTestConf::ViewUID()
       
   258 	{
       
   259 	return iViewUID;
       
   260 	}
       
   261 
       
   262 TInt CBCTestConf::Timeout()
       
   263 	{
       
   264 	return iTimeout;
       
   265 	}
       
   266 
       
   267 TInt CBCTestConf::Version()
       
   268 	{
       
   269 	return iVersion;
       
   270 	}