ReactOS 0.4.15-dev-7953-g1f49173
NumPutGetTest Class Reference
Inheritance diagram for NumPutGetTest:
Collaboration diagram for NumPutGetTest:

Private Member Functions

 CPPUNIT_TEST_SUITE (NumPutGetTest)
 
 CPPUNIT_TEST (num_put_float)
 
 CPPUNIT_TEST (num_put_integer)
 
 CPPUNIT_TEST (num_get_float)
 
 CPPUNIT_TEST (num_get_integer)
 
 CPPUNIT_TEST (inhex)
 
 CPPUNIT_TEST (pointer)
 
 CPPUNIT_TEST (fix_float_long)
 
 CPPUNIT_TEST (custom_numpunct)
 
 CPPUNIT_TEST_SUITE_END ()
 
void num_put_float ()
 
void num_put_integer ()
 
void num_get_float ()
 
void num_get_integer ()
 
void inhex ()
 
void pointer ()
 
void fix_float_long ()
 
void custom_numpunct ()
 
template<class F >
void check_get_float (F v)
 

Static Private Member Functions

static bool check_float (float val, float ref)
 
static bool check_double (double val, double ref)
 
static string reset_stream (ostringstream &ostr)
 

Detailed Description

Definition at line 23 of file num_put_get_test.cpp.

Member Function Documentation

◆ check_double()

static bool NumPutGetTest::check_double ( double  val,
double  ref 
)
inlinestaticprivate

Definition at line 62 of file num_put_get_test.cpp.

63 {
64 double epsilon = numeric_limits<double>::epsilon();
65 return val <= ref + epsilon && val >= ref - epsilon;
66 }
Definition: send.c:48

Referenced by fix_float_long().

◆ check_float()

static bool NumPutGetTest::check_float ( float  val,
float  ref 
)
inlinestaticprivate

Definition at line 56 of file num_put_get_test.cpp.

57 {
58 float epsilon = numeric_limits<float>::epsilon();
59 return val <= ref + epsilon && val >= ref - epsilon;
60 }

Referenced by num_get_float().

◆ check_get_float()

template<class F >
void NumPutGetTest::check_get_float ( F  v)
inlineprivate

Definition at line 77 of file num_put_get_test.cpp.

