1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
// ============================================================================
// $Id$
//
// = LIBRARY
// tests
//
// = FILENAME
// SString_Test.cpp
//
// = DESCRIPTION
// This is a simple test that illustrates the use of ACE_CString
// and ACE_WString. No command line arguments are needed to run
// the test.
//
// = AUTHOR
// Prashant Jain
//
// ============================================================================
#include "test_config.h"
#include "ace/SString.h"
ACE_RCSID(tests, SString_Test, "$Id$")
#if defined(__BORLANDC__) && __BORLANDC__ >= 0x0530
USELIB("..\ace\aced.lib");
//---------------------------------------------------------------------------
#endif /* defined(__BORLANDC__) && __BORLANDC__ >= 0x0530 */
int
main (int, ASYS_TCHAR *[])
{
ACE_START_TEST (ASYS_TEXT ("SString_Test"));
{
ACE_CString s0 ("hello");
ACE_CString s1 ("hello");
ACE_CString s2 ("world");
ACE_CString s3 ("ll");
ACE_CString s4 ("ello");
ACE_CString s5 = s1 + " " + s2;
char single_character = 'z';
ACE_CString single_character_string (single_character);
ACE_CString empty_string;
ACE_CString zero_size_string (s1.c_str (), 0, 0, 1);
// Not equal comparisons.
ACE_ASSERT (s1 != s2);
ACE_ASSERT (s1 != s5);
// Equal comparisons.
ACE_ASSERT (s1 == s1);
ACE_ASSERT (s1 == s0);
// Substring match.
ACE_ASSERT (s1.strstr (s2) == -1);
ACE_ASSERT (s1.strstr (s3) == 2);
ACE_ASSERT (s3.strstr (s1) == -1);
ACE_ASSERT (s1.strstr (s4) == 1);
// Substring creation.
ACE_ASSERT (s1.substring (0) == s1);
ACE_ASSERT (s1.substring (1) == s4);
ACE_ASSERT (s1.substring (2, 2) == s3);
ACE_ASSERT (s1.substring (0, 0) == empty_string);
// Forward search.
ACE_ASSERT (s1.find (s3) == 2);
ACE_ASSERT (s3.find (s1) == ACE_CString::npos);
ACE_ASSERT (s1.find (s3, 2) == 0);
ACE_ASSERT (s3.find (s1, 1) == ACE_CString::npos);
ACE_ASSERT (s1.find (s2) == ACE_CString::npos);
ACE_ASSERT (s1.find ('o') == 4);
// Reverse search.
ACE_ASSERT (s1.rfind ('l') == 3);
ACE_ASSERT (s1.rfind ('l', 3) == 2);
}
{
ACE_CString s0 ("hello", 0, 0);
ACE_CString s1 ("hello", 0, 0);
ACE_CString s2 ("world", 0, 0);
ACE_CString s3 ("ll", 0, 0);
ACE_CString s4 ("ello", 0, 0);
ACE_CString s5 = s1 + " " + s2;
char single_character = 'z';
ACE_CString single_character_string (single_character);
ACE_CString empty_string (0, 0, 0);
ACE_CString zero_size_string (s1.c_str (), 0, 0, 0);
// Not equal comparisons.
ACE_ASSERT (s1 != s2);
ACE_ASSERT (s1 != s5);
// Equal comparisons.
ACE_ASSERT (s1 == s1);
ACE_ASSERT (s1 == s0);
// Substring match.
ACE_ASSERT (s1.strstr (s2) == -1);
ACE_ASSERT (s1.strstr (s3) == 2);
ACE_ASSERT (s3.strstr (s1) == -1);
ACE_ASSERT (s1.strstr (s4) == 1);
// Substring creation.
ACE_ASSERT (s1.substring (0) == s1);
ACE_ASSERT (s1.substring (1) == s4);
ACE_ASSERT (s1.substring (2, 2) == s3);
ACE_ASSERT (s1.substring (0, 0) == empty_string);
// Forward search.
ACE_ASSERT (s1.find (s3) == 2);
ACE_ASSERT (s3.find (s1) == ACE_CString::npos);
ACE_ASSERT (s1.find (s3, 2) == 0);
ACE_ASSERT (s3.find (s1, 1) == ACE_CString::npos);
ACE_ASSERT (s1.find (s2) == ACE_CString::npos);
ACE_ASSERT (s1.find ('o') == 4);
// Reverse search.
ACE_ASSERT (s1.rfind ('l') == 3);
ACE_ASSERT (s1.rfind ('l', 3) == 2);
}
{
ACE_WString s0 ("hello");
ACE_WString s1 ("hello");
ACE_WString s2 ("world");
ACE_WString s3 ("ll");
ACE_WString s4 ("ello");
ACE_WString s5 = s1 + " " + s2;
ACE_USHORT16 single_character = 'z';
ACE_WString single_character_string (single_character);
ACE_WString empty_string;
ACE_WString zero_size_string (s1.c_str (), 0, 0);
// Not equal comparisons.
ACE_ASSERT (s1 != s2);
ACE_ASSERT (s1 != s5);
// Equal comparisons.
ACE_ASSERT (s1 == s1);
ACE_ASSERT (s1 == s0);
// Substring match.
ACE_ASSERT (s1.strstr (s2) == -1);
ACE_ASSERT (s1.strstr (s3) == 2);
ACE_ASSERT (s3.strstr (s1) == -1);
ACE_ASSERT (s1.strstr (s4) == 1);
// Substring creation.
ACE_ASSERT (s1.substring (0) == s1);
ACE_ASSERT (s1.substring (1) == s4);
ACE_ASSERT (s1.substring (2, 2) == s3);
ACE_ASSERT (s1.substring (0, 0) == empty_string);
// Forward search.
ACE_ASSERT (s1.find (s3) == 2);
ACE_ASSERT (s3.find (s1) == ACE_WString::npos);
ACE_ASSERT (s1.find (s3, 2) == 0);
ACE_ASSERT (s3.find (s1, 1) == ACE_WString::npos);
ACE_ASSERT (s1.find (s2) == ACE_WString::npos);
ACE_ASSERT (s1.find ('o') == 4);
// Reverse search.
ACE_ASSERT (s1.rfind ('l') == 3);
ACE_ASSERT (s1.rfind ('l', 3) == 2);
}
ACE_END_TEST;
return 0;
}
|