|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file Test code for example Device Driver |
|
18 @publishedPartner |
|
19 @released |
|
20 */ |
|
21 |
|
22 #include <e32test.h> |
|
23 #include <e32def.h> |
|
24 #include <e32def_private.h> |
|
25 #include "driver1.h" |
|
26 |
|
27 LOCAL_D RTest test(_L("DRIVER1_TEST")); |
|
28 |
|
29 _LIT(KDriver1LddFileName,"DRIVER1_LDD"); |
|
30 _LIT(KDriver1PddFileName,"DRIVER1_PDD"); |
|
31 |
|
32 _LIT8(KTestSendData,"abcdefghijklmnopqrstuvwxyz"); |
|
33 |
|
34 GLDEF_C TInt E32Main() |
|
35 { |
|
36 test.Title(); |
|
37 |
|
38 TInt r; |
|
39 |
|
40 test.Start(_L("Load Physical Device")); |
|
41 r=User::LoadPhysicalDevice(KDriver1PddFileName); |
|
42 test(r==KErrNone || r==KErrAlreadyExists); |
|
43 |
|
44 test.Next(_L("Load Logical Device")); |
|
45 r=User::LoadLogicalDevice(KDriver1LddFileName); |
|
46 test(r==KErrNone || r==KErrAlreadyExists); |
|
47 |
|
48 __KHEAP_MARK; |
|
49 |
|
50 test.Next(_L("Open Device")); |
|
51 RDevice device; |
|
52 r=device.Open(RDriver1::Name()); |
|
53 test(r==KErrNone); |
|
54 |
|
55 test.Next(_L("Get Device Capabilities")); |
|
56 RDriver1::TCaps caps; |
|
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); |
|
64 |
|
65 test.Next(_L("Close Device")); |
|
66 device.Close(); |
|
67 |
|
68 test.Next(_L("Open Logical Channel")); |
|
69 RDriver1 ldd; |
|
70 r=ldd.Open(); |
|
71 test(r==KErrNone); |
|
72 |
|
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); |
|
77 test(r==KErrNone); |
|
78 |
|
79 RDriver1::TConfig& config=configBuf(); |
|
80 test(config.iPddBufferSize!=0); |
|
81 test(config.iMaxSendDataSize!=0); |
|
82 test(config.iMaxReceiveDataSize!=0); |
|
83 |
|
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 |
|
88 test(r==KErrNone); |
|
89 |
|
90 configBuf.FillZ(); |
|
91 r=ldd.GetConfig(configBuf); |
|
92 test(r==KErrNone); |
|
93 test(configBuf().iSpeed==speed); |
|
94 |
|
95 test.Next(_L("Check access by wrong client")); |
|
96 RDriver1 ldd2=ldd; |
|
97 r=ldd2.Duplicate(RThread(),EOwnerProcess); |
|
98 test(r==KErrAccessDenied); |
|
99 |
|
100 test.Next(_L("Check handle duplication")); |
|
101 ldd2=ldd; |
|
102 r=ldd2.Duplicate(RThread(),EOwnerThread); |
|
103 test(r==KErrNone); |
|
104 ldd2.Close(); |
|
105 |
|
106 test.Next(_L("SendData")); |
|
107 TRequestStatus status; |
|
108 ldd.SendData(status,KTestSendData); |
|
109 |
|
110 test.Next(_L("SendDataCancel")); |
|
111 ldd.SendDataCancel(); |
|
112 User::WaitForRequest(status); |
|
113 r=status.Int(); |
|
114 test(r==KErrCancel); |
|
115 |
|
116 test.Next(_L("SendData")); |
|
117 ldd.SendData(status,KTestSendData); |
|
118 User::WaitForRequest(status); |
|
119 r=status.Int(); |
|
120 test(r==KErrNone); |
|
121 |
|
122 test.Next(_L("ReceiveData")); |
|
123 TBuf8<256> buffer; |
|
124 ldd.ReceiveData(status,buffer); |
|
125 |
|
126 test.Next(_L("ReceiveDataCancel")); |
|
127 ldd.ReceiveDataCancel(); |
|
128 User::WaitForRequest(status); |
|
129 r=status.Int(); |
|
130 test(r==KErrCancel); |
|
131 |
|
132 test.Next(_L("ReceiveData")); |
|
133 buffer.FillZ(buffer.MaxLength()); |
|
134 buffer.Zero(); |
|
135 ldd.ReceiveData(status,buffer); |
|
136 User::WaitForRequest(status); |
|
137 r=status.Int(); |
|
138 test(r==KErrNone); |
|
139 |
|
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)); |
|
145 |
|
146 test.Next(_L("Close Logical Channel")); |
|
147 ldd.Close(); |
|
148 |
|
149 __KHEAP_MARKEND; |
|
150 |
|
151 test.Next(_L("Unload Logical Device")); |
|
152 r=User::FreeLogicalDevice(RDriver1::Name()); |
|
153 test(r==KErrNone); |
|
154 |
|
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); |
|
160 test(r==KErrNone); |
|
161 |
|
162 test.End(); |
|
163 |
|
164 return(0); |
|
165 } |
|
166 |
|
167 |