|
Boost-Commit : |
From: oryol_at_[hidden]
Date: 2007-09-15 23:55:48
Author: jeremypack
Date: 2007-09-15 23:55:48 EDT (Sat, 15 Sep 2007)
New Revision: 39304
URL: http://svn.boost.org/trac/boost/changeset/39304
Log:
New Boost.Reflection test file.
Added:
sandbox/libs/reflection/test/multi_param_test.cpp (contents, props changed)
Added: sandbox/libs/reflection/test/multi_param_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/reflection/test/multi_param_test.cpp 2007-09-15 23:55:48 EDT (Sat, 15 Sep 2007)
@@ -0,0 +1,62 @@
+/*
+ * Boost.Reflection / basic many 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, const char * color, int quantity) : cost_(cost) {}
+ float get_cost(const char * color) {return cost_;}
+ int start(bool fast, float direction) {
+ 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, const char *, int>();
+ car_reflector.reflect<int, bool, float>(&car::start, "start");
+ car_reflector.reflect(&car::get_cost, "get_cost");
+ // Check for argless constructor
+ BOOST_CHECK((car_reflection.get_constructor<float, const char *, int>
+ ().valid()));
+ instance car_instance =
+ car_reflection.get_constructor<float, const char *, int>()
+ .call(10.0f, "red", 2);
+ function<int, bool, float> f1 =
+ car_reflection.get_function<int, bool, float>("start");
+ BOOST_CHECK(f1.valid());
+ int ret_val = f1(car_instance, false, 90.0f);
+ BOOST_CHECK_EQUAL
+ (ret_val, 30);
+ BOOST_CHECK_EQUAL
+ ((car_reflection.get_function<float, const char *>("get_cost")
+ .call(car_instance, "blue")), 10.0f);
+ function<float, const char *> f2 =
+ car_reflection.get_function<float, const char *>("get_cost");
+ BOOST_CHECK_EQUAL((f2(car_instance, "green")), 10.0f);
+}
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