Boost logo

Boost-Commit :

From: oryol_at_[hidden]
Date: 2008-02-08 23:45:15


Author: jeremypack
Date: 2008-02-08 23:45:14 EST (Fri, 08 Feb 2008)
New Revision: 43182
URL: http://svn.boost.org/trac/boost/changeset/43182

Log:
Additional unit test files for Reflection

Added:
   sandbox/libs/reflection/test/basic_static_test.cpp (contents, props changed)
   sandbox/libs/reflection/test/parameter_info_test.cpp (contents, props changed)
   sandbox/libs/reflection/test/parameters_test.cpp (contents, props changed)

Added: sandbox/libs/reflection/test/basic_static_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/reflection/test/basic_static_test.cpp 2008-02-08 23:45:14 EST (Fri, 08 Feb 2008)
@@ -0,0 +1,39 @@
+/*
+ * Boost.Reflection / basic unit test
+ *
+ * (C) Copyright Mariano G. Consoni and 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_TEST_MAIN
+#define BOOST_TEST_DYN_LINK 1
+#include <boost/test/unit_test.hpp>
+#include <boost/reflection/static_reflection.hpp>
+
+
+int func1(int j) {
+ return j * 2;
+}
+int func2(int j) {
+ return j + 2;
+}
+int func3(int j, float f) {
+ return j - 2;
+}
+using namespace boost::reflections;
+BOOST_AUTO_TEST_CASE(argless) {
+ static_reflection sr;
+ sr.set<std::string, int, int>("First Function", &func1);
+ sr.set<std::string, int, int>("Second Function", &func2);
+ sr.set<std::string, int, int, float>("Third Function", &func3);
+ int result = sr.get<std::string, int, int, float>("Third Function")(3, 2.0f);
+ BOOST_CHECK_EQUAL(result, 1);
+}
\ No newline at end of file

Added: sandbox/libs/reflection/test/parameter_info_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/reflection/test/parameter_info_test.cpp 2008-02-08 23:45:14 EST (Fri, 08 Feb 2008)
@@ -0,0 +1,46 @@
+/*
+ * Boost.Reflection / basic 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_TEST_MAIN
+#define BOOST_TEST_DYN_LINK 1
+#include <boost/test/unit_test.hpp>
+#include <boost/reflection/reflector.hpp>
+
+class car {
+public:
+ int start() {
+ return 3;
+ }
+};
+
+using namespace boost::reflections;
+BOOST_AUTO_TEST_CASE(argless) {
+ basic_reflection<std::string, std::string> car_reflection;
+ reflector<car, std::string, std::string> car_reflector(&car_reflection);
+ car_reflector.reflect_constructor();
+ car_reflector.reflect<int>(&car::start, "start", "speed");
+ // Check for argless constructor
+ BOOST_CHECK(car_reflection.get_constructor().valid());
+ instance car_instance =
+ car_reflection.get_constructor().call();
+ BOOST_CHECK(car_reflection.get_function<int>("start").valid());
+ // Make sure it doesn't have this undeclared method
+ BOOST_CHECK(!car_reflection.get_function<int>("stop").valid());
+ BOOST_CHECK_EQUAL
+ (car_reflection.get_function<int>("start").call(car_instance), 3);
+ function<int> f =
+ car_reflection.get_function<int>("start");
+ BOOST_CHECK_EQUAL(f(car_instance), 3);
+}
\ No newline at end of file

Added: sandbox/libs/reflection/test/parameters_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/reflection/test/parameters_test.cpp 2008-02-08 23:45:14 EST (Fri, 08 Feb 2008)
@@ -0,0 +1,42 @@
+/*
+ * Boost.Reflection / parameter map 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>
+#include <boost/reflection/parameter_map.hpp>
+using namespace boost::reflections;
+BOOST_AUTO_TEST_CASE(paramter_map) {
+ parameter_map<std::string,
+ boost::extension::default_type_info> pm;
+ int m = 5;
+ int j = 6;
+ parameter<int &> it =
+ pm.insert<int &>(m, "integer m");
+ it->converts_to<float>();
+ it->converts_to<short>();
+ it->converts_to<long>();
+ it->converts_to<unsigned long>();
+ it = pm.insert<int &>(j, "integer m");
+ it->converts_to<float>();
+ BOOST_CHECK_EQUAL(pm.has<float>());
+ float val = pm.get<float>("integer j");
+ BOOST_CHECK_EQUAL(val, 5.0f);
+ float val2 = pm.get<float>("integer j");
+ BOOST_CHECK_EQUAL(val2, 6.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