owi_st_tests.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*=============================================================================
  2. Copyright (c) 2002-2003 Martin Wille
  3. http://spirit.sourceforge.net/
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. // vim:ts=4:sw=4:et
  9. #if defined(BOOST_BUILD_PCH_ENABLED) && defined(BOOST_SPIRIT_THREADSAFE)
  10. # error BOOST_SPIRIT_THREADSAFE has to be undefined for this test
  11. #endif
  12. #undef BOOST_SPIRIT_THREADSAFE
  13. #include <boost/spirit/home/classic/core/non_terminal/impl/object_with_id.ipp>
  14. #include <boost/detail/lightweight_test.hpp>
  15. #include <iostream>
  16. using BOOST_SPIRIT_CLASSIC_NS::impl::object_with_id;
  17. struct tag1 {};
  18. struct tag2 {};
  19. typedef object_with_id<tag1> class1;
  20. typedef object_with_id<tag2> class2;
  21. int
  22. main()
  23. {
  24. std::cout << "/////////////////////////////////////////////////////////\n";
  25. std::cout << "\n";
  26. std::cout << " object_with_id test (ST)\n";
  27. std::cout << "\n";
  28. std::cout << "/////////////////////////////////////////////////////////\n";
  29. std::cout << "\n";
  30. class1 *c1o1 = new class1;
  31. class1 *c1o2 = new class1;
  32. class1 *c1o3 = new class1;
  33. // test wether the objects have consecutive numbers
  34. BOOST_TEST(c1o1->get_object_id()==1);
  35. BOOST_TEST(c1o2->get_object_id()==2);
  36. BOOST_TEST(c1o3->get_object_id()==3);
  37. // test wether number recycling works
  38. delete c1o3;
  39. c1o3 = new class1;
  40. BOOST_TEST(c1o3->get_object_id()==3);
  41. delete c1o2;
  42. c1o2 = new class1;
  43. BOOST_TEST(c1o2->get_object_id()==2);
  44. delete c1o2;
  45. delete c1o3;
  46. c1o2 = new class1;
  47. c1o3 = new class1;
  48. BOOST_TEST(c1o3->get_object_id()==3);
  49. BOOST_TEST(c1o2->get_object_id()==2);
  50. // test whether objects of different classes are numbered independently
  51. class2 *c2o1 = new class2;
  52. class2 *c2o2 = new class2;
  53. class2 *c2o3 = new class2;
  54. BOOST_TEST(c2o1->get_object_id()==1);
  55. BOOST_TEST(c2o2->get_object_id()==2);
  56. BOOST_TEST(c2o3->get_object_id()==3);
  57. //
  58. delete c1o1;
  59. delete c2o2;
  60. c2o2 = new class2;
  61. c1o1 = new class1;
  62. BOOST_TEST(c1o1->get_object_id()==1);
  63. BOOST_TEST(c2o2->get_object_id()==2);
  64. // test wether the copy ctor doesn't copy the id
  65. delete c1o1;
  66. c1o1 = new class1(*c1o2);
  67. BOOST_TEST(c1o1->get_object_id()==1);
  68. // test wether the assignment operator doesn't assign the id
  69. *c1o1 = *c1o2;
  70. BOOST_TEST(c1o1->get_object_id()==1);
  71. return boost::report_errors();
  72. }