|
Boost-Commit : |
From: jefffaust_at_[hidden]
Date: 2007-05-24 20:56:35
Author: jefffaust
Date: 2007-05-24 20:56:34 EDT (Thu, 24 May 2007)
New Revision: 4232
URL: http://svn.boost.org/trac/boost/changeset/4232
Log:
Add user-defined test.
Added:
sandbox/explore/libs/explore/test/user_defined_container.cpp
- copied, changed from r4230, /sandbox/explore/libs/explore/test/std_vector.cpp
Text files modified:
sandbox/explore/libs/explore/test/Jamfile.v2 | 5
sandbox/explore/libs/explore/test/user_defined_container.cpp | 135 ++++++++-------------------------------
2 files changed, 33 insertions(+), 107 deletions(-)
Modified: sandbox/explore/libs/explore/test/Jamfile.v2
==============================================================================
--- sandbox/explore/libs/explore/test/Jamfile.v2 (original)
+++ sandbox/explore/libs/explore/test/Jamfile.v2 2007-05-24 20:56:34 EDT (Thu, 24 May 2007)
@@ -21,6 +21,7 @@
:
[ run simple_types.cpp ]
[ run c_array.cpp ]
+ [ run user_defined_container.cpp ]
[ run std_vector.cpp ]
[ run std_deque.cpp ]
@@ -33,7 +34,7 @@
[ run boost_tuple.cpp ]
[ run boost_variant.cpp ]
- // conflicts with stream operator already defined for iterator_range
- //[ run boost_range.cpp ]
+ # conflicts with stream operator already defined for iterator_range
+ #[ run boost_range.cpp ]
;
}
Copied: sandbox/explore/libs/explore/test/user_defined_container.cpp (from r4230, /sandbox/explore/libs/explore/test/std_vector.cpp)
==============================================================================
--- /sandbox/explore/libs/explore/test/std_vector.cpp (original)
+++ sandbox/explore/libs/explore/test/user_defined_container.cpp 2007-05-24 20:56:34 EDT (Thu, 24 May 2007)
@@ -9,131 +9,56 @@
#define BOOST_TEST_MODULE PrintLib
#include <boost/test/unit_test.hpp>
-#include <string>
#include <sstream>
#include <vector>
#include "../../../boost/explore/explore.hpp"
#include "../../../boost/explore/stream_container.hpp"
-BOOST_AUTO_TEST_CASE( basic_vector_print_test )
+class user_vector
{
- std::stringstream str_out;
-
- std::vector<int> vi;
- explore::print(vi, str_out);
- BOOST_CHECK_EQUAL(str_out.str(), "[]");
+public:
+ user_vector()
+ {
+ m_vec.push_back(1);
+ m_vec.push_back(2);
+ m_vec.push_back(3);
+ }
- str_out.str("");
+ std::vector<int>::const_iterator begin() const
+ {
+ return m_vec.begin();
+ }
- vi.push_back(1);
- explore::print(vi, str_out);
- BOOST_CHECK_EQUAL(str_out.str(), "[1]");
+ std::vector<int>::const_iterator end() const
+ {
+ return m_vec.end();
+ }
- str_out.str("");
+private:
+ std::vector<int> m_vec;
+};
- vi.push_back(2);
- vi.push_back(3);
- explore::print(vi, str_out);
- BOOST_CHECK_EQUAL(str_out.str(), "[1, 2, 3]");
-}
+std::ostream& operator<<(std::ostream& ostr, user_vector& u)
+{
+ return boost::stream_container(ostr, u.begin(), u.end());
+}
-BOOST_AUTO_TEST_CASE( basic_vector_stream_test )
+BOOST_AUTO_TEST_CASE( user_defined_print_test )
{
- using namespace boost;
std::stringstream str_out;
- std::vector<int> vi;
- str_out << vi;
- BOOST_CHECK_EQUAL(str_out.str(), "[]");
-
- str_out.str("");
-
- vi.push_back(1);
- str_out << vi;
- BOOST_CHECK_EQUAL(str_out.str(), "[1]");
-
- str_out.str("");
-
- vi.push_back(2);
- vi.push_back(3);
- str_out << vi;
+ user_vector v;
+ explore::print(v, str_out);
BOOST_CHECK_EQUAL(str_out.str(), "[1, 2, 3]");
}
-BOOST_AUTO_TEST_CASE( vector_in_vector_print_test )
-{
- std::stringstream str_out;
-
- std::vector<int> vi;
- vi.push_back(1);
- vi.push_back(2);
- vi.push_back(3);
-
- std::vector<std::vector<int> > vvi;
- explore::print(vvi, str_out);
- BOOST_CHECK_EQUAL(str_out.str(), "[]");
-
- str_out.str("");
-
- vvi.push_back(vi);
- explore::print(vvi, str_out);
- BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3]]");
-
- str_out.str("");
-
- vvi.push_back(vi);
- vvi.push_back(vi);
- explore::print(vvi, str_out);
- BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3], [1, 2, 3], [1, 2, 3]]");
-}
-
-BOOST_AUTO_TEST_CASE( vector_in_vector_stream_test )
+BOOST_AUTO_TEST_CASE( user_defined_stream_test )
{
using namespace boost;
std::stringstream str_out;
- std::vector<int> vi;
- vi.push_back(1);
- vi.push_back(2);
- vi.push_back(3);
-
- std::vector<std::vector<int> > vvi;
- str_out << vvi;
- BOOST_CHECK_EQUAL(str_out.str(), "[]");
-
- str_out.str("");
-
- vvi.push_back(vi);
- str_out << vvi;
- BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3]]");
-
- str_out.str("");
-
- vvi.push_back(vi);
- vvi.push_back(vi);
- str_out << vvi;
- BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3], [1, 2, 3], [1, 2, 3]]");
-}
-
-// This test shows that you can use a string to cause the same outputs
-// as other print statements.
-BOOST_AUTO_TEST_CASE( vector_with_ugly_string_case_print_test )
-{
- std::stringstream str_out;
-
- std::vector<std::string> vs;
- vs.push_back("[1, 2, 3], [1, 2, 3], [1, 2, 3]");
- explore::print(vs, str_out);
- BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3], [1, 2, 3], [1, 2, 3]]");
+ user_vector v;
+ str_out << v;
+ BOOST_CHECK_EQUAL(str_out.str(), "[1, 2, 3]");
}
-BOOST_AUTO_TEST_CASE( vector_with_ugly_string_case_stream_test )
-{
- using namespace boost;
- std::stringstream str_out;
-
- std::vector<std::string> vs;
- vs.push_back("[1, 2, 3], [1, 2, 3], [1, 2, 3]");
- str_out << vs;
- BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3], [1, 2, 3], [1, 2, 3]]");
-}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk