1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/examples/convert1/convert1_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,232 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// camera1_test.cpp
1.18 +// in its implementation.
1.19 +//
1.20 +//
1.21 +
1.22 +/**
1.23 + @file Test code for example data converter device driver which uses Shared Chunks
1.24 + @publishedPartner
1.25 + @prototype 9.1
1.26 +*/
1.27 +
1.28 +#include <e32test.h>
1.29 +#include <e32svr.h>
1.30 +#include <e32def.h>
1.31 +#include <e32def_private.h>
1.32 +#include "convert1.h"
1.33 +
1.34 +LOCAL_D RTest test(_L("CONVERT1_TEST"));
1.35 +
1.36 +RConvert1 Convert;
1.37 +
1.38 +RConvert1::TConfigBuf ConfigBuf;
1.39 +
1.40 +_LIT(KConvert1FileName,"convert1_ldd");
1.41 +
1.42 +
1.43 +_LIT8(KTestData1,"0123456789ABCDEF");
1.44 +_LIT8(KTestData2,"1032547698@CBEDG");
1.45 +
1.46 +class RHeapFriend : public RHeap
1.47 + {
1.48 +public: RChunk Chunk() { return *(RChunk*)&iChunkHandle; };
1.49 + };
1.50 +
1.51 +GLDEF_C TInt E32Main()
1.52 + {
1.53 + test.Title();
1.54 +
1.55 + TInt r;
1.56 + TRequestStatus s;
1.57 +
1.58 + test.Start(_L("Load Device"));
1.59 + r=User::LoadLogicalDevice(KConvert1FileName);
1.60 + test(r==KErrNone || r==KErrAlreadyExists);
1.61 +
1.62 + __KHEAP_MARK;
1.63 +
1.64 + test.Next(_L("Open Device"));
1.65 + RDevice device;
1.66 + r=device.Open(RConvert1::Name());
1.67 + test(r==KErrNone);
1.68 +
1.69 + test.Next(_L("Get Device Capabilities"));
1.70 + RConvert1::TCaps caps;
1.71 + TPckg<RConvert1::TCaps>capsPckg(caps);
1.72 + capsPckg.FillZ(); // Zero 'caps' so we can tell if GetCaps has really filled it
1.73 + device.GetCaps(capsPckg);
1.74 + TVersion expectedVer(RConvert1::VersionRequired());
1.75 + test(caps.iVersion.iMajor==expectedVer.iMajor);
1.76 + test(caps.iVersion.iMinor==expectedVer.iMinor);
1.77 + test(caps.iVersion.iBuild==expectedVer.iBuild);
1.78 + test(caps.iMaxChannels>0);
1.79 +
1.80 + test.Next(_L("Close Device"));
1.81 + device.Close();
1.82 +
1.83 + test.Next(_L("Open Logical Channel"));
1.84 + r=Convert.Open();
1.85 + test(r==KErrNone);
1.86 +
1.87 + test.Next(_L("GetConfig"));
1.88 + RConvert1::TConfig& config=ConfigBuf();
1.89 + ConfigBuf.FillZ(); // Zero 'config' so we can tell if GetConfig has really filled it
1.90 + r=Convert.GetConfig(ConfigBuf);
1.91 + test(r==KErrNone);
1.92 +
1.93 + // Check config values
1.94 + const TInt KDefaultBufferSize(config.iBufferSize);
1.95 + test(KDefaultBufferSize!=0);
1.96 + test(config.iSpeed!=0);
1.97 +
1.98 + test.Next(_L("SetConfig"));
1.99 + config.iBufferSize = KDefaultBufferSize*2;
1.100 + config.iCreateInputChunk = ETrue;
1.101 + test.Printf(_L("config = %d,%d,%d"),config.iBufferSize,config.iCreateInputChunk,config.iSpeed);
1.102 + r=Convert.SetConfig(ConfigBuf);
1.103 + test.Printf(_L("result = %d"),r);
1.104 + test(r==KErrNone);
1.105 +
1.106 + test.Next(_L("Check config set"));
1.107 + ConfigBuf.FillZ();
1.108 + r=Convert.GetConfig(ConfigBuf);
1.109 + test(r==KErrNone);
1.110 + test(config.iBufferSize==KDefaultBufferSize*2);
1.111 +
1.112 + test.Next(_L("Check access by wrong client"));
1.113 + RConvert1 ldd2=Convert;
1.114 + r=((RHandleBase&)ldd2).Duplicate(RThread(),EOwnerProcess);
1.115 + test(r==KErrAccessDenied);
1.116 +
1.117 + test.Next(_L("Check handle duplication"));
1.118 + ldd2=Convert;
1.119 + r=((RHandleBase&)ldd2).Duplicate(RThread(),EOwnerThread);
1.120 + test(r==KErrNone);
1.121 + ((RHandleBase&)ldd2).Close();
1.122 +
1.123 + test.Next(_L("Check input chunk handle"));
1.124 + TUint8* chunkBase = Convert.InChunk().Base();
1.125 +
1.126 + {
1.127 + test.Next(_L("Convert a descriptor"));
1.128 + Convert.Convert(KTestData1,s);
1.129 + User::WaitForRequest(s);
1.130 + r = s.Int();
1.131 + test(r>=0);
1.132 + TPtrC8 out(Convert.OutChunk().Base()+r,KTestData1().Size());
1.133 + test(out==KTestData2);
1.134 +
1.135 + test.Next(_L("Convert a descriptor (too big)"));
1.136 + RBuf8 big;
1.137 + test(big.CreateMax(config.iBufferSize+1)==KErrNone);
1.138 + Convert.Convert(big,s);
1.139 + User::WaitForRequest(s);
1.140 + r = s.Int();
1.141 + test(r==KErrTooBig);
1.142 +
1.143 + test.Next(_L("Convert a descriptor (max length)"));
1.144 + big.SetLength(big.Length()-1);
1.145 + Convert.Convert(big,s);
1.146 + User::WaitForRequest(s);
1.147 + r = s.Int();
1.148 + test(r==KErrNone);
1.149 + }
1.150 +
1.151 + {
1.152 + test.Next(_L("Convert a descriptor in a shared chunk"));
1.153 + TPtr8 in(chunkBase+KTestData2().Size(),KTestData2().Size());
1.154 + in = KTestData2;
1.155 + Convert.Convert(in,s);
1.156 + User::WaitForRequest(s);
1.157 + r = s.Int();
1.158 + test(r>=0);
1.159 + TPtrC8 out(Convert.OutChunk().Base()+r,KTestData2().Size());
1.160 + test(out==KTestData1);
1.161 +
1.162 + test.Next(_L("Convert a descriptor in a shared chunk (overflow chunk)"));
1.163 + Convert.Convert(TPtr8(chunkBase+1,config.iBufferSize),s);
1.164 + User::WaitForRequest(s);
1.165 + r = s.Int();
1.166 + test(r==KErrNone);
1.167 + }
1.168 +
1.169 + {
1.170 + test.Next(_L("Convert data in a shared chunk"));
1.171 + TInt offset = 2*KTestData1().Size();
1.172 + TPtr8 in(chunkBase+offset,KTestData1().Size());
1.173 + in = KTestData1;
1.174 + Convert.Convert(Convert.InChunk(),offset,KTestData1().Size(),s);
1.175 + User::WaitForRequest(s);
1.176 + r = s.Int();
1.177 + test(r>=0);
1.178 + TPtrC8 out(Convert.OutChunk().Base()+r,KTestData1().Size());
1.179 + test(out==KTestData2);
1.180 +
1.181 + test.Next(_L("Convert data in a non-shared chunk (should fail)"));
1.182 + Convert.Convert(((RHeapFriend&)User::Heap()).Chunk(),offset,KTestData1().Size(),s);
1.183 + User::WaitForRequest(s);
1.184 + r = s.Int();
1.185 + test(r==KErrArgument);
1.186 +
1.187 + test.Next(_L("Convert data in a shared chunk (overflow chunk)"));
1.188 + Convert.Convert(Convert.InChunk(),1,config.iBufferSize,s);
1.189 + User::WaitForRequest(s);
1.190 + r = s.Int();
1.191 + test(r==KErrNotFound || r==KErrArgument);
1.192 + }
1.193 +
1.194 + {
1.195 + test.Next(_L("Convert data in input shared chunk"));
1.196 + Convert.InBuffer() = KTestData2;
1.197 + Convert.Convert(KTestData2().Size(),s);
1.198 + User::WaitForRequest(s);
1.199 + r = s.Int();
1.200 + test(r>=0);
1.201 + TPtrC8 out(Convert.OutChunk().Base()+r,KTestData2().Size());
1.202 + test(out==KTestData1);
1.203 + }
1.204 +
1.205 + test.Next(_L("Close Logical Channel"));
1.206 + Convert.Close();
1.207 +
1.208 + {
1.209 + test.Next(_L("Test max number of Logical Channels"));
1.210 + RConvert1* channels = new RConvert1[caps.iMaxChannels+1];
1.211 + TInt i=0;
1.212 + // Open max number of channels
1.213 + for(; i<caps.iMaxChannels; i++)
1.214 + test(channels[i].Open()==KErrNone);
1.215 + // Try one more
1.216 + test(channels[i].Open()==KErrInUse);
1.217 + // Close all channels
1.218 + while(--i>=0)
1.219 + channels[i].Close();
1.220 + delete[] channels;
1.221 + }
1.222 +
1.223 + User::After(500000); // allow any async close operations to complete
1.224 +
1.225 + __KHEAP_MARKEND;
1.226 +
1.227 + test.Next(_L("Unload Device"));
1.228 + User::FreeLogicalDevice(RConvert1::Name());
1.229 +
1.230 + test.End();
1.231 +
1.232 + return(0);
1.233 + }
1.234 +
1.235 +