stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_vec/src/vec2.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 // STLport regression testsuite component.
       
    19 // To compile as a separate example, please #define MAIN.
       
    20 
       
    21 #include <iostream>
       
    22 #include <vector>
       
    23 #include <algorithm>
       
    24 
       
    25 #ifdef MAIN 
       
    26 #define vec2_test main
       
    27 #endif
       
    28 
       
    29 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    30 using namespace std;
       
    31 #endif
       
    32 
       
    33 static void print(vector<double>& vector_)
       
    34 {
       
    35   for(int i = 0; i < vector_.size(); i++)
       
    36     cout << vector_[i] << " ";
       
    37   cout << endl;
       
    38 }
       
    39 
       
    40 int vec2_test(int, char**)
       
    41 {
       
    42   int failures=0;
       
    43   cout<<"Results of vec2_test:"<<endl;
       
    44 
       
    45   vector<double> v1; // Empty vector of doubles.
       
    46   v1.push_back(32.1);
       
    47   v1.push_back(40.5);
       
    48   vector<double> v2; // Another empty vector of doubles.
       
    49   v2.push_back(3.56);
       
    50   cout << "v1 = ";
       
    51   print(v1);
       
    52   cout << "v2 = ";
       
    53   print(v2);
       
    54   
       
    55   if(32.1!=v1[0])
       
    56     failures++;
       
    57   else if(40.5 !=v1[1])
       
    58     failures++;
       
    59   else if(3.56 !=v2[0])
       
    60     failures++;     
       
    61     
       
    62   v1.swap(v2); // Swap the vector's contents.
       
    63   cout << "v1 = ";
       
    64   print(v1);
       
    65   cout << "v2 = ";
       
    66   print(v2);
       
    67   
       
    68   if(32.1!=v2[0])
       
    69     failures++;
       
    70   else if(40.5 !=v2[1])
       
    71     failures++;
       
    72   else if(3.56 !=v1[0])
       
    73     failures++; 
       
    74     
       
    75   v2 = v1; // Assign one vector to another.
       
    76   cout << "v2 = ";
       
    77   print(v2);
       
    78   
       
    79   if(3.56!=v2[0])
       
    80    failures++;
       
    81    
       
    82    if(failures)
       
    83      return 1;
       
    84    else   
       
    85     return 0;
       
    86 }
       
    87 
       
    88 /*Results of vec2_test:
       
    89 v1 = 32.1 40.5
       
    90 v2 = 3.56
       
    91 
       
    92 v1 = 3.56
       
    93 v2 = 32.1 40.5
       
    94 
       
    95 v2 = 3.56
       
    96 */