From 4fc2f55f761d71aae1f145d5aa94ba929cc39676 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 11:34:30 +0200 Subject: Adding upstream version 1.7.3. Signed-off-by: Daniel Baumann --- test-delaypipe_hh.cc | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 test-delaypipe_hh.cc (limited to 'test-delaypipe_hh.cc') diff --git a/test-delaypipe_hh.cc b/test-delaypipe_hh.cc new file mode 100644 index 0000000..9e678ee --- /dev/null +++ b/test-delaypipe_hh.cc @@ -0,0 +1,80 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_NO_MAIN +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include "delaypipe.hh" + +BOOST_AUTO_TEST_SUITE(test_delaypipe_hh); + +BOOST_AUTO_TEST_CASE(test_object_pipe) { + ObjectPipe op; + for(int n=0; n < 100; ++n) + op.write(n); + + int i; + for(int n=0; n < 100; ++n) { + int res=op.readTimeout(&i, -1); + BOOST_CHECK_EQUAL(res, 1); + BOOST_CHECK_EQUAL(n, i); + } + + op.close(); + BOOST_CHECK_EQUAL(op.readTimeout(&i, 1), 0); + +}; + +std::atomic done = 0; +BOOST_AUTO_TEST_CASE(test_delay_pipe_small) { + done = 0; + struct Work + { + int i; + void operator()() + { + ++done; + } + }; + DelayPipe dp; + int n; + for(n=0; n < 5; ++n) { + Work w{n}; + dp.submit(w, 500); + } + BOOST_CHECK_EQUAL(done, 0); + + for(; n < 10; ++n) { + Work w{n}; + dp.submit(w, 1200); + } + sleep(1); + BOOST_CHECK_EQUAL(done, 5); + sleep(1); + BOOST_CHECK_EQUAL(done, n); + +}; + +BOOST_AUTO_TEST_CASE(test_delay_pipe_big) { + done=0; + struct Work + { + int i; + void operator()() + { + ++done; + } + }; + DelayPipe dp; + int n; + for(n=0; n < 1000000; ++n) { + Work w{n}; + dp.submit(w, 100); + } + + sleep(1); + BOOST_CHECK_EQUAL(done, n); +}; + + +BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3