sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\cppexceptions\t_unmap2.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32std.h>
|
sl@0
|
19 |
#include <e32std_private.h>
|
sl@0
|
20 |
#include <e32base.h>
|
sl@0
|
21 |
#include <e32base_private.h>
|
sl@0
|
22 |
#include <e32test.h>
|
sl@0
|
23 |
#include "d_unmap.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
_LIT(KTestName, "t_unmap2");
|
sl@0
|
26 |
RTest test(KTestName);
|
sl@0
|
27 |
RSemaphore WaitSemaphore;
|
sl@0
|
28 |
RSemaphore SignalSemaphore;
|
sl@0
|
29 |
|
sl@0
|
30 |
void TestLibraryCleanup();
|
sl@0
|
31 |
|
sl@0
|
32 |
TInt E32Main()
|
sl@0
|
33 |
{
|
sl@0
|
34 |
test.Start(_L("Check code seg unmapping over User::Leave()/C++ exceptions."));
|
sl@0
|
35 |
|
sl@0
|
36 |
__UHEAP_MARK;
|
sl@0
|
37 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
38 |
TInt r = KErrNoMemory;
|
sl@0
|
39 |
if (cleanup)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
test.Printf(_L("Opening semaphores for barrier with other process\n"));
|
sl@0
|
42 |
test(WaitSemaphore.Open(1)==KErrNone);
|
sl@0
|
43 |
test(SignalSemaphore.Open(2)==KErrNone);
|
sl@0
|
44 |
TRAP(r, TestLibraryCleanup());
|
sl@0
|
45 |
test.Printf(_L("Returned %d, expected %d\n"), r, KErrGeneral);
|
sl@0
|
46 |
test(r == KErrGeneral);
|
sl@0
|
47 |
WaitSemaphore.Close();
|
sl@0
|
48 |
SignalSemaphore.Close();
|
sl@0
|
49 |
r = KErrNone;
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
delete cleanup;
|
sl@0
|
53 |
__UHEAP_MARKEND;
|
sl@0
|
54 |
|
sl@0
|
55 |
test.End();
|
sl@0
|
56 |
return r;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
void Checkpoint(TAny*)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
test.Printf(_L("Checkpointing...\n"));
|
sl@0
|
62 |
SignalSemaphore.Signal();
|
sl@0
|
63 |
WaitSemaphore.Wait();
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
void TestLibraryCleanup()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
test.Printf(_L("Loading DLL.\n"));
|
sl@0
|
69 |
RLibrary library;
|
sl@0
|
70 |
test(library.Load(KLeavingDll2) == KErrNone);
|
sl@0
|
71 |
|
sl@0
|
72 |
test.Printf(_L("Pushing cleanup item to synchronise after closing library handle.\n"));
|
sl@0
|
73 |
CleanupStack::PushL(TCleanupItem(&Checkpoint, NULL));
|
sl@0
|
74 |
|
sl@0
|
75 |
test.Printf(_L("Pushing handle to dynamically loaded DLL onto the cleanup stack.\n"));
|
sl@0
|
76 |
CleanupClosePushL(library);
|
sl@0
|
77 |
|
sl@0
|
78 |
test.Printf(_L("Pushing cleanup item to synchronise during leave\n"));
|
sl@0
|
79 |
CleanupStack::PushL(TCleanupItem(&Checkpoint, NULL));
|
sl@0
|
80 |
|
sl@0
|
81 |
test.Printf(_L("Looking up leaving function.\n"));
|
sl@0
|
82 |
TLibraryFunction leaving = library.Lookup(1);
|
sl@0
|
83 |
test(leaving != NULL);
|
sl@0
|
84 |
|
sl@0
|
85 |
test.Printf(_L("Check-point whilst holding the open library handle.\n"));
|
sl@0
|
86 |
Checkpoint(NULL);
|
sl@0
|
87 |
|
sl@0
|
88 |
test.Printf(_L("Calling leaving function.\n"));
|
sl@0
|
89 |
(*leaving)();
|
sl@0
|
90 |
|
sl@0
|
91 |
test.Printf(_L("Cleaning up checkpoint operation.\n"));
|
sl@0
|
92 |
CleanupStack::Pop(); // pause leave op
|
sl@0
|
93 |
|
sl@0
|
94 |
test.Printf(_L("Cleaning up DLL handle.\n"));
|
sl@0
|
95 |
CleanupStack::PopAndDestroy();
|
sl@0
|
96 |
|
sl@0
|
97 |
test.Printf(_L("Cleaning up checkpoint operation.\n"));
|
sl@0
|
98 |
CleanupStack::Pop(); // pause leave op
|
sl@0
|
99 |
}
|