78 {
79 F in_val_d = v;
80 typedef numeric_limits<F> limits;
81 {
83
84 str << "1E+" << limits::max_exponent10;
85
86 str >> in_val_d;
87 CPPUNIT_ASSERT(!str.fail());
88 CPPUNIT_ASSERT(str.eof());
89 CPPUNIT_CHECK( in_val_d == in_val_d );
90 CPPUNIT_CHECK( in_val_d != limits::infinity() );
91 }
92 {
94
95 str << "-1E+" << limits::max_exponent10;
96
97 str >> in_val_d;
98 CPPUNIT_ASSERT(!str.fail());
99 CPPUNIT_ASSERT(str.eof());
100 CPPUNIT_CHECK( in_val_d == in_val_d );
101 CPPUNIT_CHECK( in_val_d != -limits::infinity() );
102 }
103 {
105
106 str << "1E" << limits::min_exponent10;
107
108 str >> in_val_d;
109 CPPUNIT_ASSERT(!str.fail());
110 CPPUNIT_ASSERT(str.eof());
111 CPPUNIT_CHECK( in_val_d == in_val_d );
112 CPPUNIT_CHECK( in_val_d != F(0.0) );
113 }
114 {
116
117 str << "1E+" << (limits::max_exponent10 + 1);
118
119 str >> in_val_d;
120 CPPUNIT_ASSERT(!str.fail());
121 CPPUNIT_ASSERT(str.eof());
122 CPPUNIT_CHECK( in_val_d == in_val_d );
123 CPPUNIT_CHECK( in_val_d == limits::infinity() );
124 }
125 {
127
128 str << "-1E+" << (limits::max_exponent10 + 1);
129
130 str >> in_val_d;
131 CPPUNIT_ASSERT(!str.fail());
132 CPPUNIT_ASSERT(str.eof());
133 CPPUNIT_CHECK( in_val_d == in_val_d );
134 CPPUNIT_CHECK( in_val_d == -limits::infinity() );
135 }
136 {
138
139 str << "1E" << (limits::min_exponent10 - 1);
140
141 str >> in_val_d;
142 CPPUNIT_ASSERT(!str.fail());
143 CPPUNIT_ASSERT(str.eof());
144 CPPUNIT_CHECK( in_val_d == in_val_d );
145 CPPUNIT_CHECK( in_val_d >= F(0.0) && in_val_d <= limits::min() );
146 }
147#if !defined (__MINGW32__)
148 {
150
151 str << limits::max();
152
153 CPPUNIT_ASSERT(!str.fail());
154 CPPUNIT_CHECK( str.str() != "inf" );
155 CPPUNIT_CHECK( str.str() != "-inf" );
156 CPPUNIT_CHECK( str.str() != "nan" );
157 CPPUNIT_CHECK( str.str() != "-nan" );
158 //CPPUNIT_MESSAGE( str.str().c_str() );
159
160 //str.str("");
161 //str << limits::max_exponent10;
162 //CPPUNIT_MESSAGE( str.str().c_str() );
163
164 str >> in_val_d;
165
166 CPPUNIT_ASSERT(!str.fail());
167 CPPUNIT_ASSERT(str.eof());
168 CPPUNIT_CHECK( in_val_d == in_val_d );
169 CPPUNIT_CHECK( in_val_d != limits::infinity() );
170 }
171 {
173
174 str << fixed << limits::max();
175
176 CPPUNIT_ASSERT(!str.fail());
177 CPPUNIT_CHECK( str.str() != "inf" );
178 CPPUNIT_CHECK( str.str() != "-inf" );
179 CPPUNIT_CHECK( str.str() != "nan" );
180 CPPUNIT_CHECK( str.str() != "-nan" );
181 //CPPUNIT_MESSAGE( str.str().c_str() );
182
183 //str.str("");
184 //str << limits::max_exponent10;
185 //CPPUNIT_MESSAGE( str.str().c_str() );
186
187 str >> in_val_d;
188
189 CPPUNIT_ASSERT(!str.fail());
190 CPPUNIT_ASSERT(str.eof());
191 CPPUNIT_CHECK( in_val_d == in_val_d );
192 CPPUNIT_CHECK( in_val_d != limits::infinity() );
193 }
194 {
196
197 str << scientific << setprecision(50) << limits::max();
198
199 CPPUNIT_ASSERT(!str.fail());
200 CPPUNIT_CHECK( str.str() != "inf" );
201 CPPUNIT_CHECK( str.str() != "-inf" );
202 CPPUNIT_CHECK( str.str() != "nan" );
203 CPPUNIT_CHECK( str.str() != "-nan" );
204 //CPPUNIT_MESSAGE( str.str().c_str() );
205
206 //str.str("");
207 //str << limits::max_exponent10;
208 //CPPUNIT_MESSAGE( str.str().c_str() );
209
210 str >> in_val_d;
211
212 CPPUNIT_ASSERT(!str.fail());
213 CPPUNIT_ASSERT(str.eof());
214 CPPUNIT_CHECK( in_val_d == in_val_d );
215 CPPUNIT_CHECK( in_val_d != limits::infinity() );
216 }
217#endif
218 {
220
221 str << limits::infinity();
222
223 CPPUNIT_ASSERT( !str.fail() );
224 CPPUNIT_ASSERT( !limits::has_infinity || str.str() == "inf" );
225 }
226 {
228
229 str << -limits::infinity();
230
231 CPPUNIT_ASSERT( !str.fail() );
232 CPPUNIT_ASSERT( !limits::has_infinity || str.str() == "-inf" );
233 }
234 {
236
237 str << limits::quiet_NaN();
238
239 CPPUNIT_ASSERT( !str.fail() );
240 CPPUNIT_ASSERT( !limits::has_quiet_NaN || str.str() == "nan" );
241 }
242 {
244
245 str << -limits::quiet_NaN();
246
247 CPPUNIT_ASSERT( !str.fail() );
248 CPPUNIT_ASSERT( !limits::has_quiet_NaN || str.str() == "-nan" );
249 }
250 {
252
253 str << "0." << string(limits::max_exponent10, '0') << "1e" << (limits::max_exponent10 + 1);
254 CPPUNIT_ASSERT( !str.fail() );
255
256 str >> in_val_d;
257 CPPUNIT_ASSERT( !str.fail() );
258 CPPUNIT_ASSERT( str.eof() );
259 CPPUNIT_CHECK( in_val_d == 1 );
260 }
261 {
263
264 str << "1" << string(-(limits::min_exponent10 - 1), '0') << "e" << (limits::min_exponent10 - 1);
265 CPPUNIT_ASSERT( !str.fail() );
266
267 str >> in_val_d;
268 CPPUNIT_ASSERT( !str.fail() );
269 CPPUNIT_ASSERT( str.eof() );
270 CPPUNIT_CHECK( in_val_d == 1 );
271 }
272# if defined (_STLPORT_VERSION) && (_STLPORT_VERSION >= 0x530)
273 // The following tests are showing that simply changing stream
274 // precision lead to different result. Do not seems to be a real
275 // problem, simply rounding approximation but additional study should
276 // be done after 5.2 release.
277 {
279 str << setprecision(limits::digits10 + 2) << limits::max();
280
281 CPPUNIT_MESSAGE(str.str().c_str());
282 CPPUNIT_ASSERT( !str.fail() );
283
284 F val;
285 str >> val;
286
287 CPPUNIT_ASSERT( !str.fail() );
288 CPPUNIT_ASSERT( limits::infinity() > val );
289 }
290 {
292 str << setprecision(limits::digits10 + 1) << limits::max();
293
294 CPPUNIT_MESSAGE(str.str().c_str());
295 CPPUNIT_ASSERT( !str.fail() );
296
297 F val;
298 str >> val;
299
300 CPPUNIT_ASSERT( !str.fail() );
301 CPPUNIT_ASSERT( limits::infinity() > val );
302 }
303# endif
304 }
_STLP_PRIV _Ios_Manip_1< streamsize > _STLP_CALL setprecision(int __n)
Definition: _iomanip.h:119
ios_base &_STLP_CALL scientific(ios_base &__s)
Definition: _ios_base.h:335
ios_base &_STLP_CALL fixed(ios_base &__s)
Definition: _ios_base.h:332
#define CPPUNIT_CHECK(X)
Definition: cppunit_mini.h:195
#define CPPUNIT_MESSAGE(m)
Definition: cppunit_mini.h:223
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
const GLdouble * v
Definition: gl.h:2040
GLuint GLfloat * val
Definition: glext.h:7180
const WCHAR * str
#define F(x, y, z)
Definition: md5.c:51

Referenced by num_get_float().

◆ CPPUNIT_TEST() [1/8]

NumPutGetTest::CPPUNIT_TEST ( custom_numpunct  )
private

◆ CPPUNIT_TEST() [2/8]

NumPutGetTest::CPPUNIT_TEST ( fix_float_long  )
private

◆ CPPUNIT_TEST() [3/8]

NumPutGetTest::CPPUNIT_TEST ( inhex  )
private

◆ CPPUNIT_TEST() [4/8]

NumPutGetTest::CPPUNIT_TEST ( num_get_float  )
private

◆ CPPUNIT_TEST() [5/8]

NumPutGetTest::CPPUNIT_TEST ( num_get_integer  )
private

◆ CPPUNIT_TEST() [6/8]

NumPutGetTest::CPPUNIT_TEST ( num_put_float  )
private

◆ CPPUNIT_TEST() [7/8]

NumPutGetTest::CPPUNIT_TEST ( num_put_integer  )
private

◆ CPPUNIT_TEST() [8/8]

NumPutGetTest::CPPUNIT_TEST ( pointer  )
private

◆ CPPUNIT_TEST_SUITE()

NumPutGetTest::CPPUNIT_TEST_SUITE ( NumPutGetTest  )
private

