stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_search/src/search0.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 <algorithm>
       
    22 #include <iostream>
       
    23 
       
    24 #ifdef MAIN 
       
    25 #define search0_test main
       
    26 #endif
       
    27 
       
    28 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    29 using namespace std;
       
    30 #endif
       
    31 int search0_test(int, char**)
       
    32 {
       
    33   int failures=0;
       
    34   cout<<"Results of search0_test:"<<endl;
       
    35 int v1[6] = { 1, 1, 2, 3, 5, 8 };
       
    36 int v2[6] = { 0, 1, 2, 3, 4, 5 };
       
    37 int v3[2] = { 3, 4 };
       
    38 
       
    39   int* location;
       
    40   location = search((int*)v1, (int*)v1 + 6, (int*)v3, (int*)v3 + 2);
       
    41   if(location == v1 + 6)
       
    42     cout << "v3 not contained in v1" << endl;
       
    43   else
       
    44     cout << "Found v3 in v1 at offset: " << location - v1 << endl;
       
    45     
       
    46     if(location !=v1 + 6)
       
    47         failures++;
       
    48   
       
    49   
       
    50   location = search((int*)v2, (int*)v2 + 6, (int*)v3, (int*)v3 + 2);
       
    51   if(location == v2 + 6)
       
    52     cout << "v3 not contained in v2" << endl;
       
    53   else
       
    54     cout << "Found v3 in v2 at offset: " << location - v2 << endl;
       
    55   
       
    56   if(location == v2 + 6)
       
    57      failures++;
       
    58      
       
    59    if(failures)
       
    60       return 1;
       
    61    else
       
    62      return 0;
       
    63 }