aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/property_test.cpp
diff options
context:
space:
mode:
authorAaron Rossetto <aaron.rossetto@ni.com>2019-08-28 08:32:00 -0500
committerMartin Braun <martin.braun@ettus.com>2019-09-04 19:06:08 -0700
commit94592641f0647563bc4d2163805d5284a6796273 (patch)
treebaf5ae1d7605c8a6b303426c69eae6c1a9e9b61d /host/tests/property_test.cpp
parentc198cc923ef5a8b8dcc0a24ca1f2f77c631205d6 (diff)
downloaduhd-94592641f0647563bc4d2163805d5284a6796273.tar.gz
uhd-94592641f0647563bc4d2163805d5284a6796273.tar.bz2
uhd-94592641f0647563bc4d2163805d5284a6796273.zip
uhd: Check property type at access; error if mismatch
Diffstat (limited to 'host/tests/property_test.cpp')
-rw-r--r--host/tests/property_test.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/host/tests/property_test.cpp b/host/tests/property_test.cpp
index 907ca9f73..732e3ca84 100644
--- a/host/tests/property_test.cpp
+++ b/host/tests/property_test.cpp
@@ -239,7 +239,6 @@ BOOST_AUTO_TEST_CASE(test_prop_subtree)
tree_dirs2.begin(), tree_dirs2.end(), subtree2_dirs.begin(), subtree2_dirs.end());
}
-
BOOST_AUTO_TEST_CASE(test_prop_operators)
{
uhd::fs_path path1 = "/root/";
@@ -259,3 +258,22 @@ BOOST_AUTO_TEST_CASE(test_prop_operators)
path4 = path4 / x;
BOOST_CHECK_EQUAL(path4, "/root/2");
}
+
+BOOST_AUTO_TEST_CASE(test_mismatched_type_access)
+{
+ uhd::property_tree::sptr tree = uhd::property_tree::make();
+
+ // accesses of the correct type should succeed
+ tree->create<int>("/intprop");
+ tree->create<double>("/doubleprop");
+ tree->create<std::string>("/stringprop");
+ BOOST_CHECK_NO_THROW(tree->access<int>("/intprop"));
+ BOOST_CHECK_NO_THROW(tree->access<double>("/doubleprop"));
+ BOOST_CHECK_NO_THROW(tree->access<std::string>("/stringprop"));
+
+ // accesses of the incorrect type should throw an exception
+ BOOST_CHECK_THROW(tree->access<int>("/doubleprop"), uhd::runtime_error);
+ BOOST_CHECK_THROW(tree->access<double>("/stringprop"), uhd::runtime_error);
+ BOOST_CHECK_THROW(tree->access<std::string>("/intprop"), uhd::runtime_error);
+}
+