debug_assert.h: new file

2000-08-14  Brent Verner <brent@rcfile.org>

	* testsuite/debug_assert.h: new file
	* testsuite/*/*.cc: s/test\s*&=([^;]+);/VERIFY($1);/g
	changed conditional #include <c?assert.?h?> to
	unconditional #include <debug_assert.h>
	* mkcheck.in: added $SRC_DIR/testsuite to include search path
	for testsuite compile command.

From-SVN: r35682
This commit is contained in:
Brent Verner 2000-08-14 19:59:26 +00:00 committed by Benjamin Kosnik
parent 5312a1d9d1
commit aa1b2f7d95
71 changed files with 1662 additions and 1700 deletions

View File

@ -1,3 +1,12 @@
2000-08-14 Brent Verner <brent@rcfile.org>
* testsuite/debug_assert.h: new file
* testsuite/*/*.cc: s/test\s*&=([^;]+);/VERIFY($1);/g
changed conditional #include <c?assert.?h?> to
unconditional #include <debug_assert.h>
* mkcheck.in: added $SRC_DIR/testsuite to include search path
for testsuite compile command.
2000-08-14 Levente Farkas <lfarkas@mindmaker.hu> 2000-08-14 Levente Farkas <lfarkas@mindmaker.hu>
* bits/std_fstream.h: Remove duplicate typdefs for ofstream and * bits/std_fstream.h: Remove duplicate typdefs for ofstream and

View File

@ -55,7 +55,7 @@ fi
# INC_PATH == include path to new headers for use on gcc command-line # INC_PATH == include path to new headers for use on gcc command-line
if [ $WHICH != "1" ]; then if [ $WHICH != "1" ]; then
INC_PATH="@CSHADOWFLAGS@ -I$BUILD_DIR -I$BUILD_DIR/libio -I$SRC_DIR/@ctype_include_dir@ -I$SRC_DIR/@cpu_include_dir@ -I$SRC_DIR/std -I$SRC_DIR -I$SRC_DIR/libio" INC_PATH="@CSHADOWFLAGS@ -I$BUILD_DIR -I$BUILD_DIR/libio -I$SRC_DIR/@ctype_include_dir@ -I$SRC_DIR/@cpu_include_dir@ -I$SRC_DIR/std -I$SRC_DIR -I$SRC_DIR/libio -I$SRC_DIR/testsuite"
elif [ $WHICH -eq 1 ]; then elif [ $WHICH -eq 1 ]; then
INC_PATH="" INC_PATH=""
fi fi

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, ciso646 // 17.4.1.2 Headers, ciso646
#include <ciso646> #include <ciso646>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
// 2.11 Keywords // 2.11 Keywords
@ -104,11 +102,11 @@ bool test02()
int int1 = 45; int int1 = 45;
int int2 = 0; int int2 = 0;
test &= arg1 && int1; VERIFY( arg1 && int1 );
test &= arg1 and int1; VERIFY( arg1 and int1 );
test &= (arg1 && arg2) == (arg1 and arg2); VERIFY( (arg1 && arg2) == (arg1 and arg2) );
test &= (arg1 && int1) == (arg1 and int1); VERIFY( (arg1 && int1) == (arg1 and int1) );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, fstream // 17.4.1.2 Headers, fstream
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int main(void) int main(void)

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, iomanip // 17.4.1.2 Headers, iomanip
#include <iomanip> #include <iomanip>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int main(void) int main(void)

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, ios // 17.4.1.2 Headers, ios
#include <ios> #include <ios>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int main(void) int main(void)

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, iosfwd // 17.4.1.2 Headers, iosfwd
#include <iosfwd> #include <iosfwd>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int main(void) int main(void)

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, iostream // 17.4.1.2 Headers, iostream
#include <iostream> #include <iostream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int main(void) int main(void)

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, istream // 17.4.1.2 Headers, istream
#include <istream> #include <istream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int main(void) int main(void)

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, ostream // 17.4.1.2 Headers, ostream
#include <ostream> #include <ostream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int main(void) int main(void)

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, sstream // 17.4.1.2 Headers, sstream
#include <sstream> #include <sstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int main(void) int main(void)

View File

@ -21,9 +21,7 @@
// 17.4.1.2 Headers, streambuf // 17.4.1.2 Headers, streambuf
#include <streambuf> #include <streambuf>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int main(void) int main(void)

View File

