|
Boost-Commit : |
From: oryol_at_[hidden]
Date: 2007-09-11 23:36:53
Author: jeremypack
Date: 2007-09-11 23:36:51 EDT (Tue, 11 Sep 2007)
New Revision: 39201
URL: http://svn.boost.org/trac/boost/changeset/39201
Log:
Adding new test files, and one new header for new extension/reflection API
Added:
sandbox/boost/extension/impl/decl.hpp (contents, props changed)
sandbox/libs/extension/test/double_param_test.cpp (contents, props changed)
sandbox/libs/extension/test/mixed_param_test.cpp (contents, props changed)
sandbox/libs/extension/test/shared_library_test.cpp (contents, props changed)
sandbox/libs/extension/test/single_param_test.cpp (contents, props changed)
sandbox/libs/reflection/test/single_param_test.cpp (contents, props changed)
Added: sandbox/boost/extension/impl/decl.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/extension/impl/decl.hpp 2007-09-11 23:36:51 EDT (Tue, 11 Sep 2007)
@@ -0,0 +1,24 @@
+/*
+ * Boost.Extension / main header:
+ * main header for extensions
+ *
+ * (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.
+ */
+
+#ifndef BOOST_EXTENSION_DECL_HPP
+#define BOOST_EXTENSION_DECL_HPP
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(MSC_VER)
+# define BOOST_EXTENSION_EXPORT_DECL __declspec(dllexport)
+# define BOOST_EXTENSION_IMPORT_DECL __declspec(dllimport)
+#else
+# define BOOST_EXTENSION_EXPORT_DECL
+# define BOOST_EXTENSION_IMPORT_DECL
+#endif
+
+#endif
Added: sandbox/libs/extension/test/double_param_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/test/double_param_test.cpp 2007-09-11 23:36:51 EDT (Tue, 11 Sep 2007)
@@ -0,0 +1,120 @@
+/*
+ * Boost.Extension / construction test case
+ *
+ * (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/factory.hpp>
+#include <boost/extension/factory_map.hpp>
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+#include <memory>
+#include <map>
+
+using namespace boost::extensions;
+
+
+class Automobile {
+public:
+ virtual ~Automobile() {}
+ Automobile(int speed1, float speed2) : speed_(speed1 * speed2) {}
+ virtual float getSpeed() {return speed_;}
+protected:
+ float speed_;
+};
+
+class Van : virtual public Automobile {
+public:
+ virtual ~Van() {}
+ Van(int speed1, float speed2) : Automobile(speed1, speed2) {}
+ virtual float getSpeed() {return speed_ / 2;}
+};
+
+class PickupTruck : virtual public Automobile {
+public:
+ virtual ~PickupTruck() {}
+ PickupTruck(int speed1, float speed2) : Automobile(speed1, speed2) {}
+ virtual float getSpeed() {return speed_ / 3;}
+};
+
+class Racecar : virtual public Automobile {
+public:
+ virtual ~Racecar() {}
+ Racecar(int speed1, float speed2) : Automobile(speed1, speed2) {}
+ virtual float getSpeed() {return 3 * speed_;}
+};
+
+class RacingVan : public Racecar, public Van
+{
+public:
+ virtual ~RacingVan() {}
+ RacingVan(int speed1, float speed2) : Automobile(speed1, speed2),
+ Racecar(speed1, speed2), Van(speed1, speed2) {}
+ virtual float getSpeed() {return 2 * speed_;}
+};
+
+
+
+
+BOOST_AUTO_TEST_CASE(factory_argless) {
+ factory<Automobile, int, float> f;
+ f.set<PickupTruck>();
+ BOOST_CHECK(f.is_valid());
+ std::auto_ptr<Automobile> pickup(f.create(45, 2.0f));
+ BOOST_CHECK_EQUAL(pickup->getSpeed(), 30.0f);
+}
+
+BOOST_AUTO_TEST_CASE(map_argless)
+{
+ std::map<std::string, factory<Automobile, int, float> > m;
+ m["A van"].set<Van>();
+ m["A basic automobile"].set<Automobile>();
+ m["A pickup truck"].set<PickupTruck>();
+ std::auto_ptr<Automobile> van(m["A van"].create(10, 3.0f));
+ BOOST_CHECK_EQUAL(van->getSpeed(), 15.0f);
+ BOOST_CHECK_EQUAL
+ (m["An unloaded car!"].create(30, 1.5f),
+ (Automobile*)0);
+}
+
+template <>
+Automobile * create_function<Automobile, Racecar>::create()
+{
+ return new Racecar(25, 2.0f);
+}
+
+BOOST_AUTO_TEST_CASE(factory_template)
+{
+ factory<Automobile, int, float> f;
+ f.set<Racecar>();
+ BOOST_CHECK(f.is_valid());
+ std::auto_ptr<Automobile> racecar(f.create(20, 3.0f));
+ BOOST_CHECK_EQUAL(racecar->getSpeed(), 180.0f);
+}
+
+BOOST_AUTO_TEST_CASE(factory_map_single_param)
+{
+ factory_map m;
+ m.get<Automobile, std::string, int, float>()["A pickup truck"]
+ .set<PickupTruck>();
+ m.get<Automobile, std::string, int, float>()["A racing van!"]
+ .set<RacingVan>();
+ std::auto_ptr<Automobile> pickup
+ (m.get<Automobile, std::string, int, float>()["A pickup truck"]
+ .create(30, 2.0f));
+ BOOST_CHECK_EQUAL(pickup->getSpeed(), 20);
+ std::auto_ptr<Automobile> racingVan
+ (m.get<Automobile, std::string, int, float>()["A racing van!"]
+ .create(20, 3.0f));
+ BOOST_CHECK_EQUAL(racingVan->getSpeed(), 120);
+ std::auto_ptr<Automobile> car_ptr
+ (m.get<Automobile, std::string, int, float>()["A nonexistent car!"]
+ .create(30, 1.2f));
+ BOOST_CHECK_EQUAL(car_ptr.get(), (Automobile*)0);
+}
Added: sandbox/libs/extension/test/mixed_param_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/test/mixed_param_test.cpp 2007-09-11 23:36:51 EDT (Tue, 11 Sep 2007)
@@ -0,0 +1,66 @@
+/*
+ * Boost.Extension / construction test case
+ *
+ * (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/factory.hpp>
+#include <boost/extension/factory_map.hpp>
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+#include <memory>
+#include <map>
+
+using namespace boost::extensions;
+
+
+class Base {
+public:
+ Base(int i) : value_(i) {}
+ Base(float j) : value_(int(j)) {}
+ Base() : value_(23) {}
+ Base(int i, float j) : value_(int(j) * i) {}
+ virtual int getValue() {return value_;}
+ virtual ~Base() {}
+private:
+ int value_;
+};
+class Derived : public Base {
+public:
+ virtual ~Derived() {}
+ Derived(int i) : Base(float(i * 3)) {}
+ Derived(float j) : Base(int(j)) {}
+ Derived() : Base(2, 23.0f) {}
+ Derived(int i, float j) : Base() {}
+ virtual int getValue() {return 2 * Base::getValue();}
+};
+
+
+
+
+BOOST_AUTO_TEST_CASE(CorrectConstructor) {
+ factory_map m;
+ m.get<Base, std::string, int, float>()["Derived"].set<Derived>();
+ m.get<Base, std::string, int>()["Derived"].set<Derived>();
+ m.get<Base, std::string>()["Derived"].set<Derived>();
+ m.get<Base, std::string, float>()["Derived"].set<Derived>();
+ m.get<Base, std::string, int, float>()["Base"].set<Base>();
+ m.get<Base, std::string, int>()["Base"].set<Base>();
+ m.get<Base, std::string>()["Base"].set<Base>();
+ m.get<Base, std::string, float>()["Base"].set<Base>();
+ std::auto_ptr<Base> b1(m.get<Base, std::string, float>()
+ ["Derived"].create(2.0f));
+ BOOST_CHECK_EQUAL(b1->getValue(), 4);
+ std::auto_ptr<Base> b2(m.get<Base, std::string>()
+ ["Derived"].create());
+ BOOST_CHECK_EQUAL(b2->getValue(), 92);
+ std::auto_ptr<Base> b3(m.get<Base, std::string, int, float>()
+ ["Base"].create(4, 5.0f));
+ BOOST_CHECK_EQUAL(b3->getValue(), 20.0f);
+}
\ No newline at end of file
Added: sandbox/libs/extension/test/shared_library_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/test/shared_library_test.cpp 2007-09-11 23:36:51 EDT (Tue, 11 Sep 2007)
@@ -0,0 +1,23 @@
+/*
+ * Boost.Extension / construction test case
+ *
+ * (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/shared_library.hpp>
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+#include <memory>
+#include <map>
+
+using namespace boost::extensions;
+
+BOOST_AUTO_TEST_CASE(construction) {
+ boost::extensions::shared_library sl("sl");
+}
Added: sandbox/libs/extension/test/single_param_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/test/single_param_test.cpp 2007-09-11 23:36:51 EDT (Tue, 11 Sep 2007)
@@ -0,0 +1,115 @@
+/*
+ * Boost.Extension / construction test case
+ *
+ * (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/factory.hpp>
+#include <boost/extension/factory_map.hpp>
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+#include <memory>
+#include <map>
+
+using namespace boost::extensions;
+
+
+class Automobile {
+public:
+ virtual ~Automobile() {}
+ Automobile(int speed) : speed_(speed) {}
+ virtual int getSpeed() {return speed_;}
+protected:
+ int speed_;
+};
+
+class Van : virtual public Automobile {
+public:
+ virtual ~Van() {}
+ Van(int speed) : Automobile(speed) {}
+ virtual int getSpeed() {return speed_ / 2;}
+};
+
+class PickupTruck : virtual public Automobile {
+public:
+ virtual ~PickupTruck() {}
+ PickupTruck(int speed) : Automobile(speed) {}
+ virtual int getSpeed() {return speed_ / 3;}
+};
+
+class Racecar : virtual public Automobile {
+public:
+ virtual ~Racecar() {}
+ Racecar(int speed) : Automobile(speed) {}
+ virtual int getSpeed() {return 3 * speed_;}
+};
+
+class RacingVan : public Racecar, public Van
+{
+public:
+ virtual ~RacingVan() {}
+ RacingVan(int speed) : Automobile(speed),
+ Racecar(speed), Van(speed) {}
+ virtual int getSpeed() {return 2 * speed_;}
+};
+
+
+
+
+BOOST_AUTO_TEST_CASE(factory_argless) {
+ factory<Automobile, int> f;
+ f.set<PickupTruck>();
+ BOOST_CHECK(f.is_valid());
+ std::auto_ptr<Automobile> pickup(f.create(90));
+ BOOST_CHECK_EQUAL(pickup->getSpeed(), 30);
+}
+
+BOOST_AUTO_TEST_CASE(map_argless)
+{
+ std::map<std::string, factory<Automobile, int> > m;
+ m["A van"].set<Van>();
+ m["A basic automobile"].set<Automobile>();
+ m["A pickup truck"].set<PickupTruck>();
+ std::auto_ptr<Automobile> van(m["A van"].create(30));
+ BOOST_CHECK_EQUAL(van->getSpeed(), 15);
+ BOOST_CHECK_EQUAL
+ (m["An unloaded car!"].create(30),
+ (Automobile*)0);
+}
+
+template <>
+Automobile * create_function<Automobile, Racecar>::create()
+{
+ return new Racecar(50);
+}
+
+BOOST_AUTO_TEST_CASE(factory_template)
+{
+ factory<Automobile, int> f;
+ f.set<Racecar>();
+ BOOST_CHECK(f.is_valid());
+ std::auto_ptr<Automobile> racecar(f.create(60));
+ BOOST_CHECK_EQUAL(racecar->getSpeed(), 180);
+}
+
+BOOST_AUTO_TEST_CASE(factory_map_single_param)
+{
+ factory_map m;
+ m.get<Automobile, std::string, int>()["A pickup truck"].set<PickupTruck>();
+ m.get<Automobile, std::string, int>()["A racing van!"].set<RacingVan>();
+ std::auto_ptr<Automobile> pickup
+ (m.get<Automobile, std::string, int>()["A pickup truck"].create(60));
+ BOOST_CHECK_EQUAL(pickup->getSpeed(), 20);
+ std::auto_ptr<Automobile> racingVan
+ (m.get<Automobile, std::string, int>()["A racing van!"].create(60));
+ BOOST_CHECK_EQUAL(racingVan->getSpeed(), 120);
+ std::auto_ptr<Automobile> car_ptr
+ (m.get<Automobile, std::string, int>()["A nonexistent car!"].create(30));
+ BOOST_CHECK_EQUAL(car_ptr.get(), (Automobile*)0);
+}
Added: sandbox/libs/reflection/test/single_param_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/reflection/test/single_param_test.cpp 2007-09-11 23:36:51 EDT (Tue, 11 Sep 2007)
@@ -0,0 +1,60 @@
+/*
+ * Boost.Reflection / basic single parameter unit test
+ *
+ * (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 <string>
+#include <iostream>
+
+#define BOOST_EXTENSION_USE_PP 1
+
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_DYN_LINK 1
+#include <boost/test/unit_test.hpp>
+#include <boost/reflection/reflector.hpp>
+
+class car {
+public:
+ car(float cost) : cost_(cost) {}
+ float get_cost() {return cost_;}
+ int start(bool fast) {
+ if (fast)
+ return 60;
+ else
+ return 30;
+ }
+private:
+ float cost_;
+};
+using namespace boost::reflections;
+BOOST_AUTO_TEST_CASE(argless)
+{/*
+ reflection car_reflection;
+ reflector<car> car_reflector(&car_reflection);
+ car_reflector.reflect_constructor<float>();
+ car_reflector.reflect<int, bool>(&car::start, "start");
+ car_reflector.reflect(&car::get_cost, "get_cost");
+ // Check for argless constructor
+ BOOST_CHECK(car_reflection.get_constructor<float>().valid());
+ instance car_instance =
+ car_reflection.get_constructor<float>().call(10.0f);
+ function<int, bool> f1 =
+ car_reflection.get_function<int, bool>("start");
+ BOOST_CHECK(f1.valid());
+ int ret_val = f1(car_instance, false);
+ BOOST_CHECK_EQUAL
+ (ret_val, 30);
+ BOOST_CHECK_EQUAL
+ (car_reflection.get_function<float>("get_cost")
+ .call(car_instance), 10.0f);
+ function<int> f2 =
+ car_reflection.get_function<float>("get_cost");
+ BOOST_CHECK_EQUAL(f2(car_instance), 10.0f);*/
+}
\ No newline at end of file
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