aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests
diff options
context:
space:
mode:
authorLane Kolbly <lane.kolbly@ni.com>2021-12-23 09:39:39 -0600
committerAaron Rossetto <aaron.rossetto@ni.com>2022-02-07 14:43:46 -0600
commited18ed376bcc71938ad73872148a3146814d831f (patch)
tree86056811e0643d62032a804dc6a76ff4e10028fa /host/tests
parenta7c5d70fecb7e7e37c81b0154eb3032d4d1cf6b1 (diff)
downloaduhd-ed18ed376bcc71938ad73872148a3146814d831f.tar.gz
uhd-ed18ed376bcc71938ad73872148a3146814d831f.tar.bz2
uhd-ed18ed376bcc71938ad73872148a3146814d831f.zip
host: Throw exception when accessing properties with incorrect type
Diffstat (limited to 'host/tests')
-rw-r--r--host/tests/property_test.cpp25
1 files changed, 25 insertions, 0 deletions
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 <uhd/property_tree.hpp>
+#include <uhd/types/ranges.hpp>
#include <boost/test/unit_test.hpp>
#include <exception>
#include <functional>
@@ -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<int>("/test/prop0");
+ BOOST_CHECK_THROW(tree->access<std::string>("/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<uhd::range_t>("/test/prop1");
+ uhd::range_t singleton_range(5.0);
+ tree->access<uhd::range_t>("/test/prop1").set(singleton_range);
+
+ // Check it throws a type error
+ BOOST_CHECK_THROW(tree->access<std::string>("/test/prop1"), uhd::type_error);
+
+ // Check we can access its value
+ auto& prop = tree->access<uhd::range_t>("/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();