ReactOS 0.4.15-dev-7889-g76290a6
istmit_test.cpp
Go to the documentation of this file.
1#include <algorithm>
2#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
3# include <sstream>
4# include <functional>
5# include <iterator>
6# include <vector>
7# include <string>
8#endif
9
11
12#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
13using namespace std;
14#endif
15
16//
17// TestCase class
18//
19class IStreamIteratorTest : public CPPUNIT_NS::TestCase
20{
22#if defined (STLPORT) && defined (_STLP_USE_NO_IOSTREAMS)
24#endif
26#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS)
28#endif
31
32protected:
33 void istmit1();
34 void copy_n_test();
35};
36
38
39#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
40# if !defined (STLPORT) || !defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
44# else
48# endif
49#endif
50
51//
52// tests implementation
53//
55{
56#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
57 const char* buff = "MyString";
58 istringstream istr(buff);
59
60 char buffer[100];
61 size_t i = 0;
62 istr.unsetf(ios::skipws); // Disable white-space skipping.
63 istream_char_ite s(istr), meos;
64 while (!(s == meos) &&
65 //*TY 01/10/1999 - added end of stream check
66 // NOTE operator!= should not be used here ifndef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
67 (*s != '\n') &&
68 (i < sizeof(buffer) / sizeof(buffer[0]))) { //*TY 07/28/98 - added index check
69 buffer[i++] = *s++;
70 }
71 buffer[i] = '\0'; // Null terminate buffer.
72
74
75 {
76 istringstream empty_istr;
78 }
79#endif
80}
81
83{
84#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && !defined (_STLP_USE_NO_IOSTREAMS)
85 //This test check that no character is lost while reading the istream
86 //through a istream_iterator.
87 {
88 istringstream istr("aabbcd");
89 string chars;
91 2, back_inserter(chars)).first,
92 2, back_inserter(chars)).first;
93 CPPUNIT_ASSERT( chars == "aabb" );
94 copy_n(ite, 2, back_inserter(chars));
95 CPPUNIT_ASSERT( chars == "aabbcd" );
96 }
97
98 {
99 istringstream istr("11 22 AA BB 33 44 CC DD");
100 vector<int> ints;
101 vector<string> strings;
102
104 CPPUNIT_ASSERT( ints.size() == 2 );
105 CPPUNIT_ASSERT( ints[0] == 11 );
106 CPPUNIT_ASSERT( ints[1] == 22 );
107 ints.clear();
108 istr.clear();
110 CPPUNIT_ASSERT( strings.size() == 2 );
111 CPPUNIT_ASSERT( strings[0] == "AA" );
112 CPPUNIT_ASSERT( strings[1] == "BB" );
113 strings.clear();
114 istr.clear();
115 /* The following code cannot work, '33' is extracted as a string
116 * in the previous copy_n call, this value is returned in the pair
117 * returned by copy_n but is lost as this istream_iterator is not used.
118 * copy_n and istream_iterator can only be combined safely if:
119 * - you always extract the same type of istream_iterator and you always reuse
120 * the istream_iterator returned by copy_n (see previous test with "aabbcd")
121 * - you extract different type of object and no object is convertible to an other
122 * as in this current test when you extract int and string (when you extract ints
123 * again it fails as int can be converted to strings.
124 *
125 copy_n(istream_int_ite(istr), 2, back_inserter(ints));
126 CPPUNIT_ASSERT( ints.size() == 2 );
127 CPPUNIT_ASSERT( ints[0] == 33 );
128 CPPUNIT_ASSERT( ints[1] == 44 );
129 istr.clear();
130 copy_n(istream_string_ite(istr), 2, back_inserter(strings));
131 CPPUNIT_ASSERT( strings.size() == 2 );
132 CPPUNIT_ASSERT( strings[0] == "CC" );
133 CPPUNIT_ASSERT( strings[1] == "DD" );
134 */
135 }
136
137 {
138 istringstream is("1 2 3 4 5 6 7 8 9 10");
139 vector<int> ints;
140 istream_iterator<int> itr(is);
141 itr = copy_n(itr, 0, back_inserter(ints)).first;
142 CPPUNIT_ASSERT( ints.empty() );
143 itr = copy_n(itr, -1, back_inserter(ints)).first;
144 CPPUNIT_ASSERT( ints.empty() );
145 itr = copy_n(itr, 2, back_inserter(ints)).first;
146 CPPUNIT_ASSERT( ints.size() == 2 );
147 CPPUNIT_ASSERT( ints[0] == 1 );
148 CPPUNIT_ASSERT( ints[1] == 2 );
149 itr = copy_n(itr, 2, back_inserter(ints)).first;
150 CPPUNIT_ASSERT( ints.size() == 4 );
151 CPPUNIT_ASSERT( ints[2] == 3 );
152 CPPUNIT_ASSERT( ints[3] == 4 );
153 itr = copy_n(itr, 2, back_inserter(ints)).first;
154 CPPUNIT_ASSERT( ints.size() == 6 );
155 CPPUNIT_ASSERT( ints[4] == 5 );
156 CPPUNIT_ASSERT( ints[5] == 6 );
157 }
158#endif
159}
_STLP_MOVE_TO_STD_NAMESPACE pair< _InputIter, _OutputIter > copy_n(_InputIter __first, _Size __count, _OutputIter __result)
Definition: _algobase.h:399
back_insert_iterator< _Container > _STLP_CALL back_inserter(_Container &__x)
Definition: _iterator.h:187
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
CPPUNIT_TEST(copy_n_test)
CPPUNIT_TEST_SUITE(IStreamIteratorTest)
void clear(iostate __state=goodbit)
Definition: _ios.h:91
void unsetf(fmtflags __mask)
Definition: _ios_base.h:125
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
static unsigned char buff[32768]
Definition: fatten.c:17
GLdouble s
Definition: gl.h:2039
GLsizei const GLchar *const * strings
Definition: glext.h:7622
GLuint buffer
Definition: glext.h:5915
const GLint * first
Definition: glext.h:5794
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
istream_iterator< char > istream_char_ite
Definition: istmit_test.cpp:41
istream_iterator< string > istream_string_ite
Definition: istmit_test.cpp:43
istream_iterator< int > istream_int_ite
Definition: istmit_test.cpp:42
static const struct encodedInt ints[]
Definition: encode.c:48
Definition: features.h:417