]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
92f5a8d4 TL |
11 | #if defined(BOOST_BUILD_PCH_ENABLED) && defined(BOOST_SPIRIT_THREADSAFE) |
12 | # error BOOST_SPIRIT_THREADSAFE has to be undefined for this test | |
13 | #endif | |
7c673cae FG |
14 | #undef BOOST_SPIRIT_THREADSAFE |
15 | #include <boost/spirit/home/classic/core/non_terminal/impl/object_with_id.ipp> | |
1e59de90 TL |
16 | |
17 | #include <boost/core/lightweight_test.hpp> | |
7c673cae FG |
18 | #include <iostream> |
19 | ||
20 | using BOOST_SPIRIT_CLASSIC_NS::impl::object_with_id; | |
21 | ||
22 | struct tag1 {}; | |
23 | struct tag2 {}; | |
24 | ||
25 | typedef object_with_id<tag1> class1; | |
26 | typedef object_with_id<tag2> class2; | |
27 | ||
28 | int | |
29 | main() | |
30 | { | |
31 | std::cout << "/////////////////////////////////////////////////////////\n"; | |
32 | std::cout << "\n"; | |
33 | std::cout << " object_with_id test (ST)\n"; | |
34 | std::cout << "\n"; | |
35 | std::cout << "/////////////////////////////////////////////////////////\n"; | |
36 | std::cout << "\n"; | |
37 | ||
38 | class1 *c1o1 = new class1; | |
39 | class1 *c1o2 = new class1; | |
40 | class1 *c1o3 = new class1; | |
41 | ||
42 | // test wether the objects have consecutive numbers | |
43 | BOOST_TEST(c1o1->get_object_id()==1); | |
44 | BOOST_TEST(c1o2->get_object_id()==2); | |
45 | BOOST_TEST(c1o3->get_object_id()==3); | |
46 | ||
47 | // test wether number recycling works | |
48 | delete c1o3; | |
49 | c1o3 = new class1; | |
50 | BOOST_TEST(c1o3->get_object_id()==3); | |
51 | ||
52 | delete c1o2; | |
53 | c1o2 = new class1; | |
54 | BOOST_TEST(c1o2->get_object_id()==2); | |
55 | ||
56 | delete c1o2; | |
57 | delete c1o3; | |
58 | c1o2 = new class1; | |
59 | c1o3 = new class1; | |
60 | BOOST_TEST(c1o3->get_object_id()==3); | |
61 | BOOST_TEST(c1o2->get_object_id()==2); | |
62 | ||
63 | // test whether objects of different classes are numbered independently | |
64 | class2 *c2o1 = new class2; | |
65 | class2 *c2o2 = new class2; | |
66 | class2 *c2o3 = new class2; | |
67 | BOOST_TEST(c2o1->get_object_id()==1); | |
68 | BOOST_TEST(c2o2->get_object_id()==2); | |
69 | BOOST_TEST(c2o3->get_object_id()==3); | |
70 | ||
71 | // | |
72 | delete c1o1; | |
73 | delete c2o2; | |
74 | c2o2 = new class2; | |
75 | c1o1 = new class1; | |
76 | BOOST_TEST(c1o1->get_object_id()==1); | |
77 | BOOST_TEST(c2o2->get_object_id()==2); | |
78 | ||
79 | // test wether the copy ctor doesn't copy the id | |
80 | delete c1o1; | |
81 | c1o1 = new class1(*c1o2); | |
82 | BOOST_TEST(c1o1->get_object_id()==1); | |
83 | ||
84 | // test wether the assignment operator doesn't assign the id | |
85 | *c1o1 = *c1o2; | |
86 | BOOST_TEST(c1o1->get_object_id()==1); | |
87 | ||
88 | return boost::report_errors(); | |
89 | } |