Boost logo

Boost-Commit :

From: jared_at_[hidden]
Date: 2007-05-18 10:49:56


Author: jared
Date: 2007-05-18 10:49:55 EDT (Fri, 18 May 2007)
New Revision: 4115
URL: http://svn.boost.org/trac/boost/changeset/4115

Log:
svn-commit.tmp

Added:
   sandbox/explore/libs/explore/test/Jamfile.v2 (contents, props changed)
   sandbox/explore/libs/explore/test/simple_types.cpp (contents, props changed)
   sandbox/explore/libs/explore/test/std_map.cpp
   sandbox/explore/libs/explore/test/std_pair.cpp
   sandbox/explore/libs/explore/test/std_vector.cpp

Added: sandbox/explore/libs/explore/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/explore/libs/explore/test/Jamfile.v2 2007-05-18 10:49:55 EDT (Fri, 18 May 2007)
@@ -0,0 +1,32 @@
+# Boost.Print Library
+
+# Copyright Jared McIntyre 2007. Use, modification and
+# distribution is subject to the Boost Software License, Version
+# 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+# For more information, see http://www.boost.org
+
+# bring in rules for testing
+import testing ;
+
+project
+ : source-location .
+ : requirements
+ <hardcode-dll-paths>true
+ <library>../../test/build//boost_test_exec_monitor
+ #<library>../build//print
+ ;
+{
+ test-suite signals
+ :
+ [ run simple_types.cpp ]
+
+ [ run std_vector.cpp ]
+
+ [ run std_map.cpp ]
+
+ [ run std_pair.cpp ]
+ ;
+}
+

Added: sandbox/explore/libs/explore/test/simple_types.cpp
==============================================================================
--- (empty file)
+++ sandbox/explore/libs/explore/test/simple_types.cpp 2007-05-18 10:49:55 EDT (Fri, 18 May 2007)
@@ -0,0 +1,106 @@
+// Boost.Print library
+
+// Copyright Jared McIntyre 2007. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// For more information, see http://www.boost.org
+
+#define BOOST_TEST_MODULE PrintLib
+#include <boost/test/unit_test.hpp>
+//#include <boost/print.hpp>
+#include <string>
+#include <sstream>
+#include <boost/lexical_cast.hpp>
+
+template<typename T>
+void print(T t, std::stringstream &str_out)
+{
+ str_out << "!!! fail test !!!";
+}
+
+BOOST_AUTO_TEST_CASE( int_test )
+{
+ std::stringstream str_out;
+ int i = 123;
+
+ print(i, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "123");
+
+ str_out.str("");
+ int* pi = new int(123);
+
+ print(pi, str_out);
+ // technically, we should force this to be true, though
+ // it is highly unlikely to be false. Otherwise this test is only
+ // telling you whether the following is even valid.
+ BOOST_CHECK(0 != boost::lexical_cast<std::string>((long)pi).compare("123"));
+ BOOST_CHECK_EQUAL(str_out.str(), "123");
+
+ delete pi;
+}
+
+BOOST_AUTO_TEST_CASE( float_test )
+{
+ std::stringstream str_out;
+ float f = 1.234f;
+
+ print(f, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "1.234");
+
+ BOOST_CHECK_MESSAGE(false, "Test min precision");
+ BOOST_CHECK_MESSAGE(false, "Test max precision");
+}
+
+BOOST_AUTO_TEST_CASE( double_test )
+{
+ std::stringstream str_out;
+ double d = 1.2341234f;
+
+ print(d, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "1.2341234");
+
+ BOOST_CHECK_MESSAGE(false, "Test min precision");
+ BOOST_CHECK_MESSAGE(false, "Test max precision");
+}
+
+BOOST_AUTO_TEST_CASE( bool_test )
+{
+ std::stringstream str_out;
+ bool b = true;
+
+ print(b, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "true");
+
+ str_out.str("");
+ b = false;
+
+ print(b, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "false");
+}
+
+BOOST_AUTO_TEST_CASE( char_test )
+{
+ std::stringstream str_out;
+ char c = 'c';
+
+ print(c, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "c");
+
+ str_out.str("");
+ char* pc = "c";
+
+ print(c, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "c");
+}
+
+BOOST_AUTO_TEST_CASE( string_test )
+{
+ std::stringstream str_out;
+ std::string s = "some string";
+
+ print(s, str_out);
+
+ BOOST_CHECK_EQUAL(str_out.str(), "some string");
+}

