-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_CString.cpp
185 lines (143 loc) · 3.41 KB
/
main_CString.cpp
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
180
181
182
183
184
185
/**
* \file main_CString.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
#include "CString.h"
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
/*******************************************************************************
* public, constructors
*
*******************************************************************************/
// CString()
{
{
CString s;
s.print();
}
{
// CString s();
// warning C4930: 'CString s(void)':
// prototyped function not called (was a variable definition intended?) 28
}
{
CString *s = new CString();
s->print();
delete s;
}
}
// CString(const char *str)
{
const char *str = "default constructor";
CString s(str);
s.print();
}
// CString(const CString &a_str)
{
{
const char *str = "copy constructor 1";
CString s_copy(str);
CString s(s_copy);
s.print();
}
{
const char *str = "copy constructor 2";
CString s = str;
s.print();
}
}
/*******************************************************************************
* public, methods
*
*******************************************************************************/
// isEmpty()
{
{
CString s("isEmpty()");
STD_TEST(!s.isEmpty());
}
{
CString s;
STD_TEST(s.isEmpty());
}
}
// data()
{
CString s("data()");
STD_TEST(s == "data()");
}
// print()
{
CString("print").print();
}
/*******************************************************************************
* public, operators
*
*******************************************************************************/
// operator char * ()
{
CString s("operator char * ()");
char *p = s;
STD_TEST(p == (char *)s);
}
// operator const char * ()
{
CString s("operator char * ()");
const char *p = s;
STD_TEST(p == s);
}
// operator + (const CString &a_str)
{
CString rv;
CString s1("s1");
CString s2("s2");
rv = s1 + s2;
STD_TEST(rv == "s1s2");
}
// operator = (const CString &a_str)
{
const char *str = "operator =";
CString s;
s = str;
STD_TEST(s == str);
}
// operator == (const CString &a_str)
{
CString s1("s1");
CString s2("s1");
STD_TEST(s1 == s2);
}
// operator != (const CString &a_str)
{
CString s1("s1");
CString s2("s2");
STD_TEST(s1 != s2);
}
// operator () ()
{
CString s;
s();
}
// operator [] (size_t i)
{
CString s("abc");
STD_TEST(s[size_t(0)] == 'a');
STD_TEST(s[size_t(1)] == 'b');
STD_TEST(s[size_t(2)] == 'c');
}
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
<empty>
<empty>
default constructor
copy constructor 1
copy constructor 2
print
operator ()
#endif