test_function (const char *fname,
               int (*func) (int type,
                            unsigned char *answer, int answer_length))
{
  unsigned char buf[512];
  for (int tcp = 0; tcp < 2; ++tcp)
    {
      force_tcp = tcp;
      for (unsigned int type = 1; type <= 65535; ++type)
        {
          if (test_verbose)
            printf ("info: sending QTYPE %d with %s (tcp=%d)\n",
                    type, fname, tcp);
          int ret = func (type, buf, sizeof (buf));
          if (ret != 47)
            FAIL_EXIT1 ("%s tcp=%d qtype=%d return value %d",
                        fname,tcp, type, ret);
          /* One question, one answer record.  */
          TEST_VERIFY (memcmp (buf + 4, "\0\1\0\1\0\0\0\0", 8) == 0);
          /* Question section.  */
          static const char qname[] = "\3www\7example\3com";
          size_t qname_length = sizeof (qname);
          TEST_VERIFY (memcmp (buf + 12, qname, qname_length) == 0);
          /* RDATA part of answer.  */
          uint16_t type16 = type;
          TEST_VERIFY (memcmp (buf + ret - 2, &type16, sizeof (type16)) == 0);
        }
    }

  TEST_VERIFY (func (-1, buf, sizeof (buf) == -1));
  TEST_VERIFY (func (65536, buf, sizeof (buf) == -1));
}
test_function (const char *fname,
               int (*func) (int type,
                            unsigned char *answer, int answer_length))
{
  unsigned char buf[512];
  for (int tcp = 0; tcp < 2; ++tcp)
    {
      force_tcp = tcp;
      for (unsigned int type = 1; type <= 65535; ++type)
        {
          if (test_verbose)
            printf ("info: sending QTYPE %d with %s (tcp=%d)\n",
                    type, fname, tcp);
          int ret = func (type, buf, sizeof (buf));
          if (ret != 47)
            FAIL_EXIT1 ("%s tcp=%d qtype=%d return value %d",
                        fname,tcp, type, ret);
           
          TEST_VERIFY (memcmp (buf + 4, "\0\1\0\1\0\0\0\0", 8) == 0);
           
          static const char qname[] = "\3www\7example\3com";
          size_t qname_length = sizeof (qname);
          TEST_VERIFY (memcmp (buf + 12, qname, qname_length) == 0);
           
          uint16_t type16 = type;
          TEST_VERIFY (memcmp (buf + ret - 2, &type16, sizeof (type16)) == 0);
        }
    }

  TEST_VERIFY (func (-1, buf, sizeof (buf) == -1));
  TEST_VERIFY (func (65536, buf, sizeof (buf) == -1));
}