◆ CPPUNIT_TEST_SUITE_END()

NumPutGetTest::CPPUNIT_TEST_SUITE_END ( )
private

◆ custom_numpunct()

void NumPutGetTest::custom_numpunct ( )
private

Definition at line 1234 of file num_put_get_test.cpp.

1235{
1236 ostringstream os;
1237 locale loc(os.getloc(), new CommaSepNumPunct());
1238 os.imbue(loc);
1239
1240 CHECK2(1, "+1");
1241 CHECK2(10, "+1,0");
1242 CHECK2(100, "+10,0");
1243 CHECK2(1000, "+1,00,0");
1244
1245 CHECK2(1.234, "+1.234");
1246 CHECK2(123.456, "+12,3.456");
1247 CHECK2(1234.567, "+1,23,4.567");
1248 CHECK2(12345.678, "+12,34,5.678");
1249 CHECK2(123456.789, "+123,45,6.789");
1250 CHECK2(1234567.891, "+1,234,56,7.891");
1251 CHECK2(123456789.123, "+123,456,78,9.123");
1252 //CHECK2(100000000000000000000000000000.0, "+100000000000000000000000,000,00,0.000");
1254
1255 CHECK2(-1.234, "-1.234");
1256 CHECK2(-123.456, "-12,3.456");
1257 CHECK2(-1234.567, "-1,23,4.567");
1258 CHECK2(-12345.678, "-12,34,5.678");
1259 CHECK2(-123456.789, "-123,45,6.789");
1260 CHECK2(-1234567.891, "-1,234,56,7.891");
1261 CHECK2(-123456789.123, "-123,456,78,9.123");
1262 //CHECK2(-100000000000000000000000000000.0, "-100000000000000000000000,000,00,0.000");
1264}
locale imbue(const locale &)
Definition: _ios.c:69
locale getloc() const
Definition: _ios_base.h:143
Definition: _locale.h:75
#define CHECK2(val, expected)

◆ fix_float_long()

void NumPutGetTest::fix_float_long ( )
private

Definition at line 1122 of file num_put_get_test.cpp.

1123{
1125
1126 str.setf(ios::fixed, ios::floatfield);
1127 str << 1.0e+5;
1128 CPPUNIT_CHECK( str.str() == "100000.000000" );
1129
1131 str.precision(0);
1132 str << 1.0e+5;
1133 CPPUNIT_CHECK( str.str() == "100000" );
1134
1136 str.precision(4);
1137 str << 1.0e+5;
1138 CPPUNIT_CHECK( str.str() == "100000.0000" );
1139
1141 str.precision(0);
1142 str << 1.0e+83;
1143 {
1144 istringstream istr( str.str() );
1145 double f;
1146 istr >> f;
1147 CPPUNIT_CHECK( !istr.fail() );
1148 if ( int(numeric_limits<double>::digits10) < 83 ) {
1149 double delta = 1.0;
1150 for ( int ee = 83 - int(numeric_limits<double>::digits10); ee > 0; --ee ) {
1151 delta *= 10.0;
1152 }
1153 // we may loss some digits here, but not more than mantissa:
1154 CPPUNIT_CHECK( (f > (1.0e+83 - delta)) && (f < (1.0e+83 + delta)) );
1155 } else {
1156 CPPUNIT_CHECK( check_double(f, 1.0e+83) );
1157 }
1158 }
1159
1160#if 0 // #ifndef _STLP_NO_LONG_DOUBLE
1162 str.precision(0);
1163 str << 1.0e+83l;
1164 {
1165 istringstream istr( str.str() );
1166 long double f;
1167 istr >> f;
1168 CPPUNIT_CHECK( !istr.fail() );
1169 if ( int(numeric_limits<long double>::digits10) < 83 ) {
1170 long double delta = 1.0l;
1171 for ( int ee = 83 - int(numeric_limits<long double>::digits10); ee > 0; --ee ) {
1172 delta *= 10.0l;
1173 }
1174 // we may loss some digits here, but not more than mantissa:
1175 cerr << "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" << endl;
1176 cerr << str.str() << endl;
1177 cerr << delta << endl;
1178 cerr << f << endl;
1179 CPPUNIT_CHECK( (f > (1.0e+83l - delta)) && (f < (1.0e+83l + delta)) );
1180 } else {
1181 CPPUNIT_CHECK( check_double(f, 1.0e+83l) );
1182 }
1183 }
1184#endif
1185
1187 str.precision(0);
1188 str << numeric_limits<double>::max();
1189 {
1190 istringstream istr( str.str() );
1191 double f;
1192 istr >> f;
1193 CPPUNIT_CHECK( !istr.fail() );
1195 double delta = 9.0;
1196 for ( int ee = int(numeric_limits<double>::max_exponent10) - int(numeric_limits<double>::digits10); ee > 0; --ee ) {
1197 delta *= 10.0;
1198 }
1199 // we may loss some digits here, but not more than mantissa:
1200 CPPUNIT_CHECK( (f > (numeric_limits<double>::max() - delta)) );
1201 }
1202 }
1203
1204#if 0 // #ifndef _STLP_NO_LONG_DOUBLE
1206 str.precision(0);
1207 str << numeric_limits<long double>::max();
1208 {
1209 istringstream istr( str.str() );
1210 long double f;
1211 istr >> f;
1212 CPPUNIT_CHECK( !istr.fail() );
1214 long double delta = 1.0l;
1216 delta *= 10.0l;
1217 }
1218 // we may loss some digits here, but not more than mantissa:
1220 }
1221 }
1222#endif
1223}
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
static bool check_double(double val, double ref)
static string reset_stream(ostringstream &ostr)
GLfloat f
Definition: glext.h:7540
#define cerr
Definition: iostream.cpp:39
#define f
Definition: ke_i.h:83

◆ inhex()

void NumPutGetTest::inhex ( )
private

Definition at line 1006 of file num_put_get_test.cpp.

