Boost logo

Boost-Commit :

From: chochlik_at_[hidden]
Date: 2008-08-14 13:35:05


Author: matus.chochlik
Date: 2008-08-14 13:35:04 EDT (Thu, 14 Aug 2008)
New Revision: 48142
URL: http://svn.boost.org/trac/boost/changeset/48142

Log:
[mirror 0.2.x]
- update of tests
Added:
   sandbox/mirror/libs/mirror/test/types_ct_03.cpp (contents, props changed)
   sandbox/mirror/libs/mirror/test/types_ct_04.cpp (contents, props changed)
   sandbox/mirror/libs/mirror/test/types_rt_01.cpp (contents, props changed)
   sandbox/mirror/libs/mirror/test/types_rt_02.cpp (contents, props changed)
Text files modified:
   sandbox/mirror/libs/mirror/test/Jamfile.v2 | 4 ++++
   sandbox/mirror/libs/mirror/test/types.hpp | 6 +++++-
   2 files changed, 9 insertions(+), 1 deletions(-)

Modified: sandbox/mirror/libs/mirror/test/Jamfile.v2
==============================================================================
--- sandbox/mirror/libs/mirror/test/Jamfile.v2 (original)
+++ sandbox/mirror/libs/mirror/test/Jamfile.v2 2008-08-14 13:35:04 EDT (Thu, 14 Aug 2008)
@@ -22,5 +22,9 @@
          [ compile-fail namespaces_cf_01.cpp ]
          [ compile types_ct_01.cpp ]
          [ compile types_ct_02.cpp ]
+ [ compile types_ct_03.cpp ]
+ [ compile types_ct_04.cpp ]
+ [ run types_rt_01.cpp ]
+ [ run types_rt_02.cpp ]
     ;
 

Modified: sandbox/mirror/libs/mirror/test/types.hpp
==============================================================================
--- sandbox/mirror/libs/mirror/test/types.hpp (original)
+++ sandbox/mirror/libs/mirror/test/types.hpp 2008-08-14 13:35:04 EDT (Thu, 14 Aug 2008)
@@ -12,8 +12,8 @@
 #ifndef BOOST_MIRROR_LIBS_MIRROR_TEST_TYPES_HPP
 #define BOOST_MIRROR_LIBS_MIRROR_TEST_TYPES_HPP
 
-// test namespaces
 #include "./namespaces.hpp"
