kerneltest/e32test/buffer/d_version.cpp
author hgs
Mon, 11 Oct 2010 17:54:41 +0100
changeset 286 48e57fb1237e
parent 271 dc268b18d709
permissions -rw-r--r--
201039_11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
271
dc268b18d709 201037_07
hgs
parents:
diff changeset
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
dc268b18d709 201037_07
hgs
parents:
diff changeset
     2
// All rights reserved.
dc268b18d709 201037_07
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
dc268b18d709 201037_07
hgs
parents:
diff changeset
     4
// under the terms of the License "Eclipse Public License v1.0"
dc268b18d709 201037_07
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
dc268b18d709 201037_07
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
dc268b18d709 201037_07
hgs
parents:
diff changeset
     7
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
     8
// Initial Contributors:
dc268b18d709 201037_07
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
dc268b18d709 201037_07
hgs
parents:
diff changeset
    10
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    11
// Contributors:
dc268b18d709 201037_07
hgs
parents:
diff changeset
    12
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    13
// Description:
dc268b18d709 201037_07
hgs
parents:
diff changeset
    14
// e32test\buffer\d_version.cpp
dc268b18d709 201037_07
hgs
parents:
diff changeset
    15
// LDD for testing kernel side of TVersion
dc268b18d709 201037_07
hgs
parents:
diff changeset
    16
// 
dc268b18d709 201037_07
hgs
parents:
diff changeset
    17
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    18
dc268b18d709 201037_07
hgs
parents:
diff changeset
    19
#include <kernel/kern_priv.h>
dc268b18d709 201037_07
hgs
parents:
diff changeset
    20
#include "d_version.h"
dc268b18d709 201037_07
hgs
parents:
diff changeset
    21
dc268b18d709 201037_07
hgs
parents:
diff changeset
    22
class DVersionTestFactory : public DLogicalDevice
dc268b18d709 201037_07
hgs
parents:
diff changeset
    23
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    24
// VersionTest LDD factory
dc268b18d709 201037_07
hgs
parents:
diff changeset
    25
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    26
	{
dc268b18d709 201037_07
hgs
parents:
diff changeset
    27
public:
dc268b18d709 201037_07
hgs
parents:
diff changeset
    28
	DVersionTestFactory();
dc268b18d709 201037_07
hgs
parents:
diff changeset
    29
	~DVersionTestFactory();
dc268b18d709 201037_07
hgs
parents:
diff changeset
    30
	virtual TInt Install();						//overriding pure virtual
dc268b18d709 201037_07
hgs
parents:
diff changeset
    31
	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
dc268b18d709 201037_07
hgs
parents:
diff changeset
    32
	virtual TInt Create(DLogicalChannelBase*& aChannel);	//overriding pure virtual
dc268b18d709 201037_07
hgs
parents:
diff changeset
    33
	};
dc268b18d709 201037_07
hgs
parents:
diff changeset
    34
dc268b18d709 201037_07
hgs
parents:
diff changeset
    35
class DVersionTest : public DLogicalChannelBase
dc268b18d709 201037_07
hgs
parents:
diff changeset
    36
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    37
// VersionTest LDD channel
dc268b18d709 201037_07
hgs
parents:
diff changeset
    38
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    39
	{
dc268b18d709 201037_07
hgs
parents:
diff changeset
    40
public:
dc268b18d709 201037_07
hgs
parents:
diff changeset
    41
	DVersionTest();
dc268b18d709 201037_07
hgs
parents:
diff changeset
    42
	~DVersionTest();
dc268b18d709 201037_07
hgs
parents:
diff changeset
    43
protected:
dc268b18d709 201037_07
hgs
parents:
diff changeset
    44
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
dc268b18d709 201037_07
hgs
parents:
diff changeset
    45
	virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
dc268b18d709 201037_07
hgs
parents:
diff changeset
    46
private:
dc268b18d709 201037_07
hgs
parents:
diff changeset
    47
	TBool QVS(TInt aCurrent,TInt aRequested);
dc268b18d709 201037_07
hgs
parents:
diff changeset
    48
    TVersion* iTV[KNumTVersions];
dc268b18d709 201037_07
hgs
parents:
diff changeset
    49
    TVersion iDefTV;     // tests default constructor
dc268b18d709 201037_07
hgs
parents:
diff changeset
    50
	};
dc268b18d709 201037_07
hgs
parents:
diff changeset
    51
dc268b18d709 201037_07
hgs
parents:
diff changeset
    52
