sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include //this includes e32cmn.h sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: LOCAL_D RTest TheTest (_L("T_StdlibDefect")); sl@0: // sl@0: // sl@0: //Test macroses and functions sl@0: sl@0: static void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: static void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: sl@0: sl@0: const TInt KTestDataLen = 10000; sl@0: const TInt KTestIterations = 1000; sl@0: sl@0: #ifdef __ARMCC__ sl@0: const TInt KMinCharARMCC = 0; sl@0: const TInt KMaxCharARMCC = 255; sl@0: #else sl@0: const TInt KMinCharNoARMCC = -128; sl@0: const TInt KMaxCharNoARMCC = 127; sl@0: #endif sl@0: sl@0: /** sl@0: DEF062679 : memcpy in stdlib is slow sl@0: */ sl@0: void Defect_DEF062679_memcpy() sl@0: { sl@0: sl@0: TUint8* src1 = new TUint8[KTestDataLen]; sl@0: TEST(src1 != NULL); sl@0: Mem::Fill(src1, KTestDataLen, 'A'); sl@0: sl@0: TUint8* dst1 = new TUint8[KTestDataLen]; sl@0: TEST(dst1 != NULL); sl@0: sl@0: TTime startTime, stopTime; sl@0: TInt i; sl@0: //Loop to check time spent using Mem::Copy sl@0: startTime.UniversalTime(); sl@0: for(i=0; i0); sl@0: ret = memcmp(str1, str3, KTestDataLen); sl@0: TEST(ret<0); sl@0: sl@0: delete str1; sl@0: delete str2; sl@0: delete str3; sl@0: } sl@0: sl@0: /** sl@0: INC073740: inet_addr and inet_aton returns wrong results with invalid input on STDLIB sl@0: */ sl@0: void Defect_INC073740() sl@0: { sl@0: TheTest.Next(_L("INC073740: inet_addr and inet_aton returns wrong results with invalid input on STDLIB")); sl@0: sl@0: int err; sl@0: struct in_addr iaddr; sl@0: char* good_addr="16.33.50.67"; sl@0: char* bad_addr="256.33.50.67"; sl@0: char* worse_addr="16.1456.50.67"; sl@0: char* worst_addr="16.33.333333.67"; sl@0: sl@0: err=inet_aton(good_addr, &iaddr); sl@0: TEST2(err, 1); sl@0: sl@0: err=inet_aton(bad_addr, &iaddr); sl@0: TEST2(err, 0); sl@0: sl@0: err=inet_aton(worse_addr, &iaddr); sl@0: TEST2(err, 0); sl@0: sl@0: err=inet_aton(worst_addr, &iaddr); sl@0: TEST2(err, 0); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-CT-1863 sl@0: @SYMTestCaseDesc Tests for minimum and maximum values type "char" with ARMCC macro sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for checking minimum and maximum values for a variable of type "char" sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF PDEF091928 sl@0: */ sl@0: void Defect_PDEF091928() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-CT-1863 PDEF091928: limits.h not correct for ARM RVCT compiler ")); sl@0: sl@0: char charmn=CHAR_MIN; sl@0: char charmx=CHAR_MAX; sl@0: sl@0: #ifdef __ARMCC__ sl@0: sl@0: TEST2(charmn, KMinCharARMCC); sl@0: TEST2(charmx, KMaxCharARMCC); sl@0: sl@0: #else sl@0: sl@0: TEST2(charmn, KMinCharNoARMCC); sl@0: TEST2(charmx, KMaxCharNoARMCC); sl@0: sl@0: #endif sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-UT-3612 sl@0: @SYMTestCaseDesc Tests for __errno(). sl@0: @SYMTestPriority Normal sl@0: @SYMTestActions Tests for __errno(). Test whether it is correctly exported and functioning sl@0: as expected after being declared with IMPORT_C. sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF110593 sl@0: */ sl@0: void Defect_DEF110593() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-UT-3612 DEF110593: IMPORT_C/EXPORT_C: ERRNO.H ")); sl@0: sl@0: // randomly selected 24 macros from errno.h sl@0: const int errMacros[24] = sl@0: { sl@0: EPERM, ENOENT, ESRCH, EINTR, EIO, sl@0: EBADF, ENOMEM, EFAULT, EBUSY, ENOTDIR, sl@0: ENFILE, ESPIPE, ERANGE, ENOMSG, EDEADLK, sl@0: ENOLCK, ENOTSOCK, ENOLINK, EBADMSG, ENOTUNIQ, sl@0: EBADFD, ENOSYS, EILSEQ, __ELASTERROR sl@0: }; sl@0: sl@0: // Step 1: setting errno using assign "=", test value returned by errno sl@0: errno = 0; sl@0: TEST(errno == 0); sl@0: sl@0: int i; sl@0: for (i = 0; i < 24; i++) sl@0: { sl@0: errno = errMacros[i]; sl@0: TEST(errno == errMacros[i]); sl@0: } sl@0: sl@0: // Step 2: setting errno using the library globals struct, test value returned by errno sl@0: struct _reent *r = _REENT2; sl@0: r->_errno = 0; sl@0: TEST(errno == 0); sl@0: sl@0: for (i = 0; i < 24; i++) sl@0: { sl@0: r->_errno = errMacros[i]; sl@0: TEST(errno == errMacros[i]); sl@0: } sl@0: sl@0: r->_errno = 0; sl@0: TEST(errno == 0); sl@0: sl@0: // Step3: Test errno by using other C function in STDLIB sl@0: // Test using ldexp(double value, int exp); sl@0: // Giving val a huge number to make res overflow. errno should return ERANGE sl@0: double val = 1.5E+308; sl@0: int exp = 10; sl@0: ldexp(val, exp); sl@0: TEST(errno == ERANGE); sl@0: sl@0: //finish sl@0: CloseSTDLIB(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-CT-4001 sl@0: @SYMTestCaseDesc Test strtoul() with a string whose first character is '-' or '+'. sl@0: @SYMTestPriority 3. Medium sl@0: @SYMTestActions Test strtoul() with a string whose first character is '-' or '+'. sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF PDEF114447 sl@0: */ sl@0: void Defect_PDEF114447 () sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-CT-4001 PDEF114447 : add the processing for '-' and '+' in a string passed to strtoul() ")); sl@0: sl@0: unsigned long result; sl@0: sl@0: result = strtoul("+80", NULL, 10); sl@0: TEST2(result, 80); sl@0: sl@0: result = strtoul("-80", NULL, 10); sl@0: TEST2(result, -80); sl@0: } sl@0: sl@0: /** sl@0: Calls ImpurePtr2() to allocate memory for the library globals struct then calls CloseSTDLIB() sl@0: to release it. sl@0: Leaves if system-wide error occurs. sl@0: */ sl@0: LOCAL_C void TestImpurePtrL() sl@0: { sl@0: struct _reent * p = ImpurePtr2(); sl@0: User::LeaveIfNull(p); sl@0: CloseSTDLIB(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-UT-4002 sl@0: @SYMTestCaseDesc Test checks the constructor of CLocalSystemInterface does not panics in OOM test sl@0: or when error KErrNoMemory occurs. sl@0: @SYMTestPriority Normal sl@0: @SYMTestActions In an OOM test, repeats calling ImpurePtr2(), which creates CLocalSystemInterface instance. sl@0: @SYMTestExpectedResults The test program should not panic or fail. sl@0: @SYMDEF DEF114383 sl@0: */ sl@0: LOCAL_C void Defect_DEF114383() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-UT-4002 DEF114383: STDLIB, CLocalSystemInterface::CLocalSystemInterface() panics in OOM ")); sl@0: sl@0: TInt err=KErrNone; sl@0: TInt tryCount = 0; sl@0: do sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); sl@0: TRAP(err, TestImpurePtrL()); sl@0: __UHEAP_SETFAIL(RHeap::ENone, 0); sl@0: sl@0: if (err!=KErrNoMemory) sl@0: TEST(err == KErrNone); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } while(err == KErrNoMemory); sl@0: sl@0: TEST(err == KErrNone); sl@0: sl@0: TheTest.Printf(_L("- ImpurePtr2() succeeded at heap failure rate of %i\n"), tryCount); sl@0: } sl@0: sl@0: /** sl@0: Invoke the tests sl@0: */ sl@0: LOCAL_C void RunTestsL () sl@0: { sl@0: Defect_DEF062679_memcpy(); sl@0: Defect_DEF062679_memcmp(); sl@0: sl@0: Defect_INC073740(); sl@0: sl@0: Defect_PDEF091928(); sl@0: sl@0: Defect_DEF110593(); sl@0: sl@0: Defect_PDEF114447(); sl@0: sl@0: Defect_DEF114383(); sl@0: } sl@0: sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: TEST(tc != NULL); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TheTest.Title(); sl@0: TheTest.Start (_L("Defect Tests")); sl@0: TInt err; sl@0: TRAP(err, ::RunTestsL()) sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: delete tc; sl@0: __UHEAP_MARKEND; sl@0: sl@0: sl@0: sl@0: return(KErrNone); sl@0: sl@0: } sl@0: