1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/bsul/test/t_iniparser/T_IniParserUnit.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,219 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// @internalComponent
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <e32base.h>
1.23 +#include <e32test.h>
1.24 +#include <f32file.h>
1.25 +#include <s32file.h>
1.26 +#include "IniTemplate.h"
1.27 +#include "IniParserImpl.h"
1.28 +
1.29 +RTest test(_L("Ini Parser Unit Test"));
1.30 +RFs TheRFs;
1.31 +
1.32 +using namespace BSUL;
1.33 +
1.34 +typedef void (*ClassFuncPtr8L) (void);
1.35 +
1.36 +//utils class for testing
1.37 +static void DoBasicTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc)
1.38 + {
1.39 + test.Next(aTestDesc);
1.40 +
1.41 + __UHEAP_MARK;
1.42 + // find out the number of open handles
1.43 + TInt startProcessHandleCount;
1.44 + TInt startThreadHandleCount;
1.45 + RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
1.46 +
1.47 + (testFuncL)();
1.48 +
1.49 + // check that no handles have leaked
1.50 + TInt endProcessHandleCount;
1.51 + TInt endThreadHandleCount;
1.52 + RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
1.53 +
1.54 + test(startProcessHandleCount == endProcessHandleCount);
1.55 + test(startThreadHandleCount == endThreadHandleCount);
1.56 +
1.57 + __UHEAP_MARKEND;
1.58 + }
1.59 +
1.60 +static void DoOOMTestL(ClassFuncPtr8L testFuncL, const TDesC& aTestDesc)
1.61 + {
1.62 + test.Next(aTestDesc);
1.63 +
1.64 + TInt err;
1.65 + TInt tryCount = 0;
1.66 + do
1.67 + {
1.68 + __UHEAP_MARK;
1.69 + // find out the number of open handles
1.70 + TInt startProcessHandleCount;
1.71 + TInt startThreadHandleCount;
1.72 + RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
1.73 +
1.74 + __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
1.75 + TRAP(err, testFuncL());
1.76 + __UHEAP_SETFAIL(RHeap::ENone, 0);
1.77 +
1.78 + // check that no handles have leaked
1.79 + TInt endProcessHandleCount;
1.80 + TInt endThreadHandleCount;
1.81 + RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
1.82 +
1.83 + test(startProcessHandleCount == endProcessHandleCount);
1.84 + test(startThreadHandleCount == endThreadHandleCount);
1.85 +
1.86 + __UHEAP_MARKEND;
1.87 + } while(err == KErrNoMemory);
1.88 +
1.89 + test(err==KErrNone);
1.90 + test.Printf(_L("- succeeded at heap failure rate of %i\n"), tryCount);
1.91 + }
1.92 +
1.93 +/**
1.94 +@SYMTestCaseID SYSLIB-BAFL-CT-1555
1.95 +@SYMTestCaseDesc Test CIniKeyX
1.96 +@SYMTestPriority High
1.97 +@SYMTestActions Create, compare and delete CIniKeyX.
1.98 +@SYMTestExpectedResults The test must not fail.
1.99 +@SYMREQ PREQ505
1.100 +*/
1.101 +static void DoTest1L()
1.102 + {
1.103 + test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1555 "));
1.104 + //basic constructor
1.105 + CIniKey8* key1=CIniKey8::NewL(_L8("mykey"),_L8("myvalue"));
1.106 + CleanupStack::PushL(key1);
1.107 + CIniKey8* key2=CIniKey8::NewL(_L8("nykey"),_L8("myvalue"));
1.108 + CleanupStack::PushL(key2);
1.109 +
1.110 + //Compare key
1.111 + test(CIniKey8::CompareKey(*key1,*key2)<0);
1.112 + test(CIniKey8::CompareKey(*key2,*key1)>0);
1.113 +
1.114 + //test key name and value
1.115 + test(key1->KeyName().Compare(_L8("mykey"))==0);
1.116 + test(key1->KeyValue().Compare(_L8("myvalue"))==0);
1.117 +
1.118 + //SetKeyValue
1.119 + key1->SetKeyValue(_L8("newvalue"));
1.120 + test(key1->KeyValue().Compare(_L8("newvalue"))==0);
1.121 +
1.122 + CleanupStack::PopAndDestroy(2);
1.123 + }
1.124 +
1.125 +/**
1.126 +@SYMTestCaseID SYSLIB-BAFL-CT-1556
1.127 +@SYMTestCaseDesc Test CiniSectionX
1.128 +@SYMTestPriority High
1.129 +@SYMTestActions Test CiniSectionX by using compare section, InsertKeyL etc.
1.130 +@SYMTestExpectedResults The test must not fail.
1.131 +@SYMREQ PREQ505
1.132 +*/
1.133 +static void DoTest2L()
1.134 + {
1.135 + test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1556 "));
1.136 + //basic constructor
1.137 + CIniSection16* section1=CIniSection16::NewLC(_L("abc"));
1.138 + CIniSection16* section2=CIniSection16::NewLC(_L("cde"));
1.139 + CIniSection16* section3=CIniSection16::NewLC(_L("ABC"));
1.140 +
1.141 + //compare section
1.142 + test(CIniSection16::CompareSection(*section1,*section2)<0);
1.143 + test(CIniSection16::CompareSection(*section2,*section1)>0);
1.144 + //case sensitive
1.145 + test(CIniSection16::CompareSection(*section3,*section1)<0);
1.146 +
1.147 + //no key yet, this will create one
1.148 + section1->InsertKeyL(_L("newkey"),_L("XXXX"));
1.149 +
1.150 + //InsertKeyL(will leave with KErrAlreadyExists)
1.151 + TRAPD(err,section1->InsertKeyL(_L("newkey"),_L("keyvalue")));
1.152 + if (err==KErrNoMemory)
1.153 + User::LeaveNoMemory();
1.154 + test(err==KErrAlreadyExists);
1.155 + test(section1->KeyCount()==1);
1.156 + section1->InsertKeyL(_L("key2"),_L("keyval2"));
1.157 + test(section1->KeyCount()==2);
1.158 +
1.159 + //KeyValueL
1.160 + TPtrC value;
1.161 + TRAP(err,value.Set(section2->KeyValueL(_L("unknownkey"))));
1.162 + if (err==KErrNoMemory)
1.163 + User::LeaveNoMemory();
1.164 + test(err==KErrNotFound);
1.165 + value.Set(section1->KeyValueL(_L("newkey")));
1.166 + test(value.Compare(_L("XXXX"))==0);
1.167 +
1.168 +
1.169 + //FindKeyL(ordered list)
1.170 + CIniKey16* myKey=NULL;
1.171 + TRAP(err, myKey=section1->FindKeyL(_L("newkey")));
1.172 + if (err==KErrNoMemory)
1.173 + User::LeaveNoMemory();
1.174 + test(myKey!= NULL);
1.175 + TRAP(err,section1->FindKeyL(_L("tommy")));
1.176 + if (err==KErrNoMemory)
1.177 + User::LeaveNoMemory();
1.178 + test(err==KErrNotFound);
1.179 +
1.180 + //RemoveKeyL
1.181 + TRAP(err,section1->RemoveKeyL(_L("unknownkey")));
1.182 + if (err==KErrNoMemory)
1.183 + User::LeaveNoMemory();
1.184 + test(err==KErrNotFound);
1.185 + section1->RemoveKeyL(_L("key2"));
1.186 + test(section1->KeyCount()==1);
1.187 +
1.188 + CleanupStack::PopAndDestroy(3);
1.189 + }
1.190 +
1.191 +
1.192 +static void DoTestL()
1.193 + {
1.194 + //basic test
1.195 + DoBasicTestL(&DoTest1L,_L("CIniKey basic test"));
1.196 + DoBasicTestL(&DoTest2L,_L("CIniSection basic test"));
1.197 +
1.198 + //oom test
1.199 + DoOOMTestL(&DoTest1L,_L("CIniKey OOM test"));
1.200 + DoOOMTestL(&DoTest2L,_L("CIniSection OOM test"));
1.201 + }
1.202 +
1.203 +
1.204 +GLDEF_C TInt E32Main()
1.205 + {
1.206 + __UHEAP_MARK;
1.207 + CTrapCleanup* trapCleanup=CTrapCleanup::New();
1.208 + test(TheRFs.Connect()==KErrNone);
1.209 + test.Start(_L("Ini Parser Unit Test"));
1.210 +
1.211 + TRAPD(error, DoTestL());
1.212 + test(error == KErrNone);
1.213 +
1.214 +
1.215 + TheRFs.Close();
1.216 + test.End();
1.217 + test.Close();
1.218 + delete trapCleanup;
1.219 + __UHEAP_MARKEND;
1.220 + return error;
1.221 + }
1.222 +