|
From: Daryle L. W. <dlw...@us...> - 2005-12-14 09:10:12
|
Update of /cvsroot/boost-sandbox/boost-sandbox/libs/io/test/cstdio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16450/boost-sandbox/libs/io/test/cstdio Added Files: cstdio_test.cpp simple_input_test.cpp simple_output_test.cpp string_input_test.cpp string_output_test.cpp Log Message: Added library that reimagines <cstdio> through C++ --- NEW FILE: simple_output_test.cpp --- // Boost cstdio_simple_output_test.cpp test file ---------------------------// // Copyright 2005 Daryle Walker. Use, modification, and distribution are // subject to the Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) // See <http://www.boost.org/libs/io/> for the library's home page. // Revision History // 13 Dec 2005 Initial version (Daryle Walker) #include <boost/io/cstdio/simple_output.hpp> // for iputc, iputs #include <boost/test/auto_unit_test.hpp> // for BOOST_AUTO_UNIT_TEST, etc. #include <sstream> // for std::ostringstream #include <string> // for std::string #include <strstream> // for std::ostrstream BOOST_AUTO_TEST_SUITE( simple_output_tests ); // Simple character output that successfully writes BOOST_AUTO_TEST_CASE( iputc_pass_test ) { std::ostringstream oss; char const sample = 'x'; BOOST_CHECK( boost::io::cstdio::iputc(sample, oss) ); BOOST_CHECK( oss ); BOOST_CHECK_EQUAL( oss.str(), std::string(1u, sample) ); } // Simple character output that fails to write BOOST_AUTO_TEST_CASE( iputc_fail_test ) { char const sample = 'x'; char buffer[ 1 ]; std::ostrstream oss( buffer, sizeof(buffer) ); oss.freeze(); // prevent re-allocations oss.put( '\0' ); // exhaust the only element available BOOST_CHECK( not boost::io::cstdio::iputc(sample, oss) ); BOOST_CHECK( not oss ); } // Simple C-string output that successfully writes BOOST_AUTO_TEST_CASE( iputs_pass_test ) { std::ostringstream oss; char const sample[] = "Hello world"; BOOST_CHECK( boost::io::cstdio::iputs(sample, oss) ); BOOST_CHECK( oss ); BOOST_CHECK_EQUAL( oss.str(), sample ); } // Simple C-string output that fails to write BOOST_AUTO_TEST_CASE( iputs_fail_test ) { char const sample[] = "Hello world"; char buffer[ sizeof(sample) / 2u ]; std::ostrstream oss( buffer, sizeof(buffer) ); oss.freeze(); // prevent re-allocations BOOST_CHECK( not boost::io::cstdio::iputs(sample, oss) ); BOOST_CHECK( not oss ); } BOOST_AUTO_TEST_SUITE_END(); --- NEW FILE: cstdio_test.cpp --- // Boost cstdio_test.cpp test file -----------------------------------------// // Copyright 2005 Daryle Walker. Use, modification, and distribution are // subject to the Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) // See <http://www.boost.org/libs/io/> for the library's home page. // Revision History // 12 Dec 2005 Initial version (Daryle Walker) #define BOOST_AUTO_TEST_MAIN "cstdio extensions test" #include <boost/io/cstdio.hpp> // for ??? #include <boost/test/auto_unit_test.hpp> // for BOOST_AUTO_UNIT_TEST, etc. // Put other Boost headers here // Put Standard headers here // Types // e.g. using boost::my_new_type; // e.g. typedef long_and_complicated easy; // Testing preparations // e.g. BOOST_TEST_DONT_PRINT_LOG_VALUE( some_unprintable_type ); // Describe what classes (and thier members) I'm testing here BOOST_AUTO_TEST_CASE( my_first_test ) { } --- NEW FILE: string_input_test.cpp --- // Boost string_input_test.cpp test file -----------------------------------// // Copyright 2005 Daryle Walker. Use, modification, and distribution are // subject to the Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) // See <http://www.boost.org/libs/io/> for the library's home page. // Revision History // 13 Dec 2005 Initial version (Daryle Walker) #include <boost/io/cstdio/string_input.hpp> // for igets #include <boost/test/auto_unit_test.hpp> // for BOOST_AUTO_UNIT_TEST, etc. #include <sstream> // for std::istringstream #include <string> // for std::string BOOST_AUTO_TEST_SUITE( string_input_tests ); // C++-string input that successfully reads BOOST_AUTO_TEST_CASE( cpp_igets_pass_test ) { using boost::io::cstdio::igets; std::string temp( "Hello There,\nWorld" ); std::istringstream iss( temp ); BOOST_CHECK( igets(temp, iss) ); BOOST_CHECK_EQUAL( temp, "Hello There," ); BOOST_CHECK( igets(temp, iss) ); BOOST_CHECK_EQUAL( temp, "World" ); BOOST_CHECK( iss.eof() ); } // C++-string input that fails to read BOOST_AUTO_TEST_CASE( cpp_igets_fail_test ) { std::string temp( "" ); std::istringstream iss( temp ); BOOST_CHECK( (iss.get(), iss.fail()) ); // start off in a bad state BOOST_CHECK( not boost::io::cstdio::igets(temp, iss) ); } BOOST_AUTO_TEST_SUITE_END(); --- NEW FILE: simple_input_test.cpp --- // Boost cstdio_simple_input_test.cpp test file ----------------------------// // Copyright 2005 Daryle Walker. Use, modification, and distribution are // subject to the Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) // See <http://www.boost.org/libs/io/> for the library's home page. // Revision History // 13 Dec 2005 Initial version (Daryle Walker) #include <boost/io/cstdio/simple_input.hpp> // for igetc, iungetc, igets #include <boost/test/auto_unit_test.hpp> // for BOOST_AUTO_UNIT_TEST, etc. #include <cstring> // for std::strcmp #include <sstream> // for std::istringstream, std::stringstream #include <string> // for std::char_traits, std::string #include <strstream> // for std::istrstream typedef std::char_traits<char> traits_t; BOOST_AUTO_TEST_SUITE( simple_input_tests ); // Simple character input that successfully reads BOOST_AUTO_TEST_CASE( igetc_pass_test ) { char const sample = 'x'; std::istringstream iss( std::string(1u, sample) ); BOOST_CHECK( traits_t::eq_int_type(boost::io::cstdio::igetc( iss ), traits_t::to_int_type( sample )) ); } // Simple character input that fails to read BOOST_AUTO_TEST_CASE( igetc_fail_test ) { std::istringstream iss( std::string("") ); BOOST_CHECK( traits_t::eq_int_type(boost::io::cstdio::igetc( iss ), traits_t::eof()) ); BOOST_CHECK( iss.eof() ); } // Simple character put-back that successfully pushes BOOST_AUTO_TEST_CASE( iungetc_pass_test ) { char const sample1 = 'x', sample2 = 'y'; std::stringstream ss( std::string(1u, sample1) ); BOOST_CHECK( traits_t::eq_int_type(traits_t::to_int_type( sample1 ), ss.get()) ); BOOST_CHECK( boost::io::cstdio::iungetc(sample2, ss) ); BOOST_CHECK( traits_t::eq_int_type(traits_t::to_int_type( sample2 ), ss.peek()) ); } // Simple character put-back that fails to push BOOST_AUTO_TEST_CASE( iungetc_fail_test ) { std::istrstream iss( "Hello world" ); BOOST_CHECK( traits_t::eq_int_type(traits_t::to_int_type( 'H' ), iss.get()) ); //iss.freeze(); BOOST_CHECK( not boost::io::cstdio::iungetc('i', iss) ); BOOST_CHECK( not iss ); } // Simple C-string input that successfully reads BOOST_AUTO_TEST_CASE( igets_pass_test ) { using boost::io::cstdio::igets; using std::strcmp; char temp[] = "00000000000000000000000000"; std::istringstream iss( std::string("Hello there,\nWorld") ); BOOST_CHECK( igets(temp, 3, iss) ); BOOST_CHECK_EQUAL( 0, strcmp(temp, "He") ); BOOST_CHECK( igets(temp, 13, iss) ); BOOST_CHECK( 0 != strcmp(temp, "llo there,\nW") ); BOOST_CHECK_EQUAL( 0, strcmp(temp, "llo there,\n") ); BOOST_CHECK( igets(temp, sizeof(temp), iss) ); BOOST_CHECK_EQUAL( 0, strcmp(temp, "World") ); BOOST_CHECK( iss.eof() ); } // Simple C-string input that fails to read BOOST_AUTO_TEST_CASE( igets_fail_test ) { char temp[ 10 ]; std::istringstream iss( std::string("") ); BOOST_CHECK( (iss.get(), iss.fail()) ); // start off in a bad state BOOST_CHECK( not boost::io::cstdio::igets(temp, sizeof(temp), iss) ); } BOOST_AUTO_TEST_SUITE_END(); --- NEW FILE: string_output_test.cpp --- // Boost string_output_test.cpp test file ----------------------------------// // Copyright 2005 Daryle Walker. Use, modification, and distribution are // subject to the Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) // See <http://www.boost.org/libs/io/> for the library's home page. // Revision History // 13 Dec 2005 Initial version (Daryle Walker) #include <boost/io/cstdio/string_output.hpp> // for iputs #include <boost/test/auto_unit_test.hpp> // for BOOST_AUTO_UNIT_TEST, etc. #include <sstream> // for std::ostringstream #include <string> // for std::string #include <strstream> // for std::ostrstream BOOST_AUTO_TEST_SUITE( string_output_tests ); // C++-string output that successfully writes BOOST_AUTO_TEST_CASE( cpp_iputs_pass_test ) { std::ostringstream oss; std::string const sample( "Hello world" ); BOOST_CHECK( boost::io::cstdio::iputs(sample, oss) ); BOOST_CHECK( oss ); BOOST_CHECK_EQUAL( oss.str(), sample ); } // C++-string output that fails to write BOOST_AUTO_TEST_CASE( cpp_iputs_fail_test ) { char const sample_base[] = "Hello world"; std::string const sample( sample_base ); char buffer[ sizeof(sample_base) / 2u ]; std::ostrstream oss( buffer, sizeof(buffer) ); oss.freeze(); BOOST_CHECK( not boost::io::cstdio::iputs(sample, oss) ); BOOST_CHECK( not oss ); } BOOST_AUTO_TEST_SUITE_END(); |