1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/examples/driver1/driver1_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,167 @@
1.4 +// Copyright (c) 2003-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 +//
1.18 +
1.19 +/**
1.20 + @file Test code for example Device Driver
1.21 + @publishedPartner
1.22 + @released
1.23 +*/
1.24 +
1.25 +#include <e32test.h>
1.26 +#include <e32def.h>
1.27 +#include <e32def_private.h>
1.28 +#include "driver1.h"
1.29 +
1.30 +LOCAL_D RTest test(_L("DRIVER1_TEST"));
1.31 +
1.32 +_LIT(KDriver1LddFileName,"DRIVER1_LDD");
1.33 +_LIT(KDriver1PddFileName,"DRIVER1_PDD");
1.34 +
1.35 +_LIT8(KTestSendData,"abcdefghijklmnopqrstuvwxyz");
1.36 +
1.37 +GLDEF_C TInt E32Main()
1.38 + {
1.39 + test.Title();
1.40 +
1.41 + TInt r;
1.42 +
1.43 + test.Start(_L("Load Physical Device"));
1.44 + r=User::LoadPhysicalDevice(KDriver1PddFileName);
1.45 + test(r==KErrNone || r==KErrAlreadyExists);
1.46 +
1.47 + test.Next(_L("Load Logical Device"));
1.48 + r=User::LoadLogicalDevice(KDriver1LddFileName);
1.49 + test(r==KErrNone || r==KErrAlreadyExists);
1.50 +
1.51 + __KHEAP_MARK;
1.52 +
1.53 + test.Next(_L("Open Device"));
1.54 + RDevice device;
1.55 + r=device.Open(RDriver1::Name());
1.56 + test(r==KErrNone);
1.57 +
1.58 + test.Next(_L("Get Device Capabilities"));
1.59 + RDriver1::TCaps caps;
1.60 + TPckg<RDriver1::TCaps>capsPckg(caps);
1.61 + capsPckg.FillZ(); // Zero 'caps' so we can tell if GetCaps has really filled it
1.62 + device.GetCaps(capsPckg);
1.63 + TVersion expectedVer(RDriver1::VersionRequired());
1.64 + test(caps.iVersion.iMajor==expectedVer.iMajor);
1.65 + test(caps.iVersion.iMinor==expectedVer.iMinor);
1.66 + test(caps.iVersion.iBuild==expectedVer.iBuild);
1.67 +
1.68 + test.Next(_L("Close Device"));
1.69 + device.Close();
1.70 +
1.71 + test.Next(_L("Open Logical Channel"));
1.72 + RDriver1 ldd;
1.73 + r=ldd.Open();
1.74 + test(r==KErrNone);
1.75 +
1.76 + test.Next(_L("GetConfig"));
1.77 + RDriver1::TConfigBuf configBuf;
1.78 + configBuf.FillZ(); // Zero 'config' so we can tell if GetConfig has really filled it
1.79 + r=ldd.GetConfig(configBuf);
1.80 + test(r==KErrNone);
1.81 +
1.82 + RDriver1::TConfig& config=configBuf();
1.83 + test(config.iPddBufferSize!=0);
1.84 + test(config.iMaxSendDataSize!=0);
1.85 + test(config.iMaxReceiveDataSize!=0);
1.86 +
1.87 + test.Next(_L("SetConfig"));
1.88 + TInt speed = configBuf().iSpeed+1;
1.89 + configBuf().iSpeed = speed;
1.90 + r=ldd.SetConfig(configBuf); // Use SetConfig to change speed
1.91 + test(r==KErrNone);
1.92 +
1.93 + configBuf.FillZ();
1.94 + r=ldd.GetConfig(configBuf);
1.95 + test(r==KErrNone);
1.96 + test(configBuf().iSpeed==speed);
1.97 +
1.98 + test.Next(_L("Check access by wrong client"));
1.99 + RDriver1 ldd2=ldd;
1.100 + r=ldd2.Duplicate(RThread(),EOwnerProcess);
1.101 + test(r==KErrAccessDenied);
1.102 +
1.103 + test.Next(_L("Check handle duplication"));
1.104 + ldd2=ldd;
1.105 + r=ldd2.Duplicate(RThread(),EOwnerThread);
1.106 + test(r==KErrNone);
1.107 + ldd2.Close();
1.108 +
1.109 + test.Next(_L("SendData"));
1.110 + TRequestStatus status;
1.111 + ldd.SendData(status,KTestSendData);
1.112 +
1.113 + test.Next(_L("SendDataCancel"));
1.114 + ldd.SendDataCancel();
1.115 + User::WaitForRequest(status);
1.116 + r=status.Int();
1.117 + test(r==KErrCancel);
1.118 +
1.119 + test.Next(_L("SendData"));
1.120 + ldd.SendData(status,KTestSendData);
1.121 + User::WaitForRequest(status);
1.122 + r=status.Int();
1.123 + test(r==KErrNone);
1.124 +
1.125 + test.Next(_L("ReceiveData"));
1.126 + TBuf8<256> buffer;
1.127 + ldd.ReceiveData(status,buffer);
1.128 +
1.129 + test.Next(_L("ReceiveDataCancel"));
1.130 + ldd.ReceiveDataCancel();
1.131 + User::WaitForRequest(status);
1.132 + r=status.Int();
1.133 + test(r==KErrCancel);
1.134 +
1.135 + test.Next(_L("ReceiveData"));
1.136 + buffer.FillZ(buffer.MaxLength());
1.137 + buffer.Zero();
1.138 + ldd.ReceiveData(status,buffer);
1.139 + User::WaitForRequest(status);
1.140 + r=status.Int();
1.141 + test(r==KErrNone);
1.142 +
1.143 + TInt expectedSize = config.iPddBufferSize;
1.144 + if(expectedSize>(&KTestSendData)->Size())
1.145 + expectedSize = (&KTestSendData)->Size();
1.146 + test(buffer.Size()==expectedSize);
1.147 + test(buffer==(&KTestSendData)->Right(expectedSize));
1.148 +
1.149 + test.Next(_L("Close Logical Channel"));
1.150 + ldd.Close();
1.151 +
1.152 + __KHEAP_MARKEND;
1.153 +
1.154 + test.Next(_L("Unload Logical Device"));
1.155 + r=User::FreeLogicalDevice(RDriver1::Name());
1.156 + test(r==KErrNone);
1.157 +
1.158 + test.Next(_L("Unload Physical Device"));
1.159 + TName pddName(RDriver1::Name());
1.160 + _LIT(KVariantExtension,".template");
1.161 + pddName.Append(KVariantExtension);
1.162 + r=User::FreePhysicalDevice(pddName);
1.163 + test(r==KErrNone);
1.164 +
1.165 + test.End();
1.166 +
1.167 + return(0);
1.168 + }
1.169 +
1.170 +