First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\device\t_comm.cpp
19 #include <e32base_private.h>
25 LOCAL_D RTest test(_L("T_COMM"));
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";
30 class RComm : public RBusDevComm
33 TInt WriteS(const TDesC8& aDes);
34 TInt WriteS(const TDesC8& aDes,TInt aLength);
38 LOCAL_C void testRDevice(const RBusDevComm& aDev,const TFindLogicalDevice& aFind)
40 // Test the RDevice class
44 test.Start(_L("Testing RDevice with find handle"));
50 test.Next(_L("Testing RDevice open by name"));
54 test.Next(_L("Query version supported"));
55 TBool b=d.QueryVersionSupported(aDev.VersionRequired());
58 test.Next(_L("Query is available"));
59 b=d.IsAvailable(KDefaultUnit,NULL,NULL);
62 test.Next(_L("Query device capabilities"));
63 TPckgBuf<TCapsDevCommV01> c;
65 TVersionName aName = c().version.Name();
66 test.Printf(_L(" Version = %S\n"),&aName);
72 TInt RComm::WriteS(const TDesC8& aDes)
78 return(WriteS(aDes,aDes.Length()));
81 TInt RComm::WriteS(const TDesC8& aDes,TInt aLength)
88 Write(s,aDes,aLength);
89 User::WaitForRequest(s);
93 LOCAL_C void testComm()
95 // Test the comms device driver
99 test.Start(_L("Testing comm device"));
102 TInt r=com.Open(KUnit0);
105 test.Next(_L("Set config to 9600,8,N,1"));
107 TCommConfigV01& c=cBuf();
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
118 c.iParityErrorChar=0;
119 r=com.SetConfig(cBuf);
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));
127 test.Next(_L("Set config to 4800,7,N,1"));
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
138 c.iParityErrorChar=0;
139 r=com.SetConfig(cBuf);
142 test.Next(_L("Close comm device"));
148 GLDEF_C TInt E32Main()
150 // Test the various kernel types.
156 test.Start(_L("Load PDD"));
157 TInt r=User::LoadPhysicalDevice(_L("ECDRV"));
160 test.Next(_L("Load LDD"));
161 r=User::LoadLogicalDevice(_L("ECOMM"));
164 test.Next(_L("Find libs"));
167 while (fL.Next(n)==KErrNone)
168 test.Printf(_L(" %S\n"),&n);
170 test.Next(_L("Find devices"));
171 TFindLogicalDevice fD;
172 while (fD.Next(n)==KErrNone)
173 test.Printf(_L(" %S\n"),&n);
181 test.Next(_L("Open device"));
186 test.Next(_L("Free device/In use"));
187 r=User::FreeLogicalDevice(_L("Comm"));
190 test.Next(_L("Close device"));
194 test.Next(_L("Testing comms device"));
197 TFindPhysicalDevice fDr;
198 test.Next(_L("Free driver/Ok"));
200 fDr.Find(_L("Comm.*"));
201 r=fDr.Next(drivName);
203 r=User::FreePhysicalDevice(drivName);
206 test.Next(_L("Free device/Ok"));
207 r=User::FreeLogicalDevice(_L("Comm"));
210 test.Next(_L("Find libs none"));
212 while (fL.Next(n)==KErrNone)
213 test.Printf(_L(" %S\n"),&n);
215 test.Next(_L("Find devices none"));
217 while (fD.Next(n)==KErrNone)
218 test.Printf(_L(" %S\n"),&n);
220 test.Next(_L("Find drivers none"));
221 while (fDr.Next(n)==KErrNone)
222 test.Printf(_L(" %S\n"),&n);