|
1 // Copyright (c) 2005-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 // camera1_test.cpp |
|
15 // in its implementation. |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file Test code for example data converter device driver which uses Shared Chunks |
|
21 @publishedPartner |
|
22 @prototype 9.1 |
|
23 */ |
|
24 |
|
25 #include <e32test.h> |
|
26 #include <e32svr.h> |
|
27 #include <e32def.h> |
|
28 #include <e32def_private.h> |
|
29 #include "convert1.h" |
|
30 |
|
31 LOCAL_D RTest test(_L("CONVERT1_TEST")); |
|
32 |
|
33 RConvert1 Convert; |
|
34 |
|
35 RConvert1::TConfigBuf ConfigBuf; |
|
36 |
|
37 _LIT(KConvert1FileName,"convert1_ldd"); |
|
38 |
|
39 |
|
40 _LIT8(KTestData1,"0123456789ABCDEF"); |
|
41 _LIT8(KTestData2,"1032547698@CBEDG"); |
|
42 |
|
43 class RHeapFriend : public RHeap |
|
44 { |
|
45 public: RChunk Chunk() { return *(RChunk*)&iChunkHandle; }; |
|
46 }; |
|
47 |
|
48 GLDEF_C TInt E32Main() |
|
49 { |
|
50 test.Title(); |
|
51 |
|
52 TInt r; |
|
53 TRequestStatus s; |
|
54 |
|
55 test.Start(_L("Load Device")); |
|
56 r=User::LoadLogicalDevice(KConvert1FileName); |
|
57 test(r==KErrNone || r==KErrAlreadyExists); |
|
58 |
|
59 __KHEAP_MARK; |
|
60 |
|
61 test.Next(_L("Open Device")); |
|
62 RDevice device; |
|
63 r=device.Open(RConvert1::Name()); |
|
64 test(r==KErrNone); |
|
65 |
|
66 test.Next(_L("Get Device Capabilities")); |
|
67 RConvert1::TCaps caps; |
|
68 TPckg<RConvert1::TCaps>capsPckg(caps); |
|
69 capsPckg.FillZ(); // Zero 'caps' so we can tell if GetCaps has really filled it |
|
70 device.GetCaps(capsPckg); |
|
71 TVersion expectedVer(RConvert1::VersionRequired()); |
|
72 test(caps.iVersion.iMajor==expectedVer.iMajor); |
|
73 test(caps.iVersion.iMinor==expectedVer.iMinor); |
|
74 test(caps.iVersion.iBuild==expectedVer.iBuild); |
|
75 test(caps.iMaxChannels>0); |
|
76 |
|
77 test.Next(_L("Close Device")); |
|
78 device.Close(); |
|
79 |
|
80 test.Next(_L("Open Logical Channel")); |
|
81 r=Convert.Open(); |
|
82 test(r==KErrNone); |
|
83 |
|
84 test.Next(_L("GetConfig")); |
|
85 RConvert1::TConfig& config=ConfigBuf(); |
|
86 ConfigBuf.FillZ(); // Zero 'config' so we can tell if GetConfig has really filled it |
|
87 r=Convert.GetConfig(ConfigBuf); |
|
88 test(r==KErrNone); |
|
89 |
|
90 // Check config values |
|
91 const TInt KDefaultBufferSize(config.iBufferSize); |
|
92 test(KDefaultBufferSize!=0); |
|
93 test(config.iSpeed!=0); |
|
94 |
|
95 test.Next(_L("SetConfig")); |
|
96 config.iBufferSize = KDefaultBufferSize*2; |
|
97 config.iCreateInputChunk = ETrue; |
|
98 test.Printf(_L("config = %d,%d,%d"),config.iBufferSize,config.iCreateInputChunk,config.iSpeed); |
|
99 r=Convert.SetConfig(ConfigBuf); |
|
100 test.Printf(_L("result = %d"),r); |
|
101 test(r==KErrNone); |
|
102 |
|
103 test.Next(_L("Check config set")); |
|
104 ConfigBuf.FillZ(); |
|
105 r=Convert.GetConfig(ConfigBuf); |
|
106 test(r==KErrNone); |
|
107 test(config.iBufferSize==KDefaultBufferSize*2); |
|
108 |
|
109 test.Next(_L("Check access by wrong client")); |
|
110 RConvert1 ldd2=Convert; |
|
111 r=((RHandleBase&)ldd2).Duplicate(RThread(),EOwnerProcess); |
|
112 test(r==KErrAccessDenied); |
|
113 |
|
114 test.Next(_L("Check handle duplication")); |
|
115 ldd2=Convert; |
|
116 r=((RHandleBase&)ldd2).Duplicate(RThread(),EOwnerThread); |
|
117 test(r==KErrNone); |
|
118 ((RHandleBase&)ldd2).Close(); |
|
119 |
|
120 test.Next(_L("Check input chunk handle")); |
|
121 TUint8* chunkBase = Convert.InChunk().Base(); |
|
122 |
|
123 { |
|
124 test.Next(_L("Convert a descriptor")); |
|
125 Convert.Convert(KTestData1,s); |
|
126 User::WaitForRequest(s); |
|
127 r = s.Int(); |
|
128 test(r>=0); |
|
129 TPtrC8 out(Convert.OutChunk().Base()+r,KTestData1().Size()); |
|
130 test(out==KTestData2); |
|
131 |
|
132 test.Next(_L("Convert a descriptor (too big)")); |
|
133 RBuf8 big; |
|
134 test(big.CreateMax(config.iBufferSize+1)==KErrNone); |
|
135 Convert.Convert(big,s); |
|
136 User::WaitForRequest(s); |
|
137 r = s.Int(); |
|
138 test(r==KErrTooBig); |
|
139 |
|
140 test.Next(_L("Convert a descriptor (max length)")); |
|
141 big.SetLength(big.Length()-1); |
|
142 Convert.Convert(big,s); |
|
143 User::WaitForRequest(s); |
|
144 r = s.Int(); |
|
145 test(r==KErrNone); |
|
146 } |
|
147 |
|
148 { |
|
149 test.Next(_L("Convert a descriptor in a shared chunk")); |
|
150 TPtr8 in(chunkBase+KTestData2().Size(),KTestData2().Size()); |
|
151 in = KTestData2; |
|
152 Convert.Convert(in,s); |
|
153 User::WaitForRequest(s); |
|
154 r = s.Int(); |
|
155 test(r>=0); |
|
156 TPtrC8 out(Convert.OutChunk().Base()+r,KTestData2().Size()); |
|
157 test(out==KTestData1); |
|
158 |
|
159 test.Next(_L("Convert a descriptor in a shared chunk (overflow chunk)")); |
|
160 Convert.Convert(TPtr8(chunkBase+1,config.iBufferSize),s); |
|
161 User::WaitForRequest(s); |
|
162 r = s.Int(); |
|
163 test(r==KErrNone); |
|
164 } |
|
165 |
|
166 { |
|
167 test.Next(_L("Convert data in a shared chunk")); |
|
168 TInt offset = 2*KTestData1().Size(); |
|
169 TPtr8 in(chunkBase+offset,KTestData1().Size()); |
|
170 in = KTestData1; |
|
171 Convert.Convert(Convert.InChunk(),offset,KTestData1().Size(),s); |
|
172 User::WaitForRequest(s); |
|
173 r = s.Int(); |
|
174 test(r>=0); |
|
175 TPtrC8 out(Convert.OutChunk().Base()+r,KTestData1().Size()); |
|
176 test(out==KTestData2); |
|
177 |
|
178 test.Next(_L("Convert data in a non-shared chunk (should fail)")); |
|
179 Convert.Convert(((RHeapFriend&)User::Heap()).Chunk(),offset,KTestData1().Size(),s); |
|
180 User::WaitForRequest(s); |
|
181 r = s.Int(); |
|
182 test(r==KErrArgument); |
|
183 |
|
184 test.Next(_L("Convert data in a shared chunk (overflow chunk)")); |
|
185 Convert.Convert(Convert.InChunk(),1,config.iBufferSize,s); |
|
186 User::WaitForRequest(s); |
|
187 r = s.Int(); |
|
188 test(r==KErrNotFound || r==KErrArgument); |
|
189 } |
|
190 |
|
191 { |
|
192 test.Next(_L("Convert data in input shared chunk")); |
|
193 Convert.InBuffer() = KTestData2; |
|
194 Convert.Convert(KTestData2().Size(),s); |
|
195 User::WaitForRequest(s); |
|
196 r = s.Int(); |
|
197 test(r>=0); |
|
198 TPtrC8 out(Convert.OutChunk().Base()+r,KTestData2().Size()); |
|
199 test(out==KTestData1); |
|
200 } |
|
201 |
|
202 test.Next(_L("Close Logical Channel")); |
|
203 Convert.Close(); |
|
204 |
|
205 { |
|
206 test.Next(_L("Test max number of Logical Channels")); |
|
207 RConvert1* channels = new RConvert1[caps.iMaxChannels+1]; |
|
208 TInt i=0; |
|
209 // Open max number of channels |
|
210 for(; i<caps.iMaxChannels; i++) |
|
211 test(channels[i].Open()==KErrNone); |
|
212 // Try one more |
|
213 test(channels[i].Open()==KErrInUse); |
|
214 // Close all channels |
|
215 while(--i>=0) |
|
216 channels[i].Close(); |
|
217 delete[] channels; |
|
218 } |
|
219 |
|
220 User::After(500000); // allow any async close operations to complete |
|
221 |
|
222 __KHEAP_MARKEND; |
|
223 |
|
224 test.Next(_L("Unload Device")); |
|
225 User::FreeLogicalDevice(RConvert1::Name()); |
|
226 |
|
227 test.End(); |
|
228 |
|
229 return(0); |
|
230 } |
|
231 |
|
232 |