Commit aa1b2f7d by Brent Verner Committed by Benjamin Kosnik

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
parent 5312a1d9
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>
* bits/std_fstream.h: Remove duplicate typdefs for ofstream and
......
......@@ -55,7 +55,7 @@ fi
# INC_PATH == include path to new headers for use on gcc command-line
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
INC_PATH=""
fi
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, ciso646
#include <ciso646>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
// 2.11 Keywords
......@@ -104,11 +102,11 @@ bool test02()
int int1 = 45;
int int2 = 0;
test &= arg1 && int1;
test &= arg1 and int1;
VERIFY( arg1 && int1 );
VERIFY( arg1 and int1 );
test &= (arg1 && arg2) == (arg1 and arg2);
test &= (arg1 && int1) == (arg1 and int1);
VERIFY( (arg1 && arg2) == (arg1 and arg2) );
VERIFY( (arg1 && int1) == (arg1 and int1) );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, fstream
#include <fstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int main(void)
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, iomanip
#include <iomanip>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int main(void)
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, ios
#include <ios>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int main(void)
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, iosfwd
#include <iosfwd>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int main(void)
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, iostream
#include <iostream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int main(void)
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, istream
#include <istream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int main(void)
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, ostream
#include <ostream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int main(void)
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, sstream
#include <sstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int main(void)
......
......@@ -21,9 +21,7 @@
// 17.4.1.2 Headers, streambuf
#include <streambuf>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int main(void)
......
......@@ -21,9 +21,7 @@
// 18.2.1.1 template class numeric_limits
#include <limits>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
template<typename T>
......@@ -44,36 +42,36 @@ bool test01()
bool test = true;
std::numeric_limits< A<B> > obj;
test &= !obj.is_specialized;
test &= obj.min() == 0;
test &= obj.max() == 0;
test &= obj.digits == 0;
test &= obj.digits10 == 0;
test &= !obj.is_signed;
test &= !obj.is_integer;
test &= !obj.is_exact;
test &= obj.radix == 0;
test &= obj.epsilon() == 0;
test &= obj.round_error() == 0;
test &= obj.min_exponent == 0;
test &= obj.min_exponent10 == 0;
test &= obj.max_exponent == 0;
test &= obj.max_exponent10 == 0;
test &= !obj.has_infinity;
test &= !obj.has_quiet_NaN;
test &= !obj.has_signaling_NaN;
test &= !obj.has_denorm;
test &= !obj.has_denorm_loss;
test &= obj.infinity() == 0;
test &= obj.quiet_NaN() == 0;
test &= obj.signaling_NaN() == 0;
test &= obj.denorm_min() == 0;
test &= !obj.is_iec559;
test &= !obj.is_bounded;
test &= !obj.is_modulo;
test &= !obj.traps;
test &= !obj.tinyness_before;
test &= obj.round_style == std::round_toward_zero;
VERIFY( !obj.is_specialized );
VERIFY( obj.min() == 0 );
VERIFY( obj.max() == 0 );
VERIFY( obj.digits == 0 );
VERIFY( obj.digits10 == 0 );
VERIFY( !obj.is_signed );
VERIFY( !obj.is_integer );
VERIFY( !obj.is_exact );
VERIFY( obj.radix == 0 );
VERIFY( obj.epsilon() == 0 );
VERIFY( obj.round_error() == 0 );
VERIFY( obj.min_exponent == 0 );
VERIFY( obj.min_exponent10 == 0 );
VERIFY( obj.max_exponent == 0 );
VERIFY( obj.max_exponent10 == 0 );
VERIFY( !obj.has_infinity );
VERIFY( !obj.has_quiet_NaN );
VERIFY( !obj.has_signaling_NaN );
VERIFY( !obj.has_denorm );
VERIFY( !obj.has_denorm_loss );
VERIFY( obj.infinity() == 0 );
VERIFY( obj.quiet_NaN() == 0 );
VERIFY( obj.signaling_NaN() == 0 );
VERIFY( obj.denorm_min() == 0 );
VERIFY( !obj.is_iec559 );
VERIFY( !obj.is_bounded );
VERIFY( !obj.is_modulo );
VERIFY( !obj.traps );
VERIFY( !obj.tinyness_before );
VERIFY( obj.round_style == std::round_toward_zero );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -19,10 +19,7 @@
// 20.4.5 Template class auto_ptr [lib.auto.ptr]
#include <memory>
#ifdef DEBUG_ASSERT
# include <assert.h>
#endif
#include <debug_assert.h>
struct A
{
......@@ -60,41 +57,43 @@ struct reset_count_struct
// 20.4.5.1 auto_ptr constructors [lib.auto.ptr.cons]
// Construction from pointer
bool test01()
int
test01()
{
reset_count_struct reset;
bool test = true;
std::auto_ptr<A> A_default;
test &= A_default.get() == 0;
test &= A::ctor_count == 0;
test &= A::dtor_count == 0;
test &= B::ctor_count == 0;
test &= B::dtor_count == 0;
VERIFY( A_default.get() == 0 );
VERIFY( A::ctor_count == 0 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 0 );
VERIFY( B::dtor_count == 0 );
std::auto_ptr<A> A_from_A(new A);
test &= A_from_A.get() != 0;
test &= A::ctor_count == 1;
test &= A::dtor_count == 0;
test &= B::ctor_count == 0;
test &= B::dtor_count == 0;
VERIFY( A_from_A.get() != 0 );
VERIFY( A::ctor_count == 1 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 0 );
VERIFY( B::dtor_count == 0 );
std::auto_ptr<A> A_from_B(new B);
test &= A_from_B.get() != 0;
test &= A::ctor_count == 2;
test &= A::dtor_count == 0;
test &= B::ctor_count == 1;
test &= B::dtor_count == 0;
VERIFY( A_from_B.get() != 0 );
VERIFY( A::ctor_count == 2 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 1 );
VERIFY( B::dtor_count == 0 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
return 0;
}
// Construction from std::auto_ptr
bool test02()
int
test02()
{
reset_count_struct reset;
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_B(B_from_B);
test &= A_from_A.get() == 0;
test &= B_from_B.get() == 0;
test &= A_from_ptr_A.get() != 0;
test &= A_from_ptr_B.get() != 0;
test &= A::ctor_count == 2;
test &= A::dtor_count == 0;
test &= B::ctor_count == 1;
test &= B::dtor_count == 0;
VERIFY( A_from_A.get() == 0 );
VERIFY( B_from_B.get() == 0 );
VERIFY( A_from_ptr_A.get() != 0 );
VERIFY( A_from_ptr_B.get() != 0 );
VERIFY( A::ctor_count == 2 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 1 );
VERIFY( B::dtor_count == 0 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
return 0;
}
// Assignment from std::auto_ptr
bool test03()
int
test03()
{
reset_count_struct reset;
bool test = true;
......@@ -133,24 +133,25 @@ bool test03()
A_from_ptr_A = A_from_A;
A_from_ptr_B = B_from_B;
test &= A_from_A.get() == 0;
test &= B_from_B.get() == 0;
test &= A_from_ptr_A.get() != 0;
test &= A_from_ptr_B.get() != 0;
test &= A::ctor_count == 2;
test &= A::dtor_count == 0;
test &= B::ctor_count == 1;
test &= B::dtor_count == 0;
VERIFY( A_from_A.get() == 0 );
VERIFY( B_from_B.get() == 0 );
VERIFY( A_from_ptr_A.get() != 0 );
VERIFY( A_from_ptr_B.get() != 0 );
VERIFY( A::ctor_count == 2 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 1 );
VERIFY( B::dtor_count == 0 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
return 0;
}
// Destruction
bool test04()
int
test04()
{
reset_count_struct reset;
bool test = true;
......@@ -161,16 +162,16 @@ bool test04()
std::auto_ptr<B> B_from_B(new B);
}/*destructors called here*/
test &= A::ctor_count == 3;
test &= A::dtor_count == 3;
test &= B::ctor_count == 2;
test &= B::dtor_count == 2;
VERIFY( A::ctor_count == 3 );
VERIFY( A::dtor_count == 3 );
VERIFY( B::ctor_count == 2 );
VERIFY( B::dtor_count == 2 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
return 0;
}
// Class member construction/destruction
......@@ -183,58 +184,60 @@ private:
std::auto_ptr<T> p_impl;
};
bool test05()
int
test05()
{
bool test = true;
reset_count_struct reset;
pimpl<A>();
pimpl<B>();
test &= A::ctor_count == 2;
test &= A::dtor_count == 2;
test &= B::ctor_count == 1;
test &= B::dtor_count == 1;
VERIFY( A::ctor_count == 2 );
VERIFY( A::dtor_count == 2 );
VERIFY( B::ctor_count == 1 );
VERIFY( B::dtor_count == 1 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
return 0;
}
// 20.4.5.2 auto_ptr members [lib.auto.ptr.members]
// Member access
bool test06()
int
test06()
{
reset_count_struct reset;
bool test = true;
std::auto_ptr<A> A_from_A(new A);
std::auto_ptr<A> A_from_A_ptr(A_from_A.release());
test &= A_from_A.get() == 0;
test &= A_from_A_ptr.get() != 0;
test &= A_from_A->ctor_count == 1;
test &= (*A_from_A).dtor_count == 0;
VERIFY( A_from_A.get() == 0 );
VERIFY( A_from_A_ptr.get() != 0 );
VERIFY( A_from_A->ctor_count == 1 );
VERIFY( (*A_from_A).dtor_count == 0 );
A* A_ptr = A_from_A_ptr.get();
A_from_A_ptr.reset(A_ptr);
test &= A_from_A_ptr.get() == A_ptr;
test &= A_from_A_ptr->ctor_count == 1;
test &= (*A_from_A_ptr).dtor_count == 0;
VERIFY( A_from_A_ptr.get() == A_ptr );
VERIFY( A_from_A_ptr->ctor_count == 1 );
VERIFY( (*A_from_A_ptr).dtor_count == 0 );
A_from_A_ptr.reset(new A);
test &= A_from_A_ptr.get() != A_ptr;
test &= A_from_A_ptr->ctor_count == 2;
test &= (*A_from_A_ptr).dtor_count == 1;
VERIFY( A_from_A_ptr.get() != A_ptr );
VERIFY( A_from_A_ptr->ctor_count == 2 );
VERIFY( (*A_from_A_ptr).dtor_count == 1 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
return 0;
}
......@@ -251,7 +254,8 @@ template <typename T>
static void drain(std::auto_ptr<T>)
{}
bool test07()
int
test07()
{
bool test = true;
reset_count_struct reset;
......@@ -259,30 +263,29 @@ bool test07()
drain(source<A>());
drain<A>(source<B>());
drain(source<B>());
test &= A::ctor_count == 3;
test &= A::dtor_count == 3;
test &= B::ctor_count == 2;
test &= B::dtor_count == 2;
VERIFY( A::ctor_count == 3 );
VERIFY( A::dtor_count == 3 );
VERIFY( B::ctor_count == 2 );
VERIFY( B::dtor_count == 2 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
return 0;
}
int main()
int
main()
{
bool test = true;
test &= test01();
test &= test02();
test &= test03();
test &= test04();
test &= test05();
test &= test06();
test &= test07();
return test ? 0 : 1;
test01();
test02();
test03();
test04();
test05();
test06();
test07();
return 0;
}
......@@ -22,9 +22,7 @@
#include <string>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01(void)
{
......@@ -45,14 +43,14 @@ bool test01(void)
// string& append(const string&)
str05 = str02;
str05.append(str05);
test &= str05 == "corpus, corpus, ";
VERIFY( str05 == "corpus, corpus, " );
str05.append(str01);
test &= str05 == "corpus, corpus, point bolivar, texas";
VERIFY( str05 == "corpus, corpus, point bolivar, texas" );
str05.append(str03);
test &= str05 == "corpus, corpus, point bolivar, texas";
VERIFY( str05 == "corpus, corpus, point bolivar, texas" );
std::string str06;
str06.append(str05);
test &= str06 == str05;
VERIFY( str06 == str05 );
// string& append(const string&, size_type pos, size_type n)
......@@ -61,78 +59,78 @@ bool test01(void)
csz01 = str03.size();
try {
str06.append(str03, csz01 + 1, 0);
test &= false;
VERIFY( false );
}
catch(std::out_of_range& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
csz01 = str01.size();
try {
str06.append(str01, csz01 + 1, 0);
test &= false;
VERIFY( false );
}
catch(std::out_of_range& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
str05 = str02;
str05.append(str01, 0, std::string::npos);
test &= str05 == "corpus, point bolivar, texas";
test &= str05 != str02;
VERIFY( str05 == "corpus, point bolivar, texas" );
VERIFY( str05 != str02 );
str06 = str02;
str06.append(str01, 15, std::string::npos);
test &= str06 == "corpus, texas";
test &= str02 != str06;
VERIFY( str06 == "corpus, texas" );
VERIFY( str02 != str06 );
// string& append(const char* s)
str05.erase();
str06.erase();
str05.append("");
test &= str05 == str03;
VERIFY( str05 == str03 );
str05.append(str_lit01);
test &= str05 == str01;
VERIFY( str05 == str01 );
str06 = str02;
str06.append("corpus, ");
test &= str06 == "corpus, corpus, ";
VERIFY( str06 == "corpus, corpus, " );
// string& append(const char* s, size_type n)
str05.erase();
str06.erase();
str05.append("", 0);
test &= str05.size() == 0;
test &= str05 == str03;
VERIFY( str05.size() == 0 );
VERIFY( str05 == str03 );
str05.append(str_lit01, sizeof(str_lit01) - 1);
test &= str05 == str01;
VERIFY( str05 == str01 );
str06 = str02;
str06.append("corpus, ", 6);
test &= str06 == "corpus, corpus";
VERIFY( str06 == "corpus, corpus" );
str06 = str02;
str06.append("corpus, ", 12);
test &= str06 != "corpus, corpus, ";
VERIFY( str06 != "corpus, corpus, " );
// string& append(size_type n, char c)
str05.erase();
str06.erase();
str05.append(0, 'a');
test &= str05 == str03;
VERIFY( str05 == str03 );
str06.append(8, '.');
test &= str06 == "........";
VERIFY( str06 == "........" );
// template<typename InputIter>
......@@ -140,18 +138,18 @@ bool test01(void)
str05.erase();
str06.erase();
str05.append(str03.begin(), str03.end());
test &= str05 == str03;
VERIFY( str05 == str03 );
str06 = str02;
str06.append(str01.begin(), str01.begin() + str01.find('r'));
test &= str06 == "corpus, point boliva";
test &= str06 != str01;
test &= str06 != str02;
VERIFY( str06 == "corpus, point boliva" );
VERIFY( str06 != str01 );
VERIFY( str06 != str02 );
str05 = str01;
str05.append(str05.begin(), str05.begin() + str05.find('r'));
test &= str05 == "point bolivar, texaspoint boliva";
test &= str05 != str01;
VERIFY( str05 == "point bolivar, texaspoint boliva" );
VERIFY( str05 != str01 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -22,9 +22,7 @@
#include <string>
#include <cstdio>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
template<typename T>
struct A { };
......@@ -49,27 +47,27 @@ bool test01()
size_type_s sz01 = str01.capacity();
str01.reserve(100);
size_type_s sz02 = str01.capacity();
test &= sz02 >= sz01;
test &= sz02 >= 100;
VERIFY( sz02 >= sz01 );
VERIFY( sz02 >= 100 );
str01.reserve();
sz01 = str01.capacity();
test &= sz01 >= 0;
VERIFY( sz01 >= 0 );
sz01 = str01.size() + 5;
str01.resize(sz01);
sz02 = str01.size();
test &= sz01 == sz02;
VERIFY( sz01 == sz02 );
sz01 = str01.size() - 5;
str01.resize(sz01);
sz02 = str01.size();
test &= sz01 == sz02;
VERIFY( sz01 == sz02 );
std::string str05(30, 'q');
std::string str06 = str05;
str05 = str06 + str05;
test &= str05.capacity() >= str05.size();
test &= str06.capacity() >= str06.size();
VERIFY( str05.capacity() >= str05.size() );
VERIFY( str06.capacity() >= str06.size() );
// 2 non POD types : resize, capacity, reserve
std::basic_string< A<B> > str02;
......@@ -80,50 +78,50 @@ bool test01()
sz03 = str02.capacity();
str02.reserve(100);
sz04 = str02.capacity();
test &= sz04 >= sz03;
test &= sz04 >= 100;
VERIFY( sz04 >= sz03 );
VERIFY( sz04 >= 100 );
str02.reserve();
sz03 = str02.capacity();
test &= sz03 >= 0;
VERIFY( sz03 >= 0 );
sz03 = str02.size() + 5;
str02.resize(sz03);
sz04 = str02.size();
test &= sz03 == sz04;
VERIFY( sz03 == sz04 );
sz03 = str02.size() - 5;
str02.resize(sz03);
sz04 = str02.size();
test &= sz03 == sz04;
VERIFY( sz03 == sz04 );
A<B> inst_obj;
std::basic_string<A<B> > str07(30, inst_obj);
std::basic_string<A<B> > str08 = str07;
str07 = str08 + str07;
test &= str07.capacity() >= str07.size();
test &= str08.capacity() >= str08.size();
VERIFY( str07.capacity() >= str07.size() );
VERIFY( str08.capacity() >= str08.size() );
// 3 POD types: size, length, max_size, clear(), empty()
bool b01;
std::string str011;
b01 = str01.empty();
test &= b01 == true;
VERIFY( b01 == true );
sz01 = str01.size();
sz02 = str01.length();
test &= sz01 == sz02;
VERIFY( sz01 == sz02 );
str01.c_str();
sz01 = str01.size();
sz02 = str01.length();
test &= sz01 == sz02;
VERIFY( sz01 == sz02 );
sz01 = str01.length();
str01.c_str();
str011 = str01 + "_addendum_";
str01.c_str();
sz02 = str01.length();
test &= sz01 == sz02;
VERIFY( sz01 == sz02 );
sz02 = str011.length();
test &= sz02 > sz01;
VERIFY( sz02 > sz01 );
// trickster allocator (__USE_MALLOC, luke) issues involved with these:
std::string str3 = "8-chars_8-chars_";
......@@ -133,36 +131,36 @@ bool test01()
sz01 = str01.size();
sz02 = str01.max_size();
test &= sz02 >= sz01;
VERIFY( sz02 >= sz01 );
sz01 = str01.size();
str01.clear();
b01 = str01.empty();
test &= b01 == true;
VERIFY( b01 == true );
sz02 = str01.size();
test &= sz01 >= sz02;
VERIFY( sz01 >= sz02 );
// 4 non-POD types: size, length, max_size, clear(), empty()
b01 = str02.empty();
test &= b01 == true;
VERIFY( b01 == true );
sz03 = str02.size();
sz04 = str02.length();
test &= sz03 == sz04;
VERIFY( sz03 == sz04 );
str02.c_str();
sz03 = str02.size();
sz04 = str02.length();
test &= sz03 == sz04;
VERIFY( sz03 == sz04 );
sz03 = str02.max_size();
test &= sz03 >= sz04;
VERIFY( sz03 >= sz04 );
sz03 = str02.size();
str02.clear();
b01 = str02.empty();
test &= b01 == true;
VERIFY( b01 == true );
sz04 = str02.size();
test &= sz03 >= sz04;
VERIFY( sz03 >= sz04 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -21,9 +21,7 @@
// 21.1 Characher traits
#include <string>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int test01(void)
{
......@@ -47,9 +45,9 @@ int test01(void)
// assigns c = d;
char c1 = 'z';
char c2 = 'u';
test &= c1 != c2;
VERIFY( 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)
// 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
char array2[len];
test &= str_lit1[0] == 'm';
VERIFY( str_lit1[0] == 'm' );
c1 = array2[0];
c2 = str_lit1[0];
char c3 = array2[1];
char c4 = str_lit1[1];
std::char_traits<char>::move(array2, str_lit1, 0);
test &= array2[0] == c1;
test &= str_lit1[0] == c2;
VERIFY( array2[0] == c1 );
VERIFY( str_lit1[0] == c2 );
std::char_traits<char>::move(array2, str_lit1, 1);
test &= array2[0] == c2;
test &= str_lit1[0] == c2;
test &= array2[1] == c3;
test &= str_lit1[1] == c4;
VERIFY( array2[0] == c2 );
VERIFY( str_lit1[0] == c2 );
VERIFY( array2[1] == c3 );
VERIFY( str_lit1[1] == c4 );
std::char_traits<char>::move(array2, str_lit1, 2);
test &= array2[0] == c2;
test &= str_lit1[0] == c2;
test &= array2[1] == c4;
test &= str_lit1[1] == c4;
VERIFY( array2[0] == c2 );
VERIFY( str_lit1[0] == c2 );
VERIFY( array2[1] == c4 );
VERIFY( str_lit1[1] == c4 );
char* pc1 = array1 + 1;
c1 = pc1[0];
c2 = array1[0];
test &= c1 != c2;
VERIFY( c1 != c2 );
char* pc2 = std::char_traits<char>::move(array1, pc1, 0);
c3 = pc1[0];
c4 = array1[0];
test &= c1 == c3;
test &= c2 == c4;
test &= pc2 == array1;
VERIFY( c1 == c3 );
VERIFY( c2 == c4 );
VERIFY( pc2 == array1 );
c1 = pc1[0];
c2 = array1[0];
......@@ -95,13 +93,13 @@ int test01(void)
pc2 = std::char_traits<char>::move(array1, pc1, 10);
c3 = pc1[0];
c4 = array1[0];
test &= c1 != c3; // underlying char array changed.
test &= c4 != c3;
test &= pc2 == array1;
test &= pc3 == pc1; // but pointers o-tay
VERIFY( c1 != c3 ); // underlying char array changed.
VERIFY( c4 != c3 );
VERIFY( pc2 == array1 );
VERIFY( pc3 == pc1 ); // but pointers o-tay
c1 = *(str_01.data());
c2 = array1[0];
test &= c1 != c2;
VERIFY( c1 != c2 );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -132,9 +130,9 @@ int test02(void)
// assigns c = d;
wchar_t c1 = L'z';
wchar_t c2 = L'u';
test &= c1 != c2;
VERIFY( 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)
// 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
wchar_t array2[len];
test &= str_lit1[0] == 'm';
VERIFY( str_lit1[0] == 'm' );
c1 = array2[0];
c2 = str_lit1[0];
wchar_t c3 = array2[1];
wchar_t c4 = str_lit1[1];
std::char_traits<wchar_t>::move(array2, str_lit1, 0);
test &= array2[0] == c1;
test &= str_lit1[0] == c2;
VERIFY( array2[0] == c1 );
VERIFY( str_lit1[0] == c2 );
std::char_traits<wchar_t>::move(array2, str_lit1, 1);
test &= array2[0] == c2;
test &= str_lit1[0] == c2;
test &= array2[1] == c3;
test &= str_lit1[1] == c4;
VERIFY( array2[0] == c2 );
VERIFY( str_lit1[0] == c2 );
VERIFY( array2[1] == c3 );
VERIFY( str_lit1[1] == c4 );
std::char_traits<wchar_t>::move(array2, str_lit1, 2);
test &= array2[0] == c2;
test &= str_lit1[0] == c2;
test &= array2[1] == c4;
test &= str_lit1[1] == c4;
VERIFY( array2[0] == c2 );
VERIFY( str_lit1[0] == c2 );
VERIFY( array2[1] == c4 );
VERIFY( str_lit1[1] == c4 );
wchar_t* pc1 = array1 + 1;
c1 = pc1[0];
c2 = array1[0];
test &= c1 != c2;
VERIFY( c1 != c2 );
wchar_t* pc2 = std::char_traits<wchar_t>::move(array1, pc1, 0);
c3 = pc1[0];
c4 = array1[0];
test &= c1 == c3;
test &= c2 == c4;
test &= pc2 == array1;
VERIFY( c1 == c3 );
VERIFY( c2 == c4 );
VERIFY( pc2 == array1 );
c1 = pc1[0];
c2 = array1[0];
......@@ -180,13 +178,13 @@ int test02(void)
pc2 = std::char_traits<wchar_t>::move(array1, pc1, 10);
c3 = pc1[0];
c4 = array1[0];
test &= c1 != c3; // underlying wchar_t array changed.
test &= c4 != c3;
test &= pc2 == array1;
test &= pc3 == pc1; // but pointers o-tay
VERIFY( c1 != c3 ); // underlying wchar_t array changed.
VERIFY( c4 != c3 );
VERIFY( pc2 == array1 );
VERIFY( pc3 == pc1 ); // but pointers o-tay
c1 = *(str_01.data());
c2 = array1[0];
test &= c1 != c2;
VERIFY( c1 != c2 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -31,14 +31,16 @@
// things would be sorted in a dictionary.
#include <string>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
enum want_value {lt=0, z=1, gt=2};
void test_value(int result, want_value expected);
void test_value(int result, want_value expected) {
int
test_value(int result, want_value expected);
int
test_value(int result, want_value expected)
{
bool pass = false;
switch (expected) {
......@@ -61,11 +63,14 @@ void test_value(int result, want_value expected) {
#ifdef DEBUG_ASSERT
assert(pass);
#endif
}
return 0;
}
int test01(void) {
int
test01()
{
std::string str_0("costa rica");
std::string str_1("costa marbella");
std::string str_2;
......@@ -121,8 +126,12 @@ int test01(void) {
}
int main() {
int
main()
{
test01();
return 0;
}
......
......@@ -23,9 +23,7 @@
#include <new>
#include <string>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int test01(void)
{
......@@ -43,22 +41,22 @@ int test01(void)
csz01 = str01.size();
try {
std::string str03(str01, csz01 + 1);
test &= false;
VERIFY( false );
}
catch(std::out_of_range& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
try {
std::string str03(str01, csz01);
test &= str03.size() == 0;
test &= str03.size() <= str03.capacity();
VERIFY( str03.size() == 0 );
VERIFY( str03.size() <= str03.capacity() );
}
catch(...) {
test &= false;
VERIFY( false );
}
......@@ -68,13 +66,13 @@ int test01(void)
// should not crash, but what gets constructed is a bit arbitrary.
try {
std::string str03(str_lit01, csz01 + 1);
test &= true;
VERIFY( true );
}
catch(std::length_error& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
// 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.
try {
std::string str04(str_lit01, npos);
test &= true;
VERIFY( true );
}
catch(std::length_error& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
// Build a maxsize-1 lengthed string consisting of all A's
try {
std::string str03(csz01 - 1, 'A');
test &= str03.size() == csz01 - 1;
test &= str03.size() <= str03.capacity();
VERIFY( str03.size() == csz01 - 1 );
VERIFY( str03.size() <= str03.capacity() );
}
// NB: bad_alloc is regrettable but entirely kosher for
// out-of-memory situations.
catch(std::bad_alloc& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
// basic_string(const char* s, const allocator& a = allocator())
std::string str04(str_lit01);
test &= str01 == str04;
VERIFY( str01 == str04 );
// basic_string(size_type n, char c, const allocator& a = allocator())
csz01 = str01.max_size();
try {
std::string str03(csz01 + 1, 'z');
test &= false;
VERIFY( false );
}
catch(std::length_error& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
try {
std::string str04(npos, 'b'); // the "maverick's" of all string objects.
test &= false;
VERIFY( false );
}
catch(std::length_error& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
try {
std::string str03(csz01 - 1, 'z');
test &= str03.size() != 0;
test &= str03.size() <= str03.capacity();
VERIFY( str03.size() != 0 );
VERIFY( str03.size() <= str03.capacity() );
}
// NB: bad_alloc is regrettable but entirely kosher for
// out-of-memory situations.
catch(std::bad_alloc& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
// template<typename _InputIter>
// basic_string(_InputIter begin, _InputIter end, const allocator& a)
std::string str06(str01.begin(), str01.end());
test &= str06 == str01;
VERIFY( str06 == str01 );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -170,7 +168,7 @@ void test02()
// basic_string(_InputIter begin, _InputIter end, const allocator& a)
// where _InputIter is integral [21.3.1 para 15]
std::string s(10,0);
test &= s.size() == 10;
VERIFY( s.size() == 10 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
......
......@@ -22,9 +22,7 @@
#include <string>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01(void)
{
......@@ -42,45 +40,45 @@ bool test01(void)
// const_reference operator[] (size_type pos) const;
csz01 = str01.size();
cref cref1 = str01[csz01 - 1];
test &= cref1 == 'a';
VERIFY( cref1 == 'a' );
cref cref2 = str01[csz01];
test &= cref2 == char();
VERIFY( cref2 == char() );
// reference operator[] (size_type pos);
csz02 = str02.size();
ref ref1 = str02[csz02 - 1];
test &= ref1 == 'a';
VERIFY( ref1 == 'a' );
ref ref2 = str02[1];
test &= ref2 == '4';
VERIFY( ref2 == '4' );
// const_reference at(size_type pos) const;
csz01 = str01.size();
cref cref3 = str01.at(csz01 - 1);
test &= cref3 == 'a';
VERIFY( cref3 == 'a' );
try {
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) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
// reference at(size_type pos);
csz01 = str02.size();
ref ref3 = str02.at(csz02 - 1);
test &= ref3 == 'a';
VERIFY( ref3 == 'a' );
try {
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) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
#ifdef DEBUG_ASSERT
......
......@@ -22,9 +22,7 @@
#include <string>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01(void)
{
......@@ -43,71 +41,71 @@ bool test01(void)
// size_type find(const string&, size_type pos = 0) const;
csz01 = str01.find(str01);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.find(str01, 4);
test &= csz01 == npos;
VERIFY( csz01 == npos );
csz01 = str01.find(str02, 0);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.find(str02, 3);
test &= csz01 == npos;
VERIFY( csz01 == npos );
csz01 = str01.find(str03, 0);
test &= csz01 == 8;
VERIFY( csz01 == 8 );
csz01 = str01.find(str03, 3);
test &= csz01 == 8;
VERIFY( csz01 == 8 );
csz01 = str01.find(str03, 12);
test &= csz01 == npos;
VERIFY( csz01 == npos );
// An empty string consists of no characters
// therefore it should be found at every point in a string,
// except beyond the end
csz01 = str01.find(str04, 0);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.find(str04, 5);
test &= csz01 == 5;
VERIFY( csz01 == 5 );
csz01 = str01.find(str04, str01.size());
test &= csz01 == str01.size();
VERIFY( csz01 == str01.size() );
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;
csz01 = str01.find(str_lit01, 0, 3);
test &= csz01 == 0;
VERIFY( csz01 == 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;
csz01 = str01.find(str_lit01);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.find(str_lit01, 3);
test &= csz01 == npos;
VERIFY( csz01 == npos );
// size_type find(char c, size_type pos = 0) const;
csz01 = str01.find('z');
csz02 = str01.size() - 1;
test &= csz01 == csz02;
VERIFY( csz01 == csz02 );
csz01 = str01.find('/');
test &= csz01 == npos;
VERIFY( csz01 == npos );
// size_type find_first_of(const string&, size_type pos = 0) const;
std::string str05("xena rulez");
csz01 = str01.find_first_of(str01);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.find_first_of(str01, 4);
test &= csz01 == 4;
VERIFY( csz01 == 4 );
csz01 = str01.find_first_of(str02, 0);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.find_first_of(str02, 3);
test &= csz01 == 3;
VERIFY( csz01 == 3 );
csz01 = str01.find_first_of(str03, 0);
test &= csz01 == 8;
VERIFY( csz01 == 8 );
csz01 = str01.find_first_of(str03, 3);
test &= csz01 == 8;
VERIFY( csz01 == 8 );
csz01 = str01.find_first_of(str03, 12);
test &= csz01 == 16;
VERIFY( csz01 == 16 );
csz01 = str01.find_first_of(str05, 0);
test &= csz01 == 1;
VERIFY( csz01 == 1 );
csz01 = str01.find_first_of(str05, 4);
test &= csz01 == 4;
VERIFY( csz01 == 4 );
// An empty string consists of no characters
// 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
// str1 (starting at pos) that exists in str2, which is none for empty str2
csz01 = str01.find_first_of(str04, 0);
test &= csz01 == npos;
VERIFY( csz01 == npos );
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;
csz01 = str01.find_first_of(str_lit01, 0, 3);
test &= csz01 == 0;
VERIFY( csz01 == 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;
csz01 = str01.find_first_of(str_lit01);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
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;
csz01 = str01.find_first_of('z');
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 char* s, size_type pos, size_type n) const;
......@@ -146,45 +144,45 @@ bool test01(void)
std::string x;
std::string::size_type pos;
pos = x.find_last_not_of('X');
test &= pos == npos;
VERIFY( pos == npos );
pos = x.find_last_not_of("XYZ");
test &= pos == npos;
VERIFY( pos == npos );
std::string y("a");
pos = y.find_last_not_of('X');
test &= pos == 0;
VERIFY( pos == 0 );
pos = y.find_last_not_of('a');
test &= pos == npos;
VERIFY( pos == npos );
pos = y.find_last_not_of("XYZ");
test &= pos == 0;
VERIFY( pos == 0 );
pos = y.find_last_not_of("a");
test &= pos == npos;
VERIFY( pos == npos );
std::string z("ab");
pos = z.find_last_not_of('X');
test &= pos == 1;
VERIFY( pos == 1 );
pos = z.find_last_not_of("XYZ");
test &= pos == 1;
VERIFY( pos == 1 );
pos = z.find_last_not_of('b');
test &= pos == 0;
VERIFY( pos == 0 );
pos = z.find_last_not_of("Xb");
test &= pos == 0;
VERIFY( pos == 0 );
pos = z.find_last_not_of("Xa");
test &= pos == 1;
VERIFY( pos == 1 );
pos = z.find_last_of("ab");
test &= pos == 1;
VERIFY( pos == 1 );
pos = z.find_last_of("Xa");
test &= pos == 0;
VERIFY( pos == 0 );
pos = z.find_last_of("Xb");
test &= pos == 1;
VERIFY( pos == 1 );
pos = z.find_last_of("XYZ");
test &= pos == std::string::npos;
VERIFY( pos == std::string::npos );
pos = z.find_last_of('a');
test &= pos == 0;
VERIFY( pos == 0 );
pos = z.find_last_of('b');
test &= pos == 1;
VERIFY( pos == 1 );
pos = z.find_last_of('X');
test &= pos == std::string::npos;
VERIFY( pos == std::string::npos );
#endif
#ifdef DEBUG_ASSERT
......
......@@ -22,9 +22,7 @@
#include <string>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int test01(void)
{
......@@ -56,13 +54,13 @@ int test01(void)
csz02 = str02.size();
try {
str03.insert(csz01 + 1, str02, 0, 5);
test &= false;
VERIFY( false );
}
catch(std::out_of_range& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
str03 = str01;
......@@ -70,13 +68,13 @@ int test01(void)
csz02 = str02.size();
try {
str03.insert(0, str02, csz02 + 1, 5);
test &= false;
VERIFY( false );
}
catch(std::out_of_range& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
csz01 = str01.max_size();
......@@ -86,39 +84,39 @@ int test01(void)
csz02 = str02.size();
try {
str03.insert(0, str02, 0, 5);
test &= false;
VERIFY( false );
}
catch(std::length_error& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
}
catch(std::bad_alloc& failure){
test &= true;
VERIFY( true );
}
catch(std::exception& failure){
test &= false;
VERIFY( false );
}
str03 = str01;
csz01 = str03.size();
csz02 = str02.size();
str03.insert(13, str02, 0, 12);
test&= str03 == "rodeo beach, baker beach,marin";
VERIFY( str03 == "rodeo beach, baker beach,marin" );
str03 = str01;
csz01 = str03.size();
csz02 = str02.size();
str03.insert(0, str02, 0, 12);
test&= str03 == "baker beach,rodeo beach, marin";
VERIFY( str03 == "baker beach,rodeo beach, marin" );
str03 = str01;
csz01 = str03.size();
csz02 = str02.size();
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);
// insert(p1, str, 0, npos)
......@@ -126,47 +124,47 @@ int test01(void)
csz01 = str03.size();
csz02 = str02.size();
str03.insert(csz01, str02);
test&= str03 == "rodeo beach, marinbaker beach, san francisco";
VERIFY( str03 == "rodeo beach, marinbaker beach, san francisco" );
str03 = str01;
csz01 = str03.size();
csz02 = str02.size();
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);
// insert(p1, string(s,n))
str03 = str02;
csz01 = str03.size();
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);
// insert(p1, string(s))
str03 = str02;
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)
// insert(p1, string(n,c))
str03 = str02;
csz01 = str03.size();
str03.insert(csz01, 5, 'z');
test&= str03 == "baker beach, san franciscozzzzz";
VERIFY( str03 == "baker beach, san franciscozzzzz" );
// iterator insert(iterator p, char c)
// inserts a copy of c before the character referred to by p
str03 = str02;
citerator cit01 = str03.begin();
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)
// inserts n copies of c before the character referred to by p
str03 = str02;
cit01 = str03.begin();
str03.insert(cit01, 5, 'u');
test&= str03 == "uuuuubaker beach, san francisco";
VERIFY( str03 == "uuuuubaker beach, san francisco" );
// template<inputit>
// void
......@@ -176,12 +174,12 @@ int test01(void)
str03 = str02;
csz01 = str03.size();
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;
csz01 = str03.size();
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
assert(test);
......
......@@ -29,9 +29,7 @@
#include <sstream>
#include <fstream>
#include <iostream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01(void)
{
......@@ -54,91 +52,91 @@ bool test01(void)
// istream& operator>>(istream&, string&)
std::istringstream istrs01(str01);
istrs01 >> str10;
test &= str10 == str02;
VERIFY( str10 == str02 );
try {
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) {
test &= false; // shouldn't throw
VERIFY( false ); // shouldn't throw
}
istrs01 >> str10;
test &= str10 == str03;
VERIFY( str10 == str03 );
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
istrs02 >> str10;
test &= str10 == str04;
VERIFY( str10 == str04 );
// istream& getline(istream&, string&, char)
// istream& getline(istream&, string&)
try {
getline(istrs01, str10);
test &= !istrs01.fail();
test &= !istrs01.eof();
test &= istrs01.good();
test &= str10 == " bay";
VERIFY( !istrs01.fail() );
VERIFY( !istrs01.eof() );
VERIFY( istrs01.good() );
VERIFY( str10 == " bay" );
}
catch(std::exception& fail) {
test &= false; // shouldn't throw
VERIFY( false ); // shouldn't throw
}
try {
istrs01.clear();
getline(istrs01, str10,'\t');
test &= !istrs01.fail();
test &= !istrs01.eof();
test &= istrs01.good();
test &= str10 == str05;
VERIFY( !istrs01.fail() );
VERIFY( !istrs01.eof() );
VERIFY( istrs01.good() );
VERIFY( str10 == str05 );
}
catch(std::exception& fail) {
test &= false; // shouldn't throw
VERIFY( false ); // shouldn't throw
}
try {
istrs01.clear();
getline(istrs01, str10,'\t');
test &= !istrs01.fail();
test &= !istrs01.eof();
test &= istrs01.good();
test &= str10 == str05;
VERIFY( !istrs01.fail() );
VERIFY( !istrs01.eof() );
VERIFY( istrs01.good() );
VERIFY( str10 == str05 );
}
catch(std::exception& fail) {
test &= false; // shouldn't throw
VERIFY( false ); // shouldn't throw
}
try {
istrs01.clear();
getline(istrs01, str10, '.');
test &= !istrs01.fail();
test &= istrs01.eof();
test &= !istrs01.good();
test &= str10 == "\t from Elk Rapids to the point reminds me of miles";
VERIFY( !istrs01.fail() );
VERIFY( istrs01.eof() );
VERIFY( !istrs01.good() );
VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
}
catch(std::exception& fail) {
test &= false; // shouldn't throw
VERIFY( false ); // shouldn't throw
}
try {
getline(istrs02, str10);
test &= istrs02.fail();
test &= istrs02.eof();
test &= str10 == "\t from Elk Rapids to the point reminds me of miles";
VERIFY( istrs02.fail() );
VERIFY( istrs02.eof() );
VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
}
catch(std::exception& fail) {
test &= false; // shouldn't throw
VERIFY( false ); // shouldn't throw
}
// ostream& operator<<(ostream&, const basic_string&)
std::ostringstream ostrs01;
try {
ostrs01 << str01;
test &= ostrs01.str() == str01;
VERIFY( ostrs01.str() == str01 );
}
catch(std::exception& fail) {
test &= false;
VERIFY( false );
}
std::string hello_world;
......@@ -161,8 +159,8 @@ void test04(int size)
std::ostringstream oss(str);
// sanity checks
test &= str.size() == size;
test &= oss.good();
VERIFY( str.size() == size );
VERIFY( oss.good() );
// stress test
oss << str << std::endl;
......@@ -173,10 +171,10 @@ void test04(int size)
if (!oss.good())
test = false;
test &= str.size() == size;
test &= oss.good();
VERIFY( str.size() == size );
VERIFY( oss.good() );
std::string str_tmp = oss.str();
test &= str_tmp.size() == expected_size;
VERIFY( str_tmp.size() == expected_size );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -196,8 +194,8 @@ void test05(int size)
std::string str(size, fillc);
// sanity checks
test &= str.size() == size;
test &= ofs.good();
VERIFY( str.size() == size );
VERIFY( ofs.good() );
// stress test
ofs << str << std::endl;
......@@ -208,8 +206,8 @@ void test05(int size)
if (!ofs.good())
test = false;
test &= str.size() == size;
test &= ofs.good();
VERIFY( str.size() == size );
VERIFY( ofs.good() );
ofs.close();
......@@ -229,7 +227,7 @@ void test05(int size)
break;
}
test &= count == 2 * size;
VERIFY( count == 2 * size );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -251,16 +249,16 @@ void test06(void)
str01.erase(0, 1);
size_type i03 = str01.size();
size_type i04 = str01.capacity();
test &= i01 - 1 == i03;
test &= i02 >= i04;
VERIFY( i01 - 1 == i03 );
VERIFY( i02 >= i04 );
std::istringstream is(str01);
std::string str02;
is >> str02 >> std::ws;
size_type i05 = str02.size();
size_type i06 = str02.capacity();
test &= i05 == i03;
test &= i06 <= i04;
VERIFY( i05 == i03 );
VERIFY( i06 <= i04 );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -281,8 +279,8 @@ void test07(void)
while (iss >> s)
++i;
test &= i < 3;
test &= static_cast<bool>(iss.rdstate() & std::ios_base::failbit);
VERIFY( i < 3 );
VERIFY( static_cast<bool>(iss.rdstate() & std::ios_base::failbit) );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -22,9 +22,7 @@
#include <string>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
// Do a quick sanity check on known problems with element access and
// ref-counted strings. These should all pass, regardless of the
......@@ -60,48 +58,48 @@ bool test01(void)
str03 = str01;
it1 = str01.begin();
*it1 = 'x';
test &= str01[0] == 'x';
test &= str03[0] == 'm';
VERIFY( str01[0] == 'x' );
VERIFY( str03[0] == 'm' );
str03 = str01;
csz01 = str01.size();
rit1 = str01.rbegin(); // NB: Pointing at one-past the end, so ...
*rit1 = 'z'; // ... but it's taken care of here
test &= str01[csz01 - 1] == 'z';
test &= str03[csz01 - 1] == 'y';
VERIFY( str01[csz01 - 1] == 'z' );
VERIFY( str03[csz01 - 1] == 'y' );
str03 = str01;
csz01 = str01.size();
std::string::reference r1 = str01.at(csz01 - 2);
test &= str03 == str01;
VERIFY( str03 == str01 );
r1 = 'd';
test &= str01[csz01 - 2] == 'd';
test &= str03[csz01 - 2] == 'a';
VERIFY( str01[csz01 - 2] == 'd' );
VERIFY( str03[csz01 - 2] == 'a' );
str03 = str01;
csz01 = str01.size();
std::string::reference r2 = str01[csz01 - 3];
test &= str03 == str01;
VERIFY( str03 == str01 );
r2 = 'w';
test &= str01[csz01 - 3] == 'w';
test &= str03[csz01 - 3] == 'b';
VERIFY( str01[csz01 - 3] == 'w' );
VERIFY( str03[csz01 - 3] == 'b' );
str03 = str01;
csz02 = str01.size();
it1 = str01.end();
test &= str03 == str01;
VERIFY( str03 == str01 );
--it1;
*it1 = 'q';
test &= str01[csz02 - 1] == 'q';
test &= str03[csz02 - 1] == 'z';
VERIFY( str01[csz02 - 1] == 'q' );
VERIFY( str03[csz02 - 1] == 'z' );
str03 = str01;
rit1 = str01.rend();
test &= str03 == str01;
VERIFY( str03 == str01 );
--rit1;
*rit1 = 'p';
test &= str01[0] == 'p';
test &= str03[0] == 'x';
VERIFY( str01[0] == 'p' );
VERIFY( str03[0] == 'x' );
// need to also test for const begin/const end
#ifdef DEBUG_ASSERT
......@@ -129,39 +127,39 @@ bool test02(void)
std::string str05 = str02; // optional, so that begin below causes a mutate
std::string::iterator p = str02.insert(str02.begin(), ' ');
std::string str03 = str02;
test &= str03 == str02;
VERIFY( str03 == str02 );
*p = '!';
test &= *str03.c_str() == ' ';
VERIFY( *str03.c_str() == ' ' );
str03[0] = '@';
test &= str02[0] == '!';
test &= *p == '!';
test &= str02 != str05;
test &= str02 != str03;
VERIFY( str02[0] == '!' );
VERIFY( *p == '!' );
VERIFY( str02 != str05 );
VERIFY( str02 != str03 );
std::string str10 = str01;
std::string::iterator p2 = str10.insert(str10.begin(), 'a');
std::string str11 = str10;
*p2 = 'e';
test &= str11 != str10;
VERIFY( str11 != str10 );
std::string str06 = str01;
std::string str07 = str06; // optional, so that begin below causes a mutate
p = str06.erase(str06.begin());
std::string str08 = str06;
test &= str08 == str06;
VERIFY( str08 == str06 );
*p = '!';
test &= *str08.c_str() == 't';
VERIFY( *str08.c_str() == 't' );
str08[0] = '@';
test &= str06[0] == '!';
test &= *p == '!';
test &= str06 != str07;
test &= str06 != str08;
VERIFY( str06[0] == '!' );
VERIFY( *p == '!' );
VERIFY( str06 != str07 );
VERIFY( str06 != str08 );
std::string str12 = str01;
p2 = str12.erase(str12.begin(), str12.begin() + str12.size() - 1);
std::string str13 = str12;
*p2 = 'e';
test &= str12 != str13;
VERIFY( str12 != str13 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -111,9 +111,7 @@ template<class charT, class traits, class Allocator>
*/
#include <string>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int test01(void)
{
......@@ -126,114 +124,114 @@ int test01(void)
str_4 = str_0;
//comparisons between string objects
test &= !(str_0 == str_1);
test &= !(str_0 == str_2);
test &= !(str_0 == str_3);
test &= !(str_1 == str_0);
test &= !(str_2 == str_0);
test &= !(str_3 == str_0);
test &= str_4 == str_0;
test &= str_0 == str_4;
test &= str_0 != str_1;
test &= str_0 != str_2;
test &= str_0 != str_3;
test &= str_1 != str_0;
test &= str_2 != str_0;
test &= str_3 != str_0;
test &= !(str_0 != str_4);
test &= !(str_4 != str_0);
test &= str_0 > str_1; //true cuz r>m
test &= str_0 > str_2;
test &= !(str_0 > str_3);
test &= !(str_1 > str_0); //false cuz m<r
test &= !(str_2 > str_0);
test &= str_3 > str_0;
test &= !(str_0 > str_4);
test &= !(str_4 > str_0);
test &= !(str_0 < str_1); //false cuz r>m
test &= !(str_0 < str_2);
test &= str_0 < str_3;
test &= str_1 < str_0; //true cuz m<r
test &= str_2 < str_0;
test &= !(str_3 < str_0);
test &= !(str_0 < str_4);
test &= !(str_4 < str_0);
test &= str_0 >= str_1; //true cuz r>m
test &= str_0 >= str_2;
test &= !(str_0 >= str_3);
test &= !(str_1 >= str_0);//false cuz m<r
test &= !(str_2 >= str_0);
test &= str_3 >= str_0;
test &= str_0 >= str_4;
test &= str_4 >= str_0;
test &= !(str_0 <= str_1);//false cuz r>m
test &= !(str_0 <= str_2);
test &= str_0 <= str_3;
test &= str_1 <= str_0;//true cuz m<r
test &= str_2 <= str_0;
test &= !(str_3 <= str_0);
test &= str_0 <= str_4;
test &= str_4 <= str_0;
VERIFY( !(str_0 == str_1) );
VERIFY( !(str_0 == str_2) );
VERIFY( !(str_0 == str_3) );
VERIFY( !(str_1 == str_0) );
VERIFY( !(str_2 == str_0) );
VERIFY( !(str_3 == str_0) );
VERIFY( str_4 == str_0 );
VERIFY( str_0 == str_4 );
VERIFY( str_0 != str_1 );
VERIFY( str_0 != str_2 );
VERIFY( str_0 != str_3 );
VERIFY( str_1 != str_0 );
VERIFY( str_2 != str_0 );
VERIFY( str_3 != str_0 );
VERIFY( !(str_0 != str_4) );
VERIFY( !(str_4 != str_0) );
VERIFY( str_0 > str_1 ); //true cuz r>m
VERIFY( str_0 > str_2 );
VERIFY( !(str_0 > str_3) );
VERIFY( !(str_1 > str_0) ); //false cuz m<r
VERIFY( !(str_2 > str_0) );
VERIFY( str_3 > str_0 );
VERIFY( !(str_0 > str_4) );
VERIFY( !(str_4 > str_0) );
VERIFY( !(str_0 < str_1) ); //false cuz r>m
VERIFY( !(str_0 < str_2) );
VERIFY( str_0 < str_3 );
VERIFY( str_1 < str_0 ); //true cuz m<r
VERIFY( str_2 < str_0 );
VERIFY( !(str_3 < str_0) );
VERIFY( !(str_0 < str_4) );
VERIFY( !(str_4 < str_0) );
VERIFY( str_0 >= str_1 ); //true cuz r>m
VERIFY( str_0 >= str_2 );
VERIFY( !(str_0 >= str_3) );
VERIFY( !(str_1 >= str_0) );//false cuz m<r
VERIFY( !(str_2 >= str_0) );
VERIFY( str_3 >= str_0 );
VERIFY( str_0 >= str_4 );
VERIFY( str_4 >= str_0 );
VERIFY( !(str_0 <= str_1) );//false cuz r>m
VERIFY( !(str_0 <= str_2) );
VERIFY( str_0 <= str_3 );
VERIFY( str_1 <= str_0 );//true cuz m<r
VERIFY( str_2 <= str_0 );
VERIFY( !(str_3 <= str_0) );
VERIFY( str_0 <= str_4 );
VERIFY( str_4 <= str_0 );
//comparisons between string object and string literal
test &= !(str_0 == "costa marbella");
test &= !(str_0 == "cost");
test &= !(str_0 == "costa ricans");
test &= !("costa marbella" == str_0);
test &= !("cost" == str_0);
test &= !("costa ricans" == str_0);
test &= "costa rica" == str_0;
test &= str_0 == "costa rica";
test &= str_0 != "costa marbella";
test &= str_0 != "cost";
test &= str_0 != "costa ricans";
test &= "costa marbella" != str_0;
test &= "cost" != str_0;
test &= "costa ricans" != str_0;
test &= !("costa rica" != str_0);
test &= !(str_0 != "costa rica");
test &= str_0 > "costa marbella"; //true cuz r>m
test &= str_0 > "cost";
test &= !(str_0 > "costa ricans");
test &= !("costa marbella" > str_0);//false cuz m<r
test &= !("cost" > str_0);
test &= "costa ricans" > str_0;
test &= !("costa rica" > str_0);
test &= !(str_0 > "costa rica");
test &= !(str_0 < "costa marbella");//false cuz r>m
test &= !(str_0 < "cost");
test &= str_0 < "costa ricans";
test &= "costa marbella" < str_0;//true cuz m<r
test &= "cost" < str_0;
test &= !("costa ricans" < str_0);
test &= !("costa rica" < str_0);
test &= !(str_0 < "costa rica");
test &= str_0 >= "costa marbella";//true cuz r>m
test &= str_0 >= "cost";
test &= !(str_0 >= "costa ricans");
test &= !("costa marbella" >= str_0);//false cuz m<r
test &= !("cost" >= str_0);
test &= "costa ricans" >= str_0;
test &= "costa rica" >= str_0;
test &= str_0 >= "costa rica";
test &= !(str_0 <= "costa marbella");//false cuz r>m
test &= !(str_0 <= "cost");
test &= str_0 <= "costa ricans";
test &= "costa marbella" <= str_0;//true cuz m<r
test &= "cost" <= str_0;
test &= !("costa ricans" <= str_0);
test &= "costa rica" <= str_0;
test &= str_0 <= "costa rica";
VERIFY( !(str_0 == "costa marbella") );
VERIFY( !(str_0 == "cost") );
VERIFY( !(str_0 == "costa ricans") );
VERIFY( !("costa marbella" == str_0) );
VERIFY( !("cost" == str_0) );
VERIFY( !("costa ricans" == str_0) );
VERIFY( "costa rica" == str_0 );
VERIFY( str_0 == "costa rica" );
VERIFY( str_0 != "costa marbella" );
VERIFY( str_0 != "cost" );
VERIFY( str_0 != "costa ricans" );
VERIFY( "costa marbella" != str_0 );
VERIFY( "cost" != str_0 );
VERIFY( "costa ricans" != str_0 );
VERIFY( !("costa rica" != str_0) );
VERIFY( !(str_0 != "costa rica") );
VERIFY( str_0 > "costa marbella" ); //true cuz r>m
VERIFY( str_0 > "cost" );
VERIFY( !(str_0 > "costa ricans") );
VERIFY( !("costa marbella" > str_0) );//false cuz m<r
VERIFY( !("cost" > str_0) );
VERIFY( "costa ricans" > str_0 );
VERIFY( !("costa rica" > str_0) );
VERIFY( !(str_0 > "costa rica") );
VERIFY( !(str_0 < "costa marbella") );//false cuz r>m
VERIFY( !(str_0 < "cost") );
VERIFY( str_0 < "costa ricans" );
VERIFY( "costa marbella" < str_0 );//true cuz m<r
VERIFY( "cost" < str_0 );
VERIFY( !("costa ricans" < str_0) );
VERIFY( !("costa rica" < str_0) );
VERIFY( !(str_0 < "costa rica") );
VERIFY( str_0 >= "costa marbella" );//true cuz r>m
VERIFY( str_0 >= "cost" );
VERIFY( !(str_0 >= "costa ricans") );
VERIFY( !("costa marbella" >= str_0) );//false cuz m<r
VERIFY( !("cost" >= str_0) );
VERIFY( "costa ricans" >= str_0 );
VERIFY( "costa rica" >= str_0 );
VERIFY( str_0 >= "costa rica" );
VERIFY( !(str_0 <= "costa marbella") );//false cuz r>m
VERIFY( !(str_0 <= "cost") );
VERIFY( str_0 <= "costa ricans" );
VERIFY( "costa marbella" <= str_0 );//true cuz m<r
VERIFY( "cost" <= str_0 );
VERIFY( !("costa ricans" <= str_0) );
VERIFY( "costa rica" <= str_0 );
VERIFY( str_0 <= "costa rica" );
// 21.3.7.1 operator+
/*
......@@ -262,19 +260,19 @@ template<class charT, class traits, class Allocator>
*/
str_4 = str_0 + "ns";
test &= str_4 == str_3;
VERIFY( str_4 == str_3 );
const std::string str_5(" marbella");
str_4 = "costa" + str_5;
test &= str_4 == str_1;
VERIFY( str_4 == str_1 );
std::string str_6("ns");
str_4 = str_0 + str_6;
test &= str_4 == str_3;
VERIFY( str_4 == str_3 );
str_4 = str_0 + 'n';
str_4 = str_4 + 's';
test &= str_4 == str_3;
VERIFY( str_4 == str_3 );
str_4 = 'a' + str_6;
str_4 = 'c' + str_4;
......@@ -286,7 +284,7 @@ template<class charT, class traits, class Allocator>
str_4 = 's' + str_4;
str_4 = 'o' + str_4;
str_4 = 'c' + str_4;
test &= str_4 == str_3;
VERIFY( str_4 == str_3 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -22,9 +22,7 @@
#include <string>
#include <cstdio>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int test01(void)
{
......
......@@ -22,9 +22,7 @@
#include <string>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01(void)
{
......@@ -60,23 +58,23 @@ bool test01(void)
std::string x = X;
char ch = x[0];
test &= ch == 'H';
VERIFY( ch == 'H' );
std::string z = x.substr(2, 3);
test &= z == "llo";
VERIFY( z == "llo" );
x.replace(2, 2, "r");
test &= x == "Hero";
VERIFY( x == "Hero" );
x = X;
x.replace(0, 1, "j");
test &= x == "jello";
VERIFY( x == "jello" );
int ar[] = { 'H', 'e', 'l', 'l', 'o' };
x.replace(std::find(x.begin(), x.end(), 'l'),
std::find(x.rbegin(), x.rend(), 'l').base(), ar,
ar + sizeof(ar) / sizeof(ar[0]));
test &= x == "jeHelloo";
VERIFY( x == "jeHelloo" );
#endif
#ifdef DEBUG_ASSERT
......
......@@ -20,9 +20,7 @@
#include <string>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
// 21.3.6.2 basic_string rfind
bool test01(void)
......@@ -42,50 +40,50 @@ bool test01(void)
// size_type rfind(const string&, size_type pos = 0) const;
csz01 = str01.rfind(str01);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str01, 4);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str02,3);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str02);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str03);
test &= csz01 == 8;
VERIFY( csz01 == 8 );
csz01 = str01.rfind(str03, 3);
test &= csz01 == npos;
VERIFY( csz01 == npos );
csz01 = str01.rfind(str03, 12);
test &= csz01 == 8;
VERIFY( csz01 == 8 );
// An empty string consists of no characters
// therefore it should be found at every point in a string,
// except beyond the end
csz01 = str01.rfind(str04, 0);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str04, 5);
test &= csz01 == 5;
VERIFY( csz01 == 5 );
csz01 = str01.rfind(str04, str01.size());
test &= csz01 == str01.size();
VERIFY( csz01 == str01.size() );
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;
csz01 = str01.rfind(str_lit01, 0, 3);
test &= csz01 == 0;
VERIFY( csz01 == 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;
csz01 = str01.rfind(str_lit01);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
csz01 = str01.rfind(str_lit01, 3);
test &= csz01 == 0;
VERIFY( csz01 == 0 );
// size_type rfind(char c, size_type pos = 0) const;
csz01 = str01.rfind('z');
csz02 = str01.size() - 1;
test &= csz01 == csz02;
VERIFY( csz01 == csz02 );
csz01 = str01.rfind('/');
test &= csz01 == npos;
VERIFY( csz01 == npos );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -22,9 +22,7 @@
#include <string>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01(void)
{
......@@ -43,30 +41,30 @@ bool test01(void)
// substr(size_type pos = 0, size_type n = npos) const;
csz01 = str01.size();
str02 = str01.substr(0, 1);
test &= str02 == "r";
VERIFY( str02 == "r" );
str02 = str01.substr(10);
test &= str02 == "pacifica";
VERIFY( str02 == "pacifica" );
try {
str02 = str01.substr(csz01 + 1);
test &= false;
VERIFY( false );
}
catch(std::out_of_range& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
try {
str02 = str01.substr(csz01);
test &= str02.size() == 0;
VERIFY( str02.size() == 0 );
}
catch(std::out_of_range& fail) {
test &= false;
VERIFY( false );
}
catch(...) {
test &= false;
VERIFY( false );
}
#ifdef DEBUG_ASSERT
......
......@@ -31,9 +31,7 @@
#include <locale>
// NB: Don't include any other headers in this file.
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
class gnu_ctype: public std::ctype<char> {};
......@@ -59,37 +57,37 @@ void test01()
char c_array[len + 1];
// bool is(mask m, char c) const;
test &= gctype.is(std::ctype_base::space, c30);
test &= gctype.is(std::ctype_base::upper, c00);
test &= gctype.is(std::ctype_base::lower, c10);
test &= gctype.is(std::ctype_base::digit, c20);
test &= gctype.is(std::ctype_base::punct, c40);
test &= gctype.is(std::ctype_base::alpha, c50);
test &= gctype.is(std::ctype_base::alpha, c60);
test &= gctype.is(std::ctype_base::xdigit, c20);
test &= !gctype.is(std::ctype_base::xdigit, c80);
test &= gctype.is(std::ctype_base::alnum, c50);
test &= gctype.is(std::ctype_base::alnum, c20);
test &= gctype.is(std::ctype_base::graph, c40);
test &= gctype.is(std::ctype_base::graph, c20);
VERIFY( gctype.is(std::ctype_base::space, c30) );
VERIFY( gctype.is(std::ctype_base::upper, c00) );
VERIFY( gctype.is(std::ctype_base::lower, c10) );
VERIFY( gctype.is(std::ctype_base::digit, c20) );
VERIFY( gctype.is(std::ctype_base::punct, c40) );
VERIFY( gctype.is(std::ctype_base::alpha, c50) );
VERIFY( gctype.is(std::ctype_base::alpha, c60) );
VERIFY( gctype.is(std::ctype_base::xdigit, c20) );
VERIFY( !gctype.is(std::ctype_base::xdigit, c80) );
VERIFY( gctype.is(std::ctype_base::alnum, c50) );
VERIFY( gctype.is(std::ctype_base::alnum, c20) );
VERIFY( gctype.is(std::ctype_base::graph, c40) );
VERIFY( gctype.is(std::ctype_base::graph, c20) );
// char toupper(char c) const
c100 = gctype.toupper(c10);
test &= c100 == c00;
VERIFY( c100 == c00 );
// char tolower(char c) const
c100 = gctype.tolower(c00);
test &= c100 == c10;
VERIFY( c100 == c10 );
// char toupper(char* low, const char* hi) const
std::char_traits<char>::copy(c_array, strlit02, len + 1);
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
std::char_traits<char>::copy(c_array, strlit01, len + 1);
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
......
......@@ -22,9 +22,7 @@
#include <string>
#include <bitset>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01(void)
{
......@@ -34,15 +32,15 @@ bool test01(void)
const size_t n1 = 5;
std::bitset<n1> bit01;
for (int i = 0; i < n1; ++i)
test &= !bit01.test(i);
VERIFY( !bit01.test(i) );
// bitset(unsigned long)
const size_t n2 = 32;
unsigned long ul1 = 2;
std::bitset<n2> bit02(ul1);
test &= !bit02.test(0);
test &= bit02.test(1);
test &= !bit02.test(2);
VERIFY( !bit02.test(0) );
VERIFY( bit02.test(1) );
VERIFY( !bit02.test(2) );
// template<_CharT, _Traits, _Alloc>
// 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);
}
catch(std::invalid_argument& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test&= false;
VERIFY( false );
}
std::string str02("010101000011");
......@@ -66,13 +64,13 @@ bool test01(void)
for (int i = 0; i < sz; ++i)
str03 += (bit03.test(i) ? '1' : '0');
std::reverse(str03.begin(), str03.end());
test &= str03 == str02;
VERIFY( str03 == str02 );
}
catch(std::invalid_argument& fail) {
test &= false;
VERIFY( false );
}
catch(...) {
test&= false;
VERIFY( false );
}
......
......@@ -22,9 +22,7 @@
#include <set>
#include <bitset>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
static char original_bits[1024];
static char left_shifted[1024];
......@@ -78,13 +76,13 @@ template <size_t size>
shifted <<= shift_step;
//correct = std::string(left_shifted);
correct = std::bitset<size> (std::string(left_shifted));
test &= shifted == correct;
VERIFY( shifted == correct );
shifted = original;
shifted >>= shift_step;
//correct = std::string(right_shifted);
correct = std::bitset<size> (std::string(right_shifted));
test &= shifted == correct;
VERIFY( shifted == correct );
}
return test;
......@@ -94,13 +92,13 @@ bool
test01() {
bool test = true;
test &= do_test<32>();
test &= do_test<48>();
test &= do_test<64>();
VERIFY( do_test<32>() );
VERIFY( do_test<48>() );
VERIFY( do_test<64>() );
test &= do_test<511>();
test &= do_test<513>();
test &= do_test<997>();
VERIFY( do_test<511>() );
VERIFY( do_test<513>() );
VERIFY( do_test<997>() );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -22,9 +22,7 @@
// 23.2.4.2 vector capacity
#include <vector>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
template<typename T>
struct A { };
......@@ -42,17 +40,17 @@ bool test01()
size_type sz01 = vec01.capacity();
vec01.reserve(100);
size_type sz02 = vec01.capacity();
test &= sz02 >= sz01;
VERIFY( sz02 >= sz01 );
sz01 = vec01.size() + 5;
vec01.resize(sz01);
sz02 = vec01.size();
test &= sz01 == sz02;
VERIFY( sz01 == sz02 );
sz01 = vec01.size() - 5;
vec01.resize(sz01);
sz02 = vec01.size();
test &= sz01 == sz02;
VERIFY( sz01 == sz02 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -22,9 +22,7 @@
// 23.2.4.1 vector constructors, copy, and assignment
#include <vector>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
template<typename T>
struct A { };
......
......@@ -21,9 +21,7 @@
// 23.2.4.3 vector modifiers
#include <vector>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
template<typename T>
struct A { };
......
......@@ -22,9 +22,7 @@
#include <sstream>
#include <iterator>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01(void)
{
......@@ -41,55 +39,55 @@ bool test01(void)
cistreambuf_iter istrb_it01(istrs00);
cistreambuf_iter istrb_it02;
std::string tmp(istrb_it01, istrb_it02);
test &= tmp == str01;
VERIFY( tmp == str01 );
cistreambuf_iter istrb_it03(0);
cistreambuf_iter istrb_it04;
test &= istrb_it03 == istrb_it04;
VERIFY( istrb_it03 == istrb_it04 );
cistreambuf_iter istrb_it05(istrs01);
cistreambuf_iter istrb_it06(istrs01.rdbuf());
test &= istrb_it05 == istrb_it06;
VERIFY( istrb_it05 == istrb_it06 );
// bool equal(istreambuf_iter& b)
cistreambuf_iter istrb_it07(0);
cistreambuf_iter istrb_it08;
test &= istrb_it07.equal(istrb_it08);
VERIFY( istrb_it07.equal(istrb_it08) );
cistreambuf_iter istrb_it09(0);
cistreambuf_iter istrb_it10;
test &= istrb_it10.equal(istrb_it09);
VERIFY( istrb_it10.equal(istrb_it09) );
cistreambuf_iter istrb_it11(istrs01);
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_it14(istrs01.rdbuf());
test &= istrb_it14.equal(istrb_it13);
VERIFY( istrb_it14.equal(istrb_it13) );
cistreambuf_iter istrb_it15(istrs01);
cistreambuf_iter istrb_it16;
test &= !(istrb_it15.equal(istrb_it16));
VERIFY( !(istrb_it15.equal(istrb_it16)) );
cistreambuf_iter istrb_it17(istrs01);
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)
cistreambuf_iter istrb_it19(0);
cistreambuf_iter istrb_it20;
test &= istrb_it19 == istrb_it20;
VERIFY( istrb_it19 == istrb_it20 );
cistreambuf_iter istrb_it21(istrs01);
cistreambuf_iter istrb_it22(istrs01.rdbuf());
test &= istrb_it22 == istrb_it21;
VERIFY( istrb_it22 == istrb_it21 );
cistreambuf_iter istrb_it23(istrs01);
cistreambuf_iter istrb_it24;
test &= istrb_it23 != istrb_it24;
VERIFY( istrb_it23 != istrb_it24 );
cistreambuf_iter istrb_it25(0);
cistreambuf_iter istrb_it26(istrs01.rdbuf());
test &= istrb_it25 != istrb_it26;
VERIFY( istrb_it25 != istrb_it26 );
// charT operator*() const
// istreambuf_iterator& operator++();
......@@ -99,7 +97,7 @@ bool test01(void)
for (int i = 0; i < sizeof(slit01) - 2; ++i)
{
c = *istrb_it27++;
test &= c == slit01[i];
VERIFY( c == slit01[i] );
}
std::istringstream istrs02(str01);
......@@ -107,7 +105,7 @@ bool test01(void)
for (int i = 0; i < sizeof(slit01) - 3;)
{
c = *++istrb_it28;
test &= c == slit01[++i];
VERIFY( c == slit01[++i] );
}
#ifdef DEBUG_ASSERT
......
......@@ -21,11 +21,10 @@
#include <string>
#include <vector>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
int string_stuff()
int
string_stuff()
{
int failures(0);
......@@ -250,7 +249,8 @@ int string_stuff()
return failures;
}
int vector_stuff()
int
vector_stuff()
{
int failures(0);
......@@ -487,7 +487,8 @@ int vector_stuff()
return failures;
}
int reverse_stuff()
int
reverse_stuff()
{
int failures(0);
......@@ -512,7 +513,8 @@ int reverse_stuff()
// the following should be compiler errors
// flag runtime errors in case they slip through the compiler
int wrong_stuff()
int
wrong_stuff()
{
int failures(0);
......@@ -575,7 +577,8 @@ int wrong_stuff()
return failures;
}
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
int failures(0);
......@@ -594,6 +597,3 @@ int main(int argc, char **argv)
return failures ? 1 : 0;
}
......@@ -17,9 +17,7 @@
// USA.
#include <algorithm>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
// http://sourceware.cygnus.com/ml/libstdc++/2000-06/msg00316.html
struct foo { };
......
......@@ -19,22 +19,20 @@
// USA.
#include <algorithm>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
void test01()
{
bool test = true;
const int& x = std::max(1, 2);
const int& y = std::max(3, 4);
test &= x == 2;
test &= y == 4;
VERIFY( x == 2 );
VERIFY( y == 4 );
const int& z = std::min(1, 2);
const int& w = std::min(3, 4);
test &= z == 1;
test &= w == 3;
VERIFY( z == 1 );
VERIFY( w == 3 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -20,38 +20,48 @@
// USA.
#include <cmath>
#include <cassert>
#include <debug_assert.h>
// test compilation.
void test01()
int
test01()
{
float a = 1.f;
float b;
std::modf(a, &b);
return 0;
}
// need more extravagant checks than this, of course, but this used to core...
void test02()
int
test02()
{
sin(static_cast<float>(0));
return 0;
}
// as did this.
void test03()
int
test03()
{
double powtest = pow(2., 0);
return 0;
}
// this used to abort.
void test04()
int
test04()
{
bool test = true;
float x[2] = {1, 2};
float y = 3.4;
std::modf(y, &x[0]);
assert (x[1] == 2);
VERIFY(x[1] == 2);
return 0;
}
int main()
int
main()
{
test01();
test02();
......@@ -59,3 +69,4 @@ int main()
test04();
return 0;
}
......@@ -24,9 +24,7 @@
#include <string>
#include <sstream>
#include <complex>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
#include <cmath>
template<typename R>
......@@ -37,25 +35,28 @@ inline bool flteq(R x, R y)
}
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;
std::complex<R> z;
char ch;
std::istringstream iss(str);
iss >> z >> ch;
test &= iss.good();
test &= flteq(z.real(), x);
test &= flteq(z.imag(), y);
test &= ch == '#';
VERIFY( iss.good() );
VERIFY( flteq(z.real(), x) );
VERIFY( flteq(z.imag(), y) );
VERIFY( ch == '#' );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return 0;
}
template<typename R>
void test_fail(std::string str)
int
test_fail(std::string str)
{
std::complex<R> z;
std::istringstream iss(str);
......@@ -63,10 +64,12 @@ void test_fail(std::string str)
#ifdef DEBUG_ASSERT
assert(iss.fail() && !iss.bad());
#endif
return 0;
}
template<typename R>
void testall()
int
testall()
{
test_good<R>("(-1.1,3.7)#", -1.1, 3.7);
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|");
return 0;
}
int main()
int
main()
{
testall<float>();
testall<double>();
......@@ -92,5 +97,3 @@ int main()
return 0;
}
......@@ -25,7 +25,7 @@
#include <cassert>
#include <unistd.h>
#include <fcntl.h>
#include <debug_assert.h>
// verify that std::filebuf doesn't close files that it didn't open
// when using the following std::filebuf ctor:
......@@ -48,29 +48,29 @@ test_01()
// read (ext)
int fd = open(name_01, O_RDONLY);
test &= fd >= 0;
VERIFY( fd >= 0 );
{
std::filebuf fb(fd, "double_read", std::ios_base::in);
}
close_num = close(fd);
test &= close_num == 0;
VERIFY( close_num == 0 );
// read (standard)
FILE* f = fopen(name_01, "r");
test &= f != NULL;
VERIFY( f != NULL );
{
std::ifstream ifstream1(name_01);
test &= ifstream1.is_open();
VERIFY( ifstream1.is_open() );
std::ios_base::iostate st01 = ifstream1.rdstate();
test &= st01 == std::ios_base::goodbit;
VERIFY( st01 == std::ios_base::goodbit );
}
close_num = fclose(f);
test &= close_num == 0;
VERIFY( close_num == 0 );
#ifdef DEBUG_ASSERT
......
......@@ -30,9 +30,7 @@
// 27.4.3 template class fpos
#include <ios>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
void test01()
{
......@@ -61,7 +59,7 @@ void test01()
// operators, increment and deincrement operators need to be in place.
pos01.state(state02);
state01 = pos01.state();
test &= state01 == state02;
VERIFY( state01 == state02 );
#endif
#ifdef DEBUG_ASSERT
......@@ -87,43 +85,43 @@ void test02()
// p(i), p = i
std::streampos pos01(i02);
std::streampos pos02 = i02;
test &= pos01 == pos02;
VERIFY( pos01 == pos02 );
// p(o), p = o
// NB: P(o) is only required.
std::streampos pos03(off02);
std::streampos pos04 = off02;
test &= pos03 == pos04;
VERIFY( pos03 == pos04 );
// O(p)
std::streamoff off03(pos04);
test &= off03 == off02;
VERIFY( off03 == off02 );
// p == q, p!= q
test &= pos01 == pos02;
test &= pos02 != pos03;
VERIFY( pos01 == pos02 );
VERIFY( pos02 != pos03 );
// q = p + o
// p += o
pos03 = pos03 + off02;
pos04 += off02;
test &= pos03 == pos04;
VERIFY( pos03 == pos04 );
// q = p - o
// p -= o
pos03 = pos03 - off02;
pos04 -= off02;
test &= pos03 == pos04;
VERIFY( pos03 == pos04 );
// o = p - q
test &= 0 == pos03 - pos04;
VERIFY( 0 == pos03 - pos04 );
// streamsize -> streamoff
// streamoff -> streamsize
off01 = off02;
std::streamsize size01(off02);
std::streamoff off04(size01);
test &= off01 == off04;
VERIFY( off01 == off04 );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -152,14 +150,14 @@ void test03()
// equality/inequality with const args
const std::streampos pos02(54);
std::streampos pos03(44);
test &= !(pos03 == pos02);
test &= pos03 != pos02;
test &= !(pos02 == pos03);
test &= pos02 != pos03;
VERIFY( !(pos03 == pos02) );
VERIFY( pos03 != pos02 );
VERIFY( !(pos02 == pos03) );
VERIFY( pos02 != pos03 );
// default values
std::streampos pos04;
test &= (std::streamoff)pos04 == 0;
VERIFY( (std::streamoff)pos04 == 0 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -20,9 +20,7 @@
#include <istream>
#include <fstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
const char name_01[] = "testsuite/ifstream_members-1.tst";
const char name_02[] = "testsuite/ifstream_members-1.txt";
......@@ -35,15 +33,15 @@ bool test00()
ifs1.close();
// false as expected:
test &= !ifs1.is_open();
VERIFY( !ifs1.is_open() );
// this is now true:
test &= !(ifs1);
VERIFY( !(ifs1) );
ifs1.open(name_01);
test &= ifs1.is_open();
VERIFY( ifs1.is_open() );
// fail bit still true
test &= !(ifs1);
test &= ifs1.rdstate() == std::ios_base::failbit;
VERIFY( !(ifs1) );
VERIFY( ifs1.rdstate() == std::ios_base::failbit );
ifs1.close();
......@@ -63,7 +61,7 @@ bool test01()
for(int i = 0; ++i < more_than_max_open_files;)
{
std::ifstream ifs(name_01);
test &= static_cast<bool>(ifs);
VERIFY( static_cast<bool>(ifs) );
}
#ifdef DEBUG_ASSERT
......
......@@ -22,9 +22,7 @@
#include <string>
#include <sstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
const std::string str01("the nubians of plutonia");
std::string str02;
......@@ -52,7 +50,7 @@ bool test01()
ios01.register_callback(callb02, 1);
ios01.register_callback(callb01, 1);
ios01.imbue(locco);
test &= str01 == str02;
VERIFY( str01 == str02 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -24,9 +24,7 @@
#include <sstream>
#include <iostream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01()
{
......@@ -36,15 +34,15 @@ bool test01()
std::ios ios01(&strbuf01);
// 1: basic invocation
test &= ios01.sync_with_stdio();
test &= ios01.sync_with_stdio(false); //returns previous state
VERIFY( ios01.sync_with_stdio() );
VERIFY( ios01.sync_with_stdio(false) ); //returns previous state
// 2: need to test interleaving of C and C++ io on a file object.
test &= std::cout.good();
test &= !std::cout.sync_with_stdio(0);
test &= std::cout.good();
test &= !std::cout.sync_with_stdio(0);
test &= std::cout.good();
VERIFY( std::cout.good() );
VERIFY( !std::cout.sync_with_stdio(0) );
VERIFY( std::cout.good() );
VERIFY( !std::cout.sync_with_stdio(0) );
VERIFY( std::cout.good() );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -31,9 +31,7 @@
#include <ios>
#include <sstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
void test01()
{
......@@ -60,27 +58,27 @@ void test01()
// void init(sreambuf* sb)
// NB: This is protected so need to go through fstream/stringstream
// Can double-check the accuracy of the above initializations though.
test &= ios_00.rdbuf() == 0;
test &= ios_00.tie() == 0;
test &= ios_00.rdstate() == std::ios_base::badbit;
test &= ios_00.exceptions() == std::ios_base::goodbit;
VERIFY( ios_00.rdbuf() == 0 );
VERIFY( ios_00.tie() == 0 );
VERIFY( ios_00.rdstate() == std::ios_base::badbit );
VERIFY( ios_00.exceptions() == std::ios_base::goodbit );
flag02 = ios_00.flags();
test &= flag02 == flag01;
test &= ios_00.width() == 0;
test &= ios_00.precision() == 6;
test &= ios_00.fill() == ios_00.widen(' ');
test &= ios_00.getloc() == glocale;
VERIFY( flag02 == flag01 );
VERIFY( ios_00.width() == 0 );
VERIFY( ios_00.precision() == 6 );
VERIFY( ios_00.fill() == ios_00.widen(' ') );
VERIFY( ios_00.getloc() == glocale );
test &= ios_01.rdbuf() == &strb_01;
test &= ios_01.tie() == 0;
test &= ios_01.rdstate() == std::ios_base::goodbit;
test &= ios_01.exceptions() == std::ios_base::goodbit;
VERIFY( ios_01.rdbuf() == &strb_01 );
VERIFY( ios_01.tie() == 0 );
VERIFY( ios_01.rdstate() == std::ios_base::goodbit );
VERIFY( ios_01.exceptions() == std::ios_base::goodbit );
flag02 = ios_01.flags();
test &= flag02 == flag01;
test &= ios_01.width() == 0;
test &= ios_01.precision() == 6;
test &= ios_01.fill() == ios_01.widen(' ');
test &= ios_01.getloc() == glocale;
VERIFY( flag02 == flag01 );
VERIFY( ios_01.width() == 0 );
VERIFY( ios_01.precision() == 6 );
VERIFY( ios_01.fill() == ios_01.widen(' ') );
VERIFY( ios_01.getloc() == glocale );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -31,9 +31,7 @@
#include <sstream>
#include <locale>
#include <iomanip>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
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; }
char MyNP::do_thousands_sep() const { return ' '; }
void test01()
int
test01()
{
std::cout.imbue(std::locale(std::locale(), new MyNP));
std::cout << std::oct << std::showbase;
......@@ -71,9 +70,11 @@ void test01()
#ifdef DEBUG_ASSERT
assert (std::cout.good());
#endif
return 0;
}
void test02()
int
test02()
{
bool test = true;
const std::string str_blank;
......@@ -82,23 +83,25 @@ void test02()
std::ostream o(&strbuf);
o << std::setw(6) << std::right << "san";
test &= strbuf.str() == " san";
VERIFY( strbuf.str() == " san" );
strbuf.str(str_blank);
o << std::setw(6) << std::internal << "fran";
test &= strbuf.str() == " fran";
VERIFY( strbuf.str() == " fran" );
strbuf.str(str_blank);
o << std::setw(6) << std::left << "cisco";
test &= strbuf.str() == "cisco ";
VERIFY( strbuf.str() == "cisco " );
strbuf.str(str_blank);
#ifdef DEBUG_ASSERT
assert (test);
#endif
return 0;
}
int main() {
int
main() {
test01();
return 0;
}
......
......@@ -31,9 +31,7 @@
#include <sstream>
#include <locale>
#include <iomanip>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
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_falsename() const { static std::string s("nay"); return s; }
void test01()
int
test01()
{
std::cout << true << " " << false << std::endl;
std::cout << std::boolalpha;
......@@ -71,9 +70,11 @@ void test01()
#ifdef DEBUG_ASSERT
assert (std::cout.good());
#endif
return 0;
}
void test02()
int
test02()
{
bool test = true;
const std::string strue("true");
......@@ -88,19 +89,21 @@ void test02()
ostr01 << true;
str02 = ostr01.str();
test &= str02 == strue;
VERIFY( str02 == strue );
ostr01.str(str01);
ostr01 << false;
str02 = ostr01.str();
test &= str02 == sfalse;
VERIFY( str02 == sfalse );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return 0;
}
int main() {
int
main() {
test01();
test02();
return 0;
......
......@@ -31,9 +31,7 @@
#include <ios>
// NB: Don't include any other headers in this file.
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
void test01()
{
......@@ -54,11 +52,11 @@ void test01()
// char narrow(char_type c, char dfault) const;
char c1 = ios_01.narrow(ct02, 0);
test &= c1 == 'x';
VERIFY( c1 == 'x' );
// char_type widen(char c) const;
ct01 = ios_01.widen('c');
test &= ct01 == 'c';
VERIFY( ct01 == 'c' );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -85,57 +83,57 @@ void test02()
std::ios::char_type ct02('x');;
// bool fail() const
test &= ios_01.fail();
VERIFY( ios_01.fail() );
// bool operator!() const
test &= !ios_01;
VERIFY( !ios_01 );
// iostate rdstate() const
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)
try {
ios_01.clear(std::ios_base::eofbit);
iostate02 = ios_01.rdstate();
test &= static_cast<bool>(iostate02 & iostate01);
VERIFY( static_cast<bool>(iostate02 & iostate01) );
}
catch(std::ios_base::failure& fail) {
test &= false;
VERIFY( false );
}
catch(...) {
test &= false;
VERIFY( false );
}
// iostate exceptions() const
test &= ios_01.exceptions() == std::ios_base::goodbit;
VERIFY( ios_01.exceptions() == std::ios_base::goodbit );
// void exceptions(iostate except)
try {
ios_01.exceptions(std::ios_base::eofbit);
test &= false;
VERIFY( false );
}
catch(std::ios_base::failure& fail) {
iostate02 = ios_01.exceptions();
test &= static_cast<bool>(iostate02 & std::ios_base::eofbit);
VERIFY( static_cast<bool>(iostate02 & std::ios_base::eofbit) );
}
catch(...) {
test &= false;
VERIFY( false );
}
// basic_ios& copyfmt(const basic_ios& rhs)
std::ios ios_02(NULL);
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 {
ios_01.copyfmt(ios_02);
test &= false;
VERIFY( false );
}
catch(std::ios_base::failure& fail) {
test &= true;
VERIFY( true );
}
catch(...) {
test &= false;
VERIFY( false );
}
#ifdef DEBUG_ASSERT
......
......@@ -22,9 +22,7 @@
#include <istream>
#include <sstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01() {
......@@ -53,28 +51,28 @@ bool test01() {
is_01 >> array1; // should snake 0 characters, not alter stream state
i2 = ctraits_type::length(array1);
state2 = is_01.rdstate();
test &= i1 == i2;
test &= state1 != state2;
test &= static_cast<bool>(state2 & statefail);
VERIFY( i1 == i2 );
VERIFY( state1 != state2 );
VERIFY( static_cast<bool>(state2 & statefail) );
state1 = is_02.rdstate();
is_02 >> array1; // should snake "coltrane"
state2 = is_02.rdstate();
test &= state1 == state2;
test &= !static_cast<bool>(state2 & statefail);
test &= array1[str_03.size() - 1] == 'e';
VERIFY( state1 == state2 );
VERIFY( !static_cast<bool>(state2 & statefail) );
VERIFY( array1[str_03.size() - 1] == 'e' );
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 ' '
test &= int1 == ' ';
VERIFY( int1 == ' ' );
state1 = is_02.rdstate();
is_02 >> array1; // should snake "playing" as sentry "eats" ws
state2 = is_02.rdstate();
int1 = is_02.peek(); // should be ' '
test &= int1 == ' ';
test &= state1 == state2;
test &= !static_cast<bool>(state2 & statefail);
VERIFY( int1 == ' ' );
VERIFY( state1 == state2 );
VERIFY( !static_cast<bool>(state2 & statefail) );
// template<_CharT, _Traits>
......@@ -83,13 +81,13 @@ bool test01() {
state1 = is_02.rdstate();
is_02 >> array2; // should snake 'softly
state2 = is_02.rdstate();
test &= state1 == state2;
test &= !static_cast<bool>(state2 & statefail);
test &= array2[0] == '\'';
test &= array2[1] == 's';
test &= array2[6] == 'y';
VERIFY( state1 == state2 );
VERIFY( !static_cast<bool>(state2 & statefail) );
VERIFY( array2[0] == '\'' );
VERIFY( array2[1] == 's' );
VERIFY( array2[6] == 'y' );
int1 = is_02.peek(); // should be ' '
test &= int1 == ' ';
VERIFY( int1 == ' ' );
// template<_CharT, _Traits>
......@@ -98,12 +96,12 @@ bool test01() {
state1 = is_02.rdstate();
is_02 >> array3; // should snake "as"
state2 = is_02.rdstate();
test &= state1 == state2;
test &= !static_cast<bool>(state2 & statefail);
test &= array3[0] == 'a';
test &= array3[1] == 's';
VERIFY( state1 == state2 );
VERIFY( !static_cast<bool>(state2 & statefail) );
VERIFY( array3[0] == 'a' );
VERIFY( array3[1] == 's' );
int1 = is_02.peek(); // should be ' '
test &= int1 == ' ';
VERIFY( int1 == ' ' );
// testing with width() control enabled.
......@@ -111,25 +109,25 @@ bool test01() {
state1 = is_02.rdstate();
is_02 >> array1; // should snake a
state2 = is_02.rdstate();
test &= state1 == state2;
test &= !ctraits_type::compare(array1, "a", 2);
VERIFY( state1 == state2 );
VERIFY( !ctraits_type::compare(array1, "a", 2) );
is_02.width(1);
state1 = is_02.rdstate();
is_02 >> array1; // should snake nothing, set failbit
state2 = is_02.rdstate();
test &= state1 != state2;
test &= state2 == statefail;
test &= array1[0] == '\0';
VERIFY( state1 != state2 );
VERIFY( state2 == statefail );
VERIFY( array1[0] == '\0' );
is_02.width(8);
is_02.clear();
state1 = is_02.rdstate();
test &= !state1;
VERIFY( !state1 );
is_02 >> array1; // should snake "morning"
state2 = is_02.rdstate();
test &= state1 == state2;
test &= !ctraits_type::compare(array1, "morning", 8);
VERIFY( state1 == state2 );
VERIFY( !ctraits_type::compare(array1, "morning", 8) );
// testing for correct exception setting
const std::string str_04(" impulse!!");
......@@ -139,13 +137,13 @@ bool test01() {
std::istream is_04(&isbuf_04);
is_03 >> array1;
test &= !ctraits_type::compare(array1,"impulse!!", 10);
test &= is_03.rdstate() == std::ios_base::eofbit;
VERIFY( !ctraits_type::compare(array1,"impulse!!", 10) );
VERIFY( is_03.rdstate() == std::ios_base::eofbit );
is_04.width(9);
is_04 >> array1;
test &= ! std::ios::traits_type::compare(array1,"impulse!", 9);
test &= !is_04.rdstate();
VERIFY( ! std::ios::traits_type::compare(array1,"impulse!", 9) );
VERIFY( !is_04.rdstate() );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -176,19 +174,19 @@ bool test02() {
state1 = is_01.rdstate();
is_01 >> c1;
state2 = is_01.rdstate();
test &= state1 != state2;
test &= c1 == c2;
test &= static_cast<bool>(state2 & statefail);
VERIFY( state1 != state2 );
VERIFY( c1 == c2 );
VERIFY( static_cast<bool>(state2 & statefail) );
state1 = is_02.rdstate();
is_02 >> c1;
state2 = is_02.rdstate();
test &= state1 == state2;
test &= c1 == 'o';
VERIFY( state1 == state2 );
VERIFY( c1 == 'o' );
is_02 >> c1;
is_02 >> c1;
test &= c1 == 'c';
test &= !static_cast<bool>(state2 & statefail);
VERIFY( c1 == 'c' );
VERIFY( !static_cast<bool>(state2 & statefail) );
// template<_CharT, _Traits>
// basic_istream& operator>>(istream&, unsigned char&)
......@@ -196,11 +194,11 @@ bool test02() {
state1 = is_02.rdstate();
is_02 >> uc1;
state2 = is_02.rdstate();
test &= state1 == state2;
test &= uc1 == 'o';
VERIFY( state1 == state2 );
VERIFY( uc1 == 'o' );
is_02 >> uc1;
is_02 >> uc1;
test &= uc1 == 't';
VERIFY( uc1 == 't' );
// template<_CharT, _Traits>
// basic_istream& operator>>(istream&, signed char&)
......@@ -208,11 +206,11 @@ bool test02() {
state1 = is_02.rdstate();
is_02 >> sc1;
state2 = is_02.rdstate();
test &= state1 == state2;
test &= sc1 == 'r';
VERIFY( state1 == state2 );
VERIFY( sc1 == 'r' );
is_02 >> sc1;
is_02 >> sc1;
test &= sc1 == 'n';
VERIFY( sc1 == 'n' );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -23,9 +23,7 @@
#include <istream>
#include <sstream>
#include <fstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
// stringbufs.
......@@ -71,78 +69,78 @@ bool test01() {
state1 = is_00.rdstate();
is_00 >> &isbuf_00;
state2 = is_00.rdstate();
test &= state1 != state2;
test &= static_cast<bool>(state2 & statefail);
test &= isbuf_00.str() == str_01;
VERIFY( state1 != state2 );
VERIFY( static_cast<bool>(state2 & statefail) );
VERIFY( isbuf_00.str() == str_01 );
// null istream to empty in_out_buf
is_00.clear(std::ios_base::goodbit);
state1 = is_00.rdstate();
is_00 >> &isbuf_01;
state2 = is_00.rdstate();
test &= state1 != state2;
test &= static_cast<bool>(state2 & statefail);
test &= isbuf_01.str() == str_01;
VERIFY( state1 != state2 );
VERIFY( static_cast<bool>(state2 & statefail) );
VERIFY( isbuf_01.str() == str_01 );
// null istream to full in_buf
is_00.clear(std::ios_base::goodbit);
state1 = is_00.rdstate();
is_00 >> &isbuf_04;
state2 = is_00.rdstate();
test &= state1 != state2;
test &= static_cast<bool>(state2 & statefail);
test &= isbuf_04.str() == str_02;
VERIFY( state1 != state2 );
VERIFY( static_cast<bool>(state2 & statefail) );
VERIFY( isbuf_04.str() == str_02 );
// null istream to full in_out_buf
is_00.clear(std::ios_base::goodbit);
state1 = is_00.rdstate();
is_00 >> &isbuf_05;
state2 = is_00.rdstate();
test &= state1 != state2;
test &= static_cast<bool>(state2 & statefail);
test &= isbuf_05.str() == str_02;
VERIFY( state1 != state2 );
VERIFY( static_cast<bool>(state2 & statefail) );
VERIFY( isbuf_05.str() == str_02 );
// empty but non-null istream to full in_buf
state1 = is_02.rdstate();
is_02 >> &isbuf_04;
state2 = is_02.rdstate();
test &= state1 != state2;
test &= static_cast<bool>(state2 & statefail);
test &= isbuf_04.str() == str_02; // as only an "in" buffer
test &= isbuf_04.sgetc() == 'a';
VERIFY( state1 != state2 );
VERIFY( static_cast<bool>(state2 & statefail) );
VERIFY( isbuf_04.str() == str_02 ); // as only an "in" buffer
VERIFY( isbuf_04.sgetc() == 'a' );
// empty but non-null istream to full in_out_buf
is_02.clear(std::ios_base::goodbit);
state1 = is_02.rdstate();
is_02 >> &isbuf_05;
state2 = is_02.rdstate();
test &= state1 != state2;
test &= static_cast<bool>(state2 & statefail);
test &= isbuf_05.str() == str_02; // as only an "in" buffer
test &= isbuf_05.sgetc() == 'a';
VERIFY( state1 != state2 );
VERIFY( static_cast<bool>(state2 & statefail) );
VERIFY( isbuf_05.str() == str_02 ); // as only an "in" buffer
VERIFY( isbuf_05.sgetc() == 'a' );
// full istream to empty in_buf (need out_buf, you know?)
state1 = is_04.rdstate();
is_04 >> &isbuf_02;
state2 = is_04.rdstate();
test &= state1 != state2;
test &= static_cast<bool>(state2 & statefail);
test &= isbuf_02.str() == str_01; // as only an "in" buffer
test &= isbuf_02.sgetc() == ctraits_type::eof();
test &= is_04.peek() == ctraits_type::eof(); // as failed
VERIFY( state1 != state2 );
VERIFY( static_cast<bool>(state2 & statefail) );
VERIFY( isbuf_02.str() == str_01 ); // as only an "in" buffer
VERIFY( isbuf_02.sgetc() == ctraits_type::eof() );
VERIFY( is_04.peek() == ctraits_type::eof() ); // as failed
// full istream to empty in_out_buf
is_04.clear(std::ios_base::goodbit);
state1 = is_04.rdstate();
is_04 >> &isbuf_03;
state2 = is_04.rdstate();
test &= state1 != state2;
test &= !static_cast<bool>(state2 & statefail);
test &= state2 == stateeof;
VERIFY( state1 != state2 );
VERIFY( !static_cast<bool>(state2 & statefail) );
VERIFY( state2 == stateeof );
strtmp = isbuf_03.str();
test &= strtmp == str_02; // as only an "in" buffer
test &= isbuf_03.sgetc() == 'a';
test &= is_04.peek() == ctraits_type::eof();
VERIFY( strtmp == str_02 ); // as only an "in" buffer
VERIFY( isbuf_03.sgetc() == 'a' );
VERIFY( is_04.peek() == ctraits_type::eof() );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -162,8 +160,8 @@ bool test02() {
std::filebuf fbin, fbout;
fbin.open(name_01, std::ios_base::in);
fbout.open(name_02, std::ios_base::out | std::ios_base::trunc);
test &= fbin.is_open();
test &= fbout.is_open();
VERIFY( fbin.is_open() );
VERIFY( fbout.is_open() );
if (test)
{
......@@ -174,8 +172,8 @@ bool test02() {
fbout.close();
fbin.close();
test &= !fbin.is_open();
test &= !fbout.is_open();
VERIFY( !fbin.is_open() );
VERIFY( !fbout.is_open() );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -23,9 +23,7 @@
#include <istream>
#include <sstream>
#include <stdexcept>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01(void)
{
......@@ -44,36 +42,36 @@ bool test01(void)
std::istringstream iss02(str01);
iss01 >> str04;
test &= str04.size() != str01.size();
test &= str04 == "santa";
VERIFY( str04.size() != str01.size() );
VERIFY( str04 == "santa" );
iss02 >> std::ws;
iss02 >> str05;
test &= str05.size() != str01.size();
test &= str05 == "santa";
test &= str05 == str04;
VERIFY( str05.size() != str01.size() );
VERIFY( str05 == "santa" );
VERIFY( str05 == str04 );
iss01 >> str04;
test &= str04.size() != str01.size();
test &= str04 == "barbara";
VERIFY( str04.size() != str01.size() );
VERIFY( str04 == "barbara" );
iss02 >> std::ws;
iss02 >> str05;
test &= str05.size() != str01.size();
test &= str05 == "barbara";
test &= str05 == str04;
VERIFY( str05.size() != str01.size() );
VERIFY( str05 == "barbara" );
VERIFY( str05 == str04 );
flag3 = std::ios_base::eofbit;
flag4 = std::ios_base::badbit;
flag5 = std::ios_base::failbit;
test &= !iss01.fail();
test &= !iss02.fail();
test &= !iss01.eof();
test &= !iss02.eof();
VERIFY( !iss01.fail() );
VERIFY( !iss02.fail() );
VERIFY( !iss01.eof() );
VERIFY( !iss02.eof() );
iss01 >> std::ws;
test &= !iss01.fail();
test &= iss01.eof();
VERIFY( !iss01.fail() );
VERIFY( iss01.eof() );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -24,9 +24,7 @@
#include <istream>
#include <sstream>
#include <fstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
bool test01()
......@@ -45,7 +43,7 @@ bool test01()
ifstream ifs1;
pos_type p4 = ifs1.tellg();
test &= p3 == p4;
VERIFY( p3 == p4 );
// in
// test ctors leave things in the same positions...
......@@ -55,7 +53,7 @@ bool test01()
ifstream ifs2(str_lit01);
p4 = ifs2.tellg();
test &= p3 == p4;
VERIFY( p3 == p4 );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -75,9 +73,9 @@ void test04(void)
std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out);
std::ifstream if02(str_lit01, std::ios_base::in);
std::ifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc);
test &= if01.good();
test &= if02.good();
test &= if03.good();
VERIFY( if01.good() );
VERIFY( if02.good() );
VERIFY( if03.good() );
std::istream is01(if01.rdbuf());
std::istream is02(if02.rdbuf());
......@@ -87,20 +85,20 @@ void test04(void)
// in | out
pos01 = is01.tellg();
pos02 = is01.tellg();
test &= pos01 == pos02;
// test &= istream::pos_type(0) != pos01; //depricated
VERIFY( pos01 == pos02 );
// VERIFY( istream::pos_type(0) != pos01 ); //depricated
// in
pos03 = is02.tellg();
pos04 = is02.tellg();
test &= pos03 == pos04;
// test &= istream::pos_type(0) != pos03; //depricated
VERIFY( pos03 == pos04 );
// VERIFY( istream::pos_type(0) != pos03 ); //depricated
// out
pos05 = is03.tellg();
pos06 = is03.tellg();
test &= pos05 == pos06;
// test &= istream::pos_type(0) != pos01; //depricated
VERIFY( pos05 == pos06 );
// VERIFY( istream::pos_type(0) != pos01 ); //depricated
// istream& seekg(pos_type)
// istream& seekg(off_type, ios_base::seekdir)
......@@ -114,56 +112,56 @@ void test04(void)
is01.seekg(10, std::ios_base::cur);
state02 = is01.rdstate();
pos01 = is01.tellg();
test &= pos01 == pos02 + 10;
test &= state01 == state02;
VERIFY( pos01 == pos02 + 10 );
VERIFY( state01 == state02 );
pos02 = is01.tellg();
test &= pos02 == pos01;
VERIFY( pos02 == pos01 );
state01 = is02.rdstate();
is02.seekg(10, std::ios_base::cur);
state02 = is02.rdstate();
pos03 = is02.tellg();
test &= pos03 == pos04 + 10;
test &= state01 == state02;
VERIFY( pos03 == pos04 + 10 );
VERIFY( state01 == state02 );
pos04 = is02.tellg();
test &= pos03 == pos04;
VERIFY( pos03 == pos04 );
state01 = is03.rdstate();
is03.seekg(10, std::ios_base::cur);
state02 = is03.rdstate();
pos05 = is03.tellg();
test &= pos05 == pos06 + 10;
test &= state01 == state02;
VERIFY( pos05 == pos06 + 10 );
VERIFY( state01 == state02 );
pos06 = is03.tellg();
test &= pos05 == pos06;
VERIFY( pos05 == pos06 );
// beg
state01 = is01.rdstate();
is01.seekg(20, std::ios_base::beg);
state02 = is01.rdstate();
pos01 = is01.tellg();
test &= pos01 == pos02 + 10;
test &= state01 == state02;
VERIFY( pos01 == pos02 + 10 );
VERIFY( state01 == state02 );
pos02 = is01.tellg();
test &= pos02 == pos01;
VERIFY( pos02 == pos01 );
state01 = is02.rdstate();
is02.seekg(20, std::ios_base::beg);
state02 = is02.rdstate();
pos03 = is02.tellg();
test &= pos03 == pos04 + 10;
test &= state01 == state02;
VERIFY( pos03 == pos04 + 10 );
VERIFY( state01 == state02 );
pos04 = is02.tellg();
test &= pos03 == pos04;
VERIFY( pos03 == pos04 );
state01 = is03.rdstate();
is03.seekg(20, std::ios_base::beg);
state02 = is03.rdstate();
pos05 = is03.tellg();
test &= pos05 == pos06 + 10;
test &= state01 == state02;
VERIFY( pos05 == pos06 + 10 );
VERIFY( state01 == state02 );
pos06 = is03.tellg();
test &= pos05 == pos06;
VERIFY( pos05 == pos06 );
#ifdef DEBUG_ASSERT
assert(test);
......@@ -180,9 +178,9 @@ void test05(void)
std::ifstream if01(str_lit01);
std::ifstream if02(str_lit01);
std::ifstream if03(str_lit01);
test &= if01.good();
test &= if02.good();
test &= if03.good();
VERIFY( if01.good() );
VERIFY( if02.good() );
VERIFY( if03.good() );
std::stringbuf strbuf01(std::ios_base::in | std::ios_base::out);
if01 >> &strbuf01;
......@@ -199,20 +197,20 @@ void test05(void)
// in | out
pos01 = is01.tellg();
pos02 = is01.tellg();
test &= pos01 == pos02;
// test &= istream::pos_type(0) != pos01; // deprecated
VERIFY( pos01 == pos02 );
// VERIFY( istream::pos_type(0) != pos01 ); // deprecated
// in
pos03 = is02.tellg();
pos04 = is02.tellg();
test &= pos03 == pos04;
// test &= istream::pos_type(0) != pos03; // deprecated
VERIFY( pos03 == pos04 );
// VERIFY( istream::pos_type(0) != pos03 ); // deprecated
// out
pos05 = is03.tellg();
pos06 = is03.tellg();
test &= pos05 == pos06;
// test &= istream::pos_type(0) != pos01; //deprecated
VERIFY( pos05 == pos06 );
// VERIFY( istream::pos_type(0) != pos01 ); //deprecated
// istream& seekg(pos_type)
// istream& seekg(off_type, ios_base::seekdir)
......@@ -226,56 +224,56 @@ void test05(void)
is01.seekg(10, std::ios_base::cur);
state02 = is01.rdstate();
pos01 = is01.tellg();
test &= pos01 == pos02 + 10;
test &= state01 == state02;
VERIFY( pos01 == pos02 + 10 );
VERIFY( state01 == state02 );
pos02 = is01.tellg();
test &= pos02 == pos01;
VERIFY( pos02 == pos01 );
state01 = is02.rdstate();
is02.seekg(10, std::ios_base::cur);
state02 = is02.rdstate();
pos03 = is02.tellg();
test &= pos03 == pos04 + 10;
test &= state01 == state02;
VERIFY( pos03 == pos04 + 10 );
VERIFY( state01 == state02 );
pos04 = is02.tellg();
test &= pos03 == pos04;
VERIFY( pos03 == pos04 );
state01 = is03.rdstate();
is03.seekg(10, std::ios_base::cur);
state02 = is03.rdstate();
pos05 = is03.tellg();
test &= pos05 == pos06; // as only out buffer
test &= state01 == state02;
VERIFY( pos05 == pos06 ); // as only out buffer
VERIFY( state01 == state02 );
pos06 = is03.tellg();
test &= pos05 == pos06;
VERIFY( pos05 == pos06 );
// beg
state01 = is01.rdstate();
is01.seekg(20, std::ios_base::beg);
state02 = is01.rdstate();
pos01 = is01.tellg();
test &= pos01 == pos02 + 10;
test &= state01 == state02;
VERIFY( pos01 == pos02 + 10 );
VERIFY( state01 == state02 );
pos02 = is01.tellg();
test &= pos02 == pos01;
VERIFY( pos02 == pos01 );
state01 = is02.rdstate();
is02.seekg(20, std::ios_base::beg);
state02 = is02.rdstate();
pos03 = is02.tellg();
test &= pos03 == pos04 + 10;
test &= state01 == state02;
VERIFY( pos03 == pos04 + 10 );
VERIFY( state01 == state02 );
pos04 = is02.tellg();
test &= pos03 == pos04;
VERIFY( pos03 == pos04 );
state01 = is03.rdstate();
is03.seekg(20, std::ios_base::beg);
state02 = is03.rdstate();
pos05 = is03.tellg();
test &= pos05 == pos06; // as only out buffer
test &= state01 == state02;
VERIFY( pos05 == pos06 ); // as only out buffer
VERIFY( state01 == state02 );
pos06 = is03.tellg();
test &= pos05 == pos06;
VERIFY( pos05 == pos06 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -31,9 +31,7 @@
#include <istream>
#include <sstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
void test01()
{
......@@ -48,17 +46,17 @@ void test01()
// test negatives
std::istream::sentry sentry01(istr01);
test &= bool(sentry01) == false;
VERIFY( bool(sentry01) == false );
std::istream::sentry sentry02(istr01, true);
test &= bool(sentry02) == false;
VERIFY( bool(sentry02) == false );
// positive tests
std::istream::sentry sentry03(istr02);
test &= bool(sentry03) == true;
VERIFY( bool(sentry03) == true );
std::istream::sentry sentry04(istr02, true);
test &= bool(sentry04) == true;
VERIFY( bool(sentry04) == true );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -24,9 +24,7 @@
// stringbuf* rdbuf() const
#include <sstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
void test01()
......@@ -47,30 +45,30 @@ void test01()
state1 = is01.rdstate();
is01 >> a;
state2 = is01.rdstate();
test &= a = i01;
VERIFY( a = i01 );
// 22.2.2.1.2 num_get virtual functions
// p 13
// in any case, if stage 2 processing was terminated by the test for
// in == end then err != ios_base::eofbit is performed.
test &= state1 != state2;
test &= state2 == stateeof;
VERIFY( state1 != state2 );
VERIFY( state2 == stateeof );
is01.str(str01);
is01 >> b;
test &= b != a;
VERIFY( b != a );
// as is01.good() is false, istream::sentry blocks extraction.
is01.clear();
state1 = is01.rdstate();
is01 >> b;
state2 = is01.rdstate();
test &= b == a;
test &= state1 != state2;
test &= state2 == stateeof;
VERIFY( b == a );
VERIFY( state1 != state2 );
VERIFY( state2 == stateeof );
// string str() const
str02 = is01.str();
test &= str01 == str02;
VERIFY( str01 == str02 );
#ifdef DEBUG_ASSERT
assert(test);
......
......@@ -66,13 +66,15 @@
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <debug_assert.h>
// Include iostream last, just to make is as difficult as possible to
// properly initialize the standard iostream objects.
#include <iostream>
// Make sure all the standard streams are defined.
bool test01()
int
test01()
{
bool test = true;
......@@ -83,17 +85,19 @@ bool test01()
array1[i] = '\0';
std::cout << "testing cout" << 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::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();
return 0;
}
......@@ -20,9 +20,7 @@
#include <ostream>
#include <fstream>
#ifdef DEBUG_ASSERT
#include <assert.h>
#endif
#include <debug_assert.h>
const char name_01[] = "testsuite/ofstream_members-1.tst";
const char name_02[] = "testsuite/ofstream_members-1.txt";
......@@ -35,15 +33,15 @@ bool test00()
ofs1.close();
// false as expected:
test &= !ofs1.is_open();
VERIFY( !ofs1.is_open() );
// this is now true:
test &= !(ofs1);
VERIFY( !(ofs1) );
ofs1.open(name_02);
test &= ofs1.is_open();
VERIFY( ofs1.is_open() );
// fail bit still true
test &= !(ofs1);
test &= ofs1.rdstate() == std::ios_base::failbit;
VERIFY( !(ofs1) );
VERIFY( ofs1.rdstate() == std::ios_base::failbit );
ofs1.close();
......@@ -64,7 +62,7 @@ bool test01()
for(int i = 0; ++i < more_than_max_open_files;)
{
std::ofstream ifs(name_02);
test &= static_cast<bool>(ifs);
VERIFY( static_cast<bool>(ifs) );
}
#ifdef DEBUG_ASSERT
......
......@@ -24,7 +24,7 @@
#include <locale>
#include <sstream>
#include <limits>
#include <assert.h>
#include <debug_assert.h>
using namespace std;
......@@ -187,8 +187,10 @@ void apply_formatting(const _TestCase & tc, basic_ostream<_CharT> & os)
os.setf(ios::right);
}
void test01()
int
test01()
{
bool test = true;
for (int j=0; j<sizeof(testcases)/sizeof(testcases[0]); j++)
{
_TestCase & tc = testcases[j];
......@@ -206,7 +208,7 @@ void test01()
#ifdef TEST_NUMPUT_VERBOSE
cout << "result: " << os.str() << endl;
#endif
assert(os && os.str() == tc.result);
VERIFY( os && os.str() == tc.result );
}
// test long double with char type
{
......@@ -219,7 +221,7 @@ void test01()
#ifdef TEST_NUMPUT_VERBOSE
cout << "result: " << os.str() << endl;
#endif
assert(os && os.str() == tc.result);
VERIFY( os && os.str() == tc.result );
}
#if _GLIBCPP_USE_WCHAR_T
// test double with wchar_t type
......@@ -230,7 +232,7 @@ void test01()
os.imbue(__loc);
apply_formatting(tc, os);
os << tc.val;
assert(os && os.str() == tc.wresult);
VERIFY( os && os.str() == tc.wresult );
}
// test long double with wchar_t type
{
......@@ -240,14 +242,18 @@ void test01()
os.imbue(__loc);
apply_formatting(tc, os);
os << (long double)tc.val;
assert(os && os.str() == tc.wresult);
VERIFY( os && os.str() == tc.wresult );
}
#endif
}
return 0;
}
void test02()
int
test02()
{
bool test = true;
// make sure we can output a very long float
long double val = 1.2345678901234567890123456789e+1000L;
int prec = numeric_limits<long double>::digits10;
......@@ -263,10 +269,13 @@ void test02()
cout << "expect: " << largebuf << endl;
cout << "result: " << os.str() << endl;
#endif
assert(os && os.str() == largebuf);
VERIFY(os && os.str() == largebuf);
return 0;
}
void test03()
int
test03()
{
short s = -1;
int i = -1;
......@@ -279,24 +288,27 @@ void test03()
ostream o(&strbuf);
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);
o << oct << i << ' ' << hex << i;
test &= strbuf.str() == "37777777777 ffffffff";
VERIFY( strbuf.str() == "37777777777 ffffffff" );
strbuf.str(str_blank);
o << oct << l << ' ' << hex << l;
test &= strbuf.str() == "37777777777 ffffffff";
VERIFY( strbuf.str() == "37777777777 ffffffff" );
strbuf.str(str_blank);
o << showpos << hex << showbase << 11;
test &= strbuf.str() == "0xb";
VERIFY( strbuf.str() == "0xb" );
assert(test);
VERIFY(test);
return 0;
}
int main()
int
main()
{
test01();
test02();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment