Boost logo

Boost-Commit :

From: oryol_at_[hidden]
Date: 2008-07-19 22:25:16


Author: jeremypack
Date: 2008-07-19 22:25:15 EDT (Sat, 19 Jul 2008)
New Revision: 47614
URL: http://svn.boost.org/trac/boost/changeset/47614

Log:
adaptable_factory test.

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

Modified: sandbox/libs/extension/test/Jamfile.v2
==============================================================================
--- sandbox/libs/extension/test/Jamfile.v2 (original)
+++ sandbox/libs/extension/test/Jamfile.v2 2008-07-19 22:25:15 EDT (Sat, 19 Jul 2008)
@@ -23,9 +23,9 @@
     :
     ;
 
-
 test-suite extension_tests_all
 :
+ [ run adaptable_factory_test.cpp ]
   [ run factory_test.cpp ]
   [ run zone_test.cpp ]
   [ run construction.cpp ]

Added: sandbox/libs/extension/test/adaptable_factory_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/test/adaptable_factory_test.cpp 2008-07-19 22:25:15 EDT (Sat, 19 Jul 2008)
@@ -0,0 +1,86 @@
+/*
+ * Boost.Extension / testing of adapter class
+ *
+ * (C) Copyright Jeremy Pack 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 <boost/extension/adaptable_factory.hpp>
+#include <boost/extension/shared_library.hpp>
+#include <boost/reflection/parameter_map.hpp>
+#include <boost/function.hpp>
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_DYN_LINK 1
+#include <boost/test/unit_test.hpp>
+
+
+using namespace boost::extensions;
+using namespace boost::reflections;
+
+class adaptable_class_base {
+public:
+ virtual ~adaptable_class_base() {}
+ virtual int get() {
+ return 5;
+ }
+};
+
+class adaptable_class : public adaptable_class_base {
+public:
+ virtual int get() {
+ return my_value;
+ }
+ adaptable_class()
+ : my_value(1) {
+ }
+ adaptable_class(int new_val)
+ : my_value(new_val) {
+ }
+ adaptable_class(int first_new_val, int second_new_val)
+ : my_value(first_new_val * second_new_val) {
+ }
+private:
+ int my_value;
+};
+
+BOOST_AUTO_TEST_CASE(noArgTest) {
+ parameter_map params;
+ adaptable_factory<adaptable_class_base> current_factory;
+ current_factory.set<adaptable_class>();
+ adaptable_class_base* a = current_factory.create(params);
+ BOOST_CHECK_EQUAL(a->get(), 1);
+}
+
+BOOST_AUTO_TEST_CASE(oneArgTest) {
+ parameter_map params;
+ parameter<int>* p1 = new parameter<int>(5);
+ params.insert(std::make_pair("first value", p1));
+
+ generic_parameter<>* g = params.get_first<int>("first value");
+ BOOST_CHECK(g->can_cast<int>());
+ BOOST_CHECK_EQUAL(5, g->cast<int>());
+
+ adaptable_factory<adaptable_class_base> current_factory;
+ current_factory.set<adaptable_class, int>("first value");
+ BOOST_CHECK(current_factory.get_missing_parameter_list(params).empty());
+ adaptable_class_base* a = current_factory.create(params);
+ BOOST_CHECK_EQUAL(a->get(), 5);
+}
+
+BOOST_AUTO_TEST_CASE(twoArgTest) {
+ parameter_map params;
+ parameter<int>* p1 = new parameter<int>(5);
+ parameter<int>* p2 = new parameter<int>(2);
+ params.insert(std::make_pair("first value", p1));
+ params.insert(std::make_pair("second value", p2));
+
+ adaptable_factory<adaptable_class_base> current_factory;
+ current_factory.set<adaptable_class, int, int>("first value", "second value");
+ BOOST_CHECK(current_factory.get_missing_parameter_list(params).empty());
+ adaptable_class_base* a = current_factory.create(params);
+ BOOST_CHECK_EQUAL(a->get(), 10);
+}


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