summaryrefslogtreecommitdiffstats
path: root/test-delaypipe_hh.cc
blob: 3d1c1b00dfac00e3d323a84dcc4f1ef23305ca35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_NO_MAIN
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <boost/test/unit_test.hpp>
#include "delaypipe.hh"

BOOST_AUTO_TEST_SUITE(test_delaypipe_hh);

BOOST_AUTO_TEST_CASE(test_object_pipe) {
  ObjectPipe<int> op;
  for(int n=0; n < 100; ++n)
    op.write(n);

  int i;
  for(int n=0; n < 100; ++n) {
    bool res=op.read(&i);
    BOOST_CHECK_EQUAL(res, true);
    BOOST_CHECK_EQUAL(n, i);
  }

  op.close();
  BOOST_CHECK_EQUAL(op.read(&i), false);

};

int done=0;
BOOST_AUTO_TEST_CASE(test_delay_pipe_small) {
  done=0;
  struct Work
  {
    int i;
    void operator()()
    {
      ++done;
    }
  };
  DelayPipe<Work> 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<Work> 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();