|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\cppexceptions\d_unmap.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32std_private.h> |
|
20 #include <e32base.h> |
|
21 #include <e32base_private.h> |
|
22 #include "d_unmap.h" |
|
23 |
|
24 class TAlwaysTrue |
|
25 { |
|
26 public: |
|
27 TBool val; |
|
28 TAlwaysTrue() { val = ETrue; } |
|
29 ~TAlwaysTrue() { val = EFalse; } |
|
30 }; |
|
31 |
|
32 #ifndef NO_STATIC_DATA |
|
33 static TAlwaysTrue alwaysTrue; |
|
34 #endif |
|
35 |
|
36 // Test C++ stack unwinding |
|
37 class TNeedsCxxCleanup |
|
38 { |
|
39 public: |
|
40 TNeedsCxxCleanup() : iPtr(NULL) {} |
|
41 ~TNeedsCxxCleanup() { delete iPtr; } |
|
42 private: |
|
43 TInt* iPtr; |
|
44 }; |
|
45 |
|
46 void AnotherStackLevelL() |
|
47 { |
|
48 TNeedsCxxCleanup foo; |
|
49 User::Leave(KErrGeneral); |
|
50 } |
|
51 |
|
52 EXPORT_C void Ordinal1L() |
|
53 { |
|
54 TNeedsCxxCleanup bar; |
|
55 AnotherStackLevelL(); |
|
56 } |
|
57 |
|
58 // Test DLL unloading |
|
59 NONSHARABLE_CLASS( CDllUnloader ) : public CTimer |
|
60 { |
|
61 public: |
|
62 static CDllUnloader* NewL(); |
|
63 |
|
64 private: |
|
65 CDllUnloader(); |
|
66 void ConstructL(); |
|
67 |
|
68 private: |
|
69 void RunL(); |
|
70 |
|
71 private: |
|
72 RLibrary iLibrary; |
|
73 }; |
|
74 |
|
75 |
|
76 CDllUnloader::CDllUnloader() |
|
77 : CTimer(EPriorityNormal) |
|
78 { |
|
79 CActiveScheduler::Add(this); |
|
80 } |
|
81 |
|
82 void CDllUnloader::ConstructL() |
|
83 { |
|
84 CTimer::ConstructL(); |
|
85 User::LeaveIfError(iLibrary.Load(KLeavingDll)); |
|
86 } |
|
87 |
|
88 CDllUnloader* CDllUnloader::NewL() |
|
89 { |
|
90 CDllUnloader* self = new(ELeave) CDllUnloader(); |
|
91 CleanupStack::PushL(self); |
|
92 self->ConstructL(); |
|
93 CleanupStack::Pop(self); |
|
94 return self; |
|
95 } |
|
96 |
|
97 void CDllUnloader::RunL() |
|
98 { |
|
99 // Temporary copy of handle |
|
100 RLibrary library(iLibrary); |
|
101 |
|
102 // Prevent the AS calling back into us later |
|
103 // - everything is poison now |
|
104 delete this; |
|
105 |
|
106 // Push the library handle onto the cleanupstack for euser to clean up |
|
107 CleanupClosePushL(library); |
|
108 |
|
109 // Prevent [Run]Error() from being called... |
|
110 // - effect thread diversion out of the DLL |
|
111 // - and breath a sigh of relief that you've been so cunning |
|
112 User::Leave(KErrNone); |
|
113 } |
|
114 |
|
115 EXPORT_C TBool Ordinal2() |
|
116 { |
|
117 /* |
|
118 CDllUnloader* unloader = CDllUnloader::NewL(); |
|
119 unloader->After(1000000); |
|
120 */ |
|
121 #ifdef NO_STATIC_DATA |
|
122 return EFalse; |
|
123 #else |
|
124 return alwaysTrue.val; |
|
125 #endif |
|
126 } |
|
127 |