sl@0
|
1 |
// Copyright (c) 1997-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\personality\example\t_expers.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32base.h>
|
sl@0
|
19 |
#include <e32base_private.h>
|
sl@0
|
20 |
#include <e32test.h>
|
sl@0
|
21 |
#include "ifcldd.h"
|
sl@0
|
22 |
#include "../../misc/prbs.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
RTest test(_L("EXAMPLE PERSONALITY"));
|
sl@0
|
25 |
|
sl@0
|
26 |
_LIT(KIfcLddName,"expers.ldd");
|
sl@0
|
27 |
|
sl@0
|
28 |
class CRxData : public CActive
|
sl@0
|
29 |
{
|
sl@0
|
30 |
public:
|
sl@0
|
31 |
CRxData();
|
sl@0
|
32 |
static void New(RRtosIfc aIfc);
|
sl@0
|
33 |
void Start();
|
sl@0
|
34 |
void RunL();
|
sl@0
|
35 |
void DoCancel();
|
sl@0
|
36 |
public:
|
sl@0
|
37 |
RRtosIfc iIfc;
|
sl@0
|
38 |
TUint8 iBuf[512];
|
sl@0
|
39 |
};
|
sl@0
|
40 |
|
sl@0
|
41 |
void CRxData::New(RRtosIfc aIfc)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
CRxData* p = new CRxData;
|
sl@0
|
44 |
test(p!=NULL);
|
sl@0
|
45 |
p->iIfc = aIfc;
|
sl@0
|
46 |
CActiveScheduler::Add(p);
|
sl@0
|
47 |
p->Start();
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
CRxData::CRxData()
|
sl@0
|
51 |
: CActive(0)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
void CRxData::DoCancel()
|
sl@0
|
56 |
{
|
sl@0
|
57 |
iIfc.Cancel(RRtosIfc::ECancelReceive);
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
void CRxData::Start()
|
sl@0
|
61 |
{
|
sl@0
|
62 |
iIfc.Receive(iStatus, *(SRxData*)iBuf);
|
sl@0
|
63 |
SetActive();
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
void CRxData::RunL()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
SRxData& rxd = *(SRxData*)iBuf;
|
sl@0
|
69 |
TInt l = rxd.iLength;
|
sl@0
|
70 |
TUint cs = 0;
|
sl@0
|
71 |
TInt i;
|
sl@0
|
72 |
for (i=0; i<l; ++i)
|
sl@0
|
73 |
cs += rxd.iData[i];
|
sl@0
|
74 |
test( (cs & 0xff) == rxd.iChecksum);
|
sl@0
|
75 |
test.Printf(_L("RXD: l=%02x cs=%02x\n"), l, rxd.iChecksum);
|
sl@0
|
76 |
Start();
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
class CReport : public CActive
|
sl@0
|
80 |
{
|
sl@0
|
81 |
public:
|
sl@0
|
82 |
CReport();
|
sl@0
|
83 |
static void New(RRtosIfc aIfc);
|
sl@0
|
84 |
void Start();
|
sl@0
|
85 |
void RunL();
|
sl@0
|
86 |
void DoCancel();
|
sl@0
|
87 |
void SendData();
|
sl@0
|
88 |
public:
|
sl@0
|
89 |
RRtosIfc iIfc;
|
sl@0
|
90 |
TUint iSeed[2];
|
sl@0
|
91 |
SReport iRpt;
|
sl@0
|
92 |
};
|
sl@0
|
93 |
|
sl@0
|
94 |
void CReport::New(RRtosIfc aIfc)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
CReport* p = new CReport;
|
sl@0
|
97 |
test(p!=NULL);
|
sl@0
|
98 |
p->iIfc = aIfc;
|
sl@0
|
99 |
CActiveScheduler::Add(p);
|
sl@0
|
100 |
p->Start();
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
CReport::CReport()
|
sl@0
|
104 |
: CActive(0)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
iSeed[0] = 0xb504f333;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
void CReport::DoCancel()
|
sl@0
|
110 |
{
|
sl@0
|
111 |
iIfc.Cancel(RRtosIfc::ECancelReport);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
void CReport::Start()
|
sl@0
|
115 |
{
|
sl@0
|
116 |
iIfc.Report(iStatus, iRpt);
|
sl@0
|
117 |
SetActive();
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
void CReport::RunL()
|
sl@0
|
121 |
{
|
sl@0
|
122 |
switch (iRpt.iType)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
case SReport::ESem:
|
sl@0
|
125 |
test.Printf(_L("SEM: C:%10d OK:%10d BAD:%10d\n"), iRpt.iCount, iRpt.iOkCount, iRpt.iBadCount);
|
sl@0
|
126 |
if (iRpt.iOkCount>1000000)
|
sl@0
|
127 |
CActiveScheduler::Stop();
|
sl@0
|
128 |
break;
|
sl@0
|
129 |
case SReport::ERcv:
|
sl@0
|
130 |
test.Printf(_L("RCV: C:%10d OK:%10d BAD:%10d\n"), iRpt.iCount, iRpt.iOkCount, iRpt.iBadCount);
|
sl@0
|
131 |
break;
|
sl@0
|
132 |
case SReport::ETm:
|
sl@0
|
133 |
test.Printf(_L("TM: C:%10d\n"), iRpt.iCount);
|
sl@0
|
134 |
#ifndef __EPOC32__
|
sl@0
|
135 |
if (iRpt.iCount > 100000)
|
sl@0
|
136 |
CActiveScheduler::Stop();
|
sl@0
|
137 |
#endif
|
sl@0
|
138 |
TUint x = Random(iSeed) & 3;
|
sl@0
|
139 |
if (x==3)
|
sl@0
|
140 |
SendData();
|
sl@0
|
141 |
if (x)
|
sl@0
|
142 |
SendData();
|
sl@0
|
143 |
else
|
sl@0
|
144 |
iIfc.FlushData();
|
sl@0
|
145 |
break;
|
sl@0
|
146 |
}
|
sl@0
|
147 |
Start();
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
void CReport::SendData()
|
sl@0
|
151 |
{
|
sl@0
|
152 |
TInt l = (Random(iSeed)&127)+128;
|
sl@0
|
153 |
TUint buf[64];
|
sl@0
|
154 |
TInt i;
|
sl@0
|
155 |
for (i=0; i<64; ++i)
|
sl@0
|
156 |
buf[i] = Random(iSeed);
|
sl@0
|
157 |
TPtrC8 ptr((const TUint8*)buf, l);
|
sl@0
|
158 |
TInt r = iIfc.SendData(ptr);
|
sl@0
|
159 |
test(r==KErrNone);
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
|
sl@0
|
163 |
GLDEF_C TInt E32Main()
|
sl@0
|
164 |
{
|
sl@0
|
165 |
test.Title();
|
sl@0
|
166 |
test.Start(_L("Load interface LDD"));
|
sl@0
|
167 |
|
sl@0
|
168 |
TInt r = User::LoadLogicalDevice(KIfcLddName);
|
sl@0
|
169 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
170 |
|
sl@0
|
171 |
test.Next(_L("Open channel"));
|
sl@0
|
172 |
RRtosIfc ifc;
|
sl@0
|
173 |
RThread().SetPriority(EPriorityAbsoluteHigh);
|
sl@0
|
174 |
r = ifc.Open();
|
sl@0
|
175 |
test(r==KErrNone);
|
sl@0
|
176 |
|
sl@0
|
177 |
test.Next(_L("Start personality tests"));
|
sl@0
|
178 |
ifc.Init();
|
sl@0
|
179 |
|
sl@0
|
180 |
TRequestStatus s;
|
sl@0
|
181 |
ifc.WaitInitialTests(s);
|
sl@0
|
182 |
User::WaitForRequest(s);
|
sl@0
|
183 |
test(s==KErrNone);
|
sl@0
|
184 |
|
sl@0
|
185 |
CActiveScheduler* as = new CActiveScheduler;
|
sl@0
|
186 |
test(as!=NULL);
|
sl@0
|
187 |
CActiveScheduler::Install(as);
|
sl@0
|
188 |
CRxData::New(ifc);
|
sl@0
|
189 |
CReport::New(ifc);
|
sl@0
|
190 |
|
sl@0
|
191 |
CActiveScheduler::Start();
|
sl@0
|
192 |
|
sl@0
|
193 |
ifc.Finish();
|
sl@0
|
194 |
ifc.Close();
|
sl@0
|
195 |
|
sl@0
|
196 |
test.End();
|
sl@0
|
197 |
return 0;
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|