diff options
author | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-14 10:35:25 -0800 |
---|---|---|
committer | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-16 11:40:23 -0800 |
commit | 967be2a4e82b1a125b26bb72a60318a4fb2b50c4 (patch) | |
tree | 8a24954b54d1546dc8049a17e485adb0a605f74f /host/tests/error_c_test.cpp | |
parent | aafe4e8b742a0e21d3818f21f34e3c8613132530 (diff) | |
download | uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.gz uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.bz2 uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.zip |
uhd: mpm: apply clang-format to all files
Applying formatting changes to all .cpp and .hpp files in the following
directories:
```
find host/examples/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/tests/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/dboard/neon/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/dboard/magnesium/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/device3/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/mpmd/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/x300/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/utils/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find mpm/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
```
Also formatted host/include/, except Cpp03 was used as a the language
standard instead of Cpp11.
```
sed -i 's/ Cpp11/ Cpp03/g' .clang-format
find host/include/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
```
Formatting style was designated by the .clang-format file.
Diffstat (limited to 'host/tests/error_c_test.cpp')
-rw-r--r-- | host/tests/error_c_test.cpp | 129 |
1 files changed, 63 insertions, 66 deletions
diff --git a/host/tests/error_c_test.cpp b/host/tests/error_c_test.cpp index a60abe289..c697ebac7 100644 --- a/host/tests/error_c_test.cpp +++ b/host/tests/error_c_test.cpp @@ -7,11 +7,10 @@ #include <uhd/error.h> #include <uhd/types/dict.hpp> - -#include <boost/test/unit_test.hpp> #include <boost/algorithm/string.hpp> #include <boost/assign.hpp> #include <boost/format.hpp> +#include <boost/test/unit_test.hpp> /* * Test our conversions from exceptions to C-level UHD error codes. @@ -19,97 +18,93 @@ * to test our C++ macro, which returns the error code. */ -typedef struct { +typedef struct +{ std::string last_error; } dummy_handle_t; template <typename error_type> -UHD_INLINE uhd_error throw_uhd_exception(dummy_handle_t *handle, const uhd::exception* except){ - UHD_SAFE_C_SAVE_ERROR(handle, - throw *dynamic_cast<const error_type*>(except); - ) +UHD_INLINE uhd_error throw_uhd_exception( + dummy_handle_t* handle, const uhd::exception* except) +{ + UHD_SAFE_C_SAVE_ERROR(handle, throw *dynamic_cast<const error_type*>(except);) } -UHD_INLINE uhd_error throw_boost_exception(dummy_handle_t *handle){ - UHD_SAFE_C_SAVE_ERROR(handle, +UHD_INLINE uhd_error throw_boost_exception(dummy_handle_t* handle) +{ + UHD_SAFE_C_SAVE_ERROR( + handle, std::runtime_error except("This is a std::runtime_error, thrown by Boost."); - BOOST_THROW_EXCEPTION(except); - ) + BOOST_THROW_EXCEPTION(except);) } -UHD_INLINE uhd_error throw_std_exception(dummy_handle_t *handle){ - UHD_SAFE_C_SAVE_ERROR(handle, - throw std::runtime_error("This is a std::runtime_error."); - ) +UHD_INLINE uhd_error throw_std_exception(dummy_handle_t* handle) +{ + UHD_SAFE_C_SAVE_ERROR( + handle, throw std::runtime_error("This is a std::runtime_error.");) } -UHD_INLINE uhd_error throw_unknown_exception(dummy_handle_t *handle){ - UHD_SAFE_C_SAVE_ERROR(handle, - throw 1; - ) +UHD_INLINE uhd_error throw_unknown_exception(dummy_handle_t* handle) +{ + UHD_SAFE_C_SAVE_ERROR(handle, throw 1;) } // There are enough non-standard names that we can't just use a conversion function static const uhd::dict<std::string, std::string> pretty_exception_names = - boost::assign::map_list_of - ("assertion_error", "AssertionError") - ("lookup_error", "LookupError") - ("index_error", "LookupError: IndexError") - ("key_error", "LookupError: KeyError") - ("type_error", "TypeError") - ("value_error", "ValueError") - ("runtime_error", "RuntimeError") - ("not_implemented_error", "RuntimeError: NotImplementedError") - ("usb_error", "RuntimeError: USBError 1") - ("environment_error", "EnvironmentError") - ("io_error", "EnvironmentError: IOError") - ("os_error", "EnvironmentError: OSError") - ("system_error", "SystemError") - ; - -#define UHD_TEST_CHECK_ERROR_CODE(cpp_exception_type, c_error_code) \ - expected_msg = str(boost::format("This is a uhd::%s.") % BOOST_STRINGIZE(cpp_exception_type)); \ - uhd::cpp_exception_type cpp_exception_type ## _foo(expected_msg); \ - error_code = throw_uhd_exception<uhd::cpp_exception_type>(&handle, &cpp_exception_type ## _foo); \ - BOOST_CHECK_EQUAL(error_code, c_error_code); \ - expected_msg = str(boost::format("%s: %s") \ + boost::assign::map_list_of("assertion_error", "AssertionError")( + "lookup_error", "LookupError")("index_error", "LookupError: IndexError")( + "key_error", "LookupError: KeyError")("type_error", "TypeError")("value_error", + "ValueError")("runtime_error", "RuntimeError")("not_implemented_error", + "RuntimeError: NotImplementedError")("usb_error", "RuntimeError: USBError 1")( + "environment_error", "EnvironmentError")("io_error", "EnvironmentError: IOError")( + "os_error", "EnvironmentError: OSError")("system_error", "SystemError"); + +#define UHD_TEST_CHECK_ERROR_CODE(cpp_exception_type, c_error_code) \ + expected_msg = \ + str(boost::format("This is a uhd::%s.") % BOOST_STRINGIZE(cpp_exception_type)); \ + uhd::cpp_exception_type cpp_exception_type##_foo(expected_msg); \ + error_code = throw_uhd_exception<uhd::cpp_exception_type>( \ + &handle, &cpp_exception_type##_foo); \ + BOOST_CHECK_EQUAL(error_code, c_error_code); \ + expected_msg = str(boost::format("%s: %s") \ % pretty_exception_names.get(BOOST_STRINGIZE(cpp_exception_type)) \ - % expected_msg); \ - BOOST_CHECK_EQUAL(handle.last_error, expected_msg); \ + % expected_msg); \ + BOOST_CHECK_EQUAL(handle.last_error, expected_msg); \ BOOST_CHECK_EQUAL(get_c_global_error_string(), expected_msg); // uhd::usb_error has a different constructor -#define UHD_TEST_CHECK_USB_ERROR_CODE() \ - expected_msg = "This is a uhd::usb_error."; \ - uhd::usb_error usb_error_foo(1, expected_msg); \ - error_code = throw_uhd_exception<uhd::usb_error>(&handle, &usb_error_foo); \ - BOOST_CHECK_EQUAL(error_code, UHD_ERROR_USB); \ - expected_msg = str(boost::format("%s: %s") \ - % pretty_exception_names.get("usb_error") \ - % expected_msg); \ - BOOST_CHECK_EQUAL(handle.last_error, expected_msg); \ +#define UHD_TEST_CHECK_USB_ERROR_CODE() \ + expected_msg = "This is a uhd::usb_error."; \ + uhd::usb_error usb_error_foo(1, expected_msg); \ + error_code = throw_uhd_exception<uhd::usb_error>(&handle, &usb_error_foo); \ + BOOST_CHECK_EQUAL(error_code, UHD_ERROR_USB); \ + expected_msg = str(boost::format("%s: %s") % pretty_exception_names.get("usb_error") \ + % expected_msg); \ + BOOST_CHECK_EQUAL(handle.last_error, expected_msg); \ BOOST_CHECK_EQUAL(get_c_global_error_string(), expected_msg); -BOOST_AUTO_TEST_CASE(test_uhd_exception){ +BOOST_AUTO_TEST_CASE(test_uhd_exception) +{ dummy_handle_t handle; std::string expected_msg; uhd_error error_code; - UHD_TEST_CHECK_ERROR_CODE(assertion_error, UHD_ERROR_ASSERTION); - UHD_TEST_CHECK_ERROR_CODE(lookup_error, UHD_ERROR_LOOKUP); - UHD_TEST_CHECK_ERROR_CODE(index_error, UHD_ERROR_INDEX); - UHD_TEST_CHECK_ERROR_CODE(key_error, UHD_ERROR_KEY); - UHD_TEST_CHECK_ERROR_CODE(type_error, UHD_ERROR_TYPE); - UHD_TEST_CHECK_ERROR_CODE(value_error, UHD_ERROR_VALUE); - UHD_TEST_CHECK_ERROR_CODE(runtime_error, UHD_ERROR_RUNTIME); + UHD_TEST_CHECK_ERROR_CODE(assertion_error, UHD_ERROR_ASSERTION); + UHD_TEST_CHECK_ERROR_CODE(lookup_error, UHD_ERROR_LOOKUP); + UHD_TEST_CHECK_ERROR_CODE(index_error, UHD_ERROR_INDEX); + UHD_TEST_CHECK_ERROR_CODE(key_error, UHD_ERROR_KEY); + UHD_TEST_CHECK_ERROR_CODE(type_error, UHD_ERROR_TYPE); + UHD_TEST_CHECK_ERROR_CODE(value_error, UHD_ERROR_VALUE); + UHD_TEST_CHECK_ERROR_CODE(runtime_error, UHD_ERROR_RUNTIME); UHD_TEST_CHECK_ERROR_CODE(not_implemented_error, UHD_ERROR_NOT_IMPLEMENTED); - UHD_TEST_CHECK_ERROR_CODE(io_error, UHD_ERROR_IO); - UHD_TEST_CHECK_ERROR_CODE(os_error, UHD_ERROR_OS); - UHD_TEST_CHECK_ERROR_CODE(system_error, UHD_ERROR_SYSTEM); + UHD_TEST_CHECK_ERROR_CODE(io_error, UHD_ERROR_IO); + UHD_TEST_CHECK_ERROR_CODE(os_error, UHD_ERROR_OS); + UHD_TEST_CHECK_ERROR_CODE(system_error, UHD_ERROR_SYSTEM); UHD_TEST_CHECK_USB_ERROR_CODE(); } -BOOST_AUTO_TEST_CASE(test_boost_exception){ +BOOST_AUTO_TEST_CASE(test_boost_exception) +{ dummy_handle_t handle; uhd_error error_code = throw_boost_exception(&handle); @@ -117,7 +112,8 @@ BOOST_AUTO_TEST_CASE(test_boost_exception){ BOOST_CHECK_EQUAL(error_code, UHD_ERROR_BOOSTEXCEPT); } -BOOST_AUTO_TEST_CASE(test_std_exception){ +BOOST_AUTO_TEST_CASE(test_std_exception) +{ dummy_handle_t handle; uhd_error error_code = throw_std_exception(&handle); @@ -125,7 +121,8 @@ BOOST_AUTO_TEST_CASE(test_std_exception){ BOOST_CHECK_EQUAL(handle.last_error, "This is a std::runtime_error."); } -BOOST_AUTO_TEST_CASE(test_unknown_exception){ +BOOST_AUTO_TEST_CASE(test_unknown_exception) +{ dummy_handle_t handle; uhd_error error_code = throw_unknown_exception(&handle); |