|
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 #include <iterator> |
|
10 |
|
11 #ifdef MAIN |
|
12 #define parsrt2_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 parsrt2_test(int, char**) |
|
25 { |
|
26 |
|
27 int failures=0; |
|
28 cout<<"Results of parsrt2_test:"<<endl; |
|
29 |
|
30 char* names[] = { "aa", "ff", "dd", "ee", "cc", "bb" }; |
|
31 |
|
32 const unsigned nameSize = sizeof(names) / sizeof(names[0]); |
|
33 vector <char*> v1(nameSize); |
|
34 for(int i = 0; i < v1.size(); i++) |
|
35 v1[i] = names[i]; |
|
36 ostream_iterator<char*> iter(cout, " "); |
|
37 copy(v1.begin(), v1.end(), iter); |
|
38 cout << endl; |
|
39 if(strcmp("aa", v1[0])) |
|
40 failures++; |
|
41 if(strcmp("ff", v1[1])) |
|
42 failures++; |
|
43 if(strcmp("dd", v1[2])) |
|
44 failures++; |
|
45 if(strcmp("ee", v1[3])) |
|
46 failures++; |
|
47 if(strcmp("cc", v1[4])) |
|
48 failures++; |
|
49 if(strcmp("bb", v1[5])) |
|
50 failures++; |
|
51 |
|
52 partial_sort(v1.begin(), |
|
53 v1.begin() + nameSize / 2, |
|
54 v1.end(), |
|
55 str_compare); |
|
56 copy(v1.begin(), v1.end(), iter); |
|
57 cout << endl; |
|
58 |
|
59 if(strcmp(v1[0], "aa")) |
|
60 failures++; |
|
61 if(strcmp("bb", v1[1])) |
|
62 failures++; |
|
63 if(strcmp("cc", v1[2])) |
|
64 failures++; |
|
65 if(strcmp("ff", v1[3])) |
|
66 failures++; |
|
67 if(strcmp("ee", v1[4])) |
|
68 failures++; |
|
69 if(strcmp("dd", v1[5])) |
|
70 failures++; |
|
71 |
|
72 if(failures) |
|
73 return 1; |
|
74 else |
|
75 return 0; |
|
76 } |