os/kernelhwsrv/kerneltest/e32test/buffer/t_versio.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1995-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\buffer\t_versio.cpp
    15 // Overview:
    16 // Test the version information class.
    17 // API Information:
    18 // TVersion.
    19 // Details:
    20 // - Test the version name for different versions as expected.
    21 // - Compare the major, minor, build version number of current version and 
    22 // specified version and verify that error message is popped when version
    23 // is not supported.
    24 // Platforms/Drives/Compatibility:
    25 // All 
    26 // Assumptions/Requirement/Pre-requisites:
    27 // Failures and causes:
    28 // Base Port information:
    29 // 
    30 //
    31 
    32 #include <e32test.h>
    33 
    34 const TInt KNumTVersions=1+3*3*3;
    35 
    36 class RTvTest : public RTest
    37     {
    38 public:
    39     RTvTest();
    40     void TestName();
    41     void TestQVS();
    42     void Start(const TDesC &aHeading) {Printf(aHeading);Push();}
    43 private:
    44     TBool QVS(TInt i,TInt j);
    45 private:
    46     TVersion* iTV[KNumTVersions];
    47     TVersion iDefTV;     // tests default constructor
    48     };
    49 
    50 LOCAL_D const TText* Names[]=
    51     {
    52     _S("0.00(0)"),
    53     _S("0.00(0)"),
    54     _S("0.00(1)"),
    55     _S("0.00(999)"),
    56     _S("0.01(0)"),
    57     _S("0.01(1)"),
    58     _S("0.01(999)"),
    59     _S("0.99(0)"),
    60     _S("0.99(1)"),
    61     _S("0.99(999)"),
    62     _S("1.00(0)"),
    63     _S("1.00(1)"),
    64     _S("1.00(999)"),
    65     _S("1.01(0)"),
    66     _S("1.01(1)"),
    67     _S("1.01(999)"),
    68     _S("1.99(0)"),
    69     _S("1.99(1)"),
    70     _S("1.99(999)"),
    71     _S("99.00(0)"),
    72     _S("99.00(1)"),
    73     _S("99.00(999)"),
    74     _S("99.01(0)"),
    75     _S("99.01(1)"),
    76     _S("99.01(999)"),
    77     _S("99.99(0)"),
    78     _S("99.99(1)"),
    79     _S("99.99(999)")
    80     };
    81 
    82 RTvTest::RTvTest()
    83 //
    84 // Constructor
    85 //
    86     : RTest(_L("T_VERSIO"))
    87     {
    88 
    89     iTV[0]=&iDefTV;
    90     TInt i=1;
    91     TInt major=0;
    92     FOREVER
    93         {
    94         TInt minor=0;
    95         FOREVER
    96             {
    97             TInt build=0;
    98             FOREVER
    99                 {
   100                 iTV[i++]=new TVersion(major,minor,build);
   101                 if (build==999)
   102                     break;
   103                 build=(build==1? 999: 1);
   104                 }
   105             if (minor==99)
   106                 break;
   107             minor=(minor==1? 99: 1);
   108             }
   109         if (major==99)
   110             break;
   111         major=(major==1? 99: 1);
   112         }
   113     }
   114 
   115 void RTvTest::TestName()
   116 //
   117 // Test the version name
   118 //
   119     {
   120  
   121 	Next(_L("Testing TVersion::Name()"));
   122     for (TInt i=0; i<KNumTVersions; i++)
   123         {
   124         TPtrC Name=(TPtrC)Names[i];
   125         if (iTV[i]->Name().Compare(Name))
   126             Panic(Name);
   127         }
   128     }
   129 
   130 TBool RTvTest::QVS(TInt aCurrent,TInt aRequested)
   131 //
   132 // An independent calculation of what QueryVersionSupported should return
   133 //
   134     {
   135 
   136     if (aCurrent)
   137         aCurrent--;
   138     if (aRequested)
   139         aRequested--;
   140     aCurrent/=3;
   141     aRequested/=3;
   142     return(aCurrent>=aRequested);
   143     }
   144 
   145 void RTvTest::TestQVS()
   146 //
   147 // Check QueryVersionSupported()
   148 //
   149     {
   150  
   151    Next(_L("Testing User::QueryVersionSupported()"));
   152     for (TInt i=0; i<KNumTVersions; i++)
   153         {
   154         for (TInt j=0; j<KNumTVersions; j++)
   155             {
   156             if (User::QueryVersionSupported(*iTV[i],*iTV[j])!=QVS(i,j))
   157                 Panic(_L("Query version supported failed"));
   158             }
   159         }
   160     }
   161 
   162 GLDEF_C TInt E32Main()
   163 //
   164 // Test TVersion class.
   165 //
   166     {
   167 
   168     RTvTest test;
   169 	test.Title();
   170 	test.Start(_L("Testing TVersion\n"));
   171     test.TestName();
   172     test.TestQVS();
   173     test.Printf(_L("TVersion passed testing\n"));
   174 	test.End();
   175 	return(0);
   176     }
   177 
   178