Update contrib.
1 // Copyright (c) 1995-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 the License "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 // e32test\system\t_ref.cpp
16 // Test the methods of the RRef class.
20 // - Check for the existence of all RRef methods.
21 // - Test and verify the results of the RRef constructors.
22 // - Test and verify the results of the RRef assignment methods.
23 // - Test and verify the results of the RRef smart pointer methods.
24 // - Attempt to allocate all available heap space, verify that it
26 // - Test and verify the results of the RRef allocation methods.
27 // Platforms/Drives/Compatibility:
29 // Assumptions/Requirement/Pre-requisites:
30 // Failures and causes:
31 // Base Port information:
37 LOCAL_D RTest test(_L("T_REF"));
52 anObj.aBuf=_L("Hello World");
55 RRef<SObj> aRef2(aRef1);
58 test(aRef1->iInt==10);
59 test(((SObj*)aRef1)->aBuf==_L("Hello World"));
72 anObj.aBuf=_L("Hello World");
75 RRef<SObj> aRef2(aRef1);
76 test(aRef1->iInt==10);
77 test(aRef1->aBuf==_L("Hello World"));
78 test(aRef2->iInt==10);
79 test(aRef2->aBuf==_L("Hello World"));
93 anObj.aBuf=_L("Hello World");
98 test(aRef1->iInt==10);
99 test(aRef1->aBuf==_L("Hello World"));
100 test(aRef2->iInt==10);
101 test(aRef2->aBuf==_L("Hello World"));
109 // Smart Pointer methods
113 anObj.aBuf=_L("Hello World");
116 test(aRef1->iInt==10);
117 test(aRef1->aBuf==_L("Hello World"));
118 SObj* pObj=(SObj*)aRef1;
119 test(pObj->iInt==10);
120 test(pObj->aBuf==_L("Hello World"));
123 void allocAllL(TInt*& aPtr,RRef<SObj>& aRef1,SObj& anObj)
125 // Alloc all and cause leave.
130 TInt avail=User::Available(temp);
131 aPtr=(TInt*)User::AllocL(avail);
136 Reinstate if some method is found of forcing alloc fail
137 This test no longer works due to heap growing functionality of E32 057
139 ... so leave with KErrNoMemory to simulate alloc failure
141 User::Leave(KErrNoMemory);
146 // Allocation methods
153 anObj.aBuf=_L("Hello World");
156 test(aRef1->iInt==10);
157 test(aRef1->aBuf==_L("Hello World"));
158 aRef1.Alloc(anObj,sizeof(SObj)-245*sizeof(TText));
159 test(aRef1->iInt==10);
160 test(aRef1->aBuf==_L("Hello World"));
162 test(aRef1->iInt==10);
163 test(aRef1->aBuf==_L("Hello World"));
164 aRef1.AllocL(anObj,sizeof(SObj)-245*sizeof(TText));
165 test(aRef1->iInt==10);
166 test(aRef1->aBuf==_L("Hello World"));
168 TRAPD(ret,allocAllL(p,aRef1,anObj))
169 test(ret==KErrNoMemory);
172 test(aRef1->iInt==10);
173 test(aRef1->aBuf==_L("Hello World"));
182 test.Start(_L("class RRef"));
183 test.Next(_L("Test all methods"));
185 test.Next(_L("Constructors"));
187 test.Next(_L("Assignment methods"));
189 test.Next(_L("Smart pointer methods"));
191 test.Next(_L("Allocation methods"));