0
|
1 |
// Copyright (c) 1995-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\active\t_messge.cpp
|
|
15 |
// Overview:
|
|
16 |
// Test the RMessage2 and RMessagePtr2 classes.
|
|
17 |
// API Information:
|
|
18 |
// RMessage2, RMessagePtr2, RSessionBase, CSession2, CServer2
|
|
19 |
// Details:
|
|
20 |
// - Verify copy constructor and assignment operator of Rmessage2 is implemented correctly.
|
|
21 |
// - Verify default constructor, copy constructor and assignment operator of RMessagePtr2
|
|
22 |
// is implemented correctly, construct RMessagePtr2 from pointer to RMessage2 and verify
|
|
23 |
// that it is constructed successfully.
|
|
24 |
// - Create client and server threads, open a session with specified number of message slots
|
|
25 |
// - Send integer message arguments from client and test that the server receives the
|
|
26 |
// same integers.
|
|
27 |
// - Send pointers as message arguments from client and test that the server receives the
|
|
28 |
// same pointers.
|
|
29 |
// - Test Client() method of RMessage2 and verify it opened a handle to the client thread
|
|
30 |
// - Complete several messages using RMessage2::Complete and verify the client gets the
|
|
31 |
// error codes back correctly.
|
|
32 |
// - Complete several messages using RMessagePtr2::Complete and verify the client gets the
|
|
33 |
// error codes back correctly.
|
|
34 |
// - Check RMessage construction from RMessagePtr2 is successful.
|
|
35 |
// - Check creation of other sessions to the same server is successful.
|
|
36 |
// - Check the server return KErrServerBusy when client has more outstanding requests than
|
|
37 |
// available message slots.
|
|
38 |
// - Send stop signal and check that the server has stopped as expected.
|
|
39 |
// - Check the client and server have exited as expected.
|
|
40 |
// - Create client and server threads, open a connection to the server and verify that
|
|
41 |
// - Server is panicked when completing a message twice.
|
|
42 |
// Platforms/Drives/Compatibility:
|
|
43 |
// All.
|
|
44 |
// Assumptions/Requirement/Pre-requisites:
|
|
45 |
// Failures and causes:
|
|
46 |
// Base Port information:
|
|
47 |
//
|
|
48 |
//
|
|
49 |
|
|
50 |
#include <e32std.h>
|
|
51 |
#include <e32std_private.h>
|
|
52 |
#include <e32test.h>
|
|
53 |
#include <e32panic.h>
|
|
54 |
|
|
55 |
const TInt KHeapMinSize=0x1000;
|
|
56 |
const TInt KHeapMaxSize=0x1000;
|
|
57 |
|
|
58 |
_LIT(KServerName,"CTestServer");
|
|
59 |
|
|
60 |
class CTestServer : public CServer2
|
|
61 |
{
|
|
62 |
public:
|
|
63 |
IMPORT_C CTestServer(TInt aPriority);
|
|
64 |
enum TPanicType{
|
|
65 |
EInt0Error=1, EInt1Error, EInt2Error, EInt3Error,
|
|
66 |
EPtr0Error, EPtr1Error, EPtr2Error, EPtr3Error,
|
|
67 |
ECreateNameError, ENewSessionError,
|
|
68 |
EClientError
|
|
69 |
};
|
|
70 |
static void Panic(TPanicType aReason);
|
|
71 |
protected:
|
|
72 |
//override the pure virtual functions:
|
|
73 |
IMPORT_C virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
|
|
74 |
};
|
|
75 |
|
|
76 |
|
|
77 |
class CTestSession : public CSession2
|
|
78 |
{
|
|
79 |
public:
|
|
80 |
enum {EStop,ETestInt,ETestPtr,ETestClient,ETestComplete,ETestPtrComplete,ETestCompletePanic,ETestOtherSession,ETestCompleteAfter,ETestMessageConstruction, ETestRMessagePtr2LeavingInterface};
|
|
81 |
//Override pure virtual
|
|
82 |
IMPORT_C virtual void ServiceL(const RMessage2& aMessage);
|
|
83 |
private:
|
|
84 |
void TestInt(const RMessage2& aMessage);
|
|
85 |
void TestPtr(const RMessage2& aMessage);
|
|
86 |
void TestClient(const RMessage2& aMessage);
|
|
87 |
void TestComplete(const RMessage2& aMessage);
|
|
88 |
void TestPtrComplete(const RMessage2& aMessage);
|
|
89 |
void TestCompletePanic();
|
|
90 |
TInt TestMessageConstruction(const RMessage2& aMessage);
|
|
91 |
TInt TestRMessagePtr2LeavingInterface(const RMessage2& aMessage);
|
|
92 |
//
|
|
93 |
TInt count1;//initially ==0
|
|
94 |
RMessage2 messages[5];//Used in TestComplete()
|
|
95 |
//
|
|
96 |
TInt count2;//initially ==0
|
|
97 |
RMessagePtr2 messagePtrs[5];//User in TestPtrComplete()
|
|
98 |
};
|
|
99 |
|
|
100 |
|
|
101 |
class CMyActiveScheduler : public CActiveScheduler
|
|
102 |
{
|
|
103 |
public:
|
|
104 |
virtual void Error(TInt anError) const; //override pure virtual error function
|
|
105 |
};
|
|
106 |
|
|
107 |
|
|
108 |
class RSession : public RSessionBase
|
|
109 |
{
|
|
110 |
public:
|
|
111 |
TInt PublicSendReceive(TInt aFunction, const TIpcArgs &aPtr)
|
|
112 |
{
|
|
113 |
return (SendReceive(aFunction, aPtr));
|
|
114 |
}
|
|
115 |
void PublicSendReceive(TInt aFunction, const TIpcArgs &aPtr, TRequestStatus& aStatus)
|
|
116 |
{
|
|
117 |
SendReceive(aFunction, aPtr, aStatus);
|
|
118 |
}
|
|
119 |
TInt PublicCreateSession(const TDesC& aServer,TInt aMessageSlots)
|
|
120 |
{
|
|
121 |
return (CreateSession(aServer,User::Version(),aMessageSlots));
|
|
122 |
}
|
|
123 |
};
|
|
124 |
|
|
125 |
// CTestServer functions
|
|
126 |
|
|
127 |
CTestServer::CTestServer(TInt aPriority)
|
|
128 |
//
|
|
129 |
// Constructor - sets name
|
|
130 |
//
|
|
131 |
: CServer2(aPriority)
|
|
132 |
{}
|
|
133 |
|
|
134 |
CSession2* CTestServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/) const
|
|
135 |
//
|
|
136 |
// Virtual fn - checks version supported and creates a CTestSession
|
|
137 |
//
|
|
138 |
{
|
|
139 |
TVersion version(KE32MajorVersionNumber,KE32MinorVersionNumber,KE32BuildVersionNumber);
|
|
140 |
if (User::QueryVersionSupported(version,aVersion)==EFalse)
|
|
141 |
User::Leave(KErrNotSupported);
|
|
142 |
CTestSession* newCTestSession = new CTestSession;
|
|
143 |
if (newCTestSession==NULL)
|
|
144 |
Panic(ENewSessionError);
|
|
145 |
return(newCTestSession);
|
|
146 |
}
|
|
147 |
|
|
148 |
RThread clientThread, serverThread;
|
|
149 |
|
|
150 |
void CTestServer::Panic(TPanicType aReason) //static function
|
|
151 |
{
|
|
152 |
clientThread.Kill(KErrNone);
|
|
153 |
User::Panic(_L("CTestServer"),aReason);
|
|
154 |
}
|
|
155 |
|
|
156 |
RSession session, otherSession;
|
|
157 |
RSemaphore sem;
|
|
158 |
|
|
159 |
const TInt KTestInt[] = {-3866,30566,0,200};
|
|
160 |
|
|
161 |
void CTestSession::TestInt(const RMessage2& aMessage)
|
|
162 |
//
|
|
163 |
// Tests to see that the correct Int0/1/2/3 have been received
|
|
164 |
//
|
|
165 |
{
|
|
166 |
if (aMessage.Int0()!=KTestInt[0])
|
|
167 |
CTestServer::Panic(CTestServer::EInt0Error);
|
|
168 |
if (aMessage.Int1()!=KTestInt[1])
|
|
169 |
CTestServer::Panic(CTestServer::EInt1Error);
|
|
170 |
if (aMessage.Int2()!=KTestInt[2])
|
|
171 |
CTestServer::Panic(CTestServer::EInt2Error);
|
|
172 |
if (aMessage.Int3()!=KTestInt[3])
|
|
173 |
CTestServer::Panic(CTestServer::EInt3Error);
|
|
174 |
}
|
|
175 |
|
|
176 |
const TAny* KTestPtr[]={&clientThread, &serverThread, &session, &sem};
|
|
177 |
|
|
178 |
void CTestSession::TestPtr(const RMessage2& aMessage)
|
|
179 |
//
|
|
180 |
// Tests to see that the correct Ptr0/1/2/3 have been received
|
|
181 |
//
|
|
182 |
{
|
|
183 |
if (aMessage.Ptr0()!=KTestPtr[0])
|
|
184 |
CTestServer::Panic(CTestServer::EPtr0Error);
|
|
185 |
if (aMessage.Ptr1()!=KTestPtr[1])
|
|
186 |
CTestServer::Panic(CTestServer::EPtr1Error);
|
|
187 |
if (aMessage.Ptr2()!=KTestPtr[2])
|
|
188 |
CTestServer::Panic(CTestServer::EPtr2Error);
|
|
189 |
if (aMessage.Ptr3()!=KTestPtr[3])
|
|
190 |
CTestServer::Panic(CTestServer::EPtr3Error);
|
|
191 |
}
|
|
192 |
|
|
193 |
void CTestSession::TestClient(const RMessage2& aMessage)
|
|
194 |
//
|
|
195 |
// Tests Client()
|
|
196 |
//
|
|
197 |
{
|
|
198 |
|
|
199 |
TFullName n=RProcess().Name();
|
|
200 |
n+=_L("::Client Thread");
|
|
201 |
RThread t;
|
|
202 |
TInt r=aMessage.Client(t);
|
|
203 |
if (r!=KErrNone)
|
|
204 |
User::Invariant();
|
|
205 |
if (t.FullName().CompareF(n)!=0)
|
|
206 |
{
|
|
207 |
clientThread.Kill(0);
|
|
208 |
CTestServer::Panic(CTestServer::EClientError);
|
|
209 |
}
|
|
210 |
t.Close();
|
|
211 |
}
|
|
212 |
|
|
213 |
void CTestSession::TestComplete(const RMessage2& aMessage)
|
|
214 |
//
|
|
215 |
// Stores messages up then Completes in reverse order
|
|
216 |
//
|
|
217 |
{
|
|
218 |
messages[count1] = aMessage;
|
|
219 |
if (++count1==5)
|
|
220 |
for(count1=4; count1>=0; count1--)
|
|
221 |
messages[count1].Complete(5-count1); //Complete with different 'error messages'
|
|
222 |
}
|
|
223 |
|
|
224 |
void CTestSession::TestPtrComplete(const RMessage2& aMessage)
|
|
225 |
//
|
|
226 |
// Stores messages up as RMessagePtrs then Completes in reverse order
|
|
227 |
// Also tests RMessage2::MessagePtr()
|
|
228 |
//
|
|
229 |
{
|
|
230 |
|
|
231 |
messagePtrs[count2] = aMessage;
|
|
232 |
__ASSERT_ALWAYS(!messagePtrs[count2].IsNull(), User::Invariant());
|
|
233 |
if (++count2==5)
|
|
234 |
for(count2=4; count2>=0; count2--)
|
|
235 |
{
|
|
236 |
messagePtrs[count2].Complete(10-count2*2);
|
|
237 |
__ASSERT_ALWAYS(messagePtrs[count2].IsNull(), User::Invariant());
|
|
238 |
}
|
|
239 |
}
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
TInt CTestSession::TestMessageConstruction(const RMessage2& aMessage)
|
|
244 |
{
|
|
245 |
RMessage2 m2((RMessagePtr2&)aMessage);
|
|
246 |
if(m2!=aMessage)
|
|
247 |
return KErrGeneral;
|
|
248 |
return KErrNone;
|
|
249 |
}
|
|
250 |
|
|
251 |
TInt CTestSession::TestRMessagePtr2LeavingInterface(const RMessage2& aMessage)
|
|
252 |
{
|
|
253 |
RThread thread1, thread2;
|
|
254 |
TProcessPriority priority = EPriorityForeground;
|
|
255 |
|
|
256 |
//Check that both Client and ClientL methods return the same thread and error code.
|
|
257 |
if (aMessage.Client(thread1))
|
|
258 |
return KErrGeneral;
|
|
259 |
|
|
260 |
TRAPD(r1, aMessage.ClientL(thread2))
|
|
261 |
if (KErrNone != r1)
|
|
262 |
{
|
|
263 |
thread1.Close();
|
|
264 |
return r1;
|
|
265 |
}
|
|
266 |
if (thread1.Id() != thread2.Id())
|
|
267 |
{
|
|
268 |
thread1.Close();
|
|
269 |
thread2.Close();
|
|
270 |
return KErrBadHandle;
|
|
271 |
}
|
|
272 |
|
|
273 |
//Check that both SetPriority & SetPriorityL methods return the same error code
|
|
274 |
r1 = aMessage.SetProcessPriority(priority);
|
|
275 |
TRAPD(r2, aMessage.SetProcessPriorityL(priority))
|
|
276 |
|
|
277 |
thread1.Close();
|
|
278 |
thread2.Close();
|
|
279 |
if (r1 != r2)
|
|
280 |
return KErrGeneral;
|
|
281 |
|
|
282 |
return KErrNone;
|
|
283 |
}
|
|
284 |
|
|
285 |
void CTestSession::ServiceL(const RMessage2& aMessage)
|
|
286 |
//
|
|
287 |
// Virtual message-handler
|
|
288 |
//
|
|
289 |
{
|
|
290 |
TInt r=KErrNone;
|
|
291 |
switch (aMessage.Function())
|
|
292 |
{
|
|
293 |
case EStop:
|
|
294 |
CActiveScheduler::Stop();
|
|
295 |
break;
|
|
296 |
case ETestInt:
|
|
297 |
TestInt(aMessage);
|
|
298 |
break;
|
|
299 |
case ETestPtr:
|
|
300 |
TestPtr(aMessage);
|
|
301 |
break;
|
|
302 |
case ETestClient:
|
|
303 |
TestClient(aMessage);
|
|
304 |
break;
|
|
305 |
case ETestComplete:
|
|
306 |
TestComplete(aMessage);
|
|
307 |
return;
|
|
308 |
case ETestPtrComplete:
|
|
309 |
TestPtrComplete(aMessage);
|
|
310 |
return;
|
|
311 |
case ETestCompletePanic:
|
|
312 |
aMessage.Complete(KErrNone);
|
|
313 |
break;
|
|
314 |
case ETestOtherSession:
|
|
315 |
break;
|
|
316 |
case ETestCompleteAfter:
|
|
317 |
User::After(7000000);
|
|
318 |
break;
|
|
319 |
case ETestMessageConstruction:
|
|
320 |
r=TestMessageConstruction(aMessage);
|
|
321 |
break;
|
|
322 |
case ETestRMessagePtr2LeavingInterface:
|
|
323 |
r=TestRMessagePtr2LeavingInterface(aMessage);
|
|
324 |
break;
|
|
325 |
default:
|
|
326 |
r=KErrNotSupported;
|
|
327 |
|
|
328 |
}
|
|
329 |
aMessage.Complete(r);
|
|
330 |
|
|
331 |
}
|
|
332 |
|
|
333 |
// CTestSession funtions
|
|
334 |
|
|
335 |
void CMyActiveScheduler::Error(TInt anError) const
|
|
336 |
//
|
|
337 |
// Virtual error handler
|
|
338 |
//
|
|
339 |
{
|
|
340 |
User::Panic(_L("CMyActiveScheduer::Error"), anError);
|
|
341 |
}
|
|
342 |
|
|
343 |
#include <e32svr.h>
|
|
344 |
|
|
345 |
TInt ClientThread(TAny*)
|
|
346 |
//
|
|
347 |
// Passed as the first client thread - signals the server to do several tests
|
|
348 |
//
|
|
349 |
{
|
|
350 |
RTest test(_L("T_MESSGE...client"));
|
|
351 |
|
|
352 |
test.Title();
|
|
353 |
test.Start(_L("Wait for server to start"));
|
|
354 |
sem.Wait();
|
|
355 |
|
|
356 |
test.Next(_L("Create Session"));
|
|
357 |
TInt r=session.PublicCreateSession(_L("CTestServer"),5);
|
|
358 |
if (r!=KErrNone)
|
|
359 |
User::Panic(_L("CreateSessn failure"),r);
|
|
360 |
|
|
361 |
test.Next(_L("Signal to test Int0/1/2/3()"));
|
|
362 |
r=session.PublicSendReceive(CTestSession::ETestInt,TIpcArgs(-3866,30566,0,200) );
|
|
363 |
test(r==KErrNone);
|
|
364 |
|
|
365 |
test.Next(_L("Signal to test Ptr0/1/2/3()"));
|
|
366 |
|
|
367 |
r=session.PublicSendReceive(CTestSession::ETestPtr, TIpcArgs(&clientThread, &serverThread, &session, &sem));
|
|
368 |
test(r==KErrNone);
|
|
369 |
|
|
370 |
test.Next(_L("Signal to test Client()"));
|
|
371 |
r=session.PublicSendReceive(CTestSession::ETestClient, TIpcArgs());
|
|
372 |
test(r==KErrNone);
|
|
373 |
|
|
374 |
test.Next(_L("Test RMessage2::Complete()"));
|
|
375 |
TRequestStatus stat[7];
|
|
376 |
for (r=0;r<4;r++)
|
|
377 |
{
|
|
378 |
session.PublicSendReceive(CTestSession::ETestComplete, TIpcArgs(), stat[r]);
|
|
379 |
test(stat[r]==KRequestPending);
|
|
380 |
}
|
|
381 |
session.PublicSendReceive(CTestSession::ETestComplete, TIpcArgs(), stat[4]);
|
|
382 |
User::WaitForRequest(stat[0]);
|
|
383 |
for (r=0;r<5;r++)
|
|
384 |
test(stat[r]==5-r); //Test the 'error messages' set by Complete()
|
|
385 |
test.Next(_L("Test RMessagePtr2::Complete()"));
|
|
386 |
for (r=0;r<4;r++)
|
|
387 |
{
|
|
388 |
session.PublicSendReceive(CTestSession::ETestPtrComplete, TIpcArgs(), stat[r]);
|
|
389 |
test(stat[r]==KRequestPending);
|
|
390 |
}
|
|
391 |
session.PublicSendReceive(CTestSession::ETestPtrComplete, TIpcArgs(), stat[4]);
|
|
392 |
User::WaitForRequest(stat[0]);
|
|
393 |
for (r=0;r<5;r++)
|
|
394 |
test(stat[r]==10-r*2);
|
|
395 |
|
|
396 |
test.Next(_L("Test RMessage contruction from Ptr"));
|
|
397 |
if(UserSvr::IpcV1Available())
|
|
398 |
{
|
|
399 |
r=session.PublicSendReceive(CTestSession::ETestMessageConstruction, TIpcArgs(111,222,333,444));
|
|
400 |
test(r==KErrNone);
|
|
401 |
}
|
|
402 |
else
|
|
403 |
{
|
|
404 |
test.Printf(_L("NOT TESTED - IPC V1 is not supported by system"));
|
|
405 |
}
|
|
406 |
|
|
407 |
test.Next(_L("Test RMessagePtr leaving interface"));
|
|
408 |
r=session.PublicSendReceive(CTestSession::ETestRMessagePtr2LeavingInterface, TIpcArgs());
|
|
409 |
test(r==KErrNone);
|
|
410 |
|
|
411 |
test.Next(_L("Try another session"));
|
|
412 |
r=otherSession.PublicCreateSession(_L("CTestServer"),5);
|
|
413 |
test(r==KErrNone);
|
|
414 |
|
|
415 |
r=otherSession.PublicSendReceive(CTestSession::ETestOtherSession, TIpcArgs());
|
|
416 |
test(r==KErrNone);
|
|
417 |
|
|
418 |
test.Next(_L("Saturate server"));
|
|
419 |
for(r=0;r<7;r++)
|
|
420 |
{
|
|
421 |
test.Printf(_L("Send %d\r"),r);
|
|
422 |
session.PublicSendReceive(CTestSession::ETestCompleteAfter,TIpcArgs(),stat[r]);
|
|
423 |
if (r<5)
|
|
424 |
test(stat[r]==KRequestPending);
|
|
425 |
else
|
|
426 |
test(stat[r]==KErrServerBusy);
|
|
427 |
}
|
|
428 |
test.Printf(_L("\n"));
|
|
429 |
for(r=0;r<5;r++)
|
|
430 |
{
|
|
431 |
test.Printf(_L("Wait %d\r"),r);
|
|
432 |
User::WaitForRequest(stat[r]);
|
|
433 |
test(stat[r]==KErrNone);
|
|
434 |
}
|
|
435 |
test.Printf(_L("\n"));
|
|
436 |
|
|
437 |
test.Next(_L("Signal to stop ActiveScheduler"));
|
|
438 |
session.PublicSendReceive(CTestSession::EStop, TIpcArgs());
|
|
439 |
session.Close();
|
|
440 |
otherSession.PublicSendReceive(CTestSession::EStop, TIpcArgs());
|
|
441 |
otherSession.Close();
|
|
442 |
test.Close();
|
|
443 |
|
|
444 |
return (KErrNone);
|
|
445 |
}
|
|
446 |
|
|
447 |
TInt ServerThread(TAny*)
|
|
448 |
//
|
|
449 |
// Passed as the server thread in 2 tests - sets up and runs CTestServer
|
|
450 |
//
|
|
451 |
{
|
|
452 |
RTest test(_L("T_MESSGE...server"));
|
|
453 |
|
|
454 |
test.Title();
|
|
455 |
test.Start(_L("Create and install ActiveScheduler"));
|
|
456 |
CMyActiveScheduler* pScheduler = new CMyActiveScheduler;
|
|
457 |
if (pScheduler==NULL)
|
|
458 |
{
|
|
459 |
clientThread.Kill(0);
|
|
460 |
User::Panic(_L("CreateSched failure"),KErrNoMemory);
|
|
461 |
}
|
|
462 |
|
|
463 |
CActiveScheduler::Install(pScheduler);
|
|
464 |
|
|
465 |
test.Next(_L("Creating and starting Server"));
|
|
466 |
CTestServer* pServer = new CTestServer(0);
|
|
467 |
if (pServer==NULL)
|
|
468 |
{
|
|
469 |
clientThread.Kill(0);
|
|
470 |
User::Panic(_L("CreateServr failure"),KErrNoMemory);
|
|
471 |
}
|
|
472 |
|
|
473 |
TInt r=pServer->Start(KServerName);//Starting a CServer2 also Adds it to the ActiveScheduler
|
|
474 |
if (r!=KErrNone)
|
|
475 |
{
|
|
476 |
clientThread.Kill(0);
|
|
477 |
User::Panic(_L("StartServr failure"),r);
|
|
478 |
}
|
|
479 |
|
|
480 |
|
|
481 |
test.Next(_L("Start ActiveScheduler and signal to client"));
|
|
482 |
test.Printf(_L(" There might be something going on beneath this window"));
|
|
483 |
sem.Signal();
|
|
484 |
CActiveScheduler::Start();
|
|
485 |
test.Next(_L("Destroy ActiveScheduler"));
|
|
486 |
delete pScheduler;
|
|
487 |
delete pServer;
|
|
488 |
|
|
489 |
test.Close();
|
|
490 |
|
|
491 |
return (KErrNone);
|
|
492 |
}
|
|
493 |
|
|
494 |
const TInt KTestPanic = 14849;
|
|
495 |
|
|
496 |
TInt PanicTestThread (TAny*)
|
|
497 |
//
|
|
498 |
// Passed as a thread entry - just calls RMessage2::Panic()
|
|
499 |
//
|
|
500 |
{
|
|
501 |
RMessage2 message;
|
|
502 |
message.Panic(_L("Testing Panic"),KTestPanic);
|
|
503 |
return(KErrNone);
|
|
504 |
}
|
|
505 |
|
|
506 |
RTest test(_L("Main T_MESSGE test"));
|
|
507 |
|
|
508 |
TInt CompletePanicClientThread (TAny*)
|
|
509 |
//
|
|
510 |
// Passed as the second client thread entry - signals to server to call Complete() twice
|
|
511 |
//
|
|
512 |
{
|
|
513 |
sem.Wait();
|
|
514 |
|
|
515 |
TInt r=session.PublicCreateSession(_L("CTestServer"),1);
|
|
516 |
test(r==KErrNone);
|
|
517 |
|
|
518 |
r=session.PublicSendReceive(CTestSession::ETestCompletePanic, TIpcArgs());
|
|
519 |
test(r==KErrNone);
|
|
520 |
|
|
521 |
session.PublicSendReceive(CTestSession::EStop, TIpcArgs());//panic should occur before this is serviced
|
|
522 |
return(KErrNone);
|
|
523 |
}
|
|
524 |
|
|
525 |
void SimpleRMessage()
|
|
526 |
//
|
|
527 |
// Simple RMessage2 Tests - constructors and assignment
|
|
528 |
//
|
|
529 |
{
|
|
530 |
|
|
531 |
test.Start(_L("Default constructor"));
|
|
532 |
RMessage2 message1;
|
|
533 |
|
|
534 |
test.Next(_L("Copy constructor"));
|
|
535 |
RMessage2 message2(message1);
|
|
536 |
test(message1.Function()==message2.Function());
|
|
537 |
test(message1.Int0()==message2.Int0());
|
|
538 |
test(message1.Int1()==message2.Int1());
|
|
539 |
test(message1.Int2()==message2.Int2());
|
|
540 |
test(message1.Int3()==message2.Int3());
|
|
541 |
|
|
542 |
test.Next(_L("Assignment operator"));
|
|
543 |
RMessage2 message3;
|
|
544 |
Mem::Fill(&message3,sizeof(message3),0xb9); // first fill message 3 with rubbish
|
|
545 |
message3=message1;
|
|
546 |
test(message1.Function()==message3.Function());
|
|
547 |
test(message1.Int0()==message3.Int0());
|
|
548 |
test(message1.Int1()==message3.Int1());
|
|
549 |
test(message1.Int2()==message3.Int2());
|
|
550 |
test(message1.Int3()==message3.Int3());
|
|
551 |
|
|
552 |
test.End();
|
|
553 |
}
|
|
554 |
|
|
555 |
void SimpleRMessagePtr()
|
|
556 |
//
|
|
557 |
// Simple RMessagePtr2 tests - constructors and assignment
|
|
558 |
//
|
|
559 |
{
|
|
560 |
test.Start(_L("Default constructor"));
|
|
561 |
RMessagePtr2 messagePtr1;
|
|
562 |
test(messagePtr1.IsNull());
|
|
563 |
|
|
564 |
test.Next(_L("Copy constructor"));
|
|
565 |
RMessagePtr2 messagePtr2(messagePtr1);
|
|
566 |
test(messagePtr2.IsNull());
|
|
567 |
|
|
568 |
test.Next(_L("Constructor from pointer to RMessage2"));
|
|
569 |
RMessage2 message;
|
|
570 |
messagePtr1= message;
|
|
571 |
|
|
572 |
test.Next(_L("Assignment operator"));
|
|
573 |
messagePtr1=messagePtr2;
|
|
574 |
|
|
575 |
test.End();
|
|
576 |
}
|
|
577 |
|
|
578 |
|
|
579 |
GLDEF_C TInt E32Main()
|
|
580 |
{
|
|
581 |
test.Title();
|
|
582 |
|
|
583 |
test.Start(_L("Simple RMessage2 tests"));
|
|
584 |
SimpleRMessage();
|
|
585 |
|
|
586 |
test.Next(_L("Simple RMessagePtr2 tests"));
|
|
587 |
SimpleRMessagePtr();
|
|
588 |
|
|
589 |
test.Next(_L("Sending messages between two threads"));
|
|
590 |
test.Start(_L("Create client and server threads"));
|
|
591 |
clientThread.Create(_L("Client Thread"),ClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
|
|
592 |
serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
|
|
593 |
|
|
594 |
test.Next(_L("Logon to the threads"));
|
|
595 |
TRequestStatus clientStat,serverStat;
|
|
596 |
clientThread.Logon(clientStat);
|
|
597 |
serverThread.Logon(serverStat);
|
|
598 |
|
|
599 |
test.Next(_L("Start the threads"));
|
|
600 |
sem.CreateLocal(0);
|
|
601 |
clientThread.Resume();
|
|
602 |
serverThread.Resume();
|
|
603 |
|
|
604 |
test.Next(_L("Wait for the threads to stop"));
|
|
605 |
if(clientStat==KRequestPending)
|
|
606 |
User::WaitForRequest(clientStat);
|
|
607 |
if(serverStat==KRequestPending)
|
|
608 |
User::WaitForRequest(serverStat);
|
|
609 |
switch (clientThread.ExitType())
|
|
610 |
{
|
|
611 |
case EExitKill:
|
|
612 |
test.Printf(_L(" Client thread killed\n"));
|
|
613 |
break;
|
|
614 |
case EExitTerminate:
|
|
615 |
test.Printf(_L("!!Client thread terminated:"));
|
|
616 |
test.Panic(clientThread.ExitCategory(), clientThread.ExitReason());
|
|
617 |
case EExitPanic:
|
|
618 |
test.Panic(_L("!!Client thread panicked:"));
|
|
619 |
test.Panic(clientThread.ExitCategory(), clientThread.ExitReason());
|
|
620 |
default:
|
|
621 |
test.Panic(_L("!!Client thread did something bizarre"), clientThread.ExitReason());
|
|
622 |
}
|
|
623 |
switch (serverThread.ExitType())
|
|
624 |
{
|
|
625 |
case EExitKill:
|
|
626 |
test.Printf(_L(" Server thread killed\n"));
|
|
627 |
break;
|
|
628 |
case EExitTerminate:
|
|
629 |
test.Printf(_L("!!Server thread terminated:"));
|
|
630 |
test.Panic(serverThread.ExitCategory(), serverThread.ExitReason());
|
|
631 |
case EExitPanic:
|
|
632 |
test.Printf(_L("!!Server thread panicked:"));
|
|
633 |
test.Panic(serverThread.ExitCategory(), serverThread.ExitReason());
|
|
634 |
//
|
|
635 |
// To catch a panic put a breakpoint in User::Panic() (in UCDT\UC_UNC.CPP).
|
|
636 |
//
|
|
637 |
default:
|
|
638 |
test.Panic(_L("!!Server thread did something bizarre"), serverThread.ExitReason());
|
|
639 |
}
|
|
640 |
|
|
641 |
test.Next(_L("Close the threads"));
|
|
642 |
CLOSE_AND_WAIT(serverThread);
|
|
643 |
CLOSE_AND_WAIT(clientThread);
|
|
644 |
test.End();
|
|
645 |
|
|
646 |
TBool justInTime=User::JustInTime();
|
|
647 |
|
|
648 |
test.Next(_L("Check it Panics if you try to Complete a message twice"));
|
|
649 |
test.Start(_L("Create client and server threads"));
|
|
650 |
clientThread.Create(_L("Client Thread1"),CompletePanicClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
|
|
651 |
serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
|
|
652 |
|
|
653 |
test.Next(_L("Logon to the threads"));
|
|
654 |
clientThread.Logon(clientStat);
|
|
655 |
serverThread.Logon(serverStat);
|
|
656 |
|
|
657 |
test.Next(_L("Start the threads"));
|
|
658 |
sem.CreateLocal(0);
|
|
659 |
User::SetJustInTime(EFalse);
|
|
660 |
clientThread.Resume();
|
|
661 |
serverThread.Resume();
|
|
662 |
|
|
663 |
test.Next(_L("Wait for the threads to stop"));
|
|
664 |
User::WaitForRequest(clientStat); //
|
|
665 |
User::WaitForRequest(serverStat);
|
|
666 |
User::SetJustInTime(justInTime);
|
|
667 |
test.Next(_L("Check the exit categories"));
|
|
668 |
test(clientThread.ExitType()==EExitKill);
|
|
669 |
test(clientThread.ExitCategory().Compare(_L("Kill"))==0);
|
|
670 |
test(clientThread.ExitReason()==KErrNone);
|
|
671 |
|
|
672 |
test(serverThread.ExitType()==EExitPanic);
|
|
673 |
test(serverThread.ExitCategory().Compare(_L("USER"))==0);
|
|
674 |
test(serverThread.ExitReason()==ETMesCompletion);
|
|
675 |
|
|
676 |
test.Next(_L("Close the threads"));
|
|
677 |
CLOSE_AND_WAIT(serverThread);
|
|
678 |
CLOSE_AND_WAIT(clientThread);
|
|
679 |
test.End();
|
|
680 |
|
|
681 |
test.End();
|
|
682 |
|
|
683 |
return (KErrNone);
|
|
684 |
}
|
|
685 |
|
|
686 |
|