Added: sandbox/explore/libs/explore/test/std_map.cpp
==============================================================================
--- (empty file)
+++ sandbox/explore/libs/explore/test/std_map.cpp 2007-05-18 10:49:55 EDT (Fri, 18 May 2007)
@@ -0,0 +1,71 @@
+// Boost.Print library
+
+// Copyright Jared McIntyre 2007. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// For more information, see http://www.boost.org
+
+#define BOOST_TEST_MODULE PrintLib
+#include <boost/test/unit_test.hpp>
+//#include <boost/print.hpp>
+#include <string>
+#include <sstream>
+#include <vector>
+#include <map>
+
+template<typename T>
+void print(T t, std::stringstream &str_out)
+{
+ str_out << "!!! fail test !!!";
+}
+
+BOOST_AUTO_TEST_CASE( basic_map_test )
+{
+ std::stringstream str_out;
+
+ std::map<int,std::string> mis;
+ print(mis, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[]");
+
+ str_out.str("");
+
+ mis.insert(std::make_pair(1, "first"));
+ print(mis, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[1:first]");
+
+ str_out.str("");
+
+ mis.insert(std::make_pair(2, "second"));
+ mis.insert(std::make_pair(3, "third"));
+ print(mis, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[1:first, 2:second, 3:third]");
+}
+
+BOOST_AUTO_TEST_CASE( vector_in_map_test )
+{
+ std::stringstream str_out;
+
+ std::vector<int> vi;
+ vi.push_back(1);
+ vi.push_back(2);
+ vi.push_back(3);
+
+ std::map<int,std::vector<int> > mivi;
+ print(mivi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[]");
+
+ str_out.str("");
+
+ mivi.insert(std::make_pair(1, vi));
+ print(mivi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[1:[1,2,3]]");
+
+ str_out.str("");
+
+ mivi.insert(std::make_pair(2, vi));
+ mivi.insert(std::make_pair(3, vi));
+ print(mivi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[1:[1,2,3], 2:[1,2,3], 3:[1,2,3]]");
+}
\ No newline at end of file

Added: sandbox/explore/libs/explore/test/std_pair.cpp
==============================================================================
--- (empty file)
+++ sandbox/explore/libs/explore/test/std_pair.cpp 2007-05-18 10:49:55 EDT (Fri, 18 May 2007)
@@ -0,0 +1,56 @@
+// Boost.Print library
+
+// Copyright Jared McIntyre 2007. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// For more information, see http://www.boost.org
+
+#define BOOST_TEST_MODULE PrintLib
+#include <boost/test/unit_test.hpp>
+//#include <boost/print.hpp>
+#include <sstream>
+#include <vector>
+
+template<typename T>
+void print(T t, std::stringstream &str_out)
+{
+ str_out << "!!! fail test !!!";
+}
+
+BOOST_AUTO_TEST_CASE( basic_pair_test )
+{
+ std::stringstream str_out;
+
+ std::pair<int,int> pi = std::make_pair(1,2);
+ print(pi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[1, 2]");
+}
+
+// This is an interesting case as it shows a stylistic difference between a vector of
+// pairs and a map. It also shows that if we allow this syntax, simple type and depth
+// formatters will need to be enhanced to meet this requirement.
+BOOST_AUTO_TEST_CASE( pair_in_vector_test )
+{
+ std::stringstream str_out;
+
+ std::vector<std::pair<int,int> > vpi;
+ print(vpi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[]");
+
+ str_out.str("");
+
+ std::pair<int,int> pi = std::make_pair(1,2);
+
+ vpi.push_back(pi);
+ print(vpi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2]]");
+
+ str_out.str("");
+
+ vpi.push_back(pi);
+ vpi.push_back(pi);
+ print(vpi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2], [1, 2], [1, 2]]");
+}
\ No newline at end of file

Added: sandbox/explore/libs/explore/test/std_vector.cpp
==============================================================================
--- (empty file)
+++ sandbox/explore/libs/explore/test/std_vector.cpp 2007-05-18 10:49:55 EDT (Fri, 18 May 2007)
@@ -0,0 +1,82 @@
+// Boost.Print library
+
+// Copyright Jared McIntyre 2007. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// For more information, see http://www.boost.org
+
+#define BOOST_TEST_MODULE PrintLib
+#include <boost/test/unit_test.hpp>
+//#include <boost/print.hpp>
+#include <string>
+#include <sstream>
+#include <vector>
+
+template<typename T>
+void print(T t, std::stringstream &str_out)
+{
+ str_out << "!!! fail test !!!";
+}
+
+BOOST_AUTO_TEST_CASE( basic_vector_test )
+{
+ std::stringstream str_out;
+
+ std::vector<int> vi;
+ print(vi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[]");
+
+ str_out.str("");
+
+ vi.push_back(1);
+ print(vi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[1]");
+
+ str_out.str("");
+
+ vi.push_back(2);
+ vi.push_back(3);
+ print(vi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[1, 2, 3]");
+}
+
+BOOST_AUTO_TEST_CASE( vector_in_vector_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;
+ print(vvi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[]");
+
+ str_out.str("");
+
+ vvi.push_back(vi);
+ print(vvi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3]]");
+
+ str_out.str("");
+
+ vvi.push_back(vi);
+ vvi.push_back(vi);
+ print(vvi, str_out);
+ 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_test )
+{
+ std::stringstream str_out;
+
+ std::vector<std::string> vs;
+ vs.push_back("[1, 2, 3], [1, 2, 3], [1, 2, 3]");
+ print(vs, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3], [1, 2, 3], [1, 2, 3]]");
+}
\ No newline at end of file


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