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