performance_vector.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_vector.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 <fstream>
  9. #include <cstdio> // remove
  10. #include <boost/config.hpp>
  11. #if defined(BOOST_NO_STDC_NAMESPACE)
  12. namespace std{
  13. using ::remove;
  14. }
  15. #endif
  16. #include "../test/test_tools.hpp"
  17. #include <boost/preprocessor/stringize.hpp>
  18. // #include <boost/preprocessor/cat.hpp>
  19. // the following fails with (only!) gcc 3.4
  20. // #include BOOST_PP_STRINGIZE(BOOST_PP_CAT(../test/,BOOST_ARCHIVE_TEST))
  21. // just copy over the files from the test directory
  22. #include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
  23. #include <boost/serialization/vector.hpp>
  24. #include "../test/A.hpp"
  25. template <class T>
  26. int test_vector(T)
  27. {
  28. const char * testfile = boost::archive::tmpnam(NULL);
  29. BOOST_REQUIRE(NULL != testfile);
  30. // test array of objects
  31. std::vector<T> avector;
  32. avector.push_back(T());
  33. avector.push_back(T());
  34. {
  35. test_ostream os(testfile, TEST_STREAM_FLAGS);
  36. test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
  37. oa << boost::serialization::make_nvp("avector", avector);
  38. }
  39. std::vector<T> avector1;
  40. {
  41. test_istream is(testfile, TEST_STREAM_FLAGS);
  42. test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
  43. ia >> boost::serialization::make_nvp("avector", avector1);
  44. }
  45. BOOST_CHECK(avector == avector1);
  46. std::remove(testfile);
  47. return EXIT_SUCCESS;
  48. }
  49. int test_main( int /* argc */, char* /* argv */[] )
  50. {
  51. int res = test_vector(A());
  52. // test an int vector for which optimized versions should be available
  53. if (res == EXIT_SUCCESS)
  54. res = test_vector(0);
  55. // test a bool vector
  56. if (res == EXIT_SUCCESS)
  57. res = test_vector(false);
  58. return res;
  59. }
  60. // EOF