1007{
1008 {
1010 s << hex << 0;
1011 CPPUNIT_CHECK( s.str() == "0" );
1012 }
1013 {
1015 s << hex << 0xff;
1016 CPPUNIT_CHECK( s.str() == "ff" );
1017 }
1018 {
1020 s << hex << setw( 4 ) << 0xff;
1021 CPPUNIT_CHECK( s.str() == " ff" );
1022 }
1023 {
1025 s << hex << setw( 4 ) << 0;
1026 CPPUNIT_CHECK( s.str() == " 0" );
1027 }
1028 {
1030 s << hex << showbase << 0;
1031 CPPUNIT_CHECK( s.str() == "0" );
1032 }
1033 {
1035 s << hex << showbase << 0xff;
1036 CPPUNIT_CHECK( s.str() == "0xff" );
1037 }
1038 {
1040 s << hex << showbase << setw( 4 ) << 0xff;
1041 CPPUNIT_CHECK( s.str() == "0xff" );
1042 }
1043 { // special case for regression (partially duplicate CHECK_COMPLETE above):
1045 s.setf( ios_base::internal, ios_base::adjustfield );
1046 s << hex << showbase << setw(8+2) << 0;
1047 CPPUNIT_CHECK( s.str() == " 0" );
1048 }
1049}
_STLP_PRIV _Ios_Manip_1< streamsize > _STLP_CALL setw(int __n)
Definition: _iomanip.h:125
ios_base &_STLP_CALL showbase(ios_base &__s)
Definition: _ios_base.h:273
GLdouble s
Definition: gl.h:2039
int hex(char ch)

◆ num_get_float()

void NumPutGetTest::num_get_float ( )
private

Definition at line 779 of file num_put_get_test.cpp.

780{
781 float in_val;
782
783 istringstream istr;
784
785 istr.str("1.2345");
786 istr >> in_val;
787 CPPUNIT_ASSERT(!istr.fail());
788 CPPUNIT_ASSERT(istr.eof());
789 CPPUNIT_ASSERT(check_float(in_val, 1.2345f));
790 istr.clear();
791
792 istr.str("-1.2345");
793 istr >> in_val;
794 CPPUNIT_ASSERT(!istr.fail());
795 CPPUNIT_ASSERT(istr.eof());
796 CPPUNIT_ASSERT(check_float(in_val, -1.2345f));
797 istr.clear();
798
799 istr.str("+1.2345");
800 istr >> in_val;
801 CPPUNIT_ASSERT(!istr.fail());
802 CPPUNIT_ASSERT(check_float(in_val, 1.2345f));
803 istr.clear();
804
805 istr.str("000000000000001.234500000000");
806 istr >> in_val;
807 CPPUNIT_ASSERT(!istr.fail());
808 CPPUNIT_ASSERT(istr.eof());
809 CPPUNIT_ASSERT(check_float(in_val, 1.2345f));
810 istr.clear();
811
812 istr.str("1.2345e+04");
813 istr >> in_val;
814 CPPUNIT_ASSERT(!istr.fail());
815 CPPUNIT_ASSERT(istr.eof());
816 CPPUNIT_ASSERT(check_float(in_val, 12345.0f));
817 istr.clear();
818
819 CPPUNIT_MESSAGE( "float" );
820 check_get_float( 0.0F );
821 CPPUNIT_MESSAGE( "double" );
822 check_get_float( 0.0 );
823#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE)
824 CPPUNIT_MESSAGE( "long double" );
825 check_get_float( 0.0L );
826#endif
827 {
829
831 CPPUNIT_ASSERT(!str.fail());
832
833 float val;
834 str >> val;
835 CPPUNIT_ASSERT(!str.fail());
836 CPPUNIT_ASSERT(str.eof());
839 }
840 {
842
844 CPPUNIT_ASSERT(!str.fail());
845
846 float val;
847 str >> val;
848 CPPUNIT_ASSERT(!str.fail());
849 CPPUNIT_ASSERT(str.eof());
851 val == 0.0f );
852 }
853#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE)
854 {
856
858 CPPUNIT_ASSERT(!str.fail());
859
860 double val;
861 str >> val;
862 CPPUNIT_ASSERT(!str.fail());
863 CPPUNIT_ASSERT(str.eof());
866 }
867 {
869
871 CPPUNIT_ASSERT(!str.fail());
872
873 double val;
874 str >> val;
875 CPPUNIT_ASSERT(!str.fail());
876 CPPUNIT_ASSERT(str.eof());
878 val == 0.0 );
879 }
880 {
881 const char* p = "2.718281828459045235360287471352662497757247093e0";
882 std::stringstream s;
883 s << p;
884 long double x;
885 s >> x;
886 CPPUNIT_ASSERT( x > 2.70l && x < 2.72l );
887 }
888#endif
889}
void check_get_float(F v)
static bool check_float(float val, float ref)
void clear(iostate __state=goodbit)
Definition: _ios.h:91
_String str() const
Definition: _sstream.h:141
bool fail() const
Definition: _ios_base.h:174
bool eof() const
Definition: _ios_base.h:173
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLfloat GLfloat p
Definition: glext.h:8902

◆ num_get_integer()

void NumPutGetTest::num_get_integer ( )
private

Definition at line 891 of file num_put_get_test.cpp.

