1 /*=============================================================================
2     Copyright (c) 2004 Joao Abecasis
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 
10 // This test requires NDEBUG to be undefined,  because it depends on
11 // BOOST_SPIRIT_ASSERT throwing an exception.
12 #ifdef NDEBUG
13 #  undef NDEBUG
14 #endif
15 
16 #include <stdexcept>
17 
18 #define BOOST_SPIRIT_ASSERT_EXCEPTION ::spirit_exception
19 
20 struct spirit_exception : std::exception
21 {
spirit_exceptionspirit_exception22     spirit_exception(char const * msg)
23         : message(msg)
24     {
25     }
~spirit_exceptionspirit_exception26     ~spirit_exception() throw() {}
27 
whatspirit_exception28     char const* what() const throw() { return message; }
29 
30     char const * message;
31 };
32 
33 #include <boost/spirit/include/classic_scanner.hpp>
34 #include <boost/spirit/home/classic/symbols/impl/tst.ipp>
35 #include <boost/utility/addressof.hpp>
36 
37 #include <boost/detail/lightweight_test.hpp>
38 
39 typedef char char_type;
40 typedef char const * iterator;
41 
42 char_type data_[] = "whatever";
43 
44 iterator begin = data_;
45 iterator end = data_
46     + sizeof(data_)/sizeof(char_type); // Yes, this is an intentional bug ;)
47 
48 char_type data2_[] = "\0something";
49 iterator begin2 = data2_;
50 iterator end2 = data2_ + sizeof(data2_)/sizeof(char_type) - 1;
51 
main()52 int main()
53 {
54     typedef BOOST_SPIRIT_CLASSIC_NS::scanner<> scanner;
55     typedef BOOST_SPIRIT_CLASSIC_NS::impl::tst<void *, char_type> symbols;
56 
57     symbols symbols_;
58 
59     try
60     {
61         // It is not ok to add strings containing the null character.
62         symbols_.add(begin, end, (void*) boost::addressof(symbols_));
63         BOOST_TEST(0);
64     }
65     catch (spirit_exception &/*e*/)
66     {
67     }
68 
69     try
70     {
71         // It is not ok to add strings containing the null character.
72         symbols_.add(begin2, end2, (void*) boost::addressof(symbols_));
73         BOOST_TEST(0);
74     }
75     catch (spirit_exception &/*e*/)
76     {
77     }
78     return boost::report_errors();
79 }
80