31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <vector>
|
|
6 |
#include <algorithm>
|
|
7 |
#include <iostream>
|
|
8 |
#include <cstring>
|
|
9 |
|
|
10 |
#ifdef MAIN
|
|
11 |
#define incl2_test main
|
|
12 |
#endif
|
|
13 |
|
|
14 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
15 |
using namespace std;
|
|
16 |
#endif
|
|
17 |
static bool compare_strings(const char* s1_, const char* s2_)
|
|
18 |
{
|
|
19 |
return strcmp(s1_, s2_) < 0 ? 1 : 0;
|
|
20 |
}
|
|
21 |
int incl2_test(int, char**)
|
|
22 |
{
|
|
23 |
cout<<"Results of incl2_test:"<<endl;
|
|
24 |
int failures = 0;
|
|
25 |
char* names[] = { "Todd", "Mike", "Graham", "Jack", "Brett"};
|
|
26 |
|
|
27 |
const unsigned nameSize = sizeof(names)/sizeof(names[0]);
|
|
28 |
vector <char*> v1(nameSize);
|
|
29 |
for(int i = 0; i < v1.size(); i++)
|
|
30 |
{
|
|
31 |
v1[i] = names[i];
|
|
32 |
}
|
|
33 |
vector <char*> v2(2);
|
|
34 |
|
|
35 |
v2[0] = "foo";
|
|
36 |
v2[1] = "bar";
|
|
37 |
sort(v1.begin(), v1.end(), compare_strings);
|
|
38 |
// cout << "v1 sorted;\n";
|
|
39 |
sort(v2.begin(), v2.end(), compare_strings);
|
|
40 |
// cout << "v1 sorted;\n";
|
|
41 |
|
|
42 |
bool inc = includes(v1.begin(), v1.end(),
|
|
43 |
v2.begin(), v2.end(),
|
|
44 |
compare_strings);
|
|
45 |
if(inc)
|
|
46 |
{
|
|
47 |
failures++;
|
|
48 |
cout << "v1 includes v2" << endl;
|
|
49 |
}
|
|
50 |
else
|
|
51 |
cout << "v1 does not include v2" << endl;
|
|
52 |
v2[0] = "Brett";
|
|
53 |
v2[1] = "Todd";
|
|
54 |
inc = includes(v1.begin(), v1.end(),
|
|
55 |
v2.begin(), v2.end(),
|
|
56 |
compare_strings);
|
|
57 |
if(inc)
|
|
58 |
cout << "v1 includes v2" << endl;
|
|
59 |
else
|
|
60 |
{
|
|
61 |
failures++;
|
|
62 |
cout << "v1 does not include v2" << endl;
|
|
63 |
}
|
|
64 |
return 0;
|
|
65 |
}
|