From: Braden M. <br...@us...> - 2006-08-23 06:49:53
|
Update of /cvsroot/openvrml/openvrml/tests In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv12380/tests Modified Files: Tag: OpenVRML-0_16-BRANCH Makefile.am Added Files: Tag: OpenVRML-0_16-BRANCH color.cpp image.cpp mat4f.cpp rotation.cpp Log Message: Overloaded stream extraction operators for the fundamental types. --- NEW FILE: color.cpp --- // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*- // // Copyright 2006 Braden McDaniel // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // # include <sstream> # include <boost/test/unit_test.hpp> # include <openvrml/basetypes.h> using namespace std; using namespace openvrml; void stream_extraction_without_commas() { color c1(1.0, 1.0, 1.0), c2(0.5, 0.5, 0.5), c3, c4; string color_str = "1.0 1.0 1.0 0.5 0.5 0.5"; istringstream in(color_str); in >> c3 >> c4; BOOST_REQUIRE(in.good()); BOOST_REQUIRE_EQUAL(c1, c3); BOOST_REQUIRE_EQUAL(c2, c4); } void stream_extraction_with_commas() { color c1(1.0, 1.0, 1.0), c2(0.5, 0.5, 0.5), c3, c4; string color_str = "1.0, 1.0, 1.0, 0.5, 0.5, 0.5"; istringstream in(color_str); in >> c3 >> c4; BOOST_REQUIRE(in.good()); BOOST_REQUIRE_EQUAL(c1, c3); BOOST_REQUIRE_EQUAL(c2, c4); } void stream_extraction_fail_on_invalid_intensity() { color c; string color_str = "2.0 0.5 0.5"; istringstream in(color_str); in >> c; BOOST_REQUIRE(in.fail()); } boost::unit_test::test_suite * init_unit_test_suite(int, char * []) { using boost::unit_test::test_suite; test_suite * const suite = BOOST_TEST_SUITE("color"); suite->add(BOOST_TEST_CASE(&stream_extraction_without_commas)); suite->add(BOOST_TEST_CASE(&stream_extraction_with_commas)); suite->add(BOOST_TEST_CASE(&stream_extraction_fail_on_invalid_intensity)); return suite; } --- NEW FILE: image.cpp --- // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*- // // Copyright 2006 Braden McDaniel // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // # include <sstream> # include <boost/array.hpp> # include <boost/test/unit_test.hpp> # include <openvrml/basetypes.h> using namespace std; using namespace openvrml; void stream_insertion() { const image img(2, 2, 1); const string image_str = "2 2 1 0x0 0x0 0x0 0x0"; ostringstream out; out << img; BOOST_REQUIRE(out.good()); BOOST_REQUIRE_EQUAL(out.str(), image_str); } void stream_extraction() { const boost::array<unsigned char, 4> pixels = { 0xFF, 0x00, 0xFF, 0x00 }; const image img1(2, 2, 1, pixels.begin(), pixels.end()); image img2; const string image_str = "2 2 1 0xFF 0x00 0xFF 0x00"; istringstream in(image_str); in >> img2; BOOST_REQUIRE(in.good()); BOOST_REQUIRE_EQUAL(img1, img2); } void stream_extraction_insufficient_pixel_values() { const string image_str = "2 2 1 0xFF 0x00 0xFF"; istringstream in(image_str); image img; in >> img; BOOST_REQUIRE(in.fail()); } boost::unit_test::test_suite * init_unit_test_suite(int, char * []) { using boost::unit_test::test_suite; test_suite * const suite = BOOST_TEST_SUITE("image"); suite->add(BOOST_TEST_CASE(&stream_insertion)); suite->add(BOOST_TEST_CASE(&stream_extraction)); suite->add(BOOST_TEST_CASE(&stream_extraction_insufficient_pixel_values)); return suite; } --- NEW FILE: mat4f.cpp --- // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*- // // Copyright 2006 Braden McDaniel // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // # include <sstream> # include <boost/test/unit_test.hpp> # include <openvrml/basetypes.h> using namespace std; using namespace openvrml; void stream_insertion() { mat4f m; const string mat4f_str = "[1, 0, 0, 0], " "[0, 1, 0, 0], " "[0, 0, 1, 0], " "[0, 0, 0, 1]"; ostringstream out; out << m; BOOST_REQUIRE_EQUAL(out.str(), mat4f_str); } void stream_extraction_numbers_only() { const mat4f m1(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4); mat4f m2; const string mat4f_str = "1 0 0 0 " "0 2 0 0 " "0 0 3 0 " "0 0 0 4"; istringstream in(mat4f_str); in >> m2; BOOST_REQUIRE_EQUAL(m1, m2); } void stream_extraction_numbers_with_commas() { const mat4f m1(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4); mat4f m2; const string mat4f_str = "1, 0, 0, 0, " "0, 2, 0, 0, " "0, 0, 3, 0, " "0, 0, 0, 4"; istringstream in(mat4f_str); in >> m2; BOOST_REQUIRE_EQUAL(m1, m2); } boost::unit_test::test_suite * init_unit_test_suite(int, char * []) { using boost::unit_test::test_suite; test_suite * const suite = BOOST_TEST_SUITE("mat4f"); suite->add(BOOST_TEST_CASE(&stream_insertion)); suite->add(BOOST_TEST_CASE(&stream_extraction_numbers_only)); suite->add(BOOST_TEST_CASE(&stream_extraction_numbers_with_commas)); return suite; } Index: Makefile.am =================================================================== RCS file: /cvsroot/openvrml/openvrml/tests/Makefile.am,v retrieving revision 1.14 retrieving revision 1.14.2.1 diff -C2 -d -r1.14 -r1.14.2.1 *** Makefile.am 28 Jul 2006 07:11:10 -0000 1.14 --- Makefile.am 23 Aug 2006 06:49:49 -0000 1.14.2.1 *************** *** 6,10 **** TESTS_ENVIRONMENT = BOOST_TEST_REPORT_LEVEL=detailed ! TESTS = \ browser \ parse_anchor \ --- 6,13 ---- TESTS_ENVIRONMENT = BOOST_TEST_REPORT_LEVEL=detailed ! TESTS = color \ ! rotation \ ! mat4f \ ! image \ browser \ parse_anchor \ *************** *** 19,22 **** --- 22,45 ---- libtest_openvrml_la_LIBADD = $(top_builddir)/src/libopenvrml/libopenvrml.la + color_SOURCES = color.cpp + color_LDADD = \ + $(top_builddir)/src/libopenvrml/libopenvrml.la \ + -lboost_unit_test_framework + + rotation_SOURCES = rotation.cpp + rotation_LDADD = \ + $(top_builddir)/src/libopenvrml/libopenvrml.la \ + -lboost_unit_test_framework + + mat4f_SOURCES = mat4f.cpp + mat4f_LDADD = \ + $(top_builddir)/src/libopenvrml/libopenvrml.la \ + -lboost_unit_test_framework + + image_SOURCES = image.cpp + image_LDADD = \ + $(top_builddir)/src/libopenvrml/libopenvrml.la \ + -lboost_unit_test_framework + browser_SOURCES = browser.cpp browser_LDADD = libtest-openvrml.la -lboost_unit_test_framework -lboost_filesystem --- NEW FILE: rotation.cpp --- // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*- // // Copyright 2006 Braden McDaniel // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // # include <sstream> # include <boost/test/unit_test.hpp> # include <openvrml/basetypes.h> using namespace std; using namespace openvrml; void stream_extraction_fail_on_nonnormalized_axis() { string rotation_str = "2.0 2.0 0.0 0.0"; istringstream in(rotation_str); rotation r; in >> r; BOOST_REQUIRE(in.fail()); } boost::unit_test::test_suite * init_unit_test_suite(int, char * []) { using boost::unit_test::test_suite; test_suite * const suite = BOOST_TEST_SUITE("rotation"); suite->add(BOOST_TEST_CASE(&stream_extraction_fail_on_nonnormalized_axis)); return suite; } |