Boost logo

Boost-Commit :

From: mconsoni_at_[hidden]
Date: 2007-06-01 19:06:26


Author: mconsoni
Date: 2007-06-01 19:06:25 EDT (Fri, 01 Jun 2007)
New Revision: 4416
URL: http://svn.boost.org/trac/boost/changeset/4416

Log:
- Jamfile.v2:
        . Added BOOST_TEST_DYN_LINK to try to fix the unresolved reference of main().
        . Added hello_world_test.cpp, the new test.

- hello_world_test.cpp:
        . The new test. It opens libHelloWorldLib.extension, registers the factory and then
          it tries to get the different classes (words) and checks if the returned strings are
          correct.

Added:
   sandbox/libs/extension/test/hello_world_test.cpp
Text files modified:
   sandbox/libs/extension/test/Jamfile.v2 | 2 ++
   1 files changed, 2 insertions(+), 0 deletions(-)

Modified: sandbox/libs/extension/test/Jamfile.v2
==============================================================================
--- sandbox/libs/extension/test/Jamfile.v2 (original)
+++ sandbox/libs/extension/test/Jamfile.v2 2007-06-01 19:06:25 EDT (Fri, 01 Jun 2007)
@@ -8,6 +8,7 @@
       <include>../../../
       <include>$(BOOST_ROOT)
       <define>BOOST_TEST_NO_AUTO_LINK=1
+ <toolset>gcc:<define>BOOST_TEST_DYN_LINK
       <toolset>gcc:<find-static-library>dl
     :
     ;
@@ -17,6 +18,7 @@
 : [ run factory_test.cpp ]
   [ run zone_test.cpp ]
   [ run construction.cpp ]
+ [ run hello_world_test.cpp ]
   [ run extension_test.cpp ]
   [ run counted_factory_test.cpp ]
   [ run registry_test.cpp ]

Added: sandbox/libs/extension/test/hello_world_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/test/hello_world_test.cpp 2007-06-01 19:06:25 EDT (Fri, 01 Jun 2007)
@@ -0,0 +1,51 @@
+/* (C) Copyright Mariano G. Consoni 2007
+ * Distributed under 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)
+ */
+
+#include <boost/extension/factory_map.hpp>
+#include <boost/extension/factory.hpp>
+#include <boost/extension/shared_library.hpp>
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_DYN_LINK 1
+#include <boost/test/unit_test.hpp>
+
+#include "../examples/word.hpp"
+
+
+using namespace boost::extensions;
+
+BOOST_AUTO_TEST_CASE(hello_world_example)
+{
+ // check if the library can be loaded
+ shared_library l((std::string("libHelloWorldLib") + ".extension").c_str());
+ BOOST_CHECK_EQUAL( l.open(), true );
+
+ // check if the factory can return the functor
+ factory_map fm;
+ functor<void, factory_map &> load_func = l.get_functor<void, factory_map &>("extension_export_word");
+ BOOST_CHECK_EQUAL( load_func.is_valid(), true );
+
+ load_func(fm);
+
+ // check if we can get the word list
+ std::list<factory<word, int> > & factory_list = fm.get<word, int>();
+ BOOST_CHECK_EQUAL( factory_list.size(), 2 );
+
+ // iterate trough the classes and execute get_val method to obtain the correct words
+ std::list<factory<word, int> >::iterator current_word = factory_list.begin();
+
+ std::auto_ptr<word> hello_word_ptr(current_word->create());
+ BOOST_CHECK_EQUAL( !hello_word_ptr.get(), 0 );
+
+ BOOST_CHECK_EQUAL( hello_word_ptr->get_val(), "hello");
+
+ ++current_word;
+
+ std::auto_ptr<word> world_word_ptr(current_word->create());
+ BOOST_CHECK_EQUAL( !world_word_ptr.get(), 0 );
+
+ BOOST_CHECK_EQUAL( world_word_ptr->get_val(), "world!");
+}
+


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