dburgess | 82c46ff | 2011-10-07 02:40:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Free Software Foundation, Inc. |
| 3 | * |
| 4 | * |
| 5 | * This software is distributed under the terms of the GNU Affero Public License. |
| 6 | * See the COPYING file in the main directory for details. |
| 7 | * |
| 8 | * This use of this software may be subject to additional restrictions. |
| 9 | * See the LEGAL file in the main directory for details. |
| 10 | |
| 11 | This program is free software: you can redistribute it and/or modify |
| 12 | it under the terms of the GNU Affero General Public License as published by |
| 13 | the Free Software Foundation, either version 3 of the License, or |
| 14 | (at your option) any later version. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU Affero General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU Affero General Public License |
| 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | #include "Timeval.h" |
| 30 | #include <iostream> |
Pau Espin Pedrol | 2652f2b | 2018-01-09 19:12:21 +0100 | [diff] [blame] | 31 | #include <assert.h> |
dburgess | 82c46ff | 2011-10-07 02:40:51 +0000 | [diff] [blame] | 32 | |
| 33 | using namespace std; |
| 34 | |
| 35 | int main(int argc, char *argv[]) |
| 36 | { |
dburgess | 82c46ff | 2011-10-07 02:40:51 +0000 | [diff] [blame] | 37 | Timeval then(10000); |
Pau Espin Pedrol | 2652f2b | 2018-01-09 19:12:21 +0100 | [diff] [blame] | 38 | assert(then.elapsed() == -10000); |
| 39 | cerr << then << " elapsed: " << then.elapsed() << endl; |
| 40 | double then_seconds = then.seconds(); |
| 41 | double last_now = Timeval().seconds(); |
| 42 | long last_remaining = 10000; |
| 43 | int loops = 0; |
dburgess | 82c46ff | 2011-10-07 02:40:51 +0000 | [diff] [blame] | 44 | |
| 45 | while (!then.passed()) { |
Pau Espin Pedrol | 2652f2b | 2018-01-09 19:12:21 +0100 | [diff] [blame] | 46 | double tnow = Timeval().seconds(); |
| 47 | cerr << "now: " << tnow << " then: " << then << " remaining: " << then.remaining() << endl; |
| 48 | assert(last_now <= tnow && last_remaining >= then.remaining()); |
| 49 | assert(then_seconds == then.seconds()); |
dburgess | 82c46ff | 2011-10-07 02:40:51 +0000 | [diff] [blame] | 50 | usleep(500000); |
Pau Espin Pedrol | 2652f2b | 2018-01-09 19:12:21 +0100 | [diff] [blame] | 51 | loops++; |
dburgess | 82c46ff | 2011-10-07 02:40:51 +0000 | [diff] [blame] | 52 | } |
Pau Espin Pedrol | 2652f2b | 2018-01-09 19:12:21 +0100 | [diff] [blame] | 53 | cerr << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl; |
| 54 | assert(then.remaining() <= 0); |
| 55 | assert(loops >= 18); |
| 56 | |
| 57 | printf("Done\n"); |
dburgess | 82c46ff | 2011-10-07 02:40:51 +0000 | [diff] [blame] | 58 | } |