]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/net/timer/waitable/cons.cc
1 // Copyright (C) 2015-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++14 } }
19 // { dg-add-options libatomic }
21 #include <experimental/timer>
22 #include <testsuite_hooks.h>
24 using std::experimental::net::system_timer
;
25 using std::experimental::net::io_context
;
30 bool test
__attribute__((unused
)) = false;
32 io_context ctx1
, ctx2
;
34 system_timer
timer1(ctx1
);
35 VERIFY( timer1
.get_executor() == ctx1
.get_executor() );
36 VERIFY( timer1
.expiry() == system_timer::time_point() );
38 system_timer
timer2(ctx2
);
39 VERIFY( timer2
.get_executor() == ctx2
.get_executor() );
40 VERIFY( timer2
.get_executor() != timer1
.get_executor() );
41 VERIFY( timer2
.expiry() == system_timer::time_point() );
43 system_timer
timer3(std::move(timer1
));
44 VERIFY( timer3
.get_executor() == ctx1
.get_executor() );
45 VERIFY( timer3
.expiry() == system_timer::time_point() );
46 VERIFY( timer1
.expiry() == system_timer::time_point() );
48 system_timer
timer4(std::move(timer2
));
49 VERIFY( timer4
.get_executor() == ctx2
.get_executor() );
50 VERIFY( timer4
.expiry() == system_timer::time_point() );
51 VERIFY( timer2
.expiry() == system_timer::time_point() );
57 bool test
__attribute__((unused
)) = false;
59 io_context ctx1
, ctx2
;
60 auto t1
= system_timer::clock_type::now();
61 auto t2
= t1
+ system_timer::duration(10);
63 system_timer
timer1(ctx1
, t1
);
64 VERIFY( timer1
.get_executor() == ctx1
.get_executor() );
65 VERIFY( timer1
.expiry() == t1
);
67 system_timer
timer2(ctx2
, t2
);
68 VERIFY( timer2
.get_executor() == ctx2
.get_executor() );
69 VERIFY( timer2
.get_executor() != timer1
.get_executor() );
70 VERIFY( timer2
.expiry() == t2
);
72 system_timer
timer3(std::move(timer1
));
73 VERIFY( timer3
.get_executor() == ctx1
.get_executor() );
74 VERIFY( timer3
.expiry() == t1
);
75 VERIFY( timer1
.expiry() == system_timer::time_point() );
77 system_timer
timer4(std::move(timer2
));
78 VERIFY( timer4
.get_executor() == ctx2
.get_executor() );
79 VERIFY( timer4
.expiry() == t2
);
80 VERIFY( timer2
.expiry() == system_timer::time_point() );
86 bool test
__attribute__((unused
)) = false;
88 io_context ctx1
, ctx2
;
89 auto now
= system_timer::clock_type::now();
90 auto d1
= system_timer::duration(10);
91 auto d2
= system_timer::duration(100);
93 system_timer
timer1(ctx1
, d1
);
94 VERIFY( timer1
.get_executor() == ctx1
.get_executor() );
95 VERIFY( timer1
.expiry() > now
);
97 system_timer
timer2(ctx2
, d2
);
98 VERIFY( timer2
.get_executor() == ctx2
.get_executor() );
99 VERIFY( timer2
.get_executor() != timer1
.get_executor() );
100 VERIFY( timer2
.expiry() > now
);
101 VERIFY( timer2
.expiry() != timer1
.expiry() );
103 system_timer
timer3(std::move(timer1
));
104 VERIFY( timer3
.get_executor() == ctx1
.get_executor() );
105 VERIFY( timer3
.expiry() > now
);
106 VERIFY( timer1
.expiry() == system_timer::time_point() );
108 system_timer
timer4(std::move(timer2
));
109 VERIFY( timer4
.get_executor() == ctx2
.get_executor() );
110 VERIFY( timer4
.expiry() > now
);
111 VERIFY( timer2
.expiry() == system_timer::time_point() );