Update contrib.
1 // Copyright (c) 2004-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\cppexceptions\t_romtable2.cpp
16 // Check exceptions in RAM loaded image.
20 // - Throw and catch a variety of exceptions and verify
21 // results are as expected.
22 // Platforms/Drives/Compatibility:
23 // Hardware (Automatic).
24 // Assumptions/Requirement/Pre-requisites:
25 // Failures and causes:
26 // Base Port information:
33 GLDEF_D RTest test(_L("T_ROMTABLE"));
40 void TestUncaught(void);
42 GLDEF_C TInt E32Main()
44 test.Start(_L("Check exceptions in RAM loaded image."));
46 test.Printf(_L("Throwing first exception.\n"));
48 test.Printf(_L("Returned %d expected 2\n"), r);
51 test.Printf(_L("Not throwing first exception.\n"));
53 test.Printf(_L("Returned %d expected -1\n"), r);
56 test.Printf(_L("Throwing second exception.\n"));
58 test.Printf(_L("Returned %d expected 3\n"), r);
61 test.Printf(_L("Not throwing second exception.\n"));
63 test.Printf(_L("Returned %d expected -1\n"), r);
66 test.Printf(_L("Throwing third exception.\n"));
68 test.Printf(_L("Returned %d expected 4\n"), r);
71 test.Printf(_L("Not throwing third exception.\n"));
73 test.Printf(_L("Returned %d expected -1\n"), r);
76 test.Printf(_L("Throwing fourth exception.\n"));
78 test.Printf(_L("Returned %d expected 5\n"), r);
81 test.Printf(_L("Not throwing fourth exception.\n"));
83 test.Printf(_L("Returned %d expected -1\n"), r);
86 test.Printf(_L("Throwing fifth exception.\n"));
88 test.Printf(_L("Returned %d expected 6\n"), r);
91 test.Printf(_L("Not throwing fifth exception.\n"));
93 test.Printf(_L("Returned %d expected -1\n"), r);
96 test.Printf(_L("Testing std::uncaught_exception.\n"));
106 class MyFirstException {
108 MyFirstException(int x) { iVal = x; };
109 virtual ~MyFirstException();
113 MyFirstException::~MyFirstException(){}
115 int thrower (int x) {
116 #ifdef __SUPPORT_CPP_EXCEPTIONS__
117 if (x != 0) throw MyFirstException(x);
118 #else //!__SUPPORT_CPP_EXCEPTIONS__
122 #endif //__SUPPORT_CPP_EXCEPTIONS__
127 #ifdef __SUPPORT_CPP_EXCEPTIONS__
129 #endif //__SUPPORT_CPP_EXCEPTIONS__
131 #ifdef __SUPPORT_CPP_EXCEPTIONS__
133 catch(MyFirstException& e)
137 #endif //__SUPPORT_CPP_EXCEPTIONS__
141 #include "second_excp.h"
144 int catcher2(int x) {
145 #ifdef __SUPPORT_CPP_EXCEPTIONS__
147 #endif //__SUPPORT_CPP_EXCEPTIONS__
149 #ifdef __SUPPORT_CPP_EXCEPTIONS__
151 catch(MySecondException& e)
155 #endif //__SUPPORT_CPP_EXCEPTIONS__
158 int catcher3(int x) {
159 #ifdef __SUPPORT_CPP_EXCEPTIONS__
161 #endif //__SUPPORT_CPP_EXCEPTIONS__
163 #ifdef __SUPPORT_CPP_EXCEPTIONS__
165 catch(MyThirdException& e)
169 #endif //__SUPPORT_CPP_EXCEPTIONS__
172 int catcher4(int x) {
173 #ifdef __SUPPORT_CPP_EXCEPTIONS__
175 #endif //__SUPPORT_CPP_EXCEPTIONS__
177 #ifdef __SUPPORT_CPP_EXCEPTIONS__
179 catch(MyFourthException& e)
183 #endif //__SUPPORT_CPP_EXCEPTIONS__
186 int catcher5(int x) {
187 #ifdef __SUPPORT_CPP_EXCEPTIONS__
189 #endif //__SUPPORT_CPP_EXCEPTIONS__
191 #ifdef __SUPPORT_CPP_EXCEPTIONS__
193 catch(MyFifthException& e)
197 #endif //__SUPPORT_CPP_EXCEPTIONS__
200 void TestUncaught(void) {
202 #ifdef __SUPPORT_CPP_EXCEPTIONS__
204 UncaughtTester aTester(x);
205 test.Printf(_L("Check throw case\n"));
209 catch(MyFirstException& /*e*/)
211 #if defined(__MSVCDOTNET__) || (defined(__CW32__) && (__MWERKS__ > 0x3200)) || defined(__EABI__)
212 test.Printf(_L("~Check x == 2\n"));
215 test.Printf(_L("Checking x == 1, as std::uncaught_exception() broken\n"));
220 #endif //__SUPPORT_CPP_EXCEPTIONS__
222 UncaughtTester aTester(x);
223 test.Printf(_L("Check no throw case\n"));
225 #ifdef __SUPPORT_CPP_EXCEPTIONS__
226 catch(MyFirstException& /*e*/)
228 test.Printf(_L("Whoops!!!\n"));
230 #endif //__SUPPORT_CPP_EXCEPTIONS__