1/*
2Copyright (c) 2018 Contributors as noted in the AUTHORS file
3
4This file is part of 0MQ.
5
60MQ is free software; you can redistribute it and/or modify it under
7the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation; either version 3 of the License, or
9(at your option) any later version.
10
110MQ is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "../tests/testutil.hpp"
21
22#include <ypipe.hpp>
23
24#include <unity.h>
25
26void setUp ()
27{
28}
29void tearDown ()
30{
31}
32
33void test_create ()
34{
35 zmq::ypipe_t<int, 1> ypipe;
36}
37
38void test_check_read_empty ()
39{
40 zmq::ypipe_t<int, 1> ypipe;
41 TEST_ASSERT_FALSE (ypipe.check_read ());
42}
43
44void test_read_empty ()
45{
46 zmq::ypipe_t<int, 1> ypipe;
47 int read_value = -1;
48 TEST_ASSERT_FALSE (ypipe.read (&read_value));
49 TEST_ASSERT_EQUAL (-1, read_value);
50}
51
52void test_write_complete_and_check_read_and_read ()
53{
54 const int value = 42;
55 zmq::ypipe_t<int, 1> ypipe;
56 ypipe.write (value, false);
57 TEST_ASSERT_FALSE (ypipe.check_read ());
58 int read_value = -1;
59 TEST_ASSERT_FALSE (ypipe.read (&read_value));
60 TEST_ASSERT_EQUAL_INT (-1, read_value);
61}
62
63void test_write_complete_and_flush_and_check_read_and_read ()
64{
65 const int value = 42;
66 zmq::ypipe_t<int, 1> ypipe;
67 ypipe.write (value, false);
68 ypipe.flush ();
69 TEST_ASSERT_TRUE (ypipe.check_read ());
70 int read_value = -1;
71 TEST_ASSERT_TRUE (ypipe.read (&read_value));
72 TEST_ASSERT_EQUAL_INT (value, read_value);
73}
74
75int main (void)
76{
77 setup_test_environment ();
78
79 UNITY_BEGIN ();
80 RUN_TEST (test_create);
81 RUN_TEST (test_check_read_empty);
82 RUN_TEST (test_read_empty);
83 RUN_TEST (test_write_complete_and_check_read_and_read);
84 RUN_TEST (test_write_complete_and_flush_and_check_read_and_read);
85
86 return UNITY_END ();
87}
88