+#include <boost/mirror/meta_type.hpp>
 
 namespace test {
 namespace feature {
@@ -29,6 +29,8 @@
 
 struct bar;
 
+typedef feature::foo foobar;
+
 } // namespace test
 
 // type on the global scope
@@ -42,6 +44,8 @@
 BOOST_MIRROR_REG_TYPE(::test::feature::detail, foo_impl)
 BOOST_MIRROR_REG_TYPE(::test::feature, foo)
 BOOST_MIRROR_REG_TYPE(::test, bar)
+// register the nested typedef
+BOOST_MIRROR_REG_TYPEDEF(::test, foobar)
 // register the type defined on the global scope
 BOOST_MIRROR_REG_TYPE_GS(baz)
 

Added: sandbox/mirror/libs/mirror/test/types_ct_03.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/types_ct_03.cpp 2008-08-14 13:35:04 EDT (Thu, 14 Aug 2008)
@@ -0,0 +1,111 @@
+/**
+ * \file test/types_ct_03.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing cooperation between mirror and mpl.
+ *
+ * Copyright 2008 Matus Chochlik. 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)
+ */
+
+// MPL
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/accumulate.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/or.hpp>
+//
+#include <boost/mirror/traits/reflects_global_scope.hpp>
+#include <boost/mirror/meta_namespace.hpp>
+// pre-registered types
+#include <boost/mirror/meta_type.hpp>
+//
+//
+#include "./namespaces.hpp"
+#include "./types.hpp"
+#include "./test.hpp"
+
+template <typename MetaType>
+struct get_scope
+{
+ typedef typename MetaType::scope type;
+};
+
+template <typename MetaType>
+struct get_reflected_type
+{
+ typedef typename MetaType::reflected_type type;
+};
+
+void test_main()
+{
+ using namespace ::boost;
+
+ typedef mpl::vector<
+ bool,
+ char,
+ short,
+ unsigned short,
+ int,
+ unsigned int,
+ long,
+ float,
+ double
+ > some_types;
+
+ BOOST_MPL_ASSERT(( mpl::accumulate<
+ some_types,
+ mpl::true_,
+ mpl::and_<
+ mpl::_1,
+ mirror::reflects_global_scope<
+ get_scope<
+ BOOST_MIRRORED_TYPE(mpl::_2)
+ >
+ >
+ >
+ >::type ));
+
+ BOOST_MPL_ASSERT(( mpl::accumulate<
+ some_types,
+ mpl::true_,
+ mpl::and_<
+ mpl::_1,
+ is_same<
+ get_reflected_type<BOOST_MIRRORED_TYPE(mpl::_2)>,
+ mpl::_2
+ >
+ >
+ >::type ));
+
+ typedef mpl::vector<
+ ::std::string,
+ ::std::wstring,
+ BOOST_MIRROR_TYPEDEF(::boost::cts, bstring)
+ > other_types;
+
+ BOOST_MPL_ASSERT_NOT(( mpl::accumulate<
+ other_types,
+ mpl::false_,
+ mpl::or_<
+ mpl::_1,
+ mirror::reflects_global_scope<
+ get_scope<
+ BOOST_MIRRORED_TYPE(mpl::_2)
+ >
+ >
+ >
+ >::type ));
+
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: types compile test 03");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+

Added: sandbox/mirror/libs/mirror/test/types_ct_04.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/types_ct_04.cpp 2008-08-14 13:35:04 EDT (Thu, 14 Aug 2008)
@@ -0,0 +1,125 @@
+/**
+ * \file test/types_ct_04.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing of meta_types for derived types and
+ * complex type name getters.
+ *
+ * Copyright 2008 Matus Chochlik. 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)
+ */
+
+#include <boost/mirror/meta_namespace.hpp>
+#include <boost/mirror/meta_type.hpp>
+#include <boost/mirror/meta_types/std_list.hpp>
+#include <boost/mirror/meta_types/std_set.hpp>
+#include <boost/mirror/meta_types/std_map.hpp>
+#include <boost/mirror/meta_types/std_pair.hpp>
+#include <boost/mirror/meta_types/boost_tuple.hpp>
+//
+#include <cstdlib>
+//
+#include "./namespaces.hpp"
+#include "./types.hpp"
+#include "./test.hpp"
+
+bool operator == (const ::std::string& str, const ::std::wstring& wstr)
+{
+ if(str.length() != wstr.length()) return false;
+ //
+ ::std::string::const_iterator stri = str.begin();
+ ::std::string::const_iterator stre = str.end();
+ ::std::wstring::const_iterator wstri = wstr.begin();
+ ::std::wstring::const_iterator wstre = wstr.end();
+ //
+ // go through the strings
+ while((stri != stre) && (wstri != wstre))
+ {
+ char ambc[2] = {*(stri++), '\0'};
+ wchar_t wc = *(wstri++);
+ wchar_t wcc = L'\0';
+ mbtowc(&wcc, ambc, 1);
+ // on mismatch return false
+ if(wc != wcc) return false;
+ }
+ //
+ // double check the iterators
+ return (stri == stre) && (wstri == wstre);
+
+}
+
+void test_main()
+{
+ using namespace ::boost;
+ typedef ::test::feature::detail::foo_impl X;
+ typedef BOOST_MIRROR_TYPEDEF(::test, foobar) Y;
+ typedef BOOST_MIRROR_TYPEDEF(::boost::cts, bstring) W;
+ typedef long int Z;
+ //
+ typedef X * const T1;
+ typedef Y volatile * const T2;
+ typedef const volatile W T3;
+ typedef Z const * const T4[][1][2][3][4][5][6][7][8][9];
+ typedef T1& (T5)(T2, T3, T4);
+ typedef T5* (T6)(T5*, T5&, Z);
+ //
+ typedef T6& T;
+ //
+ typedef BOOST_MIRRORED_TYPE(T) meta_T;
+ BOOST_CHECK((meta_T::full_name().length() > 0));
+ //
+ typedef ::std::list<
+ ::std::set<
+ ::std::map<
+ W,
+ ::std::pair<
+ T6*,
+ ::boost::tuple<
+ X,
+ Y,
+ W,
+ Z,
+ T6*
+ >
+ >
+ >
+ >
+ > U;
+ //
+ typedef BOOST_MIRRORED_TYPE(U) meta_U;
+ BOOST_CHECK((
+ meta_U::full_name() ==
+ meta_U::get_name(
+ mpl::true_(),
+ cts::bchar_traits()
+ )
+ ));
+ //
+ // the char and wchar_t variants of the full
+ // name must be equal
+ //
+ typedef BOOST_MIRRORED_TYPE(U) meta_U;
+ BOOST_CHECK((
+ meta_U::get_name(
+ mpl::true_(),
+ ::std::char_traits<char>()
+ ) ==
+ meta_U::get_name(
+ mpl::true_(),
+ ::std::char_traits<wchar_t>()
+ )
+ ));
+
+
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: types compile test 04");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+

Added: sandbox/mirror/libs/mirror/test/types_rt_01.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/types_rt_01.cpp 2008-08-14 13:35:04 EDT (Thu, 14 Aug 2008)
@@ -0,0 +1,111 @@
+/**
+ * \file test/type_rt_01.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing type registration and reflection.
+ *
+ * Simple tests of runtime features of the meta_type template.
+ *
+ * Copyright 2008 Matus Chochlik. 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)
+ */
+
+#include <boost/mirror/traits/reflects_global_scope.hpp>
+#include "./namespaces.hpp"
+#include "./types.hpp"
+#include "./test.hpp"
+
+
+void test_main()
+{
+ //
+ // base name getters for native C++ type and std::string
+ //
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int)::base_name() ==
+ BOOST_CTS_LIT("int")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(::std::string)::base_name() ==
+ BOOST_CTS_LIT("string")
+ );
+ //
+ // base and full name getter
+ //
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(::test::feature::foo)::base_name() ==
+ BOOST_CTS_LIT("foo")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(::test::feature::foo)::full_name() ==
+ BOOST_CTS_LIT("::test::feature::foo")
+ );
+ //
+ // scope full name getter
+ //
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(
+ ::test::feature::detail::foo_impl
+ )::scope::full_name() ==
+ BOOST_CTS_LIT("::test::feature::detail")
+ );
+ //
+ // difference between a typedef and it's source type
+ //
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(
+ ::test::foobar
+ )::full_name() ==
+ BOOST_CTS_LIT("::test::feature::foo")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE_NS(
+ ::test, foobar
+ )::full_name() ==
+ BOOST_CTS_LIT("::test::feature::foo")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPEDEF(
+ ::test, foobar
+ )::full_name() ==
+ BOOST_CTS_LIT("::test::foobar")
+ );
+ //
+ // the generic type name getter
+ //
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(::test::feature::detail::foo_impl)::get_name(
+ ::boost::mpl::false_(),
+ ::std::char_traits<char>()
+ ) == "foo_impl"
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(::test::feature::detail::foo_impl)::get_name(
+ ::boost::mpl::false_(),
+ ::std::char_traits<wchar_t>()
+ ) == L"foo_impl"
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(::test::feature::foo)::get_name(
+ ::boost::mpl::true_(),
+ ::std::char_traits<char>()
+ ) == "::test::feature::foo"
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(::test::feature::foo)::get_name(
+ ::boost::mpl::true_(),
+ ::std::char_traits<wchar_t>()
+ ) == L"::test::feature::foo"
+ );
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: types run-time test 01");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+

