stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_vec/src/vec7.cpp
changeset 31 ce057bb09d0b
child 34 5fae379060a7
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     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 // STLport regression testsuite component.
       
    20 // To compile as a separate example, please #define MAIN.
       
    21 
       
    22 #include <iostream>
       
    23 #include <vector>
       
    24 #include <algorithm>
       
    25 
       
    26 #ifdef MAIN 
       
    27 #define vec7_test main
       
    28 #endif
       
    29 
       
    30 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    31 using namespace std;
       
    32 #endif
       
    33 int vec7_test(int, char**)
       
    34 {
       
    35   int failures=0;
       
    36   cout<<"Results of vec7_test:"<<endl;
       
    37 int array1 [] = { 1, 4, 25 };
       
    38 int array2 [] = { 9, 16 };
       
    39 
       
    40   vector<int> v(array1, array1 + 3);
       
    41   v.insert(v.begin(), 0); // Insert before first element.
       
    42   v.insert(v.end(), 36); // Insert after last element.
       
    43   int i;
       
    44   for(i = 0; i < v.size(); i++)
       
    45     cout << "v[" << i << "] = " << v[i] << endl;
       
    46   cout << endl;
       
    47   
       
    48   if(0!=v[0])
       
    49      failures++;
       
    50    else if(1!=v[1]) 
       
    51      failures++;
       
    52    else if(4!=v[2])
       
    53      failures++;
       
    54    else if(25!=v[3])
       
    55      failures++;
       
    56    else if(36!=v[4])
       
    57      failures++;
       
    58      
       
    59   // Insert contents of array2 before fourth element.
       
    60   v.insert(v.begin() + 3, array2, array2 + 2);
       
    61   for(i = 0; i < v.size(); i++)
       
    62     cout << "v[" << i << "] = " << v[i] << endl;
       
    63   
       
    64   if(0!=v[0])
       
    65      failures++;
       
    66    else if(1!=v[1]) 
       
    67      failures++;
       
    68    else if(4!=v[2])
       
    69      failures++;
       
    70    else if(9!=v[3])
       
    71      failures++;
       
    72    else if(16!=v[4])
       
    73      failures++;
       
    74    else if(25!=v[5])
       
    75      failures++;
       
    76    else if(36!=v[6])
       
    77      failures++;
       
    78      
       
    79   cout << endl;
       
    80   
       
    81   if(failures)
       
    82     return 1;
       
    83   else  
       
    84     return 0;
       
    85 }
       
    86 
       
    87 /*Results of vec7_test:
       
    88 v[0] = 0
       
    89 v[1] = 1
       
    90 v[2] = 4
       
    91 v[3] = 25
       
    92 v[4] = 36
       
    93 
       
    94 v[0] = 0
       
    95 v[1] = 1
       
    96 v[2] = 4
       
    97 v[3] = 9
       
    98 v[4] = 16
       
    99 v[5] = 25
       
   100 v[6] = 36
       
   101 */