Update contrib.
1 // Copyright (c) 2006-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.
26 static RTest TheTest(_L("T_SPRINTF"));
30 //Test macro and function
32 static void Check(TInt aValue, TInt aLine)
36 TheTest(EFalse, aLine);
40 #define TEST(arg) ::Check((arg), __LINE__)
46 @SYMTestCaseID SYSLIB-STDLIB-UT-1670
47 @SYMTestCaseDesc Making sure that error codes are returned from sprintf when when out of memory.
48 @SYMTestPriority Critical
49 @SYMTestActions Sets heap failures to occur at different stages and calls sprintf. The sprintf function should return with error codes
51 @SYMTestExpectedResults The test should not fail.
56 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-UT-1670 DEF083988 - Prop: sprintf panics with ESTLIB-INIT 0 when out of memory "));
60 char* hw = "How are you?";
66 ret = sprintf(buf, "Hello");
67 TEST(ret == err); // Error returned as memory needed to be allocated, but none was spare.
71 ret = sprintf(buf, "Hello");
72 TEST(ret == 5); // No Error, as memory allocation failure did not affected sprintf.
73 TEST(strcmp(buf, "Hello")==0);
75 // Releases all the STDLIB resources so memory for the globals will need to be allocated once more.
82 ret = sprintf(buf, "Hello");
83 TEST(ret == err); // Error returned as memory needed to be allocated, but none was spare.
89 ret = sprintf(buf, "Hello");
90 TEST(strcmp(buf, "Hello") == 0);
91 TEST(ret == 5); // Returns the number of characters printed.
93 ret = sprintf(buf, hw);
94 TEST(strcmp(buf, "How are you?") == 0);
95 TEST(ret == 12); // Returns the number of characters printed, as the memory is already allocated.
99 ret = sprintf(buf, hw);
100 TEST(strcmp(buf, "How are you?") == 0);
101 TEST(ret == 12); // Returns the number of characters printed, as the memory is already allocated.
107 ret = sprintf(buf, "How are you?");
108 TEST(strcmp(buf, "How are you?") == 0);
109 TEST(ret == 12); // Returns the number of characters printed, as the memory is able to be allocated.
119 TheTest.Start(_L("Defect..."));
120 DEF083988(); //DEF083988 - Prop: sprintf panics with ESTLIB-INIT 0 when out of memory
128 CTrapCleanup* tc = CTrapCleanup::New();
144 User::Heap().Check();