LOCAL_D const TText* Names[]=
dc268b18d709 201037_07
hgs
parents:
diff changeset
    53
    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
    54
    _S("0.00(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    55
    _S("0.00(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    56
    _S("0.00(1)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    57
    _S("0.00(999)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    58
    _S("0.01(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    59
    _S("0.01(1)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    60
    _S("0.01(999)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    61
    _S("0.99(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    62
    _S("0.99(1)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    63
    _S("0.99(999)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    64
    _S("1.00(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    65
    _S("1.00(1)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    66
    _S("1.00(999)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    67
    _S("1.01(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    68
    _S("1.01(1)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    69
    _S("1.01(999)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    70
    _S("1.99(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    71
    _S("1.99(1)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    72
    _S("1.99(999)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    73
    _S("99.00(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    74
    _S("99.00(1)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    75
    _S("99.00(999)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    76
    _S("99.01(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    77
    _S("99.01(1)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    78
    _S("99.01(999)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    79
    _S("99.99(0)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    80
    _S("99.99(1)"),
dc268b18d709 201037_07
hgs
parents:
diff changeset
    81
    _S("99.99(999)")
dc268b18d709 201037_07
hgs
parents:
diff changeset
    82
    };
dc268b18d709 201037_07
hgs
parents:
diff changeset
    83
dc268b18d709 201037_07
hgs
parents:
diff changeset
    84
DVersionTestFactory::DVersionTestFactory()
dc268b18d709 201037_07
hgs
parents:
diff changeset
    85
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    86
// Constructor
dc268b18d709 201037_07
hgs
parents:
diff changeset
    87
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    88
    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
    89
    }
dc268b18d709 201037_07
hgs
parents:
diff changeset
    90
dc268b18d709 201037_07
hgs
parents:
diff changeset
    91
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    92
// Destructor
dc268b18d709 201037_07
hgs
parents:
diff changeset
    93
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
    94
DVersionTestFactory::~DVersionTestFactory()
dc268b18d709 201037_07
hgs
parents:
diff changeset
    95
	{
dc268b18d709 201037_07
hgs
parents:
diff changeset
    96
	}
dc268b18d709 201037_07
hgs
parents:
diff changeset
    97
dc268b18d709 201037_07
hgs
parents:
diff changeset
    98
TInt DVersionTestFactory::Create(DLogicalChannelBase*& aChannel)
dc268b18d709 201037_07
hgs
parents:
diff changeset
    99
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   100
// Create 
dc268b18d709 201037_07
hgs
parents:
diff changeset
   101
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   102
    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   103
	aChannel=new DVersionTest;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   104
	return aChannel?KErrNone:KErrNoMemory;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   105
    }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   106
dc268b18d709 201037_07
hgs
parents:
diff changeset
   107
TInt DVersionTestFactory::Install()
dc268b18d709 201037_07
hgs
parents:
diff changeset
   108
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   109
// Install the LDD - overriding pure virtual
dc268b18d709 201037_07
hgs
parents:
diff changeset
   110
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   111
    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   112
	return SetName(&KVersionTestLddName);
dc268b18d709 201037_07
hgs
parents:
diff changeset
   113
    }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   114
dc268b18d709 201037_07
hgs
parents:
diff changeset
   115
void DVersionTestFactory::GetCaps(TDes8& /*aDes*/) const
dc268b18d709 201037_07
hgs
parents:
diff changeset
   116
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   117
// Get capabilities - overriding pure virtual
dc268b18d709 201037_07
hgs
parents:
diff changeset
   118
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   119
    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   120
    // Not used but required as DLogicalDevice::GetCaps is pure virtual
dc268b18d709 201037_07
hgs
parents:
diff changeset
   121
    }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   122
dc268b18d709 201037_07
hgs
parents:
diff changeset
   123
DECLARE_STANDARD_LDD()
dc268b18d709 201037_07
hgs
parents:
diff changeset
   124
	{
dc268b18d709 201037_07
hgs
parents:
diff changeset
   125
    return new DVersionTestFactory;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   126
    }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   127
dc268b18d709 201037_07
hgs
parents:
diff changeset
   128
DVersionTest::DVersionTest()
dc268b18d709 201037_07
hgs
parents:
diff changeset
   129
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   130
// Constructor
dc268b18d709 201037_07
hgs
parents:
diff changeset
   131
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   132
    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   133
    iTV[0]=&iDefTV;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   134
    TInt i=1;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   135
    TInt major=0;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   136
    FOREVER
dc268b18d709 201037_07
hgs
parents:
diff changeset
   137
        {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   138
        TInt minor=0;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   139
        FOREVER
dc268b18d709 201037_07
hgs
parents:
diff changeset
   140
            {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   141
            TInt build=0;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   142
            FOREVER
dc268b18d709 201037_07
hgs
parents:
diff changeset
   143
                {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   144
                iTV[i++]=new TVersion(major,minor,build);
dc268b18d709 201037_07
hgs
parents:
diff changeset
   145
                if (build==999)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   146
                    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   147
                    break;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   148
                    }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   149
                build=(build==1? 999: 1);
dc268b18d709 201037_07
hgs
parents:
diff changeset
   150
                }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   151
            if (minor==99)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   152
                {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   153
                break;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   154
                }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   155
            minor=(minor==1? 99: 1);
dc268b18d709 201037_07
hgs
parents:
diff changeset
   156
            }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   157
        if (major==99)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   158
            {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   159
            break;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   160
            }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   161
        major=(major==1? 99: 1);
dc268b18d709 201037_07
hgs
parents:
diff changeset
   162
        }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   163
	}
dc268b18d709 201037_07
hgs
parents:
diff changeset
   164
	
dc268b18d709 201037_07
hgs
parents:
diff changeset
   165
TInt DVersionTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   166
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   167
// Create channel
dc268b18d709 201037_07
hgs
parents:
diff changeset
   168
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   169
    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   170
	return KErrNone;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   171
	}
dc268b18d709 201037_07
hgs
parents:
diff changeset
   172
dc268b18d709 201037_07
hgs
parents:
diff changeset
   173
DVersionTest::~DVersionTest()
dc268b18d709 201037_07
hgs
parents:
diff changeset
   174
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   175
// Destructor
dc268b18d709 201037_07
hgs
parents:
diff changeset
   176
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   177
    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   178
    }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   179
dc268b18d709 201037_07
hgs
parents:
diff changeset
   180
TInt DVersionTest::Request(TInt aFunction, TAny* /*a1*/, TAny* /*a2*/)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   181
	{
dc268b18d709 201037_07
hgs
parents:
diff changeset
   182
	TInt r=KErrNone;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   183
	switch (aFunction)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   184
		{
dc268b18d709 201037_07
hgs
parents:
diff changeset
   185
		case RVersionTest::EVersionTestName:
dc268b18d709 201037_07
hgs
parents:
diff changeset
   186
			{
dc268b18d709 201037_07
hgs
parents:
diff changeset
   187
			//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   188
			// Test the version name
dc268b18d709 201037_07
hgs
parents:
diff changeset
   189
			//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   190
			{
dc268b18d709 201037_07
hgs
parents:
diff changeset
   191
			for (TInt i=0; i<KNumTVersions; i++)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   192
			    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   193
                TPtrC Name=(TPtrC)Names[i];
dc268b18d709 201037_07
hgs
parents:
diff changeset
   194
			    if (iTV[i]->Name().Compare(Name))
dc268b18d709 201037_07
hgs
parents:
diff changeset
   195
			        {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   196
                    r=KErrNotSupported;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   197
			        return r;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   198
			        }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   199
			    }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   200
			}
dc268b18d709 201037_07
hgs
parents:
diff changeset
   201
			break;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   202
			}
dc268b18d709 201037_07
hgs
parents:
diff changeset
   203
		case RVersionTest::EVersionTestQVS:
dc268b18d709 201037_07
hgs
parents:
diff changeset
   204
			{
dc268b18d709 201037_07
hgs
parents:
diff changeset
   205
			//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   206
			// Check QueryVersionSupported()
dc268b18d709 201037_07
hgs
parents:
diff changeset
   207
			//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   208
			for (TInt i=0; i<KNumTVersions; i++)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   209
			    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   210
			    for (TInt j=0; j<KNumTVersions; j++)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   211
			        {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   212
			        if (Kern::QueryVersionSupported(*iTV[i],*iTV[j])!=QVS(i,j))
dc268b18d709 201037_07
hgs
parents:
diff changeset
   213
			            {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   214
                        r=KErrNotSupported;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   215
			            return r;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   216
			            }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   217
			        }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   218
			    }
dc268b18d709 201037_07
hgs
parents:
diff changeset
   219
			    
dc268b18d709 201037_07
hgs
parents:
diff changeset
   220
			break;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   221
			}
dc268b18d709 201037_07
hgs
parents:
diff changeset
   222
		default:
dc268b18d709 201037_07
hgs
parents:
diff changeset
   223
			break;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   224
		}
dc268b18d709 201037_07
hgs
parents:
diff changeset
   225
	return r;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   226
	}
dc268b18d709 201037_07
hgs
parents:
diff changeset
   227
dc268b18d709 201037_07
hgs
parents:
diff changeset
   228
TBool DVersionTest::QVS(TInt aCurrent,TInt aRequested)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   229
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   230
// An independent calculation of what QueryVersionSupported should return
dc268b18d709 201037_07
hgs
parents:
diff changeset
   231
//
dc268b18d709 201037_07
hgs
parents:
diff changeset
   232
    {
dc268b18d709 201037_07
hgs
parents:
diff changeset
   233
    if (aCurrent)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   234
        aCurrent--;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   235
    if (aRequested)
dc268b18d709 201037_07
hgs
parents:
diff changeset
   236
        aRequested--;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   237
    aCurrent/=3;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   238
    aRequested/=3;
dc268b18d709 201037_07
hgs
parents:
diff changeset
   239
    return(aCurrent>=aRequested);
dc268b18d709 201037_07
hgs
parents:
diff changeset
   240
    }