892{
893 //octal input
894 {
895 istringstream istr;
896 istr.str("30071");
897 short val;
898 istr >> oct >> val;
899 CPPUNIT_ASSERT( !istr.fail() );
900 CPPUNIT_ASSERT( istr.eof() );
901 CPPUNIT_ASSERT( val == 12345 );
902 istr.clear();
903
904 if (sizeof(short) == 2) {
905 istr.str("177777");
906 istr >> oct >> val;
907 CPPUNIT_ASSERT( !istr.fail() );
908 CPPUNIT_ASSERT( istr.eof() );
909 CPPUNIT_ASSERT( val == -1 );
910 istr.clear();
911 }
912 }
913
914 //decimal input
915 {
916 istringstream istr;
917 istr.str("10000");
918 short val = -1;
919 istr >> val;
920 CPPUNIT_ASSERT( !istr.fail() );
921 CPPUNIT_ASSERT( istr.eof() );
922 CPPUNIT_ASSERT( val == 10000 );
923 istr.clear();
924
925 istr.str("+10000");
926 val = -1;
927 istr >> val;
928 CPPUNIT_ASSERT( !istr.fail() );
929 CPPUNIT_ASSERT( istr.eof() );
930 CPPUNIT_ASSERT( val == 10000 );
931 istr.clear();
932
933 if (sizeof(short) == 2) {
934 val = -1;
935 istr.str("10000000");
936 istr >> val;
937 CPPUNIT_ASSERT( istr.fail() );
938 CPPUNIT_ASSERT( istr.eof() );
939 CPPUNIT_ASSERT( val == -1 );
940 istr.clear();
941 }
942
943 val = -1;
944 istr.str("0x0");
945 istr >> val;
946 CPPUNIT_ASSERT( !istr.fail() );
947 CPPUNIT_ASSERT( !istr.eof() );
948 CPPUNIT_ASSERT( val == 0 );
949 istr.clear();
950
951 val = -1;
952 istr.str("000001");
953 istr >> val;
954 CPPUNIT_ASSERT( !istr.fail() );
955 CPPUNIT_ASSERT( istr.eof() );
956 CPPUNIT_ASSERT( val == 1 );
957 istr.clear();
958 }
959
960 //hexadecimal input
961 {
962 istringstream istr;
963 istr.str("3039");
964 short val = -1;
965 istr >> hex >> val;
966 CPPUNIT_ASSERT( !istr.fail() );
967 CPPUNIT_ASSERT( istr.eof() );
968 CPPUNIT_ASSERT( val == 12345 );
969 istr.clear();
970
971 istr.str("x3039");
972 val = -1;
973 istr >> hex >> val;
974 CPPUNIT_ASSERT( istr.fail() );
975 CPPUNIT_ASSERT( !istr.eof() );
976 CPPUNIT_ASSERT( val == -1 );
977 istr.clear();
978
979 istr.str("03039");
980 val = -1;
981 istr >> hex >> val;
982 CPPUNIT_ASSERT( !istr.fail() );
983 CPPUNIT_ASSERT( istr.eof() );
984 CPPUNIT_ASSERT( val == 12345 );
985 istr.clear();
986
987 istr.str("0x3039");
988 istr >> hex >> val;
989 CPPUNIT_ASSERT( !istr.fail() );
990 CPPUNIT_ASSERT( istr.eof() );
991 CPPUNIT_ASSERT( val == 12345 );
992 istr.clear();
993
994 if (sizeof(short) == 2) {
995 val = -1;
996 istr.str("cfc7");
997 istr >> hex >> val;
998 CPPUNIT_ASSERT( !istr.fail() );
999 CPPUNIT_ASSERT( istr.eof() );
1000 CPPUNIT_ASSERT( val == -12345 );
1001 istr.clear();
1002 }
1003 }
1004}
ios_base &_STLP_CALL oct(ios_base &__s)
Definition: _ios_base.h:327

◆ num_put_float()

void NumPutGetTest::num_put_float ( )
private

Definition at line 397 of file num_put_get_test.cpp.

