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_slave.cpp
18 #define __E32TEST_EXTENSION__
21 #include <e32std_private.h>
24 #include <e32msgqueue.h>
26 #include "t_destruct.h"
28 _LIT(KDynamicDll, "t_destruct_dll2");
39 RTest test(_L("t_desruct_slave"));
40 TThreadId MainThreadId;
41 TTestObject GlobalObjectWithDestructor;
43 void Panic(TInt aReason)
45 User::Panic(_L("t_destruct_slave"), aReason);
48 TInt ExitThread(TAny*)
53 TInt PanicThread(TAny*)
59 TInt LoopThread(TAny*)
61 // Open handle on dynamic DLL in this thread
63 test_KErrNone(library.Load(KDynamicDll));
68 TInt ChildThread(TAny* aArg)
70 TInt testType = (TInt)aArg;
72 TInt r = mainThread.Open(MainThreadId);
75 // Open handle on dynamic DLL in this thread
77 test_KErrNone(library.Load(KDynamicDll));
78 RThread().Rendezvous(KErrNone);
79 TRequestStatus status;
80 mainThread.Logon(status);
81 User::WaitForRequest(status);
82 if (mainThread.ExitType() != EExitKill)
84 if (mainThread.ExitReason() != KErrNone)
85 return mainThread.ExitReason();
87 if (testType != ETestRecursive)
89 RMsgQueue<TMessage> messageQueue;
90 r = messageQueue.OpenGlobal(KMessageQueueName);
93 r = messageQueue.Send(EMessagePreDestruct);
100 TInt PermanentThread(TAny* aArg)
102 TInt testType = (TInt)aArg;
103 // Open handle on dynamic DLL in this thread
105 TInt r = library.Load(KDynamicDll);
108 RMsgQueue<TMessage> messageQueue;
109 r = messageQueue.OpenGlobal(KMessageQueueName);
112 r = messageQueue.Send(EMessagePreDestruct);
115 messageQueue.Close();
116 User::SetCritical(User::EProcessPermanent);
117 User::Exit(testType);
121 TTestObject::TTestObject()
123 RDebug::Printf("t_destruct_slave constructor called\n");
124 RMsgQueue<TMessage> messageQueue;
125 TInt r = messageQueue.OpenGlobal(KMessageQueueName);
128 messageQueue.Send(EMessageConstruct);
133 TTestObject::~TTestObject()
135 RDebug::Printf("t_destruct_slave destructor called\n");
136 if (iTestType == ETestRecursive)
138 // Start child thread passing this thread's id
139 MainThreadId = RThread().Id();
141 test_KErrNone(childThread.Create(_L("ChildThread"), ChildThread, 4096, NULL, (TAny*)iTestType));
142 TRequestStatus status;
143 childThread.Rendezvous(status);
144 childThread.Resume();
146 // Wait for child to open handle on this thread
147 User::WaitForRequest(status);
148 test_KErrNone(status.Int());
151 // Set this thread non-critical
152 User::SetCritical(User::ENotCritical);
154 else if (iTestType == ETestDestructorExits)
156 User::Exit(iTestType);
159 RMsgQueue<TMessage> messageQueue;
160 TInt r = messageQueue.OpenGlobal(KMessageQueueName);
163 messageQueue.Send(EMessageDestruct);
173 test_KErrNone(cmd.Create(User::CommandLineLength()));
174 User::CommandLine(cmd);
178 test_KErrNone(lex.Val((TInt&)type));
179 GlobalObjectWithDestructor.iTestType = type;
181 RMsgQueue<TMessage> messageQueue;
182 test_KErrNone(messageQueue.OpenGlobal(KMessageQueueName));
184 // Dynamically load DLL with global data
186 test_KErrNone(library.Load(KDynamicDll));
190 case ETestMainThreadReturn:
191 test_KErrNone(messageQueue.Send(EMessagePreDestruct));
194 case ETestMainThreadExit:
195 test_KErrNone(messageQueue.Send(EMessagePreDestruct));
199 case ETestChildThreadReturn:
201 // Start child thread passing this thread's id
202 MainThreadId = RThread().Id();
204 test_KErrNone(childThread.Create(_L("ChildThread"), ChildThread, 4096, NULL, (TAny*)type));
205 TRequestStatus status;
206 childThread.Rendezvous(status);
207 childThread.Resume();
211 // Wait for child to open handle on this thread
212 User::WaitForRequest(status);
213 test_KErrNone(status.Int());
216 // Set this thread non-critical and exit
217 User::SetCritical(User::ENotCritical);
221 case ETestOtherThreadExit:
224 test_KErrNone(childThread.Create(_L("ChildThread"), ExitThread, 4096, NULL, (TAny*)type));
225 childThread.Resume();
226 TRequestStatus status;
227 childThread.Logon(status);
228 User::WaitForRequest(status);
229 test_KErrNone(status.Int());
231 test_KErrNone(messageQueue.Send(EMessagePreDestruct));
235 case ETestOtherThreadPanic:
238 test_KErrNone(childThread.Create(_L("ChildThread"), PanicThread, 4096, NULL, (TAny*)type));
239 childThread.Resume();
240 TRequestStatus status;
241 childThread.Logon(status);
242 User::WaitForRequest(status);
243 test_KErrNone(status.Int());
245 test_KErrNone(messageQueue.Send(EMessagePreDestruct));
249 case ETestOtherThreadRunning:
252 test_KErrNone(childThread.Create(_L("ChildThread"), LoopThread, 4096, NULL, (TAny*)type));
253 childThread.Resume();
255 test_KErrNone(messageQueue.Send(EMessagePreDestruct));
259 case ETestPermanentThreadExit:
262 test_KErrNone(childThread.Create(_L("ChildThread"), PermanentThread, 4096, NULL, (TAny*)type));
263 childThread.Resume();
264 TRequestStatus status;
265 childThread.Logon(status);
266 User::WaitForRequest(status);
267 test_KErrNone(status.Int());
273 test_KErrNone(messageQueue.Send(EMessagePreDestruct));
276 case ETestDestructorExits:
277 test_KErrNone(messageQueue.Send(EMessagePreDestruct));
280 case ETestLastThreadPanic:
281 test_KErrNone(messageQueue.Send(EMessagePreDestruct));