/* * Boost.Extension / implementations versions test * * (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) * * See http://www.boost.org/ for latest version. */ #include #include #include #define BOOST_TEST_MAIN #define BOOST_TEST_DYN_LINK 1 #include #include #include #include #include "../examples/word.hpp" #include "../examples/versioning/salute.hpp" BOOST_AUTO_TEST_CASE(versions_test) { using namespace boost::extensions; // Create the factory_map object - it will hold all of the available // constructors. Multiple factory_maps can be constructed. factory_map fm; // load hello world first version load_single_library(fm, "libHelloWorldLib.extension", "extension_export_word"); // load hello world second version load_single_library(fm, "libHelloWorldLibv2.extension", "extension_export_word"); // load hello world second version again load_single_library(fm, "libHelloWorldLibv2.extension", "extension_export_word"); // load salute library (with hello included) load_single_library(fm, "libSaluteLib.extension", "extension_export_salute"); // Get a reference to the list of constructors for words. std::map > & factory_list = fm.get(); // the point here is to check if six classes were loaded // (two for each one of the first three libraries) BOOST_CHECK_EQUAL( factory_list.size(), 6U ); // these are the expected strings std::vector words; words.push_back("hello"); words.push_back("world!"); words.push_back("| v2 hello"); words.push_back("world! v2"); words.push_back("| v2 hello"); words.push_back("world! v2"); std::vector::const_iterator expected_word = words.begin(); for (std::map >::iterator current_word = factory_list.begin(); current_word != factory_list.end(); ++current_word) { /// check that the pointer is OK and the word is the one that /// we're expecting std::auto_ptr word_ptr(current_word->second.create()); BOOST_CHECK_EQUAL( !word_ptr.get(), 0 ); BOOST_CHECK_EQUAL( word_ptr->get_val(), *expected_word); ++expected_word; } // Get a reference to the list of constructors for salutes. std::map > & salute_factory_list = fm.get(); // the point here is to check if only two classes were loaded BOOST_CHECK_EQUAL( salute_factory_list.size(), 2U ); // these are the expected strings std::vector salutes; salutes.push_back("hello"); salutes.push_back("bye!"); std::vector::const_iterator expected_salute = salutes.begin(); for (std::map >::iterator current_salute = salute_factory_list.begin(); current_salute != salute_factory_list.end(); ++current_salute) { /// check that the pointer is OK and the salute is the one that /// we're expecting std::auto_ptr salute_ptr(current_salute->second.create()); BOOST_CHECK_EQUAL( !salute_ptr.get(), 0 ); BOOST_CHECK_EQUAL( salute_ptr->say(), *expected_salute); ++expected_salute; } // all ok }