398{
399 {
400 string output, digits;
401
402 {
403 ostringstream ostr;
404 ostr << 1.23457e+17f;
405 CPPUNIT_ASSERT(ostr.good());
406 output = reset_stream(ostr);
407 digits = "17";
409 CPPUNIT_CHECK(output == string("1.23457e+") + digits );
410 }
411
412 {
413 ostringstream ostr;
414 ostr << setprecision(200) << 1.23457e+17f;
415 CPPUNIT_ASSERT(ostr.good());
416 output = reset_stream(ostr);
417 CPPUNIT_CHECK( output.size() < 200 );
418 }
419
420 {
421 ostringstream ostr;
423 CPPUNIT_ASSERT(ostr.good());
424 output = reset_stream(ostr);
425 CPPUNIT_CHECK( output.size() < 200 );
426 }
427
428 {
429 ostringstream ostr;
430 ostr << fixed << 1.23457e+17f;
431 CPPUNIT_ASSERT(ostr.good());
432 output = reset_stream(ostr);
433 CPPUNIT_CHECK(output.size() == 25);
434 CPPUNIT_CHECK(output.substr(0, 5) == "12345");
435 CPPUNIT_CHECK(output.substr(18) == ".000000");
436 }
437
438 {
439 ostringstream ostr;
440 ostr << fixed << showpos << 1.23457e+17f;
441 CPPUNIT_ASSERT(ostr.good());
442 output = reset_stream(ostr);
443 CPPUNIT_CHECK(output.size() == 26);
444 CPPUNIT_CHECK(output.substr(0, 6) == "+12345");
445 CPPUNIT_CHECK(output.substr(19) == ".000000");
446 }
447
448 {
449 ostringstream ostr;
450 ostr << fixed << showpos << setprecision(100) << 1.23457e+17f;
451 CPPUNIT_ASSERT(ostr.good());
452 output = reset_stream(ostr);
453 CPPUNIT_CHECK(output.size() == 120);
454 CPPUNIT_CHECK(output.substr(0, 6) == "+12345");
455 CPPUNIT_CHECK(output.substr(19) == ".0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" );
456 }
457
458 {
459 ostringstream ostr;
460 ostr << scientific << setprecision(8) << 0.12345678f;
461 CPPUNIT_ASSERT(ostr.good());
462 output = reset_stream(ostr);
463 digits = "1";
465 CPPUNIT_CHECK(output == string("1.23456780e-") + digits );
466 }
467
468 {
469 ostringstream ostr;
470 ostr << fixed << setprecision(8) << setw(30) << setfill('0') << 0.12345678f;
471 CPPUNIT_ASSERT(ostr.good());
472 output = reset_stream(ostr);
473 CPPUNIT_CHECK(output == "000000000000000000000.12345678");
474 }
475
476 {
477 ostringstream ostr;
478 ostr << fixed << showpos << setprecision(8) << setw(30) << setfill('0') << 0.12345678f;
479 CPPUNIT_ASSERT(ostr.good());
480 output = reset_stream(ostr);
481 CPPUNIT_CHECK(output == "0000000000000000000+0.12345678");
482 }
483
484 {
485 ostringstream ostr;
486 ostr << fixed << showpos << setprecision(8) << setw(30) << left << setfill('0') << 0.12345678f;
487 CPPUNIT_ASSERT(ostr.good());
488 output = reset_stream(ostr);
489 CPPUNIT_CHECK(output == "+0.123456780000000000000000000");
490 }
491
492 {
493 ostringstream ostr;
494 ostr << fixed << showpos << setprecision(8) << setw(30) << internal << setfill('0') << 0.12345678f;
495 CPPUNIT_ASSERT(ostr.good());
496 output = reset_stream(ostr);
497 CPPUNIT_CHECK(output == "+00000000000000000000.12345678");
498 }
499
500 {
501 ostringstream ostr;
502 ostr << fixed << showpos << setprecision(100) << 1.234567e+17;
503 CPPUNIT_ASSERT(ostr.good());
504 output = reset_stream(ostr);
505 CPPUNIT_CHECK(output.size() == 120);
506 CPPUNIT_CHECK(output.substr(0, 6) == "+12345");
507 CPPUNIT_CHECK(output.substr(19) == ".0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" );
508 }
509
510#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE)
511 {
512 ostringstream ostr;
513 ostr << fixed << showpos << setprecision(100) << 1.234567e+17l;
514 CPPUNIT_ASSERT(ostr.good());
515 output = reset_stream(ostr);
516 CPPUNIT_CHECK(output.size() == 120);
517 CPPUNIT_CHECK(output.substr(0, 6) == "+12345");
518 CPPUNIT_CHECK(output.substr(19) == ".0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" );
519 }
520#endif
521
522 {
523 ostringstream ostr;
524 ostr << scientific << setprecision(50) << 0.0;
525 CPPUNIT_ASSERT(ostr.good());
526 output = reset_stream(ostr);
527 CPPUNIT_CHECK( output == "0.00000000000000000000000000000000000000000000000000e+00" );
528 }
529 {
530 ostringstream ostr;
531 ostr << fixed << setprecision(100) << numeric_limits<float>::max();
532 CPPUNIT_ASSERT(ostr.good());
533 output = reset_stream(ostr);
534 //CPPUNIT_MESSAGE( output.c_str() );
535 }
536
537 {
538 ostringstream ostr;
540 CPPUNIT_ASSERT(ostr.good());
541 output = reset_stream(ostr);
542 //CPPUNIT_MESSAGE( output.c_str() );
543 }
544
545#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE)
546 {
547 ostringstream ostr;
549 CPPUNIT_ASSERT(ostr.good());
550 output = reset_stream(ostr);
551 //CPPUNIT_MESSAGE( output.c_str() );
552 }
553#endif
554
555 //{
556 // ostringstream ostr;
557 // ostr << setprecision(-numeric_limits<float>::min_exponent10 + numeric_limits<float>::digits10 + 9) << numeric_limits<float>::min();
558 // CPPUNIT_ASSERT(ostr.good());
559 // output = reset_stream(ostr);
560 // //CPPUNIT_MESSAGE( output.c_str() );
561 //}
562
563 //{
564 // ostringstream ostr;
565 // ostr << setprecision(-numeric_limits<double>::min_exponent10 + numeric_limits<double>::digits10) << numeric_limits<double>::min();
566 // CPPUNIT_ASSERT(ostr.good());
567 // output = reset_stream(ostr);
568 // //CPPUNIT_MESSAGE( output.c_str() );
569 //}
570
571//#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE)
572// {
573// ostringstream ostr;
574// ostr << setprecision(-numeric_limits<long double>::min_exponent10 + numeric_limits<long double>::digits10) << numeric_limits<long double>::min();
575// CPPUNIT_ASSERT(ostr.good());
576// output = reset_stream(ostr);
577// CPPUNIT_MESSAGE( output.c_str() );
578// }
579//#endif
580 }
581
582 {
584
585 str.setf(ios::fixed, ios::floatfield);
586 str << 1.0e+5;
587 // cerr << str.str() << endl;
588 CPPUNIT_CHECK( str.str() == "100000.000000" );
589
591 str.precision(0);
592 str << 1.0e+5;
593 CPPUNIT_CHECK( str.str() == "100000" );
594
596 str.precision(4);
597 str << 1.0e+5;
598 CPPUNIT_CHECK( str.str() == "100000.0000" );
599
601 str.precision(0);
602 str << 1.0e+83;
603 CPPUNIT_CHECK( str.str().size() == 84 );
604 //printf("\nC result: %.0f\n", 1.0e+83);
605 //CPPUNIT_MESSAGE( str.str().c_str() );
606 //CPPUNIT_CHECK( str.str() == "100000000000000000000000000000000000000000000000000000000000000000000000000000000000" );
607
608 // cerr.setf(ios::fixed, ios::floatfield);
609 // cerr << DBL_MAX << endl;
610 // cerr << 1.0e+37 << endl;
611 }
612}
_STLP_PRIV _Setfill_Manip< _CharT > _STLP_CALL setfill(_CharT __c)
Definition: _iomanip.h:160
ios_base &_STLP_CALL internal(ios_base &__s)
Definition: _ios_base.h:311
ios_base &_STLP_CALL showpos(ios_base &__s)
Definition: _ios_base.h:285
_Self substr(size_type __pos=0, size_type __n=npos) const
Definition: _string.h:1022
size_type size() const
Definition: _string.h:400
bool good() const
Definition: _ios_base.h:172
void complete_digits(std::string &digits)
GLint left
Definition: glext.h:7726
static const int digits[]
Definition: decode.c:71

◆ num_put_integer()

void NumPutGetTest::num_put_integer ( )
private

Definition at line 625 of file num_put_get_test.cpp.