Added: sandbox/mirror/libs/mirror/test/types_rt_02.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/types_rt_02.cpp 2008-08-14 13:35:04 EDT (Thu, 14 Aug 2008)
@@ -0,0 +1,82 @@
+/**
+ * \file test/type_rt_02.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing type registration and reflection.
+ *
+ * Simple tests of runtime features of the meta_type template.
+ *
+ * Copyright 2008 Matus Chochlik. 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)
+ */
+
+#include <boost/mirror/traits/reflects_global_scope.hpp>
+#include "./namespaces.hpp"
+#include "./types.hpp"
+#include "./test.hpp"
+
+
+void test_main()
+{
+ //
+ // base name getters for native C++ type and std::string
+ //
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int *)::base_name() ==
+ BOOST_CTS_LIT("int *")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int const *)::base_name() ==
+ BOOST_CTS_LIT("int const *")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int const * volatile)::base_name() ==
+ BOOST_CTS_LIT("int const * volatile")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int const volatile &)::base_name() ==
+ BOOST_CTS_LIT("int const volatile &")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(const volatile int &)::base_name() ==
+ BOOST_MIRRORED_TYPE(int const volatile &)::base_name()
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int [])::base_name() ==
+ BOOST_CTS_LIT("int []")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int [123])::base_name() ==
+ BOOST_CTS_LIT("int [123]")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int [123][456])::base_name() ==
+ BOOST_CTS_LIT("int [123][456]")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int const [][123][456])::base_name() ==
+ BOOST_CTS_LIT("int const [][123][456]")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(int ( *)())::base_name() ==
+ BOOST_CTS_LIT("int ( *)()")
+ );
+ BOOST_CHECK(
+ BOOST_MIRRORED_TYPE(
+ int const volatile ( *)(int const &, int volatile *)
+ )::base_name() == BOOST_CTS_LIT(
+ "int const volatile ( *)(int const &, int volatile *)"
+ )
+ );
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: types run-time test 02");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+


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