stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_hset/src/hmset1.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 <hash_set>
       
    23 
       
    24 #ifdef MAIN
       
    25 #define hmset1_test main
       
    26 #endif
       
    27 
       
    28 
       
    29 // struct hash<string> {
       
    30 //      size_t operator()(const string& s) const { return __stl_hash_string(s.c_str()); }
       
    31 //};
       
    32 
       
    33 #if defined (__MVS__)
       
    34   #define star   92
       
    35 #else
       
    36   #define star   42
       
    37 
       
    38 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    39 using namespace std;
       
    40 #endif
       
    41 #endif
       
    42 
       
    43 typedef hash_multiset<char, hash<char>, equal_to<char> > hmset;
       
    44 // __STL_TYPE_TRAITS_POD_SPECIALIZE(_Hashtable_node<char>*);
       
    45 
       
    46 
       
    47 int hmset1_test(int, char**)
       
    48 {
       
    49 	cout<<	"Results of hmset1_test:"<<endl;
       
    50 
       
    51 	hmset s;
       
    52 	int failures = 0;
       
    53 	cout << "count(" << star << ") = " << s.count(star) << endl;
       
    54 	if(s.count(star)  != 0)
       
    55 		failures++;
       
    56 
       
    57 	s.insert(star);
       
    58 	cout << "count(" << star << ") = " << s.count(star) << endl;
       
    59 	if(s.count(star)  != 1)
       
    60 		failures++;
       
    61 
       
    62 	s.insert(star);
       
    63 	cout << "count(" << star << ") = " << s.count(star) << endl;
       
    64 	if(s.count(star)  != 2)
       
    65 		failures++;
       
    66 
       
    67 	hmset::iterator i = s.find(40);
       
    68 	if(i == s.end())
       
    69 	{
       
    70 		cout << "40 Not found" << endl;
       
    71 	}
       
    72 	else
       
    73 	{
       
    74 		cout << "Found " << *i << endl;
       
    75 		failures++;
       
    76 	}
       
    77 	i = s.find(star);
       
    78 	if(i == s.end())
       
    79 	{
       
    80 		cout << "Not found" << endl;
       
    81 		failures++;
       
    82 	}
       
    83 	else
       
    84 	{
       
    85 		cout << "Found " << *i << endl;
       
    86 	}
       
    87 
       
    88 	int count = s.erase(star);
       
    89 	cout << "Erased " << count << " instances" << endl;
       
    90 	if(count != 2)
       
    91 		failures++;
       
    92 
       
    93 	if (!failures)
       
    94 	return 0;
       
    95 	else
       
    96 	return 1;
       
    97 }