From c48c57073d618df5a023b5daec372aec5770b471 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 10 Jan 2018 14:45:30 -0800 Subject: uhd: Add narrow_cast and narrow Reviewed-by: Ashish Chaudhari --- host/tests/narrow_cast_test.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 host/tests/narrow_cast_test.cpp (limited to 'host/tests/narrow_cast_test.cpp') diff --git a/host/tests/narrow_cast_test.cpp b/host/tests/narrow_cast_test.cpp new file mode 100644 index 000000000..2f784bfe3 --- /dev/null +++ b/host/tests/narrow_cast_test.cpp @@ -0,0 +1,21 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0 +// + +#include +#include <../lib/include/uhdlib/utils/narrow.hpp> +#include +#include + +using namespace uhd; + +BOOST_AUTO_TEST_CASE(test_narrow){ + uint16_t x = 5; + uint8_t y = narrow_cast(x); + BOOST_CHECK_EQUAL(x, y); + + BOOST_CHECK_THROW(narrow(uint16_t(1<<10)), narrowing_error); + BOOST_CHECK_THROW(narrow(int8_t(-1)), narrowing_error); +} -- cgit v1.2.3