| 1 | /*============================================================================= |
|---|
| 2 | Copyright (C) 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 | |
|---|
| 10 | // Nota bene: the actual locking is _not_ tested here! |
|---|
| 11 | |
|---|
| 12 | #include <iostream> |
|---|
| 13 | #include <boost/config.hpp> |
|---|
| 14 | |
|---|
| 15 | void banner() |
|---|
| 16 | { |
|---|
| 17 | std::cout << "/////////////////////////////////////////////////////////\n"; |
|---|
| 18 | std::cout << "\n"; |
|---|
| 19 | std::cout << " scoped_lock test\n"; |
|---|
| 20 | std::cout << "\n"; |
|---|
| 21 | std::cout << "/////////////////////////////////////////////////////////\n"; |
|---|
| 22 | std::cout << "\n"; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | #if defined(DONT_HAVE_BOOST) || !defined(BOOST_HAS_THREADS) || defined(BOOST_DISABLE_THREADS) |
|---|
| 26 | // if boost libraries are not available we have to skip the tests |
|---|
| 27 | int |
|---|
| 28 | main() |
|---|
| 29 | { |
|---|
| 30 | banner(); |
|---|
| 31 | std::cout << "Test skipped (Boost libaries not available)\n"; |
|---|
| 32 | return 0; |
|---|
| 33 | } |
|---|
| 34 | #else |
|---|
| 35 | |
|---|
| 36 | #include <boost/thread/mutex.hpp> |
|---|
| 37 | #include <boost/spirit/core.hpp> |
|---|
| 38 | #include <boost/spirit/utility/scoped_lock.hpp> |
|---|
| 39 | #include <boost/detail/lightweight_test.hpp> |
|---|
| 40 | |
|---|
| 41 | int |
|---|
| 42 | main() |
|---|
| 43 | { |
|---|
| 44 | banner(); |
|---|
| 45 | |
|---|
| 46 | using boost::spirit::rule; |
|---|
| 47 | using boost::spirit::scoped_lock_d; |
|---|
| 48 | using boost::spirit::parse_info; |
|---|
| 49 | using boost::spirit::parse; |
|---|
| 50 | using boost::mutex; |
|---|
| 51 | |
|---|
| 52 | mutex m; |
|---|
| 53 | rule<> r = scoped_lock_d(m)['x']; |
|---|
| 54 | parse_info<> pi = parse("x", r); |
|---|
| 55 | BOOST_TEST(pi.hit); |
|---|
| 56 | BOOST_TEST(pi.full); |
|---|
| 57 | |
|---|
| 58 | return boost::report_errors(); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | #endif // defined(DONT_HAVE_BOOST) |
|---|