Update contrib.
1 // Copyright (c) 2008-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.
14 // Simple STDLIB tests.
25 //CPP file is used for C tests, because by default any console opened from a C file
26 //expects a key to be pressed when it is about to be closed. That makes impossible
27 //the creation of automated C tests.
32 static RTest TheTest(_L("TMisc3"));
33 const double KPi = 3.14159265358979323846;
37 //Test macroses and functions
39 static void Check(TInt aValue, TInt aLine)
43 TheTest(EFalse, aLine);
46 static void Check(TInt aValue, TInt aExpected, TInt aLine)
48 if(aValue != aExpected)
50 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
51 TheTest(EFalse, aLine);
54 #define TEST(arg) ::Check((arg), __LINE__)
55 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
57 #define TEST_NAN (0.0/0.0)
58 #define TEST_POS_INFINITY (1.0/0.0)
59 #define TEST_NEG_INFINITY (-1.0/0.0)
64 static void TestCType()
79 TEST(c >= 'a' && c <= 'f' ? isxdigit(c) : !isxdigit(c));
93 TEST(c >= 'A' && c <= 'F' ? isxdigit(c) : !isxdigit(c));
119 if(c != '\t' && c != '\n' && c != '\r' && c != '\v' && c != '\f')
131 static void TestMath()
133 double eps = 0.000001;
135 double res = fabs(21.091);
136 TEST((21.091 - res) < eps);
138 TEST((res - 1.91) < eps);
141 TEST(fabs(res) < eps);
144 TEST(res > 1000000000.0);
146 TEST(fabs(res - KPi/2) < eps);
149 TEST(fabs(res - 1.0) < eps);
151 TEST(fabs(res - KPi/4) < eps);
153 res = tan((3 * KPi) / 4);
154 TEST(fabs(res + 1.0) < eps);
156 TEST(fabs((KPi + res) - (3 * KPi) / 4) < eps);
160 TEST(fabs(res - 1) < eps);
166 TEST(fabs(res + 1.0) < eps);
173 TEST(fabs(res - 1) < eps);
179 TEST(fabs(res - 0.761594) < eps);
182 res = frexp(0.51E+2, &exponent);
183 TEST((0.51E+2 - res * pow(2.0, exponent)) < eps);
186 res = modf(34.567, &integer);
187 TEST(fabs(res - 0.567) < eps);
188 TEST(fabs(integer - 34.0) < eps);
189 res = modf(-35.567, &integer);
190 TEST(fabs(res + 0.567) < eps);
191 TEST(fabs(integer + 35.0) < eps);
193 res = ceil(245.8903);
194 TEST(fabs(res - 246.0) < eps);
196 TEST(fabs(res + 11.0) < eps);
198 res = floor(245.8903);
199 TEST(fabs(res - 245.0) < eps);
201 TEST(fabs(res + 12.0) < eps);
203 res = copysign(4.789, -9.001);
204 TEST((res + 4.789) < eps);
205 res = copysign(-4.789, 9.001);
206 TEST((res - 4.789) < eps);
210 static void TestDef113884()
215 frexp(0.51E+2, &exponent);
222 // Added 'LL' as GCC needs to know these are explicitly 'long long'
223 pow(34523543434234LL , 23423432234LL);
224 TEST2(errno, ERANGE);
226 pow(-34523543434234LL , -23423432234LL);
227 TEST2(errno, ERANGE);
261 TEST2(errno, ERANGE);
264 TEST2(errno, ERANGE);
274 TEST2(errno, ERANGE);
284 TEST2(errno, ERANGE);
293 #pragma diag_suppress 222 //armv5 Warning #222-D is an echo of the following test. We want to ensure that the test reports the error as well.
295 #pragma warning (disable: 222) //winscw Warning #222-D is an echo of the following test. We want to ensure that the test reports the error as well.
298 sqrt(2.0 * HUGE_VAL);
299 TEST2(errno, ERANGE);
301 #pragma diag_default 222 //armv5 Warning #222-D turned back on.
303 #pragma warning (default: 222) //winscw Warning #222-D turned back on.
309 #pragma warning (disable: 222) //Warning #222-D is an echo of the following test.
313 #pragma warning (default: 222) //Warning #222-D is an echo of the following test.
334 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STDLIB-LEGACY-TMISC3-0001 CTYPE tests "));
337 TheTest.Next(_L("MATH tests"));
340 TheTest.Next(_L("MATH DEF113884 tests"));
350 CTrapCleanup* tc = CTrapCleanup::New();
354 TRAPD(err, ::MainL());
355 TEST2(err, KErrNone);
364 User::Heap().Check();