626{
627 //octal outputs
628 {
629 CHECK(short, 0, oct, "0")
630 CHECK(short, 1, oct, "1")
631 CHECK(short, 12345, oct, "30071")
632 if (sizeof(short) == 2) {
633 CHECK(short, -1, oct, "177777")
634 CHECK(short, -12345, oct, "147707")
635 }
636
637 CHECK(unsigned short, 0, oct, "0")
638 CHECK(unsigned short, 12345, oct, "30071")
639
640 CHECK(int, 0, oct, "0")
641 CHECK(int, 12345678, oct, "57060516")
642 if (sizeof(int) == 4) {
643 CHECK(int, -1, oct, "37777777777")
644 CHECK(int, -12345678, oct, "37720717262")
645 }
646
647 CHECK(unsigned int, 0, oct, "0")
648 CHECK(unsigned int, 12345678, oct, "57060516")
649
650 CHECK(long, 0, oct, "0")
651 CHECK(long, 12345678, oct, "57060516")
652 if (sizeof(long) == 4) {
653 CHECK(long, -1, oct, "37777777777")
654 CHECK(long, -12345678, oct, "37720717262")
655 }
656
657 CHECK(unsigned long, 0, oct, "0")
658 CHECK(unsigned long, 12345678, oct, "57060516")
659
660#if defined (STLPORT) && defined (_STLP_LONG_LONG)
661 CHECK(_STLP_LONG_LONG, 0, oct, "0")
662 CHECK(_STLP_LONG_LONG, 12345678, oct, "57060516")
663 if (sizeof(_STLP_LONG_LONG) == 8) {
664 CHECK(_STLP_LONG_LONG, -1, oct, "1777777777777777777777")
665 CHECK(_STLP_LONG_LONG, -12345678, oct, "1777777777777720717262")
666 }
667
668 CHECK(unsigned _STLP_LONG_LONG, 0, oct, "0")
669 CHECK(unsigned _STLP_LONG_LONG, 12345678, oct, "57060516")
670#endif
671
672 //Even with showbase, 0 value gives "0" (see printf documentation)
674 CHECK_COMPLETE(short, 0, oct, showbase, showpos, nouppercase, 6, right, " 0")
675
676 CHECK_COMPLETE(short, 1, oct, showbase, noshowpos, nouppercase, 6, right, " 01")
677 CHECK_COMPLETE(short, 1, oct, showbase, noshowpos, nouppercase, 6, left, "01 ")
678 CHECK_COMPLETE(short, 1, oct, showbase, showpos, nouppercase, 6, internal, " 01")
679 }
680
681 //decimal outputs
682 {
683 CHECK(short, 0, dec, "0")
684 CHECK(short, -1, dec, "-1")
685 CHECK(short, 12345, dec, "12345")
686 CHECK(short, -12345, dec, "-12345")
687
688 CHECK(unsigned short, 0, dec, "0")
689 CHECK(unsigned short, 12345, dec, "12345")
690
691 CHECK(int, 0, dec, "0")
692 CHECK(int, -1, dec, "-1")
693 CHECK(int, 12345678, dec, "12345678")
694 CHECK(int, -12345678, dec, "-12345678")
695
696 CHECK(unsigned int, 0, dec, "0")
697 CHECK(unsigned int, 12345678, dec, "12345678")
698
699 CHECK(long, 0, dec, "0")
700 CHECK(long, -1, dec, "-1")
701 CHECK(long, 12345678, dec, "12345678")
702 CHECK(long, -12345678, dec, "-12345678")
703
704 CHECK(unsigned long, 0, dec, "0")
705 CHECK(unsigned long, 12345678, dec, "12345678")
706#if defined (STLPORT) && defined (_STLP_LONG_LONG)
707 CHECK(_STLP_LONG_LONG, 0, dec, "0")
708 CHECK(_STLP_LONG_LONG, -1, dec, "-1")
709 CHECK(_STLP_LONG_LONG, 12345678, dec, "12345678")
710 CHECK(_STLP_LONG_LONG, -12345678, dec, "-12345678")
711
712 CHECK(unsigned _STLP_LONG_LONG, 0, dec, "0")
713 CHECK(unsigned _STLP_LONG_LONG, 12345678, dec, "12345678")
714#endif
715
716 CHECK_COMPLETE(short, 0, dec, showbase, showpos, nouppercase, 0, right, "+0")
717 CHECK_COMPLETE(short, 0, dec, showbase, showpos, nouppercase, 6, right, " +0")
718 CHECK_COMPLETE(short, 1, dec, showbase, showpos, nouppercase, 6, right, " +1")
719 CHECK_COMPLETE(short, 1, dec, showbase, showpos, nouppercase, 6, left, "+1 ")
720 CHECK_COMPLETE(short, 1, dec, showbase, showpos, nouppercase, 6, internal, "+ 1")
721 }
722
723 //hexadecimal outputs
724 {
725 CHECK(short, 0, hex, "0")
726 CHECK(short, 12345, hex, "3039")
727 if (sizeof(short) == 2) {
728 CHECK(short, -1, hex, "ffff")
729 CHECK(short, -12345, hex, "cfc7")
730 }
731
732 CHECK(unsigned short, 0, hex, "0")
733 CHECK(unsigned short, 12345, hex, "3039")
734
735 CHECK(int, 0, hex, "0")
736 CHECK(int, 12345678, hex, "bc614e")
737 if (sizeof(int) == 4) {
738 CHECK(int, -1, hex, "ffffffff")
739 CHECK(int, -12345678, hex, "ff439eb2")
740 }
741
742 CHECK(unsigned int, 0, hex, "0")
743 CHECK(unsigned int, 12345678, hex, "bc614e")
744
745 CHECK(long, 0, hex, "0")
746 CHECK(long, 12345678, hex, "bc614e")
747 if (sizeof(long) == 4) {
748 CHECK(long, -1, hex, "ffffffff")
749 CHECK(long, -12345678, hex, "ff439eb2")
750 }
751
752 CHECK(unsigned long, 0, hex, "0")
753 CHECK(unsigned long, 12345678, hex, "bc614e")
754#if defined (STLPORT) && defined (_STLP_LONG_LONG)
755 CHECK(_STLP_LONG_LONG, 0, hex, "0")
756 CHECK(_STLP_LONG_LONG, 12345678, hex, "bc614e")
757 if (sizeof(_STLP_LONG_LONG) == 8) {
758 CHECK(_STLP_LONG_LONG, -1, hex, "ffffffffffffffff")
759 CHECK(_STLP_LONG_LONG, -12345678, hex, "ffffffffff439eb2")
760 }
761
762 CHECK(unsigned _STLP_LONG_LONG, 0, hex, "0")
763 CHECK(unsigned _STLP_LONG_LONG, 12345678, hex, "bc614e")
764#endif
765
766 //Even with showbase, 0 value gives "0" output (see printf documentation)
767 CHECK_COMPLETE(short, 0, hex, showbase, showpos, nouppercase, 0, right, "0")
768 CHECK_COMPLETE(short, 0, hex, showbase, noshowpos, nouppercase, 6, right, " 0")
769 CHECK_COMPLETE(short, 0, hex, showbase, noshowpos, nouppercase, 6, internal, " 0")
770
771 CHECK_COMPLETE(short, 1, hex, showbase, noshowpos, nouppercase, 6, right, " 0x1")
772 CHECK_COMPLETE(short, 1, hex, showbase, noshowpos, nouppercase, 6, left, "0x1 ")
773 CHECK_COMPLETE(short, 1, hex, showbase, noshowpos, nouppercase, 6, internal, "0x 1")
774 CHECK_COMPLETE(short, 1, hex, showbase, noshowpos, uppercase, 6, left, "0X1 ")
775 CHECK_COMPLETE(short, 1, hex, showbase, showpos, uppercase, 6, internal, "0X 1")
776 }
777}
#define _STLP_LONG_LONG
Definition: _apcc.h:12
ios_base &_STLP_CALL nouppercase(ios_base &__s)
Definition: _ios_base.h:300
ios_base &_STLP_CALL dec(ios_base &__s)
Definition: _ios_base.h:321
ios_base &_STLP_CALL noshowpos(ios_base &__s)
Definition: _ios_base.h:288
ios_base &_STLP_CALL uppercase(ios_base &__s)
Definition: _ios_base.h:297
GLdouble GLdouble right
Definition: glext.h:10859
if(dx< 0)
Definition: linetemp.h:194
#define CHECK(type, val, base, expected)
#define CHECK_COMPLETE(type, val, base, showbase, showpos, casing, width, adjust, expected)
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3708
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

