test_interrupts.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_array.cpp
  3. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  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. // should pass compilation and execution
  8. #include <stdlib.h>
  9. #include <boost/config.hpp>
  10. #include <cstddef>
  11. #include <fstream>
  12. #include <algorithm> // equal
  13. #include <cstdio> // remove
  14. #if defined(BOOST_NO_STDC_NAMESPACE)
  15. namespace std{
  16. using ::remove;
  17. }
  18. #endif
  19. #include "test_tools.hpp"
  20. #include <boost/serialization/nvp.hpp>
  21. #include <boost/serialization/split_member.hpp>
  22. #include <boost/core/no_exceptions_support.hpp>
  23. #include <boost/archive/archive_exception.hpp>
  24. struct test_dummy_out {
  25. template<class Archive>
  26. void save(Archive &, const unsigned int /*version*/) const {
  27. throw boost::archive::archive_exception(
  28. boost::archive::archive_exception::other_exception
  29. );
  30. }
  31. template<class Archive>
  32. void load(Archive & ar, const unsigned int version){
  33. }
  34. BOOST_SERIALIZATION_SPLIT_MEMBER()
  35. test_dummy_out(){}
  36. };
  37. template<class T>
  38. int test_out(){
  39. const char * testfile = boost::archive::tmpnam(NULL);
  40. BOOST_REQUIRE(NULL != testfile);
  41. const T t;
  42. {
  43. test_ostream os(testfile, TEST_STREAM_FLAGS);
  44. {
  45. BOOST_TRY {
  46. test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
  47. bool exception_invoked = false;
  48. BOOST_TRY {
  49. oa << BOOST_SERIALIZATION_NVP(t);
  50. }
  51. BOOST_CATCH (boost::archive::archive_exception const& ae){
  52. BOOST_CHECK(
  53. boost::archive::archive_exception::other_exception
  54. == ae.code
  55. );
  56. exception_invoked = true;
  57. }
  58. BOOST_CATCH_END
  59. BOOST_CHECK(exception_invoked);
  60. }
  61. BOOST_CATCH (boost::archive::archive_exception const& ae){}
  62. BOOST_CATCH_END
  63. }
  64. os.close();
  65. }
  66. std::remove(testfile);
  67. return EXIT_SUCCESS;
  68. }
  69. struct test_dummy_in {
  70. template<class Archive>
  71. void save(Archive & /* ar */, const unsigned int /*version*/) const {
  72. }
  73. template<class Archive>
  74. void load(Archive & /* ar */, const unsigned int /*version*/){
  75. throw boost::archive::archive_exception(
  76. boost::archive::archive_exception::other_exception
  77. );
  78. }
  79. BOOST_SERIALIZATION_SPLIT_MEMBER()
  80. test_dummy_in(){}
  81. };
  82. template<class T>
  83. int test_in(){
  84. const char * testfile = boost::archive::tmpnam(NULL);
  85. BOOST_REQUIRE(NULL != testfile);
  86. const T t;
  87. {
  88. test_ostream os(testfile, TEST_STREAM_FLAGS);
  89. {
  90. test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
  91. oa << BOOST_SERIALIZATION_NVP(t);
  92. }
  93. os.close();
  94. }
  95. {
  96. test_istream is(testfile, TEST_STREAM_FLAGS);
  97. {
  98. T t1;
  99. BOOST_TRY {
  100. test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
  101. bool exception_invoked = false;
  102. BOOST_TRY {
  103. ia >> BOOST_SERIALIZATION_NVP(t1);
  104. }
  105. BOOST_CATCH (boost::archive::archive_exception const& ae){
  106. BOOST_CHECK(
  107. boost::archive::archive_exception::other_exception
  108. == ae.code
  109. );
  110. exception_invoked = true;
  111. }
  112. BOOST_CATCH_END
  113. BOOST_CHECK(exception_invoked);
  114. }
  115. BOOST_CATCH (boost::archive::archive_exception const& ae){}
  116. BOOST_CATCH_END
  117. }
  118. is.close();
  119. }
  120. std::remove(testfile);
  121. return EXIT_SUCCESS;
  122. }
  123. int test_main( int /* argc */, char* /* argv */[] )
  124. {
  125. int res;
  126. res = test_out<test_dummy_out>();
  127. if (res != EXIT_SUCCESS)
  128. return EXIT_FAILURE;
  129. res = test_in<test_dummy_in>();
  130. if (res != EXIT_SUCCESS)
  131. return EXIT_FAILURE;
  132. return EXIT_SUCCESS;
  133. }
  134. // EOF