ReactOS  0.4.15-dev-1049-g1062a29
copy_test.cpp
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cstring>
3 #include <vector>
4 #include <iterator>
5 
7 
8 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
9 using namespace std;
10 #endif
11 
12 //
13 // TestCase class
14 //
15 class CopyTest : public CPPUNIT_NS::TestCase
16 {
18  CPPUNIT_TEST(copy_array);
19  CPPUNIT_TEST(copy_volatile);
20  CPPUNIT_TEST(copy_vector);
21  CPPUNIT_TEST(copy_insert);
22  CPPUNIT_TEST(copy_back);
23  CPPUNIT_TEST(copy_back_array);
25 
26 protected:
27  void copy_array();
28  void copy_volatile();
29  void copy_vector();
30  void copy_insert();
31  void copy_back();
32  void copy_back_array();
33 };
34 
36 
37 //
38 // tests implementation
39 //
41 {
42  char string[23] = "A string to be copied.";
43  char result[23];
44  copy(string, string + 23, result);
45  CPPUNIT_ASSERT(!strncmp(string, result, 23));
46 }
47 
49 {
50  {
51  int a[] = {0, 1, 2, 3, 4, 5};
52  const size_t size = sizeof(a) / sizeof(a[0]);
53  volatile int va[size];
54  copy(a, a + size, va);
55  for (size_t i = 0; i != size; ++i) {
56  CPPUNIT_ASSERT( a[i] == va[i] );
57  }
58  }
59 
60  {
61  const int a[] = {0, 1, 2, 3, 4, 5};
62  const size_t size = sizeof(a) / sizeof(a[0]);
63  volatile int va[size];
64  copy(a, a + size, va);
65  for (size_t i = 0; i != size; ++i) {
66  CPPUNIT_ASSERT( a[i] == va[i] );
67  }
68  }
69 
70  // Following code can be activated to check that it doesn't compiled
71 #if 0
72  {
73  int a[] = {0, 1, 2, 3, 4, 5};
74  const size_t size = sizeof(a) / sizeof(a[0]);
75  const volatile int va[size] = {5, 4, 3, 2, 1, 0};
76  copy(a, a + size, va);
77  for (size_t i = 0; i != size; ++i) {
78  CPPUNIT_ASSERT( a[i] == va[i] );
79  }
80  }
81 #endif
82 }
83 
85 {
86  vector<int> v1(10);
87  for (int i = 0; (size_t)i < v1.size(); ++i)
88  v1[i] = i;
89 
90  vector<int> v2(v1.size());
91  copy(v1.begin(), v1.end(), v2.begin());
92 
93  CPPUNIT_ASSERT( v2 == v1 );
94 }
95 
97  vector<int> v1(10);
98  for (int loc = 0; (size_t)loc < v1.size(); ++loc)
99  v1[loc] = loc;
100  vector<int> v2;
101  insert_iterator<vector<int> > i(v2, v2.begin());
102  copy(v1.begin(), v1.end(), i);
103 
104  CPPUNIT_ASSERT( v2 == v1 );
105 }
106 
108 {
109  vector<int> v1(10);
110  for (int i = 0; (size_t)i < v1.size(); ++i)
111  v1[i] = i;
112  vector<int> v2(v1.size());
113  copy_backward(v1.begin(), v1.end(), v2.end());
114 
115  CPPUNIT_ASSERT( v2 == v1 );
116 }
117 
119 {
120  int numbers[5] = { 1, 2, 3, 4, 5 };
121 
122  int result[5];
123  copy_backward(numbers, numbers + 5, (int*)result + 5);
124  CPPUNIT_ASSERT(result[0]==numbers[0]);
125  CPPUNIT_ASSERT(result[1]==numbers[1]);
126  CPPUNIT_ASSERT(result[2]==numbers[2]);
127  CPPUNIT_ASSERT(result[3]==numbers[3]);
128  CPPUNIT_ASSERT(result[4]==numbers[4]);
129 }
void copy_insert()
Definition: copy_test.cpp:96
void copy_back_array()
Definition: copy_test.cpp:118
void copy_back()
Definition: copy_test.cpp:107
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
Definition: features.h:417
void copy_vector()
Definition: copy_test.cpp:84
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 a
Definition: ke_i.h:78
CPPUNIT_TEST_SUITE_REGISTRATION(CopyTest)
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
__kernel_size_t size_t
Definition: linux.h:237
void copy_volatile()
Definition: copy_test.cpp:48
GLsizeiptr size
Definition: glext.h:5919
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
void copy_array()
Definition: copy_test.cpp:40
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLuint64EXT * result
Definition: glext.h:11304
_STLP_MOVE_TO_STD_NAMESPACE _OutputIter copy_backward(_InputIter __first, _InputIter __last, _OutputIter __result)
Definition: _algobase.h:328
GLfloat GLfloat v1
Definition: glext.h:6062