aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-08-30 17:24:40 -0700
committerJosh Blum <josh@joshknows.com>2011-08-30 17:24:40 -0700
commitbe1be806d2ce576bc23c7ac62227d24fbd6800c5 (patch)
tree10bb471a28224647a431a4337ee48b22f1afaa01
parent44d397dd6147a52f0c4b90ef3c3accd971f71f57 (diff)
downloaduhd-be1be806d2ce576bc23c7ac62227d24fbd6800c5.tar.gz
uhd-be1be806d2ce576bc23c7ac62227d24fbd6800c5.tar.bz2
uhd-be1be806d2ce576bc23c7ac62227d24fbd6800c5.zip
uhd: also normalise the time spec when adding/subtracting (added unit test)
-rw-r--r--host/lib/types/time_spec.cpp12
-rw-r--r--host/tests/time_spec_test.cpp11
2 files changed, 19 insertions, 4 deletions
diff --git a/host/lib/types/time_spec.cpp b/host/lib/types/time_spec.cpp
index 0224fb6c2..e019f1ccd 100644
--- a/host/lib/types/time_spec.cpp
+++ b/host/lib/types/time_spec.cpp
@@ -128,14 +128,18 @@ double time_spec_t::get_frac_secs(void) const{
* Time spec math overloads
**********************************************************************/
time_spec_t &time_spec_t::operator+=(const time_spec_t &rhs){
- this->_full_secs += rhs.get_full_secs();
- this->_frac_secs += rhs.get_frac_secs();
+ time_spec_init(
+ this->_full_secs + rhs.get_full_secs(),
+ this->_frac_secs + rhs.get_frac_secs()
+ );
return *this;
}
time_spec_t &time_spec_t::operator-=(const time_spec_t &rhs){
- this->_full_secs -= rhs.get_full_secs();
- this->_frac_secs -= rhs.get_frac_secs();
+ time_spec_init(
+ this->_full_secs - rhs.get_full_secs(),
+ this->_frac_secs - rhs.get_frac_secs()
+ );
return *this;
}
diff --git a/host/tests/time_spec_test.cpp b/host/tests/time_spec_test.cpp
index 97e0dec21..467da5c18 100644
--- a/host/tests/time_spec_test.cpp
+++ b/host/tests/time_spec_test.cpp
@@ -85,4 +85,15 @@ BOOST_AUTO_TEST_CASE(test_time_spec_neg_values){
std::cout << "ts1 " << ts1.get_real_secs() << std::endl;
std::cout << "ts2 " << ts2.get_real_secs() << std::endl;
BOOST_CHECK(ts1 > ts2);
+
+ uhd::time_spec_t tsa(430.001083);
+ uhd::time_spec_t tsb(429.999818);
+ uhd::time_spec_t tsc(0.3);
+ uhd::time_spec_t tsd = tsa - tsb;
+ std::cout << "tsa " << tsa.get_real_secs() << std::endl;
+ std::cout << "tsb " << tsb.get_real_secs() << std::endl;
+ std::cout << "tsc " << tsc.get_real_secs() << std::endl;
+ std::cout << "tsd " << tsd.get_real_secs() << std::endl;
+ BOOST_CHECK(tsa > tsb);
+ BOOST_CHECK(tsc > tsd);
}