Update contrib.
1 // Copyright (c) 2003-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.
17 @file Test code for example Device Driver
24 #include <e32def_private.h>
27 LOCAL_D RTest test(_L("DRIVER1_TEST"));
29 _LIT(KDriver1LddFileName,"DRIVER1_LDD");
30 _LIT(KDriver1PddFileName,"DRIVER1_PDD");
32 _LIT8(KTestSendData,"abcdefghijklmnopqrstuvwxyz");
34 GLDEF_C TInt E32Main()
40 test.Start(_L("Load Physical Device"));
41 r=User::LoadPhysicalDevice(KDriver1PddFileName);
42 test(r==KErrNone || r==KErrAlreadyExists);
44 test.Next(_L("Load Logical Device"));
45 r=User::LoadLogicalDevice(KDriver1LddFileName);
46 test(r==KErrNone || r==KErrAlreadyExists);
50 test.Next(_L("Open Device"));
52 r=device.Open(RDriver1::Name());
55 test.Next(_L("Get Device Capabilities"));
57 TPckg<RDriver1::TCaps>capsPckg(caps);
58 capsPckg.FillZ(); // Zero 'caps' so we can tell if GetCaps has really filled it
59 device.GetCaps(capsPckg);
60 TVersion expectedVer(RDriver1::VersionRequired());
61 test(caps.iVersion.iMajor==expectedVer.iMajor);
62 test(caps.iVersion.iMinor==expectedVer.iMinor);
63 test(caps.iVersion.iBuild==expectedVer.iBuild);
65 test.Next(_L("Close Device"));
68 test.Next(_L("Open Logical Channel"));
73 test.Next(_L("GetConfig"));
74 RDriver1::TConfigBuf configBuf;
75 configBuf.FillZ(); // Zero 'config' so we can tell if GetConfig has really filled it
76 r=ldd.GetConfig(configBuf);
79 RDriver1::TConfig& config=configBuf();
80 test(config.iPddBufferSize!=0);
81 test(config.iMaxSendDataSize!=0);
82 test(config.iMaxReceiveDataSize!=0);
84 test.Next(_L("SetConfig"));
85 TInt speed = configBuf().iSpeed+1;
86 configBuf().iSpeed = speed;
87 r=ldd.SetConfig(configBuf); // Use SetConfig to change speed
91 r=ldd.GetConfig(configBuf);
93 test(configBuf().iSpeed==speed);
95 test.Next(_L("Check access by wrong client"));
97 r=ldd2.Duplicate(RThread(),EOwnerProcess);
98 test(r==KErrAccessDenied);
100 test.Next(_L("Check handle duplication"));
102 r=ldd2.Duplicate(RThread(),EOwnerThread);
106 test.Next(_L("SendData"));
107 TRequestStatus status;
108 ldd.SendData(status,KTestSendData);
110 test.Next(_L("SendDataCancel"));
111 ldd.SendDataCancel();
112 User::WaitForRequest(status);
116 test.Next(_L("SendData"));
117 ldd.SendData(status,KTestSendData);
118 User::WaitForRequest(status);
122 test.Next(_L("ReceiveData"));
124 ldd.ReceiveData(status,buffer);
126 test.Next(_L("ReceiveDataCancel"));
127 ldd.ReceiveDataCancel();
128 User::WaitForRequest(status);
132 test.Next(_L("ReceiveData"));
133 buffer.FillZ(buffer.MaxLength());
135 ldd.ReceiveData(status,buffer);
136 User::WaitForRequest(status);
140 TInt expectedSize = config.iPddBufferSize;
141 if(expectedSize>(&KTestSendData)->Size())
142 expectedSize = (&KTestSendData)->Size();
143 test(buffer.Size()==expectedSize);
144 test(buffer==(&KTestSendData)->Right(expectedSize));
146 test.Next(_L("Close Logical Channel"));
151 test.Next(_L("Unload Logical Device"));
152 r=User::FreeLogicalDevice(RDriver1::Name());
155 test.Next(_L("Unload Physical Device"));
156 TName pddName(RDriver1::Name());
157 _LIT(KVariantExtension,".template");
158 pddName.Append(KVariantExtension);
159 r=User::FreePhysicalDevice(pddName);