blob: f415c6ea271e1b866ab4a8d611f50a1067211527 [file] [log] [blame]
Brian Silverman88678712018-08-04 23:56:48 -07001/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// test_vector.cpp
3
4// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
5// Use, modification and distribution is subject to the Boost Software
6// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// should pass compilation and execution
10
11#include <fstream>
12
13#include <cstdio> // remove
14#include <boost/config.hpp>
15#if defined(BOOST_NO_STDC_NAMESPACE)
16namespace std{
17 using ::remove;
18}
19#endif
20
21#include "../test/test_tools.hpp"
22#include <boost/preprocessor/stringize.hpp>
23// #include <boost/preprocessor/cat.hpp>
24// the following fails with (only!) gcc 3.4
25// #include BOOST_PP_STRINGIZE(BOOST_PP_CAT(../test/,BOOST_ARCHIVE_TEST))
26// just copy over the files from the test directory
27#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
28#include <boost/serialization/vector.hpp>
29
30#include "../test/A.hpp"
31
32template <class T>
33int test_vector(T)
34{
35 const char * testfile = boost::archive::tmpnam(NULL);
36 BOOST_REQUIRE(NULL != testfile);
37
38 // test array of objects
39 std::vector<T> avector;
40 avector.push_back(T());
41 avector.push_back(T());
42 {
43 test_ostream os(testfile, TEST_STREAM_FLAGS);
44 test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
45 oa << boost::serialization::make_nvp("avector", avector);
46 }
47 std::vector<T> avector1;
48 {
49 test_istream is(testfile, TEST_STREAM_FLAGS);
50 test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
51 ia >> boost::serialization::make_nvp("avector", avector1);
52 }
53 BOOST_CHECK(avector == avector1);
54 std::remove(testfile);
55 return EXIT_SUCCESS;
56}
57
58int test_main( int /* argc */, char* /* argv */[] )
59{
60 int res = test_vector(A());
61 // test an int vector for which optimized versions should be available
62 if (res == EXIT_SUCCESS)
63 res = test_vector(0);
64 // test a bool vector
65 if (res == EXIT_SUCCESS)
66 res = test_vector(false);
67 return res;
68}
69
70// EOF