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