Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include <e32test.h> //this includes e32cmn.h
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <sys/ioctl.h>
23 #include <libc/netinet/in.h>
24 #include <libc/arpa/inet.h>
27 #include <sys/errno.h>
31 LOCAL_D RTest TheTest (_L("T_StdlibDefect"));
34 //Test macroses and functions
36 static void Check(TInt aValue, TInt aLine)
40 TheTest(EFalse, aLine);
43 static void Check(TInt aValue, TInt aExpected, TInt aLine)
45 if(aValue != aExpected)
47 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
48 TheTest(EFalse, aLine);
51 #define TEST(arg) ::Check((arg), __LINE__)
52 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
56 const TInt KTestDataLen = 10000;
57 const TInt KTestIterations = 1000;
60 const TInt KMinCharARMCC = 0;
61 const TInt KMaxCharARMCC = 255;
63 const TInt KMinCharNoARMCC = -128;
64 const TInt KMaxCharNoARMCC = 127;
68 DEF062679 : memcpy in stdlib is slow
70 void Defect_DEF062679_memcpy()
73 TUint8* src1 = new TUint8[KTestDataLen];
75 Mem::Fill(src1, KTestDataLen, 'A');
77 TUint8* dst1 = new TUint8[KTestDataLen];
80 TTime startTime, stopTime;
82 //Loop to check time spent using Mem::Copy
83 startTime.UniversalTime();
84 for(i=0; i<KTestIterations ; i++)
85 Mem::Copy(dst1, src1, KTestDataLen );
86 stopTime.UniversalTime();
87 TTimeIntervalMicroSeconds timeTaken = stopTime.MicroSecondsFrom(startTime);
88 TheTest.Printf(_L("Time taken using Mem::Copy :%d microseconds\n"), timeTaken.Int64() );
90 //Loop to check the time spent using memcpy after the change
91 startTime.UniversalTime();
92 for(i=0; i<KTestIterations ; i++)
93 memcpy(dst1, src1, KTestDataLen );
94 stopTime.UniversalTime();
95 TTimeIntervalMicroSeconds timeTaken2 = stopTime.MicroSecondsFrom(startTime);
96 TheTest.Printf(_L("Time taken using memcpy: %d microseconds\n"), timeTaken2.Int64() );
97 TheTest.Printf(_L("Time taken using memcpy before the change about 613125 microseconds\n"));
99 //Test memcpy works fine
100 for(i=0; i<KTestIterations ; i++)
101 TEST(dst1[i] == src1[i]);
112 DEF062679 : memcpy in stdlib is slow
114 void Defect_DEF062679_memcmp()
117 TUint8* str1 = new TUint8[KTestDataLen];
119 Mem::Fill(str1, KTestDataLen, 'A');
121 TUint8* str2 = new TUint8[KTestDataLen];
123 Mem::Fill(str2, KTestDataLen, 'A');
125 TTime startTime, stopTime;
127 //Loop to check the time using Mem::Copy
128 startTime.UniversalTime();
130 for(i=0; i<KTestIterations ; i++)
131 ret = Mem::Compare(str2,KTestDataLen, str1, KTestDataLen );
132 stopTime.UniversalTime();
133 TTimeIntervalMicroSeconds timeTaken = stopTime.MicroSecondsFrom(startTime);
134 TheTest.Printf(_L("Time taken using Mem::Compare :%ld microseconds\n"), timeTaken.Int64() );
136 //Loop to check the time spent using memcpy after the change
137 startTime.UniversalTime();
139 for(i=0; i<KTestIterations ; i++)
140 ret = memcmp(str2,str1, KTestDataLen );
141 TEST(ret==0); //check that memcmp works fine
142 stopTime.UniversalTime();
143 TTimeIntervalMicroSeconds timeTaken2 = stopTime.MicroSecondsFrom(startTime);
144 TheTest.Printf(_L("Time taken using memcmp: %ld microseconds\n"), timeTaken2.Int64() );
146 TheTest.Printf(_L("Time taken using memcmp before changes 1007000 microseconds\n"));
149 //Test memcmp works fine
151 TUint8* str3 = new TUint8[KTestDataLen];
153 Mem::Fill(str3, KTestDataLen, 'B');
154 ret = memcmp(str3, str1, KTestDataLen);
156 ret = memcmp(str1, str3, KTestDataLen);
165 INC073740: inet_addr and inet_aton returns wrong results with invalid input on STDLIB
167 void Defect_INC073740()
169 TheTest.Next(_L("INC073740: inet_addr and inet_aton returns wrong results with invalid input on STDLIB"));
172 struct in_addr iaddr;
173 char* good_addr="16.33.50.67";
174 char* bad_addr="256.33.50.67";
175 char* worse_addr="16.1456.50.67";
176 char* worst_addr="16.33.333333.67";
178 err=inet_aton(good_addr, &iaddr);
181 err=inet_aton(bad_addr, &iaddr);
184 err=inet_aton(worse_addr, &iaddr);
187 err=inet_aton(worst_addr, &iaddr);
192 @SYMTestCaseID SYSLIB-STDLIB-CT-1863
193 @SYMTestCaseDesc Tests for minimum and maximum values type "char" with ARMCC macro
194 @SYMTestPriority High
195 @SYMTestActions Tests for checking minimum and maximum values for a variable of type "char"
196 @SYMTestExpectedResults Tests must not fail
199 void Defect_PDEF091928()
201 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-CT-1863 PDEF091928: limits.h not correct for ARM RVCT compiler "));
203 char charmn=CHAR_MIN;
204 char charmx=CHAR_MAX;
208 TEST2(charmn, KMinCharARMCC);
209 TEST2(charmx, KMaxCharARMCC);
213 TEST2(charmn, KMinCharNoARMCC);
214 TEST2(charmx, KMaxCharNoARMCC);
220 @SYMTestCaseID SYSLIB-STDLIB-UT-3612
221 @SYMTestCaseDesc Tests for __errno().
222 @SYMTestPriority Normal
223 @SYMTestActions Tests for __errno(). Test whether it is correctly exported and functioning
224 as expected after being declared with IMPORT_C.
225 @SYMTestExpectedResults Tests must not fail
228 void Defect_DEF110593()
230 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-UT-3612 DEF110593: IMPORT_C/EXPORT_C: ERRNO.H "));
232 // randomly selected 24 macros from errno.h
233 const int errMacros[24] =
235 EPERM, ENOENT, ESRCH, EINTR, EIO,
236 EBADF, ENOMEM, EFAULT, EBUSY, ENOTDIR,
237 ENFILE, ESPIPE, ERANGE, ENOMSG, EDEADLK,
238 ENOLCK, ENOTSOCK, ENOLINK, EBADMSG, ENOTUNIQ,
239 EBADFD, ENOSYS, EILSEQ, __ELASTERROR
242 // Step 1: setting errno using assign "=", test value returned by errno
247 for (i = 0; i < 24; i++)
249 errno = errMacros[i];
250 TEST(errno == errMacros[i]);
253 // Step 2: setting errno using the library globals struct, test value returned by errno
254 struct _reent *r = _REENT2;
258 for (i = 0; i < 24; i++)
260 r->_errno = errMacros[i];
261 TEST(errno == errMacros[i]);
267 // Step3: Test errno by using other C function in STDLIB
268 // Test using ldexp(double value, int exp);
269 // Giving val a huge number to make res overflow. errno should return ERANGE
270 double val = 1.5E+308;
273 TEST(errno == ERANGE);
280 @SYMTestCaseID SYSLIB-STDLIB-CT-4001
281 @SYMTestCaseDesc Test strtoul() with a string whose first character is '-' or '+'.
282 @SYMTestPriority 3. Medium
283 @SYMTestActions Test strtoul() with a string whose first character is '-' or '+'.
284 @SYMTestExpectedResults Tests must not fail
287 void Defect_PDEF114447 ()
289 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-CT-4001 PDEF114447 : add the processing for '-' and '+' in a string passed to strtoul() "));
291 unsigned long result;
293 result = strtoul("+80", NULL, 10);
296 result = strtoul("-80", NULL, 10);
301 Calls ImpurePtr2() to allocate memory for the library globals struct then calls CloseSTDLIB()
303 Leaves if system-wide error occurs.
305 LOCAL_C void TestImpurePtrL()
307 struct _reent * p = ImpurePtr2();
308 User::LeaveIfNull(p);
313 @SYMTestCaseID SYSLIB-STDLIB-UT-4002
314 @SYMTestCaseDesc Test checks the constructor of CLocalSystemInterface does not panics in OOM test
315 or when error KErrNoMemory occurs.
316 @SYMTestPriority Normal
317 @SYMTestActions In an OOM test, repeats calling ImpurePtr2(), which creates CLocalSystemInterface instance.
318 @SYMTestExpectedResults The test program should not panic or fail.
321 LOCAL_C void Defect_DEF114383()
323 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-UT-4002 DEF114383: STDLIB, CLocalSystemInterface::CLocalSystemInterface() panics in OOM "));
331 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
332 TRAP(err, TestImpurePtrL());
333 __UHEAP_SETFAIL(RHeap::ENone, 0);
335 if (err!=KErrNoMemory)
336 TEST(err == KErrNone);
339 } while(err == KErrNoMemory);
341 TEST(err == KErrNone);
343 TheTest.Printf(_L("- ImpurePtr2() succeeded at heap failure rate of %i\n"), tryCount);
349 LOCAL_C void RunTestsL ()
351 Defect_DEF062679_memcpy();
352 Defect_DEF062679_memcmp();
367 GLDEF_C TInt E32Main()
370 CTrapCleanup* tc = CTrapCleanup::New();
376 TheTest.Start (_L("Defect Tests"));
378 TRAP(err, ::RunTestsL())
379 TEST2(err, KErrNone);