Update contrib.
1 // Copyright (c) 2007-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\misc\t_destruct.cpp
15 // Test that global objects are destroyed correctly
19 #define __E32TEST_EXTENSION__
22 #include <e32std_private.h>
24 #include <e32ldr_private.h>
27 #include <e32msgqueue.h>
29 #include "t_destruct.h"
31 _LIT(KDestructSlave, "t_destruct_slave");
33 const char* KMessageNames[] =
46 RTest test(_L("t_destruct"));
47 RMsgQueue<TMessage> MessageQueue;
49 void TestNextMessage(TMessage aExpected, TBool& ok)
52 TInt r = MessageQueue.Receive(message);
53 if (r == KErrUnderflow)
55 RDebug::Printf(" * expected message %s but got underflow", KMessageNames[aExpected]);
60 test(message < ENumMessges);
61 test(aExpected < ENumMessges);
62 if (message == aExpected)
63 RDebug::Printf(" - received message %s", KMessageNames[message]);
66 RDebug::Printf(" * expected message %s but got %s", KMessageNames[aExpected], KMessageNames[message]);
71 void TestDestruction(TTestType aTestType)
74 cmd.AppendFormat(_L("%d"), aTestType);
77 test_KErrNone(p.Create(KDestructSlave, cmd));
79 TRequestStatus status;
82 User::WaitForRequest(status);
84 TExitType expectedExit = aTestType != ETestLastThreadPanic ? EExitKill : EExitPanic;
85 test_Equal(expectedExit, p.ExitType());
86 test_Equal(aTestType, p.ExitReason());
93 TestNextMessage(EMessageConstructStatic3, ok);
94 TestNextMessage(EMessageConstructStatic, ok);
95 TestNextMessage(EMessageConstruct, ok);
96 TestNextMessage(EMessageConstructDynamic, ok);
97 TestNextMessage(EMessagePreDestruct, ok);
99 if (aTestType != ETestLastThreadPanic && aTestType != ETestDestructorExits)
101 TestNextMessage(EMessageDestruct, ok);
102 TestNextMessage(EMessageDestructStatic, ok);
103 TestNextMessage(EMessageDestructStatic3, ok);
106 if (aTestType != ETestLastThreadPanic)
107 TestNextMessage(EMessageDestructDynamic, ok);
110 test_Equal(KErrUnderflow, MessageQueue.Receive(message));
116 test.Start(_L("t_destruct"));
118 // Turn off evil lazy dll unloading
120 test_KErrNone(l.Connect());
121 test_KErrNone(l.CancelLazyDllUnload());
124 test_KErrNone(MessageQueue.CreateGlobal(KMessageQueueName, 10));
126 test.Next(_L("Test global object destruction when main thread returns"));
127 TestDestruction(ETestMainThreadReturn);
129 test.Next(_L("Test global object destruction when main thread exits"));
130 TestDestruction(ETestMainThreadExit);
132 test.Next(_L("Test global object destruction when child thread exits"));
133 TestDestruction(ETestChildThreadReturn);
135 test.Next(_L("Test global object destruction when other thread has exited"));
136 TestDestruction(ETestOtherThreadExit);
138 test.Next(_L("Test global object destruction when other thread has panicked"));
139 TestDestruction(ETestOtherThreadPanic);
141 test.Next(_L("Test global object destruction when other thread killed by critial thread exit"));
142 TestDestruction(ETestOtherThreadRunning);
144 test.Next(_L("Test global object destruction when permanent thread exits"));
145 TestDestruction(ETestPermanentThreadExit);
147 test.Next(_L("Test global object destruction only happens once when destrctor creates new thread"));
148 TestDestruction(ETestRecursive);
150 test.Next(_L("Test global object destruction only happens once when destrctor calls User::Exit"));
151 TestDestruction(ETestDestructorExits);
153 test.Next(_L("Test NO global object destruction when last thread panics"));
154 TestDestruction(ETestLastThreadPanic);