@ -21,9 +21,7 @@
// 18.2.1.1 template class numeric_limits // 18.2.1.1 template class numeric_limits
#include <limits> #include <limits>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
template<typename T> template<typename T>
@ -44,36 +42,36 @@ bool test01()
bool test = true; bool test = true;
std::numeric_limits< A<B> > obj; std::numeric_limits< A<B> > obj;
test &= !obj.is_specialized; VERIFY( !obj.is_specialized );
test &= obj.min() == 0; VERIFY( obj.min() == 0 );
test &= obj.max() == 0; VERIFY( obj.max() == 0 );
test &= obj.digits == 0; VERIFY( obj.digits == 0 );
test &= obj.digits10 == 0; VERIFY( obj.digits10 == 0 );
test &= !obj.is_signed; VERIFY( !obj.is_signed );
test &= !obj.is_integer; VERIFY( !obj.is_integer );
test &= !obj.is_exact; VERIFY( !obj.is_exact );
test &= obj.radix == 0; VERIFY( obj.radix == 0 );
test &= obj.epsilon() == 0; VERIFY( obj.epsilon() == 0 );
test &= obj.round_error() == 0; VERIFY( obj.round_error() == 0 );
test &= obj.min_exponent == 0; VERIFY( obj.min_exponent == 0 );
test &= obj.min_exponent10 == 0; VERIFY( obj.min_exponent10 == 0 );
test &= obj.max_exponent == 0; VERIFY( obj.max_exponent == 0 );
test &= obj.max_exponent10 == 0; VERIFY( obj.max_exponent10 == 0 );
test &= !obj.has_infinity; VERIFY( !obj.has_infinity );
test &= !obj.has_quiet_NaN; VERIFY( !obj.has_quiet_NaN );
test &= !obj.has_signaling_NaN; VERIFY( !obj.has_signaling_NaN );
test &= !obj.has_denorm; VERIFY( !obj.has_denorm );
test &= !obj.has_denorm_loss; VERIFY( !obj.has_denorm_loss );
test &= obj.infinity() == 0; VERIFY( obj.infinity() == 0 );
test &= obj.quiet_NaN() == 0; VERIFY( obj.quiet_NaN() == 0 );
test &= obj.signaling_NaN() == 0; VERIFY( obj.signaling_NaN() == 0 );
test &= obj.denorm_min() == 0; VERIFY( obj.denorm_min() == 0 );
test &= !obj.is_iec559; VERIFY( !obj.is_iec559 );
test &= !obj.is_bounded; VERIFY( !obj.is_bounded );
test &= !obj.is_modulo; VERIFY( !obj.is_modulo );
test &= !obj.traps; VERIFY( !obj.traps );
test &= !obj.tinyness_before; VERIFY( !obj.tinyness_before );
test &= obj.round_style == std::round_toward_zero; VERIFY( obj.round_style == std::round_toward_zero );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -19,10 +19,7 @@
// 20.4.5 Template class auto_ptr [lib.auto.ptr] // 20.4.5 Template class auto_ptr [lib.auto.ptr]
#include <memory> #include <memory>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
# include <assert.h>
#endif
struct A struct A
{ {
@ -60,41 +57,43 @@ struct reset_count_struct
// 20.4.5.1 auto_ptr constructors [lib.auto.ptr.cons] // 20.4.5.1 auto_ptr constructors [lib.auto.ptr.cons]
// Construction from pointer // Construction from pointer
bool test01() int
test01()
{ {
reset_count_struct reset; reset_count_struct reset;
bool test = true; bool test = true;
std::auto_ptr<A> A_default; std::auto_ptr<A> A_default;
test &= A_default.get() == 0; VERIFY( A_default.get() == 0 );
test &= A::ctor_count == 0; VERIFY( A::ctor_count == 0 );
test &= A::dtor_count == 0; VERIFY( A::dtor_count == 0 );
test &= B::ctor_count == 0; VERIFY( B::ctor_count == 0 );
test &= B::dtor_count == 0; VERIFY( B::dtor_count == 0 );
std::auto_ptr<A> A_from_A(new A); std::auto_ptr<A> A_from_A(new A);
test &= A_from_A.get() != 0; VERIFY( A_from_A.get() != 0 );
test &= A::ctor_count == 1; VERIFY( A::ctor_count == 1 );
test &= A::dtor_count == 0; VERIFY( A::dtor_count == 0 );
test &= B::ctor_count == 0; VERIFY( B::ctor_count == 0 );
test &= B::dtor_count == 0; VERIFY( B::dtor_count == 0 );
std::auto_ptr<A> A_from_B(new B); std::auto_ptr<A> A_from_B(new B);
test &= A_from_B.get() != 0; VERIFY( A_from_B.get() != 0 );
test &= A::ctor_count == 2; VERIFY( A::ctor_count == 2 );
test &= A::dtor_count == 0; VERIFY( A::dtor_count == 0 );
test &= B::ctor_count == 1; VERIFY( B::ctor_count == 1 );
test &= B::dtor_count == 0; VERIFY( B::dtor_count == 0 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
// Construction from std::auto_ptr // Construction from std::auto_ptr
bool test02() int
test02()
{ {
reset_count_struct reset; reset_count_struct reset;
bool test = true; bool test = true;
@ -104,24 +103,25 @@ bool test02()
std::auto_ptr<A> A_from_ptr_A(A_from_A); std::auto_ptr<A> A_from_ptr_A(A_from_A);
std::auto_ptr<A> A_from_ptr_B(B_from_B); std::auto_ptr<A> A_from_ptr_B(B_from_B);
test &= A_from_A.get() == 0; VERIFY( A_from_A.get() == 0 );
test &= B_from_B.get() == 0; VERIFY( B_from_B.get() == 0 );
test &= A_from_ptr_A.get() != 0; VERIFY( A_from_ptr_A.get() != 0 );
test &= A_from_ptr_B.get() != 0; VERIFY( A_from_ptr_B.get() != 0 );
test &= A::ctor_count == 2; VERIFY( A::ctor_count == 2 );
test &= A::dtor_count == 0; VERIFY( A::dtor_count == 0 );
test &= B::ctor_count == 1; VERIFY( B::ctor_count == 1 );
test &= B::dtor_count == 0; VERIFY( B::dtor_count == 0 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
// Assignment from std::auto_ptr // Assignment from std::auto_ptr
bool test03() int
test03()
{ {
reset_count_struct reset; reset_count_struct reset;
bool test = true; bool test = true;
@ -133,24 +133,25 @@ bool test03()
A_from_ptr_A = A_from_A; A_from_ptr_A = A_from_A;
A_from_ptr_B = B_from_B; A_from_ptr_B = B_from_B;
test &= A_from_A.get() == 0; VERIFY( A_from_A.get() == 0 );
test &= B_from_B.get() == 0; VERIFY( B_from_B.get() == 0 );
test &= A_from_ptr_A.get() != 0; VERIFY( A_from_ptr_A.get() != 0 );
test &= A_from_ptr_B.get() != 0; VERIFY( A_from_ptr_B.get() != 0 );
test &= A::ctor_count == 2; VERIFY( A::ctor_count == 2 );
test &= A::dtor_count == 0; VERIFY( A::dtor_count == 0 );
test &= B::ctor_count == 1; VERIFY( B::ctor_count == 1 );
test &= B::dtor_count == 0; VERIFY( B::dtor_count == 0 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
// Destruction // Destruction
bool test04() int
test04()
{ {
reset_count_struct reset; reset_count_struct reset;
bool test = true; bool test = true;
@ -161,16 +162,16 @@ bool test04()
std::auto_ptr<B> B_from_B(new B); std::auto_ptr<B> B_from_B(new B);
}/*destructors called here*/ }/*destructors called here*/
test &= A::ctor_count == 3; VERIFY( A::ctor_count == 3 );
test &= A::dtor_count == 3; VERIFY( A::dtor_count == 3 );
test &= B::ctor_count == 2; VERIFY( B::ctor_count == 2 );
test &= B::dtor_count == 2; VERIFY( B::dtor_count == 2 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
// Class member construction/destruction // Class member construction/destruction
@ -183,58 +184,60 @@ private:
std::auto_ptr<T> p_impl; std::auto_ptr<T> p_impl;
}; };
bool test05() int
test05()
{ {
bool test = true; bool test = true;
reset_count_struct reset; reset_count_struct reset;
pimpl<A>(); pimpl<A>();
pimpl<B>(); pimpl<B>();
test &= A::ctor_count == 2; VERIFY( A::ctor_count == 2 );
test &= A::dtor_count == 2; VERIFY( A::dtor_count == 2 );
test &= B::ctor_count == 1; VERIFY( B::ctor_count == 1 );
test &= B::dtor_count == 1; VERIFY( B::dtor_count == 1 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
// 20.4.5.2 auto_ptr members [lib.auto.ptr.members] // 20.4.5.2 auto_ptr members [lib.auto.ptr.members]
// Member access // Member access
bool test06() int
test06()
{ {
reset_count_struct reset; reset_count_struct reset;
bool test = true; bool test = true;
std::auto_ptr<A> A_from_A(new A); std::auto_ptr<A> A_from_A(new A);
std::auto_ptr<A> A_from_A_ptr(A_from_A.release()); std::auto_ptr<A> A_from_A_ptr(A_from_A.release());
test &= A_from_A.get() == 0; VERIFY( A_from_A.get() == 0 );
test &= A_from_A_ptr.get() != 0; VERIFY( A_from_A_ptr.get() != 0 );
test &= A_from_A->ctor_count == 1; VERIFY( A_from_A->ctor_count == 1 );
test &= (*A_from_A).dtor_count == 0; VERIFY( (*A_from_A).dtor_count == 0 );
A* A_ptr = A_from_A_ptr.get(); A* A_ptr = A_from_A_ptr.get();
A_from_A_ptr.reset(A_ptr); A_from_A_ptr.reset(A_ptr);
test &= A_from_A_ptr.get() == A_ptr; VERIFY( A_from_A_ptr.get() == A_ptr );
test &= A_from_A_ptr->ctor_count == 1; VERIFY( A_from_A_ptr->ctor_count == 1 );
test &= (*A_from_A_ptr).dtor_count == 0; VERIFY( (*A_from_A_ptr).dtor_count == 0 );
A_from_A_ptr.reset(new A); A_from_A_ptr.reset(new A);
test &= A_from_A_ptr.get() != A_ptr; VERIFY( A_from_A_ptr.get() != A_ptr );
test &= A_from_A_ptr->ctor_count == 2; VERIFY( A_from_A_ptr->ctor_count == 2 );
test &= (*A_from_A_ptr).dtor_count == 1; VERIFY( (*A_from_A_ptr).dtor_count == 1 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
@ -251,7 +254,8 @@ template <typename T>
static void drain(std::auto_ptr<T>) static void drain(std::auto_ptr<T>)
{} {}
bool test07() int
test07()
{ {
bool test = true; bool test = true;
reset_count_struct reset; reset_count_struct reset;
@ -259,30 +263,29 @@ bool test07()
drain(source<A>()); drain(source<A>());
drain<A>(source<B>()); drain<A>(source<B>());
drain(source<B>()); drain(source<B>());
test &= A::ctor_count == 3; VERIFY( A::ctor_count == 3 );
test &= A::dtor_count == 3; VERIFY( A::dtor_count == 3 );
test &= B::ctor_count == 2; VERIFY( B::ctor_count == 2 );
test &= B::dtor_count == 2; VERIFY( B::dtor_count == 2 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
int
int main() main()
{ {
bool test = true; test01();
test02();
test03();
test04();
test05();
test06();
test07();
test &= test01(); return 0;
test &= test02();
test &= test03();
test &= test04();
test &= test05();
test &= test06();
test &= test07();
return test ? 0 : 1;
} }

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -45,14 +43,14 @@ bool test01(void)
// string& append(const string&) // string& append(const string&)
str05 = str02; str05 = str02;
str05.append(str05); str05.append(str05);
test &= str05 == "corpus, corpus, "; VERIFY( str05 == "corpus, corpus, " );
str05.append(str01); str05.append(str01);
test &= str05 == "corpus, corpus, point bolivar, texas"; VERIFY( str05 == "corpus, corpus, point bolivar, texas" );
str05.append(str03); str05.append(str03);
test &= str05 == "corpus, corpus, point bolivar, texas"; VERIFY( str05 == "corpus, corpus, point bolivar, texas" );
std::string str06; std::string str06;
str06.append(str05); str06.append(str05);
test &= str06 == str05; VERIFY( str06 == str05 );
// string& append(const string&, size_type pos, size_type n) // string& append(const string&, size_type pos, size_type n)
@ -61,78 +59,78 @@ bool test01(void)
csz01 = str03.size(); csz01 = str03.size();
try { try {
str06.append(str03, csz01 + 1, 0); str06.append(str03, csz01 + 1, 0);
test &= false; VERIFY( false );
} }
catch(std::out_of_range& fail) { catch(std::out_of_range& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
csz01 = str01.size(); csz01 = str01.size();
try { try {
str06.append(str01, csz01 + 1, 0); str06.append(str01, csz01 + 1, 0);
test &= false; VERIFY( false );
} }
catch(std::out_of_range& fail) { catch(std::out_of_range& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
str05 = str02; str05 = str02;
str05.append(str01, 0, std::string::npos); str05.append(str01, 0, std::string::npos);
test &= str05 == "corpus, point bolivar, texas"; VERIFY( str05 == "corpus, point bolivar, texas" );
test &= str05 != str02; VERIFY( str05 != str02 );
str06 = str02; str06 = str02;
str06.append(str01, 15, std::string::npos); str06.append(str01, 15, std::string::npos);
test &= str06 == "corpus, texas"; VERIFY( str06 == "corpus, texas" );
test &= str02 != str06; VERIFY( str02 != str06 );
// string& append(const char* s) // string& append(const char* s)
str05.erase(); str05.erase();
str06.erase(); str06.erase();
str05.append(""); str05.append("");
test &= str05 == str03; VERIFY( str05 == str03 );
str05.append(str_lit01); str05.append(str_lit01);
test &= str05 == str01; VERIFY( str05 == str01 );
str06 = str02; str06 = str02;
str06.append("corpus, "); str06.append("corpus, ");
test &= str06 == "corpus, corpus, "; VERIFY( str06 == "corpus, corpus, " );
// string& append(const char* s, size_type n) // string& append(const char* s, size_type n)
str05.erase(); str05.erase();
str06.erase(); str06.erase();
str05.append("", 0); str05.append("", 0);
test &= str05.size() == 0; VERIFY( str05.size() == 0 );
test &= str05 == str03; VERIFY( str05 == str03 );
str05.append(str_lit01, sizeof(str_lit01) - 1); str05.append(str_lit01, sizeof(str_lit01) - 1);
test &= str05 == str01; VERIFY( str05 == str01 );
str06 = str02; str06 = str02;
str06.append("corpus, ", 6); str06.append("corpus, ", 6);
test &= str06 == "corpus, corpus"; VERIFY( str06 == "corpus, corpus" );
str06 = str02; str06 = str02;
str06.append("corpus, ", 12); str06.append("corpus, ", 12);
test &= str06 != "corpus, corpus, "; VERIFY( str06 != "corpus, corpus, " );
// string& append(size_type n, char c) // string& append(size_type n, char c)
str05.erase(); str05.erase();
str06.erase(); str06.erase();
str05.append(0, 'a'); str05.append(0, 'a');
test &= str05 == str03; VERIFY( str05 == str03 );
str06.append(8, '.'); str06.append(8, '.');
test &= str06 == "........"; VERIFY( str06 == "........" );
// template<typename InputIter> // template<typename InputIter>
@ -140,18 +138,18 @@ bool test01(void)
str05.erase(); str05.erase();
str06.erase(); str06.erase();
str05.append(str03.begin(), str03.end()); str05.append(str03.begin(), str03.end());
test &= str05 == str03; VERIFY( str05 == str03 );
str06 = str02; str06 = str02;
str06.append(str01.begin(), str01.begin() + str01.find('r')); str06.append(str01.begin(), str01.begin() + str01.find('r'));
test &= str06 == "corpus, point boliva"; VERIFY( str06 == "corpus, point boliva" );
test &= str06 != str01; VERIFY( str06 != str01 );
test &= str06 != str02; VERIFY( str06 != str02 );
str05 = str01; str05 = str01;
str05.append(str05.begin(), str05.begin() + str05.find('r')); str05.append(str05.begin(), str05.begin() + str05.find('r'));
test &= str05 == "point bolivar, texaspoint boliva"; VERIFY( str05 == "point bolivar, texaspoint boliva" );
test &= str05 != str01; VERIFY( str05 != str01 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <cstdio> #include <cstdio>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
template<typename T> template<typename T>
struct A { }; struct A { };
@ -49,27 +47,27 @@ bool test01()
size_type_s sz01 = str01.capacity(); size_type_s sz01 = str01.capacity();
str01.reserve(100); str01.reserve(100);
size_type_s sz02 = str01.capacity(); size_type_s sz02 = str01.capacity();
test &= sz02 >= sz01; VERIFY( sz02 >= sz01 );
test &= sz02 >= 100; VERIFY( sz02 >= 100 );
str01.reserve(); str01.reserve();
sz01 = str01.capacity(); sz01 = str01.capacity();
test &= sz01 >= 0; VERIFY( sz01 >= 0 );
sz01 = str01.size() + 5; sz01 = str01.size() + 5;
str01.resize(sz01); str01.resize(sz01);
sz02 = str01.size(); sz02 = str01.size();
test &= sz01 == sz02; VERIFY( sz01 == sz02 );
sz01 = str01.size() - 5; sz01 = str01.size() - 5;
str01.resize(sz01); str01.resize(sz01);
sz02 = str01.size(); sz02 = str01.size();
test &= sz01 == sz02; VERIFY( sz01 == sz02 );
std::string str05(30, 'q'); std::string str05(30, 'q');
std::string str06 = str05; std::string str06 = str05;
str05 = str06 + str05; str05 = str06 + str05;
test &= str05.capacity() >= str05.size(); VERIFY( str05.capacity() >= str05.size() );
test &= str06.capacity() >= str06.size(); VERIFY( str06.capacity() >= str06.size() );
// 2 non POD types : resize, capacity, reserve // 2 non POD types : resize, capacity, reserve
std::basic_string< A<B> > str02; std::basic_string< A<B> > str02;
@ -80,50 +78,50 @@ bool test01()
sz03 = str02.capacity(); sz03 = str02.capacity();
str02.reserve(100); str02.reserve(100);
sz04 = str02.capacity(); sz04 = str02.capacity();
test &= sz04 >= sz03; VERIFY( sz04 >= sz03 );
test &= sz04 >= 100; VERIFY( sz04 >= 100 );
str02.reserve(); str02.reserve();
sz03 = str02.capacity(); sz03 = str02.capacity();
test &= sz03 >= 0; VERIFY( sz03 >= 0 );
sz03 = str02.size() + 5; sz03 = str02.size() + 5;
str02.resize(sz03); str02.resize(sz03);
sz04 = str02.size(); sz04 = str02.size();
test &= sz03 == sz04; VERIFY( sz03 == sz04 );
sz03 = str02.size() - 5; sz03 = str02.size() - 5;
str02.resize(sz03); str02.resize(sz03);
sz04 = str02.size(); sz04 = str02.size();
test &= sz03 == sz04; VERIFY( sz03 == sz04 );
A<B> inst_obj; A<B> inst_obj;
std::basic_string<A<B> > str07(30, inst_obj); std::basic_string<A<B> > str07(30, inst_obj);
std::basic_string<A<B> > str08 = str07; std::basic_string<A<B> > str08 = str07;
str07 = str08 + str07; str07 = str08 + str07;
test &= str07.capacity() >= str07.size(); VERIFY( str07.capacity() >= str07.size() );
test &= str08.capacity() >= str08.size(); VERIFY( str08.capacity() >= str08.size() );
// 3 POD types: size, length, max_size, clear(), empty() // 3 POD types: size, length, max_size, clear(), empty()
bool b01; bool b01;
std::string str011; std::string str011;
b01 = str01.empty(); b01 = str01.empty();
test &= b01 == true; VERIFY( b01 == true );
sz01 = str01.size(); sz01 = str01.size();
sz02 = str01.length(); sz02 = str01.length();
test &= sz01 == sz02; VERIFY( sz01 == sz02 );
str01.c_str(); str01.c_str();
sz01 = str01.size(); sz01 = str01.size();
sz02 = str01.length(); sz02 = str01.length();
test &= sz01 == sz02; VERIFY( sz01 == sz02 );
sz01 = str01.length(); sz01 = str01.length();
str01.c_str(); str01.c_str();
str011 = str01 + "_addendum_"; str011 = str01 + "_addendum_";
str01.c_str(); str01.c_str();
sz02 = str01.length(); sz02 = str01.length();
test &= sz01 == sz02; VERIFY( sz01 == sz02 );
sz02 = str011.length(); sz02 = str011.length();
test &= sz02 > sz01; VERIFY( sz02 > sz01 );
// trickster allocator (__USE_MALLOC, luke) issues involved with these: // trickster allocator (__USE_MALLOC, luke) issues involved with these:
std::string str3 = "8-chars_8-chars_"; std::string str3 = "8-chars_8-chars_";
@ -133,36 +131,36 @@ bool test01()
sz01 = str01.size(); sz01 = str01.size();
sz02 = str01.max_size(); sz02 = str01.max_size();
test &= sz02 >= sz01; VERIFY( sz02 >= sz01 );
sz01 = str01.size(); sz01 = str01.size();
str01.clear(); str01.clear();
b01 = str01.empty(); b01 = str01.empty();
test &= b01 == true; VERIFY( b01 == true );
sz02 = str01.size(); sz02 = str01.size();
test &= sz01 >= sz02; VERIFY( sz01 >= sz02 );
// 4 non-POD types: size, length, max_size, clear(), empty() // 4 non-POD types: size, length, max_size, clear(), empty()
b01 = str02.empty(); b01 = str02.empty();
test &= b01 == true; VERIFY( b01 == true );
sz03 = str02.size(); sz03 = str02.size();
sz04 = str02.length(); sz04 = str02.length();
test &= sz03 == sz04; VERIFY( sz03 == sz04 );
str02.c_str(); str02.c_str();
sz03 = str02.size(); sz03 = str02.size();
sz04 = str02.length(); sz04 = str02.length();
test &= sz03 == sz04; VERIFY( sz03 == sz04 );
sz03 = str02.max_size(); sz03 = str02.max_size();
test &= sz03 >= sz04; VERIFY( sz03 >= sz04 );
sz03 = str02.size(); sz03 = str02.size();
str02.clear(); str02.clear();
b01 = str02.empty(); b01 = str02.empty();
test &= b01 == true; VERIFY( b01 == true );
sz04 = str02.size(); sz04 = str02.size();
test &= sz03 >= sz04; VERIFY( sz03 >= sz04 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -21,9 +21,7 @@
// 21.1 Characher traits // 21.1 Characher traits
#include <string> #include <string>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int test01(void) int test01(void)
{ {
@ -47,9 +45,9 @@ int test01(void)
// assigns c = d; // assigns c = d;
char c1 = 'z'; char c1 = 'z';
char c2 = 'u'; char c2 = 'u';
test &= c1 != c2; VERIFY( c1 != c2 );
std::char_traits<char>::assign(c1,c2); std::char_traits<char>::assign(c1,c2);
test &= c1 == 'u'; VERIFY( c1 == 'u' );
// char* X::move(char* s, const char* p, size_t n) // char* X::move(char* s, const char* p, size_t n)
// for each i in [0,n) performs X::assign(s[i], p[i]). Copies // for each i in [0,n) performs X::assign(s[i], p[i]). Copies
@ -59,35 +57,35 @@ int test01(void)
int len = sizeof(str_lit1) + sizeof(array1) - 1; // two terminating chars int len = sizeof(str_lit1) + sizeof(array1) - 1; // two terminating chars
char array2[len]; char array2[len];
test &= str_lit1[0] == 'm'; VERIFY( str_lit1[0] == 'm' );
c1 = array2[0]; c1 = array2[0];
c2 = str_lit1[0]; c2 = str_lit1[0];
char c3 = array2[1]; char c3 = array2[1];
char c4 = str_lit1[1]; char c4 = str_lit1[1];
std::char_traits<char>::move(array2, str_lit1, 0); std::char_traits<char>::move(array2, str_lit1, 0);
test &= array2[0] == c1; VERIFY( array2[0] == c1 );
test &= str_lit1[0] == c2; VERIFY( str_lit1[0] == c2 );
std::char_traits<char>::move(array2, str_lit1, 1); std::char_traits<char>::move(array2, str_lit1, 1);
test &= array2[0] == c2; VERIFY( array2[0] == c2 );
test &= str_lit1[0] == c2; VERIFY( str_lit1[0] == c2 );
test &= array2[1] == c3; VERIFY( array2[1] == c3 );
test &= str_lit1[1] == c4; VERIFY( str_lit1[1] == c4 );
std::char_traits<char>::move(array2, str_lit1, 2); std::char_traits<char>::move(array2, str_lit1, 2);
test &= array2[0] == c2; VERIFY( array2[0] == c2 );
test &= str_lit1[0] == c2; VERIFY( str_lit1[0] == c2 );
test &= array2[1] == c4; VERIFY( array2[1] == c4 );
test &= str_lit1[1] == c4; VERIFY( str_lit1[1] == c4 );
char* pc1 = array1 + 1; char* pc1 = array1 + 1;
c1 = pc1[0]; c1 = pc1[0];
c2 = array1[0]; c2 = array1[0];
test &= c1 != c2; VERIFY( c1 != c2 );
char* pc2 = std::char_traits<char>::move(array1, pc1, 0); char* pc2 = std::char_traits<char>::move(array1, pc1, 0);
c3 = pc1[0]; c3 = pc1[0];
c4 = array1[0]; c4 = array1[0];
test &= c1 == c3; VERIFY( c1 == c3 );
test &= c2 == c4; VERIFY( c2 == c4 );
test &= pc2 == array1; VERIFY( pc2 == array1 );
c1 = pc1[0]; c1 = pc1[0];
c2 = array1[0]; c2 = array1[0];
@ -95,13 +93,13 @@ int test01(void)
pc2 = std::char_traits<char>::move(array1, pc1, 10); pc2 = std::char_traits<char>::move(array1, pc1, 10);
c3 = pc1[0]; c3 = pc1[0];
c4 = array1[0]; c4 = array1[0];
test &= c1 != c3; // underlying char array changed. VERIFY( c1 != c3 ); // underlying char array changed.
test &= c4 != c3; VERIFY( c4 != c3 );
test &= pc2 == array1; VERIFY( pc2 == array1 );
test &= pc3 == pc1; // but pointers o-tay VERIFY( pc3 == pc1 ); // but pointers o-tay
c1 = *(str_01.data()); c1 = *(str_01.data());
c2 = array1[0]; c2 = array1[0];
test &= c1 != c2; VERIFY( c1 != c2 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -132,9 +130,9 @@ int test02(void)
// assigns c = d; // assigns c = d;
wchar_t c1 = L'z'; wchar_t c1 = L'z';
wchar_t c2 = L'u'; wchar_t c2 = L'u';
test &= c1 != c2; VERIFY( c1 != c2 );
std::char_traits<wchar_t>::assign(c1,c2); std::char_traits<wchar_t>::assign(c1,c2);
test &= c1 == L'u'; VERIFY( c1 == L'u' );
// char* X::move(char* s, const char* p, size_t n) // char* X::move(char* s, const char* p, size_t n)
// for each i in [0,n) performs X::assign(s[i], p[i]). Copies // for each i in [0,n) performs X::assign(s[i], p[i]). Copies
@ -144,35 +142,35 @@ int test02(void)
int len = sizeof(str_lit1) + sizeof(array1) - 1; // two terminating chars int len = sizeof(str_lit1) + sizeof(array1) - 1; // two terminating chars
wchar_t array2[len]; wchar_t array2[len];
test &= str_lit1[0] == 'm'; VERIFY( str_lit1[0] == 'm' );
c1 = array2[0]; c1 = array2[0];
c2 = str_lit1[0]; c2 = str_lit1[0];
wchar_t c3 = array2[1]; wchar_t c3 = array2[1];
wchar_t c4 = str_lit1[1]; wchar_t c4 = str_lit1[1];
std::char_traits<wchar_t>::move(array2, str_lit1, 0); std::char_traits<wchar_t>::move(array2, str_lit1, 0);
test &= array2[0] == c1; VERIFY( array2[0] == c1 );
test &= str_lit1[0] == c2; VERIFY( str_lit1[0] == c2 );
std::char_traits<wchar_t>::move(array2, str_lit1, 1); std::char_traits<wchar_t>::move(array2, str_lit1, 1);
test &= array2[0] == c2; VERIFY( array2[0] == c2 );
test &= str_lit1[0] == c2; VERIFY( str_lit1[0] == c2 );
test &= array2[1] == c3; VERIFY( array2[1] == c3 );
test &= str_lit1[1] == c4; VERIFY( str_lit1[1] == c4 );
std::char_traits<wchar_t>::move(array2, str_lit1, 2); std::char_traits<wchar_t>::move(array2, str_lit1, 2);
test &= array2[0] == c2; VERIFY( array2[0] == c2 );
test &= str_lit1[0] == c2; VERIFY( str_lit1[0] == c2 );
test &= array2[1] == c4; VERIFY( array2[1] == c4 );
test &= str_lit1[1] == c4; VERIFY( str_lit1[1] == c4 );
wchar_t* pc1 = array1 + 1; wchar_t* pc1 = array1 + 1;
c1 = pc1[0]; c1 = pc1[0];
c2 = array1[0]; c2 = array1[0];
test &= c1 != c2; VERIFY( c1 != c2 );
wchar_t* pc2 = std::char_traits<wchar_t>::move(array1, pc1, 0); wchar_t* pc2 = std::char_traits<wchar_t>::move(array1, pc1, 0);
c3 = pc1[0]; c3 = pc1[0];
c4 = array1[0]; c4 = array1[0];
test &= c1 == c3; VERIFY( c1 == c3 );
test &= c2 == c4; VERIFY( c2 == c4 );
test &= pc2 == array1; VERIFY( pc2 == array1 );
c1 = pc1[0]; c1 = pc1[0];
c2 = array1[0]; c2 = array1[0];
@ -180,13 +178,13 @@ int test02(void)
pc2 = std::char_traits<wchar_t>::move(array1, pc1, 10); pc2 = std::char_traits<wchar_t>::move(array1, pc1, 10);
c3 = pc1[0]; c3 = pc1[0];
c4 = array1[0]; c4 = array1[0];
test &= c1 != c3; // underlying wchar_t array changed. VERIFY( c1 != c3 ); // underlying wchar_t array changed.
test &= c4 != c3; VERIFY( c4 != c3 );
test &= pc2 == array1; VERIFY( pc2 == array1 );
test &= pc3 == pc1; // but pointers o-tay VERIFY( pc3 == pc1 ); // but pointers o-tay
c1 = *(str_01.data()); c1 = *(str_01.data());
c2 = array1[0]; c2 = array1[0];
test &= c1 != c2; VERIFY( c1 != c2 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -31,14 +31,16 @@
// things would be sorted in a dictionary. // things would be sorted in a dictionary.
#include <string> #include <string>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
enum want_value {lt=0, z=1, gt=2}; enum want_value {lt=0, z=1, gt=2};
void test_value(int result, want_value expected); int
void test_value(int result, want_value expected) { test_value(int result, want_value expected);
int
test_value(int result, want_value expected)
{
bool pass = false; bool pass = false;
switch (expected) { switch (expected) {
@ -61,11 +63,14 @@ void test_value(int result, want_value expected) {
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(pass); assert(pass);
#endif #endif
return 0;
} }
int test01(void) { int
test01()
{
std::string str_0("costa rica"); std::string str_0("costa rica");
std::string str_1("costa marbella"); std::string str_1("costa marbella");
std::string str_2; std::string str_2;
@ -121,8 +126,12 @@ int test01(void) {
} }
int main() { int
main()
{
test01(); test01();
return 0;
} }

View File

@ -23,9 +23,7 @@
#include <new> #include <new>
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int test01(void) int test01(void)
{ {
@ -43,22 +41,22 @@ int test01(void)
csz01 = str01.size(); csz01 = str01.size();
try { try {
std::string str03(str01, csz01 + 1); std::string str03(str01, csz01 + 1);
test &= false; VERIFY( false );
} }
catch(std::out_of_range& fail) { catch(std::out_of_range& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
try { try {
std::string str03(str01, csz01); std::string str03(str01, csz01);
test &= str03.size() == 0; VERIFY( str03.size() == 0 );
test &= str03.size() <= str03.capacity(); VERIFY( str03.size() <= str03.capacity() );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
@ -68,13 +66,13 @@ int test01(void)
// should not crash, but what gets constructed is a bit arbitrary. // should not crash, but what gets constructed is a bit arbitrary.
try { try {
std::string str03(str_lit01, csz01 + 1); std::string str03(str_lit01, csz01 + 1);
test &= true; VERIFY( true );
} }
catch(std::length_error& fail) { catch(std::length_error& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
// NB: As strlen(str_lit01) != csz01, this test is undefined. It // NB: As strlen(str_lit01) != csz01, this test is undefined. It
@ -82,79 +80,79 @@ int test01(void)
// The "maverick's" of all string objects. // The "maverick's" of all string objects.
try { try {
std::string str04(str_lit01, npos); std::string str04(str_lit01, npos);
test &= true; VERIFY( true );
} }
catch(std::length_error& fail) { catch(std::length_error& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
// Build a maxsize-1 lengthed string consisting of all A's // Build a maxsize-1 lengthed string consisting of all A's
try { try {
std::string str03(csz01 - 1, 'A'); std::string str03(csz01 - 1, 'A');
test &= str03.size() == csz01 - 1; VERIFY( str03.size() == csz01 - 1 );
test &= str03.size() <= str03.capacity(); VERIFY( str03.size() <= str03.capacity() );
} }
// NB: bad_alloc is regrettable but entirely kosher for // NB: bad_alloc is regrettable but entirely kosher for
// out-of-memory situations. // out-of-memory situations.
catch(std::bad_alloc& fail) { catch(std::bad_alloc& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
// basic_string(const char* s, const allocator& a = allocator()) // basic_string(const char* s, const allocator& a = allocator())
std::string str04(str_lit01); std::string str04(str_lit01);
test &= str01 == str04; VERIFY( str01 == str04 );
// basic_string(size_type n, char c, const allocator& a = allocator()) // basic_string(size_type n, char c, const allocator& a = allocator())
csz01 = str01.max_size(); csz01 = str01.max_size();
try { try {
std::string str03(csz01 + 1, 'z'); std::string str03(csz01 + 1, 'z');
test &= false; VERIFY( false );
} }
catch(std::length_error& fail) { catch(std::length_error& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
try { try {
std::string str04(npos, 'b'); // the "maverick's" of all string objects. std::string str04(npos, 'b'); // the "maverick's" of all string objects.
test &= false; VERIFY( false );
} }
catch(std::length_error& fail) { catch(std::length_error& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
try { try {
std::string str03(csz01 - 1, 'z'); std::string str03(csz01 - 1, 'z');
test &= str03.size() != 0; VERIFY( str03.size() != 0 );
test &= str03.size() <= str03.capacity(); VERIFY( str03.size() <= str03.capacity() );
} }
// NB: bad_alloc is regrettable but entirely kosher for // NB: bad_alloc is regrettable but entirely kosher for
// out-of-memory situations. // out-of-memory situations.
catch(std::bad_alloc& fail) { catch(std::bad_alloc& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
// template<typename _InputIter> // template<typename _InputIter>
// basic_string(_InputIter begin, _InputIter end, const allocator& a) // basic_string(_InputIter begin, _InputIter end, const allocator& a)
std::string str06(str01.begin(), str01.end()); std::string str06(str01.begin(), str01.end());
test &= str06 == str01; VERIFY( str06 == str01 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -170,7 +168,7 @@ void test02()
// basic_string(_InputIter begin, _InputIter end, const allocator& a) // basic_string(_InputIter begin, _InputIter end, const allocator& a)
// where _InputIter is integral [21.3.1 para 15] // where _InputIter is integral [21.3.1 para 15]
std::string s(10,0); std::string s(10,0);
test &= s.size() == 10; VERIFY( s.size() == 10 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -42,45 +40,45 @@ bool test01(void)
// const_reference operator[] (size_type pos) const; // const_reference operator[] (size_type pos) const;
csz01 = str01.size(); csz01 = str01.size();
cref cref1 = str01[csz01 - 1]; cref cref1 = str01[csz01 - 1];
test &= cref1 == 'a'; VERIFY( cref1 == 'a' );
cref cref2 = str01[csz01]; cref cref2 = str01[csz01];
test &= cref2 == char(); VERIFY( cref2 == char() );
// reference operator[] (size_type pos); // reference operator[] (size_type pos);
csz02 = str02.size(); csz02 = str02.size();
ref ref1 = str02[csz02 - 1]; ref ref1 = str02[csz02 - 1];
test &= ref1 == 'a'; VERIFY( ref1 == 'a' );
ref ref2 = str02[1]; ref ref2 = str02[1];
test &= ref2 == '4'; VERIFY( ref2 == '4' );
// const_reference at(size_type pos) const; // const_reference at(size_type pos) const;
csz01 = str01.size(); csz01 = str01.size();
cref cref3 = str01.at(csz01 - 1); cref cref3 = str01.at(csz01 - 1);
test &= cref3 == 'a'; VERIFY( cref3 == 'a' );
try { try {
cref cref4 = str01.at(csz01); cref cref4 = str01.at(csz01);
test &= false; // Should not get here, as exception thrown. VERIFY( false ); // Should not get here, as exception thrown.
} }
catch(std::out_of_range& fail) { catch(std::out_of_range& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
// reference at(size_type pos); // reference at(size_type pos);
csz01 = str02.size(); csz01 = str02.size();
ref ref3 = str02.at(csz02 - 1); ref ref3 = str02.at(csz02 - 1);
test &= ref3 == 'a'; VERIFY( ref3 == 'a' );
try { try {
ref ref4 = str02.at(csz02); ref ref4 = str02.at(csz02);
test &= false; // Should not get here, as exception thrown. VERIFY( false ); // Should not get here, as exception thrown.
} }
catch(std::out_of_range& fail) { catch(std::out_of_range& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -43,71 +41,71 @@ bool test01(void)
// size_type find(const string&, size_type pos = 0) const; // size_type find(const string&, size_type pos = 0) const;
csz01 = str01.find(str01); csz01 = str01.find(str01);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.find(str01, 4); csz01 = str01.find(str01, 4);
test &= csz01 == npos; VERIFY( csz01 == npos );
csz01 = str01.find(str02, 0); csz01 = str01.find(str02, 0);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.find(str02, 3); csz01 = str01.find(str02, 3);
test &= csz01 == npos; VERIFY( csz01 == npos );
csz01 = str01.find(str03, 0); csz01 = str01.find(str03, 0);
test &= csz01 == 8; VERIFY( csz01 == 8 );
csz01 = str01.find(str03, 3); csz01 = str01.find(str03, 3);
test &= csz01 == 8; VERIFY( csz01 == 8 );
csz01 = str01.find(str03, 12); csz01 = str01.find(str03, 12);
test &= csz01 == npos; VERIFY( csz01 == npos );
// An empty string consists of no characters // An empty string consists of no characters
// therefore it should be found at every point in a string, // therefore it should be found at every point in a string,
// except beyond the end // except beyond the end
csz01 = str01.find(str04, 0); csz01 = str01.find(str04, 0);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.find(str04, 5); csz01 = str01.find(str04, 5);
test &= csz01 == 5; VERIFY( csz01 == 5 );
csz01 = str01.find(str04, str01.size()); csz01 = str01.find(str04, str01.size());
test &= csz01 == str01.size(); VERIFY( csz01 == str01.size() );
csz01 = str01.find(str04, str01.size()+1); csz01 = str01.find(str04, str01.size()+1);
test &= csz01 == npos; VERIFY( csz01 == npos );
// size_type find(const char* s, size_type pos, size_type n) const; // size_type find(const char* s, size_type pos, size_type n) const;
csz01 = str01.find(str_lit01, 0, 3); csz01 = str01.find(str_lit01, 0, 3);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.find(str_lit01, 3, 0); csz01 = str01.find(str_lit01, 3, 0);
test &= csz01 == 3; VERIFY( csz01 == 3 );
// size_type find(const char* s, size_type pos = 0) const; // size_type find(const char* s, size_type pos = 0) const;
csz01 = str01.find(str_lit01); csz01 = str01.find(str_lit01);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.find(str_lit01, 3); csz01 = str01.find(str_lit01, 3);
test &= csz01 == npos; VERIFY( csz01 == npos );
// size_type find(char c, size_type pos = 0) const; // size_type find(char c, size_type pos = 0) const;
csz01 = str01.find('z'); csz01 = str01.find('z');
csz02 = str01.size() - 1; csz02 = str01.size() - 1;
test &= csz01 == csz02; VERIFY( csz01 == csz02 );
csz01 = str01.find('/'); csz01 = str01.find('/');
test &= csz01 == npos; VERIFY( csz01 == npos );
// size_type find_first_of(const string&, size_type pos = 0) const; // size_type find_first_of(const string&, size_type pos = 0) const;
std::string str05("xena rulez"); std::string str05("xena rulez");
csz01 = str01.find_first_of(str01); csz01 = str01.find_first_of(str01);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.find_first_of(str01, 4); csz01 = str01.find_first_of(str01, 4);
test &= csz01 == 4; VERIFY( csz01 == 4 );
csz01 = str01.find_first_of(str02, 0); csz01 = str01.find_first_of(str02, 0);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.find_first_of(str02, 3); csz01 = str01.find_first_of(str02, 3);
test &= csz01 == 3; VERIFY( csz01 == 3 );
csz01 = str01.find_first_of(str03, 0); csz01 = str01.find_first_of(str03, 0);
test &= csz01 == 8; VERIFY( csz01 == 8 );
csz01 = str01.find_first_of(str03, 3); csz01 = str01.find_first_of(str03, 3);
test &= csz01 == 8; VERIFY( csz01 == 8 );
csz01 = str01.find_first_of(str03, 12); csz01 = str01.find_first_of(str03, 12);
test &= csz01 == 16; VERIFY( csz01 == 16 );
csz01 = str01.find_first_of(str05, 0); csz01 = str01.find_first_of(str05, 0);
test &= csz01 == 1; VERIFY( csz01 == 1 );
csz01 = str01.find_first_of(str05, 4); csz01 = str01.find_first_of(str05, 4);
test &= csz01 == 4; VERIFY( csz01 == 4 );
// An empty string consists of no characters // An empty string consists of no characters
// therefore it should be found at every point in a string, // therefore it should be found at every point in a string,
@ -115,26 +113,26 @@ bool test01(void)
// However, str1.find_first_of(str2,pos) finds the first character in // However, str1.find_first_of(str2,pos) finds the first character in
// str1 (starting at pos) that exists in str2, which is none for empty str2 // str1 (starting at pos) that exists in str2, which is none for empty str2
csz01 = str01.find_first_of(str04, 0); csz01 = str01.find_first_of(str04, 0);
test &= csz01 == npos; VERIFY( csz01 == npos );
csz01 = str01.find_first_of(str04, 5); csz01 = str01.find_first_of(str04, 5);
test &= csz01 == npos; VERIFY( csz01 == npos );
// size_type find_first_of(const char* s, size_type pos, size_type n) const; // size_type find_first_of(const char* s, size_type pos, size_type n) const;
csz01 = str01.find_first_of(str_lit01, 0, 3); csz01 = str01.find_first_of(str_lit01, 0, 3);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.find_first_of(str_lit01, 3, 0); csz01 = str01.find_first_of(str_lit01, 3, 0);
test &= csz01 == npos; VERIFY( csz01 == npos );
// size_type find_first_of(const char* s, size_type pos = 0) const; // size_type find_first_of(const char* s, size_type pos = 0) const;
csz01 = str01.find_first_of(str_lit01); csz01 = str01.find_first_of(str_lit01);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.find_first_of(str_lit01, 3); csz01 = str01.find_first_of(str_lit01, 3);
test &= csz01 == 3; VERIFY( csz01 == 3 );
// size_type find_first_of(char c, size_type pos = 0) const; // size_type find_first_of(char c, size_type pos = 0) const;
csz01 = str01.find_first_of('z'); csz01 = str01.find_first_of('z');
csz02 = str01.size() - 1; csz02 = str01.size() - 1;
test &= csz01 == csz02; VERIFY( csz01 == csz02 );
// size_type find_last_of(const string& str, size_type pos = 0) const; // size_type find_last_of(const string& str, size_type pos = 0) const;
// size_type find_last_of(const char* s, size_type pos, size_type n) const; // size_type find_last_of(const char* s, size_type pos, size_type n) const;
@ -146,45 +144,45 @@ bool test01(void)
std::string x; std::string x;
std::string::size_type pos; std::string::size_type pos;
pos = x.find_last_not_of('X'); pos = x.find_last_not_of('X');
test &= pos == npos; VERIFY( pos == npos );
pos = x.find_last_not_of("XYZ"); pos = x.find_last_not_of("XYZ");
test &= pos == npos; VERIFY( pos == npos );
std::string y("a"); std::string y("a");
pos = y.find_last_not_of('X'); pos = y.find_last_not_of('X');
test &= pos == 0; VERIFY( pos == 0 );
pos = y.find_last_not_of('a'); pos = y.find_last_not_of('a');
test &= pos == npos; VERIFY( pos == npos );
pos = y.find_last_not_of("XYZ"); pos = y.find_last_not_of("XYZ");
test &= pos == 0; VERIFY( pos == 0 );
pos = y.find_last_not_of("a"); pos = y.find_last_not_of("a");
test &= pos == npos; VERIFY( pos == npos );
std::string z("ab"); std::string z("ab");
pos = z.find_last_not_of('X'); pos = z.find_last_not_of('X');
test &= pos == 1; VERIFY( pos == 1 );
pos = z.find_last_not_of("XYZ"); pos = z.find_last_not_of("XYZ");
test &= pos == 1; VERIFY( pos == 1 );
pos = z.find_last_not_of('b'); pos = z.find_last_not_of('b');
test &= pos == 0; VERIFY( pos == 0 );
pos = z.find_last_not_of("Xb"); pos = z.find_last_not_of("Xb");
test &= pos == 0; VERIFY( pos == 0 );
pos = z.find_last_not_of("Xa"); pos = z.find_last_not_of("Xa");
test &= pos == 1; VERIFY( pos == 1 );
pos = z.find_last_of("ab"); pos = z.find_last_of("ab");
test &= pos == 1; VERIFY( pos == 1 );
pos = z.find_last_of("Xa"); pos = z.find_last_of("Xa");
test &= pos == 0; VERIFY( pos == 0 );
pos = z.find_last_of("Xb"); pos = z.find_last_of("Xb");
test &= pos == 1; VERIFY( pos == 1 );
pos = z.find_last_of("XYZ"); pos = z.find_last_of("XYZ");
test &= pos == std::string::npos; VERIFY( pos == std::string::npos );
pos = z.find_last_of('a'); pos = z.find_last_of('a');
test &= pos == 0; VERIFY( pos == 0 );
pos = z.find_last_of('b'); pos = z.find_last_of('b');
test &= pos == 1; VERIFY( pos == 1 );
pos = z.find_last_of('X'); pos = z.find_last_of('X');
test &= pos == std::string::npos; VERIFY( pos == std::string::npos );
#endif #endif
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int test01(void) int test01(void)
{ {
@ -56,13 +54,13 @@ int test01(void)
csz02 = str02.size(); csz02 = str02.size();
try { try {
str03.insert(csz01 + 1, str02, 0, 5); str03.insert(csz01 + 1, str02, 0, 5);
test &= false; VERIFY( false );
} }
catch(std::out_of_range& fail) { catch(std::out_of_range& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
str03 = str01; str03 = str01;
@ -70,13 +68,13 @@ int test01(void)
csz02 = str02.size(); csz02 = str02.size();
try { try {
str03.insert(0, str02, csz02 + 1, 5); str03.insert(0, str02, csz02 + 1, 5);
test &= false; VERIFY( false );
} }
catch(std::out_of_range& fail) { catch(std::out_of_range& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
csz01 = str01.max_size(); csz01 = str01.max_size();
@ -86,39 +84,39 @@ int test01(void)
csz02 = str02.size(); csz02 = str02.size();
try { try {
str03.insert(0, str02, 0, 5); str03.insert(0, str02, 0, 5);
test &= false; VERIFY( false );
} }
catch(std::length_error& fail) { catch(std::length_error& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
} }
catch(std::bad_alloc& failure){ catch(std::bad_alloc& failure){
test &= true; VERIFY( true );
} }
catch(std::exception& failure){ catch(std::exception& failure){
test &= false; VERIFY( false );
} }
str03 = str01; str03 = str01;
csz01 = str03.size(); csz01 = str03.size();
csz02 = str02.size(); csz02 = str02.size();
str03.insert(13, str02, 0, 12); str03.insert(13, str02, 0, 12);
test&= str03 == "rodeo beach, baker beach,marin"; VERIFY( str03 == "rodeo beach, baker beach,marin" );
str03 = str01; str03 = str01;
csz01 = str03.size(); csz01 = str03.size();
csz02 = str02.size(); csz02 = str02.size();
str03.insert(0, str02, 0, 12); str03.insert(0, str02, 0, 12);
test&= str03 == "baker beach,rodeo beach, marin"; VERIFY( str03 == "baker beach,rodeo beach, marin" );
str03 = str01; str03 = str01;
csz01 = str03.size(); csz01 = str03.size();
csz02 = str02.size(); csz02 = str02.size();
str03.insert(csz01, str02, 0, csz02); str03.insert(csz01, str02, 0, csz02);
test&= str03 == "rodeo beach, marinbaker beach, san francisco"; VERIFY( str03 == "rodeo beach, marinbaker beach, san francisco" );
// string& insert(size_type __p, const string& string); // string& insert(size_type __p, const string& string);
// insert(p1, str, 0, npos) // insert(p1, str, 0, npos)
@ -126,47 +124,47 @@ int test01(void)
csz01 = str03.size(); csz01 = str03.size();
csz02 = str02.size(); csz02 = str02.size();
str03.insert(csz01, str02); str03.insert(csz01, str02);
test&= str03 == "rodeo beach, marinbaker beach, san francisco"; VERIFY( str03 == "rodeo beach, marinbaker beach, san francisco" );
str03 = str01; str03 = str01;
csz01 = str03.size(); csz01 = str03.size();
csz02 = str02.size(); csz02 = str02.size();
str03.insert(0, str02); str03.insert(0, str02);
test&= str03 == "baker beach, san franciscorodeo beach, marin"; VERIFY( str03 == "baker beach, san franciscorodeo beach, marin" );
// string& insert(size_type __p, const char* s, size_type n); // string& insert(size_type __p, const char* s, size_type n);
// insert(p1, string(s,n)) // insert(p1, string(s,n))
str03 = str02; str03 = str02;
csz01 = str03.size(); csz01 = str03.size();
str03.insert(0, "-break at the bridge", 20); str03.insert(0, "-break at the bridge", 20);
test&= str03 == "-break at the bridgebaker beach, san francisco"; VERIFY( str03 == "-break at the bridgebaker beach, san francisco" );
// string& insert(size_type __p, const char* s); // string& insert(size_type __p, const char* s);
// insert(p1, string(s)) // insert(p1, string(s))
str03 = str02; str03 = str02;
str03.insert(0, "-break at the bridge"); str03.insert(0, "-break at the bridge");
test&= str03 == "-break at the bridgebaker beach, san francisco"; VERIFY( str03 == "-break at the bridgebaker beach, san francisco" );
// string& insert(size_type __p, size_type n, char c) // string& insert(size_type __p, size_type n, char c)
// insert(p1, string(n,c)) // insert(p1, string(n,c))
str03 = str02; str03 = str02;
csz01 = str03.size(); csz01 = str03.size();
str03.insert(csz01, 5, 'z'); str03.insert(csz01, 5, 'z');
test&= str03 == "baker beach, san franciscozzzzz"; VERIFY( str03 == "baker beach, san franciscozzzzz" );
// iterator insert(iterator p, char c) // iterator insert(iterator p, char c)
// inserts a copy of c before the character referred to by p // inserts a copy of c before the character referred to by p
str03 = str02; str03 = str02;
citerator cit01 = str03.begin(); citerator cit01 = str03.begin();
str03.insert(cit01, 'u'); str03.insert(cit01, 'u');
test&= str03 == "ubaker beach, san francisco"; VERIFY( str03 == "ubaker beach, san francisco" );
// iterator insert(iterator p, size_type n, char c) // iterator insert(iterator p, size_type n, char c)
// inserts n copies of c before the character referred to by p // inserts n copies of c before the character referred to by p
str03 = str02; str03 = str02;
cit01 = str03.begin(); cit01 = str03.begin();
str03.insert(cit01, 5, 'u'); str03.insert(cit01, 5, 'u');
test&= str03 == "uuuuubaker beach, san francisco"; VERIFY( str03 == "uuuuubaker beach, san francisco" );
// template<inputit> // template<inputit>
// void // void
@ -176,12 +174,12 @@ int test01(void)
str03 = str02; str03 = str02;
csz01 = str03.size(); csz01 = str03.size();
str03.insert(str03.begin(), str01.begin(), str01.end()); str03.insert(str03.begin(), str01.begin(), str01.end());
test&= str03 == "rodeo beach, marinbaker beach, san francisco"; VERIFY( str03 == "rodeo beach, marinbaker beach, san francisco" );
str03 = str02; str03 = str02;
csz01 = str03.size(); csz01 = str03.size();
str03.insert(str03.end(), str01.begin(), str01.end()); str03.insert(str03.end(), str01.begin(), str01.end());
test&= str03 == "baker beach, san franciscorodeo beach, marin"; VERIFY( str03 == "baker beach, san franciscorodeo beach, marin" );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -29,9 +29,7 @@
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -54,91 +52,91 @@ bool test01(void)
// istream& operator>>(istream&, string&) // istream& operator>>(istream&, string&)
std::istringstream istrs01(str01); std::istringstream istrs01(str01);
istrs01 >> str10; istrs01 >> str10;
test &= str10 == str02; VERIFY( str10 == str02 );
try { try {
std::istringstream::int_type i01 = istrs01.peek(); //a-boo std::istringstream::int_type i01 = istrs01.peek(); //a-boo
test &= std::istringstream::traits_type::to_char_type(i01) == ' '; VERIFY( std::istringstream::traits_type::to_char_type(i01) == ' ' );
} }
catch(std::exception& fail) { catch(std::exception& fail) {
test &= false; // shouldn't throw VERIFY( false ); // shouldn't throw
} }
istrs01 >> str10; istrs01 >> str10;
test &= str10 == str03; VERIFY( str10 == str03 );
istrs01 >> str10; istrs01 >> str10;
test &= str10 == str04; // sentry picks out the white spaces. . VERIFY( str10 == str04 ); // sentry picks out the white spaces. .
std::istringstream istrs02(str05); // empty std::istringstream istrs02(str05); // empty
istrs02 >> str10; istrs02 >> str10;
test &= str10 == str04; VERIFY( str10 == str04 );
// istream& getline(istream&, string&, char) // istream& getline(istream&, string&, char)
// istream& getline(istream&, string&) // istream& getline(istream&, string&)
try { try {
getline(istrs01, str10); getline(istrs01, str10);
test &= !istrs01.fail(); VERIFY( !istrs01.fail() );
test &= !istrs01.eof(); VERIFY( !istrs01.eof() );
test &= istrs01.good(); VERIFY( istrs01.good() );
test &= str10 == " bay"; VERIFY( str10 == " bay" );
} }
catch(std::exception& fail) { catch(std::exception& fail) {
test &= false; // shouldn't throw VERIFY( false ); // shouldn't throw
} }
try { try {
istrs01.clear(); istrs01.clear();
getline(istrs01, str10,'\t'); getline(istrs01, str10,'\t');
test &= !istrs01.fail(); VERIFY( !istrs01.fail() );
test &= !istrs01.eof(); VERIFY( !istrs01.eof() );
test &= istrs01.good(); VERIFY( istrs01.good() );
test &= str10 == str05; VERIFY( str10 == str05 );
} }
catch(std::exception& fail) { catch(std::exception& fail) {
test &= false; // shouldn't throw VERIFY( false ); // shouldn't throw
} }
try { try {
istrs01.clear(); istrs01.clear();
getline(istrs01, str10,'\t'); getline(istrs01, str10,'\t');
test &= !istrs01.fail(); VERIFY( !istrs01.fail() );
test &= !istrs01.eof(); VERIFY( !istrs01.eof() );
test &= istrs01.good(); VERIFY( istrs01.good() );
test &= str10 == str05; VERIFY( str10 == str05 );
} }
catch(std::exception& fail) { catch(std::exception& fail) {
test &= false; // shouldn't throw VERIFY( false ); // shouldn't throw
} }
try { try {
istrs01.clear(); istrs01.clear();
getline(istrs01, str10, '.'); getline(istrs01, str10, '.');
test &= !istrs01.fail(); VERIFY( !istrs01.fail() );
test &= istrs01.eof(); VERIFY( istrs01.eof() );
test &= !istrs01.good(); VERIFY( !istrs01.good() );
test &= str10 == "\t from Elk Rapids to the point reminds me of miles"; VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
} }
catch(std::exception& fail) { catch(std::exception& fail) {
test &= false; // shouldn't throw VERIFY( false ); // shouldn't throw
} }
try { try {
getline(istrs02, str10); getline(istrs02, str10);
test &= istrs02.fail(); VERIFY( istrs02.fail() );
test &= istrs02.eof(); VERIFY( istrs02.eof() );
test &= str10 == "\t from Elk Rapids to the point reminds me of miles"; VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
} }
catch(std::exception& fail) { catch(std::exception& fail) {
test &= false; // shouldn't throw VERIFY( false ); // shouldn't throw
} }
// ostream& operator<<(ostream&, const basic_string&) // ostream& operator<<(ostream&, const basic_string&)
std::ostringstream ostrs01; std::ostringstream ostrs01;
try { try {
ostrs01 << str01; ostrs01 << str01;
test &= ostrs01.str() == str01; VERIFY( ostrs01.str() == str01 );
} }
catch(std::exception& fail) { catch(std::exception& fail) {
test &= false; VERIFY( false );
} }
std::string hello_world; std::string hello_world;
@ -161,8 +159,8 @@ void test04(int size)
std::ostringstream oss(str); std::ostringstream oss(str);
// sanity checks // sanity checks
test &= str.size() == size; VERIFY( str.size() == size );
test &= oss.good(); VERIFY( oss.good() );
// stress test // stress test
oss << str << std::endl; oss << str << std::endl;
@ -173,10 +171,10 @@ void test04(int size)
if (!oss.good()) if (!oss.good())
test = false; test = false;
test &= str.size() == size; VERIFY( str.size() == size );
test &= oss.good(); VERIFY( oss.good() );
std::string str_tmp = oss.str(); std::string str_tmp = oss.str();
test &= str_tmp.size() == expected_size; VERIFY( str_tmp.size() == expected_size );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -196,8 +194,8 @@ void test05(int size)
std::string str(size, fillc); std::string str(size, fillc);
// sanity checks // sanity checks
test &= str.size() == size; VERIFY( str.size() == size );
test &= ofs.good(); VERIFY( ofs.good() );
// stress test // stress test
ofs << str << std::endl; ofs << str << std::endl;
@ -208,8 +206,8 @@ void test05(int size)
if (!ofs.good()) if (!ofs.good())
test = false; test = false;
test &= str.size() == size; VERIFY( str.size() == size );
test &= ofs.good(); VERIFY( ofs.good() );
ofs.close(); ofs.close();
@ -229,7 +227,7 @@ void test05(int size)
break; break;
} }
test &= count == 2 * size; VERIFY( count == 2 * size );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -251,16 +249,16 @@ void test06(void)
str01.erase(0, 1); str01.erase(0, 1);
size_type i03 = str01.size(); size_type i03 = str01.size();
size_type i04 = str01.capacity(); size_type i04 = str01.capacity();
test &= i01 - 1 == i03; VERIFY( i01 - 1 == i03 );
test &= i02 >= i04; VERIFY( i02 >= i04 );
std::istringstream is(str01); std::istringstream is(str01);
std::string str02; std::string str02;
is >> str02 >> std::ws; is >> str02 >> std::ws;
size_type i05 = str02.size(); size_type i05 = str02.size();
size_type i06 = str02.capacity(); size_type i06 = str02.capacity();
test &= i05 == i03; VERIFY( i05 == i03 );
test &= i06 <= i04; VERIFY( i06 <= i04 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -281,8 +279,8 @@ void test07(void)
while (iss >> s) while (iss >> s)
++i; ++i;
test &= i < 3; VERIFY( i < 3 );
test &= static_cast<bool>(iss.rdstate() & std::ios_base::failbit); VERIFY( static_cast<bool>(iss.rdstate() & std::ios_base::failbit) );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
// Do a quick sanity check on known problems with element access and // Do a quick sanity check on known problems with element access and
// ref-counted strings. These should all pass, regardless of the // ref-counted strings. These should all pass, regardless of the
@ -60,48 +58,48 @@ bool test01(void)
str03 = str01; str03 = str01;
it1 = str01.begin(); it1 = str01.begin();
*it1 = 'x'; *it1 = 'x';
test &= str01[0] == 'x'; VERIFY( str01[0] == 'x' );
test &= str03[0] == 'm'; VERIFY( str03[0] == 'm' );
str03 = str01; str03 = str01;
csz01 = str01.size(); csz01 = str01.size();
rit1 = str01.rbegin(); // NB: Pointing at one-past the end, so ... rit1 = str01.rbegin(); // NB: Pointing at one-past the end, so ...
*rit1 = 'z'; // ... but it's taken care of here *rit1 = 'z'; // ... but it's taken care of here
test &= str01[csz01 - 1] == 'z'; VERIFY( str01[csz01 - 1] == 'z' );
test &= str03[csz01 - 1] == 'y'; VERIFY( str03[csz01 - 1] == 'y' );
str03 = str01; str03 = str01;
csz01 = str01.size(); csz01 = str01.size();
std::string::reference r1 = str01.at(csz01 - 2); std::string::reference r1 = str01.at(csz01 - 2);
test &= str03 == str01; VERIFY( str03 == str01 );
r1 = 'd'; r1 = 'd';
test &= str01[csz01 - 2] == 'd'; VERIFY( str01[csz01 - 2] == 'd' );
test &= str03[csz01 - 2] == 'a'; VERIFY( str03[csz01 - 2] == 'a' );
str03 = str01; str03 = str01;
csz01 = str01.size(); csz01 = str01.size();
std::string::reference r2 = str01[csz01 - 3]; std::string::reference r2 = str01[csz01 - 3];
test &= str03 == str01; VERIFY( str03 == str01 );
r2 = 'w'; r2 = 'w';
test &= str01[csz01 - 3] == 'w'; VERIFY( str01[csz01 - 3] == 'w' );
test &= str03[csz01 - 3] == 'b'; VERIFY( str03[csz01 - 3] == 'b' );
str03 = str01; str03 = str01;
csz02 = str01.size(); csz02 = str01.size();
it1 = str01.end(); it1 = str01.end();
test &= str03 == str01; VERIFY( str03 == str01 );
--it1; --it1;
*it1 = 'q'; *it1 = 'q';
test &= str01[csz02 - 1] == 'q'; VERIFY( str01[csz02 - 1] == 'q' );
test &= str03[csz02 - 1] == 'z'; VERIFY( str03[csz02 - 1] == 'z' );
str03 = str01; str03 = str01;
rit1 = str01.rend(); rit1 = str01.rend();
test &= str03 == str01; VERIFY( str03 == str01 );
--rit1; --rit1;
*rit1 = 'p'; *rit1 = 'p';
test &= str01[0] == 'p'; VERIFY( str01[0] == 'p' );
test &= str03[0] == 'x'; VERIFY( str03[0] == 'x' );
// need to also test for const begin/const end // need to also test for const begin/const end
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
@ -129,39 +127,39 @@ bool test02(void)
std::string str05 = str02; // optional, so that begin below causes a mutate std::string str05 = str02; // optional, so that begin below causes a mutate
std::string::iterator p = str02.insert(str02.begin(), ' '); std::string::iterator p = str02.insert(str02.begin(), ' ');
std::string str03 = str02; std::string str03 = str02;
test &= str03 == str02; VERIFY( str03 == str02 );
*p = '!'; *p = '!';
test &= *str03.c_str() == ' '; VERIFY( *str03.c_str() == ' ' );
str03[0] = '@'; str03[0] = '@';
test &= str02[0] == '!'; VERIFY( str02[0] == '!' );
test &= *p == '!'; VERIFY( *p == '!' );
test &= str02 != str05; VERIFY( str02 != str05 );
test &= str02 != str03; VERIFY( str02 != str03 );
std::string str10 = str01; std::string str10 = str01;
std::string::iterator p2 = str10.insert(str10.begin(), 'a'); std::string::iterator p2 = str10.insert(str10.begin(), 'a');
std::string str11 = str10; std::string str11 = str10;
*p2 = 'e'; *p2 = 'e';
test &= str11 != str10; VERIFY( str11 != str10 );
std::string str06 = str01; std::string str06 = str01;
std::string str07 = str06; // optional, so that begin below causes a mutate std::string str07 = str06; // optional, so that begin below causes a mutate
p = str06.erase(str06.begin()); p = str06.erase(str06.begin());
std::string str08 = str06; std::string str08 = str06;
test &= str08 == str06; VERIFY( str08 == str06 );
*p = '!'; *p = '!';
test &= *str08.c_str() == 't'; VERIFY( *str08.c_str() == 't' );
str08[0] = '@'; str08[0] = '@';
test &= str06[0] == '!'; VERIFY( str06[0] == '!' );
test &= *p == '!'; VERIFY( *p == '!' );
test &= str06 != str07; VERIFY( str06 != str07 );
test &= str06 != str08; VERIFY( str06 != str08 );
std::string str12 = str01; std::string str12 = str01;
p2 = str12.erase(str12.begin(), str12.begin() + str12.size() - 1); p2 = str12.erase(str12.begin(), str12.begin() + str12.size() - 1);
std::string str13 = str12; std::string str13 = str12;
*p2 = 'e'; *p2 = 'e';
test &= str12 != str13; VERIFY( str12 != str13 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -111,9 +111,7 @@ template<class charT, class traits, class Allocator>
*/ */
#include <string> #include <string>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int test01(void) int test01(void)
{ {
@ -126,114 +124,114 @@ int test01(void)
str_4 = str_0; str_4 = str_0;
//comparisons between string objects //comparisons between string objects
test &= !(str_0 == str_1); VERIFY( !(str_0 == str_1) );
test &= !(str_0 == str_2); VERIFY( !(str_0 == str_2) );
test &= !(str_0 == str_3); VERIFY( !(str_0 == str_3) );
test &= !(str_1 == str_0); VERIFY( !(str_1 == str_0) );
test &= !(str_2 == str_0); VERIFY( !(str_2 == str_0) );
test &= !(str_3 == str_0); VERIFY( !(str_3 == str_0) );
test &= str_4 == str_0; VERIFY( str_4 == str_0 );
test &= str_0 == str_4; VERIFY( str_0 == str_4 );
test &= str_0 != str_1; VERIFY( str_0 != str_1 );
test &= str_0 != str_2; VERIFY( str_0 != str_2 );
test &= str_0 != str_3; VERIFY( str_0 != str_3 );
test &= str_1 != str_0; VERIFY( str_1 != str_0 );
test &= str_2 != str_0; VERIFY( str_2 != str_0 );
test &= str_3 != str_0; VERIFY( str_3 != str_0 );
test &= !(str_0 != str_4); VERIFY( !(str_0 != str_4) );
test &= !(str_4 != str_0); VERIFY( !(str_4 != str_0) );
test &= str_0 > str_1; //true cuz r>m VERIFY( str_0 > str_1 ); //true cuz r>m
test &= str_0 > str_2; VERIFY( str_0 > str_2 );
test &= !(str_0 > str_3); VERIFY( !(str_0 > str_3) );
test &= !(str_1 > str_0); //false cuz m<r VERIFY( !(str_1 > str_0) ); //false cuz m<r
test &= !(str_2 > str_0); VERIFY( !(str_2 > str_0) );
test &= str_3 > str_0; VERIFY( str_3 > str_0 );
test &= !(str_0 > str_4); VERIFY( !(str_0 > str_4) );
test &= !(str_4 > str_0); VERIFY( !(str_4 > str_0) );
test &= !(str_0 < str_1); //false cuz r>m VERIFY( !(str_0 < str_1) ); //false cuz r>m
test &= !(str_0 < str_2); VERIFY( !(str_0 < str_2) );
test &= str_0 < str_3; VERIFY( str_0 < str_3 );
test &= str_1 < str_0; //true cuz m<r VERIFY( str_1 < str_0 ); //true cuz m<r
test &= str_2 < str_0; VERIFY( str_2 < str_0 );
test &= !(str_3 < str_0); VERIFY( !(str_3 < str_0) );
test &= !(str_0 < str_4); VERIFY( !(str_0 < str_4) );
test &= !(str_4 < str_0); VERIFY( !(str_4 < str_0) );
test &= str_0 >= str_1; //true cuz r>m VERIFY( str_0 >= str_1 ); //true cuz r>m
test &= str_0 >= str_2; VERIFY( str_0 >= str_2 );
test &= !(str_0 >= str_3); VERIFY( !(str_0 >= str_3) );
test &= !(str_1 >= str_0);//false cuz m<r VERIFY( !(str_1 >= str_0) );//false cuz m<r
test &= !(str_2 >= str_0); VERIFY( !(str_2 >= str_0) );
test &= str_3 >= str_0; VERIFY( str_3 >= str_0 );
test &= str_0 >= str_4; VERIFY( str_0 >= str_4 );
test &= str_4 >= str_0; VERIFY( str_4 >= str_0 );
test &= !(str_0 <= str_1);//false cuz r>m VERIFY( !(str_0 <= str_1) );//false cuz r>m
test &= !(str_0 <= str_2); VERIFY( !(str_0 <= str_2) );
test &= str_0 <= str_3; VERIFY( str_0 <= str_3 );
test &= str_1 <= str_0;//true cuz m<r VERIFY( str_1 <= str_0 );//true cuz m<r
test &= str_2 <= str_0; VERIFY( str_2 <= str_0 );
test &= !(str_3 <= str_0); VERIFY( !(str_3 <= str_0) );
test &= str_0 <= str_4; VERIFY( str_0 <= str_4 );
test &= str_4 <= str_0; VERIFY( str_4 <= str_0 );
//comparisons between string object and string literal //comparisons between string object and string literal
test &= !(str_0 == "costa marbella"); VERIFY( !(str_0 == "costa marbella") );
test &= !(str_0 == "cost"); VERIFY( !(str_0 == "cost") );
test &= !(str_0 == "costa ricans"); VERIFY( !(str_0 == "costa ricans") );
test &= !("costa marbella" == str_0); VERIFY( !("costa marbella" == str_0) );
test &= !("cost" == str_0); VERIFY( !("cost" == str_0) );
test &= !("costa ricans" == str_0); VERIFY( !("costa ricans" == str_0) );
test &= "costa rica" == str_0; VERIFY( "costa rica" == str_0 );
test &= str_0 == "costa rica"; VERIFY( str_0 == "costa rica" );
test &= str_0 != "costa marbella"; VERIFY( str_0 != "costa marbella" );
test &= str_0 != "cost"; VERIFY( str_0 != "cost" );
test &= str_0 != "costa ricans"; VERIFY( str_0 != "costa ricans" );
test &= "costa marbella" != str_0; VERIFY( "costa marbella" != str_0 );
test &= "cost" != str_0; VERIFY( "cost" != str_0 );
test &= "costa ricans" != str_0; VERIFY( "costa ricans" != str_0 );
test &= !("costa rica" != str_0); VERIFY( !("costa rica" != str_0) );
test &= !(str_0 != "costa rica"); VERIFY( !(str_0 != "costa rica") );
test &= str_0 > "costa marbella"; //true cuz r>m VERIFY( str_0 > "costa marbella" ); //true cuz r>m
test &= str_0 > "cost"; VERIFY( str_0 > "cost" );
test &= !(str_0 > "costa ricans"); VERIFY( !(str_0 > "costa ricans") );
test &= !("costa marbella" > str_0);//false cuz m<r VERIFY( !("costa marbella" > str_0) );//false cuz m<r
test &= !("cost" > str_0); VERIFY( !("cost" > str_0) );
test &= "costa ricans" > str_0; VERIFY( "costa ricans" > str_0 );
test &= !("costa rica" > str_0); VERIFY( !("costa rica" > str_0) );
test &= !(str_0 > "costa rica"); VERIFY( !(str_0 > "costa rica") );
test &= !(str_0 < "costa marbella");//false cuz r>m VERIFY( !(str_0 < "costa marbella") );//false cuz r>m
test &= !(str_0 < "cost"); VERIFY( !(str_0 < "cost") );
test &= str_0 < "costa ricans"; VERIFY( str_0 < "costa ricans" );
test &= "costa marbella" < str_0;//true cuz m<r VERIFY( "costa marbella" < str_0 );//true cuz m<r
test &= "cost" < str_0; VERIFY( "cost" < str_0 );
test &= !("costa ricans" < str_0); VERIFY( !("costa ricans" < str_0) );
test &= !("costa rica" < str_0); VERIFY( !("costa rica" < str_0) );
test &= !(str_0 < "costa rica"); VERIFY( !(str_0 < "costa rica") );
test &= str_0 >= "costa marbella";//true cuz r>m VERIFY( str_0 >= "costa marbella" );//true cuz r>m
test &= str_0 >= "cost"; VERIFY( str_0 >= "cost" );
test &= !(str_0 >= "costa ricans"); VERIFY( !(str_0 >= "costa ricans") );
test &= !("costa marbella" >= str_0);//false cuz m<r VERIFY( !("costa marbella" >= str_0) );//false cuz m<r
test &= !("cost" >= str_0); VERIFY( !("cost" >= str_0) );
test &= "costa ricans" >= str_0; VERIFY( "costa ricans" >= str_0 );
test &= "costa rica" >= str_0; VERIFY( "costa rica" >= str_0 );
test &= str_0 >= "costa rica"; VERIFY( str_0 >= "costa rica" );
test &= !(str_0 <= "costa marbella");//false cuz r>m VERIFY( !(str_0 <= "costa marbella") );//false cuz r>m
test &= !(str_0 <= "cost"); VERIFY( !(str_0 <= "cost") );
test &= str_0 <= "costa ricans"; VERIFY( str_0 <= "costa ricans" );
test &= "costa marbella" <= str_0;//true cuz m<r VERIFY( "costa marbella" <= str_0 );//true cuz m<r
test &= "cost" <= str_0; VERIFY( "cost" <= str_0 );
test &= !("costa ricans" <= str_0); VERIFY( !("costa ricans" <= str_0) );
test &= "costa rica" <= str_0; VERIFY( "costa rica" <= str_0 );
test &= str_0 <= "costa rica"; VERIFY( str_0 <= "costa rica" );
// 21.3.7.1 operator+ // 21.3.7.1 operator+
/* /*
@ -262,19 +260,19 @@ template<class charT, class traits, class Allocator>
*/ */
str_4 = str_0 + "ns"; str_4 = str_0 + "ns";
test &= str_4 == str_3; VERIFY( str_4 == str_3 );
const std::string str_5(" marbella"); const std::string str_5(" marbella");
str_4 = "costa" + str_5; str_4 = "costa" + str_5;
test &= str_4 == str_1; VERIFY( str_4 == str_1 );
std::string str_6("ns"); std::string str_6("ns");
str_4 = str_0 + str_6; str_4 = str_0 + str_6;
test &= str_4 == str_3; VERIFY( str_4 == str_3 );
str_4 = str_0 + 'n'; str_4 = str_0 + 'n';
str_4 = str_4 + 's'; str_4 = str_4 + 's';
test &= str_4 == str_3; VERIFY( str_4 == str_3 );
str_4 = 'a' + str_6; str_4 = 'a' + str_6;
str_4 = 'c' + str_4; str_4 = 'c' + str_4;
@ -286,7 +284,7 @@ template<class charT, class traits, class Allocator>
str_4 = 's' + str_4; str_4 = 's' + str_4;
str_4 = 'o' + str_4; str_4 = 'o' + str_4;
str_4 = 'c' + str_4; str_4 = 'c' + str_4;
test &= str_4 == str_3; VERIFY( str_4 == str_3 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <cstdio> #include <cstdio>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int test01(void) int test01(void)
{ {

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -60,23 +58,23 @@ bool test01(void)
std::string x = X; std::string x = X;
char ch = x[0]; char ch = x[0];
test &= ch == 'H'; VERIFY( ch == 'H' );
std::string z = x.substr(2, 3); std::string z = x.substr(2, 3);
test &= z == "llo"; VERIFY( z == "llo" );
x.replace(2, 2, "r"); x.replace(2, 2, "r");
test &= x == "Hero"; VERIFY( x == "Hero" );
x = X; x = X;
x.replace(0, 1, "j"); x.replace(0, 1, "j");
test &= x == "jello"; VERIFY( x == "jello" );
int ar[] = { 'H', 'e', 'l', 'l', 'o' }; int ar[] = { 'H', 'e', 'l', 'l', 'o' };
x.replace(std::find(x.begin(), x.end(), 'l'), x.replace(std::find(x.begin(), x.end(), 'l'),
std::find(x.rbegin(), x.rend(), 'l').base(), ar, std::find(x.rbegin(), x.rend(), 'l').base(), ar,
ar + sizeof(ar) / sizeof(ar[0])); ar + sizeof(ar) / sizeof(ar[0]));
test &= x == "jeHelloo"; VERIFY( x == "jeHelloo" );
#endif #endif
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -20,9 +20,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
// 21.3.6.2 basic_string rfind // 21.3.6.2 basic_string rfind
bool test01(void) bool test01(void)
@ -42,50 +40,50 @@ bool test01(void)
// size_type rfind(const string&, size_type pos = 0) const; // size_type rfind(const string&, size_type pos = 0) const;
csz01 = str01.rfind(str01); csz01 = str01.rfind(str01);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.rfind(str01, 4); csz01 = str01.rfind(str01, 4);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.rfind(str02,3); csz01 = str01.rfind(str02,3);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.rfind(str02); csz01 = str01.rfind(str02);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.rfind(str03); csz01 = str01.rfind(str03);
test &= csz01 == 8; VERIFY( csz01 == 8 );
csz01 = str01.rfind(str03, 3); csz01 = str01.rfind(str03, 3);
test &= csz01 == npos; VERIFY( csz01 == npos );
csz01 = str01.rfind(str03, 12); csz01 = str01.rfind(str03, 12);
test &= csz01 == 8; VERIFY( csz01 == 8 );
// An empty string consists of no characters // An empty string consists of no characters
// therefore it should be found at every point in a string, // therefore it should be found at every point in a string,
// except beyond the end // except beyond the end
csz01 = str01.rfind(str04, 0); csz01 = str01.rfind(str04, 0);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.rfind(str04, 5); csz01 = str01.rfind(str04, 5);
test &= csz01 == 5; VERIFY( csz01 == 5 );
csz01 = str01.rfind(str04, str01.size()); csz01 = str01.rfind(str04, str01.size());
test &= csz01 == str01.size(); VERIFY( csz01 == str01.size() );
csz01 = str01.rfind(str04, str01.size()+1); csz01 = str01.rfind(str04, str01.size()+1);
test &= csz01 == str01.size(); VERIFY( csz01 == str01.size() );
// size_type rfind(const char* s, size_type pos, size_type n) const; // size_type rfind(const char* s, size_type pos, size_type n) const;
csz01 = str01.rfind(str_lit01, 0, 3); csz01 = str01.rfind(str_lit01, 0, 3);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.rfind(str_lit01, 3, 0); csz01 = str01.rfind(str_lit01, 3, 0);
test &= csz01 == 3; VERIFY( csz01 == 3 );
// size_type rfind(const char* s, size_type pos = 0) const; // size_type rfind(const char* s, size_type pos = 0) const;
csz01 = str01.rfind(str_lit01); csz01 = str01.rfind(str_lit01);
test &= csz01 == 0; VERIFY( csz01 == 0 );
csz01 = str01.rfind(str_lit01, 3); csz01 = str01.rfind(str_lit01, 3);
test &= csz01 == 0; VERIFY( csz01 == 0 );
// size_type rfind(char c, size_type pos = 0) const; // size_type rfind(char c, size_type pos = 0) const;
csz01 = str01.rfind('z'); csz01 = str01.rfind('z');
csz02 = str01.size() - 1; csz02 = str01.size() - 1;
test &= csz01 == csz02; VERIFY( csz01 == csz02 );
csz01 = str01.rfind('/'); csz01 = str01.rfind('/');
test &= csz01 == npos; VERIFY( csz01 == npos );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -43,30 +41,30 @@ bool test01(void)
// substr(size_type pos = 0, size_type n = npos) const; // substr(size_type pos = 0, size_type n = npos) const;
csz01 = str01.size(); csz01 = str01.size();
str02 = str01.substr(0, 1); str02 = str01.substr(0, 1);
test &= str02 == "r"; VERIFY( str02 == "r" );
str02 = str01.substr(10); str02 = str01.substr(10);
test &= str02 == "pacifica"; VERIFY( str02 == "pacifica" );
try { try {
str02 = str01.substr(csz01 + 1); str02 = str01.substr(csz01 + 1);
test &= false; VERIFY( false );
} }
catch(std::out_of_range& fail) { catch(std::out_of_range& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
try { try {
str02 = str01.substr(csz01); str02 = str01.substr(csz01);
test &= str02.size() == 0; VERIFY( str02.size() == 0 );
} }
catch(std::out_of_range& fail) { catch(std::out_of_range& fail) {
test &= false; VERIFY( false );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -31,9 +31,7 @@
#include <locale> #include <locale>
// NB: Don't include any other headers in this file. // NB: Don't include any other headers in this file.
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
class gnu_ctype: public std::ctype<char> {}; class gnu_ctype: public std::ctype<char> {};
@ -59,37 +57,37 @@ void test01()
char c_array[len + 1]; char c_array[len + 1];
// bool is(mask m, char c) const; // bool is(mask m, char c) const;
test &= gctype.is(std::ctype_base::space, c30); VERIFY( gctype.is(std::ctype_base::space, c30) );
test &= gctype.is(std::ctype_base::upper, c00); VERIFY( gctype.is(std::ctype_base::upper, c00) );
test &= gctype.is(std::ctype_base::lower, c10); VERIFY( gctype.is(std::ctype_base::lower, c10) );
test &= gctype.is(std::ctype_base::digit, c20); VERIFY( gctype.is(std::ctype_base::digit, c20) );
test &= gctype.is(std::ctype_base::punct, c40); VERIFY( gctype.is(std::ctype_base::punct, c40) );
test &= gctype.is(std::ctype_base::alpha, c50); VERIFY( gctype.is(std::ctype_base::alpha, c50) );
test &= gctype.is(std::ctype_base::alpha, c60); VERIFY( gctype.is(std::ctype_base::alpha, c60) );
test &= gctype.is(std::ctype_base::xdigit, c20); VERIFY( gctype.is(std::ctype_base::xdigit, c20) );
test &= !gctype.is(std::ctype_base::xdigit, c80); VERIFY( !gctype.is(std::ctype_base::xdigit, c80) );
test &= gctype.is(std::ctype_base::alnum, c50); VERIFY( gctype.is(std::ctype_base::alnum, c50) );
test &= gctype.is(std::ctype_base::alnum, c20); VERIFY( gctype.is(std::ctype_base::alnum, c20) );
test &= gctype.is(std::ctype_base::graph, c40); VERIFY( gctype.is(std::ctype_base::graph, c40) );
test &= gctype.is(std::ctype_base::graph, c20); VERIFY( gctype.is(std::ctype_base::graph, c20) );
// char toupper(char c) const // char toupper(char c) const
c100 = gctype.toupper(c10); c100 = gctype.toupper(c10);
test &= c100 == c00; VERIFY( c100 == c00 );
// char tolower(char c) const // char tolower(char c) const
c100 = gctype.tolower(c00); c100 = gctype.tolower(c00);
test &= c100 == c10; VERIFY( c100 == c10 );
// char toupper(char* low, const char* hi) const // char toupper(char* low, const char* hi) const
std::char_traits<char>::copy(c_array, strlit02, len + 1); std::char_traits<char>::copy(c_array, strlit02, len + 1);
gctype.toupper(c_array, c_array + len); gctype.toupper(c_array, c_array + len);
test &= !std::char_traits<char>::compare(c_array, strlit01, len - 1); VERIFY( !std::char_traits<char>::compare(c_array, strlit01, len - 1) );
// char tolower(char* low, const char* hi) const // char tolower(char* low, const char* hi) const
std::char_traits<char>::copy(c_array, strlit01, len + 1); std::char_traits<char>::copy(c_array, strlit01, len + 1);
gctype.tolower(c_array, c_array + len); gctype.tolower(c_array, c_array + len);
test &= !std::char_traits<char>::compare(c_array, strlit02, len - 1); VERIFY( !std::char_traits<char>::compare(c_array, strlit02, len - 1) );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <bitset> #include <bitset>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -34,15 +32,15 @@ bool test01(void)
const size_t n1 = 5; const size_t n1 = 5;
std::bitset<n1> bit01; std::bitset<n1> bit01;
for (int i = 0; i < n1; ++i) for (int i = 0; i < n1; ++i)
test &= !bit01.test(i); VERIFY( !bit01.test(i) );
// bitset(unsigned long) // bitset(unsigned long)
const size_t n2 = 32; const size_t n2 = 32;
unsigned long ul1 = 2; unsigned long ul1 = 2;
std::bitset<n2> bit02(ul1); std::bitset<n2> bit02(ul1);
test &= !bit02.test(0); VERIFY( !bit02.test(0) );
test &= bit02.test(1); VERIFY( bit02.test(1) );
test &= !bit02.test(2); VERIFY( !bit02.test(2) );
// template<_CharT, _Traits, _Alloc> // template<_CharT, _Traits, _Alloc>
// explicit bitset(const basic_string<_C,_T,_A>&, size_type pos, size_type n) // explicit bitset(const basic_string<_C,_T,_A>&, size_type pos, size_type n)
@ -52,10 +50,10 @@ bool test01(void)
std::bitset<n3> bit03(str01, 5); std::bitset<n3> bit03(str01, 5);
} }
catch(std::invalid_argument& fail) { catch(std::invalid_argument& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test&= false; VERIFY( false );
} }
std::string str02("010101000011"); std::string str02("010101000011");
@ -66,13 +64,13 @@ bool test01(void)
for (int i = 0; i < sz; ++i) for (int i = 0; i < sz; ++i)
str03 += (bit03.test(i) ? '1' : '0'); str03 += (bit03.test(i) ? '1' : '0');
std::reverse(str03.begin(), str03.end()); std::reverse(str03.begin(), str03.end());
test &= str03 == str02; VERIFY( str03 == str02 );
} }
catch(std::invalid_argument& fail) { catch(std::invalid_argument& fail) {
test &= false; VERIFY( false );
} }
catch(...) { catch(...) {
test&= false; VERIFY( false );
} }

View File

@ -22,9 +22,7 @@
#include <set> #include <set>
#include <bitset> #include <bitset>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
static char original_bits[1024]; static char original_bits[1024];
static char left_shifted[1024]; static char left_shifted[1024];
@ -78,13 +76,13 @@ template <size_t size>
shifted <<= shift_step; shifted <<= shift_step;
//correct = std::string(left_shifted); //correct = std::string(left_shifted);
correct = std::bitset<size> (std::string(left_shifted)); correct = std::bitset<size> (std::string(left_shifted));
test &= shifted == correct; VERIFY( shifted == correct );
shifted = original; shifted = original;
shifted >>= shift_step; shifted >>= shift_step;
//correct = std::string(right_shifted); //correct = std::string(right_shifted);
correct = std::bitset<size> (std::string(right_shifted)); correct = std::bitset<size> (std::string(right_shifted));
test &= shifted == correct; VERIFY( shifted == correct );
} }
return test; return test;
@ -94,13 +92,13 @@ bool
test01() { test01() {
bool test = true; bool test = true;
test &= do_test<32>(); VERIFY( do_test<32>() );
test &= do_test<48>(); VERIFY( do_test<48>() );
test &= do_test<64>(); VERIFY( do_test<64>() );
test &= do_test<511>(); VERIFY( do_test<511>() );
test &= do_test<513>(); VERIFY( do_test<513>() );
test &= do_test<997>(); VERIFY( do_test<997>() );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -22,9 +22,7 @@
// 23.2.4.2 vector capacity // 23.2.4.2 vector capacity
#include <vector> #include <vector>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
template<typename T> template<typename T>
struct A { }; struct A { };
@ -42,17 +40,17 @@ bool test01()
size_type sz01 = vec01.capacity(); size_type sz01 = vec01.capacity();
vec01.reserve(100); vec01.reserve(100);
size_type sz02 = vec01.capacity(); size_type sz02 = vec01.capacity();
test &= sz02 >= sz01; VERIFY( sz02 >= sz01 );
sz01 = vec01.size() + 5; sz01 = vec01.size() + 5;
vec01.resize(sz01); vec01.resize(sz01);
sz02 = vec01.size(); sz02 = vec01.size();
test &= sz01 == sz02; VERIFY( sz01 == sz02 );
sz01 = vec01.size() - 5; sz01 = vec01.size() - 5;
vec01.resize(sz01); vec01.resize(sz01);
sz02 = vec01.size(); sz02 = vec01.size();
test &= sz01 == sz02; VERIFY( sz01 == sz02 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -22,9 +22,7 @@
// 23.2.4.1 vector constructors, copy, and assignment // 23.2.4.1 vector constructors, copy, and assignment
#include <vector> #include <vector>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
template<typename T> template<typename T>
struct A { }; struct A { };

View File

@ -21,9 +21,7 @@
// 23.2.4.3 vector modifiers // 23.2.4.3 vector modifiers
#include <vector> #include <vector>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
template<typename T> template<typename T>
struct A { }; struct A { };

View File

@ -22,9 +22,7 @@
#include <sstream> #include <sstream>
#include <iterator> #include <iterator>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -41,55 +39,55 @@ bool test01(void)
cistreambuf_iter istrb_it01(istrs00); cistreambuf_iter istrb_it01(istrs00);
cistreambuf_iter istrb_it02; cistreambuf_iter istrb_it02;
std::string tmp(istrb_it01, istrb_it02); std::string tmp(istrb_it01, istrb_it02);
test &= tmp == str01; VERIFY( tmp == str01 );
cistreambuf_iter istrb_it03(0); cistreambuf_iter istrb_it03(0);
cistreambuf_iter istrb_it04; cistreambuf_iter istrb_it04;
test &= istrb_it03 == istrb_it04; VERIFY( istrb_it03 == istrb_it04 );
cistreambuf_iter istrb_it05(istrs01); cistreambuf_iter istrb_it05(istrs01);
cistreambuf_iter istrb_it06(istrs01.rdbuf()); cistreambuf_iter istrb_it06(istrs01.rdbuf());
test &= istrb_it05 == istrb_it06; VERIFY( istrb_it05 == istrb_it06 );
// bool equal(istreambuf_iter& b) // bool equal(istreambuf_iter& b)
cistreambuf_iter istrb_it07(0); cistreambuf_iter istrb_it07(0);
cistreambuf_iter istrb_it08; cistreambuf_iter istrb_it08;
test &= istrb_it07.equal(istrb_it08); VERIFY( istrb_it07.equal(istrb_it08) );
cistreambuf_iter istrb_it09(0); cistreambuf_iter istrb_it09(0);
cistreambuf_iter istrb_it10; cistreambuf_iter istrb_it10;
test &= istrb_it10.equal(istrb_it09); VERIFY( istrb_it10.equal(istrb_it09) );
cistreambuf_iter istrb_it11(istrs01); cistreambuf_iter istrb_it11(istrs01);
cistreambuf_iter istrb_it12(istrs01.rdbuf()); cistreambuf_iter istrb_it12(istrs01.rdbuf());
test &= istrb_it11.equal(istrb_it12); VERIFY( istrb_it11.equal(istrb_it12) );
cistreambuf_iter istrb_it13(istrs01); cistreambuf_iter istrb_it13(istrs01);
cistreambuf_iter istrb_it14(istrs01.rdbuf()); cistreambuf_iter istrb_it14(istrs01.rdbuf());
test &= istrb_it14.equal(istrb_it13); VERIFY( istrb_it14.equal(istrb_it13) );
cistreambuf_iter istrb_it15(istrs01); cistreambuf_iter istrb_it15(istrs01);
cistreambuf_iter istrb_it16; cistreambuf_iter istrb_it16;
test &= !(istrb_it15.equal(istrb_it16)); VERIFY( !(istrb_it15.equal(istrb_it16)) );
cistreambuf_iter istrb_it17(istrs01); cistreambuf_iter istrb_it17(istrs01);
cistreambuf_iter istrb_it18; cistreambuf_iter istrb_it18;
test &= !(istrb_it18.equal(istrb_it17)); VERIFY( !(istrb_it18.equal(istrb_it17)) );
// bool operator==(const istreambuf_iterator&a, const istreambuf_iterator& b) // bool operator==(const istreambuf_iterator&a, const istreambuf_iterator& b)
// bool operator!=(const istreambuf_iterator&a, const istreambuf_iterator& b) // bool operator!=(const istreambuf_iterator&a, const istreambuf_iterator& b)
cistreambuf_iter istrb_it19(0); cistreambuf_iter istrb_it19(0);
cistreambuf_iter istrb_it20; cistreambuf_iter istrb_it20;
test &= istrb_it19 == istrb_it20; VERIFY( istrb_it19 == istrb_it20 );
cistreambuf_iter istrb_it21(istrs01); cistreambuf_iter istrb_it21(istrs01);
cistreambuf_iter istrb_it22(istrs01.rdbuf()); cistreambuf_iter istrb_it22(istrs01.rdbuf());
test &= istrb_it22 == istrb_it21; VERIFY( istrb_it22 == istrb_it21 );
cistreambuf_iter istrb_it23(istrs01); cistreambuf_iter istrb_it23(istrs01);
cistreambuf_iter istrb_it24; cistreambuf_iter istrb_it24;
test &= istrb_it23 != istrb_it24; VERIFY( istrb_it23 != istrb_it24 );
cistreambuf_iter istrb_it25(0); cistreambuf_iter istrb_it25(0);
cistreambuf_iter istrb_it26(istrs01.rdbuf()); cistreambuf_iter istrb_it26(istrs01.rdbuf());
test &= istrb_it25 != istrb_it26; VERIFY( istrb_it25 != istrb_it26 );
// charT operator*() const // charT operator*() const
// istreambuf_iterator& operator++(); // istreambuf_iterator& operator++();
@ -99,7 +97,7 @@ bool test01(void)
for (int i = 0; i < sizeof(slit01) - 2; ++i) for (int i = 0; i < sizeof(slit01) - 2; ++i)
{ {
c = *istrb_it27++; c = *istrb_it27++;
test &= c == slit01[i]; VERIFY( c == slit01[i] );
} }
std::istringstream istrs02(str01); std::istringstream istrs02(str01);
@ -107,7 +105,7 @@ bool test01(void)
for (int i = 0; i < sizeof(slit01) - 3;) for (int i = 0; i < sizeof(slit01) - 3;)
{ {
c = *++istrb_it28; c = *++istrb_it28;
test &= c == slit01[++i]; VERIFY( c == slit01[++i] );
} }
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -21,11 +21,10 @@
#include <string> #include <string>
#include <vector> #include <vector>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
int string_stuff() int
string_stuff()
{ {
int failures(0); int failures(0);
@ -250,7 +249,8 @@ int string_stuff()
return failures; return failures;
} }
int vector_stuff() int
vector_stuff()
{ {
int failures(0); int failures(0);
@ -487,7 +487,8 @@ int vector_stuff()
return failures; return failures;
} }
int reverse_stuff() int
reverse_stuff()
{ {
int failures(0); int failures(0);
@ -512,7 +513,8 @@ int reverse_stuff()
// the following should be compiler errors // the following should be compiler errors
// flag runtime errors in case they slip through the compiler // flag runtime errors in case they slip through the compiler
int wrong_stuff() int
wrong_stuff()
{ {
int failures(0); int failures(0);
@ -575,7 +577,8 @@ int wrong_stuff()
return failures; return failures;
} }
int main(int argc, char **argv) int
main(int argc, char **argv)
{ {
int failures(0); int failures(0);
@ -594,6 +597,3 @@ int main(int argc, char **argv)
return failures ? 1 : 0; return failures ? 1 : 0;
} }

View File

@ -17,9 +17,7 @@
// USA. // USA.
#include <algorithm> #include <algorithm>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
// http://sourceware.cygnus.com/ml/libstdc++/2000-06/msg00316.html // http://sourceware.cygnus.com/ml/libstdc++/2000-06/msg00316.html
struct foo { }; struct foo { };

View File

@ -19,22 +19,20 @@
// USA. // USA.
#include <algorithm> #include <algorithm>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
void test01() void test01()
{ {
bool test = true; bool test = true;
const int& x = std::max(1, 2); const int& x = std::max(1, 2);
const int& y = std::max(3, 4); const int& y = std::max(3, 4);
test &= x == 2; VERIFY( x == 2 );
test &= y == 4; VERIFY( y == 4 );
const int& z = std::min(1, 2); const int& z = std::min(1, 2);
const int& w = std::min(3, 4); const int& w = std::min(3, 4);
test &= z == 1; VERIFY( z == 1 );
test &= w == 3; VERIFY( w == 3 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -20,38 +20,48 @@
// USA. // USA.
#include <cmath> #include <cmath>
#include <cassert> #include <debug_assert.h>
// test compilation. // test compilation.
void test01() int
test01()
{ {
float a = 1.f; float a = 1.f;
float b; float b;
std::modf(a, &b); std::modf(a, &b);
return 0;
} }
// need more extravagant checks than this, of course, but this used to core... // need more extravagant checks than this, of course, but this used to core...
void test02() int
test02()
{ {
sin(static_cast<float>(0)); sin(static_cast<float>(0));
return 0;
} }
// as did this. // as did this.
void test03() int
test03()
{ {
double powtest = pow(2., 0); double powtest = pow(2., 0);
return 0;
} }
// this used to abort. // this used to abort.
void test04() int
test04()
{ {
bool test = true;
float x[2] = {1, 2}; float x[2] = {1, 2};
float y = 3.4; float y = 3.4;
std::modf(y, &x[0]); std::modf(y, &x[0]);
assert (x[1] == 2); VERIFY(x[1] == 2);
return 0;
} }
int main() int
main()
{ {
test01(); test01();
test02(); test02();
@ -59,3 +69,4 @@ int main()
test04(); test04();
return 0; return 0;
} }

View File

@ -24,9 +24,7 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <complex> #include <complex>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
#include <cmath> #include <cmath>
template<typename R> template<typename R>
@ -37,25 +35,28 @@ inline bool flteq(R x, R y)
} }
template<typename R> template<typename R>
void test_good(std::string str, R x, R y) int
test_good(std::string str, R x, R y)
{ {
bool test = true; bool test = true;
std::complex<R> z; std::complex<R> z;
char ch; char ch;
std::istringstream iss(str); std::istringstream iss(str);
iss >> z >> ch; iss >> z >> ch;
test &= iss.good(); VERIFY( iss.good() );
test &= flteq(z.real(), x); VERIFY( flteq(z.real(), x) );
test &= flteq(z.imag(), y); VERIFY( flteq(z.imag(), y) );
test &= ch == '#'; VERIFY( ch == '#' );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return 0;
} }
template<typename R> template<typename R>
void test_fail(std::string str) int
test_fail(std::string str)
{ {
std::complex<R> z; std::complex<R> z;
std::istringstream iss(str); std::istringstream iss(str);
@ -63,10 +64,12 @@ void test_fail(std::string str)
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(iss.fail() && !iss.bad()); assert(iss.fail() && !iss.bad());
#endif #endif
return 0;
} }
template<typename R> template<typename R>
void testall() int
testall()
{ {
test_good<R>("(-1.1,3.7)#", -1.1, 3.7); test_good<R>("(-1.1,3.7)#", -1.1, 3.7);
test_good<R>("( .7e6 , \n-3.1)#", .7e6, -3.1); test_good<R>("( .7e6 , \n-3.1)#", .7e6, -3.1);
@ -82,9 +85,11 @@ void testall()
test_fail<R>("|1,1)"); test_fail<R>("|1,1)");
test_fail<R>("(1|1)"); test_fail<R>("(1|1)");
test_fail<R>("(1,1|"); test_fail<R>("(1,1|");
return 0;
} }
int main() int
main()
{ {
testall<float>(); testall<float>();
testall<double>(); testall<double>();
@ -92,5 +97,3 @@ int main()
return 0; return 0;
} }

View File

@ -23,9 +23,7 @@
// simulated a bit more readily. // simulated a bit more readily.
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
const char carray_01[] = "santa cruz or sandiego?"; const char carray_01[] = "santa cruz or sandiego?";
const char carray_02[] = "memphis, new orleans, and savanah"; const char carray_02[] = "memphis, new orleans, and savanah";
@ -72,9 +70,9 @@ bool test02() {
bool test = true; bool test = true;
// bool is_open() // bool is_open()
test &= !fb_01.is_open(); VERIFY( !fb_01.is_open() );
test &= !fb_02.is_open(); VERIFY( !fb_02.is_open() );
test &= !fb_03.is_open(); VERIFY( !fb_03.is_open() );
// filebuf_type* open(const char* __s, ios_base::openmode __mode) // filebuf_type* open(const char* __s, ios_base::openmode __mode)
fb_01.open(name_01, std::ios_base::in | std::ios_base::ate); fb_01.open(name_01, std::ios_base::in | std::ios_base::ate);
@ -83,17 +81,17 @@ bool test02() {
// Should keep the old file attached, and disregard attempt to overthrow. // Should keep the old file attached, and disregard attempt to overthrow.
fb_02.open(name_03, std::ios_base::in | std::ios_base::out); fb_02.open(name_03, std::ios_base::in | std::ios_base::out);
fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc); fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc);
test &= fb_01.is_open(); VERIFY( fb_01.is_open() );
test &= fb_02.is_open(); VERIFY( fb_02.is_open() );
test &= fb_03.is_open(); VERIFY( fb_03.is_open() );
// filebuf_type* close() // filebuf_type* close()
fb_01.close(); fb_01.close();
fb_02.close(); fb_02.close();
fb_03.close(); fb_03.close();
test &= !fb_01.is_open(); VERIFY( !fb_01.is_open() );
test &= !fb_02.is_open(); VERIFY( !fb_02.is_open() );
test &= !fb_03.is_open(); VERIFY( !fb_03.is_open() );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -131,35 +129,35 @@ bool test03() {
// else return showmanyc. // else return showmanyc.
strmof_1 = fb_01.in_avail(); strmof_1 = fb_01.in_avail();
strmof_2 = fb_02.in_avail(); strmof_2 = fb_02.in_avail();
test &= strmof_1 == -1; VERIFY( strmof_1 == -1 );
test &= strmof_1 == strmof_2; //fail because not open VERIFY( strmof_1 == strmof_2 ); //fail because not open
strmof_1 = fb_03.in_avail(); strmof_1 = fb_03.in_avail();
test &= strmof_1 == strmof_2; VERIFY( strmof_1 == strmof_2 );
fb_01.open(name_01, std::ios_base::in); fb_01.open(name_01, std::ios_base::in);
fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc);
fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc);
strmof_1 = fb_01.in_avail(); strmof_1 = fb_01.in_avail();
strmof_2 = fb_02.in_avail(); strmof_2 = fb_02.in_avail();
test &= strmof_1 != strmof_2; VERIFY( strmof_1 != strmof_2 );
test &= strmof_1 >= 0; VERIFY( strmof_1 >= 0 );
test &= strmof_2 == -1; // empty file VERIFY( strmof_2 == -1 ); // empty file
strmof_1 = fb_03.in_avail(); strmof_1 = fb_03.in_avail();
test &= strmof_1 == -1; // empty file VERIFY( strmof_1 == -1 ); // empty file
// int_type sbumpc() // int_type sbumpc()
// if read_cur not avail returns uflow(), else return *read_cur & increment // if read_cur not avail returns uflow(), else return *read_cur & increment
int_type c1 = fb_01.sbumpc(); int_type c1 = fb_01.sbumpc();
int_type c2 = fb_02.sbumpc(); int_type c2 = fb_02.sbumpc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c1 == '/'; VERIFY( c1 == '/' );
test &= c2 == -1; VERIFY( c2 == -1 );
int_type c3 = fb_01.sbumpc(); int_type c3 = fb_01.sbumpc();
int_type c4 = fb_02.sbumpc(); int_type c4 = fb_02.sbumpc();
test &= c3 != c4; VERIFY( c3 != c4 );
test &= c1 == c3; // fluke, both happen to be '/' VERIFY( c1 == c3 ); // fluke, both happen to be '/'
test &= c2 == c4; VERIFY( c2 == c4 );
int_type c5 = fb_03.sbumpc(); int_type c5 = fb_03.sbumpc();
test &= c5 == traits_type::eof(); VERIFY( c5 == traits_type::eof() );
// XXX should do some kind of test to make sure that internal // XXX should do some kind of test to make sure that internal
// buffers point ot the same thing, to check consistancy. // buffers point ot the same thing, to check consistancy.
@ -167,29 +165,29 @@ bool test03() {
// if read_cur not avail, return uflow(), else return *read_cur // if read_cur not avail, return uflow(), else return *read_cur
int_type c6 = fb_01.sgetc(); int_type c6 = fb_01.sgetc();
int_type c7 = fb_02.sgetc(); int_type c7 = fb_02.sgetc();
test &= c6 != c3; VERIFY( c6 != c3 );
test &= c7 == c4; // both -1 VERIFY( c7 == c4 ); // both -1
int_type c8 = fb_01.sgetc(); int_type c8 = fb_01.sgetc();
int_type c9 = fb_02.sgetc(); int_type c9 = fb_02.sgetc();
test &= c6 == c8; VERIFY( c6 == c8 );
test &= c7 == c9; VERIFY( c7 == c9 );
c5 = fb_03.sgetc(); c5 = fb_03.sgetc();
test &= c5 == traits_type::eof(); VERIFY( c5 == traits_type::eof() );
// int_type snextc() // int_type snextc()
// calls sbumpc and if sbumpc != eof, return sgetc // calls sbumpc and if sbumpc != eof, return sgetc
c6 = fb_01.snextc(); c6 = fb_01.snextc();
c7 = fb_02.snextc(); c7 = fb_02.snextc();
test &= c6 != c8; VERIFY( c6 != c8 );
test &= c7 == c9; // -1 VERIFY( c7 == c9 ); // -1
test &= c6 == '9'; VERIFY( c6 == '9' );
c6 = fb_01.snextc(); c6 = fb_01.snextc();
c7 = fb_02.snextc(); c7 = fb_02.snextc();
test &= c6 != c8; VERIFY( c6 != c8 );
test &= c7 == c9; // -1 VERIFY( c7 == c9 ); // -1
test &= c6 == '9'; VERIFY( c6 == '9' );
c5 = fb_03.snextc(); c5 = fb_03.snextc();
test &= c5 == traits_type::eof(); VERIFY( c5 == traits_type::eof() );
// streamsize sgetn(char_type *s, streamsize n) // streamsize sgetn(char_type *s, streamsize n)
// streamsize xsgetn(char_type *s, streamsize n) // streamsize xsgetn(char_type *s, streamsize n)
@ -202,30 +200,30 @@ bool test03() {
strmsz_1 = fb_01.sgetn(carray1, 10); strmsz_1 = fb_01.sgetn(carray1, 10);
char carray2[buffer_size] = ""; char carray2[buffer_size] = "";
strmsz_2 = fb_02.sgetn(carray2, 10); strmsz_2 = fb_02.sgetn(carray2, 10);
test &= strmsz_1 != strmsz_2; VERIFY( strmsz_1 != strmsz_2 );
test &= strmsz_1 == 10; VERIFY( strmsz_1 == 10 );
test &= strmsz_2 == 0; VERIFY( strmsz_2 == 0 );
c1 = fb_01.sgetc(); c1 = fb_01.sgetc();
c2 = fb_02.sgetc(); c2 = fb_02.sgetc();
test &= c1 == '\n'; VERIFY( c1 == '\n' );
test &= c7 == c2; // n != i VERIFY( c7 == c2 ); // n != i
strmsz_1 = fb_03.sgetn(carray1, 10); strmsz_1 = fb_03.sgetn(carray1, 10);
test &= !strmsz_1; //zero VERIFY( !strmsz_1 ); //zero
strmsz_1 = fb_01.in_avail(); strmsz_1 = fb_01.in_avail();
strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5);
test &= strmsz_1 == strmsz_2 - 5; VERIFY( strmsz_1 == strmsz_2 - 5 );
c4 = fb_01.sgetc(); // buffer should have underflowed from above. c4 = fb_01.sgetc(); // buffer should have underflowed from above.
test &= c4 == 'i'; VERIFY( c4 == 'i' );
strmsz_1 = fb_01.in_avail(); strmsz_1 = fb_01.in_avail();
test &= strmsz_1 > 0; VERIFY( strmsz_1 > 0 );
strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5);
test &= strmsz_1 == strmsz_2; //at the end of the actual file VERIFY( strmsz_1 == strmsz_2 ); //at the end of the actual file
strmsz_1 = fb_02.in_avail(); strmsz_1 = fb_02.in_avail();
strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5); strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5);
test &= strmsz_1 == -1; VERIFY( strmsz_1 == -1 );
test &= strmsz_2 == 0; VERIFY( strmsz_2 == 0 );
c4 = fb_02.sgetc(); // should be EOF c4 = fb_02.sgetc(); // should be EOF
test &= c4 == traits_type::eof(); VERIFY( c4 == traits_type::eof() );
// PUT // PUT
// int_type sputc(char_type c) // int_type sputc(char_type c)
@ -235,12 +233,12 @@ bool test03() {
// strmsz_1 = fb_03.in_avail(); // XXX valid for in|out?? // strmsz_1 = fb_03.in_avail(); // XXX valid for in|out??
c1 = fb_02.sputc('a'); c1 = fb_02.sputc('a');
c2 = fb_03.sputc('b'); c2 = fb_03.sputc('b');
test &= c1 != c2; VERIFY( c1 != c2 );
c1 = fb_02.sputc('c'); c1 = fb_02.sputc('c');
c2 = fb_03.sputc('d'); c2 = fb_03.sputc('d');
test &= c1 != c2; VERIFY( c1 != c2 );
// strmsz_2 = fb_03.in_avail(); // strmsz_2 = fb_03.in_avail();
// test &= strmsz_1 != strmsz_2; // VERIFY( strmsz_1 != strmsz_2 );
for (int i = 50; i <= 90; ++i) for (int i = 50; i <= 90; ++i)
c2 = fb_02.sputc(char(i)); c2 = fb_02.sputc(char(i));
// 27filebuf-2.txt == ac23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX // 27filebuf-2.txt == ac23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX
@ -249,30 +247,30 @@ bool test03() {
for (int i = 50; i <= 90; ++i) for (int i = 50; i <= 90; ++i)
c2 = fb_03.sputc(char(i)); c2 = fb_03.sputc(char(i));
strmsz_2 = fb_03.in_avail(); strmsz_2 = fb_03.in_avail();
// test &= strmsz_1 != strmsz_2; // VERIFY( strmsz_1 != strmsz_2 );
// test &= strmsz_1 > 0; // VERIFY( strmsz_1 > 0 );
// test &= strmsz_2 > 0; // VERIFY( strmsz_2 > 0 );
// 27filebuf-2.txt == bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX // 27filebuf-2.txt == bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX
// fb_02._M_out_cur = '2' // fb_02._M_out_cur = '2'
c3 = fb_01.sputc('a'); // should be EOF because this is read-only c3 = fb_01.sputc('a'); // should be EOF because this is read-only
test &= c3 == traits_type::eof(); VERIFY( c3 == traits_type::eof() );
// streamsize sputn(const char_typs* s, streamsize n) // streamsize sputn(const char_typs* s, streamsize n)
// write up to n chars to out_cur from s, returning number assigned // write up to n chars to out_cur from s, returning number assigned
// NB *sputn will happily put '\0' into your stream if you give it a chance* // NB *sputn will happily put '\0' into your stream if you give it a chance*
strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?" strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?"
test &= strmsz_1 == 10; VERIFY( strmsz_1 == 10 );
strmsz_2 = fb_03.sputn(", i wanna reach out and", 10); strmsz_2 = fb_03.sputn(", i wanna reach out and", 10);
test &= strmsz_2 == 10; VERIFY( strmsz_2 == 10 );
test &= strmsz_1 == strmsz_2; VERIFY( strmsz_1 == strmsz_2 );
// fb_03._M_out_beg = "YZracadabras, i wanna FGHIJKLMNOPQRSTUVW" // fb_03._M_out_beg = "YZracadabras, i wanna FGHIJKLMNOPQRSTUVW"
// fb_03._M_out_cur = "FGHIJKLMNOPQRSTUVW" // fb_03._M_out_cur = "FGHIJKLMNOPQRSTUVW"
strmsz_1 = fb_02.sputn("racadabras", 10); strmsz_1 = fb_02.sputn("racadabras", 10);
test &= strmsz_1 == 10; VERIFY( strmsz_1 == 10 );
// fb_02._M_out_beg = "YZracadabras<=>?@ABCDEFGHIJKLMNOPQRSTUVW" // fb_02._M_out_beg = "YZracadabras<=>?@ABCDEFGHIJKLMNOPQRSTUVW"
// fb_02._M_out_cur = "<=>?@ABCDEFGHIJKLMNOPQRSTUVW" // fb_02._M_out_cur = "<=>?@ABCDEFGHIJKLMNOPQRSTUVW"
strmsz_1 = fb_01.sputn("racadabra", 10); strmsz_1 = fb_01.sputn("racadabra", 10);
test &= strmsz_1 == 0; VERIFY( strmsz_1 == 0 );
// PUTBACK // PUTBACK
// int_type pbfail(int_type c) // int_type pbfail(int_type c)
@ -293,9 +291,9 @@ bool test03() {
c2 = fb_03.sputbackc('z'); c2 = fb_03.sputbackc('z');
strmsz_2 = fb_03.in_avail(); strmsz_2 = fb_03.in_avail();
c3 = fb_03.sgetc(); c3 = fb_03.sgetc();
test &= c3 == c2; VERIFY( c3 == c2 );
test &= c1 != c3; VERIFY( c1 != c3 );
test &= 1 == strmsz_2; VERIFY( 1 == strmsz_2 );
//test for _in_cur == _in_beg //test for _in_cur == _in_beg
// fb_03._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc // fb_03._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc
fb_03.pubseekoff(10, std::ios_base::beg, fb_03.pubseekoff(10, std::ios_base::beg,
@ -307,11 +305,11 @@ bool test03() {
c2 = fb_03.sputbackc('z'); c2 = fb_03.sputbackc('z');
strmsz_2 = fb_03.in_avail(); strmsz_2 = fb_03.in_avail();
c3 = fb_03.sgetc(); c3 = fb_03.sgetc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c3 == c2; VERIFY( c3 == c2 );
test &= c1 != c3; VERIFY( c1 != c3 );
test &= c2 == 'z'; VERIFY( c2 == 'z' );
test &= strmsz_1 == strmsz_2; VERIFY( strmsz_1 == strmsz_2 );
// test for replacing char with identical one // test for replacing char with identical one
fb_03.snextc(); fb_03.snextc();
fb_03.sputc('u'); fb_03.sputc('u');
@ -321,13 +319,13 @@ bool test03() {
c2 = fb_03.sputbackc('a'); c2 = fb_03.sputbackc('a');
strmsz_2 = fb_03.in_avail(); strmsz_2 = fb_03.in_avail();
c3 = fb_03.sgetc(); c3 = fb_03.sgetc();
test &= c3 == c2; VERIFY( c3 == c2 );
test &= strmsz_1 + 1 == strmsz_2; VERIFY( strmsz_1 + 1 == strmsz_2 );
//test for ios_base::out //test for ios_base::out
c1 = fb_02.sgetc(); // undefined c1 = fb_02.sgetc(); // undefined
c2 = fb_02.sputbackc('a'); c2 = fb_02.sputbackc('a');
test &= c1 == c2; VERIFY( c1 == c2 );
test &= c1 == -1; VERIFY( c1 == -1 );
// int_type sungetc() // int_type sungetc()
// if in_cur not avail, return pbackfail(), else decrement and // if in_cur not avail, return pbackfail(), else decrement and
@ -337,8 +335,8 @@ bool test03() {
strmsz_1 = fb_03.in_avail(); strmsz_1 = fb_03.in_avail();
c2 = fb_03.sungetc(); // delete the 'a' c2 = fb_03.sungetc(); // delete the 'a'
strmsz_2 = fb_03.in_avail(); strmsz_2 = fb_03.in_avail();
test &= c2 == 'v'; // test &= c2 != traits_type::eof(); VERIFY( c2 == 'v' ); // VERIFY( c2 != traits_type::eof() );
test &= strmsz_1 + 1 == strmsz_2; VERIFY( strmsz_1 + 1 == strmsz_2 );
//test for _in_cur == _in_beg //test for _in_cur == _in_beg
for (int i = 50; i < 32 + 29; ++i) for (int i = 50; i < 32 + 29; ++i)
fb_02.sputc(char(i)); fb_02.sputc(char(i));
@ -348,11 +346,11 @@ bool test03() {
c2 = fb_02.sungetc(); c2 = fb_02.sungetc();
strmsz_2 = fb_02.in_avail(); strmsz_2 = fb_02.in_avail();
c3 = fb_02.sgetc(); c3 = fb_02.sgetc();
test &= c1 == c2; VERIFY( c1 == c2 );
test &= c3 == c2; VERIFY( c3 == c2 );
test &= c1 == c3; VERIFY( c1 == c3 );
test &= c2 == traits_type::eof(); VERIFY( c2 == traits_type::eof() );
test &= strmsz_1 == strmsz_2; VERIFY( strmsz_1 == strmsz_2 );
//test for _in_cur == _in_end //test for _in_cur == _in_end
fb_03.pubseekoff(0, std::ios_base::end); fb_03.pubseekoff(0, std::ios_base::end);
strmsz_1 = fb_03.in_avail(); // -1 cuz at the end strmsz_1 = fb_03.in_avail(); // -1 cuz at the end
@ -360,10 +358,10 @@ bool test03() {
c2 = fb_03.sungetc(); c2 = fb_03.sungetc();
strmsz_2 = fb_03.in_avail(); // 1 strmsz_2 = fb_03.in_avail(); // 1
c3 = fb_03.sgetc(); c3 = fb_03.sgetc();
test &= c1 != c2; VERIFY( c1 != c2 );
// test &= c2 == c3 || c2 == traits_type::not_eof(int(c3)); // VERIFY( c2 == c3 || c2 == traits_type::not_eof(int(c3)) );
test &= strmsz_2 != strmsz_1; VERIFY( strmsz_2 != strmsz_1 );
test &= strmsz_2 == 1; VERIFY( strmsz_2 == 1 );
//test for ios_base::out //test for ios_base::out
// BUFFER MANAGEMENT & POSITIONING // BUFFER MANAGEMENT & POSITIONING
@ -373,21 +371,21 @@ bool test03() {
strmsz_1 = fb_01.in_avail(); strmsz_1 = fb_01.in_avail();
fb_01.pubsync(); fb_01.pubsync();
strmsz_2 = fb_01.in_avail(); strmsz_2 = fb_01.in_avail();
test &= strmsz_2 == strmsz_1; VERIFY( strmsz_2 == strmsz_1 );
strmsz_1 = fb_02.in_avail(); strmsz_1 = fb_02.in_avail();
fb_02.pubsync(); fb_02.pubsync();
// 27filebuf-2.txt == 53 bytes after this. // 27filebuf-2.txt == 53 bytes after this.
strmsz_2 = fb_02.in_avail(); strmsz_2 = fb_02.in_avail();
test &= strmsz_2 == -1; VERIFY( strmsz_2 == -1 );
test &= strmsz_2 == strmsz_1; VERIFY( strmsz_2 == strmsz_1 );
strmsz_1 = fb_03.in_avail(); strmsz_1 = fb_03.in_avail();
fb_03.pubsync(); fb_03.pubsync();
// 27filebuf-3.txt // 27filebuf-3.txt
// bd23456789mzuva?@ABCDEFGHIJKLMNOPQRSTUVWXYZracadabras, i wannaz // bd23456789mzuva?@ABCDEFGHIJKLMNOPQRSTUVWXYZracadabras, i wannaz
// 63 bytes. // 63 bytes.
strmsz_2 = fb_03.in_avail(); strmsz_2 = fb_03.in_avail();
test &= strmsz_1 == 1; VERIFY( strmsz_1 == 1 );
test &= strmsz_2 == 1; VERIFY( strmsz_2 == 1 );
// setbuf // setbuf
// pubsetbuf(char_type* s, streamsize n) // pubsetbuf(char_type* s, streamsize n)
@ -412,42 +410,42 @@ bool test03() {
pt_1 = fb_03.pubseekoff(2, std::ios_base::beg); pt_1 = fb_03.pubseekoff(2, std::ios_base::beg);
strmsz_2 = fb_03.in_avail(); strmsz_2 = fb_03.in_avail();
off_1 = pt_1; off_1 = pt_1;
test &= off_1 > 0; VERIFY( off_1 > 0 );
c1 = fb_03.snextc(); //current in pointer +1 c1 = fb_03.snextc(); //current in pointer +1
test &= c1 == '3'; VERIFY( c1 == '3' );
c2 = fb_03.sputc('\n'); //current in pointer +1 c2 = fb_03.sputc('\n'); //current in pointer +1
c3 = fb_03.sgetc(); c3 = fb_03.sgetc();
test &= c2 != c3; VERIFY( c2 != c3 );
test &= c3 == '4'; VERIFY( c3 == '4' );
fb_03.pubsync(); fb_03.pubsync();
c1 = fb_03.sgetc(); c1 = fb_03.sgetc();
test &= c1 == c3; VERIFY( c1 == c3 );
//cur //cur
// 27filebuf-3.txt = bd2\n456789:;<=>?... // 27filebuf-3.txt = bd2\n456789:;<=>?...
pt_2 = fb_03.pubseekoff(2, std::ios_base::cur); pt_2 = fb_03.pubseekoff(2, std::ios_base::cur);
off_2 = pt_2; off_2 = pt_2;
test &= (off_2 == (off_1 + 2 + 1 + 1)); VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
c1 = fb_03.snextc(); //current in pointer +1 c1 = fb_03.snextc(); //current in pointer +1
test &= c1 == '7'; VERIFY( c1 == '7' );
c2 = fb_03.sputc('x'); //test current out pointer c2 = fb_03.sputc('x'); //test current out pointer
c3 = fb_03.sputc('\n'); c3 = fb_03.sputc('\n');
c1 = fb_03.sgetc(); c1 = fb_03.sgetc();
fb_03.pubsync(); fb_03.pubsync();
c3 = fb_03.sgetc(); c3 = fb_03.sgetc();
test &= c1 == c3; VERIFY( c1 == c3 );
//end //end
// 27filebuf-3.txt = "bd2\n456x\n9" // 27filebuf-3.txt = "bd2\n456x\n9"
pt_2 = fb_03.pubseekoff(0, std::ios_base::end, pt_2 = fb_03.pubseekoff(0, std::ios_base::end,
std::ios_base::in|std::ios_base::out); std::ios_base::in|std::ios_base::out);
off_1 = pt_2; off_1 = pt_2;
test &= off_1 > off_2; //weak, but don't know exactly where it ends VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
c3 = fb_03.sputc('\n'); c3 = fb_03.sputc('\n');
strmsz_1 = fb_03.sputn("because because because. . .", 28); strmsz_1 = fb_03.sputn("because because because. . .", 28);
test &= strmsz_1 == 28; VERIFY( strmsz_1 == 28 );
c1 = fb_03.sungetc(); c1 = fb_03.sungetc();
fb_03.pubsync(); fb_03.pubsync();
c3 = fb_03.sgetc(); c3 = fb_03.sgetc();
test &= c1 == c3; VERIFY( c1 == c3 );
// IN // IN
// OUT // OUT
@ -459,20 +457,20 @@ bool test03() {
//beg //beg
pt_1 = fb_03.pubseekoff(78, std::ios_base::beg); pt_1 = fb_03.pubseekoff(78, std::ios_base::beg);
off_1 = pt_1; off_1 = pt_1;
test &= off_1 > 0; VERIFY( off_1 > 0 );
c1 = fb_03.snextc(); //current in pointer +1 c1 = fb_03.snextc(); //current in pointer +1
test &= c1 == ' '; VERIFY( c1 == ' ' );
c2 = fb_03.sputc('\n'); //test current out pointer c2 = fb_03.sputc('\n'); //test current out pointer
c3 = fb_03.sgetc(); c3 = fb_03.sgetc();
fb_03.pubsync(); //resets pointers fb_03.pubsync(); //resets pointers
pt_2 = fb_03.pubseekpos(pt_1); pt_2 = fb_03.pubseekpos(pt_1);
off_2 = pt_2; off_2 = pt_2;
test &= off_1 == off_2; VERIFY( off_1 == off_2 );
c3 = fb_03.snextc(); //current in pointer +1 c3 = fb_03.snextc(); //current in pointer +1
test &= c2 == c3; VERIFY( c2 == c3 );
pt_1 = fb_03.pubseekoff(0, std::ios_base::end); pt_1 = fb_03.pubseekoff(0, std::ios_base::end);
off_1 = pt_1; off_1 = pt_1;
test &= off_1 > off_2; VERIFY( off_1 > off_2 );
fb_03.sputn("\nof the wonderful things he does!!\nok", 37); fb_03.sputn("\nof the wonderful things he does!!\nok", 37);
fb_03.pubsync(); fb_03.pubsync();
@ -494,9 +492,9 @@ bool test03() {
fb_01.close(); fb_01.close();
fb_02.close(); fb_02.close();
fb_03.close(); fb_03.close();
test &= !fb_01.is_open(); VERIFY( !fb_01.is_open() );
test &= !fb_02.is_open(); VERIFY( !fb_02.is_open() );
test &= !fb_03.is_open(); VERIFY( !fb_03.is_open() );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -514,8 +512,8 @@ bool test04()
ifstream ifs(name_02); ifstream ifs(name_02);
char buffer[] = "xxxxxxxxxx"; char buffer[] = "xxxxxxxxxx";
int_type len1 = ifs.rdbuf()->sgetn(buffer, sizeof(buffer)); int_type len1 = ifs.rdbuf()->sgetn(buffer, sizeof(buffer));
test &= len1 == sizeof(buffer); VERIFY( len1 == sizeof(buffer) );
test &= buffer[0] == 'a'; VERIFY( buffer[0] == 'a' );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -25,7 +25,7 @@
#include <cassert> #include <cassert>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <debug_assert.h>
// verify that std::filebuf doesn't close files that it didn't open // verify that std::filebuf doesn't close files that it didn't open
// when using the following std::filebuf ctor: // when using the following std::filebuf ctor:
@ -48,29 +48,29 @@ test_01()
// read (ext) // read (ext)
int fd = open(name_01, O_RDONLY); int fd = open(name_01, O_RDONLY);
test &= fd >= 0; VERIFY( fd >= 0 );
{ {
std::filebuf fb(fd, "double_read", std::ios_base::in); std::filebuf fb(fd, "double_read", std::ios_base::in);
} }
close_num = close(fd); close_num = close(fd);
test &= close_num == 0; VERIFY( close_num == 0 );
// read (standard) // read (standard)
FILE* f = fopen(name_01, "r"); FILE* f = fopen(name_01, "r");
test &= f != NULL; VERIFY( f != NULL );
{ {
std::ifstream ifstream1(name_01); std::ifstream ifstream1(name_01);
test &= ifstream1.is_open(); VERIFY( ifstream1.is_open() );
std::ios_base::iostate st01 = ifstream1.rdstate(); std::ios_base::iostate st01 = ifstream1.rdstate();
test &= st01 == std::ios_base::goodbit; VERIFY( st01 == std::ios_base::goodbit );
} }
close_num = fclose(f); close_num = fclose(f);
test &= close_num == 0; VERIFY( close_num == 0 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -30,9 +30,7 @@
// 27.4.3 template class fpos // 27.4.3 template class fpos
#include <ios> #include <ios>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
void test01() void test01()
{ {
@ -61,7 +59,7 @@ void test01()
// operators, increment and deincrement operators need to be in place. // operators, increment and deincrement operators need to be in place.
pos01.state(state02); pos01.state(state02);
state01 = pos01.state(); state01 = pos01.state();
test &= state01 == state02; VERIFY( state01 == state02 );
#endif #endif
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
@ -87,43 +85,43 @@ void test02()
// p(i), p = i // p(i), p = i
std::streampos pos01(i02); std::streampos pos01(i02);
std::streampos pos02 = i02; std::streampos pos02 = i02;
test &= pos01 == pos02; VERIFY( pos01 == pos02 );
// p(o), p = o // p(o), p = o
// NB: P(o) is only required. // NB: P(o) is only required.
std::streampos pos03(off02); std::streampos pos03(off02);
std::streampos pos04 = off02; std::streampos pos04 = off02;
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
// O(p) // O(p)
std::streamoff off03(pos04); std::streamoff off03(pos04);
test &= off03 == off02; VERIFY( off03 == off02 );
// p == q, p!= q // p == q, p!= q
test &= pos01 == pos02; VERIFY( pos01 == pos02 );
test &= pos02 != pos03; VERIFY( pos02 != pos03 );
// q = p + o // q = p + o
// p += o // p += o
pos03 = pos03 + off02; pos03 = pos03 + off02;
pos04 += off02; pos04 += off02;
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
// q = p - o // q = p - o
// p -= o // p -= o
pos03 = pos03 - off02; pos03 = pos03 - off02;
pos04 -= off02; pos04 -= off02;
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
// o = p - q // o = p - q
test &= 0 == pos03 - pos04; VERIFY( 0 == pos03 - pos04 );
// streamsize -> streamoff // streamsize -> streamoff
// streamoff -> streamsize // streamoff -> streamsize
off01 = off02; off01 = off02;
std::streamsize size01(off02); std::streamsize size01(off02);
std::streamoff off04(size01); std::streamoff off04(size01);
test &= off01 == off04; VERIFY( off01 == off04 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -152,14 +150,14 @@ void test03()
// equality/inequality with const args // equality/inequality with const args
const std::streampos pos02(54); const std::streampos pos02(54);
std::streampos pos03(44); std::streampos pos03(44);
test &= !(pos03 == pos02); VERIFY( !(pos03 == pos02) );
test &= pos03 != pos02; VERIFY( pos03 != pos02 );
test &= !(pos02 == pos03); VERIFY( !(pos02 == pos03) );
test &= pos02 != pos03; VERIFY( pos02 != pos03 );
// default values // default values
std::streampos pos04; std::streampos pos04;
test &= (std::streamoff)pos04 == 0; VERIFY( (std::streamoff)pos04 == 0 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -20,9 +20,7 @@
#include <istream> #include <istream>
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
const char name_01[] = "testsuite/ifstream_members-1.tst"; const char name_01[] = "testsuite/ifstream_members-1.tst";
const char name_02[] = "testsuite/ifstream_members-1.txt"; const char name_02[] = "testsuite/ifstream_members-1.txt";
@ -35,15 +33,15 @@ bool test00()
ifs1.close(); ifs1.close();
// false as expected: // false as expected:
test &= !ifs1.is_open(); VERIFY( !ifs1.is_open() );
// this is now true: // this is now true:
test &= !(ifs1); VERIFY( !(ifs1) );
ifs1.open(name_01); ifs1.open(name_01);
test &= ifs1.is_open(); VERIFY( ifs1.is_open() );
// fail bit still true // fail bit still true
test &= !(ifs1); VERIFY( !(ifs1) );
test &= ifs1.rdstate() == std::ios_base::failbit; VERIFY( ifs1.rdstate() == std::ios_base::failbit );
ifs1.close(); ifs1.close();
@ -63,7 +61,7 @@ bool test01()
for(int i = 0; ++i < more_than_max_open_files;) for(int i = 0; ++i < more_than_max_open_files;)
{ {
std::ifstream ifs(name_01); std::ifstream ifs(name_01);
test &= static_cast<bool>(ifs); VERIFY( static_cast<bool>(ifs) );
} }
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -22,9 +22,7 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
const std::string str01("the nubians of plutonia"); const std::string str01("the nubians of plutonia");
std::string str02; std::string str02;
@ -52,7 +50,7 @@ bool test01()
ios01.register_callback(callb02, 1); ios01.register_callback(callb02, 1);
ios01.register_callback(callb01, 1); ios01.register_callback(callb01, 1);
ios01.imbue(locco); ios01.imbue(locco);
test &= str01 == str02; VERIFY( str01 == str02 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -24,9 +24,7 @@
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01() bool test01()
{ {
@ -36,15 +34,15 @@ bool test01()
std::ios ios01(&strbuf01); std::ios ios01(&strbuf01);
// 1: basic invocation // 1: basic invocation
test &= ios01.sync_with_stdio(); VERIFY( ios01.sync_with_stdio() );
test &= ios01.sync_with_stdio(false); //returns previous state VERIFY( ios01.sync_with_stdio(false) ); //returns previous state
// 2: need to test interleaving of C and C++ io on a file object. // 2: need to test interleaving of C and C++ io on a file object.
test &= std::cout.good(); VERIFY( std::cout.good() );
test &= !std::cout.sync_with_stdio(0); VERIFY( !std::cout.sync_with_stdio(0) );
test &= std::cout.good(); VERIFY( std::cout.good() );
test &= !std::cout.sync_with_stdio(0); VERIFY( !std::cout.sync_with_stdio(0) );
test &= std::cout.good(); VERIFY( std::cout.good() );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -31,9 +31,7 @@
#include <ios> #include <ios>
#include <sstream> #include <sstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
void test01() void test01()
{ {
@ -60,27 +58,27 @@ void test01()
// void init(sreambuf* sb) // void init(sreambuf* sb)
// NB: This is protected so need to go through fstream/stringstream // NB: This is protected so need to go through fstream/stringstream
// Can double-check the accuracy of the above initializations though. // Can double-check the accuracy of the above initializations though.
test &= ios_00.rdbuf() == 0; VERIFY( ios_00.rdbuf() == 0 );
test &= ios_00.tie() == 0; VERIFY( ios_00.tie() == 0 );
test &= ios_00.rdstate() == std::ios_base::badbit; VERIFY( ios_00.rdstate() == std::ios_base::badbit );
test &= ios_00.exceptions() == std::ios_base::goodbit; VERIFY( ios_00.exceptions() == std::ios_base::goodbit );
flag02 = ios_00.flags(); flag02 = ios_00.flags();
test &= flag02 == flag01; VERIFY( flag02 == flag01 );
test &= ios_00.width() == 0; VERIFY( ios_00.width() == 0 );
test &= ios_00.precision() == 6; VERIFY( ios_00.precision() == 6 );
test &= ios_00.fill() == ios_00.widen(' '); VERIFY( ios_00.fill() == ios_00.widen(' ') );
test &= ios_00.getloc() == glocale; VERIFY( ios_00.getloc() == glocale );
test &= ios_01.rdbuf() == &strb_01; VERIFY( ios_01.rdbuf() == &strb_01 );
test &= ios_01.tie() == 0; VERIFY( ios_01.tie() == 0 );
test &= ios_01.rdstate() == std::ios_base::goodbit; VERIFY( ios_01.rdstate() == std::ios_base::goodbit );
test &= ios_01.exceptions() == std::ios_base::goodbit; VERIFY( ios_01.exceptions() == std::ios_base::goodbit );
flag02 = ios_01.flags(); flag02 = ios_01.flags();
test &= flag02 == flag01; VERIFY( flag02 == flag01 );
test &= ios_01.width() == 0; VERIFY( ios_01.width() == 0 );
test &= ios_01.precision() == 6; VERIFY( ios_01.precision() == 6 );
test &= ios_01.fill() == ios_01.widen(' '); VERIFY( ios_01.fill() == ios_01.widen(' ') );
test &= ios_01.getloc() == glocale; VERIFY( ios_01.getloc() == glocale );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -31,9 +31,7 @@
#include <sstream> #include <sstream>
#include <locale> #include <locale>
#include <iomanip> #include <iomanip>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
struct MyNP : std::numpunct<char> struct MyNP : std::numpunct<char>
{ {
@ -44,7 +42,8 @@ struct MyNP : std::numpunct<char>
std::string MyNP::do_grouping() const { static std::string s("\3"); return s; } std::string MyNP::do_grouping() const { static std::string s("\3"); return s; }
char MyNP::do_thousands_sep() const { return ' '; } char MyNP::do_thousands_sep() const { return ' '; }
void test01() int
test01()
{ {
std::cout.imbue(std::locale(std::locale(), new MyNP)); std::cout.imbue(std::locale(std::locale(), new MyNP));
std::cout << std::oct << std::showbase; std::cout << std::oct << std::showbase;
@ -71,9 +70,11 @@ void test01()
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert (std::cout.good()); assert (std::cout.good());
#endif #endif
return 0;
} }
void test02() int
test02()
{ {
bool test = true; bool test = true;
const std::string str_blank; const std::string str_blank;
@ -82,23 +83,25 @@ void test02()
std::ostream o(&strbuf); std::ostream o(&strbuf);
o << std::setw(6) << std::right << "san"; o << std::setw(6) << std::right << "san";
test &= strbuf.str() == " san"; VERIFY( strbuf.str() == " san" );
strbuf.str(str_blank); strbuf.str(str_blank);
o << std::setw(6) << std::internal << "fran"; o << std::setw(6) << std::internal << "fran";
test &= strbuf.str() == " fran"; VERIFY( strbuf.str() == " fran" );
strbuf.str(str_blank); strbuf.str(str_blank);
o << std::setw(6) << std::left << "cisco"; o << std::setw(6) << std::left << "cisco";
test &= strbuf.str() == "cisco "; VERIFY( strbuf.str() == "cisco " );
strbuf.str(str_blank); strbuf.str(str_blank);
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert (test); assert (test);
#endif #endif
return 0;
} }
int main() { int
main() {
test01(); test01();
return 0; return 0;
} }

View File

@ -31,9 +31,7 @@
#include <sstream> #include <sstream>
#include <locale> #include <locale>
#include <iomanip> #include <iomanip>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
struct MyNP : std::numpunct<char> struct MyNP : std::numpunct<char>
{ {
@ -44,7 +42,8 @@ struct MyNP : std::numpunct<char>
std::string MyNP::do_truename() const { static std::string s("yea"); return s; } std::string MyNP::do_truename() const { static std::string s("yea"); return s; }
std::string MyNP::do_falsename() const { static std::string s("nay"); return s; } std::string MyNP::do_falsename() const { static std::string s("nay"); return s; }
void test01() int
test01()
{ {
std::cout << true << " " << false << std::endl; std::cout << true << " " << false << std::endl;
std::cout << std::boolalpha; std::cout << std::boolalpha;
@ -71,9 +70,11 @@ void test01()
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert (std::cout.good()); assert (std::cout.good());
#endif #endif
return 0;
} }
void test02() int
test02()
{ {
bool test = true; bool test = true;
const std::string strue("true"); const std::string strue("true");
@ -88,19 +89,21 @@ void test02()
ostr01 << true; ostr01 << true;
str02 = ostr01.str(); str02 = ostr01.str();
test &= str02 == strue; VERIFY( str02 == strue );
ostr01.str(str01); ostr01.str(str01);
ostr01 << false; ostr01 << false;
str02 = ostr01.str(); str02 = ostr01.str();
test &= str02 == sfalse; VERIFY( str02 == sfalse );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return 0;
} }
int main() { int
main() {
test01(); test01();
test02(); test02();
return 0; return 0;

View File

@ -31,9 +31,7 @@
#include <ios> #include <ios>
// NB: Don't include any other headers in this file. // NB: Don't include any other headers in this file.
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
void test01() void test01()
{ {
@ -54,11 +52,11 @@ void test01()
// char narrow(char_type c, char dfault) const; // char narrow(char_type c, char dfault) const;
char c1 = ios_01.narrow(ct02, 0); char c1 = ios_01.narrow(ct02, 0);
test &= c1 == 'x'; VERIFY( c1 == 'x' );
// char_type widen(char c) const; // char_type widen(char c) const;
ct01 = ios_01.widen('c'); ct01 = ios_01.widen('c');
test &= ct01 == 'c'; VERIFY( ct01 == 'c' );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -85,57 +83,57 @@ void test02()
std::ios::char_type ct02('x');; std::ios::char_type ct02('x');;
// bool fail() const // bool fail() const
test &= ios_01.fail(); VERIFY( ios_01.fail() );
// bool operator!() const // bool operator!() const
test &= !ios_01; VERIFY( !ios_01 );
// iostate rdstate() const // iostate rdstate() const
iostate03 = ios_01.rdstate(); iostate03 = ios_01.rdstate();
test &= static_cast<bool>(iostate03 & std::ios_base::badbit); VERIFY( static_cast<bool>(iostate03 & std::ios_base::badbit) );
// void clear(iostate state = goodbit) // void clear(iostate state = goodbit)
try { try {
ios_01.clear(std::ios_base::eofbit); ios_01.clear(std::ios_base::eofbit);
iostate02 = ios_01.rdstate(); iostate02 = ios_01.rdstate();
test &= static_cast<bool>(iostate02 & iostate01); VERIFY( static_cast<bool>(iostate02 & iostate01) );
} }
catch(std::ios_base::failure& fail) { catch(std::ios_base::failure& fail) {
test &= false; VERIFY( false );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
// iostate exceptions() const // iostate exceptions() const
test &= ios_01.exceptions() == std::ios_base::goodbit; VERIFY( ios_01.exceptions() == std::ios_base::goodbit );
// void exceptions(iostate except) // void exceptions(iostate except)
try { try {
ios_01.exceptions(std::ios_base::eofbit); ios_01.exceptions(std::ios_base::eofbit);
test &= false; VERIFY( false );
} }
catch(std::ios_base::failure& fail) { catch(std::ios_base::failure& fail) {
iostate02 = ios_01.exceptions(); iostate02 = ios_01.exceptions();
test &= static_cast<bool>(iostate02 & std::ios_base::eofbit); VERIFY( static_cast<bool>(iostate02 & std::ios_base::eofbit) );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
// basic_ios& copyfmt(const basic_ios& rhs) // basic_ios& copyfmt(const basic_ios& rhs)
std::ios ios_02(NULL); std::ios ios_02(NULL);
ios_02.exceptions(std::ios_base::eofbit); ios_02.exceptions(std::ios_base::eofbit);
test &= static_cast<bool>(ios_02.exceptions() & std::ios_base::eofbit); VERIFY( static_cast<bool>(ios_02.exceptions() & std::ios_base::eofbit) );
try { try {
ios_01.copyfmt(ios_02); ios_01.copyfmt(ios_02);
test &= false; VERIFY( false );
} }
catch(std::ios_base::failure& fail) { catch(std::ios_base::failure& fail) {
test &= true; VERIFY( true );
} }
catch(...) { catch(...) {
test &= false; VERIFY( false );
} }
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -24,9 +24,7 @@
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <locale> #include <locale>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
std::string str_01; std::string str_01;
std::string str_02("true false 0 1 110001"); std::string str_02("true false 0 1 110001");
@ -71,44 +69,44 @@ bool test01() {
fmt = is_02.flags(); fmt = is_02.flags();
testfmt = fmt & std::ios_base::boolalpha; testfmt = fmt & std::ios_base::boolalpha;
is_02 >> b1; is_02 >> b1;
test &= b1 == 1; VERIFY( b1 == 1 );
is_02 >> b1; is_02 >> b1;
test &= b1 == 0; VERIFY( b1 == 0 );
// process numeric versions of of bool values // process numeric versions of of bool values
is_02.unsetf(std::ios_base::boolalpha); is_02.unsetf(std::ios_base::boolalpha);
fmt = is_02.flags(); fmt = is_02.flags();
testfmt = fmt & std::ios_base::boolalpha; testfmt = fmt & std::ios_base::boolalpha;
is_02 >> b1; is_02 >> b1;
test &= b1 == 0; VERIFY( b1 == 0 );
is_02 >> b1; is_02 >> b1;
test &= b1 == 1; VERIFY( b1 == 1 );
// is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5" // is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5"
is_03 >> l1; is_03 >> l1;
test &= l1 == -19999999; VERIFY( l1 == -19999999 );
is_03 >> ul1; is_03 >> ul1;
test &= ul1 == 777777; VERIFY( ul1 == 777777 );
is_03 >> i1; is_03 >> i1;
test &= i1 == -234234; VERIFY( i1 == -234234 );
is_03 >> ui1; is_03 >> ui1;
test &= ui1 == 233; VERIFY( ui1 == 233 );
is_03 >> s1; is_03 >> s1;
test &= s1 == -234; VERIFY( s1 == -234 );
is_03 >> us1; is_03 >> us1;
test &= us1 == 33; VERIFY( us1 == 33 );
is_03 >> b1; is_03 >> b1;
test &= b1 == 1; VERIFY( b1 == 1 );
is_03 >> ld1; is_03 >> ld1;
test &= ld1 == 66300.25; VERIFY( ld1 == 66300.25 );
is_03 >> d1; is_03 >> d1;
test &= d1 == .315; VERIFY( d1 == .315 );
is_03 >> f1; is_03 >> f1;
test &= f1 == 1.5; VERIFY( f1 == 1.5 );
is_04 >> std::hex >> i1; is_04 >> std::hex >> i1;
printf ("%d %d %d\n", i1, i1 == 0x123, test); printf ("%d %d %d\n", i1, i1 == 0x123, test);
test &= i1 == 0x123; VERIFY( i1 == 0x123 );
printf ("%d %d %d\n", i1, i1 == 0x123, test); printf ("%d %d %d\n", i1, i1 == 0x123, test);
// test void pointers // test void pointers
@ -119,7 +117,7 @@ bool test01() {
ss_01 << po; ss_01 << po;
ss_01 >> pi; ss_01 >> pi;
printf ("%x %x\n", pi, po); printf ("%x %x\n", pi, po);
test &= po == pi; VERIFY( po == pi );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -138,9 +136,9 @@ bool test02() {
int n = 15; int n = 15;
is >> n; is >> n;
test &= n == 20000; VERIFY( n == 20000 );
char c = is.peek(); char c = is.peek();
test &= c == 65; VERIFY( c == 65 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -159,8 +157,8 @@ bool test03()
long l01; long l01;
ostr << "12220101"; ostr << "12220101";
istr >> l01; // _M_in_end set completely incorrectly here. istr >> l01; // _M_in_end set completely incorrectly here.
test &= l01 == 12220101; VERIFY( l01 == 12220101 );
test &= istr.rdstate() == std::ios_base::eofbit; VERIFY( istr.rdstate() == std::ios_base::eofbit );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -181,21 +179,21 @@ void test06()
std::istringstream is(s); std::istringstream is(s);
is >> h4; // 205 is >> h4; // 205
test &= h4 == 205; VERIFY( h4 == 205 );
is >> c; // ',' is >> c; // ','
test &= c == ','; VERIFY( c == ',' );
is >> h4; // 199 is >> h4; // 199
test &= h4 == 199; VERIFY( h4 == 199 );
is >> c; // ',' is >> c; // ','
test &= c == ','; VERIFY( c == ',' );
is >> h4; // 144 is >> h4; // 144
test &= is.rdstate() == std::ios_base::eofbit; VERIFY( is.rdstate() == std::ios_base::eofbit );
test &= h4 == 144; VERIFY( h4 == 144 );
is >> c; // EOF is >> c; // EOF
test &= c == ','; VERIFY( c == ',' );
test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -224,24 +222,24 @@ void test07()
// Basic operation. // Basic operation.
is >> h4; is >> h4;
test &= h4 == 205199; VERIFY( h4 == 205199 );
test &= is.good(); VERIFY( is.good() );
is.clear(); is.clear();
is >> f1; is >> f1;
test &= f1 == 23445.25; VERIFY( f1 == 23445.25 );
test &= is.good(); VERIFY( is.good() );
is.clear(); is.clear();
is >> h3; is >> h3;
test &= h3 == 1024365; VERIFY( h3 == 1024365 );
test &= is.good(); VERIFY( is.good() );
is.clear(); is.clear();
is >> h2; is >> h2;
test &= h2 == 0; VERIFY( h2 == 0 );
test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
test &= static_cast<bool>(is.rdstate() & std::ios_base::eofbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) );
// Stress tests for explicit errors in grouping corner cases. The // Stress tests for explicit errors in grouping corner cases. The
// validity of these tests and results have been hammered out in // validity of these tests and results have been hammered out in
@ -256,64 +254,64 @@ void test07()
is.str(s2); is.str(s2);
is >> h4; is >> h4;
test &= h4 == 0; VERIFY( h4 == 0 );
test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
is.clear(); is.clear();
is >> c; is >> c;
test &= c == ','; VERIFY( c == ',' );
test &= is.good(); VERIFY( is.good() );
is.ignore(3); is.ignore(3);
is >> f1; is >> f1;
test &= f1 == 0.0; VERIFY( f1 == 0.0 );
test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
is.clear(); is.clear();
is >> c; is >> c;
test &= c == ','; VERIFY( c == ',' );
is >> c; is >> c;
test &= c == '4'; VERIFY( c == '4' );
test &= is.good(); VERIFY( is.good() );
is >> f1; is >> f1;
test &= f1 == 0.25; VERIFY( f1 == 0.25 );
test &= is.good(); VERIFY( is.good() );
is >> c; is >> c;
test &= c == ','; VERIFY( c == ',' );
is >> h2; is >> h2;
test &= h2 == 345; VERIFY( h2 == 345 );
test &= is.good(); VERIFY( is.good() );
f1 = 0.0; f1 = 0.0;
h2 = 0; h2 = 0;
is >> f1; is >> f1;
test &= f1 == 5.0; VERIFY( f1 == 5.0 );
test &= is.good(); VERIFY( is.good() );
is >> f1; is >> f1;
test &= f1 == .25; VERIFY( f1 == .25 );
test &= is.good(); VERIFY( is.good() );
is >> h3; is >> h3;
test &= h3 == 0; VERIFY( h3 == 0 );
test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
is.clear(); is.clear();
is >> c; is >> c;
test &= c == ','; // second one VERIFY( c == ',' ); // second one
test &= is.good(); VERIFY( is.good() );
is >> h2; is >> h2;
test &= h2 == 0; VERIFY( h2 == 0 );
test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
is.clear(); is.clear();
is >> h2; is >> h2;
test &= h2 == 1000000; VERIFY( h2 == 1000000 );
test &= is.good(); VERIFY( is.good() );
h2 = 0; h2 = 0;
is >> h2; is >> h2;
test &= h2 == 0; VERIFY( h2 == 0 );
test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
test &= static_cast<bool>(is.rdstate() & std::ios_base::eofbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) );
is.clear(); is.clear();
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
@ -345,18 +343,18 @@ void test08()
// Basic operation. // Basic operation.
is >> h4; is >> h4;
test &= h4 == 122; VERIFY( h4 == 122 );
test &= is.good(); VERIFY( is.good() );
is.clear(); is.clear();
is >> h3; is >> h3;
test &= h3 == 20519; VERIFY( h3 == 20519 );
test &= is.good(); VERIFY( is.good() );
is.clear(); is.clear();
is >> h2; is >> h2;
test &= h2 == 2212322; VERIFY( h2 == 2212322 );
test &= static_cast<bool>(is.rdstate() & std::ios_base::eofbit); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
@ -378,8 +376,8 @@ bool test09()
(is>>std::ws) >> c; (is>>std::ws) >> c;
(is>>std::ws) >> f2; (is>>std::ws) >> f2;
test = f1 == 2456; test = f1 == 2456;
test &= f2 == 0.00567; VERIFY( f2 == 0.00567 );
test &= c == '-'; VERIFY( c == '-' );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
@ -396,37 +394,37 @@ bool test10() {
int n = 365; int n = 365;
is_01 >> n; is_01 >> n;
test &= n == 0; VERIFY( n == 0 );
n = 364; n = 364;
is_01 >> n; is_01 >> n;
test &= n == 0; VERIFY( n == 0 );
n = 363; n = 363;
is_01 >> n; is_01 >> n;
test &= n == 0; VERIFY( n == 0 );
n = 362; n = 362;
is_01 >> n; is_01 >> n;
test &= n == 0; VERIFY( n == 0 );
n = 361; n = 361;
is_01 >> n; is_01 >> n;
test &= n == 0; VERIFY( n == 0 );
n = 360; n = 360;
is_01 >> n; is_01 >> n;
test &= n == 0; VERIFY( n == 0 );
test &= is_01.rdstate() == std::ios_base::eofbit; VERIFY( is_01.rdstate() == std::ios_base::eofbit );
std::string str_02("0x32 0X33 033 33"); std::string str_02("0x32 0X33 033 33");
std::stringbuf isbuf_02(str_02); std::stringbuf isbuf_02(str_02);
std::istream is_02(&isbuf_02); std::istream is_02(&isbuf_02);
is_02.unsetf(std::ios_base::basefield); is_02.unsetf(std::ios_base::basefield);
is_02 >> n; is_02 >> n;
test &= n == 50; VERIFY( n == 50 );
is_02 >> n; is_02 >> n;
test &= n == 51; VERIFY( n == 51 );
is_02 >> n; is_02 >> n;
test &= n == 27; VERIFY( n == 27 );
is_02 >> n; is_02 >> n;
test &= n == 33; VERIFY( n == 33 );
test &= is_02.rdstate() == std::ios_base::eofbit; VERIFY( is_02.rdstate() == std::ios_base::eofbit );
std::stringbuf isbuf_03(str_02); std::stringbuf isbuf_03(str_02);
std::istream is_03(&isbuf_03); std::istream is_03(&isbuf_03);
@ -434,19 +432,19 @@ bool test10() {
int m; int m;
is_03 >> std::dec >> n >> c >> m; is_03 >> std::dec >> n >> c >> m;
test &= n == 0; VERIFY( n == 0 );
test &= c == 'x'; VERIFY( c == 'x' );
test &= m == 32; VERIFY( m == 32 );
is_03 >> std::oct >> m >> c >> n; is_03 >> std::oct >> m >> c >> n;
test &= m == 0; VERIFY( m == 0 );
test &= c == 'X'; VERIFY( c == 'X' );
test &= n == 27; VERIFY( n == 27 );
is_03 >> std::dec >> m >> n; is_03 >> std::dec >> m >> n;
test &= m == 33; VERIFY( m == 33 );
test &= n == 33; VERIFY( n == 33 );
test &= is_03.rdstate() == std::ios_base::eofbit; VERIFY( is_03.rdstate() == std::ios_base::eofbit );
std::string str_04("3. 4.5E+ 2a5E-3 .6E1"); std::string str_04("3. 4.5E+ 2a5E-3 .6E1");
std::stringbuf isbuf_04(str_04); std::stringbuf isbuf_04(str_04);
@ -454,35 +452,35 @@ bool test10() {
double f; double f;
is_04 >> f; is_04 >> f;
test &= f == 3.0; VERIFY( f == 3.0 );
is_04 >> f; is_04 >> f;
test &= f == 450.0; VERIFY( f == 450.0 );
is_04.ignore(); is_04.ignore();
is_04 >> f; is_04 >> f;
test &= f == 0.005; VERIFY( f == 0.005 );
is_04 >> f; is_04 >> f;
test &= f == 6; VERIFY( f == 6 );
test &= is_03.rdstate() == std::ios_base::eofbit; VERIFY( is_03.rdstate() == std::ios_base::eofbit );
std::string str_05("0E20 5Ea E16"); std::string str_05("0E20 5Ea E16");
std::stringbuf isbuf_05(str_05); std::stringbuf isbuf_05(str_05);
std::istream is_05(&isbuf_05); std::istream is_05(&isbuf_05);
is_05 >> f; is_05 >> f;
test &= f == 0; VERIFY( f == 0 );
is_05 >> f; is_05 >> f;
test &= f == 0; VERIFY( f == 0 );
test &= is_05.rdstate() == std::ios_base::failbit; VERIFY( is_05.rdstate() == std::ios_base::failbit );
is_05.clear(); is_05.clear();
is_05 >> c; is_05 >> c;
test &= c == 'a'; VERIFY( c == 'a' );
is_05 >> f; is_05 >> f;
test &= f == 0; VERIFY( f == 0 );
test &= is_05.rdstate() == std::ios_base::failbit; VERIFY( is_05.rdstate() == std::ios_base::failbit );
is_05.clear(); is_05.clear();
is_05.ignore(); is_05.ignore();
is_05 >> n; is_05 >> n;
test &= n == 16; VERIFY( n == 16 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -22,9 +22,7 @@
#include <istream> #include <istream>
#include <sstream> #include <sstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01() { bool test01() {
@ -53,28 +51,28 @@ bool test01() {
is_01 >> array1; // should snake 0 characters, not alter stream state is_01 >> array1; // should snake 0 characters, not alter stream state
i2 = ctraits_type::length(array1); i2 = ctraits_type::length(array1);
state2 = is_01.rdstate(); state2 = is_01.rdstate();
test &= i1 == i2; VERIFY( i1 == i2 );
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> array1; // should snake "coltrane" is_02 >> array1; // should snake "coltrane"
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= !static_cast<bool>(state2 & statefail); VERIFY( !static_cast<bool>(state2 & statefail) );
test &= array1[str_03.size() - 1] == 'e'; VERIFY( array1[str_03.size() - 1] == 'e' );
array1[str_03.size()] = '\0'; array1[str_03.size()] = '\0';
test &= !str_03.compare(0, str_03.size(), array1); VERIFY( !str_03.compare(0, str_03.size(), array1) );
std::istream::int_type int1 = is_02.peek(); // should be ' ' std::istream::int_type int1 = is_02.peek(); // should be ' '
test &= int1 == ' '; VERIFY( int1 == ' ' );
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> array1; // should snake "playing" as sentry "eats" ws is_02 >> array1; // should snake "playing" as sentry "eats" ws
state2 = is_02.rdstate(); state2 = is_02.rdstate();
int1 = is_02.peek(); // should be ' ' int1 = is_02.peek(); // should be ' '
test &= int1 == ' '; VERIFY( int1 == ' ' );
test &= state1 == state2; VERIFY( state1 == state2 );
test &= !static_cast<bool>(state2 & statefail); VERIFY( !static_cast<bool>(state2 & statefail) );
// template<_CharT, _Traits> // template<_CharT, _Traits>
@ -83,13 +81,13 @@ bool test01() {
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> array2; // should snake 'softly is_02 >> array2; // should snake 'softly
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= !static_cast<bool>(state2 & statefail); VERIFY( !static_cast<bool>(state2 & statefail) );
test &= array2[0] == '\''; VERIFY( array2[0] == '\'' );
test &= array2[1] == 's'; VERIFY( array2[1] == 's' );
test &= array2[6] == 'y'; VERIFY( array2[6] == 'y' );
int1 = is_02.peek(); // should be ' ' int1 = is_02.peek(); // should be ' '
test &= int1 == ' '; VERIFY( int1 == ' ' );
// template<_CharT, _Traits> // template<_CharT, _Traits>
@ -98,12 +96,12 @@ bool test01() {
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> array3; // should snake "as" is_02 >> array3; // should snake "as"
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= !static_cast<bool>(state2 & statefail); VERIFY( !static_cast<bool>(state2 & statefail) );
test &= array3[0] == 'a'; VERIFY( array3[0] == 'a' );
test &= array3[1] == 's'; VERIFY( array3[1] == 's' );
int1 = is_02.peek(); // should be ' ' int1 = is_02.peek(); // should be ' '
test &= int1 == ' '; VERIFY( int1 == ' ' );
// testing with width() control enabled. // testing with width() control enabled.
@ -111,25 +109,25 @@ bool test01() {
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> array1; // should snake a is_02 >> array1; // should snake a
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= !ctraits_type::compare(array1, "a", 2); VERIFY( !ctraits_type::compare(array1, "a", 2) );
is_02.width(1); is_02.width(1);
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> array1; // should snake nothing, set failbit is_02 >> array1; // should snake nothing, set failbit
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= state2 == statefail; VERIFY( state2 == statefail );
test &= array1[0] == '\0'; VERIFY( array1[0] == '\0' );
is_02.width(8); is_02.width(8);
is_02.clear(); is_02.clear();
state1 = is_02.rdstate(); state1 = is_02.rdstate();
test &= !state1; VERIFY( !state1 );
is_02 >> array1; // should snake "morning" is_02 >> array1; // should snake "morning"
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= !ctraits_type::compare(array1, "morning", 8); VERIFY( !ctraits_type::compare(array1, "morning", 8) );
// testing for correct exception setting // testing for correct exception setting
const std::string str_04(" impulse!!"); const std::string str_04(" impulse!!");
@ -139,13 +137,13 @@ bool test01() {
std::istream is_04(&isbuf_04); std::istream is_04(&isbuf_04);
is_03 >> array1; is_03 >> array1;
test &= !ctraits_type::compare(array1,"impulse!!", 10); VERIFY( !ctraits_type::compare(array1,"impulse!!", 10) );
test &= is_03.rdstate() == std::ios_base::eofbit; VERIFY( is_03.rdstate() == std::ios_base::eofbit );
is_04.width(9); is_04.width(9);
is_04 >> array1; is_04 >> array1;
test &= ! std::ios::traits_type::compare(array1,"impulse!", 9); VERIFY( ! std::ios::traits_type::compare(array1,"impulse!", 9) );
test &= !is_04.rdstate(); VERIFY( !is_04.rdstate() );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -176,19 +174,19 @@ bool test02() {
state1 = is_01.rdstate(); state1 = is_01.rdstate();
is_01 >> c1; is_01 >> c1;
state2 = is_01.rdstate(); state2 = is_01.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= c1 == c2; VERIFY( c1 == c2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> c1; is_02 >> c1;
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= c1 == 'o'; VERIFY( c1 == 'o' );
is_02 >> c1; is_02 >> c1;
is_02 >> c1; is_02 >> c1;
test &= c1 == 'c'; VERIFY( c1 == 'c' );
test &= !static_cast<bool>(state2 & statefail); VERIFY( !static_cast<bool>(state2 & statefail) );
// template<_CharT, _Traits> // template<_CharT, _Traits>
// basic_istream& operator>>(istream&, unsigned char&) // basic_istream& operator>>(istream&, unsigned char&)
@ -196,11 +194,11 @@ bool test02() {
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> uc1; is_02 >> uc1;
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= uc1 == 'o'; VERIFY( uc1 == 'o' );
is_02 >> uc1; is_02 >> uc1;
is_02 >> uc1; is_02 >> uc1;
test &= uc1 == 't'; VERIFY( uc1 == 't' );
// template<_CharT, _Traits> // template<_CharT, _Traits>
// basic_istream& operator>>(istream&, signed char&) // basic_istream& operator>>(istream&, signed char&)
@ -208,11 +206,11 @@ bool test02() {
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> sc1; is_02 >> sc1;
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= sc1 == 'r'; VERIFY( sc1 == 'r' );
is_02 >> sc1; is_02 >> sc1;
is_02 >> sc1; is_02 >> sc1;
test &= sc1 == 'n'; VERIFY( sc1 == 'n' );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -23,9 +23,7 @@
#include <istream> #include <istream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
// stringbufs. // stringbufs.
@ -71,78 +69,78 @@ bool test01() {
state1 = is_00.rdstate(); state1 = is_00.rdstate();
is_00 >> &isbuf_00; is_00 >> &isbuf_00;
state2 = is_00.rdstate(); state2 = is_00.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
test &= isbuf_00.str() == str_01; VERIFY( isbuf_00.str() == str_01 );
// null istream to empty in_out_buf // null istream to empty in_out_buf
is_00.clear(std::ios_base::goodbit); is_00.clear(std::ios_base::goodbit);
state1 = is_00.rdstate(); state1 = is_00.rdstate();
is_00 >> &isbuf_01; is_00 >> &isbuf_01;
state2 = is_00.rdstate(); state2 = is_00.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
test &= isbuf_01.str() == str_01; VERIFY( isbuf_01.str() == str_01 );
// null istream to full in_buf // null istream to full in_buf
is_00.clear(std::ios_base::goodbit); is_00.clear(std::ios_base::goodbit);
state1 = is_00.rdstate(); state1 = is_00.rdstate();
is_00 >> &isbuf_04; is_00 >> &isbuf_04;
state2 = is_00.rdstate(); state2 = is_00.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
test &= isbuf_04.str() == str_02; VERIFY( isbuf_04.str() == str_02 );
// null istream to full in_out_buf // null istream to full in_out_buf
is_00.clear(std::ios_base::goodbit); is_00.clear(std::ios_base::goodbit);
state1 = is_00.rdstate(); state1 = is_00.rdstate();
is_00 >> &isbuf_05; is_00 >> &isbuf_05;
state2 = is_00.rdstate(); state2 = is_00.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
test &= isbuf_05.str() == str_02; VERIFY( isbuf_05.str() == str_02 );
// empty but non-null istream to full in_buf // empty but non-null istream to full in_buf
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> &isbuf_04; is_02 >> &isbuf_04;
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
test &= isbuf_04.str() == str_02; // as only an "in" buffer VERIFY( isbuf_04.str() == str_02 ); // as only an "in" buffer
test &= isbuf_04.sgetc() == 'a'; VERIFY( isbuf_04.sgetc() == 'a' );
// empty but non-null istream to full in_out_buf // empty but non-null istream to full in_out_buf
is_02.clear(std::ios_base::goodbit); is_02.clear(std::ios_base::goodbit);
state1 = is_02.rdstate(); state1 = is_02.rdstate();
is_02 >> &isbuf_05; is_02 >> &isbuf_05;
state2 = is_02.rdstate(); state2 = is_02.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
test &= isbuf_05.str() == str_02; // as only an "in" buffer VERIFY( isbuf_05.str() == str_02 ); // as only an "in" buffer
test &= isbuf_05.sgetc() == 'a'; VERIFY( isbuf_05.sgetc() == 'a' );
// full istream to empty in_buf (need out_buf, you know?) // full istream to empty in_buf (need out_buf, you know?)
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04 >> &isbuf_02; is_04 >> &isbuf_02;
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
test &= isbuf_02.str() == str_01; // as only an "in" buffer VERIFY( isbuf_02.str() == str_01 ); // as only an "in" buffer
test &= isbuf_02.sgetc() == ctraits_type::eof(); VERIFY( isbuf_02.sgetc() == ctraits_type::eof() );
test &= is_04.peek() == ctraits_type::eof(); // as failed VERIFY( is_04.peek() == ctraits_type::eof() ); // as failed
// full istream to empty in_out_buf // full istream to empty in_out_buf
is_04.clear(std::ios_base::goodbit); is_04.clear(std::ios_base::goodbit);
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04 >> &isbuf_03; is_04 >> &isbuf_03;
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= !static_cast<bool>(state2 & statefail); VERIFY( !static_cast<bool>(state2 & statefail) );
test &= state2 == stateeof; VERIFY( state2 == stateeof );
strtmp = isbuf_03.str(); strtmp = isbuf_03.str();
test &= strtmp == str_02; // as only an "in" buffer VERIFY( strtmp == str_02 ); // as only an "in" buffer
test &= isbuf_03.sgetc() == 'a'; VERIFY( isbuf_03.sgetc() == 'a' );
test &= is_04.peek() == ctraits_type::eof(); VERIFY( is_04.peek() == ctraits_type::eof() );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -162,8 +160,8 @@ bool test02() {
std::filebuf fbin, fbout; std::filebuf fbin, fbout;
fbin.open(name_01, std::ios_base::in); fbin.open(name_01, std::ios_base::in);
fbout.open(name_02, std::ios_base::out | std::ios_base::trunc); fbout.open(name_02, std::ios_base::out | std::ios_base::trunc);
test &= fbin.is_open(); VERIFY( fbin.is_open() );
test &= fbout.is_open(); VERIFY( fbout.is_open() );
if (test) if (test)
{ {
@ -174,8 +172,8 @@ bool test02() {
fbout.close(); fbout.close();
fbin.close(); fbin.close();
test &= !fbin.is_open(); VERIFY( !fbin.is_open() );
test &= !fbout.is_open(); VERIFY( !fbout.is_open() );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -23,9 +23,7 @@
#include <istream> #include <istream>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -44,36 +42,36 @@ bool test01(void)
std::istringstream iss02(str01); std::istringstream iss02(str01);
iss01 >> str04; iss01 >> str04;
test &= str04.size() != str01.size(); VERIFY( str04.size() != str01.size() );
test &= str04 == "santa"; VERIFY( str04 == "santa" );
iss02 >> std::ws; iss02 >> std::ws;
iss02 >> str05; iss02 >> str05;
test &= str05.size() != str01.size(); VERIFY( str05.size() != str01.size() );
test &= str05 == "santa"; VERIFY( str05 == "santa" );
test &= str05 == str04; VERIFY( str05 == str04 );
iss01 >> str04; iss01 >> str04;
test &= str04.size() != str01.size(); VERIFY( str04.size() != str01.size() );
test &= str04 == "barbara"; VERIFY( str04 == "barbara" );
iss02 >> std::ws; iss02 >> std::ws;
iss02 >> str05; iss02 >> str05;
test &= str05.size() != str01.size(); VERIFY( str05.size() != str01.size() );
test &= str05 == "barbara"; VERIFY( str05 == "barbara" );
test &= str05 == str04; VERIFY( str05 == str04 );
flag3 = std::ios_base::eofbit; flag3 = std::ios_base::eofbit;
flag4 = std::ios_base::badbit; flag4 = std::ios_base::badbit;
flag5 = std::ios_base::failbit; flag5 = std::ios_base::failbit;
test &= !iss01.fail(); VERIFY( !iss01.fail() );
test &= !iss02.fail(); VERIFY( !iss02.fail() );
test &= !iss01.eof(); VERIFY( !iss01.eof() );
test &= !iss02.eof(); VERIFY( !iss02.eof() );
iss01 >> std::ws; iss01 >> std::ws;
test &= !iss01.fail(); VERIFY( !iss01.fail() );
test &= iss01.eof(); VERIFY( iss01.eof() );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -24,9 +24,7 @@
#include <istream> #include <istream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01() bool test01()
@ -45,7 +43,7 @@ bool test01()
ifstream ifs1; ifstream ifs1;
pos_type p4 = ifs1.tellg(); pos_type p4 = ifs1.tellg();
test &= p3 == p4; VERIFY( p3 == p4 );
// in // in
// test ctors leave things in the same positions... // test ctors leave things in the same positions...
@ -55,7 +53,7 @@ bool test01()
ifstream ifs2(str_lit01); ifstream ifs2(str_lit01);
p4 = ifs2.tellg(); p4 = ifs2.tellg();
test &= p3 == p4; VERIFY( p3 == p4 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -75,9 +73,9 @@ void test04(void)
std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out); std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out);
std::ifstream if02(str_lit01, std::ios_base::in); std::ifstream if02(str_lit01, std::ios_base::in);
std::ifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc); std::ifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc);
test &= if01.good(); VERIFY( if01.good() );
test &= if02.good(); VERIFY( if02.good() );
test &= if03.good(); VERIFY( if03.good() );
std::istream is01(if01.rdbuf()); std::istream is01(if01.rdbuf());
std::istream is02(if02.rdbuf()); std::istream is02(if02.rdbuf());
@ -87,20 +85,20 @@ void test04(void)
// in | out // in | out
pos01 = is01.tellg(); pos01 = is01.tellg();
pos02 = is01.tellg(); pos02 = is01.tellg();
test &= pos01 == pos02; VERIFY( pos01 == pos02 );
// test &= istream::pos_type(0) != pos01; //depricated // VERIFY( istream::pos_type(0) != pos01 ); //depricated
// in // in
pos03 = is02.tellg(); pos03 = is02.tellg();
pos04 = is02.tellg(); pos04 = is02.tellg();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
// test &= istream::pos_type(0) != pos03; //depricated // VERIFY( istream::pos_type(0) != pos03 ); //depricated
// out // out
pos05 = is03.tellg(); pos05 = is03.tellg();
pos06 = is03.tellg(); pos06 = is03.tellg();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
// test &= istream::pos_type(0) != pos01; //depricated // VERIFY( istream::pos_type(0) != pos01 ); //depricated
// istream& seekg(pos_type) // istream& seekg(pos_type)
// istream& seekg(off_type, ios_base::seekdir) // istream& seekg(off_type, ios_base::seekdir)
@ -114,56 +112,56 @@ void test04(void)
is01.seekg(10, std::ios_base::cur); is01.seekg(10, std::ios_base::cur);
state02 = is01.rdstate(); state02 = is01.rdstate();
pos01 = is01.tellg(); pos01 = is01.tellg();
test &= pos01 == pos02 + 10; VERIFY( pos01 == pos02 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos02 = is01.tellg(); pos02 = is01.tellg();
test &= pos02 == pos01; VERIFY( pos02 == pos01 );
state01 = is02.rdstate(); state01 = is02.rdstate();
is02.seekg(10, std::ios_base::cur); is02.seekg(10, std::ios_base::cur);
state02 = is02.rdstate(); state02 = is02.rdstate();
pos03 = is02.tellg(); pos03 = is02.tellg();
test &= pos03 == pos04 + 10; VERIFY( pos03 == pos04 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos04 = is02.tellg(); pos04 = is02.tellg();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
state01 = is03.rdstate(); state01 = is03.rdstate();
is03.seekg(10, std::ios_base::cur); is03.seekg(10, std::ios_base::cur);
state02 = is03.rdstate(); state02 = is03.rdstate();
pos05 = is03.tellg(); pos05 = is03.tellg();
test &= pos05 == pos06 + 10; VERIFY( pos05 == pos06 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos06 = is03.tellg(); pos06 = is03.tellg();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
// beg // beg
state01 = is01.rdstate(); state01 = is01.rdstate();
is01.seekg(20, std::ios_base::beg); is01.seekg(20, std::ios_base::beg);
state02 = is01.rdstate(); state02 = is01.rdstate();
pos01 = is01.tellg(); pos01 = is01.tellg();
test &= pos01 == pos02 + 10; VERIFY( pos01 == pos02 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos02 = is01.tellg(); pos02 = is01.tellg();
test &= pos02 == pos01; VERIFY( pos02 == pos01 );
state01 = is02.rdstate(); state01 = is02.rdstate();
is02.seekg(20, std::ios_base::beg); is02.seekg(20, std::ios_base::beg);
state02 = is02.rdstate(); state02 = is02.rdstate();
pos03 = is02.tellg(); pos03 = is02.tellg();
test &= pos03 == pos04 + 10; VERIFY( pos03 == pos04 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos04 = is02.tellg(); pos04 = is02.tellg();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
state01 = is03.rdstate(); state01 = is03.rdstate();
is03.seekg(20, std::ios_base::beg); is03.seekg(20, std::ios_base::beg);
state02 = is03.rdstate(); state02 = is03.rdstate();
pos05 = is03.tellg(); pos05 = is03.tellg();
test &= pos05 == pos06 + 10; VERIFY( pos05 == pos06 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos06 = is03.tellg(); pos06 = is03.tellg();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -180,9 +178,9 @@ void test05(void)
std::ifstream if01(str_lit01); std::ifstream if01(str_lit01);
std::ifstream if02(str_lit01); std::ifstream if02(str_lit01);
std::ifstream if03(str_lit01); std::ifstream if03(str_lit01);
test &= if01.good(); VERIFY( if01.good() );
test &= if02.good(); VERIFY( if02.good() );
test &= if03.good(); VERIFY( if03.good() );
std::stringbuf strbuf01(std::ios_base::in | std::ios_base::out); std::stringbuf strbuf01(std::ios_base::in | std::ios_base::out);
if01 >> &strbuf01; if01 >> &strbuf01;
@ -199,20 +197,20 @@ void test05(void)
// in | out // in | out
pos01 = is01.tellg(); pos01 = is01.tellg();
pos02 = is01.tellg(); pos02 = is01.tellg();
test &= pos01 == pos02; VERIFY( pos01 == pos02 );
// test &= istream::pos_type(0) != pos01; // deprecated // VERIFY( istream::pos_type(0) != pos01 ); // deprecated
// in // in
pos03 = is02.tellg(); pos03 = is02.tellg();
pos04 = is02.tellg(); pos04 = is02.tellg();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
// test &= istream::pos_type(0) != pos03; // deprecated // VERIFY( istream::pos_type(0) != pos03 ); // deprecated
// out // out
pos05 = is03.tellg(); pos05 = is03.tellg();
pos06 = is03.tellg(); pos06 = is03.tellg();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
// test &= istream::pos_type(0) != pos01; //deprecated // VERIFY( istream::pos_type(0) != pos01 ); //deprecated
// istream& seekg(pos_type) // istream& seekg(pos_type)
// istream& seekg(off_type, ios_base::seekdir) // istream& seekg(off_type, ios_base::seekdir)
@ -226,56 +224,56 @@ void test05(void)
is01.seekg(10, std::ios_base::cur); is01.seekg(10, std::ios_base::cur);
state02 = is01.rdstate(); state02 = is01.rdstate();
pos01 = is01.tellg(); pos01 = is01.tellg();
test &= pos01 == pos02 + 10; VERIFY( pos01 == pos02 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos02 = is01.tellg(); pos02 = is01.tellg();
test &= pos02 == pos01; VERIFY( pos02 == pos01 );
state01 = is02.rdstate(); state01 = is02.rdstate();
is02.seekg(10, std::ios_base::cur); is02.seekg(10, std::ios_base::cur);
state02 = is02.rdstate(); state02 = is02.rdstate();
pos03 = is02.tellg(); pos03 = is02.tellg();
test &= pos03 == pos04 + 10; VERIFY( pos03 == pos04 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos04 = is02.tellg(); pos04 = is02.tellg();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
state01 = is03.rdstate(); state01 = is03.rdstate();
is03.seekg(10, std::ios_base::cur); is03.seekg(10, std::ios_base::cur);
state02 = is03.rdstate(); state02 = is03.rdstate();
pos05 = is03.tellg(); pos05 = is03.tellg();
test &= pos05 == pos06; // as only out buffer VERIFY( pos05 == pos06 ); // as only out buffer
test &= state01 == state02; VERIFY( state01 == state02 );
pos06 = is03.tellg(); pos06 = is03.tellg();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
// beg // beg
state01 = is01.rdstate(); state01 = is01.rdstate();
is01.seekg(20, std::ios_base::beg); is01.seekg(20, std::ios_base::beg);
state02 = is01.rdstate(); state02 = is01.rdstate();
pos01 = is01.tellg(); pos01 = is01.tellg();
test &= pos01 == pos02 + 10; VERIFY( pos01 == pos02 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos02 = is01.tellg(); pos02 = is01.tellg();
test &= pos02 == pos01; VERIFY( pos02 == pos01 );
state01 = is02.rdstate(); state01 = is02.rdstate();
is02.seekg(20, std::ios_base::beg); is02.seekg(20, std::ios_base::beg);
state02 = is02.rdstate(); state02 = is02.rdstate();
pos03 = is02.tellg(); pos03 = is02.tellg();
test &= pos03 == pos04 + 10; VERIFY( pos03 == pos04 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos04 = is02.tellg(); pos04 = is02.tellg();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
state01 = is03.rdstate(); state01 = is03.rdstate();
is03.seekg(20, std::ios_base::beg); is03.seekg(20, std::ios_base::beg);
state02 = is03.rdstate(); state02 = is03.rdstate();
pos05 = is03.tellg(); pos05 = is03.tellg();
test &= pos05 == pos06; // as only out buffer VERIFY( pos05 == pos06 ); // as only out buffer
test &= state01 == state02; VERIFY( state01 == state02 );
pos06 = is03.tellg(); pos06 = is03.tellg();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -31,9 +31,7 @@
#include <istream> #include <istream>
#include <sstream> #include <sstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
void test01() void test01()
{ {
@ -48,17 +46,17 @@ void test01()
// test negatives // test negatives
std::istream::sentry sentry01(istr01); std::istream::sentry sentry01(istr01);
test &= bool(sentry01) == false; VERIFY( bool(sentry01) == false );
std::istream::sentry sentry02(istr01, true); std::istream::sentry sentry02(istr01, true);
test &= bool(sentry02) == false; VERIFY( bool(sentry02) == false );
// positive tests // positive tests
std::istream::sentry sentry03(istr02); std::istream::sentry sentry03(istr02);
test &= bool(sentry03) == true; VERIFY( bool(sentry03) == true );
std::istream::sentry sentry04(istr02, true); std::istream::sentry sentry04(istr02, true);
test &= bool(sentry04) == true; VERIFY( bool(sentry04) == true );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -23,15 +23,11 @@
#include <istream> #include <istream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <cassert>
# define VERIFY(fn) assert(fn)
#else
# define VERIFY(fn)
#endif
bool test01() {
int
test01()
{
typedef std::ios::traits_type traits_type; typedef std::ios::traits_type traits_type;
bool test = true; bool test = true;
@ -54,78 +50,78 @@ bool test01() {
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.read(carray, 0); is_04.read(carray, 0);
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.read(carray, 9); is_04.read(carray, 9);
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= !strncmp(carray, "soul eyes", 9); VERIFY( !strncmp(carray, "soul eyes", 9) );
test &= is_04.peek() == ':'; VERIFY( is_04.peek() == ':' );
state1 = is_03.rdstate(); state1 = is_03.rdstate();
is_03.read(carray, 60); is_03.read(carray, 60);
state2 = is_03.rdstate(); state2 = is_03.rdstate();
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & stateeof); VERIFY( static_cast<bool>(state2 & stateeof) );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
test &= !strncmp(carray, "soul eyes: john coltrane quartet", 35); VERIFY( !strncmp(carray, "soul eyes: john coltrane quartet", 35) );
// istream& ignore(streamsize n = 1, int_type delim = traits::eof()) // istream& ignore(streamsize n = 1, int_type delim = traits::eof())
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.ignore(); is_04.ignore();
test &= is_04.gcount() == 1; VERIFY( is_04.gcount() == 1 );
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= is_04.peek() == ' '; VERIFY( is_04.peek() == ' ' );
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.ignore(0); is_04.ignore(0);
test &= is_04.gcount() == 0; VERIFY( is_04.gcount() == 0 );
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= is_04.peek() == ' '; VERIFY( is_04.peek() == ' ' );
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.ignore(5, traits_type::to_int_type(' ')); is_04.ignore(5, traits_type::to_int_type(' '));
test &= is_04.gcount() == 1; VERIFY( is_04.gcount() == 1 );
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= is_04.peek() == 'j'; VERIFY( is_04.peek() == 'j' );
// int_type peek() // int_type peek()
state1 = is_04.rdstate(); state1 = is_04.rdstate();
test &= is_04.peek() == 'j'; VERIFY( is_04.peek() == 'j' );
test &= is_04.gcount() == 0; VERIFY( is_04.gcount() == 0 );
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
is_04.ignore(30); is_04.ignore(30);
state1 = is_04.rdstate(); state1 = is_04.rdstate();
test &= is_04.peek() == traits_type::eof(); VERIFY( is_04.peek() == traits_type::eof() );
test &= is_04.gcount() == 0; VERIFY( is_04.gcount() == 0 );
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
// istream& putback(char c) // istream& putback(char c)
is_04.clear(); is_04.clear();
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.putback('|'); is_04.putback('|');
test &= is_04.gcount() == 0; VERIFY( is_04.gcount() == 0 );
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= is_04.peek() == '|'; VERIFY( is_04.peek() == '|' );
// istream& unget() // istream& unget()
is_04.clear(); is_04.clear();
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.unget(); is_04.unget();
test &= is_04.gcount() == 0; VERIFY( is_04.gcount() == 0 );
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= state1 == state2; VERIFY( state1 == state2 );
test &= is_04.peek() == 'e'; VERIFY( is_04.peek() == 'e' );
// int sync() // int sync()
int i = is_00.sync(); int i = is_00.sync();
@ -134,10 +130,11 @@ bool test01() {
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
bool test02(void) int
test02()
{ {
typedef std::char_traits<char> traits_type; typedef std::char_traits<char> traits_type;
@ -166,67 +163,68 @@ bool test02(void)
state2 = is_00.rdstate(); state2 = is_00.rdstate();
// make sure failbit was set, since we couldn't extract // make sure failbit was set, since we couldn't extract
// from the NULL streambuf... // from the NULL streambuf...
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
test &= is_04.gcount() == 0; VERIFY( is_04.gcount() == 0 );
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.getline(carray1, 1, '\t'); // extracts, throws away is_04.getline(carray1, 1, '\t'); // extracts, throws away
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= is_04.gcount() == 1; VERIFY( is_04.gcount() == 1 );
test &= state1 == state2; VERIFY( state1 == state2 );
test &= state1 == 0; VERIFY( state1 == 0 );
test &= !traits_type::compare("", carray1, 1); VERIFY( !traits_type::compare("", carray1, 1) );
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.getline(carray1, 20, '*'); is_04.getline(carray1, 20, '*');
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= is_04.gcount() == 10; VERIFY( is_04.gcount() == 10 );
test &= state1 == state2; VERIFY( state1 == state2 );
test &= state1 == 0; VERIFY( state1 == 0 );
test &= !traits_type::compare("\t\t sun", carray1, 10); VERIFY( !traits_type::compare("\t\t sun", carray1, 10) );
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.getline(carray1, 20); is_04.getline(carray1, 20);
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= is_04.gcount() == 4; VERIFY( is_04.gcount() == 4 );
test &= state1 == state2; VERIFY( state1 == state2 );
test &= state1 == 0; VERIFY( state1 == 0 );
test &= !traits_type::compare("ra ", carray1, 4); VERIFY( !traits_type::compare("ra ", carray1, 4) );
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.getline(carray1, 65); is_04.getline(carray1, 65);
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= is_04.gcount() == 64; VERIFY( is_04.gcount() == 64 );
test &= state1 != state2; VERIFY( state1 != state2 );
test &= state2 == statefail; VERIFY( state2 == statefail );
test &= !traits_type::compare(" and his myth science arkestra presen", carray1, 65); VERIFY( !traits_type::compare(" and his myth science arkestra presen", carray1, 65) );
is_04.clear(); is_04.clear();
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.getline(carray1, 120, '|'); is_04.getline(carray1, 120, '|');
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= is_04.gcount() == 106; VERIFY( is_04.gcount() == 106 );
test &= state1 != state2; VERIFY( state1 != state2 );
test &= state2 == stateeof; VERIFY( state2 == stateeof );
is_04.clear(); is_04.clear();
state1 = is_04.rdstate(); state1 = is_04.rdstate();
is_04.getline(carray1, 100, '|'); is_04.getline(carray1, 100, '|');
state2 = is_04.rdstate(); state2 = is_04.rdstate();
test &= is_04.gcount() == 0; VERIFY( is_04.gcount() == 0 );
test &= state1 != state2; VERIFY( state1 != state2 );
test &= static_cast<bool>(state2 & stateeof); VERIFY( static_cast<bool>(state2 & stateeof) );
test &= static_cast<bool>(state2 & statefail); VERIFY( static_cast<bool>(state2 & statefail) );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
bool test03(void) int
test03()
{ {
typedef std::char_traits<char> traits_type; typedef std::char_traits<char> traits_type;
@ -256,73 +254,74 @@ bool test03(void)
// istream& get(streambuf&, char delim) // istream& get(streambuf&, char delim)
// istream& get(streambuf&) // istream& get(streambuf&)
is_00.get(carray1, 2); is_00.get(carray1, 2);
test &= static_cast<bool>(is_00.rdstate() & statefail); VERIFY( static_cast<bool>(is_00.rdstate() & statefail) );
test &= is_00.gcount() == 0; VERIFY( is_00.gcount() == 0 );
is_04.get(carray1, 4); is_04.get(carray1, 4);
test &= !(is_04.rdstate() & statefail); VERIFY( !(is_04.rdstate() & statefail) );
test &= !traits_type::compare(carray1, " ", 4); VERIFY( !traits_type::compare(carray1, " ", 4) );
test &= is_04.gcount() == 3; VERIFY( is_04.gcount() == 3 );
is_04.clear(); is_04.clear();
is_04.get(carray1 + 3, 200); is_04.get(carray1 + 3, 200);
test &= !(is_04.rdstate() & statefail); VERIFY( !(is_04.rdstate() & statefail) );
test &= !(is_04.rdstate() & stateeof); VERIFY( !(is_04.rdstate() & stateeof) );
test &= !traits_type::compare(carray1, str_lit01, 10); VERIFY( !traits_type::compare(carray1, str_lit01, 10) );
test &= is_04.gcount() == 7; VERIFY( is_04.gcount() == 7 );
is_04.clear(); is_04.clear();
is_04.get(carray1, 200); is_04.get(carray1, 200);
test &= !(is_04.rdstate() & stateeof); VERIFY( !(is_04.rdstate() & stateeof) );
test &= static_cast<bool>(is_04.rdstate() & statefail); // delimiter VERIFY( static_cast<bool>(is_04.rdstate() & statefail) ); // delimiter
test &= is_04.gcount() == 0; VERIFY( is_04.gcount() == 0 );
is_04.clear(); is_04.clear();
is_04.get(carray1, 200, '['); is_04.get(carray1, 200, '[');
test &= static_cast<bool>(is_04.rdstate() & stateeof); VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) );
test &= !(is_04.rdstate() & statefail); VERIFY( !(is_04.rdstate() & statefail) );
test &= is_04.gcount() == 125; VERIFY( is_04.gcount() == 125 );
is_04.clear(); is_04.clear();
is_04.get(carray1, 200); is_04.get(carray1, 200);
test &= static_cast<bool>(is_04.rdstate() & stateeof); VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) );
test &= static_cast<bool>(is_04.rdstate() & statefail); VERIFY( static_cast<bool>(is_04.rdstate() & statefail) );
test &= is_04.gcount() == 0; VERIFY( is_04.gcount() == 0 );
std::stringbuf sbuf_02(std::ios_base::in); std::stringbuf sbuf_02(std::ios_base::in);
is_05.clear(); is_05.clear();
is_05.get(sbuf_02); is_05.get(sbuf_02);
test &= is_05.gcount() == 0; VERIFY( is_05.gcount() == 0 );
test &= static_cast<bool>(is_05.rdstate() & statefail); VERIFY( static_cast<bool>(is_05.rdstate() & statefail) );
test &= !(is_05.rdstate() & stateeof); VERIFY( !(is_05.rdstate() & stateeof) );
is_05.clear(); is_05.clear();
is_05.get(sbuf_03); is_05.get(sbuf_03);
test &= is_05.gcount() == 10; VERIFY( is_05.gcount() == 10 );
test &= sbuf_03.str() == " sun*ra "; VERIFY( sbuf_03.str() == " sun*ra " );
test &= !(is_05.rdstate() & statefail); VERIFY( !(is_05.rdstate() & statefail) );
test &= !(is_05.rdstate() & stateeof); VERIFY( !(is_05.rdstate() & stateeof) );
is_05.clear(); is_05.clear();
is_05.get(sbuf_03, '|'); is_05.get(sbuf_03, '|');
test &= is_05.gcount() == 125; VERIFY( is_05.gcount() == 125 );
test &= sbuf_03.str() == str_lit01; VERIFY( sbuf_03.str() == str_lit01 );
test &= !(is_05.rdstate() & statefail); VERIFY( !(is_05.rdstate() & statefail) );
test &= static_cast<bool>(is_05.rdstate() & stateeof); VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) );
is_05.clear(); is_05.clear();
is_05.get(sbuf_03, '|'); is_05.get(sbuf_03, '|');
test &= is_05.gcount() == 0; VERIFY( is_05.gcount() == 0 );
test &= static_cast<bool>(is_05.rdstate() & stateeof); VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) );
test &= static_cast<bool>(is_05.rdstate() & statefail); VERIFY( static_cast<bool>(is_05.rdstate() & statefail) );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
// http://sourceware.cygnus.com/ml/libstdc++/2000-q1/msg00177.html // http://sourceware.cygnus.com/ml/libstdc++/2000-q1/msg00177.html
void test04() int
test04()
{ {
bool test = true; bool test = true;
@ -337,21 +336,23 @@ void test04()
stateeof = std::ios_base::eofbit; stateeof = std::ios_base::eofbit;
state1 = stateeof | statefail; state1 = stateeof | statefail;
test &= is_00.gcount() == 0; VERIFY( is_00.gcount() == 0 );
is_00.read(c_array, str_00.size() + 1); is_00.read(c_array, str_00.size() + 1);
test &= is_00.gcount() == str_00.size(); VERIFY( is_00.gcount() == str_00.size() );
test &= is_00.rdstate() == state1; VERIFY( is_00.rdstate() == state1 );
is_00.read(c_array, str_00.size()); is_00.read(c_array, str_00.size());
test &= is_00.rdstate() == state1; VERIFY( is_00.rdstate() == state1 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return 0;
} }
// http://sourceware.cygnus.com/ml/libstdc++/2000-07/msg00003.html // http://sourceware.cygnus.com/ml/libstdc++/2000-07/msg00003.html
bool test05() int
test05()
{ {
const char* charray = " const char* charray = "
a a
@ -420,7 +421,7 @@ aaaaaaaaaaaaaa
// http://sources.redhat.com/ml/libstdc++/2000-07/msg00126.html // http://sources.redhat.com/ml/libstdc++/2000-07/msg00126.html
bool int
test06() test06()
{ {
using namespace std; using namespace std;
@ -434,24 +435,26 @@ test06()
istream istr(&strbuf); istream istr(&strbuf);
istr.getline(tmp,it); istr.getline(tmp,it);
test &= istr.gcount() == it; // extracted whole string VERIFY( istr.gcount() == it ); // extracted whole string
test &= strlen(tmp) == 4; // stored all but '\n' VERIFY( strlen(tmp) == 4 ); // stored all but '\n'
test &= !istr.eof(); // extracted up to but not eof VERIFY( !istr.eof() ); // extracted up to but not eof
test &= !istr.fail(); // failbit not set VERIFY( !istr.fail() ); // failbit not set
char c = 'z'; char c = 'z';
istr.get(c); istr.get(c);
test &= c == 'z'; VERIFY( c == 'z' );
test &= istr.eof(); VERIFY( istr.eof() );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test;
return 0;
} }
int main() int
main()
{ {
test01(); test01();
test02(); test02();
@ -459,6 +462,7 @@ int main()
test04(); test04();
test05(); test05();
test06(); test06();
return 0; return 0;
} }

View File

@ -24,9 +24,7 @@
// stringbuf* rdbuf() const // stringbuf* rdbuf() const
#include <sstream> #include <sstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
void test01() void test01()
@ -47,30 +45,30 @@ void test01()
state1 = is01.rdstate(); state1 = is01.rdstate();
is01 >> a; is01 >> a;
state2 = is01.rdstate(); state2 = is01.rdstate();
test &= a = i01; VERIFY( a = i01 );
// 22.2.2.1.2 num_get virtual functions // 22.2.2.1.2 num_get virtual functions
// p 13 // p 13
// in any case, if stage 2 processing was terminated by the test for // in any case, if stage 2 processing was terminated by the test for
// in == end then err != ios_base::eofbit is performed. // in == end then err != ios_base::eofbit is performed.
test &= state1 != state2; VERIFY( state1 != state2 );
test &= state2 == stateeof; VERIFY( state2 == stateeof );
is01.str(str01); is01.str(str01);
is01 >> b; is01 >> b;
test &= b != a; VERIFY( b != a );
// as is01.good() is false, istream::sentry blocks extraction. // as is01.good() is false, istream::sentry blocks extraction.
is01.clear(); is01.clear();
state1 = is01.rdstate(); state1 = is01.rdstate();
is01 >> b; is01 >> b;
state2 = is01.rdstate(); state2 = is01.rdstate();
test &= b == a; VERIFY( b == a );
test &= state1 != state2; VERIFY( state1 != state2 );
test &= state2 == stateeof; VERIFY( state2 == stateeof );
// string str() const // string str() const
str02 = is01.str(); str02 = is01.str();
test &= str01 == str02; VERIFY( str01 == str02 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -66,13 +66,15 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include <debug_assert.h>
// Include iostream last, just to make is as difficult as possible to // Include iostream last, just to make is as difficult as possible to
// properly initialize the standard iostream objects. // properly initialize the standard iostream objects.
#include <iostream> #include <iostream>
// Make sure all the standard streams are defined. // Make sure all the standard streams are defined.
bool test01() int
test01()
{ {
bool test = true; bool test = true;
@ -83,17 +85,19 @@ bool test01()
array1[i] = '\0'; array1[i] = '\0';
std::cout << "testing cout" << std::endl; std::cout << "testing cout" << std::endl;
std::cerr << "testing cerr" << std::endl; std::cerr << "testing cerr" << std::endl;
test &= std::cerr.flags() & std::ios_base::unitbuf; VERIFY( std::cerr.flags() & std::ios_base::unitbuf );
std::clog << "testing clog" << std::endl; std::clog << "testing clog" << std::endl;
// std::cin >> array1; // requires somebody to type something in. // std::cin >> array1; // requires somebody to type something in.
test &= std::cin.tie() == &std::cout; VERIFY( std::cin.tie() == &std::cout );
return test; return 0;
} }
int main(void) int
main()
{ {
test01(); test01();
return 0; return 0;
} }

View File

@ -20,9 +20,7 @@
#include <ostream> #include <ostream>
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
const char name_01[] = "testsuite/ofstream_members-1.tst"; const char name_01[] = "testsuite/ofstream_members-1.tst";
const char name_02[] = "testsuite/ofstream_members-1.txt"; const char name_02[] = "testsuite/ofstream_members-1.txt";
@ -35,15 +33,15 @@ bool test00()
ofs1.close(); ofs1.close();
// false as expected: // false as expected:
test &= !ofs1.is_open(); VERIFY( !ofs1.is_open() );
// this is now true: // this is now true:
test &= !(ofs1); VERIFY( !(ofs1) );
ofs1.open(name_02); ofs1.open(name_02);
test &= ofs1.is_open(); VERIFY( ofs1.is_open() );
// fail bit still true // fail bit still true
test &= !(ofs1); VERIFY( !(ofs1) );
test &= ofs1.rdstate() == std::ios_base::failbit; VERIFY( ofs1.rdstate() == std::ios_base::failbit );
ofs1.close(); ofs1.close();
@ -64,7 +62,7 @@ bool test01()
for(int i = 0; ++i < more_than_max_open_files;) for(int i = 0; ++i < more_than_max_open_files;)
{ {
std::ofstream ifs(name_02); std::ofstream ifs(name_02);
test &= static_cast<bool>(ifs); VERIFY( static_cast<bool>(ifs) );
} }
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT

View File

@ -24,7 +24,7 @@
#include <locale> #include <locale>
#include <sstream> #include <sstream>
#include <limits> #include <limits>
#include <assert.h> #include <debug_assert.h>
using namespace std; using namespace std;
@ -187,8 +187,10 @@ void apply_formatting(const _TestCase & tc, basic_ostream<_CharT> & os)
os.setf(ios::right); os.setf(ios::right);
} }
void test01() int
test01()
{ {
bool test = true;
for (int j=0; j<sizeof(testcases)/sizeof(testcases[0]); j++) for (int j=0; j<sizeof(testcases)/sizeof(testcases[0]); j++)
{ {
_TestCase & tc = testcases[j]; _TestCase & tc = testcases[j];
@ -206,7 +208,7 @@ void test01()
#ifdef TEST_NUMPUT_VERBOSE #ifdef TEST_NUMPUT_VERBOSE
cout << "result: " << os.str() << endl; cout << "result: " << os.str() << endl;
#endif #endif
assert(os && os.str() == tc.result); VERIFY( os && os.str() == tc.result );
} }
// test long double with char type // test long double with char type
{ {
@ -219,7 +221,7 @@ void test01()
#ifdef TEST_NUMPUT_VERBOSE #ifdef TEST_NUMPUT_VERBOSE
cout << "result: " << os.str() << endl; cout << "result: " << os.str() << endl;
#endif #endif
assert(os && os.str() == tc.result); VERIFY( os && os.str() == tc.result );
} }
#if _GLIBCPP_USE_WCHAR_T #if _GLIBCPP_USE_WCHAR_T
// test double with wchar_t type // test double with wchar_t type
@ -230,7 +232,7 @@ void test01()
os.imbue(__loc); os.imbue(__loc);
apply_formatting(tc, os); apply_formatting(tc, os);
os << tc.val; os << tc.val;
assert(os && os.str() == tc.wresult); VERIFY( os && os.str() == tc.wresult );
} }
// test long double with wchar_t type // test long double with wchar_t type
{ {
@ -240,14 +242,18 @@ void test01()
os.imbue(__loc); os.imbue(__loc);
apply_formatting(tc, os); apply_formatting(tc, os);
os << (long double)tc.val; os << (long double)tc.val;
assert(os && os.str() == tc.wresult); VERIFY( os && os.str() == tc.wresult );
} }
#endif #endif
} }
return 0;
} }
void test02() int
test02()
{ {
bool test = true;
// make sure we can output a very long float // make sure we can output a very long float
long double val = 1.2345678901234567890123456789e+1000L; long double val = 1.2345678901234567890123456789e+1000L;
int prec = numeric_limits<long double>::digits10; int prec = numeric_limits<long double>::digits10;
@ -263,10 +269,13 @@ void test02()
cout << "expect: " << largebuf << endl; cout << "expect: " << largebuf << endl;
cout << "result: " << os.str() << endl; cout << "result: " << os.str() << endl;
#endif #endif
assert(os && os.str() == largebuf); VERIFY(os && os.str() == largebuf);
return 0;
} }
void test03() int
test03()
{ {
short s = -1; short s = -1;
int i = -1; int i = -1;
@ -279,24 +288,27 @@ void test03()
ostream o(&strbuf); ostream o(&strbuf);
o << oct << s << ' ' << hex << s; o << oct << s << ' ' << hex << s;
test &= strbuf.str() == "177777 ffff"; // Assuming 2byte-shorts VERIFY( strbuf.str() == "177777 ffff" ); // Assuming 2byte-shorts
strbuf.str(str_blank); strbuf.str(str_blank);
o << oct << i << ' ' << hex << i; o << oct << i << ' ' << hex << i;
test &= strbuf.str() == "37777777777 ffffffff"; VERIFY( strbuf.str() == "37777777777 ffffffff" );
strbuf.str(str_blank); strbuf.str(str_blank);
o << oct << l << ' ' << hex << l; o << oct << l << ' ' << hex << l;
test &= strbuf.str() == "37777777777 ffffffff"; VERIFY( strbuf.str() == "37777777777 ffffffff" );
strbuf.str(str_blank); strbuf.str(str_blank);
o << showpos << hex << showbase << 11; o << showpos << hex << showbase << 11;
test &= strbuf.str() == "0xb"; VERIFY( strbuf.str() == "0xb" );
assert(test); VERIFY(test);
return 0;
} }
int main() int
main()
{ {
test01(); test01();
test02(); test02();

View File

@ -24,9 +24,7 @@
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
// ofstream // ofstream
bool test01() bool test01()
@ -75,7 +73,7 @@ bool test02(void)
oss01.flags(std::ios_base::left); oss01.flags(std::ios_base::left);
oss01 << str01; oss01 << str01;
tmp = oss01.str(); tmp = oss01.str();
test &= tmp == "00000"; VERIFY( tmp == "00000" );
std::string str02 = "1"; std::string str02 = "1";
std::ostringstream oss02; std::ostringstream oss02;
@ -84,7 +82,7 @@ bool test02(void)
oss02.flags(std::ios_base::left); oss02.flags(std::ios_base::left);
oss02 << str02; oss02 << str02;
tmp = oss02.str(); tmp = oss02.str();
test &= tmp == "10000"; VERIFY( tmp == "10000" );
std::string str03 = "909909"; std::string str03 = "909909";
std::ostringstream oss03; std::ostringstream oss03;
@ -93,7 +91,7 @@ bool test02(void)
oss03.flags(std::ios_base::left); oss03.flags(std::ios_base::left);
oss03 << str03; oss03 << str03;
tmp = oss03.str(); tmp = oss03.str();
test &= tmp == "909909"; VERIFY( tmp == "909909" );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -116,7 +114,7 @@ bool test03(void)
oss01.flags(std::ios_base::right); oss01.flags(std::ios_base::right);
oss01 << str01; oss01 << str01;
tmp = oss01.str(); tmp = oss01.str();
test &= tmp == "00000"; VERIFY( tmp == "00000" );
std::string str02 = "1"; std::string str02 = "1";
std::ostringstream oss02; std::ostringstream oss02;
@ -125,7 +123,7 @@ bool test03(void)
oss02.flags(std::ios_base::right); oss02.flags(std::ios_base::right);
oss02 << str02; oss02 << str02;
tmp = oss02.str(); tmp = oss02.str();
test &= tmp == "00001"; VERIFY( tmp == "00001" );
std::string str03 = "909909"; std::string str03 = "909909";
std::ostringstream oss03; std::ostringstream oss03;
@ -134,7 +132,7 @@ bool test03(void)
oss03.flags(std::ios_base::right); oss03.flags(std::ios_base::right);
oss03 << str03; oss03 << str03;
tmp = oss03.str(); tmp = oss03.str();
test &= tmp == "909909"; VERIFY( tmp == "909909" );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -164,10 +162,10 @@ bool test04() {
for (int i = 0; i < i_max; ++i) for (int i = 0; i < i_max; ++i)
oss_02 << "Test: " << i << std::endl; oss_02 << "Test: " << i << std::endl;
str_tmp = oss_02.str(); str_tmp = oss_02.str();
test &= !oss_02.bad(); VERIFY( !oss_02.bad() );
test &= oss_02.good(); VERIFY( oss_02.good() );
test &= str_tmp != str_01; VERIFY( str_tmp != str_01 );
test &= str_tmp.size() == 2390; VERIFY( str_tmp.size() == 2390 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -207,8 +205,8 @@ bool test05()
sstr02 << str01; sstr02 << str01;
str05 = sstr01.str(); str05 = sstr01.str();
str10 = sstr02.str(); str10 = sstr02.str();
test &= str05 == str01; VERIFY( str05 == str01 );
test &= str10 == str01; VERIFY( str10 == str01 );
// test 2: in | out // test 2: in | out
std::ostringstream sstr04(str01, std::ios_base::out | std::ios_base::in); std::ostringstream sstr04(str01, std::ios_base::out | std::ios_base::in);
@ -216,8 +214,8 @@ bool test05()
sstr05 << str01; sstr05 << str01;
str05 = sstr04.str(); str05 = sstr04.str();
str10 = sstr05.str(); str10 = sstr05.str();
test &= str05 == str01; VERIFY( str05 == str01 );
test &= str10 == str01; VERIFY( str10 == str01 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -236,21 +234,21 @@ void test06()
// normal // normal
std::ostringstream ostr1("mos def"); std::ostringstream ostr1("mos def");
test &= ostr1.str() == "mos def"; VERIFY( ostr1.str() == "mos def" );
ostr1 << " & talib kweli"; // should overwrite first part of buffer ostr1 << " & talib kweli"; // should overwrite first part of buffer
test &= ostr1.str() == " & talib kweli"; VERIFY( ostr1.str() == " & talib kweli" );
ostr1 << " are black star"; // should append to string from above ostr1 << " are black star"; // should append to string from above
test &= ostr1.str() != carray01; VERIFY( ostr1.str() != carray01 );
test &= ostr1.str() == " & talib kweli are black star"; VERIFY( ostr1.str() == " & talib kweli are black star" );
// appending // appending
std::ostringstream ostr2("blackalicious", std::ostringstream ostr2("blackalicious",
std::ios_base::out | std::ios_base::ate); std::ios_base::out | std::ios_base::ate);
test &= ostr2.str() == "blackalicious"; VERIFY( ostr2.str() == "blackalicious" );
ostr2 << " NIA "; // should not overwrite first part of buffer ostr2 << " NIA "; // should not overwrite first part of buffer
test &= ostr2.str() == "blackalicious NIA "; VERIFY( ostr2.str() == "blackalicious NIA " );
ostr2 << "4: deception (5:19)"; // should append to full string from above ostr2 << "4: deception (5:19)"; // should append to full string from above
test &= ostr2.str() == "blackalicious NIA 4: deception (5:19)"; VERIFY( ostr2.str() == "blackalicious NIA 4: deception (5:19)" );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -24,9 +24,7 @@
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
const int size = 1000; const int size = 1000;
const char name_01[] = "testsuite/ostream_inserter_other-1.tst"; const char name_01[] = "testsuite/ostream_inserter_other-1.tst";
@ -36,16 +34,20 @@ const char name_04[] = "testsuite/ostream_inserter_other-2.txt";
// stringstream // stringstream
bool test01() { int
test01()
{
bool test = true; bool test = true;
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
// fstream // fstream
bool test02() { int
test02()
{
typedef std::ios_base::iostate iostate; typedef std::ios_base::iostate iostate;
bool test = true; bool test = true;
@ -57,13 +59,13 @@ bool test02() {
iostate state01 = f_in1.rdstate(); iostate state01 = f_in1.rdstate();
f_in1 >> strbuf01; f_in1 >> strbuf01;
iostate state02 = f_in1.rdstate(); iostate state02 = f_in1.rdstate();
test &= state01 != state02; VERIFY( state01 != state02 );
test &= (state02 & std::ios_base::failbit) != 0; VERIFY( (state02 & std::ios_base::failbit) != 0 );
state01 = f_out1.rdstate(); state01 = f_out1.rdstate();
f_out1 << strbuf01; f_out1 << strbuf01;
state02 = f_out1.rdstate(); state02 = f_out1.rdstate();
test &= state01 != state02; VERIFY( state01 != state02 );
test &= (state02 & std::ios_base::failbit) != 0; VERIFY( (state02 & std::ios_base::failbit) != 0 );
// filebuf->filebuf // filebuf->filebuf
std::ifstream f_in(name_01); std::ifstream f_in(name_01);
@ -86,8 +88,8 @@ bool test02() {
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
// via Brent Verner <brent@rcfile.org> // via Brent Verner <brent@rcfile.org>
@ -130,7 +132,8 @@ test03(void)
return 0; return 0;
} }
int main() int
main()
{ {
test01(); test01();
test02(); test02();

View File

@ -23,9 +23,7 @@
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01(void) bool test01(void)
{ {
@ -47,33 +45,33 @@ bool test01(void)
oss01 << std::endl; oss01 << std::endl;
str04 = oss01.str(); str04 = oss01.str();
test &= str04.size() == str01.size(); VERIFY( str04.size() == str01.size() );
oss02 << std::endl; oss02 << std::endl;
str05 = oss02.str(); str05 = oss02.str();
test &= str05.size() == 1; VERIFY( str05.size() == 1 );
// template<_CharT, _Traits> // template<_CharT, _Traits>
// basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os) // basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os)
oss01 << std::ends; oss01 << std::ends;
str04 = oss01.str(); str04 = oss01.str();
test &= str04.size() == str01.size(); VERIFY( str04.size() == str01.size() );
test &= str04[1] == char(); VERIFY( str04[1] == char() );
oss02 << std::ends; oss02 << std::ends;
str05 = oss02.str(); str05 = oss02.str();
test &= str05.size() == 2; VERIFY( str05.size() == 2 );
test &= str05[1] == char(); VERIFY( str05[1] == char() );
// template<_CharT, _Traits> // template<_CharT, _Traits>
// basic_ostream<_CharT, _Traits>& flush(basic_ostream<_Char, _Traits>& os) // basic_ostream<_CharT, _Traits>& flush(basic_ostream<_Char, _Traits>& os)
oss01.flush(); oss01.flush();
str04 = oss01.str(); str04 = oss01.str();
test &= str04.size() == str01.size(); VERIFY( str04.size() == str01.size() );
oss02.flush(); oss02.flush();
str05 = oss02.str(); str05 = oss02.str();
test &= str05.size() == 2; VERIFY( str05.size() == 2 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -94,7 +92,7 @@ bool test02()
const string str_00("herbie_hancock"); const string str_00("herbie_hancock");
int_type len1 = str_00.size(); int_type len1 = str_00.size();
osst_01 << str_00; osst_01 << str_00;
test &= osst_01.str().size() == len1; VERIFY( osst_01.str().size() == len1 );
osst_01 << ends; osst_01 << ends;
@ -102,8 +100,8 @@ bool test02()
int_type len2 = str_01.size(); int_type len2 = str_01.size();
osst_01 << str_01; osst_01 << str_01;
int_type len3 = osst_01.str().size(); int_type len3 = osst_01.str().size();
test &= len1 < len3; VERIFY( len1 < len3 );
test &= len3 == len1 + len2 + 1; VERIFY( len3 == len1 + len2 + 1 );
osst_01 << ends; osst_01 << ends;
@ -111,8 +109,8 @@ bool test02()
int_type len4 = str_02.size(); int_type len4 = str_02.size();
osst_01 << str_02; osst_01 << str_02;
int_type len5 = osst_01.str().size(); int_type len5 = osst_01.str().size();
test &= len3 < len5; VERIFY( len3 < len5 );
test &= len5 == len3 + len4 + 1; VERIFY( len5 == len3 + len4 + 1 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -23,9 +23,7 @@
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
bool test01() bool test01()
@ -44,7 +42,7 @@ bool test01()
ofstream ofs1; ofstream ofs1;
pos_type p2 = ofs1.tellp(); pos_type p2 = ofs1.tellp();
test &= p1 == p2; VERIFY( p1 == p2 );
// out // out
// test ctors leave things in the same positions... // test ctors leave things in the same positions...
@ -54,7 +52,7 @@ bool test01()
ofstream ofs2(str_lit01); ofstream ofs2(str_lit01);
p2 = ofs2.tellp(); p2 = ofs2.tellp();
test &= p1 == p2; VERIFY( p1 == p2 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -79,9 +77,9 @@ void test04(void)
std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out); std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out);
std::ifstream if02(str_lit01, std::ios_base::in); std::ifstream if02(str_lit01, std::ios_base::in);
std::ifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc); std::ifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc);
test &= if01.good(); VERIFY( if01.good() );
test &= if02.good(); VERIFY( if02.good() );
test &= if03.good(); VERIFY( if03.good() );
std::istream is01(if01.rdbuf()); std::istream is01(if01.rdbuf());
std::istream is02(if02.rdbuf()); std::istream is02(if02.rdbuf());
@ -91,20 +89,20 @@ void test04(void)
// in | out // in | out
pos01 = is01.tellp(); pos01 = is01.tellp();
pos02 = is01.tellp(); pos02 = is01.tellp();
test &= pos01 == pos02; VERIFY( pos01 == pos02 );
// test &= istream::pos_type(0) != pos01; //depricated // VERIFY( istream::pos_type(0) != pos01 ); //depricated
// in // in
pos03 = is02.tellp(); pos03 = is02.tellp();
pos04 = is02.tellp(); pos04 = is02.tellp();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
// test &= istream::pos_type(0) != pos03; //depricated // VERIFY( istream::pos_type(0) != pos03 ); //depricated
// out // out
pos05 = is03.tellp(); pos05 = is03.tellp();
pos06 = is03.tellp(); pos06 = is03.tellp();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
// test &= istream::pos_type(0) != pos01; //depricated // VERIFY( istream::pos_type(0) != pos01 ); //depricated
// istream& seekg(pos_type) // istream& seekg(pos_type)
// istream& seekg(off_type, ios_base::seekdir) // istream& seekg(off_type, ios_base::seekdir)
@ -118,56 +116,56 @@ void test04(void)
is01.seekg(10, std::ios_base::cur); is01.seekg(10, std::ios_base::cur);
state02 = is01.rdstate(); state02 = is01.rdstate();
pos01 = is01.tellp(); pos01 = is01.tellp();
test &= pos01 == pos02 + 10; VERIFY( pos01 == pos02 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos02 = is01.tellp(); pos02 = is01.tellp();
test &= pos02 == pos01; VERIFY( pos02 == pos01 );
state01 = is02.rdstate(); state01 = is02.rdstate();
is02.seekg(10, std::ios_base::cur); is02.seekg(10, std::ios_base::cur);
state02 = is02.rdstate(); state02 = is02.rdstate();
pos03 = is02.tellp(); pos03 = is02.tellp();
test &= pos03 == pos04 + 10; VERIFY( pos03 == pos04 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos04 = is02.tellp(); pos04 = is02.tellp();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
state01 = is03.rdstate(); state01 = is03.rdstate();
is03.seekg(10, std::ios_base::cur); is03.seekg(10, std::ios_base::cur);
state02 = is03.rdstate(); state02 = is03.rdstate();
pos05 = is03.tellp(); pos05 = is03.tellp();
test &= pos05 == pos06 + 10; VERIFY( pos05 == pos06 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos06 = is03.tellp(); pos06 = is03.tellp();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
// beg // beg
state01 = is01.rdstate(); state01 = is01.rdstate();
is01.seekg(20, std::ios_base::beg); is01.seekg(20, std::ios_base::beg);
state02 = is01.rdstate(); state02 = is01.rdstate();
pos01 = is01.tellp(); pos01 = is01.tellp();
test &= pos01 == pos02 + 10; VERIFY( pos01 == pos02 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos02 = is01.tellp(); pos02 = is01.tellp();
test &= pos02 == pos01; VERIFY( pos02 == pos01 );
state01 = is02.rdstate(); state01 = is02.rdstate();
is02.seekg(20, std::ios_base::beg); is02.seekg(20, std::ios_base::beg);
state02 = is02.rdstate(); state02 = is02.rdstate();
pos03 = is02.tellp(); pos03 = is02.tellp();
test &= pos03 == pos04 + 10; VERIFY( pos03 == pos04 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos04 = is02.tellp(); pos04 = is02.tellp();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
state01 = is03.rdstate(); state01 = is03.rdstate();
is03.seekg(20, std::ios_base::beg); is03.seekg(20, std::ios_base::beg);
state02 = is03.rdstate(); state02 = is03.rdstate();
pos05 = is03.tellp(); pos05 = is03.tellp();
test &= pos05 == pos06 + 10; VERIFY( pos05 == pos06 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos06 = is03.tellp(); pos06 = is03.tellp();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -184,9 +182,9 @@ void test05(void)
std::ifstream if01(str_lit01); std::ifstream if01(str_lit01);
std::ifstream if02(str_lit01); std::ifstream if02(str_lit01);
std::ifstream if03(str_lit01); std::ifstream if03(str_lit01);
test &= if01.good(); VERIFY( if01.good() );
test &= if02.good(); VERIFY( if02.good() );
test &= if03.good(); VERIFY( if03.good() );
std::stringbuf strbuf01(std::ios_base::in | std::ios_base::out); std::stringbuf strbuf01(std::ios_base::in | std::ios_base::out);
if01 >> &strbuf01; if01 >> &strbuf01;
@ -203,20 +201,20 @@ void test05(void)
// in | out // in | out
pos01 = is01.tellp(); pos01 = is01.tellp();
pos02 = is01.tellp(); pos02 = is01.tellp();
test &= pos01 == pos02; VERIFY( pos01 == pos02 );
// test &= istream::pos_type(0) != pos01; // deprecated // VERIFY( istream::pos_type(0) != pos01 ); // deprecated
// in // in
pos03 = is02.tellp(); pos03 = is02.tellp();
pos04 = is02.tellp(); pos04 = is02.tellp();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
// test &= istream::pos_type(0) != pos03; // deprecated // VERIFY( istream::pos_type(0) != pos03 ); // deprecated
// out // out
pos05 = is03.tellp(); pos05 = is03.tellp();
pos06 = is03.tellp(); pos06 = is03.tellp();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
// test &= istream::pos_type(0) != pos01; //deprecated // VERIFY( istream::pos_type(0) != pos01 ); //deprecated
// istream& seekg(pos_type) // istream& seekg(pos_type)
// istream& seekg(off_type, ios_base::seekdir) // istream& seekg(off_type, ios_base::seekdir)
@ -230,56 +228,56 @@ void test05(void)
is01.seekg(10, std::ios_base::cur); is01.seekg(10, std::ios_base::cur);
state02 = is01.rdstate(); state02 = is01.rdstate();
pos01 = is01.tellp(); pos01 = is01.tellp();
test &= pos01 == pos02 + 10; VERIFY( pos01 == pos02 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos02 = is01.tellp(); pos02 = is01.tellp();
test &= pos02 == pos01; VERIFY( pos02 == pos01 );
state01 = is02.rdstate(); state01 = is02.rdstate();
is02.seekg(10, std::ios_base::cur); is02.seekg(10, std::ios_base::cur);
state02 = is02.rdstate(); state02 = is02.rdstate();
pos03 = is02.tellp(); pos03 = is02.tellp();
test &= pos03 == pos04 + 10; VERIFY( pos03 == pos04 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos04 = is02.tellp(); pos04 = is02.tellp();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
state01 = is03.rdstate(); state01 = is03.rdstate();
is03.seekg(10, std::ios_base::cur); is03.seekg(10, std::ios_base::cur);
state02 = is03.rdstate(); state02 = is03.rdstate();
pos05 = is03.tellp(); pos05 = is03.tellp();
test &= pos05 == pos06; // as only out buffer VERIFY( pos05 == pos06 ); // as only out buffer
test &= state01 == state02; VERIFY( state01 == state02 );
pos06 = is03.tellp(); pos06 = is03.tellp();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
// beg // beg
state01 = is01.rdstate(); state01 = is01.rdstate();
is01.seekg(20, std::ios_base::beg); is01.seekg(20, std::ios_base::beg);
state02 = is01.rdstate(); state02 = is01.rdstate();
pos01 = is01.tellp(); pos01 = is01.tellp();
test &= pos01 == pos02 + 10; VERIFY( pos01 == pos02 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos02 = is01.tellp(); pos02 = is01.tellp();
test &= pos02 == pos01; VERIFY( pos02 == pos01 );
state01 = is02.rdstate(); state01 = is02.rdstate();
is02.seekg(20, std::ios_base::beg); is02.seekg(20, std::ios_base::beg);
state02 = is02.rdstate(); state02 = is02.rdstate();
pos03 = is02.tellp(); pos03 = is02.tellp();
test &= pos03 == pos04 + 10; VERIFY( pos03 == pos04 + 10 );
test &= state01 == state02; VERIFY( state01 == state02 );
pos04 = is02.tellp(); pos04 = is02.tellp();
test &= pos03 == pos04; VERIFY( pos03 == pos04 );
state01 = is03.rdstate(); state01 = is03.rdstate();
is03.seekg(20, std::ios_base::beg); is03.seekg(20, std::ios_base::beg);
state02 = is03.rdstate(); state02 = is03.rdstate();
pos05 = is03.tellp(); pos05 = is03.tellp();
test &= pos05 == pos06; // as only out buffer VERIFY( pos05 == pos06 ); // as only out buffer
test &= state01 == state02; VERIFY( state01 == state02 );
pos06 = is03.tellp(); pos06 = is03.tellp();
test &= pos05 == pos06; VERIFY( pos05 == pos06 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -20,9 +20,7 @@
#include <sstream> #include <sstream>
#include <ostream> #include <ostream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
void test01() void test01()
@ -36,13 +34,13 @@ void test01()
ostringstream ost; ostringstream ost;
pos_type pos1; pos_type pos1;
pos1 = ost.tellp(); pos1 = ost.tellp();
test &= pos1 == pos_type(-1); VERIFY( pos1 == pos_type(-1) );
ost << "RZA "; ost << "RZA ";
pos1 = ost.tellp(); pos1 = ost.tellp();
test &= pos1 == pos_type(4); VERIFY( pos1 == pos_type(4) );
ost << "ghost dog: way of the samurai"; ost << "ghost dog: way of the samurai";
pos1 = ost.tellp(); pos1 = ost.tellp();
test &= pos1 == pos_type(33); VERIFY( pos1 == pos_type(33) );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);

View File

@ -31,9 +31,7 @@
#include <streambuf> #include <streambuf>
#include <ostream> #include <ostream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
class testbuf : public std::streambuf class testbuf : public std::streambuf
{ {
@ -50,12 +48,12 @@ public:
check_pointers() check_pointers()
{ {
bool test = true; bool test = true;
test &= this->eback() == NULL; VERIFY( this->eback() == NULL );
test &= this->gptr() == NULL; VERIFY( this->gptr() == NULL );
test &= this->egptr() == NULL; VERIFY( this->egptr() == NULL );
test &= this->pbase() == NULL; VERIFY( this->pbase() == NULL );
test &= this->pptr() == NULL; VERIFY( this->pptr() == NULL );
test &= this->epptr() == NULL; VERIFY( this->epptr() == NULL );
return test; return test;
} }
@ -103,33 +101,33 @@ void test01()
// default ctor initializes // default ctor initializes
// - all pointer members to null pointers // - all pointer members to null pointers
// - locale to current global locale // - locale to current global locale
test &= buf01.check_pointers(); VERIFY( buf01.check_pointers() );
test &= buf01.getloc() == std::locale(); VERIFY( buf01.getloc() == std::locale() );
// 27.5.2.3.1 get area // 27.5.2.3.1 get area
// 27.5.2.2.3 get area // 27.5.2.2.3 get area
// 27.5.2.4.3 get area // 27.5.2.4.3 get area
int i01 = 3; int i01 = 3;
buf01.pub_setg(lit01, lit01, (lit01 + i01)); buf01.pub_setg(lit01, lit01, (lit01 + i01));
test &= i01 == buf01.in_avail(); VERIFY( i01 == buf01.in_avail() );
test &= buf01.pub_uflow() == lit01[0]; VERIFY( buf01.pub_uflow() == lit01[0] );
test &= buf01.sgetc() == traits_type::to_int_type(lit01[1]); VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[1]) );
test &= buf01.pub_uflow() == lit01[1]; VERIFY( buf01.pub_uflow() == lit01[1] );
test &= buf01.sgetc() == traits_type::to_int_type(lit01[2]); VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[2]) );
test &= buf01.pub_uflow() == lit01[2]; VERIFY( buf01.pub_uflow() == lit01[2] );
test &= buf01.sgetc() == traits_type::eof(); VERIFY( buf01.sgetc() == traits_type::eof() );
// pbackfail // pbackfail
buf01.pub_setg(lit01, lit01, (lit01 + i01)); buf01.pub_setg(lit01, lit01, (lit01 + i01));
test &= i01 == buf01.in_avail(); VERIFY( i01 == buf01.in_avail() );
int_type intt01 = traits_type::to_int_type('b'); int_type intt01 = traits_type::to_int_type('b');
test &= traits_type::eof() == buf01.pub_pbackfail(intt01); VERIFY( traits_type::eof() == buf01.pub_pbackfail(intt01) );
// overflow // overflow
test &= traits_type::eof() == buf01.pub_overflow(intt01); VERIFY( traits_type::eof() == buf01.pub_overflow(intt01) );
test &= traits_type::eof() == buf01.pub_overflow(); VERIFY( traits_type::eof() == buf01.pub_overflow() );
test &= buf01.sgetc() == traits_type::to_int_type(lit01[0]); VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[0]) );
// sputn/xsputn // sputn/xsputn
char* lit02 = "isotope 217: the unstable molecule on thrill jockey"; char* lit02 = "isotope 217: the unstable molecule on thrill jockey";
@ -139,16 +137,16 @@ void test01()
buf01.pub_setp(carray, (carray + i02)); buf01.pub_setp(carray, (carray + i02));
buf01.sputn(lit02, 0); buf01.sputn(lit02, 0);
test &= carray[0] == 0; VERIFY( carray[0] == 0 );
test &= lit02[0] == 'i'; VERIFY( lit02[0] == 'i' );
buf01.sputn(lit02, 1); buf01.sputn(lit02, 1);
test &= lit02[0] == carray[0]; VERIFY( lit02[0] == carray[0] );
test &= lit02[1] == 's'; VERIFY( lit02[1] == 's' );
test &= carray[1] == 0; VERIFY( carray[1] == 0 );
buf01.sputn(lit02 + 1, 10); buf01.sputn(lit02 + 1, 10);
test &= memcmp(lit02, carray, 10) == 0; VERIFY( memcmp(lit02, carray, 10) == 0 );
buf01.sputn(lit02 + 11, 20); buf01.sputn(lit02 + 11, 20);
test &= memcmp(lit02, carray, 30) == 0; VERIFY( memcmp(lit02, carray, 30) == 0 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -168,8 +166,8 @@ void test02()
// default ctor initializes // default ctor initializes
// - all pointer members to null pointers // - all pointer members to null pointers
// - locale to current global locale // - locale to current global locale
test &= buf01.check_pointers(); VERIFY( buf01.check_pointers() );
test &= buf01.getloc() == std::locale(); VERIFY( buf01.getloc() == std::locale() );
// 27.5.2.2.5 Put area // 27.5.2.2.5 Put area
size_t i01 = traits_type::length(lit01); size_t i01 = traits_type::length(lit01);
@ -178,13 +176,13 @@ void test02()
buf01.pub_setg(lit01, lit01, lit01 + i01); buf01.pub_setg(lit01, lit01, lit01 + i01);
buf01.sgetn(carray01, 0); buf01.sgetn(carray01, 0);
test &= carray01[0] == 0; VERIFY( carray01[0] == 0 );
buf01.sgetn(carray01, 1); buf01.sgetn(carray01, 1);
test &= carray01[0] == 'c'; VERIFY( carray01[0] == 'c' );
buf01.sgetn(carray01 + 1, i01 - 1); buf01.sgetn(carray01 + 1, i01 - 1);
test &= carray01[0] == 'c'; VERIFY( carray01[0] == 'c' );
test &= carray01[1] == 'h'; VERIFY( carray01[1] == 'h' );
test &= carray01[i01 - 1] == 'k'; VERIFY( carray01[i01 - 1] == 'k' );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -227,7 +225,7 @@ void test03()
test01 += print('x'); test01 += print('x');
test01 += print("pipo"); test01 += print("pipo");
test &= test01 == control01; VERIFY( test01 == control01 );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif

View File

@ -19,9 +19,7 @@
// USA. // USA.
#include <sstream> #include <sstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
std::string str_01("mykonos. . . or what?"); std::string str_01("mykonos. . . or what?");
std::string str_02("paris, or sainte-maxime?"); std::string str_02("paris, or sainte-maxime?");
@ -59,20 +57,20 @@ bool test03() {
std::string str_tmp; std::string str_tmp;
//stringbuf::str() //stringbuf::str()
test &= strb_01.str() == str_01; VERIFY( strb_01.str() == str_01 );
test &= strb_02.str() == str_02; VERIFY( strb_02.str() == str_02 );
test &= strb_03.str() == str_03; VERIFY( strb_03.str() == str_03 );
//stringbuf::str(string&) //stringbuf::str(string&)
strb_03.str("none of the above, go to the oberoi in cairo, egypt."); strb_03.str("none of the above, go to the oberoi in cairo, egypt.");
strb_03.str(str_01); strb_03.str(str_01);
std::streamsize d1 = strb_01.in_avail(); std::streamsize d1 = strb_01.in_avail();
std::streamsize d2 = strb_03.in_avail(); std::streamsize d2 = strb_03.in_avail();
test &= d1; // non-zero VERIFY( d1 ); // non-zero
test &= !d2; // zero, cuz ios_base::out VERIFY( !d2 ); // zero, cuz ios_base::out
test &= d1 != d2; //these should be the same VERIFY( d1 != d2 ); //these should be the same
test &= str_01.length() == d1; VERIFY( str_01.length() == d1 );
test &= strb_01.str() == strb_03.str(); //ditto VERIFY( strb_01.str() == strb_03.str() ); //ditto
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
@ -98,50 +96,50 @@ bool test04() {
// int in_avail() // int in_avail()
strmof_1 = strb_01.in_avail(); strmof_1 = strb_01.in_avail();
strmof_2 = strb_02.in_avail(); strmof_2 = strb_02.in_avail();
test &= strmof_1 != strmof_2; VERIFY( strmof_1 != strmof_2 );
test &= strmof_1 == str_01.length(); VERIFY( strmof_1 == str_01.length() );
test &= strmof_2 == str_02.length(); VERIFY( strmof_2 == str_02.length() );
strmof_1 = strb_03.in_avail(); strmof_1 = strb_03.in_avail();
test &= strmof_1 == 0; // zero cuz write-only, or eof()? zero, from showmany VERIFY( strmof_1 == 0 ); // zero cuz write-only, or eof()? zero, from showmany
// int_type sbumpc() // int_type sbumpc()
// if read_cur not avail, return uflow(), else return *read_cur & increment // if read_cur not avail, return uflow(), else return *read_cur & increment
int_type c1 = strb_01.sbumpc(); int_type c1 = strb_01.sbumpc();
int_type c2 = strb_02.sbumpc(); int_type c2 = strb_02.sbumpc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c1 == str_01[0]; VERIFY( c1 == str_01[0] );
test &= c2 == str_02[0]; //should equal first letter at this point VERIFY( c2 == str_02[0] ); //should equal first letter at this point
int_type c3 = strb_01.sbumpc(); int_type c3 = strb_01.sbumpc();
int_type c4 = strb_02.sbumpc(); int_type c4 = strb_02.sbumpc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c1 != c3; VERIFY( c1 != c3 );
test &= c2 != c4; VERIFY( c2 != c4 );
int_type c5 = strb_03.sbumpc(); int_type c5 = strb_03.sbumpc();
test &= c5 == traits_type::eof(); VERIFY( c5 == traits_type::eof() );
// int_type sgetc() // int_type sgetc()
// if read_cur not avail, return uflow(), else return *read_cur // if read_cur not avail, return uflow(), else return *read_cur
int_type c6 = strb_01.sgetc(); int_type c6 = strb_01.sgetc();
int_type c7 = strb_02.sgetc(); int_type c7 = strb_02.sgetc();
test &= c6 != c3; VERIFY( c6 != c3 );
test &= c7 != c4; VERIFY( c7 != c4 );
int_type c8 = strb_01.sgetc(); int_type c8 = strb_01.sgetc();
int_type c9 = strb_02.sgetc(); int_type c9 = strb_02.sgetc();
test &= c6 == c8; VERIFY( c6 == c8 );
test &= c7 == c9; VERIFY( c7 == c9 );
c5 = strb_03.sgetc(); c5 = strb_03.sgetc();
test &= c5 == traits_type::eof(); VERIFY( c5 == traits_type::eof() );
// int_type snextc() // int_type snextc()
// calls sbumpc and if sbumpc != eof, return sgetc // calls sbumpc and if sbumpc != eof, return sgetc
c6 = strb_01.snextc(); c6 = strb_01.snextc();
c7 = strb_02.snextc(); c7 = strb_02.snextc();
test &= c6 != c8; VERIFY( c6 != c8 );
test &= c7 != c9; VERIFY( c7 != c9 );
test &= c6 == str_01[3]; VERIFY( c6 == str_01[3] );
test &= c7 == str_02[3]; //should equal fourth letter at this point VERIFY( c7 == str_02[3] ); //should equal fourth letter at this point
c5 = strb_03.snextc(); c5 = strb_03.snextc();
test &= c5 == traits_type::eof(); VERIFY( c5 == traits_type::eof() );
// int showmanyc // int showmanyc
// streamsize sgetn(char_type *s, streamsize n) // streamsize sgetn(char_type *s, streamsize n)
@ -151,27 +149,27 @@ bool test04() {
strmsz_1 = strb_01.in_avail(); strmsz_1 = strb_01.in_avail();
strmsz_2 = strb_02.in_avail(); strmsz_2 = strb_02.in_avail();
test = strmsz_1 != strmsz_2; test = strmsz_1 != strmsz_2;
test &= strmsz_1 != str_01.length(); VERIFY( strmsz_1 != str_01.length() );
test &= strmsz_2 != str_02.length(); //because now we've moved into string VERIFY( strmsz_2 != str_02.length() ); //because now we've moved into string
char carray1[11] = ""; char carray1[11] = "";
strmsz_1 = strb_01.sgetn(carray1, 10); strmsz_1 = strb_01.sgetn(carray1, 10);
char carray2[20] = ""; char carray2[20] = "";
strmsz_2 = strb_02.sgetn(carray2, 10); strmsz_2 = strb_02.sgetn(carray2, 10);
test &= strmsz_1 == strmsz_2; VERIFY( strmsz_1 == strmsz_2 );
test &= strmsz_1 == 10; VERIFY( strmsz_1 == 10 );
c1 = strb_01.sgetc(); c1 = strb_01.sgetc();
c2 = strb_02.sgetc(); c2 = strb_02.sgetc();
test &= c6 == c1; //just by co-incidence both o's VERIFY( c6 == c1 ); //just by co-incidence both o's
test &= c7 != c2; // n != i VERIFY( c7 != c2 ); // n != i
test &= c1 == str_01[13]; VERIFY( c1 == str_01[13] );
test &= c2 == str_02[13]; //should equal fourteenth letter at this point VERIFY( c2 == str_02[13] ); //should equal fourteenth letter at this point
strmsz_1 = strb_03.sgetn(carray1, 10); strmsz_1 = strb_03.sgetn(carray1, 10);
test &= !strmsz_1; //zero VERIFY( !strmsz_1 ); //zero
strmsz_1 = strb_02.in_avail(); strmsz_1 = strb_02.in_avail();
strmsz_2 = strb_02.sgetn(carray2, strmsz_1 + 5); strmsz_2 = strb_02.sgetn(carray2, strmsz_1 + 5);
test &= strmsz_1 == strmsz_2; //write off the end VERIFY( strmsz_1 == strmsz_2 ); //write off the end
c4 = strb_02.sgetc(); // should be EOF c4 = strb_02.sgetc(); // should be EOF
test &= c4 == traits_type::eof(); VERIFY( c4 == traits_type::eof() );
// PUT // PUT
// int_type sputc(char_type c) // int_type sputc(char_type c)
@ -181,12 +179,12 @@ bool test04() {
std::string::size_type sz1 = strb_03.str().length(); std::string::size_type sz1 = strb_03.str().length();
c1 = strb_03.sputc('a'); c1 = strb_03.sputc('a');
std::string::size_type sz2 = strb_03.str().length(); std::string::size_type sz2 = strb_03.str().length();
test &= sz1 == sz2; //cuz inserting at out_cur, which is at beg to start VERIFY( sz1 == sz2 ); //cuz inserting at out_cur, which is at beg to start
c2 = strb_03.sputc('b'); c2 = strb_03.sputc('b');
test &= c1 != c2; VERIFY( c1 != c2 );
test &= strb_03.str() != str_01; VERIFY( strb_03.str() != str_01 );
c3 = strb_02.sputc('a'); // should be EOF because this is read-only c3 = strb_02.sputc('a'); // should be EOF because this is read-only
test &= c3 == traits_type::eof(); VERIFY( c3 == traits_type::eof() );
// streamsize sputn(const char_typs* s, streamsize n) // streamsize sputn(const char_typs* s, streamsize n)
// write up to n chars to out_cur from s, returning number assigned // write up to n chars to out_cur from s, returning number assigned
@ -195,20 +193,20 @@ bool test04() {
sz1 = str_tmp.length(); sz1 = str_tmp.length();
strmsz_1 = strb_03.sputn("racadabras", 10);//"abracadabras or what?" strmsz_1 = strb_03.sputn("racadabras", 10);//"abracadabras or what?"
sz2 = strb_03.str().length(); sz2 = strb_03.str().length();
test &= sz1 == sz2; //shouldn't have changed length VERIFY( sz1 == sz2 ); //shouldn't have changed length
test &= strmsz_1 == 10; VERIFY( strmsz_1 == 10 );
test &= str_tmp != strb_03.str(); VERIFY( str_tmp != strb_03.str() );
strmsz_2 = strb_03.sputn(", i wanna reach out and", 10); strmsz_2 = strb_03.sputn(", i wanna reach out and", 10);
test &= strmsz_1 == strmsz_2; // should re-allocate, copy 10 chars. VERIFY( strmsz_1 == strmsz_2 ); // should re-allocate, copy 10 chars.
test &= strmsz_1 == 10; VERIFY( strmsz_1 == 10 );
test &= strmsz_2 == 10; VERIFY( strmsz_2 == 10 );
sz2 = strb_03.str().length(); sz2 = strb_03.str().length();
test &= sz1 != sz2; // need to change length VERIFY( sz1 != sz2 ); // need to change length
test &= str_tmp != strb_03.str(); VERIFY( str_tmp != strb_03.str() );
str_tmp = strb_02.str(); str_tmp = strb_02.str();
strmsz_1 = strb_02.sputn("racadabra", 10); strmsz_1 = strb_02.sputn("racadabra", 10);
test &= strmsz_1 == 0; VERIFY( strmsz_1 == 0 );
test &= str_tmp == strb_02.str(); VERIFY( str_tmp == strb_02.str() );
// PUTBACK // PUTBACK
// int_type pbfail(int_type c) // int_type pbfail(int_type c)
@ -230,22 +228,22 @@ bool test04() {
c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?" c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?"
c3 = strb_01.sgetc(); c3 = strb_01.sgetc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c3 == c2; VERIFY( c3 == c2 );
test &= strb_01.str() == std::string("mykonos. . .zor what?"); VERIFY( strb_01.str() == std::string("mykonos. . .zor what?") );
test &= str_tmp.size() == strb_01.str().size(); VERIFY( str_tmp.size() == strb_01.str().size() );
//test for _in_cur == _in_beg //test for _in_cur == _in_beg
strb_01.str(str_tmp); strb_01.str(str_tmp);
strmsz_1 = strb_01.in_avail(); strmsz_1 = strb_01.in_avail();
c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
c2 = strb_01.sputbackc('z');//"mykonos. . . or what?" c2 = strb_01.sputbackc('z');//"mykonos. . . or what?"
c3 = strb_01.sgetc(); c3 = strb_01.sgetc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c3 != c2; VERIFY( c3 != c2 );
test &= c1 == c3; VERIFY( c1 == c3 );
test &= c2 == traits_type::eof(); VERIFY( c2 == traits_type::eof() );
test &= strb_01.str() == str_tmp; VERIFY( strb_01.str() == str_tmp );
test &= str_tmp.size() == strb_01.str().size(); VERIFY( str_tmp.size() == strb_01.str().size() );
// test for replacing char with identical one // test for replacing char with identical one
strb_01.str(str_01); //reset strb_01.str(str_01); //reset
strmsz_1 = strb_01.in_avail(); strmsz_1 = strb_01.in_avail();
@ -254,15 +252,15 @@ bool test04() {
c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
c2 = strb_01.sputbackc('y');//"mykonos. . . or what?" c2 = strb_01.sputbackc('y');//"mykonos. . . or what?"
c3 = strb_01.sgetc(); c3 = strb_01.sgetc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c3 == c2; VERIFY( c3 == c2 );
test &= c1 != c3; VERIFY( c1 != c3 );
test &= strb_01.str() == str_01; VERIFY( strb_01.str() == str_01 );
test &= str_01.size() == strb_01.str().size(); VERIFY( str_01.size() == strb_01.str().size() );
//test for ios_base::out //test for ios_base::out
strmsz_2 = strb_03.in_avail(); strmsz_2 = strb_03.in_avail();
c4 = strb_03.sputbackc('x'); c4 = strb_03.sputbackc('x');
test &= c4 == traits_type::eof(); VERIFY( c4 == traits_type::eof() );
// int_type sungetc() // int_type sungetc()
// if in_cur not avail, return pbackfail(), else decrement and // if in_cur not avail, return pbackfail(), else decrement and
@ -274,24 +272,24 @@ bool test04() {
c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
c2 = strb_01.sungetc();//"mykonos. . . or what?" c2 = strb_01.sungetc();//"mykonos. . . or what?"
c3 = strb_01.sgetc(); c3 = strb_01.sgetc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c3 == c2; VERIFY( c3 == c2 );
test &= c1 != c3; VERIFY( c1 != c3 );
test &= c2 == ' '; VERIFY( c2 == ' ' );
test &= strb_01.str() == str_01; VERIFY( strb_01.str() == str_01 );
test &= str_01.size() == strb_01.str().size(); VERIFY( str_01.size() == strb_01.str().size() );
//test for _in_cur == _in_beg //test for _in_cur == _in_beg
strb_01.str(str_tmp); strb_01.str(str_tmp);
strmsz_1 = strb_01.in_avail(); strmsz_1 = strb_01.in_avail();
c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
c2 = strb_01.sungetc();//"mykonos. . . or what?" c2 = strb_01.sungetc();//"mykonos. . . or what?"
c3 = strb_01.sgetc(); c3 = strb_01.sgetc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c3 != c2; VERIFY( c3 != c2 );
test &= c1 == c3; VERIFY( c1 == c3 );
test &= c2 == traits_type::eof(); VERIFY( c2 == traits_type::eof() );
test &= strb_01.str() == str_01; VERIFY( strb_01.str() == str_01 );
test &= str_01.size() == strb_01.str().size(); VERIFY( str_01.size() == strb_01.str().size() );
// test for replacing char with identical one // test for replacing char with identical one
strb_01.str(str_01); //reset strb_01.str(str_01); //reset
strmsz_1 = strb_01.in_avail(); strmsz_1 = strb_01.in_avail();
@ -300,15 +298,15 @@ bool test04() {
c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
c2 = strb_01.sungetc();//"mykonos. . . or what?" c2 = strb_01.sungetc();//"mykonos. . . or what?"
c3 = strb_01.sgetc(); c3 = strb_01.sgetc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= c3 == c2; VERIFY( c3 == c2 );
test &= c1 != c3; VERIFY( c1 != c3 );
test &= strb_01.str() == str_01; VERIFY( strb_01.str() == str_01 );
test &= str_01.size() == strb_01.str().size(); VERIFY( str_01.size() == strb_01.str().size() );
//test for ios_base::out //test for ios_base::out
strmsz_2 = strb_03.in_avail(); strmsz_2 = strb_03.in_avail();
c4 = strb_03.sungetc(); c4 = strb_03.sungetc();
test &= c4 == traits_type::eof(); VERIFY( c4 == traits_type::eof() );
// BUFFER MANAGEMENT & POSITIONING // BUFFER MANAGEMENT & POSITIONING
// sync // sync
@ -321,9 +319,9 @@ bool test04() {
// pubsetbuf(char_type* s, streamsize n) // pubsetbuf(char_type* s, streamsize n)
str_tmp = std::string("naaaah, go to cebu"); str_tmp = std::string("naaaah, go to cebu");
strb_01.pubsetbuf(const_cast<char*> (str_tmp.c_str()), str_tmp.size()); strb_01.pubsetbuf(const_cast<char*> (str_tmp.c_str()), str_tmp.size());
test &= strb_01.str() == str_tmp; VERIFY( strb_01.str() == str_tmp );
strb_01.pubsetbuf(0,0); strb_01.pubsetbuf(0,0);
test &= strb_01.str() == str_tmp; VERIFY( strb_01.str() == str_tmp );
// seekoff // seekoff
// pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
@ -339,31 +337,31 @@ bool test04() {
//beg //beg
pt_1 = strb_01.pubseekoff(2, std::ios_base::beg); pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
off_1 = pt_1; off_1 = pt_1;
test &= off_1 >= 0; VERIFY( off_1 >= 0 );
c1 = strb_01.snextc(); //current in pointer +1 c1 = strb_01.snextc(); //current in pointer +1
test &= c1 == 'o'; VERIFY( c1 == 'o' );
c2 = strb_01.sputc('x'); //test current out pointer c2 = strb_01.sputc('x'); //test current out pointer
str_tmp = std::string("myxonos. . . or what?"); str_tmp = std::string("myxonos. . . or what?");
test &= strb_01.str() == str_tmp; VERIFY( strb_01.str() == str_tmp );
//cur //cur
pt_1 = strb_01.pubseekoff(2, std::ios_base::cur); pt_1 = strb_01.pubseekoff(2, std::ios_base::cur);
off_1 = pt_1; off_1 = pt_1;
test &= off_1 == -1; // can't seekoff for in and out + cur in sstreams VERIFY( off_1 == -1 ); // can't seekoff for in and out + cur in sstreams
pt_1 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); pt_1 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in);
off_1 = pt_1; off_1 = pt_1;
pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in);
off_2 = pt_2; off_2 = pt_2;
test &= off_2 == off_1 + 2; VERIFY( off_2 == off_1 + 2 );
c1 = strb_01.snextc(); //current in pointer + 1 c1 = strb_01.snextc(); //current in pointer + 1
test &= c1 == ' '; VERIFY( c1 == ' ' );
c2 = strb_01.sputc('x'); //test current out pointer c2 = strb_01.sputc('x'); //test current out pointer
str_tmp = std::string("myxxnos. . . or what?"); str_tmp = std::string("myxxnos. . . or what?");
test &= strb_01.str() == str_tmp; VERIFY( strb_01.str() == str_tmp );
//end //end
pt_2 = strb_01.pubseekoff(2, std::ios_base::end); pt_2 = strb_01.pubseekoff(2, std::ios_base::end);
off_1 = pt_2; off_1 = pt_2;
test &= off_1 == -1; // not a valid position VERIFY( off_1 == -1 ); // not a valid position
test &= strb_01.str() == str_tmp; VERIFY( strb_01.str() == str_tmp );
// end part two (from the filebuf tests) // end part two (from the filebuf tests)
strb_01.pubseekoff(0, std::ios_base::end); strb_01.pubseekoff(0, std::ios_base::end);
strmsz_1 = strb_01.in_avail(); // 0 cuz at the end strmsz_1 = strb_01.in_avail(); // 0 cuz at the end
@ -371,16 +369,16 @@ bool test04() {
c2 = strb_01.sungetc(); c2 = strb_01.sungetc();
strmsz_2 = strb_01.in_avail(); // 1 strmsz_2 = strb_01.in_avail(); // 1
c3 = strb_01.sgetc(); c3 = strb_01.sgetc();
test &= c1 != c2; VERIFY( c1 != c2 );
test &= strmsz_2 != strmsz_1; VERIFY( strmsz_2 != strmsz_1 );
test &= strmsz_2 == 1; VERIFY( strmsz_2 == 1 );
// end part three // end part three
strmsz_1 = strb_01.str().size(); strmsz_1 = strb_01.str().size();
strmsz_2 = strb_01.sputn(" ravi shankar meets carlos santana in LoHa", 90); strmsz_2 = strb_01.sputn(" ravi shankar meets carlos santana in LoHa", 90);
strb_01.pubseekoff(0, std::ios_base::end); strb_01.pubseekoff(0, std::ios_base::end);
strb_01.sputc('<'); strb_01.sputc('<');
str_tmp = strb_01.str(); str_tmp = strb_01.str();
test &= str_tmp.size() == strmsz_1 + strmsz_2 + 1; VERIFY( str_tmp.size() == strmsz_1 + strmsz_2 + 1 );
// IN // IN
// OUT // OUT
@ -394,23 +392,23 @@ bool test04() {
//beg //beg
pt_1 = strb_01.pubseekoff(2, std::ios_base::beg); pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
off_1 = pt_1; off_1 = pt_1;
test &= off_1 >= 0; VERIFY( off_1 >= 0 );
pt_1 = strb_01.pubseekoff(0, std::ios_base::cur, std::ios_base::out); pt_1 = strb_01.pubseekoff(0, std::ios_base::cur, std::ios_base::out);
off_1 = pt_1; off_1 = pt_1;
c1 = strb_01.snextc(); //current in pointer +1 c1 = strb_01.snextc(); //current in pointer +1
test &= c1 == 'o'; VERIFY( c1 == 'o' );
c2 = strb_01.sputc('x'); //test current out pointer c2 = strb_01.sputc('x'); //test current out pointer
str_tmp = std::string("myxonos. . . or what?"); str_tmp = std::string("myxonos. . . or what?");
test &= strb_01.str() == str_tmp; VERIFY( strb_01.str() == str_tmp );
strb_01.pubsync(); //resets pointers strb_01.pubsync(); //resets pointers
pt_2 = strb_01.pubseekpos(pt_1, std::ios_base::in|std::ios_base::out); pt_2 = strb_01.pubseekpos(pt_1, std::ios_base::in|std::ios_base::out);
off_2 = pt_2; off_2 = pt_2;
test &= off_1 == off_2; VERIFY( off_1 == off_2 );
c3 = strb_01.snextc(); //current in pointer +1 c3 = strb_01.snextc(); //current in pointer +1
test &= c1 == c3; VERIFY( c1 == c3 );
c2 = strb_01.sputc('x'); //test current out pointer c2 = strb_01.sputc('x'); //test current out pointer
str_tmp = std::string("myxonos. . . or what?"); str_tmp = std::string("myxonos. . . or what?");
test &= strb_01.str() == str_tmp; VERIFY( strb_01.str() == str_tmp );
// VIRTUALS (indirectly tested) // VIRTUALS (indirectly tested)
// underflow // underflow

View File

@ -32,12 +32,11 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <sstream> #include <sstream>
#ifdef DEBUG_ASSERT #include <debug_assert.h>
#include <assert.h>
#endif
// 01: sanity checks for strings, stringbufs // 01: sanity checks for strings, stringbufs
std::string test01() std::string
test01()
{ {
bool test = false; bool test = false;
@ -47,7 +46,7 @@ std::string test01()
std::string::iterator __i_end = str01.end(); std::string::iterator __i_end = str01.end();
std::string::size_type len = str01.size(); std::string::size_type len = str01.size();
test = __i_start == __i_end; test = __i_start == __i_end;
test &= len == 0; VERIFY( len == 0 );
// Full string sanity check. // Full string sanity check.
std::string str02("these golden days, i spend waiting for you:\n std::string str02("these golden days, i spend waiting for you:\n
@ -55,8 +54,8 @@ std::string test01()
__i_start = str02.begin(); __i_start = str02.begin();
__i_end = str02.end(); __i_end = str02.end();
len = str02.size(); len = str02.size();
test &= __i_start != __i_end; VERIFY( __i_start != __i_end );
test &= len != 0; VERIFY( len != 0 );
// Test an empty ostring stream for sanity. // Test an empty ostring stream for sanity.
std::ostringstream ostrstream0; std::ostringstream ostrstream0;
@ -64,16 +63,17 @@ std::string test01()
__i_start = str03.begin(); __i_start = str03.begin();
__i_end = str03.end(); __i_end = str03.end();
len = str03.size(); len = str03.size();
test &= __i_start == __i_end; VERIFY( __i_start == __i_end );
test &= len == 0; VERIFY( len == 0 );
test &= str01 == str03; VERIFY( str01 == str03 );
return str02; return str02;
} }
bool test02(void) { int
test02()
{
bool test = true; bool test = true;
// //
@ -96,8 +96,8 @@ bool test02(void) {
std::string msg01 = ostrst01.str(); std::string msg01 = ostrst01.str();
std::string msg02 = ostrst02.str(); std::string msg02 = ostrst02.str();
test &= msg01 != msg02; VERIFY( msg01 != msg02 );
test &= msg02 != blank; VERIFY( msg02 != blank );
// //
// 2: istringstream // 2: istringstream
@ -113,10 +113,10 @@ bool test02(void) {
istrst01 >> i2 >> pi2 >> d2 >> pd2; istrst01 >> i2 >> pi2 >> d2 >> pd2;
//istrst01 >> i2; //istrst01 >> i2;
//istrst01 >> pi2; //istrst01 >> pi2;
test &= i2 == i; VERIFY( i2 == i );
test &= d2 == d; VERIFY( d2 == d );
test &= pd2 == pd; VERIFY( pd2 == pd );
test &= pi2 == pi; VERIFY( pi2 == pi );
#endif #endif
// stringstream // stringstream
@ -125,7 +125,7 @@ bool test02(void) {
std::stringstream ss1(str1, std::ios_base::in|std::ios_base::out); std::stringstream ss1(str1, std::ios_base::in|std::ios_base::out);
std::stringstream ss2(str3, std::ios_base::in|std::ios_base::out); std::stringstream ss2(str3, std::ios_base::in|std::ios_base::out);
return test; return 0;
} }
// user-reported error // user-reported error
@ -135,25 +135,29 @@ public:
derived_oss() : std::ostringstream() {} derived_oss() : std::ostringstream() {}
}; };
bool test03() int
test03()
{ {
bool test = true; bool test = true;
derived_oss yy; derived_oss yy;
yy << "buena vista social club\n"; yy << "buena vista social club\n";
test &= yy.str() == std::string("buena vista social club\n"); VERIFY( yy.str() == std::string("buena vista social club\n") );
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test; return 0;
} }
int main() int
main()
{ {
test01(); test01();
test02(); test02();
test03(); test03();
return 0;
} }

View File

@ -71,13 +71,15 @@
#include <cwchar> #include <cwchar>
#include <cwctype> #include <cwctype>
#endif #endif
#include <debug_assert.h>
// Include iostream last, just to make is as difficult as possible to // Include iostream last, just to make is as difficult as possible to
// properly initialize the standard iostream objects. // properly initialize the standard iostream objects.
#include <iostream> #include <iostream>
// Make sure all the standard streams are defined. // Make sure all the standard streams are defined.
bool test01() int
test01()
{ {
bool test = true; bool test = true;
@ -88,18 +90,20 @@ bool test01()
wtraits_type::copy(array2, L"testing istream", wi); wtraits_type::copy(array2, L"testing istream", wi);
std::wcout << L"testing wcout" << std::endl; std::wcout << L"testing wcout" << std::endl;
std::wcerr << L"testing wcerr" << std::endl; std::wcerr << L"testing wcerr" << std::endl;
test &= std::wcerr.flags() & std::ios_base::unitbuf; VERIFY( std::wcerr.flags() & std::ios_base::unitbuf );
std::wclog << L"testing wclog" << std::endl; std::wclog << L"testing wclog" << std::endl;
// std::wcin >> array2; // requires somebody to type something in. // std::wcin >> array2; // requires somebody to type something in.
test &= std::wcin.tie() == &std::wcout; VERIFY( std::wcin.tie() == &std::wcout );
#endif #endif
return test; return 0;
} }
int main(void) int
{ main()
test01(); {
test01();
return 0; return 0;
} }