From ed18ed376bcc71938ad73872148a3146814d831f Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Thu, 23 Dec 2021 09:39:39 -0600 Subject: host: Throw exception when accessing properties with incorrect type --- host/tests/property_test.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'host/tests') diff --git a/host/tests/property_test.cpp b/host/tests/property_test.cpp index 9776dd91b..ff9434fd1 100644 --- a/host/tests/property_test.cpp +++ b/host/tests/property_test.cpp @@ -7,6 +7,7 @@ // #include +#include #include #include #include @@ -228,6 +229,30 @@ BOOST_AUTO_TEST_CASE(test_prop_tree) BOOST_CHECK(not tree->exists("/test/prop1")); } +BOOST_AUTO_TEST_CASE(test_prop_tree_wrong_type) +{ + uhd::property_tree::sptr tree = uhd::property_tree::make(); + tree->create("/test/prop0"); + BOOST_CHECK_THROW(tree->access("/test/prop0"), uhd::type_error); +} + +BOOST_AUTO_TEST_CASE(test_prop_tree_wrong_type_range) +{ + uhd::property_tree::sptr tree = uhd::property_tree::make(); + + // Create the property + tree->create("/test/prop1"); + uhd::range_t singleton_range(5.0); + tree->access("/test/prop1").set(singleton_range); + + // Check it throws a type error + BOOST_CHECK_THROW(tree->access("/test/prop1"), uhd::type_error); + + // Check we can access its value + auto& prop = tree->access("/test/prop1"); + BOOST_CHECK_EQUAL(prop.get().start(), 5.0); +} + BOOST_AUTO_TEST_CASE(test_prop_subtree) { uhd::property_tree::sptr tree = uhd::property_tree::make(); -- cgit v1.2.3