Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/spirit/test/symbols_add_null.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.7 KB
Line 
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#define BOOST_SPIRIT_ASSERT_EXCEPTION ::spirit_exception
11
12struct spirit_exception
13{
14    spirit_exception(char const * msg)
15        : message(msg)
16    {
17    }
18
19    char const * message;
20};
21
22#include <boost/spirit/core/scanner/scanner.hpp>
23#include <boost/spirit/symbols/impl/tst.ipp>
24#include <boost/utility/addressof.hpp>
25
26#include <boost/detail/lightweight_test.hpp>
27
28typedef char char_type;
29typedef char const * iterator;
30
31char_type data_[] = "whatever";
32
33iterator begin = data_;
34iterator end = data_
35    + sizeof(data_)/sizeof(char_type); // Yes, this is an intentional bug ;)
36
37char_type data2_[] = "\0something";
38iterator begin2 = data2_;
39iterator end2 = data2_ + sizeof(data2_)/sizeof(char_type) - 1;
40
41int main()
42{
43    typedef boost::spirit::scanner<> scanner;
44    typedef boost::spirit::impl::tst<void *, char_type> symbols;
45
46    symbols symbols_;
47
48    try
49    {
50        // It is not ok to add strings containing the null character.
51        symbols_.add(begin, end, (void*) boost::addressof(symbols_));
52        BOOST_TEST(0);
53    }
54    catch (spirit_exception &e)
55    {
56    }
57
58    try
59    {
60        // It is not ok to add strings containing the null character.
61        symbols_.add(begin2, end2, (void*) boost::addressof(symbols_));
62        BOOST_TEST(0);
63    }
64    catch (spirit_exception &e)
65    {
66    }
67    return boost::report_errors();
68}
Note: See TracBrowser for help on using the repository browser.