test_netinfo.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Copyright (c) 2007-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #include "orconfig.h"
  4. #include "core/or/or.h"
  5. #include "trunnel/netinfo.h"
  6. #include "test/test.h"
  7. static void
  8. test_netinfo_unsupported_addr(void *arg)
  9. {
  10. const uint8_t wire_data[] =
  11. { // TIME
  12. 0x00, 0x00, 0x00, 0x01,
  13. // OTHERADDR
  14. 0x04, // ATYPE
  15. 0x04, // ALEN
  16. 0x08, 0x08, 0x08, 0x08, // AVAL
  17. 0x01, // NMYADDR
  18. 0x03, // ATYPE (unsupported)
  19. 0x05, // ALEN
  20. 'a', 'd', 'r', 'r', '!' // AVAL (unsupported)
  21. };
  22. (void)arg;
  23. netinfo_cell_t *parsed_cell = NULL;
  24. ssize_t parsed = netinfo_cell_parse(&parsed_cell, wire_data,
  25. sizeof(wire_data));
  26. tt_assert(parsed == sizeof(wire_data));
  27. netinfo_addr_t *addr = netinfo_cell_get_my_addrs(parsed_cell, 0);
  28. tt_assert(addr);
  29. tt_int_op(3, OP_EQ, netinfo_addr_get_addr_type(addr));
  30. tt_int_op(5, OP_EQ, netinfo_addr_get_len(addr));
  31. done:
  32. netinfo_cell_free(parsed_cell);
  33. }
  34. struct testcase_t netinfo_tests[] = {
  35. { "unsupported_addr", test_netinfo_unsupported_addr, 0, NULL, NULL },
  36. END_OF_TESTCASES
  37. };