file_test.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2004-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5. // See http://www.boost.org/libs/iostreams for documentation.
  6. #include <boost/iostreams/device/file.hpp>
  7. #include <boost/test/test_tools.hpp>
  8. #include <boost/test/unit_test.hpp>
  9. #include "detail/temp_file.hpp"
  10. #include "detail/verification.hpp"
  11. using namespace boost;
  12. using namespace boost::iostreams;
  13. using namespace boost::iostreams::test;
  14. using std::ifstream;
  15. using boost::unit_test::test_suite;
  16. void file_test()
  17. {
  18. test_file test;
  19. //--------------Test file_source------------------------------------------//
  20. {
  21. file_source f(test.name());
  22. BOOST_CHECK(f.is_open());
  23. f.close();
  24. BOOST_CHECK(!f.is_open());
  25. f.open(test.name());
  26. BOOST_CHECK(f.is_open());
  27. }
  28. //--------------Test file_sink--------------------------------------------//
  29. {
  30. file_sink f(test.name());
  31. BOOST_CHECK(f.is_open());
  32. f.close();
  33. BOOST_CHECK(!f.is_open());
  34. f.open(test.name());
  35. BOOST_CHECK(f.is_open());
  36. }
  37. //--------------Test file-------------------------------------------------//
  38. {
  39. file f(test.name());
  40. BOOST_CHECK(f.is_open());
  41. f.close();
  42. BOOST_CHECK(!f.is_open());
  43. f.open(test.name());
  44. BOOST_CHECK(f.is_open());
  45. }
  46. }
  47. test_suite* init_unit_test_suite(int, char* [])
  48. {
  49. test_suite* test = BOOST_TEST_SUITE("file test");
  50. test->add(BOOST_TEST_CASE(&file_test));
  51. return test;
  52. }