test_address_tipc.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Copyright (c) 2007-2018 Contributors as noted in the AUTHORS file
  3. This file is part of libzmq, the ZeroMQ core engine in C++.
  4. libzmq is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU Lesser General Public License (LGPL) as published
  6. by the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. As a special exception, the Contributors give you permission to link
  9. this library with independent modules to produce an executable,
  10. regardless of the license terms of these independent modules, and to
  11. copy and distribute the resulting executable under terms of your choice,
  12. provided that you also meet, for each linked independent module, the
  13. terms and conditions of the license of that module. An independent
  14. module is a module which is not derived from or based on this library.
  15. If you modify this library, you must extend this exception to your
  16. version of the library.
  17. libzmq is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  20. License for more details.
  21. You should have received a copy of the GNU Lesser General Public License
  22. along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #include "testutil.hpp"
  25. #include "testutil_unity.hpp"
  26. SETUP_TEARDOWN_TESTCONTEXT
  27. void test_tipc_port_name_and_domain ()
  28. {
  29. // test Port Name addressing
  30. void *sb = test_context_socket (ZMQ_REP);
  31. TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tipc://{5560,0,0}"));
  32. void *sc = test_context_socket (ZMQ_REQ);
  33. TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, "tipc://{5560,0}@0.0.0"));
  34. bounce (sb, sc);
  35. test_context_socket_close (sc);
  36. test_context_socket_close (sb);
  37. }
  38. void test_tipc_port_identity ()
  39. {
  40. char endpoint[256];
  41. unsigned int z, c, n, ref;
  42. void *sb = test_context_socket (ZMQ_REP);
  43. void *sc = test_context_socket (ZMQ_REQ);
  44. // Test binding to random Port Identity and
  45. // test resolving assigned address, should return a properly formatted string
  46. bind_loopback_tipc (sb, endpoint, sizeof endpoint);
  47. int rc = sscanf (&endpoint[0], "tipc://<%u.%u.%u:%u>", &z, &c, &n, &ref);
  48. TEST_ASSERT_EQUAL_INT (4, rc);
  49. TEST_ASSERT_NOT_EQUAL_MESSAGE (
  50. 0, ref, "tipc port number must not be 0 after random assignment");
  51. TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint));
  52. bounce (sb, sc);
  53. test_context_socket_close (sc);
  54. test_context_socket_close (sb);
  55. }
  56. void test_tipc_bad_addresses ()
  57. {
  58. // Test Port Name addressing
  59. void *sb = test_context_socket (ZMQ_REP);
  60. // Test binding to a fixed address, should fail
  61. TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_bind (sb, "tipc://<1.2.3:123123>"));
  62. // Test connecting to random identity, should fail
  63. TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_connect (sb, "tipc://<*>"));
  64. // Clean up
  65. test_context_socket_close (sb);
  66. }
  67. int main ()
  68. {
  69. setup_test_environment ();
  70. if (!is_tipc_available ()) {
  71. printf ("TIPC environment unavailable, skipping test\n");
  72. return 77;
  73. }
  74. UNITY_BEGIN ();
  75. RUN_TEST (test_tipc_port_name_and_domain);
  76. RUN_TEST (test_tipc_port_identity);
  77. RUN_TEST (test_tipc_bad_addresses);
  78. return UNITY_END ();
  79. }