31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <iterator>
|
|
6 |
#include <vector>
|
|
7 |
#include <algorithm>
|
|
8 |
#include <iostream>
|
|
9 |
#include <cstring>
|
|
10 |
|
|
11 |
#ifdef MAIN
|
|
12 |
#define parsrtc2_test main
|
|
13 |
#endif
|
|
14 |
|
|
15 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
16 |
using namespace std;
|
|
17 |
#endif
|
|
18 |
|
|
19 |
static bool str_compare(const char* a_, const char* b_)
|
|
20 |
{
|
|
21 |
return strcmp(a_, b_) < 0 ? 1 : 0;
|
|
22 |
}
|
|
23 |
|
|
24 |
int parsrtc2_test(int, char**)
|
|
25 |
{
|
|
26 |
int failures=0;
|
|
27 |
cout<<"Results of parsrtc2_test:"<<endl;
|
|
28 |
|
|
29 |
char* names[] = { "aa", "ff", "dd", "ee", "cc", "bb" };
|
|
30 |
|
|
31 |
const unsigned nameSize = sizeof(names) / sizeof(names[0]);
|
|
32 |
vector <char*> v1(nameSize);
|
|
33 |
for(int i = 0; i < v1.size(); i++)
|
|
34 |
v1[i] = names[i];
|
|
35 |
ostream_iterator<char*> iter(cout, " ");
|
|
36 |
copy(v1.begin(), v1.end(), iter);
|
|
37 |
|
|
38 |
if(strcmp("aa", v1[0]))
|
|
39 |
failures++;
|
|
40 |
if(strcmp("ff", v1[1]))
|
|
41 |
failures++;
|
|
42 |
if(strcmp("dd", v1[2]))
|
|
43 |
failures++;
|
|
44 |
if(strcmp("ee", v1[3]))
|
|
45 |
failures++;
|
|
46 |
if(strcmp("cc", v1[4]))
|
|
47 |
failures++;
|
|
48 |
if(strcmp("bb", v1[5]))
|
|
49 |
failures++;
|
|
50 |
|
|
51 |
cout << endl;
|
|
52 |
vector <char*> result(5);
|
|
53 |
partial_sort_copy(v1.begin(),
|
|
54 |
v1.end(),
|
|
55 |
result.begin(),
|
|
56 |
result.end(),
|
|
57 |
str_compare);
|
|
58 |
copy(result.begin(),result.end(), iter);
|
|
59 |
|
|
60 |
if(strcmp("aa", result[0]))
|
|
61 |
failures++;
|
|
62 |
if(strcmp("bb", result[1]))
|
|
63 |
failures++;
|
|
64 |
if(strcmp("cc", result[2]))
|
|
65 |
failures++;
|
|
66 |
if(strcmp("dd", result[3]))
|
|
67 |
failures++;
|
|
68 |
if(strcmp("ee", result[4]))
|
|
69 |
failures++;
|
|
70 |
|
|
71 |
cout << endl;
|
|
72 |
|
|
73 |
if(failures)
|
|
74 |
return 1;
|
|
75 |
else
|
|
76 |
return 0;
|
|
77 |
}
|