aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/rfnoc_property_test.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-08-23 11:45:41 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:37 -0800
commitacc4dab894db1bb6285c3181548af16c1d1091f6 (patch)
treee1bc8848a5097d78e220a5b3b3b8c822147d3e93 /host/tests/rfnoc_property_test.cpp
parente6da166a179ceda0c74c4acb7eb75ea7dc4201c6 (diff)
downloaduhd-acc4dab894db1bb6285c3181548af16c1d1091f6.tar.gz
uhd-acc4dab894db1bb6285c3181548af16c1d1091f6.tar.bz2
uhd-acc4dab894db1bb6285c3181548af16c1d1091f6.zip
rfnoc: property: Add option to set properties from strings
Diffstat (limited to 'host/tests/rfnoc_property_test.cpp')
-rw-r--r--host/tests/rfnoc_property_test.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/host/tests/rfnoc_property_test.cpp b/host/tests/rfnoc_property_test.cpp
index 13ba1d4eb..7e5af20a2 100644
--- a/host/tests/rfnoc_property_test.cpp
+++ b/host/tests/rfnoc_property_test.cpp
@@ -150,3 +150,30 @@ BOOST_AUTO_TEST_CASE(test_dirtifier)
BOOST_CHECK(!prop_accessor.are_compatible(&prop_i, &dirtifier));
BOOST_CHECK(!prop_accessor.are_compatible(&dirtifier, &prop_i));
}
+
+BOOST_AUTO_TEST_CASE(test_from_str)
+{
+ prop_accessor_t prop_accessor{};
+ property_t<double> prop_d{"double_prop", 0.0, {res_source_info::USER}};
+ property_t<int> prop_i{"int_prop", 0, {res_source_info::USER}};
+ property_t<std::string> prop_s{"str_prop", "0", {res_source_info::USER}};
+ prop_accessor.set_access(prop_d, property_base_t::RW);
+ prop_accessor.set_access(prop_i, property_base_t::RW);
+ prop_accessor.set_access(prop_s, property_base_t::RW);
+
+ property_base_t* prop_base_ptr_d = static_cast<property_base_t*>(&prop_d);
+ property_base_t* prop_base_ptr_i = static_cast<property_base_t*>(&prop_i);
+ property_base_t* prop_base_ptr_s = static_cast<property_base_t*>(&prop_s);
+
+ prop_base_ptr_d->set_from_str(".25");
+ BOOST_CHECK_EQUAL(prop_d.get(), 0.25);
+
+ prop_base_ptr_i->set_from_str("23");
+ BOOST_CHECK_EQUAL(prop_i.get(), 23);
+
+ prop_base_ptr_s->set_from_str("foo");
+ BOOST_CHECK_EQUAL(prop_s.get(), "foo");
+
+ BOOST_REQUIRE_THROW(prop_base_ptr_d->set_from_str("banana"), uhd::runtime_error);
+ BOOST_REQUIRE_THROW(prop_base_ptr_i->set_from_str("potato"), uhd::runtime_error);
+}