summaryrefslogtreecommitdiff
path: root/libs/algorithm/test/hex_test3.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-06-25 22:59:01 +0000
committer <>2013-09-27 11:49:28 +0000
commit8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch)
treec09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/algorithm/test/hex_test3.cpp
downloadboost-tarball-baserock/morph.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/algorithm/test/hex_test3.cpp')
-rw-r--r--libs/algorithm/test/hex_test3.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/libs/algorithm/test/hex_test3.cpp b/libs/algorithm/test/hex_test3.cpp
new file mode 100644
index 000000000..64f0ff49e
--- /dev/null
+++ b/libs/algorithm/test/hex_test3.cpp
@@ -0,0 +1,124 @@
+/*
+ Copyright (c) Marshall Clow 2011-2012.
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+ For more information, see http://www.boost.org
+
+Try ostream_iterators
+*/
+
+#include <boost/config.hpp>
+#include <boost/algorithm/hex.hpp>
+
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+
+#include <string>
+#include <iostream>
+#include <deque>
+#include <list>
+
+
+template <typename char_type>
+void test_to_hex ( const char_type ** tests ) {
+ typedef std::basic_string<char_type> String;
+ typedef std::basic_ostringstream<char_type> Stream;
+ typedef std::ostream_iterator<char_type, char_type> Iter;
+
+ for ( const char_type **p = tests; *p; p++ ) {
+ String arg, argh;
+ Stream one, two, three;
+ arg.assign ( *p );
+ boost::algorithm::hex ( *p, Iter ( one ));
+ boost::algorithm::hex ( arg, Iter ( two ));
+ boost::algorithm::hex ( arg.begin (), arg.end (), Iter ( three ));
+ boost::algorithm::hex ( arg );
+ BOOST_CHECK ( one.str () == two.str ());
+ BOOST_CHECK ( one.str () == three.str ());
+ argh = one.str ();
+ one.str (String()); two.str (String()); three.str (String());
+ boost::algorithm::unhex ( argh.c_str (), Iter ( one ));
+ boost::algorithm::unhex ( argh, Iter ( two ));
+ boost::algorithm::unhex ( argh.begin (), argh.end (), Iter ( three ));
+ BOOST_CHECK ( one.str () == two.str ());
+ BOOST_CHECK ( one.str () == three.str ());
+ BOOST_CHECK ( one.str () == arg );
+ }
+ }
+
+
+template <typename char_type>
+void test_from_hex_success ( const char_type ** tests ) {
+ typedef std::basic_string<char_type> String;
+ typedef std::basic_ostringstream<char_type> Stream;
+ typedef std::ostream_iterator<char_type, char_type> Iter;
+
+ for ( const char_type **p = tests; *p; p++ ) {
+ String arg, argh;
+ Stream one, two, three;
+ arg.assign ( *p );
+ boost::algorithm::unhex ( *p, Iter ( one ));
+ boost::algorithm::unhex ( arg, Iter ( two ));
+ boost::algorithm::unhex ( arg.begin (), arg.end (), Iter ( three ));
+
+ BOOST_CHECK ( one.str () == two.str ());
+ BOOST_CHECK ( one.str () == three.str ());
+
+ argh = one.str ();
+ one.str (String()); two.str (String()); three.str (String());
+
+ boost::algorithm::hex ( argh.c_str (), Iter ( one ));
+ boost::algorithm::hex ( argh, Iter ( two ));
+ boost::algorithm::hex ( argh.begin (), argh.end (), Iter ( three ));
+
+ BOOST_CHECK ( one.str () == two.str ());
+ BOOST_CHECK ( one.str () == three.str ());
+ BOOST_CHECK ( one.str () == arg );
+ }
+
+ }
+
+const char *tohex [] = {
+ "",
+ "a",
+ "\001",
+ "12",
+ "asdfadsfsad",
+ "01234567890ABCDEF",
+ NULL // End of the list
+ };
+
+const wchar_t *tohex_w [] = {
+ L"",
+ L"a",
+ L"\001",
+ L"12",
+ L"asdfadsfsad",
+ L"01234567890ABCDEF",
+ NULL // End of the list
+ };
+
+
+const char *fromhex [] = {
+ "20",
+ "2122234556FF",
+ NULL // End of the list
+ };
+
+const wchar_t *fromhex_w [] = {
+ L"11223320",
+ L"21222345010256FF",
+ NULL // End of the list
+ };
+
+
+
+BOOST_AUTO_TEST_CASE( test_main )
+{
+ test_to_hex ( tohex );
+ test_to_hex ( tohex_w );
+ test_from_hex_success ( fromhex );
+ test_from_hex_success ( fromhex_w );
+}