◆ pointer()

void NumPutGetTest::pointer ( )
private

Definition at line 1051 of file num_put_get_test.cpp.

1052{
1053 // Problem with printing pointer to null
1054
1055 /*
1056 * Really C's formatting not help here, due to:
1057 *
1058 * p The argument shall be a pointer to void. The value of
1059 * the pointer is converted to a sequence of printable characters,
1060 * in an implementation-defined manner.
1061 */
1062 {
1063 /*
1064 char buf[128];
1065 void *p = (void *)0xff00;
1066 sprintf( buf, "%p", p );
1067 // cerr << buf << endl;
1068 // Hmmm, I see 0xff00 on box with 32-bits address; pointer like 'unsigned hex'?
1069 if ( sizeof( p ) == 2 ) {
1070 CPPUNIT_ASSERT( strcmp( buf, "0xff00" ) == 0 );
1071 } else if ( sizeof( p ) == 4 ) {
1072 CPPUNIT_ASSERT( strcmp( buf, "0x0000ff00" ) == 0 );
1073 } else if ( sizeof( p ) == 8 ) {
1074 CPPUNIT_ASSERT( strcmp( buf, "0x000000000000ff00" ) == 0 );
1075 } else {
1076 CPPUNIT_CHECK( sizeof( p ) == 2 || sizeof( p ) == 4 || sizeof( p ) == 8 );
1077 }
1078 */
1079 }
1080 {
1081 /*
1082 char buf[128];
1083 void *p = 0;
1084 */
1085 // sprintf( buf, "%p", p );
1086 /* Cool. "%p" print '(nil)'; "%#x" print '0' */
1087 // sprintf( buf, "%#x", (unsigned)p );
1088 // cerr << buf << endl;
1089 }
1090 {
1092 void *p = (void *)0xff00;
1093 s << p;
1094 CPPUNIT_ASSERT( s.good() );
1095 if ( sizeof( p ) == 2 ) {
1096 CPPUNIT_ASSERT( s.str() == "0xff00" );
1097 } else if ( sizeof( p ) == 4 ) {
1098 CPPUNIT_ASSERT( s.str() == "0x0000ff00" ); // this pass
1099 } else if ( sizeof( p ) == 8 ) {
1100 CPPUNIT_ASSERT( s.str() == "0x000000000000ff00" );
1101 } else {
1102 CPPUNIT_CHECK( sizeof( p ) == 2 || sizeof( p ) == 4 || sizeof( p ) == 8 );
1103 }
1104 }
1105 {
1107 void *p = 0;
1108 s << p;
1109 CPPUNIT_ASSERT( s.good() );
1110 if ( sizeof( p ) == 2 ) {
1111 CPPUNIT_ASSERT( s.str() == "0x0000" );
1112 } else if ( sizeof( p ) == 4 ) {
1113 CPPUNIT_ASSERT( s.str() == "0x00000000" ); // but this will fail, if follow %p
1114 } else if ( sizeof( p ) == 8 ) {
1115 CPPUNIT_ASSERT( s.str() == "0x0000000000000000" );
1116 } else {
1117 CPPUNIT_CHECK( sizeof( p ) == 2 || sizeof( p ) == 4 || sizeof( p ) == 8 );
1118 }
1119 }
1120}

◆ reset_stream()

static string NumPutGetTest::reset_stream ( ostringstream ostr)
inlinestaticprivate

Definition at line 68 of file num_put_get_test.cpp.

69 {
70 string tmp = ostr.str();
71 ostr.str("");
72 return tmp;
73 }
_String str() const
Definition: _sstream.h:184

Referenced by fix_float_long(), and num_put_float().


The documentation for this class was generated from the following file: