scoped_lock_tests.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*=============================================================================
  2. Copyright (C) 2003 Martin Wille
  3. http://spirit.sourceforge.net/
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. // Nota bene: the actual locking is _not_ tested here!
  9. #include <iostream>
  10. #include <boost/config.hpp>
  11. void banner()
  12. {
  13. std::cout << "/////////////////////////////////////////////////////////\n";
  14. std::cout << "\n";
  15. std::cout << " scoped_lock test\n";
  16. std::cout << "\n";
  17. std::cout << "/////////////////////////////////////////////////////////\n";
  18. std::cout << "\n";
  19. }
  20. #if defined(DONT_HAVE_BOOST) || !defined(BOOST_HAS_THREADS) || defined(BOOST_DISABLE_THREADS)
  21. // if boost libraries are not available we have to skip the tests
  22. int
  23. main()
  24. {
  25. banner();
  26. std::cout << "Test skipped (Boost libaries not available)\n";
  27. return 0;
  28. }
  29. #else
  30. #include <boost/thread/mutex.hpp>
  31. #include <boost/spirit/include/classic_core.hpp>
  32. #include <boost/spirit/include/classic_scoped_lock.hpp>
  33. #include <boost/detail/lightweight_test.hpp>
  34. int
  35. main()
  36. {
  37. banner();
  38. using BOOST_SPIRIT_CLASSIC_NS::rule;
  39. using BOOST_SPIRIT_CLASSIC_NS::scoped_lock_d;
  40. using BOOST_SPIRIT_CLASSIC_NS::parse_info;
  41. using BOOST_SPIRIT_CLASSIC_NS::parse;
  42. using boost::mutex;
  43. mutex m;
  44. rule<> r = scoped_lock_d(m)['x'];
  45. parse_info<> pi = parse("x", r);
  46. BOOST_TEST(pi.hit);
  47. BOOST_TEST(pi.full);
  48. return boost::report_errors();
  49. }
  50. #endif // defined(DONT_HAVE_BOOST)