|
| 1 | +// Copyright (c) Glyn Matthews 2011. |
| 2 | +// Distributed under the Boost Software License, Version 1.0. |
| 3 | +// (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 5 | + |
| 6 | +#define BOOST_TEST_MODULE URL encoding test |
| 7 | +#include <boost/config/warning_disable.hpp> |
| 8 | +#include <boost/test/unit_test.hpp> |
| 9 | +#include <boost/network/uri/encode.hpp> |
| 10 | +#include <boost/network/uri/decode.hpp> |
| 11 | +#include <boost/network/tags.hpp> |
| 12 | +#include <boost/network/traits/string.hpp> |
| 13 | +#include <boost/mpl/list.hpp> |
| 14 | +#include <boost/range/algorithm/equal.hpp> |
| 15 | +#include <boost/range/algorithm/copy.hpp> |
| 16 | +#include <iterator> |
| 17 | + |
| 18 | + |
| 19 | +using namespace boost::network; |
| 20 | + |
| 21 | +typedef boost::mpl::list< |
| 22 | + tags::default_string |
| 23 | + , tags::default_wstring |
| 24 | + > tag_types; |
| 25 | + |
| 26 | + |
| 27 | +BOOST_AUTO_TEST_CASE_TEMPLATE(encoding_test, T, tag_types) { |
| 28 | + typedef typename string<T>::type string_type; |
| 29 | + |
| 30 | + const std::string unencoded(" !\"#$%&\'()*"); |
| 31 | + const std::string encoded("%20%21%22%23%24%25%26%27%28%29%2A"); |
| 32 | + |
| 33 | + string_type instance; |
| 34 | + uri::encode(unencoded, std::back_inserter(instance)); |
| 35 | + BOOST_CHECK(boost::equal(instance, encoded)); |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | +BOOST_AUTO_TEST_CASE_TEMPLATE(decoding_test, T, tag_types) { |
| 40 | + typedef typename string<T>::type string_type; |
| 41 | + |
| 42 | + const std::string unencoded(" !\"#$%&\'()*"); |
| 43 | + const std::string encoded("%20%21%22%23%24%25%26%27%28%29%2A"); |
| 44 | + |
| 45 | + string_type instance; |
| 46 | + uri::decode(encoded, std::back_inserter(instance)); |
| 47 | + BOOST_CHECK(boost::equal(instance, unencoded)); |
| 48 | +} |
0 commit comments