From: Braden M. <br...@us...> - 2006-11-22 00:05:22
|
Update of /cvsroot/openvrml/openvrml/tests In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv3665/tests Modified Files: Makefile.am browser.cpp parse_anchor.cpp parse_vrml97.cpp parse_x3dvrml.cpp Added Files: test_resource_fetcher.cpp test_resource_fetcher.h Removed Files: test_browser.cpp test_browser.h Log Message: Factored creation of openvrml::resource_istreams to a dedicated abstract factory, openvrml::resource_fetcher. This allows the code associated with resource fetching to live at least as long as the browser instance, which it needs to do if there are any outstanding fetches happening when the browser instance is destroyed. --- test_browser.h DELETED --- Index: parse_vrml97.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/tests/parse_vrml97.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** parse_vrml97.cpp 6 Mar 2006 05:58:26 -0000 1.2 --- parse_vrml97.cpp 22 Nov 2006 00:05:19 -0000 1.3 *************** *** 19,23 **** # include <iostream> ! # include "test_browser.h" using namespace std; --- 19,23 ---- # include <iostream> ! # include "test_resource_fetcher.h" using namespace std; *************** *** 27,31 **** { try { ! test_browser b; b.create_vrml_from_stream(cin, vrml_media_type); } catch (invalid_vrml & ex) { --- 27,32 ---- { try { ! test_resource_fetcher fetcher; ! browser b(fetcher, std::cout, std::cerr); b.create_vrml_from_stream(cin, vrml_media_type); } catch (invalid_vrml & ex) { --- NEW FILE: test_resource_fetcher.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 <iostream> # include <fstream> # include <boost/algorithm/string/predicate.hpp> # include "test_resource_fetcher.h" std::auto_ptr<openvrml::resource_istream> test_resource_fetcher::do_get_resource(const std::string & uri) { using std::auto_ptr; using std::invalid_argument; using std::string; using openvrml::resource_istream; class file_resource_istream : public resource_istream { std::string url_; std::filebuf buf_; public: explicit file_resource_istream(const std::string & path): resource_istream(&this->buf_) { if (!this->buf_.open(path.c_str(), ios_base::in)) { this->setstate(ios_base::failbit); } } void url(const std::string & str) throw (std::bad_alloc) { this->url_ = str; } private: virtual const std::string do_url() const throw () { return this->url_; } virtual const std::string do_type() const throw () { using std::find; using std::string; using boost::algorithm::iequals; using boost::next; string media_type = "application/octet-stream"; const string::const_reverse_iterator dot_pos = find(this->url_.rbegin(), this->url_.rend(), '.'); if (dot_pos == this->url_.rend() || next(dot_pos.base()) == this->url_.end()) { return media_type; } const string::const_iterator hash_pos = find(next(dot_pos.base()), this->url_.end(), '#'); const string ext(dot_pos.base(), hash_pos); if (iequals(ext, "wrl")) { media_type = "model/vrml"; } else if (iequals(ext, "x3dv")) { media_type = "model/x3d+vrml"; } else if (iequals(ext, "png")) { media_type = "image/png"; } else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) { media_type = "image/jpeg"; } return media_type; } virtual bool do_data_available() const throw () { return !!(*this); } }; const string scheme = uri.substr(0, uri.find_first_of(':')); if (scheme != "file") { throw invalid_argument('\"' + scheme + "\" URI scheme not supported"); } // // file:// // ^ // 01234567 // string path = uri.substr(uri.find_first_of('/', 7)); auto_ptr<resource_istream> in(new file_resource_istream(path)); static_cast<file_resource_istream *>(in.get())->url(uri); return in; } Index: browser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/tests/browser.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** browser.cpp 28 Jul 2006 07:11:10 -0000 1.7 --- browser.cpp 22 Nov 2006 00:05:19 -0000 1.8 *************** *** 19,22 **** --- 19,23 ---- # include <fstream> + # include <iostream> # include <sstream> # include <boost/filesystem/operations.hpp> *************** *** 24,28 **** # include <boost/thread.hpp> # include <boost/test/unit_test.hpp> ! # include "test_browser.h" using namespace std; --- 25,29 ---- # include <boost/thread.hpp> # include <boost/test/unit_test.hpp> ! # include "test_resource_fetcher.h" using namespace std; *************** *** 33,37 **** void create_vrml_from_stream() { ! test_browser b; const char vrmlstring[] = "Group {}"; --- 34,39 ---- void create_vrml_from_stream() { ! test_resource_fetcher fetcher; ! browser b(fetcher, std::cout, std::cerr); const char vrmlstring[] = "Group {}"; *************** *** 61,65 **** stringstream vrmlstream(vrmlstring); ! test_browser b; vector<boost::intrusive_ptr<node> > nodes = --- 63,68 ---- stringstream vrmlstream(vrmlstring); ! test_resource_fetcher fetcher; ! browser b(fetcher, std::cout, std::cerr); vector<boost::intrusive_ptr<node> > nodes = *************** *** 110,114 **** boost::ignore_unused_variable_warning(test_file_guard); ! test_browser b; const char vrmlstring[] = "Group {}"; stringstream vrmlstream(vrmlstring); --- 113,118 ---- boost::ignore_unused_variable_warning(test_file_guard); ! test_resource_fetcher fetcher; ! browser b(fetcher, std::cout, std::cerr); const char vrmlstring[] = "Group {}"; stringstream vrmlstream(vrmlstring); Index: Makefile.am =================================================================== RCS file: /cvsroot/openvrml/openvrml/tests/Makefile.am,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Makefile.am 23 Aug 2006 06:41:27 -0000 1.15 --- Makefile.am 22 Nov 2006 00:05:19 -0000 1.16 *************** *** 17,23 **** check_LTLIBRARIES = libtest-openvrml.la check_PROGRAMS = $(TESTS) parse-vrml97 parse-x3dvrml ! noinst_HEADERS = test_browser.h ! libtest_openvrml_la_SOURCES = test_browser.cpp libtest_openvrml_la_LIBADD = $(top_builddir)/src/libopenvrml/libopenvrml.la --- 17,23 ---- check_LTLIBRARIES = libtest-openvrml.la check_PROGRAMS = $(TESTS) parse-vrml97 parse-x3dvrml ! noinst_HEADERS = test_resource_fetcher.h ! libtest_openvrml_la_SOURCES = test_resource_fetcher.cpp libtest_openvrml_la_LIBADD = $(top_builddir)/src/libopenvrml/libopenvrml.la Index: parse_x3dvrml.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/tests/parse_x3dvrml.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** parse_x3dvrml.cpp 6 Mar 2006 05:58:26 -0000 1.2 --- parse_x3dvrml.cpp 22 Nov 2006 00:05:19 -0000 1.3 *************** *** 19,23 **** # include <iostream> ! # include "test_browser.h" using namespace std; --- 19,23 ---- # include <iostream> ! # include "test_resource_fetcher.h" using namespace std; *************** *** 27,31 **** { try { ! test_browser b; b.create_vrml_from_stream(cin, x3d_vrml_media_type); } catch (invalid_vrml & ex) { --- 27,32 ---- { try { ! test_resource_fetcher fetcher; ! browser b(fetcher, std::cout, std::cerr); b.create_vrml_from_stream(cin, x3d_vrml_media_type); } catch (invalid_vrml & ex) { --- NEW FILE: test_resource_fetcher.h --- // -*- 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 // # ifndef TEST_RESOURCE_FETCHER # define TEST_RESOURCE_FETCHER # include <openvrml/browser.h> class test_resource_fetcher : public openvrml::resource_fetcher { private: virtual std::auto_ptr<openvrml::resource_istream> do_get_resource(const std::string & uri); }; # endif --- test_browser.cpp DELETED --- Index: parse_anchor.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/tests/parse_anchor.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** parse_anchor.cpp 27 Feb 2006 21:14:08 -0000 1.5 --- parse_anchor.cpp 22 Nov 2006 00:05:19 -0000 1.6 *************** *** 21,25 **** # include <iostream> # include <sstream> ! # include "test_browser.h" int main() --- 21,25 ---- # include <iostream> # include <sstream> ! # include "test_resource_fetcher.h" int main() *************** *** 29,33 **** try { ! test_browser b; const char vrmlstring[] = --- 29,34 ---- try { ! test_resource_fetcher fetcher; ! browser b(fetcher, std::cout, std::cerr); const char vrmlstring[] = |