os/kernelhwsrv/kerneltest/e32test/device/t_comm.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/device/t_comm.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,229 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\device\t_comm.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32base.h>
    1.22 +#include <e32base_private.h>
    1.23 +#include <e32test.h>
    1.24 +#include <e32svr.h>
    1.25 +#include <d32comm.h>
    1.26 +#include <e32uid.h>
    1.27 +
    1.28 +LOCAL_D RTest test(_L("T_COMM"));
    1.29 +
    1.30 +const TInt KUnit0=0;
    1.31 +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";
    1.32 +
    1.33 +class RComm : public RBusDevComm
    1.34 +	{
    1.35 +public:
    1.36 +	TInt WriteS(const TDesC8& aDes);
    1.37 +	TInt WriteS(const TDesC8& aDes,TInt aLength);
    1.38 +	};
    1.39 +
    1.40 +
    1.41 +LOCAL_C void testRDevice(const RBusDevComm& aDev,const TFindLogicalDevice& aFind)
    1.42 +//
    1.43 +// Test the RDevice class
    1.44 +//
    1.45 +	{
    1.46 +
    1.47 +	test.Start(_L("Testing RDevice with find handle"));
    1.48 +	RDevice d;
    1.49 +	TInt r=d.Open(aFind);
    1.50 +	test(r==KErrNone);
    1.51 +	d.Close();
    1.52 +//
    1.53 +	test.Next(_L("Testing RDevice open by name"));
    1.54 +	r=d.Open(_L("Comm"));
    1.55 +	test(r==KErrNone);
    1.56 +//
    1.57 +	test.Next(_L("Query version supported"));
    1.58 +	TBool b=d.QueryVersionSupported(aDev.VersionRequired());
    1.59 +	test(b);
    1.60 +//
    1.61 +	test.Next(_L("Query is available"));
    1.62 +	b=d.IsAvailable(KDefaultUnit,NULL,NULL);
    1.63 +	test(b);
    1.64 +//
    1.65 +	test.Next(_L("Query device capabilities"));
    1.66 +	TPckgBuf<TCapsDevCommV01> c;
    1.67 +	d.GetCaps(c);
    1.68 + 	TVersionName aName = c().version.Name();
    1.69 + 	test.Printf(_L("  Version = %S\n"),&aName);
    1.70 +//
    1.71 +	d.Close();
    1.72 +	test.End();
    1.73 +	}
    1.74 +
    1.75 +TInt RComm::WriteS(const TDesC8& aDes)
    1.76 +//
    1.77 +// Synchronous write
    1.78 +//
    1.79 +	{
    1.80 +
    1.81 +	return(WriteS(aDes,aDes.Length()));
    1.82 +	}
    1.83 +
    1.84 +TInt RComm::WriteS(const TDesC8& aDes,TInt aLength)
    1.85 +//
    1.86 +// Synchronous write
    1.87 +//
    1.88 +	{
    1.89 +
    1.90 +	TRequestStatus s;
    1.91 +	Write(s,aDes,aLength);
    1.92 +	User::WaitForRequest(s);
    1.93 +	return(s.Int());
    1.94 +	}
    1.95 +
    1.96 +LOCAL_C void testComm()
    1.97 +//
    1.98 +// Test the comms device driver
    1.99 +//
   1.100 +	{
   1.101 +
   1.102 +	test.Start(_L("Testing comm device"));
   1.103 +//
   1.104 +	RComm com;
   1.105 +	TInt r=com.Open(KUnit0);
   1.106 +	test(r==KErrNone);
   1.107 +//
   1.108 +	test.Next(_L("Set config to 9600,8,N,1"));
   1.109 +	TCommConfig cBuf;
   1.110 +	TCommConfigV01& c=cBuf();
   1.111 +	c.iRate=EBps9600;
   1.112 +	c.iDataBits=EData8;
   1.113 +	c.iStopBits=EStop1;
   1.114 +	c.iParity=EParityNone;
   1.115 +	c.iHandshake=KConfigObeyXoff|KConfigSendXoff;
   1.116 +	c.iParityError=KConfigParityErrorFail;
   1.117 +	c.iTerminatorCount=0;
   1.118 +	c.iXonChar=0x11; // XON
   1.119 +	c.iXonChar=0x13; // XOFF
   1.120 +	c.iSpecialRate=0;
   1.121 +	c.iParityErrorChar=0;
   1.122 +	r=com.SetConfig(cBuf);
   1.123 +	test(r==KErrNone);
   1.124 +//
   1.125 +	test.Next(_L("Write hello world"));
   1.126 +	com.WriteS(_L8("\r\nHello world\r\n"));
   1.127 +	test.Next(_L("Write long string"));
   1.128 +	com.WriteS(_L8(KLongString));
   1.129 +//
   1.130 +	test.Next(_L("Set config to 4800,7,N,1"));
   1.131 +	c.iRate=EBps4800;
   1.132 +	c.iDataBits=EData7;
   1.133 +	c.iStopBits=EStop1;
   1.134 +	c.iParity=EParityNone;
   1.135 +	c.iHandshake=KConfigObeyXoff|KConfigSendXoff;
   1.136 +	c.iParityError=KConfigParityErrorFail;
   1.137 +	c.iTerminatorCount=0;
   1.138 +	c.iXonChar=0x11; // XON
   1.139 +	c.iXonChar=0x13; // XOFF
   1.140 +	c.iSpecialRate=0;
   1.141 +	c.iParityErrorChar=0;
   1.142 +	r=com.SetConfig(cBuf);
   1.143 +	test(r==KErrNone);
   1.144 +
   1.145 +	test.Next(_L("Close comm device"));
   1.146 +	com.Close();
   1.147 +//
   1.148 +	test.End();
   1.149 +	}
   1.150 +
   1.151 +GLDEF_C TInt E32Main()
   1.152 +//
   1.153 +// Test the various kernel types.
   1.154 +//
   1.155 +    {
   1.156 +
   1.157 +	test.Title();
   1.158 +//
   1.159 +	test.Start(_L("Load PDD"));
   1.160 +	TInt r=User::LoadPhysicalDevice(_L("ECDRV"));
   1.161 +	test(r==KErrNone);
   1.162 +//
   1.163 +	test.Next(_L("Load LDD"));
   1.164 +	r=User::LoadLogicalDevice(_L("ECOMM"));
   1.165 +	test(r==KErrNone);
   1.166 +//
   1.167 +	test.Next(_L("Find libs"));
   1.168 +	TFindLibrary fL;
   1.169 +	TFullName n;
   1.170 +	while (fL.Next(n)==KErrNone)
   1.171 +		test.Printf(_L("  %S\n"),&n);
   1.172 +//
   1.173 +	test.Next(_L("Find devices"));
   1.174 +	TFindLogicalDevice fD;
   1.175 +	while (fD.Next(n)==KErrNone)
   1.176 +		test.Printf(_L("  %S\n"),&n);
   1.177 +//
   1.178 +	RBusDevComm com;
   1.179 +	fD.Find(_L("Comm"));
   1.180 +	r=fD.Next(n);
   1.181 +	test(r==KErrNone);
   1.182 +	testRDevice(com,fD);
   1.183 +//
   1.184 +	test.Next(_L("Open device"));
   1.185 +	r=com.Open(KUnit0);
   1.186 +	test(r==KErrNone);
   1.187 +//
   1.188 +//
   1.189 +	test.Next(_L("Free device/In use"));
   1.190 +	r=User::FreeLogicalDevice(_L("Comm"));
   1.191 +	test(r==KErrInUse);
   1.192 +//
   1.193 +	test.Next(_L("Close device"));
   1.194 +	com.Close();
   1.195 +//
   1.196 +//
   1.197 +	test.Next(_L("Testing comms device"));
   1.198 +	testComm();
   1.199 +//
   1.200 +	TFindPhysicalDevice fDr;
   1.201 + 	test.Next(_L("Free driver/Ok"));
   1.202 +	TFullName drivName;
   1.203 +	fDr.Find(_L("Comm.*"));
   1.204 +	r=fDr.Next(drivName);
   1.205 +	test(r==KErrNone);
   1.206 +	r=User::FreePhysicalDevice(drivName);
   1.207 +	test(r==KErrNone);
   1.208 +//
   1.209 +	test.Next(_L("Free device/Ok"));
   1.210 +	r=User::FreeLogicalDevice(_L("Comm"));
   1.211 +	test(r==KErrNone);
   1.212 +//
   1.213 +	test.Next(_L("Find libs none"));
   1.214 +	fL.Find(_L("*.*"));
   1.215 +	while (fL.Next(n)==KErrNone)
   1.216 +		test.Printf(_L("  %S\n"),&n);
   1.217 +//
   1.218 +	test.Next(_L("Find devices none"));
   1.219 +	fD.Find(_L("*.*"));
   1.220 +	while (fD.Next(n)==KErrNone)
   1.221 +		test.Printf(_L("  %S\n"),&n);
   1.222 +//
   1.223 +	test.Next(_L("Find drivers none"));
   1.224 +	while (fDr.Next(n)==KErrNone)
   1.225 +		test.Printf(_L("  %S\n"),&n);
   1.226 +
   1.227 +	test.End();
   1.228 +
   1.229 +	return(0);
   1.230 +    }
   1.231 +
   1.232 +