0
|
1 |
// Copyright (c) 1996-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_asyc.cpp
|
|
15 |
// Overview:
|
|
16 |
// Exercise the priority mechanism of active objects whereby active
|
|
17 |
// objects are run in the priority order.
|
|
18 |
// API Information:
|
|
19 |
// CAsyncOneShot, CActiveScheduler.
|
|
20 |
// Details:
|
|
21 |
// - Install active scheduler.
|
|
22 |
// - Create active objects of different priorities and verify their RunL
|
|
23 |
// is called in the priority order.
|
|
24 |
// - Verify that a very low priority active object will not get the chance
|
|
25 |
// to run if a higher priority object keeps rescheduling itself or a
|
|
26 |
// higher priority object stops the active scheduler.
|
|
27 |
// Platforms/Drives/Compatibility:
|
|
28 |
// All.
|
|
29 |
// Assumptions/Requirement/Pre-requisites:
|
|
30 |
// Failures and causes:
|
|
31 |
// Base Port information:
|
|
32 |
//
|
|
33 |
//
|
|
34 |
|
|
35 |
#include <e32test.h>
|
|
36 |
|
|
37 |
enum {ETopPriority=1000,EMiddlePriority=900,ELatePriority=800};
|
|
38 |
|
|
39 |
const TInt KIToldYouSo=666;
|
|
40 |
|
|
41 |
class CMyActiveScheduler : public CActiveScheduler
|
|
42 |
{
|
|
43 |
public:
|
|
44 |
virtual void Error(TInt anError) const;
|
|
45 |
};
|
|
46 |
|
|
47 |
LOCAL_D RTest test(_L("T_ASYC"));
|
|
48 |
|
|
49 |
void CMyActiveScheduler::Error(TInt anError) const
|
|
50 |
//
|
|
51 |
// Called if any Run() method leaves.
|
|
52 |
//
|
|
53 |
{
|
|
54 |
|
|
55 |
test.Panic(anError,_L("CMyActiveScheduler::Error"));
|
|
56 |
}
|
|
57 |
|
|
58 |
class CMyMultiShot : public CAsyncOneShot
|
|
59 |
{
|
|
60 |
public:
|
|
61 |
static CMyMultiShot* NewL(TInt aPriority,const TDesC& aMessage,TInt aCount);
|
|
62 |
void RunL();
|
|
63 |
CMyMultiShot(TInt aPriority,const TDesC& aMessage,TInt aCount);
|
|
64 |
private:
|
|
65 |
TInt iCountRemaining;
|
|
66 |
TPtrC iMessage;
|
|
67 |
};
|
|
68 |
|
|
69 |
class CShouldNeverRun : public CAsyncOneShot
|
|
70 |
{
|
|
71 |
public:
|
|
72 |
void RunL();
|
|
73 |
static CShouldNeverRun* NewL();
|
|
74 |
CShouldNeverRun();
|
|
75 |
};
|
|
76 |
|
|
77 |
class CStopTheScheduler : public CAsyncOneShot
|
|
78 |
{
|
|
79 |
public:
|
|
80 |
CStopTheScheduler(TInt aPriority);
|
|
81 |
static CStopTheScheduler* NewL(TInt aPriority);
|
|
82 |
void RunL();
|
|
83 |
};
|
|
84 |
|
|
85 |
CMyMultiShot* CMyMultiShot::NewL(TInt aPriority,const TDesC& aMessage,TInt aCount)
|
|
86 |
{
|
|
87 |
return new(ELeave)CMyMultiShot(aPriority,aMessage,aCount);
|
|
88 |
}
|
|
89 |
|
|
90 |
CMyMultiShot::CMyMultiShot(TInt aPriority,const TDesC& aMessage,TInt aCount)
|
|
91 |
:CAsyncOneShot(aPriority),iMessage(aMessage)
|
|
92 |
{
|
|
93 |
iCountRemaining=aCount;
|
|
94 |
}
|
|
95 |
|
|
96 |
void CMyMultiShot::RunL()
|
|
97 |
{
|
|
98 |
if (iCountRemaining--)
|
|
99 |
{
|
|
100 |
test.Printf(_L("%S,%d\n\r"),&iMessage,iCountRemaining);
|
|
101 |
Call();
|
|
102 |
}
|
|
103 |
}
|
|
104 |
CShouldNeverRun* CShouldNeverRun::NewL()
|
|
105 |
{
|
|
106 |
return new(ELeave)CShouldNeverRun;
|
|
107 |
}
|
|
108 |
|
|
109 |
CShouldNeverRun::CShouldNeverRun()
|
|
110 |
:CAsyncOneShot(KMinTInt)
|
|
111 |
{
|
|
112 |
}
|
|
113 |
|
|
114 |
void CShouldNeverRun::RunL()
|
|
115 |
{
|
|
116 |
User::Panic(_L("CShouldNeverRun"),KIToldYouSo);
|
|
117 |
}
|
|
118 |
|
|
119 |
CStopTheScheduler* CStopTheScheduler::NewL(TInt aPriority)
|
|
120 |
{
|
|
121 |
return new(ELeave)CStopTheScheduler(aPriority);
|
|
122 |
}
|
|
123 |
|
|
124 |
CStopTheScheduler::CStopTheScheduler(TInt aPriority)
|
|
125 |
:CAsyncOneShot(aPriority)
|
|
126 |
{
|
|
127 |
}
|
|
128 |
|
|
129 |
void CStopTheScheduler::RunL()
|
|
130 |
{
|
|
131 |
CActiveScheduler::Stop();
|
|
132 |
}
|
|
133 |
|
|
134 |
GLDEF_C TInt E32Main()
|
|
135 |
//
|
|
136 |
// Test idle objects.
|
|
137 |
//
|
|
138 |
{
|
|
139 |
test.Title();
|
|
140 |
test.Start(_L("Testing idle object cancellation"));
|
|
141 |
//
|
|
142 |
CMyActiveScheduler* pR=new CMyActiveScheduler;
|
|
143 |
test(pR!=NULL);
|
|
144 |
CActiveScheduler::Install(pR);
|
|
145 |
//
|
|
146 |
CShouldNeverRun* pn=CShouldNeverRun::NewL();
|
|
147 |
pn->Call();
|
|
148 |
|
|
149 |
CStopTheScheduler* ps=CStopTheScheduler::NewL(ELatePriority);
|
|
150 |
ps->Call();
|
|
151 |
|
|
152 |
CMyMultiShot* multiShot1=CMyMultiShot::NewL(EMiddlePriority,_L("Call Ten times"),10);
|
|
153 |
multiShot1->Call();
|
|
154 |
|
|
155 |
CMyMultiShot* multiShot2=CMyMultiShot::NewL(ETopPriority,_L("Call five times"),5);
|
|
156 |
multiShot2->Call();
|
|
157 |
|
|
158 |
CActiveScheduler::Start();
|
|
159 |
//
|
|
160 |
test.End();
|
|
161 |
return(0);
|
|
162 |
}
|
|
163 |
|