messagingappbase/smilparser/SMILdtd/tsrc/t_TestScript.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2001-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 // Basic test script handling.
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 #include "t_TestScript.h"
       
    20 
       
    21 
       
    22 _LIT(KCantOpenFile, "Could not open file: %S");
       
    23 _LIT(KMiscFileError, "File error");
       
    24 
       
    25 _LIT(KInfoTestFinished, "[%4d] Test finished: %S");
       
    26 _LIT(KInfoTestStarted, "[%4d] Starting test: %S");
       
    27 
       
    28 
       
    29 //
       
    30 //
       
    31 // CTestScript
       
    32 //
       
    33 
       
    34 CTestScript::~CTestScript()
       
    35 	{
       
    36 	iFile.Close();
       
    37 	}
       
    38 
       
    39 
       
    40 CTestScript* CTestScript::NewL(RFs& aFs)
       
    41 	{
       
    42 	CTestScript* self = new (ELeave) CTestScript(aFs);
       
    43 	CleanupStack::PushL(self);
       
    44 	self->ConstructL();
       
    45 	CleanupStack::Pop(self);
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 
       
    50 CTestScript::CTestScript(RFs& aFs)
       
    51 : iFs(aFs)
       
    52 	{
       
    53 	}
       
    54 
       
    55 
       
    56 void CTestScript::ConstructL()
       
    57 	{
       
    58 	}
       
    59 
       
    60 
       
    61 TBool CTestScript::LoadFileL(const TDesC& aFileName)
       
    62 	{
       
    63 	iFile.Close();
       
    64 	iEndOfFile = EFalse;
       
    65 	TBool loaded = EFalse;
       
    66 
       
    67 	TInt err = iFile.Open(iFs, aFileName, EFileShareAny);
       
    68 
       
    69 	if (err == KErrNone)
       
    70 		{
       
    71 		loaded = ETrue;
       
    72 		}
       
    73 	else
       
    74 		{
       
    75 		iLastError.Format(KCantOpenFile, aFileName);
       
    76 		}
       
    77 
       
    78 	return loaded;
       
    79 	}
       
    80 
       
    81 
       
    82 TBool CTestScript::GetLineL(TTestScriptString& aLine)
       
    83 	{
       
    84 	TBool noError = EFalse;
       
    85 	TInt startPosition = 0;
       
    86 
       
    87 	// Save the current position
       
    88 	TInt err = iFile.Seek(ESeekCurrent, startPosition);
       
    89 
       
    90 	if (err == KErrNone)
       
    91 		{
       
    92 		// Read a block of data
       
    93 		TTestScriptString dataFromFile;
       
    94 		err = iFile.Read(dataFromFile);
       
    95 
       
    96 		if (err != KErrNone)
       
    97 			{
       
    98 			iLastError.Copy(KMiscFileError);
       
    99 			}
       
   100 		else
       
   101 			{
       
   102 			// Look for the cr/lf pair, or the end of the line
       
   103 			TInt bytesOnLine = 0;
       
   104 			TBool finished = EFalse;
       
   105 			while (!finished)
       
   106 				{
       
   107 				if (bytesOnLine == dataFromFile.Size())
       
   108 					{
       
   109 					finished = ETrue;
       
   110 					}
       
   111 				else if (dataFromFile[bytesOnLine] == 0x0d)
       
   112 					{
       
   113 					finished = ETrue;
       
   114 					}
       
   115 				else
       
   116 					{
       
   117 					bytesOnLine++;
       
   118 					}
       
   119 				}
       
   120 
       
   121 			TInt startOfNextLine = startPosition + bytesOnLine + 1;
       
   122 
       
   123 			if (bytesOnLine + 1 < dataFromFile.Size())
       
   124 				{
       
   125 				if (dataFromFile[bytesOnLine + 1] == 0x0a)
       
   126 					{
       
   127 					startOfNextLine++;
       
   128 					}
       
   129 				}
       
   130 
       
   131 			// Seek to after the cr/lf pair
       
   132 			iFile.Seek(ESeekStart, startOfNextLine);
       
   133 
       
   134 			// Set the line
       
   135 			aLine.Copy(dataFromFile.Left(bytesOnLine));
       
   136 
       
   137 			// Get rid of any trailing white-space
       
   138 			TInt whiteSpaceIndex = aLine.Size();
       
   139 			TBool noMoreWhiteSpace = EFalse;
       
   140 			while ((whiteSpaceIndex--) && (!noMoreWhiteSpace))
       
   141 				{
       
   142 				if ((aLine[whiteSpaceIndex] == ' ')
       
   143 				||  (aLine[whiteSpaceIndex] == '\t'))
       
   144 					{
       
   145 					aLine.SetLength(whiteSpaceIndex);
       
   146 					}
       
   147 				else
       
   148 					{
       
   149 					noMoreWhiteSpace = ETrue;
       
   150 					}
       
   151 				}
       
   152 
       
   153 			if (dataFromFile.Size() != 0)
       
   154 				{
       
   155 				noError = ETrue;
       
   156 				}
       
   157 			}
       
   158 		}
       
   159 
       
   160 	return noError;
       
   161 	}
       
   162