test_example.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2006 Dan Marsden
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #include "./example_struct.hpp"
  8. #include "./example_struct_type.hpp"
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/fusion/sequence/intrinsic.hpp>
  11. #include <boost/fusion/support/is_sequence.hpp>
  12. #include <boost/fusion/support/category_of.hpp>
  13. #include <boost/fusion/iterator.hpp>
  14. #include <boost/type_traits/is_same.hpp>
  15. #include <boost/mpl/assert.hpp>
  16. int main()
  17. {
  18. example::example_struct bert("bert", 99);
  19. using namespace boost::fusion;
  20. BOOST_MPL_ASSERT((traits::is_associative<example::example_struct>));
  21. BOOST_MPL_ASSERT((traits::is_random_access<example::example_struct>));
  22. BOOST_MPL_ASSERT((traits::is_sequence<example::example_struct>));
  23. BOOST_TEST(deref(begin(bert)) == "bert");
  24. BOOST_TEST(*next(begin(bert)) == 99);
  25. BOOST_TEST(*prior(end(bert)) == 99);
  26. BOOST_TEST(*advance_c<1>(begin(bert)) == 99);
  27. BOOST_TEST(*advance_c<-1>(end(bert)) == 99);
  28. BOOST_TEST(distance(begin(bert), end(bert)) == 2);
  29. typedef result_of::begin<example::example_struct>::type first;
  30. typedef result_of::next<first>::type second;
  31. BOOST_MPL_ASSERT((boost::is_same<result_of::value_of<first>::type, std::string>));
  32. BOOST_MPL_ASSERT((boost::is_same<result_of::value_of<second>::type, int>));
  33. BOOST_TEST(begin(bert) != end(bert));
  34. BOOST_TEST(advance_c<2>(begin(bert)) == end(const_cast<const example::example_struct&>(bert)));
  35. BOOST_TEST(at_c<0>(bert) == "bert");
  36. BOOST_TEST(at_c<1>(bert) == 99);
  37. BOOST_TEST(at_key<fields::name>(bert) == "bert");
  38. BOOST_TEST(at_key<fields::age>(bert) == 99);
  39. BOOST_TEST(has_key<fields::name>(bert));
  40. BOOST_TEST(has_key<fields::age>(bert));
  41. BOOST_TEST(!has_key<int>(bert));
  42. BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_c<example::example_struct, 0>::type, std::string>));
  43. BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_c<example::example_struct, 1>::type, int>));
  44. BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<example::example_struct, fields::name>::type, std::string>));
  45. BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<example::example_struct, fields::age>::type, int>));
  46. BOOST_TEST(deref_data(begin(bert)) == "bert");
  47. BOOST_TEST(deref_data(next(begin(bert))) == 99);
  48. BOOST_TEST(size(bert) == 2);
  49. return boost::report_errors();
  50. }