test_valarray.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_valarrray.cpp
  3. // (C) Copyright 2005 Matthias Troyer .
  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 <cstddef> // NULL
  9. #include <fstream>
  10. #include <cstdio> // remove
  11. #include <boost/config.hpp>
  12. #if defined(BOOST_NO_STDC_NAMESPACE)
  13. namespace std{
  14. using ::remove;
  15. }
  16. #endif
  17. #include "test_tools.hpp"
  18. #include <boost/serialization/valarray.hpp>
  19. int test_main( int /* argc */, char* /* argv */[] )
  20. {
  21. const char * testfile = boost::archive::tmpnam(NULL);
  22. BOOST_REQUIRE(NULL != testfile);
  23. // test array of objects
  24. std::valarray<int> avalarray(2);
  25. avalarray[0] = 42;
  26. avalarray[1] = -42;
  27. {
  28. test_ostream os(testfile, TEST_STREAM_FLAGS);
  29. test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
  30. oa << boost::serialization::make_nvp("avalarray", avalarray);
  31. }
  32. std::valarray<int> avalarray1;
  33. {
  34. test_istream is(testfile, TEST_STREAM_FLAGS);
  35. test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
  36. ia >> boost::serialization::make_nvp("avalarray", avalarray1);
  37. }
  38. bool equal = ( avalarray.size() == avalarray1.size()
  39. && avalarray[0] == avalarray1[0]
  40. && avalarray[1] == avalarray1[1]
  41. );
  42. BOOST_CHECK(equal);
  43. std::remove(testfile);
  44. return EXIT_SUCCESS;
  45. }
  46. // EOF