util: add printHex() overload that takes a uint64_t
And AsHex helper class.
Change-Id: If6fb6edea258ab281b5ea9cc30deffd2d8994dc5
Refs: #3006
diff --git a/tests/unit-tests/name.t.cpp b/tests/unit-tests/name.t.cpp
index a49a9c4..9840196 100644
--- a/tests/unit-tests/name.t.cpp
+++ b/tests/unit-tests/name.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -67,28 +67,19 @@
BOOST_AUTO_TEST_CASE(Encode)
{
Name name("/local/ndn/prefix");
+ const Block& wire = name.wireEncode();
- const Block &wire = name.wireEncode();
-
- // for (Buffer::const_iterator i = wire.begin();
- // i != wire.end();
- // ++i)
- // {
- // std::ios::fmtflags saveFlags = std::cout.flags(std::ios::hex);
-
- // if (i != wire.begin())
- // std::cout << ", ";
- // std::cout << "0x" << static_cast<uint32_t>(*i);
-
- // std::cout.flags(saveFlags);
- // }
+ // for (auto i = wire.begin(); i != wire.end(); ++i) {
+ // if (i != wire.begin())
+ // std::cout << ", ";
+ // printHex(std::cout, *i);
+ // }
// std::cout << std::endl;
- BOOST_CHECK_EQUAL_COLLECTIONS(TestName, TestName+sizeof(TestName),
+ BOOST_CHECK_EQUAL_COLLECTIONS(TestName, TestName + sizeof(TestName),
wire.begin(), wire.end());
}
-
BOOST_AUTO_TEST_CASE(Decode)
{
Block block(TestName, sizeof(TestName));
diff --git a/tests/unit-tests/util/string-helper.t.cpp b/tests/unit-tests/util/string-helper.t.cpp
index c5cc218..64144f8 100644
--- a/tests/unit-tests/util/string-helper.t.cpp
+++ b/tests/unit-tests/util/string-helper.t.cpp
@@ -31,6 +31,47 @@
BOOST_AUTO_TEST_SUITE(Util)
BOOST_AUTO_TEST_SUITE(TestStringHelper)
+BOOST_AUTO_TEST_CASE(PrintHex)
+{
+ boost::test_tools::output_test_stream os;
+
+ printHex(os, 0);
+ BOOST_CHECK(os.is_equal("0x0"));
+
+ printHex(os, 42);
+ BOOST_CHECK(os.is_equal("0x2a"));
+
+ printHex(os, 2748, true);
+ BOOST_CHECK(os.is_equal("0xABC"));
+
+ printHex(os, static_cast<uint64_t>(-1));
+ BOOST_CHECK(os.is_equal("0xffffffffffffffff"));
+
+ printHex(os, ~0U, true);
+ BOOST_CHECK(os.is_equal("0xFFFFFFFF"));
+
+ printHex(os, ~0ULL, true);
+ BOOST_CHECK(os.is_equal("0xFFFFFFFFFFFFFFFF"));
+}
+
+BOOST_AUTO_TEST_CASE(AsHex)
+{
+ using ndn::AsHex;
+ boost::test_tools::output_test_stream os;
+
+ os << AsHex{0};
+ BOOST_CHECK(os.is_equal("0x0"));
+
+ os << AsHex{42};
+ BOOST_CHECK(os.is_equal("0x2a"));
+
+ os << std::uppercase << AsHex{~0U};
+ BOOST_CHECK(os.is_equal("0xFFFFFFFF"));
+
+ os << std::nouppercase << AsHex{~0U};
+ BOOST_CHECK(os.is_equal("0xffffffff"));
+}
+
BOOST_AUTO_TEST_CASE(ToHex)
{
std::string test = "Hello, world!";