1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/BC/apps/tutility/src/tutilityblocks.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,235 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +// INCLUDE FILES
1.24 +#include <e32svr.h>
1.25 +#include <StifParser.h>
1.26 +#include <Stiftestinterface.h>
1.27 +#include <memory>
1.28 +
1.29 +#include "tutility.h"
1.30 +
1.31 +
1.32 +using namespace std;
1.33 +
1.34 +// ============================= LOCAL FUNCTIONS ===============================
1.35 +
1.36 +// -----------------------------------------------------------------------------
1.37 +// ?function_name ?description.
1.38 +// ?description
1.39 +// Returns: ?value_1: ?description
1.40 +// ?value_n: ?description_line1
1.41 +// ?description_line2
1.42 +// -----------------------------------------------------------------------------
1.43 +//
1.44 +/*
1.45 +?type ?function_name(
1.46 + ?arg_type arg, // ?description
1.47 + ?arg_type arg) // ?description
1.48 + {
1.49 +
1.50 + ?code // ?comment
1.51 +
1.52 + // ?comment
1.53 + ?code
1.54 + }
1.55 +*/
1.56 +
1.57 +// ============================ MEMBER FUNCTIONS ===============================
1.58 +
1.59 +// -----------------------------------------------------------------------------
1.60 +// Ctutility::Delete
1.61 +// Delete here all resources allocated and opened from test methods.
1.62 +// Called from destructor.
1.63 +// -----------------------------------------------------------------------------
1.64 +//
1.65 +void Ctutility::Delete()
1.66 + {
1.67 +
1.68 + }
1.69 +
1.70 +// -----------------------------------------------------------------------------
1.71 +// Ctutility::RunMethodL
1.72 +// Run specified method. Contains also table of test mothods and their names.
1.73 +// -----------------------------------------------------------------------------
1.74 +//
1.75 +TInt Ctutility::RunMethodL(
1.76 + CStifItemParser& aItem )
1.77 + {
1.78 +
1.79 + static TStifFunctionInfo const KFunctions[] =
1.80 + {
1.81 + // Copy this line for every implemented function.
1.82 + // First string is the function name used in TestScripter script file.
1.83 + // Second is the actual implementation member function.
1.84 + ENTRY( "Uninitialized_Copy", Ctutility::Uninitialized_Copy ),
1.85 + ENTRY( "Uninitialized_Copy_n", Ctutility::Uninitialized_Copy_n ),
1.86 + ENTRY( "Uninitialized_Fill", Ctutility::Uninitialized_Fill ),
1.87 + ENTRY( "Uninitialized_Fill_n", Ctutility::Uninitialized_Fill_n ),
1.88 +
1.89 + //ADD NEW ENTRY HERE
1.90 +
1.91 + };
1.92 +
1.93 + const TInt count = sizeof( KFunctions ) /
1.94 + sizeof( TStifFunctionInfo );
1.95 +
1.96 + return RunInternalL( KFunctions, count, aItem );
1.97 +
1.98 + }
1.99 +
1.100 +// -----------------------------------------------------------------------------
1.101 +// Ctutility::Uninitialized_Copy
1.102 +// Uninitialized_Copy test method function.
1.103 +// (other items were commented in a header).
1.104 +// -----------------------------------------------------------------------------
1.105 +//
1.106 +
1.107 +TInt Ctutility::Uninitialized_Copy( CStifItemParser& aItem )
1.108 + {
1.109 +
1.110 + __UHEAP_MARK;
1.111 + int Array1[] = { 10, 20, 30, 40 };
1.112 + const int N = sizeof( Array1 ) / sizeof( int );
1.113 +
1.114 + int i, testfail = 0;
1.115 +
1.116 + Integer* ArrayPtr = ( Integer* )::operator new( N * sizeof( int ) );
1.117 + Integer* LArrayPtr = uninitialized_copy(Array1, Array1 + N, ArrayPtr);
1.118 +
1.119 + if ( ( &Array1[0] + N ) == ( void* )LArrayPtr )
1.120 + {
1.121 + testfail++;
1.122 + }
1.123 +
1.124 + if ( ( void* )LArrayPtr != ( void* )( ArrayPtr + N ) )
1.125 + {
1.126 + testfail++;
1.127 + }
1.128 +
1.129 + delete ArrayPtr ;
1.130 +
1.131 + __UHEAP_MARKEND;
1.132 +
1.133 + if( testfail == 0)
1.134 + return KErrNone;
1.135 + else
1.136 + return KErrGeneral;
1.137 +
1.138 + }
1.139 +
1.140 +// -----------------------------------------------------------------------------
1.141 +// Ctutility::Uninitialized_Copy_n
1.142 +// Uninitialized_Copy_n test method function.
1.143 +// (other items were commented in a header).
1.144 +// -----------------------------------------------------------------------------
1.145 +//
1.146 +
1.147 +TInt Ctutility::Uninitialized_Copy_n( CStifItemParser& aItem )
1.148 + {
1.149 +
1.150 + __UHEAP_MARK;
1.151 + int Array1[] = { 10, 20, 30, 40 };
1.152 + const int N = sizeof( Array1 ) / sizeof( int );
1.153 +
1.154 + int i;
1.155 +
1.156 + Integer* ArrayPtr = ( Integer* )::operator new( N * sizeof( int ) );
1.157 + std::pair<int*,Integer*> LArrayPtr = uninitialized_copy_n(Array1, N, ArrayPtr);
1.158 +
1.159 + delete ArrayPtr ;
1.160 + __UHEAP_MARKEND;
1.161 +
1.162 + return KErrNone;
1.163 +
1.164 + }
1.165 +
1.166 +
1.167 +// -----------------------------------------------------------------------------
1.168 +// Ctutility::Uninitialized_Fill
1.169 +// Uninitialized_Fill test method function.
1.170 +// (other items were commented in a header).
1.171 +// -----------------------------------------------------------------------------
1.172 +//
1.173 +
1.174 +TInt Ctutility::Uninitialized_Fill( CStifItemParser& aItem )
1.175 + {
1.176 +
1.177 + __UHEAP_MARK;
1.178 + int testfail = 0 , p = 0;
1.179 + const int N = 10;
1.180 + Integer val ( 25 );
1.181 + Integer* Array1 = ( Integer* )::operator new( N * sizeof( int ) );
1.182 + uninitialized_fill( Array1, Array1 + N, val );
1.183 +
1.184 + for ( int i = 0 ; i < N; i++ )
1.185 + {
1.186 + p = Array1[ i ].get( );
1.187 + if( p != 25 )
1.188 + testfail++;
1.189 + }
1.190 +
1.191 + delete Array1 ;
1.192 + __UHEAP_MARKEND;
1.193 +
1.194 + if( testfail == 0)
1.195 + return KErrNone;
1.196 + else
1.197 + return KErrGeneral;
1.198 + }
1.199 +
1.200 +
1.201 +// -----------------------------------------------------------------------------
1.202 +// Ctutility::Uninitialized_Fill_n
1.203 +// Uninitialized_Fill_n test method function.
1.204 +// (other items were commented in a header).
1.205 +// -----------------------------------------------------------------------------
1.206 +//
1.207 +
1.208 +TInt Ctutility::Uninitialized_Fill_n( CStifItemParser& aItem )
1.209 + {
1.210 +
1.211 + __UHEAP_MARK;
1.212 + int testfail = 0 , p = 0;
1.213 + const int N = 10;
1.214 + Integer val ( 60 );
1.215 + Integer* Array1 = ( Integer* )::operator new( N * sizeof( int ) );
1.216 + uninitialized_fill_n( Array1, N, val );
1.217 +
1.218 + for ( int i = 0 ; i < N; i++ )
1.219 + {
1.220 + p = Array1[ i ].get( );
1.221 + if( p != 60 )
1.222 + testfail++;
1.223 + }
1.224 +
1.225 + delete Array1 ;
1.226 + __UHEAP_MARKEND;
1.227 +
1.228 + if( testfail == 0)
1.229 + return KErrNone;
1.230 + else
1.231 + return KErrGeneral;
1.232 + }
1.233 +
1.234 +
1.235 +// ========================== OTHER EXPORTED FUNCTIONS =========================
1.236 +// None
1.237 +
1.238 +// End of File