os/ossrv/stdcpp/tsrc/BC/apps/tutility/src/tutilityblocks.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 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:       
    15 *
    16 */
    17 
    18 
    19 
    20 // INCLUDE FILES
    21 #include <e32svr.h>
    22 #include <StifParser.h>
    23 #include <Stiftestinterface.h>
    24 #include <memory>
    25 
    26 #include "tutility.h"
    27 
    28 
    29 using namespace std;
    30 
    31 // ============================= LOCAL FUNCTIONS ===============================
    32 
    33 // -----------------------------------------------------------------------------
    34 // ?function_name ?description.
    35 // ?description
    36 // Returns: ?value_1: ?description
    37 //          ?value_n: ?description_line1
    38 //                    ?description_line2
    39 // -----------------------------------------------------------------------------
    40 //
    41 /*
    42 ?type ?function_name(
    43     ?arg_type arg,  // ?description
    44     ?arg_type arg)  // ?description
    45     {
    46 
    47     ?code  // ?comment
    48 
    49     // ?comment
    50     ?code
    51     }
    52 */
    53 
    54 // ============================ MEMBER FUNCTIONS ===============================
    55 
    56 // -----------------------------------------------------------------------------
    57 // Ctutility::Delete
    58 // Delete here all resources allocated and opened from test methods. 
    59 // Called from destructor. 
    60 // -----------------------------------------------------------------------------
    61 //
    62 void Ctutility::Delete() 
    63     {
    64 
    65     }
    66 
    67 // -----------------------------------------------------------------------------
    68 // Ctutility::RunMethodL
    69 // Run specified method. Contains also table of test mothods and their names.
    70 // -----------------------------------------------------------------------------
    71 //
    72 TInt Ctutility::RunMethodL( 
    73     CStifItemParser& aItem ) 
    74     {
    75 
    76     static TStifFunctionInfo const KFunctions[] =
    77         {  
    78         // Copy this line for every implemented function.
    79         // First string is the function name used in TestScripter script file.
    80         // Second is the actual implementation member function. 
    81         ENTRY( "Uninitialized_Copy", Ctutility::Uninitialized_Copy ),
    82         ENTRY( "Uninitialized_Copy_n", Ctutility::Uninitialized_Copy_n ),
    83         ENTRY( "Uninitialized_Fill", Ctutility::Uninitialized_Fill ),
    84         ENTRY( "Uninitialized_Fill_n", Ctutility::Uninitialized_Fill_n ),
    85         
    86         //ADD NEW ENTRY HERE
    87 
    88         };
    89 
    90     const TInt count = sizeof( KFunctions ) / 
    91                         sizeof( TStifFunctionInfo );
    92 
    93     return RunInternalL( KFunctions, count, aItem );
    94 
    95     }
    96 
    97 // -----------------------------------------------------------------------------
    98 // Ctutility::Uninitialized_Copy
    99 // Uninitialized_Copy test method function.
   100 // (other items were commented in a header).
   101 // -----------------------------------------------------------------------------
   102 //
   103 
   104 TInt Ctutility::Uninitialized_Copy( CStifItemParser& aItem )
   105     {
   106 
   107 	__UHEAP_MARK;
   108 	 int Array1[] = { 10, 20, 30, 40 };
   109      const int N = sizeof( Array1 ) / sizeof( int );
   110 
   111      int i, testfail = 0;
   112 
   113      Integer* ArrayPtr = ( Integer* )::operator new( N * sizeof( int ) );
   114      Integer* LArrayPtr = uninitialized_copy(Array1, Array1 + N, ArrayPtr);  
   115 	 
   116      if ( ( &Array1[0] + N ) == ( void* )LArrayPtr )
   117      {
   118       testfail++;
   119      }
   120      
   121      if ( ( void* )LArrayPtr != ( void* )( ArrayPtr + N ) )
   122      {
   123       testfail++;
   124      }
   125 
   126      delete ArrayPtr ;
   127      
   128      __UHEAP_MARKEND;
   129 
   130      if( testfail == 0)
   131        return KErrNone;
   132      else
   133        return KErrGeneral;  
   134 
   135     }
   136 
   137 // -----------------------------------------------------------------------------
   138 // Ctutility::Uninitialized_Copy_n
   139 // Uninitialized_Copy_n test method function.
   140 // (other items were commented in a header).
   141 // -----------------------------------------------------------------------------
   142 //
   143 
   144 TInt Ctutility::Uninitialized_Copy_n( CStifItemParser& aItem )
   145     {
   146 
   147 	__UHEAP_MARK;
   148 	 int Array1[] = { 10, 20, 30, 40 };
   149      const int N = sizeof( Array1 ) / sizeof( int );
   150 
   151      int i;
   152 
   153      Integer* ArrayPtr = ( Integer* )::operator new( N * sizeof( int ) );
   154      std::pair<int*,Integer*> LArrayPtr = uninitialized_copy_n(Array1, N, ArrayPtr);  
   155 	 
   156      delete ArrayPtr ;
   157      __UHEAP_MARKEND;
   158 
   159      return KErrNone;  
   160 
   161     }
   162 
   163 
   164 // -----------------------------------------------------------------------------
   165 // Ctutility::Uninitialized_Fill
   166 // Uninitialized_Fill test method function.
   167 // (other items were commented in a header).
   168 // -----------------------------------------------------------------------------
   169 //
   170 
   171 TInt Ctutility::Uninitialized_Fill( CStifItemParser& aItem )
   172     {
   173 
   174 	__UHEAP_MARK;
   175      int testfail = 0 , p = 0;
   176      const int N = 10;
   177      Integer val ( 25 );
   178      Integer* Array1 = ( Integer* )::operator new( N * sizeof( int ) );
   179      uninitialized_fill( Array1, Array1 + N, val );
   180 
   181      for ( int i = 0 ; i < N; i++ )
   182       {
   183          p = Array1[ i ].get( );    
   184          if(  p != 25 )
   185            testfail++; 
   186       }
   187  
   188      delete Array1 ;
   189      __UHEAP_MARKEND;
   190 
   191      if( testfail == 0)
   192        return KErrNone;
   193      else
   194        return KErrGeneral;  
   195     }
   196 
   197 
   198 // -----------------------------------------------------------------------------
   199 // Ctutility::Uninitialized_Fill_n
   200 // Uninitialized_Fill_n test method function.
   201 // (other items were commented in a header).
   202 // -----------------------------------------------------------------------------
   203 //
   204 
   205 TInt Ctutility::Uninitialized_Fill_n( CStifItemParser& aItem )
   206     {
   207 
   208 	__UHEAP_MARK;
   209      int testfail = 0 , p = 0;
   210      const int N = 10;
   211      Integer val ( 60 );
   212      Integer* Array1 = ( Integer* )::operator new( N * sizeof( int ) );
   213      uninitialized_fill_n( Array1, N, val );
   214 
   215      for ( int i = 0 ; i < N; i++ )
   216       {
   217          p = Array1[ i ].get( );    
   218          if(  p != 60 )
   219            testfail++; 
   220       }
   221  
   222      delete Array1 ;
   223      __UHEAP_MARKEND;
   224 
   225      if( testfail == 0)
   226        return KErrNone;
   227      else
   228        return KErrGeneral;  
   229     }
   230 
   231 
   232 // ========================== OTHER EXPORTED FUNCTIONS =========================
   233 // None
   234 
   235 //  End of File