GPL v2.
[metaproxy-moved-to-github.git] / src / test_boost_time.cpp
1 /* $Id: test_boost_time.cpp,v 1.11 2007-05-09 21:23:09 adam Exp $
2    Copyright (c) 2005-2007, Index Data.
3
4 This file is part of Metaproxy.
5
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #include <iostream>
23
24 #include "config.hpp"
25 #include "boost/date_time/posix_time/posix_time.hpp"
26
27 #define BOOST_AUTO_TEST_MAIN
28 #include <boost/test/auto_unit_test.hpp>
29
30 using namespace boost::unit_test;
31
32
33
34 BOOST_AUTO_UNIT_TEST( testboosttime1 ) 
35 {
36
37     // test session 
38     try {
39
40         boost::posix_time::ptime now
41             = boost::posix_time::microsec_clock::local_time();
42         //std::cout << now << std::endl;
43         
44         sleep(1);
45         
46         boost::posix_time::ptime then
47             = boost::posix_time::microsec_clock::local_time();
48         //std::cout << then << std::endl;
49         
50         boost::posix_time::time_period period(now, then);
51         //std::cout << period << std::endl;
52         
53         boost::posix_time::time_duration duration = then - now;
54         //std::cout << duration << std::endl;
55         
56         BOOST_CHECK (duration.total_seconds() >= 1);
57         BOOST_CHECK (duration.fractional_seconds() > 0);
58         
59     }
60     catch (std::exception &e) {
61         std::cout << e.what() << "\n";
62         BOOST_CHECK (false);
63     }
64     catch (...) {
65         BOOST_CHECK (false);
66     }
67 }
68
69 /*
70  * Local variables:
71  * c-basic-offset: 4
72  * indent-tabs-mode: nil
73  * c-file-style: "stroustrup"
74  * End:
75  * vim: shiftwidth=4 tabstop=8 expandtab
76  */