31
|
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 <vector>
|
|
22 |
#include <algorithm>
|
|
23 |
#include <iostream>
|
|
24 |
#include <cstring>
|
|
25 |
|
|
26 |
#ifdef MAIN
|
|
27 |
#define incl2_test main
|
|
28 |
#endif
|
|
29 |
|
|
30 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
31 |
using namespace std;
|
|
32 |
#endif
|
|
33 |
static bool compare_strings(const char* s1_, const char* s2_)
|
|
34 |
{
|
|
35 |
return strcmp(s1_, s2_) < 0 ? 1 : 0;
|
|
36 |
}
|
|
37 |
int incl2_test(int, char**)
|
|
38 |
{
|
|
39 |
cout<<"Results of incl2_test:"<<endl;
|
|
40 |
int failures = 0;
|
|
41 |
char* names[] = { "Todd", "Mike", "Graham", "Jack", "Brett"};
|
|
42 |
|
|
43 |
const unsigned nameSize = sizeof(names)/sizeof(names[0]);
|
|
44 |
vector <char*> v1(nameSize);
|
|
45 |
for(int i = 0; i < v1.size(); i++)
|
|
46 |
{
|
|
47 |
v1[i] = names[i];
|
|
48 |
}
|
|
49 |
vector <char*> v2(2);
|
|
50 |
|
|
51 |
v2[0] = "foo";
|
|
52 |
v2[1] = "bar";
|
|
53 |
sort(v1.begin(), v1.end(), compare_strings);
|
|
54 |
// cout << "v1 sorted;\n";
|
|
55 |
sort(v2.begin(), v2.end(), compare_strings);
|
|
56 |
// cout << "v1 sorted;\n";
|
|
57 |
|
|
58 |
bool inc = includes(v1.begin(), v1.end(),
|
|
59 |
v2.begin(), v2.end(),
|
|
60 |
compare_strings);
|
|
61 |
if(inc)
|
|
62 |
{
|
|
63 |
failures++;
|
|
64 |
cout << "v1 includes v2" << endl;
|
|
65 |
}
|
|
66 |
else
|
|
67 |
cout << "v1 does not include v2" << endl;
|
|
68 |
v2[0] = "Brett";
|
|
69 |
v2[1] = "Todd";
|
|
70 |
inc = includes(v1.begin(), v1.end(),
|
|
71 |
v2.begin(), v2.end(),
|
|
72 |
compare_strings);
|
|
73 |
if(inc)
|
|
74 |
cout << "v1 includes v2" << endl;
|
|
75 |
else
|
|
76 |
{
|
|
77 |
failures++;
|
|
78 |
cout << "v1 does not include v2" << endl;
|
|
79 |
}
|
|
80 |
return 0;
|
|
81 |
}
|