unittest_ypipe.cpp 2.1 KB

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