ReactOS 0.4.15-dev-8127-g6338913
uninitialized_test.cpp
Go to the documentation of this file.
1#include <memory>
2#include <vector>
3#include <list>
4
6
7#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
8using namespace std;
9#endif
10
11//
12// TestCase class
13//
14class UninitializedTest : public CPPUNIT_NS::TestCase
15{
18 //CPPUNIT_TEST(fill_test);
19 //CPPUNIT_TEST(fill_n_test);
21
22protected:
23 void copy_test();
24 void fill_test();
26};
27
29
33
34 int member;
35};
36
40
41 int member;
42};
43
47
48 static size_t nbConstructorCalls;
49};
50
52
53#if defined (STLPORT)
54# if defined (_STLP_USE_NAMESPACES)
55namespace std {
56# endif
59 typedef __false_type has_trivial_default_constructor;
60 //This is a wrong declaration just to check that internaly a simple memcpy is called:
61 typedef __true_type has_trivial_copy_constructor;
62 typedef __true_type has_trivial_assignment_operator;
63 typedef __true_type has_trivial_destructor;
64 typedef __false_type is_POD_type;
65 };
66
69 //This is a wrong declaration just to check that internaly no initialization is done:
70 typedef __true_type has_trivial_default_constructor;
71 typedef __true_type has_trivial_copy_constructor;
72 typedef __true_type has_trivial_assignment_operator;
73 typedef __true_type has_trivial_destructor;
74 typedef __false_type is_POD_type;
75 };
76# if defined (_STLP_USE_NAMESPACES)
77}
78# endif
79#endif
80
81struct base {};
82struct derived : public base {};
83
84//
85// tests implementation
86//
88{
89 {
90 //Random iterators
91 {
92 vector<NotTrivialCopyStruct> src(10);
93 vector<NotTrivialCopyStruct> dst(10);
94 uninitialized_copy(src.begin(), src.end(), dst.begin());
96 for (; it != end; ++it) {
97 CPPUNIT_ASSERT( (*it).member == 1 );
98 }
99 }
100 {
103 size_t const count = 10;
106
107 TrivialCopyStruct* it = src + 0;
109 for (; it != end; ++it) {
110 (*it).member = 0;
111 }
112
114 for (it = dst+0, end = dst+count; it != end; ++it) {
115#if defined (STLPORT)
116 /* If the member is 1, it means that library has not found any
117 optimization oportunity and called the regular copy-ctor instead. */
118 CPPUNIT_ASSERT( (*it).member == 0 );
119#else
120 CPPUNIT_ASSERT( (*it).member == 1 );
121#endif
122 }
123 }
124 }
125
126 {
127 //Bidirectional iterator
128 {
129 vector<NotTrivialCopyStruct> src(10);
130 list<NotTrivialCopyStruct> dst(10);
131
133 for (; it != end; ++it) {
134 (*it).member = -1;
135 }
136
137 uninitialized_copy(src.begin(), src.end(), dst.begin());
138
139 for (it = dst.begin(); it != end; ++it) {
140 CPPUNIT_ASSERT( (*it).member == 1 );
141 }
142 }
143
144 {
145 list<NotTrivialCopyStruct> src(10);
146 vector<NotTrivialCopyStruct> dst(10);
147
149 for (; it != end; ++it) {
150 (*it).member = -1;
151 }
152
153 uninitialized_copy(src.begin(), src.end(), dst.begin());
154
155 for (it = dst.begin(); it != end; ++it) {
156 CPPUNIT_ASSERT( (*it).member == 1 );
157 }
158 }
159 }
160
161 {
162 //Using containers of native types:
163#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)
164 {
165 vector<int> src;
166 int i;
167 for (i = -5; i < 6; ++i) {
168 src.push_back(i);
169 }
170
171 //Building a vector result in a uninitialized_copy call internally
172 vector<unsigned int> dst(src.begin(), src.end());
174 for (i = -5; i < 6; ++i, ++it) {
175 CPPUNIT_ASSERT( *it == (unsigned int)i );
176 }
177 }
178
179 {
180 vector<char> src;
181 char i;
182 for (i = -5; i < 6; ++i) {
183 src.push_back(i);
184 }
185
186 //Building a vector result in a uninitialized_copy call internally
187 vector<unsigned int> dst(src.begin(), src.end());
189 for (i = -5; i < 6; ++i, ++it) {
190 CPPUNIT_ASSERT( *it == (unsigned int)i );
191 }
192 }
193
194 {
195 vector<int> src;
196 int i;
197 for (i = -5; i < 6; ++i) {
198 src.push_back(i);
199 }
200
201 //Building a vector result in a uninitialized_copy call internally
202 vector<float> dst(src.begin(), src.end());
204 for (i = -5; i < 6; ++i, ++it) {
205 CPPUNIT_ASSERT( *it == (float)i );
206 }
207 }
208
209 {
210 vector<vector<float>*> src(10);
211 vector<vector<float>*> dst(src.begin(), src.end());
212 }
213
214 {
215 derived d;
216 //base *pb = &d;
217 derived *pd = &d;
218 //base **ppb = &pd;
219 vector<derived*> src(10, pd);
220 vector<base*> dst(src.begin(), src.end());
221 vector<base*>::iterator it(dst.begin()), end(dst.end());
222 for (; it != end; ++it) {
223 CPPUNIT_ASSERT( (*it) == pd );
224 }
225 }
226#endif
227 }
228
229 {
230 //Vector initialization:
231 vector<TrivialInitStruct> vect(10);
232 //Just 1 constructor call for the default value:
234 }
235}
236
237/*
238void UninitializedTest::fill_test()
239{
240}
241
242void UninitializedTest::fill_n_test()
243{
244}
245*/
_STLP_MOVE_TO_STD_NAMESPACE _ForwardIter uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result)
CPPUNIT_TEST(copy_test)
CPPUNIT_TEST_SUITE(UninitializedTest)
_STLP_PRIV _List_iterator< _Tp, _Nonconst_traits< _Tp > > iterator
Definition: _list.h:275
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
#define _STLP_TEMPLATE_NULL
Definition: features.h:652
GLuint GLuint end
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define d
Definition: ke_i.h:81
Definition: features.h:417
NotTrivialCopyStruct(NotTrivialCopyStruct const &)
TrivialCopyStruct(TrivialCopyStruct const &)
static size_t nbConstructorCalls
const value_type * const_iterator
Definition: _vector.h:125
value_type * iterator
Definition: _vector.h:124