sl@0
|
1 |
// Copyright (c) 1995-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\device\t_comm.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 <e32svr.h>
|
sl@0
|
22 |
#include <d32comm.h>
|
sl@0
|
23 |
#include <e32uid.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
LOCAL_D RTest test(_L("T_COMM"));
|
sl@0
|
26 |
|
sl@0
|
27 |
const TInt KUnit0=0;
|
sl@0
|
28 |
const char* KLongString="1 3456789012345678\n\r2 3456789012345678\n\r3 3456789012345678\n\r4 3456789012345678\n\r5 3456789012345678\n\r6 3456789012345678\n\r7 3456789012345678\n\r8 3456789012345678\n\r9 3456789012345678\n\r0 3456789012345678\n\r";
|
sl@0
|
29 |
|
sl@0
|
30 |
class RComm : public RBusDevComm
|
sl@0
|
31 |
{
|
sl@0
|
32 |
public:
|
sl@0
|
33 |
TInt WriteS(const TDesC8& aDes);
|
sl@0
|
34 |
TInt WriteS(const TDesC8& aDes,TInt aLength);
|
sl@0
|
35 |
};
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
LOCAL_C void testRDevice(const RBusDevComm& aDev,const TFindLogicalDevice& aFind)
|
sl@0
|
39 |
//
|
sl@0
|
40 |
// Test the RDevice class
|
sl@0
|
41 |
//
|
sl@0
|
42 |
{
|
sl@0
|
43 |
|
sl@0
|
44 |
test.Start(_L("Testing RDevice with find handle"));
|
sl@0
|
45 |
RDevice d;
|
sl@0
|
46 |
TInt r=d.Open(aFind);
|
sl@0
|
47 |
test(r==KErrNone);
|
sl@0
|
48 |
d.Close();
|
sl@0
|
49 |
//
|
sl@0
|
50 |
test.Next(_L("Testing RDevice open by name"));
|
sl@0
|
51 |
r=d.Open(_L("Comm"));
|
sl@0
|
52 |
test(r==KErrNone);
|
sl@0
|
53 |
//
|
sl@0
|
54 |
test.Next(_L("Query version supported"));
|
sl@0
|
55 |
TBool b=d.QueryVersionSupported(aDev.VersionRequired());
|
sl@0
|
56 |
test(b);
|
sl@0
|
57 |
//
|
sl@0
|
58 |
test.Next(_L("Query is available"));
|
sl@0
|
59 |
b=d.IsAvailable(KDefaultUnit,NULL,NULL);
|
sl@0
|
60 |
test(b);
|
sl@0
|
61 |
//
|
sl@0
|
62 |
test.Next(_L("Query device capabilities"));
|
sl@0
|
63 |
TPckgBuf<TCapsDevCommV01> c;
|
sl@0
|
64 |
d.GetCaps(c);
|
sl@0
|
65 |
TVersionName aName = c().version.Name();
|
sl@0
|
66 |
test.Printf(_L(" Version = %S\n"),&aName);
|
sl@0
|
67 |
//
|
sl@0
|
68 |
d.Close();
|
sl@0
|
69 |
test.End();
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
TInt RComm::WriteS(const TDesC8& aDes)
|
sl@0
|
73 |
//
|
sl@0
|
74 |
// Synchronous write
|
sl@0
|
75 |
//
|
sl@0
|
76 |
{
|
sl@0
|
77 |
|
sl@0
|
78 |
return(WriteS(aDes,aDes.Length()));
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
TInt RComm::WriteS(const TDesC8& aDes,TInt aLength)
|
sl@0
|
82 |
//
|
sl@0
|
83 |
// Synchronous write
|
sl@0
|
84 |
//
|
sl@0
|
85 |
{
|
sl@0
|
86 |
|
sl@0
|
87 |
TRequestStatus s;
|
sl@0
|
88 |
Write(s,aDes,aLength);
|
sl@0
|
89 |
User::WaitForRequest(s);
|
sl@0
|
90 |
return(s.Int());
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
LOCAL_C void testComm()
|
sl@0
|
94 |
//
|
sl@0
|
95 |
// Test the comms device driver
|
sl@0
|
96 |
//
|
sl@0
|
97 |
{
|
sl@0
|
98 |
|
sl@0
|
99 |
test.Start(_L("Testing comm device"));
|
sl@0
|
100 |
//
|
sl@0
|
101 |
RComm com;
|
sl@0
|
102 |
TInt r=com.Open(KUnit0);
|
sl@0
|
103 |
test(r==KErrNone);
|
sl@0
|
104 |
//
|
sl@0
|
105 |
test.Next(_L("Set config to 9600,8,N,1"));
|
sl@0
|
106 |
TCommConfig cBuf;
|
sl@0
|
107 |
TCommConfigV01& c=cBuf();
|
sl@0
|
108 |
c.iRate=EBps9600;
|
sl@0
|
109 |
c.iDataBits=EData8;
|
sl@0
|
110 |
c.iStopBits=EStop1;
|
sl@0
|
111 |
c.iParity=EParityNone;
|
sl@0
|
112 |
c.iHandshake=KConfigObeyXoff|KConfigSendXoff;
|
sl@0
|
113 |
c.iParityError=KConfigParityErrorFail;
|
sl@0
|
114 |
c.iTerminatorCount=0;
|
sl@0
|
115 |
c.iXonChar=0x11; // XON
|
sl@0
|
116 |
c.iXonChar=0x13; // XOFF
|
sl@0
|
117 |
c.iSpecialRate=0;
|
sl@0
|
118 |
c.iParityErrorChar=0;
|
sl@0
|
119 |
r=com.SetConfig(cBuf);
|
sl@0
|
120 |
test(r==KErrNone);
|
sl@0
|
121 |
//
|
sl@0
|
122 |
test.Next(_L("Write hello world"));
|
sl@0
|
123 |
com.WriteS(_L8("\r\nHello world\r\n"));
|
sl@0
|
124 |
test.Next(_L("Write long string"));
|
sl@0
|
125 |
com.WriteS(_L8(KLongString));
|
sl@0
|
126 |
//
|
sl@0
|
127 |
test.Next(_L("Set config to 4800,7,N,1"));
|
sl@0
|
128 |
c.iRate=EBps4800;
|
sl@0
|
129 |
c.iDataBits=EData7;
|
sl@0
|
130 |
c.iStopBits=EStop1;
|
sl@0
|
131 |
c.iParity=EParityNone;
|
sl@0
|
132 |
c.iHandshake=KConfigObeyXoff|KConfigSendXoff;
|
sl@0
|
133 |
c.iParityError=KConfigParityErrorFail;
|
sl@0
|
134 |
c.iTerminatorCount=0;
|
sl@0
|
135 |
c.iXonChar=0x11; // XON
|
sl@0
|
136 |
c.iXonChar=0x13; // XOFF
|
sl@0
|
137 |
c.iSpecialRate=0;
|
sl@0
|
138 |
c.iParityErrorChar=0;
|
sl@0
|
139 |
r=com.SetConfig(cBuf);
|
sl@0
|
140 |
test(r==KErrNone);
|
sl@0
|
141 |
|
sl@0
|
142 |
test.Next(_L("Close comm device"));
|
sl@0
|
143 |
com.Close();
|
sl@0
|
144 |
//
|
sl@0
|
145 |
test.End();
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
GLDEF_C TInt E32Main()
|
sl@0
|
149 |
//
|
sl@0
|
150 |
// Test the various kernel types.
|
sl@0
|
151 |
//
|
sl@0
|
152 |
{
|
sl@0
|
153 |
|
sl@0
|
154 |
test.Title();
|
sl@0
|
155 |
//
|
sl@0
|
156 |
test.Start(_L("Load PDD"));
|
sl@0
|
157 |
TInt r=User::LoadPhysicalDevice(_L("ECDRV"));
|
sl@0
|
158 |
test(r==KErrNone);
|
sl@0
|
159 |
//
|
sl@0
|
160 |
test.Next(_L("Load LDD"));
|
sl@0
|
161 |
r=User::LoadLogicalDevice(_L("ECOMM"));
|
sl@0
|
162 |
test(r==KErrNone);
|
sl@0
|
163 |
//
|
sl@0
|
164 |
test.Next(_L("Find libs"));
|
sl@0
|
165 |
TFindLibrary fL;
|
sl@0
|
166 |
TFullName n;
|
sl@0
|
167 |
while (fL.Next(n)==KErrNone)
|
sl@0
|
168 |
test.Printf(_L(" %S\n"),&n);
|
sl@0
|
169 |
//
|
sl@0
|
170 |
test.Next(_L("Find devices"));
|
sl@0
|
171 |
TFindLogicalDevice fD;
|
sl@0
|
172 |
while (fD.Next(n)==KErrNone)
|
sl@0
|
173 |
test.Printf(_L(" %S\n"),&n);
|
sl@0
|
174 |
//
|
sl@0
|
175 |
RBusDevComm com;
|
sl@0
|
176 |
fD.Find(_L("Comm"));
|
sl@0
|
177 |
r=fD.Next(n);
|
sl@0
|
178 |
test(r==KErrNone);
|
sl@0
|
179 |
testRDevice(com,fD);
|
sl@0
|
180 |
//
|
sl@0
|
181 |
test.Next(_L("Open device"));
|
sl@0
|
182 |
r=com.Open(KUnit0);
|
sl@0
|
183 |
test(r==KErrNone);
|
sl@0
|
184 |
//
|
sl@0
|
185 |
//
|
sl@0
|
186 |
test.Next(_L("Free device/In use"));
|
sl@0
|
187 |
r=User::FreeLogicalDevice(_L("Comm"));
|
sl@0
|
188 |
test(r==KErrInUse);
|
sl@0
|
189 |
//
|
sl@0
|
190 |
test.Next(_L("Close device"));
|
sl@0
|
191 |
com.Close();
|
sl@0
|
192 |
//
|
sl@0
|
193 |
//
|
sl@0
|
194 |
test.Next(_L("Testing comms device"));
|
sl@0
|
195 |
testComm();
|
sl@0
|
196 |
//
|
sl@0
|
197 |
TFindPhysicalDevice fDr;
|
sl@0
|
198 |
test.Next(_L("Free driver/Ok"));
|
sl@0
|
199 |
TFullName drivName;
|
sl@0
|
200 |
fDr.Find(_L("Comm.*"));
|
sl@0
|
201 |
r=fDr.Next(drivName);
|
sl@0
|
202 |
test(r==KErrNone);
|
sl@0
|
203 |
r=User::FreePhysicalDevice(drivName);
|
sl@0
|
204 |
test(r==KErrNone);
|
sl@0
|
205 |
//
|
sl@0
|
206 |
test.Next(_L("Free device/Ok"));
|
sl@0
|
207 |
r=User::FreeLogicalDevice(_L("Comm"));
|
sl@0
|
208 |
test(r==KErrNone);
|
sl@0
|
209 |
//
|
sl@0
|
210 |
test.Next(_L("Find libs none"));
|
sl@0
|
211 |
fL.Find(_L("*.*"));
|
sl@0
|
212 |
while (fL.Next(n)==KErrNone)
|
sl@0
|
213 |
test.Printf(_L(" %S\n"),&n);
|
sl@0
|
214 |
//
|
sl@0
|
215 |
test.Next(_L("Find devices none"));
|
sl@0
|
216 |
fD.Find(_L("*.*"));
|
sl@0
|
217 |
while (fD.Next(n)==KErrNone)
|
sl@0
|
218 |
test.Printf(_L(" %S\n"),&n);
|
sl@0
|
219 |
//
|
sl@0
|
220 |
test.Next(_L("Find drivers none"));
|
sl@0
|
221 |
while (fDr.Next(n)==KErrNone)
|
sl@0
|
222 |
test.Printf(_L(" %S\n"),&n);
|
sl@0
|
223 |
|
sl@0
|
224 |
test.End();
|
sl@0
|
225 |
|
sl@0
|
226 |
return(0);
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
|