telephonyserverplugins/simtsy/testconfigfileparser/src/testconfigfile.cpp
author hgs
Wed, 25 Aug 2010 14:35:42 +0100
changeset 64 b34bb05ac869
permissions -rw-r--r--
201031_04
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64
b34bb05ac869 201031_04
hgs
parents:
diff changeset
     1
/*
b34bb05ac869 201031_04
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
b34bb05ac869 201031_04
hgs
parents:
diff changeset
     3
* All rights reserved.
b34bb05ac869 201031_04
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
b34bb05ac869 201031_04
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
b34bb05ac869 201031_04
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
b34bb05ac869 201031_04
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
b34bb05ac869 201031_04
hgs
parents:
diff changeset
     8
*
b34bb05ac869 201031_04
hgs
parents:
diff changeset
     9
* Initial Contributors:
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    11
*
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    12
* Contributors:
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    13
*
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    14
* Description: 
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    15
*
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    16
*/
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    17
#include "testconfigfileparser.h"
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    18
#include <f32file.h>
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    19
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    20
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    21
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    22
#ifndef EKA2
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    23
GLDEF_C TInt E32Dll(TDllReason/* aReason*/)	
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    24
//
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    25
// DLL entry point
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    26
//
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    27
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    28
	return (KErrNone);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    29
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    30
#endif
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    31
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    32
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    33
EXPORT_C CTestConfig* CTestConfig::NewLC(RFs& aFs, const TDesC& aComponent, const TDesC& aScript)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    34
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    35
	CTestConfig* self = NewLC(aFs, aComponent);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    36
	self->ReadScriptL(aScript);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    37
	return self;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    38
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    39
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    40
EXPORT_C CTestConfig* CTestConfig::NewLC(RFs& aFs, const TDesC& aComponent)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    41
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    42
	CTestConfig* self = new (ELeave) CTestConfig(aFs);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    43
	CleanupStack::PushL(self);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    44
	self->ConstructL(aComponent);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    45
	return self;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    46
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    47
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    48
void CTestConfig::ConstructL(const TDesC& aComponent)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    49
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    50
	iComponent = aComponent.AllocL();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    51
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    52
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    53
CTestConfig::CTestConfig(RFs& aFs)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    54
: iFs(aFs)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    55
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    56
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    57
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    58
EXPORT_C CTestConfig::~CTestConfig()
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    59
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    60
	iSections.ResetAndDestroy();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    61
	iSections.Close();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    62
	delete iComponent;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    63
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    64
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    65
EXPORT_C const CTestConfigSection* CTestConfig::Section(const TDesC8& aSectionName) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    66
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    67
	const CTestConfigSection* section = NULL;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    68
	const TInt count = iSections.Count();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    69
		
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    70
	for (TInt i = 0; i < count; i++) //order important
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    71
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    72
		if (iSections[i]->SectionName().CompareF(aSectionName) == 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    73
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    74
			section = iSections[i];
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    75
			break;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    76
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    77
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    78
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    79
	return section;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    80
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    81
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    82
EXPORT_C CTestConfigSection* CTestConfig::Section(const TDesC8& aSectionName)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    83
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    84
	CTestConfigSection* section = NULL;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    85
	const TInt count = iSections.Count();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    86
		
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    87
	for (TInt i = 0; i < count; i++) //order important
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    88
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    89
		if (iSections[i]->SectionName().CompareF(aSectionName) == 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    90
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    91
			section = iSections[i];
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    92
			break;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    93
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    94
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    95
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    96
	return section;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    97
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    98
b34bb05ac869 201031_04
hgs
parents:
diff changeset
    99
EXPORT_C const TDesC8& CTestConfig::ItemValue(const TDesC8& aSection, const TDesC8& aItem, const TDesC8& aDefault) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   100
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   101
	const CTestConfigSection* section = Section(aSection);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   102
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   103
	if (section != NULL)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   104
		return section->ItemValue(aItem, aDefault);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   105
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   106
	return aDefault;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   107
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   108
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   109
EXPORT_C TInt CTestConfig::ItemValue(const TDesC8& aSection, const TDesC8& aItem, const TInt aDefault) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   110
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   111
	TInt output = aDefault;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   112
	const CTestConfigSection* section = Section(aSection);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   113
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   114
	if (section != NULL)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   115
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   116
		output = section->ItemValue(aItem, aDefault);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   117
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   118
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   119
	return output;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   120
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   121
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   122
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   123
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   124
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   125
HBufC8* CTestConfig::ReadFileL(const TDesC& aFile) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   126
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   127
	//Returns a HBufC8 with the contents of aFile
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   128
	RFile file;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   129
	const TInt err = file.Open(iFs, aFile, EFileShareAny | EFileRead);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   130
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   131
	if (err != KErrNone)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   132
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   133
		TParse fileOut;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   134
		User::LeaveIfError(ResolveFile(iFs, *iComponent, aFile, fileOut));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   135
		User::LeaveIfError(file.Open(iFs, fileOut.FullName(), EFileShareAny | EFileRead));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   136
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   137
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   138
	CleanupClosePushL(file);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   139
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   140
	TInt size = 0;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   141
	User::LeaveIfError(file.Size(size));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   142
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   143
	HBufC8* contents = HBufC8::NewLC(size + 4);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   144
	TPtr8 contentsPtr(contents->Des());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   145
	User::LeaveIfError(file.Read(0, contentsPtr));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   146
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   147
	CleanupStack::Pop(contents);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   148
	CleanupStack::PopAndDestroy(&file);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   149
	return contents;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   150
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   151
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   152
EXPORT_C TInt CTestConfig::ResolveFile(RFs& aFs, const TDesC& aComponent, const TDesC& aFileName, TParse& aParseOut)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   153
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   154
	TFileName* savedPath = new TFileName;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   155
	TFileName* fileName = new TFileName;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   156
	if ((savedPath == NULL) || (fileName == NULL))
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   157
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   158
		delete savedPath;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   159
		delete fileName;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   160
		return KErrNoMemory;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   161
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   162
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   163
	fileName->Append(KScriptPathSep);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   164
//	fileName->Append(KSmsTestFileInputBase);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   165
//	fileName->Append(KScriptPathSep);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   166
	fileName->Append(aComponent);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   167
	fileName->Append(KScriptPathSep);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   168
	fileName->Append(aFileName);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   169
	
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   170
	// file finder will look in the session drive first, then Y->A,Z
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   171
	// so set session drive to Y (save old and restore it afterwards)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   172
	aFs.SessionPath(*savedPath);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   173
	_LIT(KTopDrive,"Y:\\");
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   174
	aFs.SetSessionPath(KTopDrive);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   175
    TFindFile file_finder(aFs);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   176
    TInt err = file_finder.FindByDir(*fileName,KNullDesC);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   177
	if(err==KErrNone)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   178
		aParseOut.Set(file_finder.File(),NULL,NULL);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   179
	aFs.SetSessionPath(*savedPath);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   180
	delete savedPath;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   181
	delete fileName;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   182
	return(err);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   183
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   184
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   185
EXPORT_C void CTestConfig::ReadScriptL(const TDesC& aScript)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   186
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   187
	iSections.ResetAndDestroy();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   188
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   189
	CTestConfigSection* section = NULL;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   190
	CTestConfigItem* currentItem = NULL;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   191
	TInt currentItemStart = 0;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   192
	CTestConfigSection* sectionDefaults = NULL;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   193
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   194
	HBufC8* scriptContents = ReadFileL(aScript);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   195
	CleanupStack::PushL(scriptContents);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   196
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   197
	TLex8 input(*scriptContents);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   198
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   199
	while (!input.Eos())
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   200
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   201
		input.SkipSpaceAndMark();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   202
		input.SkipCharacters();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   203
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   204
		if ( input.TokenLength() == 0)    // if valid potential token
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   205
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   206
			//end of the script file found
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   207
			break;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   208
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   209
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   210
		const TPtrC8 token(input.MarkedToken());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   211
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   212
		if (token.CompareF(_L8("endscript")) == 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   213
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   214
			//end of the script file found
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   215
			break;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   216
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   217
		else if (IsNewSection(*scriptContents, input))
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   218
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   219
			ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   220
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   221
			TInt mid = 1;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   222
			TInt len = token.Length() - 2;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   223
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   224
			const TPtrC8 sectionName(token.Mid(mid, len));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   225
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   226
			if (sectionDefaults != NULL)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   227
				section = CTestConfigSection::NewLC(sectionName, *sectionDefaults);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   228
			else
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   229
				section = CTestConfigSection::NewLC(sectionName);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   230
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   231
			if (sectionDefaults == NULL && IsDefaultSection(section->SectionName()))
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   232
				sectionDefaults = section;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   233
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   234
			User::LeaveIfError(iSections.Append(section));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   235
			CleanupStack::Pop(section);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   236
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   237
		else if (section != NULL)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   238
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   239
			TInt valueOffset;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   240
			TPtrC8 newItem;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   241
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   242
			if (IsNewComment(*scriptContents, input))
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   243
				{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   244
				ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   245
				__ASSERT_DEBUG(currentItem == NULL, User::Invariant());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   246
				SkipToNextLine(input);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   247
				}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   248
			else if (IsNewItem(*scriptContents, input, newItem, valueOffset))
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   249
				{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   250
				ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   251
				currentItemStart = input.MarkedOffset() + valueOffset;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   252
				currentItem = &section->AddItemL(newItem, KNullDesC8);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   253
				}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   254
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   255
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   256
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   257
	ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   258
	CleanupStack::PopAndDestroy(scriptContents);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   259
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   260
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   261
TBool CTestConfig::IsNewSection(const TDesC8& aSource, const TLex8& aInput) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   262
/**
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   263
 * Checks whether the current marked token in aInput starts with a '[' and ends with a ']',
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   264
 * and checks that this token is at the start of a line.
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   265
 *
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   266
 * @returns Whether this is a new section in the script file
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   267
 */
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   268
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   269
	const TPtrC8 token(aInput.MarkedToken());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   270
	const TInt offset(aInput.MarkedOffset());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   271
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   272
	TBool ret = token.Length() > 2 && token.Find(KScriptSectionStart) == 0;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   273
	ret = ret && token.Find(KScriptSectionEnd) != KErrNotFound;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   274
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   275
	if (ret && offset > 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   276
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   277
		const TPtrC8 lastChar(aSource.Mid(offset-1, 1));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   278
		ret = ret && (lastChar == KScriptLF || lastChar == KScriptCR);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   279
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   280
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   281
	return ret;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   282
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   283
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   284
void CTestConfig::SkipToNextLine(TLex8& aInput) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   285
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   286
	const TChar cr('\n');
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   287
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   288
	while (!aInput.Eos() && aInput.Peek() != cr)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   289
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   290
		aInput.Inc();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   291
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   292
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   293
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   294
TBool CTestConfig::IsNewItem(const TDesC8& aSource, const TLex8& aLex, TPtrC8& aItem, TInt& aStartOfVal) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   295
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   296
	TBool ret(EFalse);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   297
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   298
	if (IsAtStartOfNewLine(aSource, aLex, ETrue))
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   299
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   300
		const TPtrC8 itemEnd(KScriptItemEnd);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   301
		const TInt itemEndLen(itemEnd.Length());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   302
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   303
		TPtrC8 token(aLex.MarkedToken());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   304
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   305
		//First check to see if this token contains '='
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   306
		const TInt find = token.Find(itemEnd);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   307
		if (find > 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   308
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   309
			aStartOfVal = find + itemEndLen;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   310
			aItem.Set(token.Left(find));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   311
			ret = ETrue;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   312
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   313
		else
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   314
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   315
			aItem.Set(token);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   316
			aStartOfVal = token.Length();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   317
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   318
			const TPtrC8 remain(aLex.Remainder());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   319
			TLex8 lex(remain);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   320
			//Check that the next token starts with and '='
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   321
			lex.SkipSpaceAndMark();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   322
			lex.SkipCharacters();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   323
			token.Set(lex.MarkedToken());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   324
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   325
			if (token.Find(itemEnd) == 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   326
				{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   327
				aStartOfVal += lex.MarkedOffset() + itemEndLen;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   328
				ret = ETrue;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   329
				}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   330
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   331
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   332
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   333
	return ret;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   334
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   335
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   336
TBool CTestConfig::IsNewComment(const TDesC8& aSource, const TLex8& aLex) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   337
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   338
	TBool ret(EFalse);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   339
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   340
	const TPtrC8 token(aLex.MarkedToken());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   341
	const TPtrC8 commentStart(KScriptCommentStart);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   342
	const TInt commentStartLen(commentStart.Length());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   343
	const TInt tokenLen(token.Length());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   344
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   345
	if (commentStartLen <= tokenLen && token.Left(commentStartLen).Compare(commentStart) == 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   346
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   347
		ret = IsAtStartOfNewLine(aSource, aLex, ETrue);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   348
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   349
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   350
	return ret;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   351
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   352
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   353
TBool CTestConfig::IsAtStartOfNewLine(const TDesC8& aSource, const TLex8& aLex, TBool aIgnoreSpaces) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   354
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   355
	TInt offset(aLex.MarkedOffset());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   356
	__ASSERT_ALWAYS(offset != 0, User::Invariant());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   357
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   358
	TChar ch = NULL;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   359
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   360
	if (aIgnoreSpaces)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   361
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   362
		while (offset--)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   363
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   364
			ch = aSource[offset];
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   365
			if (ch == KScriptLFChar || ch == KScriptCRChar || !ch.IsSpace())
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   366
				break;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   367
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   368
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   369
	else
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   370
		ch = aSource[offset-1];
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   371
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   372
	TBool ret(EFalse);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   373
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   374
	if (offset <= 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   375
		ret = ETrue;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   376
	else
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   377
		ret = (ch == KScriptLFChar || ch == KScriptCRChar);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   378
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   379
	return ret;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   380
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   381
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   382
TBool CTestConfig::IsDefaultSection(const TDesC8& aSectionName) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   383
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   384
	TBool retVal = (aSectionName.CompareF(KScriptDefaults) == 0);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   385
	retVal = retVal || (aSectionName.CompareF(KScriptDefault1) == 0);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   386
	return retVal;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   387
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   388
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   389
TPtrC8 CTestConfig::ParseValue(const TDesC8& aText, const TLex8& aInput, TInt aCurrentItemStart) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   390
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   391
	const TInt mid = aCurrentItemStart;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   392
	const TInt len = aInput.MarkedOffset() - mid;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   393
	TPtrC8 ret(KNullDesC8);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   394
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   395
	if (len > 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   396
		ret.Set(aText.Mid(mid, len));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   397
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   398
	return ret;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   399
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   400
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   401
void CTestConfig::ParseAndSetItemValueL(const TDesC8& aText, const TLex8& aInput, TInt aCurrentItemStart, CTestConfigItem*& arCurrentItem)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   402
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   403
	if (arCurrentItem)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   404
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   405
		delete arCurrentItem->iValue;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   406
		arCurrentItem->iValue = NULL;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   407
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   408
		TPtrC8 val(ParseValue(aText, aInput, aCurrentItemStart));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   409
		arCurrentItem->iValue = ReplaceLC(KScriptCRLF, KScriptLF, val);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   410
		arCurrentItem->iValue->Des().Trim();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   411
		CleanupStack::Pop(arCurrentItem->iValue);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   412
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   413
		if (arCurrentItem->Item().CompareF(KScriptDefaults) == 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   414
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   415
			TName filename;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   416
			filename.Copy(arCurrentItem->Value());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   417
			CopyInDefaultsL(arCurrentItem->iParent, filename);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   418
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   419
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   420
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   421
	arCurrentItem = NULL;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   422
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   423
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   424
void CTestConfig::CopyInDefaultsL(CTestConfigSection& aSection, const TDesC& aDefaultFile)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   425
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   426
	CTestConfig* file = CTestConfig::NewLC(iFs, aDefaultFile);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   427
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   428
	TInt count = file->Sections().Count();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   429
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   430
	if (count > 0)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   431
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   432
		const CTestConfigSection& def = (*file)[0];
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   433
		aSection.SetDefaultsL(def);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   434
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   435
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   436
	CleanupStack::PopAndDestroy(file);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   437
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   438
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   439
EXPORT_C TInt CTestConfig::CountElements(const TDesC8& aInput, TChar aDelimiter)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   440
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   441
	TInt pos = aInput.Length();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   442
	TInt count = 1;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   443
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   444
	while (pos--)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   445
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   446
		if (TChar(aInput[pos]) == aDelimiter)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   447
			count++;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   448
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   449
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   450
	return count;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   451
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   452
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   453
EXPORT_C TInt CTestConfig::GetElement(const TDesC8& aInput, TChar aDelimiter, TInt aIndex, TInt& aOutput)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   454
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   455
	aOutput = 0;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   456
	TPtrC8 string;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   457
	TInt err = GetElement(aInput, aDelimiter, aIndex, string, ETrue);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   458
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   459
	if (err == KErrNone)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   460
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   461
		TLex8 number(string);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   462
		err = number.Val(aOutput);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   463
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   464
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   465
	return err;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   466
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   467
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   468
EXPORT_C TInt CTestConfig::GetElement(const TDesC8& aInput, TChar aDelimiter, TInt aIndex, TPtrC8& aOutput, TBool aTrimOutput)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   469
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   470
	TLex8 input(aInput);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   471
	TInt err = KErrNone;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   472
	TPtrC8 ptr;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   473
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   474
	for (TInt i = 0; i <= aIndex && err == KErrNone; i++)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   475
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   476
		err = GetNextElement(input, aDelimiter, ptr);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   477
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   478
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   479
	if (err == KErrNone)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   480
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   481
		if (aTrimOutput)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   482
			aOutput.Set(Trim(ptr));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   483
		else
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   484
			aOutput.Set(ptr);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   485
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   486
	else 
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   487
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   488
		const TInt count = CountElements(aInput, aDelimiter);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   489
		const TInt len = aInput.Length();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   490
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   491
		if (len != 0 && count - 1 == aIndex && TChar(aInput[len-1]) == aDelimiter)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   492
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   493
			aOutput.Set(KNullDesC8);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   494
			err = KErrNone;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   495
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   496
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   497
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   498
	return err;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   499
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   500
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   501
EXPORT_C TPtrC8 CTestConfig::Trim(const TDesC8& aInput)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   502
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   503
	const TPtrC8 ptr(TrimLeft(aInput));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   504
	return TrimRight(ptr);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   505
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   506
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   507
EXPORT_C TPtrC8 CTestConfig::TrimRight(const TDesC8& aInput)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   508
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   509
	const TText8* first = aInput.Ptr();					// pointer to first char
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   510
	const TText8* last = first + aInput.Length() - 1;		// pointer to last char
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   511
	while (last >= first && TChar(*last).IsSpace()) last--;	// trim the right
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   512
	return TPtrC8(first, last + 1 - first);				// return the result
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   513
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   514
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   515
EXPORT_C TPtrC8 CTestConfig::TrimLeft(const TDesC8& aInput)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   516
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   517
	const TText8* first = aInput.Ptr();					// pointer to first char
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   518
	const TText8* last = first + aInput.Length() - 1;		// pointer to last char
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   519
	while (first < last && TChar(*first).IsSpace()) first++;	// trim the left
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   520
	return TPtrC8(first, last + 1 - first);				// return the result
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   521
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   522
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   523
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   524
TInt CTestConfig::GetNextElement(TLex8& aInput, TChar aDelimiter, TPtrC8& aOutput)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   525
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   526
	if (aInput.Eos())
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   527
		return KErrNotFound;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   528
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   529
	//Get to the start of the descriptor
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   530
	while (!aInput.Eos() && aInput.Peek() != aDelimiter)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   531
		aInput.Inc();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   532
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   533
	aOutput.Set(aInput.MarkedToken());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   534
	if (!aInput.Eos())
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   535
		aInput.SkipAndMark(1);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   536
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   537
	return KErrNone;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   538
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   539
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   540
/*EXPORT_C void CTestConfig::ReplaceL(const TDesC8& aOld, const TDesC8& aNew, HBufC*& rString)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   541
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   542
	HBufC* repl = ReplaceLC(aOld, aNew, *rString);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   543
	CleanupStack::Pop(repl);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   544
	rString = repl;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   545
	}*/
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   546
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   547
EXPORT_C HBufC8* CTestConfig::ReplaceLC(const TDesC8& aOld, const TDesC8& aNew, const TDesC8& aOldString)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   548
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   549
	HBufC8* rString = aOldString.AllocLC();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   550
	TInt oldLen = aOld.Length();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   551
	TInt newLen = aNew.Length();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   552
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   553
	if (!oldLen)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   554
		return rString;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   555
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   556
	for (TInt pos = 0; pos < rString->Length(); pos += newLen)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   557
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   558
		TPtrC8 ptrC = rString->Mid(pos);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   559
		TInt find = ptrC.Find(aOld);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   560
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   561
		if (find == KErrNotFound)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   562
			return rString;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   563
	
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   564
		pos += find;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   565
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   566
		if (newLen > oldLen)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   567
			{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   568
			rString = rString->ReAllocL(rString->Length() + newLen - oldLen);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   569
			CleanupStack::Pop();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   570
			CleanupStack::PushL(rString);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   571
			}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   572
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   573
		TPtr8 ptr(rString->Des());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   574
		ptr.Replace(pos, oldLen, aNew);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   575
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   576
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   577
	return rString;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   578
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   579
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   580
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   581
EXPORT_C void CTestConfig::WriteFileL(const TDesC& aFileName)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   582
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   583
	RFile file;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   584
	User::LeaveIfError(file.Replace(iFs, aFileName, EFileShareAny | EFileWrite));
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   585
	CleanupClosePushL(file);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   586
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   587
	const TInt count = iSections.Count();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   588
	
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   589
	for (TInt i=0; i < count; i++)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   590
		iSections[i]->WriteL(file);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   591
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   592
	User::LeaveIfError(file.Flush());
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   593
	CleanupStack::PopAndDestroy();  //file
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   594
	}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   595
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   596
EXPORT_C TBool CTestConfig::operator==(const CTestConfig& aFile) const
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   597
	{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   598
	TInt count = iSections.Count();
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   599
	if (count != aFile.Sections().Count())
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   600
		return EFalse;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   601
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   602
	TBool retVal = ETrue;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   603
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   604
	while (count-- && retVal)
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   605
		{
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   606
		retVal = retVal && (*iSections[count] == aFile[count]);
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   607
		}
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   608
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   609
	return retVal;
b34bb05ac869 201031_04
hgs
parents:
diff changeset
   610
	}