os/kernelhwsrv/kerneltest/e32test/buffer/t_versio.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/buffer/t_versio.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,178 @@
     1.4 +// Copyright (c) 1995-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 +// e32test\buffer\t_versio.cpp
    1.18 +// Overview:
    1.19 +// Test the version information class.
    1.20 +// API Information:
    1.21 +// TVersion.
    1.22 +// Details:
    1.23 +// - Test the version name for different versions as expected.
    1.24 +// - Compare the major, minor, build version number of current version and 
    1.25 +// specified version and verify that error message is popped when version
    1.26 +// is not supported.
    1.27 +// Platforms/Drives/Compatibility:
    1.28 +// All 
    1.29 +// Assumptions/Requirement/Pre-requisites:
    1.30 +// Failures and causes:
    1.31 +// Base Port information:
    1.32 +// 
    1.33 +//
    1.34 +
    1.35 +#include <e32test.h>
    1.36 +
    1.37 +const TInt KNumTVersions=1+3*3*3;
    1.38 +
    1.39 +class RTvTest : public RTest
    1.40 +    {
    1.41 +public:
    1.42 +    RTvTest();
    1.43 +    void TestName();
    1.44 +    void TestQVS();
    1.45 +    void Start(const TDesC &aHeading) {Printf(aHeading);Push();}
    1.46 +private:
    1.47 +    TBool QVS(TInt i,TInt j);
    1.48 +private:
    1.49 +    TVersion* iTV[KNumTVersions];
    1.50 +    TVersion iDefTV;     // tests default constructor
    1.51 +    };
    1.52 +
    1.53 +LOCAL_D const TText* Names[]=
    1.54 +    {
    1.55 +    _S("0.00(0)"),
    1.56 +    _S("0.00(0)"),
    1.57 +    _S("0.00(1)"),
    1.58 +    _S("0.00(999)"),
    1.59 +    _S("0.01(0)"),
    1.60 +    _S("0.01(1)"),
    1.61 +    _S("0.01(999)"),
    1.62 +    _S("0.99(0)"),
    1.63 +    _S("0.99(1)"),
    1.64 +    _S("0.99(999)"),
    1.65 +    _S("1.00(0)"),
    1.66 +    _S("1.00(1)"),
    1.67 +    _S("1.00(999)"),
    1.68 +    _S("1.01(0)"),
    1.69 +    _S("1.01(1)"),
    1.70 +    _S("1.01(999)"),
    1.71 +    _S("1.99(0)"),
    1.72 +    _S("1.99(1)"),
    1.73 +    _S("1.99(999)"),
    1.74 +    _S("99.00(0)"),
    1.75 +    _S("99.00(1)"),
    1.76 +    _S("99.00(999)"),
    1.77 +    _S("99.01(0)"),
    1.78 +    _S("99.01(1)"),
    1.79 +    _S("99.01(999)"),
    1.80 +    _S("99.99(0)"),
    1.81 +    _S("99.99(1)"),
    1.82 +    _S("99.99(999)")
    1.83 +    };
    1.84 +
    1.85 +RTvTest::RTvTest()
    1.86 +//
    1.87 +// Constructor
    1.88 +//
    1.89 +    : RTest(_L("T_VERSIO"))
    1.90 +    {
    1.91 +
    1.92 +    iTV[0]=&iDefTV;
    1.93 +    TInt i=1;
    1.94 +    TInt major=0;
    1.95 +    FOREVER
    1.96 +        {
    1.97 +        TInt minor=0;
    1.98 +        FOREVER
    1.99 +            {
   1.100 +            TInt build=0;
   1.101 +            FOREVER
   1.102 +                {
   1.103 +                iTV[i++]=new TVersion(major,minor,build);
   1.104 +                if (build==999)
   1.105 +                    break;
   1.106 +                build=(build==1? 999: 1);
   1.107 +                }
   1.108 +            if (minor==99)
   1.109 +                break;
   1.110 +            minor=(minor==1? 99: 1);
   1.111 +            }
   1.112 +        if (major==99)
   1.113 +            break;
   1.114 +        major=(major==1? 99: 1);
   1.115 +        }
   1.116 +    }
   1.117 +
   1.118 +void RTvTest::TestName()
   1.119 +//
   1.120 +// Test the version name
   1.121 +//
   1.122 +    {
   1.123 + 
   1.124 +	Next(_L("Testing TVersion::Name()"));
   1.125 +    for (TInt i=0; i<KNumTVersions; i++)
   1.126 +        {
   1.127 +        TPtrC Name=(TPtrC)Names[i];
   1.128 +        if (iTV[i]->Name().Compare(Name))
   1.129 +            Panic(Name);
   1.130 +        }
   1.131 +    }
   1.132 +
   1.133 +TBool RTvTest::QVS(TInt aCurrent,TInt aRequested)
   1.134 +//
   1.135 +// An independent calculation of what QueryVersionSupported should return
   1.136 +//
   1.137 +    {
   1.138 +
   1.139 +    if (aCurrent)
   1.140 +        aCurrent--;
   1.141 +    if (aRequested)
   1.142 +        aRequested--;
   1.143 +    aCurrent/=3;
   1.144 +    aRequested/=3;
   1.145 +    return(aCurrent>=aRequested);
   1.146 +    }
   1.147 +
   1.148 +void RTvTest::TestQVS()
   1.149 +//
   1.150 +// Check QueryVersionSupported()
   1.151 +//
   1.152 +    {
   1.153 + 
   1.154 +   Next(_L("Testing User::QueryVersionSupported()"));
   1.155 +    for (TInt i=0; i<KNumTVersions; i++)
   1.156 +        {
   1.157 +        for (TInt j=0; j<KNumTVersions; j++)
   1.158 +            {
   1.159 +            if (User::QueryVersionSupported(*iTV[i],*iTV[j])!=QVS(i,j))
   1.160 +                Panic(_L("Query version supported failed"));
   1.161 +            }
   1.162 +        }
   1.163 +    }
   1.164 +
   1.165 +GLDEF_C TInt E32Main()
   1.166 +//
   1.167 +// Test TVersion class.
   1.168 +//
   1.169 +    {
   1.170 +
   1.171 +    RTvTest test;
   1.172 +	test.Title();
   1.173 +	test.Start(_L("Testing TVersion\n"));
   1.174 +    test.TestName();
   1.175 +    test.TestQVS();
   1.176 +    test.Printf(_L("TVersion passed testing\n"));
   1.177 +	test.End();
   1.178 +	return(0);
   1.179 +    }
   1.180 +
   1.181 +