appfw/apparchitecture/tef/TESTREC/TESTREC.CPP
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Defines a data recognizer
       
    15 // Defines a test recognizer class which recognizes data type "test/plain".\n
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent - Internal Symbian test code 
       
    22 */
       
    23 
       
    24 #include "TESTREC.H"
       
    25 
       
    26 /**
       
    27   
       
    28    Recognizer used as part of CommandLine tests
       
    29    
       
    30    @SYMPREQ 280 File Handle Support
       
    31  
       
    32    FunctionDesc : Constructor for the recognizer of data type "test\plain" . 
       
    33    
       
    34  */
       
    35 
       
    36 CAppTestRecognizer::CAppTestRecognizer()
       
    37 	:CApaDataRecognizerType(KUidTestTxtRecognizer,CApaDataRecognizerType::ELow)
       
    38 	// Text files are low recognition - they don't have a clear signature
       
    39 	{
       
    40 	iCountDataTypes=1;
       
    41 	}
       
    42 
       
    43 /**
       
    44   
       
    45    Recognizer used as part of CommandLine tests
       
    46   
       
    47    @SYMPREQ 280 File Handle Support
       
    48   
       
    49    FunctionDesc : Specifies the buffer size required by the data type
       
    50   
       
    51  */
       
    52 TUint CAppTestRecognizer::PreferredBufSize()
       
    53 	{
       
    54 	return KMaxBufferLength;
       
    55 	}
       
    56 
       
    57 /**
       
    58   
       
    59    Recognizer used as part of CommandLine tests
       
    60   
       
    61    @SYMPREQ 280 File Handle Support
       
    62    
       
    63    FunctionDesc : Returns the data type supported : test\plain
       
    64   
       
    65  */
       
    66 #if defined(_DEBUG)
       
    67 TDataType CAppTestRecognizer::SupportedDataTypeL(TInt aIndex) const
       
    68 #else
       
    69 TDataType CAppTestRecognizer::SupportedDataTypeL(TInt /*aIndex*/) const
       
    70 #endif
       
    71 	{
       
    72 	__ASSERT_DEBUG(aIndex==0,User::Invariant());
       
    73 	return TDataType(KDataTypeTestPlain);
       
    74 	}
       
    75 
       
    76  /**
       
    77   
       
    78    Recognizer used as part of CommandLine tests
       
    79   
       
    80    @SYMPREQ 280 File Handle Support
       
    81   
       
    82    FunctionDesc :  Should recognize the data type of the file. 
       
    83    Called by the RecognizeL function.
       
    84    Checks if the first three bytes are valid uids.If yes the file is not a plain/test
       
    85    Verifies if the file extension is .test
       
    86    Checks for characters that wont be in a text file.
       
    87   
       
    88  */
       
    89 void CAppTestRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
       
    90 	{
       
    91 	TBool nameRecognized=EFalse;
       
    92     
       
    93 	// check if the file has valid UIDs 
       
    94 	if (aBuffer.Length() >= 16)
       
    95 		{
       
    96 		// if the first 3 bytes are valid UIDs,then this file is not a plain/test. 
       
    97 		// Set iConfidence appropriately and exit.
       
    98 		const TCheckedUid checkUid(aBuffer.Left(16));    
       
    99 		if (checkUid.UidType().IsValid())
       
   100 			{
       
   101 			iConfidence=ENotRecognized;
       
   102 			return;
       
   103 			}
       
   104 		}
       
   105 
       
   106 	// Compare if the file extension is .TEST
       
   107 	if (aName.Length()>4)
       
   108 		{
       
   109 		nameRecognized=(aName.Right(5).CompareF(KTestFileExt)==0);
       
   110 		}
       
   111 		
       
   112 	const TInt length=Min(aBuffer.Length(), KMaxBufferLength);
       
   113 	
       
   114 	if (length<KMinBufferLength && !nameRecognized)
       
   115 		{
       
   116 		return;
       
   117 		}
       
   118 		
       
   119 	
       
   120 	// Check for characters that wont be in a text file
       
   121 	TInt index;
       
   122 	for (index=0; index<length; index++)
       
   123 		{
       
   124 		const TUint chr=aBuffer[index];
       
   125 		// these are guesses of what WON'T be in a text file
       
   126 		if (chr<9 || chr==11 || chr==12 || (chr>13 && chr<32))
       
   127 			{
       
   128 			break;
       
   129 			}
       
   130 		if (chr>148)
       
   131 			{
       
   132 			break;
       
   133 			}
       
   134 		}
       
   135 	const TBool validChars=(index==length);
       
   136 	
       
   137 	if (nameRecognized)
       
   138 		{
       
   139 		iConfidence=validChars? EProbable : EUnlikely;
       
   140 		}
       
   141 	else
       
   142 		{
       
   143 		if (!validChars)
       
   144 			{
       
   145 			return;
       
   146 			}
       
   147 		iConfidence=EPossible;
       
   148 		}
       
   149 	iDataType=TDataType(KDataTypeTestPlain);
       
   150 	}
       
   151 
       
   152 /**
       
   153   
       
   154    Recognizer used as part of CommandLine tests
       
   155   
       
   156   
       
   157    @SYMPREQ 280 File Handle Support
       
   158   
       
   159    FunctionDesc : Creates an instance of the recognizer . 
       
   160    
       
   161  */
       
   162 
       
   163 CApaDataRecognizerType* CAppTestRecognizer::CreateRecognizerL()
       
   164 	{
       
   165 	return new (ELeave) CAppTestRecognizer();
       
   166 	}
       
   167 	
       
   168 /**
       
   169   
       
   170    Recognizer used as part of CommandLine tests
       
   171   
       
   172    @SYMPREQ 280 File Handle Support
       
   173   
       
   174    Desc : Implementation table specifying the implementation uid . 
       
   175    
       
   176  */
       
   177 const TImplementationProxy ImplementationTable[] = 
       
   178     {
       
   179 	IMPLEMENTATION_PROXY_ENTRY(KTestTxtRecognizerValue,CAppTestRecognizer::CreateRecognizerL)
       
   180 	};
       
   181 
       
   182 /**
       
   183   
       
   184    Recognizer used as part of CommandLine tests
       
   185   
       
   186    @SYMPREQ 280 File Handle Support
       
   187   
       
   188    FunctionDesc : Returns the implementation table. 
       
   189    
       
   190   
       
   191  */
       
   192 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   193     {
       
   194     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   195     return ImplementationTable;
       
   196     }
       
   197 
       
   198 
       
   199 
       
   200