sl@0
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file Test code for example Device Driver
|
sl@0
|
18 |
@publishedPartner
|
sl@0
|
19 |
@released
|
sl@0
|
20 |
*/
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <e32test.h>
|
sl@0
|
23 |
#include <e32def.h>
|
sl@0
|
24 |
#include <e32def_private.h>
|
sl@0
|
25 |
#include "driver1.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
LOCAL_D RTest test(_L("DRIVER1_TEST"));
|
sl@0
|
28 |
|
sl@0
|
29 |
_LIT(KDriver1LddFileName,"DRIVER1_LDD");
|
sl@0
|
30 |
_LIT(KDriver1PddFileName,"DRIVER1_PDD");
|
sl@0
|
31 |
|
sl@0
|
32 |
_LIT8(KTestSendData,"abcdefghijklmnopqrstuvwxyz");
|
sl@0
|
33 |
|
sl@0
|
34 |
GLDEF_C TInt E32Main()
|
sl@0
|
35 |
{
|
sl@0
|
36 |
test.Title();
|
sl@0
|
37 |
|
sl@0
|
38 |
TInt r;
|
sl@0
|
39 |
|
sl@0
|
40 |
test.Start(_L("Load Physical Device"));
|
sl@0
|
41 |
r=User::LoadPhysicalDevice(KDriver1PddFileName);
|
sl@0
|
42 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
43 |
|
sl@0
|
44 |
test.Next(_L("Load Logical Device"));
|
sl@0
|
45 |
r=User::LoadLogicalDevice(KDriver1LddFileName);
|
sl@0
|
46 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
47 |
|
sl@0
|
48 |
__KHEAP_MARK;
|
sl@0
|
49 |
|
sl@0
|
50 |
test.Next(_L("Open Device"));
|
sl@0
|
51 |
RDevice device;
|
sl@0
|
52 |
r=device.Open(RDriver1::Name());
|
sl@0
|
53 |
test(r==KErrNone);
|
sl@0
|
54 |
|
sl@0
|
55 |
test.Next(_L("Get Device Capabilities"));
|
sl@0
|
56 |
RDriver1::TCaps caps;
|
sl@0
|
57 |
TPckg<RDriver1::TCaps>capsPckg(caps);
|
sl@0
|
58 |
capsPckg.FillZ(); // Zero 'caps' so we can tell if GetCaps has really filled it
|
sl@0
|
59 |
device.GetCaps(capsPckg);
|
sl@0
|
60 |
TVersion expectedVer(RDriver1::VersionRequired());
|
sl@0
|
61 |
test(caps.iVersion.iMajor==expectedVer.iMajor);
|
sl@0
|
62 |
test(caps.iVersion.iMinor==expectedVer.iMinor);
|
sl@0
|
63 |
test(caps.iVersion.iBuild==expectedVer.iBuild);
|
sl@0
|
64 |
|
sl@0
|
65 |
test.Next(_L("Close Device"));
|
sl@0
|
66 |
device.Close();
|
sl@0
|
67 |
|
sl@0
|
68 |
test.Next(_L("Open Logical Channel"));
|
sl@0
|
69 |
RDriver1 ldd;
|
sl@0
|
70 |
r=ldd.Open();
|
sl@0
|
71 |
test(r==KErrNone);
|
sl@0
|
72 |
|
sl@0
|
73 |
test.Next(_L("GetConfig"));
|
sl@0
|
74 |
RDriver1::TConfigBuf configBuf;
|
sl@0
|
75 |
configBuf.FillZ(); // Zero 'config' so we can tell if GetConfig has really filled it
|
sl@0
|
76 |
r=ldd.GetConfig(configBuf);
|
sl@0
|
77 |
test(r==KErrNone);
|
sl@0
|
78 |
|
sl@0
|
79 |
RDriver1::TConfig& config=configBuf();
|
sl@0
|
80 |
test(config.iPddBufferSize!=0);
|
sl@0
|
81 |
test(config.iMaxSendDataSize!=0);
|
sl@0
|
82 |
test(config.iMaxReceiveDataSize!=0);
|
sl@0
|
83 |
|
sl@0
|
84 |
test.Next(_L("SetConfig"));
|
sl@0
|
85 |
TInt speed = configBuf().iSpeed+1;
|
sl@0
|
86 |
configBuf().iSpeed = speed;
|
sl@0
|
87 |
r=ldd.SetConfig(configBuf); // Use SetConfig to change speed
|
sl@0
|
88 |
test(r==KErrNone);
|
sl@0
|
89 |
|
sl@0
|
90 |
configBuf.FillZ();
|
sl@0
|
91 |
r=ldd.GetConfig(configBuf);
|
sl@0
|
92 |
test(r==KErrNone);
|
sl@0
|
93 |
test(configBuf().iSpeed==speed);
|
sl@0
|
94 |
|
sl@0
|
95 |
test.Next(_L("Check access by wrong client"));
|
sl@0
|
96 |
RDriver1 ldd2=ldd;
|
sl@0
|
97 |
r=ldd2.Duplicate(RThread(),EOwnerProcess);
|
sl@0
|
98 |
test(r==KErrAccessDenied);
|
sl@0
|
99 |
|
sl@0
|
100 |
test.Next(_L("Check handle duplication"));
|
sl@0
|
101 |
ldd2=ldd;
|
sl@0
|
102 |
r=ldd2.Duplicate(RThread(),EOwnerThread);
|
sl@0
|
103 |
test(r==KErrNone);
|
sl@0
|
104 |
ldd2.Close();
|
sl@0
|
105 |
|
sl@0
|
106 |
test.Next(_L("SendData"));
|
sl@0
|
107 |
TRequestStatus status;
|
sl@0
|
108 |
ldd.SendData(status,KTestSendData);
|
sl@0
|
109 |
|
sl@0
|
110 |
test.Next(_L("SendDataCancel"));
|
sl@0
|
111 |
ldd.SendDataCancel();
|
sl@0
|
112 |
User::WaitForRequest(status);
|
sl@0
|
113 |
r=status.Int();
|
sl@0
|
114 |
test(r==KErrCancel);
|
sl@0
|
115 |
|
sl@0
|
116 |
test.Next(_L("SendData"));
|
sl@0
|
117 |
ldd.SendData(status,KTestSendData);
|
sl@0
|
118 |
User::WaitForRequest(status);
|
sl@0
|
119 |
r=status.Int();
|
sl@0
|
120 |
test(r==KErrNone);
|
sl@0
|
121 |
|
sl@0
|
122 |
test.Next(_L("ReceiveData"));
|
sl@0
|
123 |
TBuf8<256> buffer;
|
sl@0
|
124 |
ldd.ReceiveData(status,buffer);
|
sl@0
|
125 |
|
sl@0
|
126 |
test.Next(_L("ReceiveDataCancel"));
|
sl@0
|
127 |
ldd.ReceiveDataCancel();
|
sl@0
|
128 |
User::WaitForRequest(status);
|
sl@0
|
129 |
r=status.Int();
|
sl@0
|
130 |
test(r==KErrCancel);
|
sl@0
|
131 |
|
sl@0
|
132 |
test.Next(_L("ReceiveData"));
|
sl@0
|
133 |
buffer.FillZ(buffer.MaxLength());
|
sl@0
|
134 |
buffer.Zero();
|
sl@0
|
135 |
ldd.ReceiveData(status,buffer);
|
sl@0
|
136 |
User::WaitForRequest(status);
|
sl@0
|
137 |
r=status.Int();
|
sl@0
|
138 |
test(r==KErrNone);
|
sl@0
|
139 |
|
sl@0
|
140 |
TInt expectedSize = config.iPddBufferSize;
|
sl@0
|
141 |
if(expectedSize>(&KTestSendData)->Size())
|
sl@0
|
142 |
expectedSize = (&KTestSendData)->Size();
|
sl@0
|
143 |
test(buffer.Size()==expectedSize);
|
sl@0
|
144 |
test(buffer==(&KTestSendData)->Right(expectedSize));
|
sl@0
|
145 |
|
sl@0
|
146 |
test.Next(_L("Close Logical Channel"));
|
sl@0
|
147 |
ldd.Close();
|
sl@0
|
148 |
|
sl@0
|
149 |
__KHEAP_MARKEND;
|
sl@0
|
150 |
|
sl@0
|
151 |
test.Next(_L("Unload Logical Device"));
|
sl@0
|
152 |
r=User::FreeLogicalDevice(RDriver1::Name());
|
sl@0
|
153 |
test(r==KErrNone);
|
sl@0
|
154 |
|
sl@0
|
155 |
test.Next(_L("Unload Physical Device"));
|
sl@0
|
156 |
TName pddName(RDriver1::Name());
|
sl@0
|
157 |
_LIT(KVariantExtension,".template");
|
sl@0
|
158 |
pddName.Append(KVariantExtension);
|
sl@0
|
159 |
r=User::FreePhysicalDevice(pddName);
|
sl@0
|
160 |
test(r==KErrNone);
|
sl@0
|
161 |
|
sl@0
|
162 |
test.End();
|
sl@0
|
163 |
|
sl@0
|
164 |
return(0);
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
|