Ticket #2839: variant-test.diff

File variant-test.diff, 1.6 KB (added by st@…, 13 years ago)

patch adding test case to variant's unit tests

  • libs/variant/test/Jamfile.v2

     
    2727    [ run variant_reference_test.cpp ]
    2828    [ run variant_comparison_test.cpp ]
    2929    [ run variant_visit_test.cpp ]
     30    [ run test-swap.cpp ]
    3031   ;
  • libs/variant/test/test-swap.cpp

     
     1//-----------------------------------------------------------------------------
     2// boost-libs variant/test/test-swap.cpp source file
     3// See http://www.boost.org for updates, documentation, and revision history.
     4//-----------------------------------------------------------------------------
     5//
     6// Copyright (c) 2009 ArtVPS Ltd.
     7//
     8// Distributed under the Boost Software License, Version 1.0. (See
     9// accompanying file LICENSE_1_0.txt or copy at
     10// http://www.boost.org/LICENSE_1_0.txt)
     11
     12#include "boost/test/minimal.hpp"
     13#include "boost/variant.hpp"
     14
     15#include <vector>
     16
     17void run()
     18{
     19
     20   using boost::apply_visitor;
     21   using boost::variant;
     22   using std::cout;
     23   using std::endl;
     24
     25   typedef variant< int, std::vector<int>* > t_var;
     26
     27   std::vector<int> vec;
     28   t_var v0(23), v1(&vec);
     29
     30   BOOST_REQUIRE(v0.which() == 0);
     31   BOOST_REQUIRE(v1.which() == 1);
     32
     33   swap(v0, v1);
     34
     35   BOOST_CHECK(v0.which() == 1);
     36   BOOST_CHECK(v1.which() == 0);
     37}
     38
     39
     40
     41int test_main(int , char* [])
     42{
     43   run();
     44   return 0;
     45}