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