Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
15 // in its implementation.
20 @file Test code for example data converter device driver which uses Shared Chunks
28 #include <e32def_private.h>
31 LOCAL_D RTest test(_L("CONVERT1_TEST"));
35 RConvert1::TConfigBuf ConfigBuf;
37 _LIT(KConvert1FileName,"convert1_ldd");
40 _LIT8(KTestData1,"0123456789ABCDEF");
41 _LIT8(KTestData2,"1032547698@CBEDG");
43 class RHeapFriend : public RHeap
45 public: RChunk Chunk() { return *(RChunk*)&iChunkHandle; };
48 GLDEF_C TInt E32Main()
55 test.Start(_L("Load Device"));
56 r=User::LoadLogicalDevice(KConvert1FileName);
57 test(r==KErrNone || r==KErrAlreadyExists);
61 test.Next(_L("Open Device"));
63 r=device.Open(RConvert1::Name());
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);
77 test.Next(_L("Close Device"));
80 test.Next(_L("Open Logical Channel"));
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);
90 // Check config values
91 const TInt KDefaultBufferSize(config.iBufferSize);
92 test(KDefaultBufferSize!=0);
93 test(config.iSpeed!=0);
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);
103 test.Next(_L("Check config set"));
105 r=Convert.GetConfig(ConfigBuf);
107 test(config.iBufferSize==KDefaultBufferSize*2);
109 test.Next(_L("Check access by wrong client"));
110 RConvert1 ldd2=Convert;
111 r=((RHandleBase&)ldd2).Duplicate(RThread(),EOwnerProcess);
112 test(r==KErrAccessDenied);
114 test.Next(_L("Check handle duplication"));
116 r=((RHandleBase&)ldd2).Duplicate(RThread(),EOwnerThread);
118 ((RHandleBase&)ldd2).Close();
120 test.Next(_L("Check input chunk handle"));
121 TUint8* chunkBase = Convert.InChunk().Base();
124 test.Next(_L("Convert a descriptor"));
125 Convert.Convert(KTestData1,s);
126 User::WaitForRequest(s);
129 TPtrC8 out(Convert.OutChunk().Base()+r,KTestData1().Size());
130 test(out==KTestData2);
132 test.Next(_L("Convert a descriptor (too big)"));
134 test(big.CreateMax(config.iBufferSize+1)==KErrNone);
135 Convert.Convert(big,s);
136 User::WaitForRequest(s);
140 test.Next(_L("Convert a descriptor (max length)"));
141 big.SetLength(big.Length()-1);
142 Convert.Convert(big,s);
143 User::WaitForRequest(s);
149 test.Next(_L("Convert a descriptor in a shared chunk"));
150 TPtr8 in(chunkBase+KTestData2().Size(),KTestData2().Size());
152 Convert.Convert(in,s);
153 User::WaitForRequest(s);
156 TPtrC8 out(Convert.OutChunk().Base()+r,KTestData2().Size());
157 test(out==KTestData1);
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);
167 test.Next(_L("Convert data in a shared chunk"));
168 TInt offset = 2*KTestData1().Size();
169 TPtr8 in(chunkBase+offset,KTestData1().Size());
171 Convert.Convert(Convert.InChunk(),offset,KTestData1().Size(),s);
172 User::WaitForRequest(s);
175 TPtrC8 out(Convert.OutChunk().Base()+r,KTestData1().Size());
176 test(out==KTestData2);
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);
182 test(r==KErrArgument);
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);
188 test(r==KErrNotFound || r==KErrArgument);
192 test.Next(_L("Convert data in input shared chunk"));
193 Convert.InBuffer() = KTestData2;
194 Convert.Convert(KTestData2().Size(),s);
195 User::WaitForRequest(s);
198 TPtrC8 out(Convert.OutChunk().Base()+r,KTestData2().Size());
199 test(out==KTestData1);
202 test.Next(_L("Close Logical Channel"));
206 test.Next(_L("Test max number of Logical Channels"));
207 RConvert1* channels = new RConvert1[caps.iMaxChannels+1];
209 // Open max number of channels
210 for(; i<caps.iMaxChannels; i++)
211 test(channels[i].Open()==KErrNone);
213 test(channels[i].Open()==KErrInUse);
214 // Close all channels
220 User::After(500000); // allow any async close operations to complete
224 test.Next(_L("Unload Device"));
225 User::FreeLogicalDevice(RConvert1::Name());