Exemple #1
0
/* Count the number of arguments. */
int count_args (const char * input)
{
  const char * p;
  int argc = 0;
  p = input;
  while (*p) {
    SKIP (p);
    if (WANT (p)) {
      argc++;
      while (WANT (p)) p++;
      }
  }
  return argc;
}
Exemple #2
0
int copy_args (const char * input, int argc, char ** argv)
{
  int i = 0;
  const char *p;
  p = input;
  while (*p) {
    SKIP (p);
    if (WANT (p)) {
      const char* end = p;
      char* copy;
      while (WANT (end)) end++;
      copy = argv[i] = (char *)malloc (end - p + 1);
      if (! argv[i]) return -1;
      while (WANT (p)) *copy++ = *p++;
      *copy = 0;
      i++;
    }
  }
  if (i != argc) return -1;
  return 0;
}
static int
check ()
{
  char buf[128];
  char *r;
  char *b;
  struct GNUNET_TIME_Absolute at;
  const char *hdir;

  sprintf (buf, "4 %s", _( /* size unit */ "b"));
  b = GNUNET_STRINGS_byte_size_fancy (4);
  WANT (buf, b);
  sprintf (buf, "10 %s", _( /* size unit */ "KiB"));
  b = GNUNET_STRINGS_byte_size_fancy (10240);
  WANT (buf, b);
  sprintf (buf, "10 %s", _( /* size unit */ "TiB"));
  b = GNUNET_STRINGS_byte_size_fancy (10240LL * 1024LL * 1024LL * 1024LL);
  WANT (buf, b);
  sprintf (buf, "4 %s", _( /* time unit */ "ms"));
  b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
                                              (GNUNET_TIME_UNIT_MILLISECONDS,
                                               4));
  WANT (buf, b);
  sprintf (buf, "7 %s", _( /* time unit */ "s"));
  b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
                                              (GNUNET_TIME_UNIT_MILLISECONDS,
                                               7 * 1000));
  WANT (buf, b);
  sprintf (buf, "7 %s", _( /* time unit */ "h"));
  b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
                                              (GNUNET_TIME_UNIT_MILLISECONDS,
                                               7 * 60 * 60 * 1000));
  WANT (buf, b);
#ifndef MINGW
  hdir = getenv ("HOME");
#else
  hdir = getenv ("USERPROFILE");
#endif
  GNUNET_snprintf (buf, sizeof (buf), "%s%s", hdir, DIR_SEPARATOR_STR);
  b = GNUNET_STRINGS_filename_expand ("~");
  GNUNET_assert (b != NULL);
  WANT (buf, b);
  GNUNET_STRINGS_buffer_fill (buf, sizeof (buf), 3, "a", "btx", "c");
  WANTB ("a\0btx\0c", buf, 8);
  if (6 != GNUNET_STRINGS_buffer_tokenize (buf, sizeof (buf), 2, &r, &b))
    return 1;
  r = GNUNET_strdup (r);
  WANT ("a", r);
  b = GNUNET_strdup (b);
  WANT ("btx", b);
  if (0 != GNUNET_STRINGS_buffer_tokenize (buf, 2, 2, &r, &b))
    return 1;
  at.abs_value = 5000;
  r = GNUNET_STRINGS_absolute_time_to_string (at);
  /* r should be something like "Wed Dec 31 17:00:05 1969"
   * where the details of the day and hour depend on the timezone;
   * however, the "0:05 19" should always be there; hence: */
  if (NULL == strstr (r, "0:05 19"))
  {
    FPRINTF (stderr, "Got %s\n", r);
    GNUNET_break (0);
    GNUNET_free (r);
    return 1;
  }
  GNUNET_free (r);
  b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII");
  WANT ("TEST", b);
#if ENABLE_NLS && HAVE_ICONV
  GNUNET_log_skip (2, GNUNET_NO);
  b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "unknown");
  GNUNET_log_skip (0, GNUNET_YES);
  WANT ("TEST", b);
#endif
  return 0;
}
Exemple #4
0
static void dotest(const char *input) {
  adns_sockaddr ours;
  socklen_t socklen;
  struct addrinfo aip;
  struct addrinfo *air=0;
  char ourbuf[ADNS_ADDR2TEXT_BUFLEN];
  char theirbuf[ADNS_ADDR2TEXT_BUFLEN];

  memset(&ours,0,sizeof(ours));

  socklen= sizeof(ours);
  int our_r= adns_text2addr(input,PORT,0,&ours.sa,&socklen);

  memset(&aip,0,sizeof(aip));
  aip.ai_flags= AI_NUMERICHOST|AI_NUMERICSERV;
  aip.ai_socktype= SOCK_DGRAM;
  aip.ai_protocol= IPPROTO_UDP;
  air= 0;
  int libc_r= getaddrinfo(input,STRING(PORT),&aip,&air);
  printf("`%s': us %s; libc %s, air=%p",
	 input, strerror(our_r), libc_r ? gai_strerror(libc_r) : "0", air);
  if (air)
    printf(" .family=%d .socklen=%ld .addr=%p .next=%p",
	   air->ai_family, (long)air->ai_addrlen, air->ai_addr, air->ai_next);
  printf(":");

  if (libc_r==EAI_NONAME && !air) {
    if (strchr(input,'%') && (our_r==ENOSYS || our_r==ENXIO)) {
      printf(" bad-scope");
      goto ok;
    }
    if (strchr(input,'%') && our_r==ENOSYS) {
      printf(" bad-scope");
      goto ok;
    }
    if (our_r==EINVAL) {
      printf(" invalid");
      goto ok;
    }
  }
  printf(" valid");

#define FAIL do{ printf(" | FAIL\n"); fails++; }while(0)
#define WANT(x) if (!(x)) { printf(" not %s",STRING(x)); FAIL; return; } else;

  WANT(!our_r);
  WANT(!libc_r);
  WANT(air);
  WANT(air->ai_addr);
  WANT(!air->ai_next);
  if (air->ai_addrlen!=socklen || memcmp(&ours,air->ai_addr,socklen)) {
    printf(" mismatch");
    FAIL;
    dump("ours",&ours.sa,socklen);
    dump("libc",air->ai_addr,air->ai_addrlen);
    return;
  }

  printf(" |");

  int ourbuflen= sizeof(ourbuf);
  int ourport;
  our_r= adns_addr2text(&ours.sa,0, ourbuf,&ourbuflen, &ourport);

  printf(" us %s",strerror(our_r));
  if (!our_r)
    printf(" `%s'",ourbuf);

  size_t theirbuflen= sizeof(theirbuf);
  libc_r= getnameinfo(&ours.sa,socklen, theirbuf,theirbuflen, 0,0,
		      NI_NUMERICHOST|NI_NUMERICSERV);
  printf("; libc %s", libc_r ? gai_strerror(libc_r) : "0");
  if (!libc_r)
    printf(" `%s'",theirbuf);

  printf(":");

  WANT(!our_r);
  WANT(!libc_r);
  WANT(ourport==PORT);
  if (strcmp(ourbuf,theirbuf)) {
    printf(" mismatch");
    FAIL;
    return;
  }

 ok:
  printf(" | PASS\n");
}