aboutsummaryrefslogtreecommitdiffstats
path: root/host/test/gain_handler_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/test/gain_handler_test.cpp')
-rw-r--r--host/test/gain_handler_test.cpp80
1 files changed, 32 insertions, 48 deletions
diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp
index 9a6a50dab..51497b741 100644
--- a/host/test/gain_handler_test.cpp
+++ b/host/test/gain_handler_test.cpp
@@ -25,10 +25,8 @@
using namespace uhd;
enum prop_t{
- PROP_GAIN,
- PROP_GAIN_MIN,
- PROP_GAIN_MAX,
- PROP_GAIN_STEP,
+ PROP_GAIN_VALUE,
+ PROP_GAIN_RANGE,
PROP_GAIN_NAMES
};
@@ -36,24 +34,19 @@ class gainful_obj : public wax::obj{
public:
gainful_obj(void){
//initialize gain props struct
- gain_handler::gain_props_t gain_props;
- gain_props.gain_val_prop = PROP_GAIN;
- gain_props.gain_min_prop = PROP_GAIN_MIN;
- gain_props.gain_max_prop = PROP_GAIN_MAX;
- gain_props.gain_step_prop = PROP_GAIN_STEP;
- gain_props.gain_names_prop = PROP_GAIN_NAMES;
+ gain_handler::props_t gain_props;
+ gain_props.value = PROP_GAIN_VALUE;
+ gain_props.range = PROP_GAIN_RANGE;
+ gain_props.names = PROP_GAIN_NAMES;
//make a new gain handler
_gain_handler = gain_handler::make(
- this->get_link(), gain_props, boost::bind(&gain_handler::is_equal<prop_t>, _1, _2)
+ this->get_link(), gain_props,
+ boost::bind(&gain_handler::is_equal<prop_t>, _1, _2)
);
- _gains["g0"] = 0;
- _gains["g1"] = 0;
- _gains_min["g0"] = -10;
- _gains_min["g1"] = 0;
- _gains_max["g0"] = 0;
- _gains_max["g1"] = 100;
- _gains_step["g0"] = .1;
- _gains_step["g1"] = 1.5;
+ _gain_values["g0"] = 0;
+ _gain_values["g1"] = 0;
+ _gain_ranges["g0"] = gain_range_t(-10, 0, .1);
+ _gain_ranges["g1"] = gain_range_t(0, 100, 1.5);
}
~gainful_obj(void){}
@@ -67,24 +60,16 @@ private:
//handle the get request conditioned on the key
switch(wax::cast<prop_t>(key)){
- case PROP_GAIN:
- val = _gains[name];
+ case PROP_GAIN_VALUE:
+ val = _gain_values[name];
return;
- case PROP_GAIN_MIN:
- val = _gains_min[name];
- return;
-
- case PROP_GAIN_MAX:
- val = _gains_max[name];
- return;
-
- case PROP_GAIN_STEP:
- val = _gains_step[name];
+ case PROP_GAIN_RANGE:
+ val = _gain_ranges[name];
return;
case PROP_GAIN_NAMES:
- val = prop_names_t(_gains.get_keys());
+ val = _gain_values.get_keys();
return;
}
}
@@ -97,23 +82,19 @@ private:
//handle the get request conditioned on the key
switch(wax::cast<prop_t>(key)){
- case PROP_GAIN:
- _gains[name] = wax::cast<gain_t>(val);
+ case PROP_GAIN_VALUE:
+ _gain_values[name] = wax::cast<gain_t>(val);
return;
- case PROP_GAIN_MIN:
- case PROP_GAIN_MAX:
- case PROP_GAIN_STEP:
+ case PROP_GAIN_RANGE:
case PROP_GAIN_NAMES:
throw std::runtime_error("cannot set this property");
}
}
gain_handler::sptr _gain_handler;
- uhd::dict<std::string, gain_t> _gains;
- uhd::dict<std::string, gain_t> _gains_min;
- uhd::dict<std::string, gain_t> _gains_max;
- uhd::dict<std::string, gain_t> _gains_step;
+ uhd::dict<std::string, gain_t> _gain_values;
+ uhd::dict<std::string, gain_range_t> _gain_ranges;
};
@@ -122,17 +103,20 @@ BOOST_AUTO_TEST_CASE(test_gain_handler){
gainful_obj go0;
BOOST_CHECK_THROW(
- wax::cast<gain_t>(go0[named_prop_t(PROP_GAIN, "fail")]),
+ wax::cast<gain_t>(go0[named_prop_t(PROP_GAIN_VALUE, "fail")]),
std::exception
);
std::cout << "verifying the overall min, max, step" << std::endl;
- BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_MIN]), gain_t(-10));
- BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_MAX]), gain_t(100));
- BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_STEP]), gain_t(1.5));
+ gain_t gain_min, gain_max, gain_step;
+ boost::tie(gain_min, gain_max, gain_step) = \
+ wax::cast<gain_range_t>(go0[PROP_GAIN_RANGE]);
+ BOOST_CHECK_EQUAL(gain_min, gain_t(-10));
+ BOOST_CHECK_EQUAL(gain_max, gain_t(100));
+ BOOST_CHECK_EQUAL(gain_step, gain_t(1.5));
std::cout << "verifying the overall gain" << std::endl;
- go0[named_prop_t(PROP_GAIN, "g0")] = gain_t(-5);
- go0[named_prop_t(PROP_GAIN, "g1")] = gain_t(30);
- BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN]), gain_t(25));
+ go0[named_prop_t(PROP_GAIN_VALUE, "g0")] = gain_t(-5);
+ go0[named_prop_t(PROP_GAIN_VALUE, "g1")] = gain_t(30);
+ BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_VALUE]), gain_t(25));
}