d48bbd5aaf7f9bdb7c6f5aceb1ce9b4151ff119f
[metaproxy-moved-to-github.git] / src / test_boost_time.cpp
1 #include <iostream>
2
3 #include "config.hpp"
4 #include "boost/date_time/posix_time/posix_time.hpp"
5
6 #define BOOST_AUTO_TEST_MAIN
7 #include <boost/test/auto_unit_test.hpp>
8
9 using namespace boost::unit_test;
10
11
12
13 BOOST_AUTO_TEST_CASE( testboosttime1 ) 
14 {
15
16     // test session 
17     try {
18
19         boost::posix_time::ptime now
20             = boost::posix_time::microsec_clock::local_time();
21         //std::cout << now << std::endl;
22         
23         sleep(1);
24         
25         boost::posix_time::ptime then
26             = boost::posix_time::microsec_clock::local_time();
27         //std::cout << then << std::endl;
28         
29         boost::posix_time::time_period period(now, then);
30         //std::cout << period << std::endl;
31         
32         boost::posix_time::time_duration duration = then - now;
33         //std::cout << duration << std::endl;
34         
35         BOOST_CHECK (duration.total_seconds() == 1);
36         BOOST_CHECK (duration.fractional_seconds() > 0);
37         
38     }
39     catch (std::exception &e) {
40         std::cout << e.what() << "\n";
41         BOOST_CHECK (false);
42     }
43     catch (...) {
44         BOOST_CHECK (false);
45     }
46 }
47
48 /*
49  * Local variables:
50  * c-basic-offset: 4
51  * indent-tabs-mode: nil
52  * End:
53  * vim: shiftwidth=4 tabstop=8 expandtab
54  */