Ejemplo n.º 1
0
/* Checks that SET contains the CNT strings in DATA, that its structure is
   correct, and that certain operations on SET produce the expected results. */
static void
check_string_set (struct string_set *set, const int data[], size_t cnt)
{
  size_t i;

  check (string_set_is_empty (set) == (cnt == 0));
  check (string_set_count (set) == cnt);

  for (i = 0; i < cnt; i++)
    {
      struct string_set_node *node;
      const char *s = make_string (data[i]);

      check (string_set_contains (set, s));
      check (!string_set_insert (set, s));
      check (!string_set_insert_nocopy (set, xstrdup (s)));

      node = string_set_find_node (set, s);
      check (node != NULL);
      check (!strcmp (s, string_set_node_get_string (node)));
    }

  check (!string_set_contains (set, "xxx"));
  check (string_set_find_node (set, "") == NULL);

  if (cnt == 0)
    check (string_set_first (set) == NULL);
  else
    {
      const struct string_set_node *node;
      int *data_copy;
      int left;

      data_copy = xmemdup (data, cnt * sizeof *data);
      left = cnt;
      for (node = string_set_first (set), i = 0; i < cnt;
           node = string_set_next (set, node), i++)
        {
          const char *s = string_set_node_get_string (node);
          size_t j;

          for (j = 0; j < left; j++)
            if (!strcmp (s, make_string (data_copy[j])))
              {
                data_copy[j] = data_copy[--left];
                goto next;
              }
          check_die ();

        next: ;
        }
      check (node == NULL);
      free (data_copy);
    }
}
Ejemplo n.º 2
0
static void
test_boolean_ops (void (*function)(struct string_set *a, struct string_set *b,
                                   unsigned int *a_pat, unsigned int *b_pat))
{
  enum { MAX_STRINGS = 7 };
  unsigned int a_pat, b_pat;

  for (a_pat = 0; a_pat < (1u << MAX_STRINGS); a_pat++)
    for (b_pat = 0; b_pat < (1u << MAX_STRINGS); b_pat++)
      {
        unsigned int new_a_pat = a_pat;
        unsigned int new_b_pat = b_pat;
        struct string_set a, b;
        int a_strings[MAX_STRINGS], b_strings[MAX_STRINGS];
        size_t i, n_a, n_b;

        string_set_init (&a);
        string_set_init (&b);
        for (i = 0; i < MAX_STRINGS; i++)
          {
            if (a_pat & (1u << i))
              string_set_insert (&a, make_string (i));
            if (b_pat & (1u << i))
              string_set_insert (&b, make_string (i));
          }

        function (&a, &b, &new_a_pat, &new_b_pat);

        n_a = n_b = 0;
        for (i = 0; i < MAX_STRINGS; i++)
          {
            if (new_a_pat & (1u << i))
              a_strings[n_a++] = i;
            if (new_b_pat & (1u << i))
              b_strings[n_b++] = i;
          }
        check_string_set (&a, a_strings, n_a);
        check_string_set (&b, b_strings, n_b);
        string_set_destroy (&a);
        string_set_destroy (&b);
      }
}
Ejemplo n.º 3
0
void
tsig_register_algorithms()
{
    string_set_insert("hmac-md5.sig-alg.reg.int", HMAC_MD5);
    string_set_insert("hmac-sha1.sig-alg.reg.int", HMAC_SHA1);
    string_set_insert("hmac-sha224.sig-alg.reg.int", HMAC_SHA224);
    string_set_insert("hmac-sha256.sig-alg.reg.int", HMAC_SHA256);
    string_set_insert("hmac-sha384.sig-alg.reg.int", HMAC_SHA384);
    string_set_insert("hmac-sha512.sig-alg.reg.int", HMAC_SHA512);
}
Ejemplo n.º 4
0
OBJECT * object_new( const char * string )
{
#ifdef BJAM_NO_MEM_CACHE
    int l = strlen( string );
    struct hash_item * m = (struct hash_item *)BJAM_MALLOC( sizeof(struct hash_header) + l + 1 );

    strtotal += l + 1;
    memcpy( m->data, string, l + 1 );
    m->header.magic = OBJECT_MAGIC;
    return (OBJECT *)m->data;
#else
    if ( ! strhash.data )
        string_set_init( &strhash );

    strcount_in += 1;

    return (OBJECT *)string_set_insert( &strhash, string );
#endif
}
Ejemplo n.º 5
0
OBJECT * object_new_range( char const * const string, int const size )
{
    ++strcount_in;

#ifdef BJAM_NO_MEM_CACHE
    {
        struct hash_item * const m = (struct hash_item *)BJAM_MALLOC( sizeof(
            struct hash_header ) + size + 1 );
        strtotal += size + 1;
        memcpy( m->data, string, size );
        m->data[ size ] = '\0';
        m->header.magic = OBJECT_MAGIC;
        return (OBJECT *)m->data;
    }
#else
    if ( !strhash.data )
        string_set_init( &strhash );
    return (OBJECT *)string_set_insert( &strhash, string, size );
#endif
}
Ejemplo n.º 6
0
/* Inserts the CNT strings from 0 to CNT - 1 (inclusive) into a set in the
   order specified by INSERTIONS, then deletes them in the order specified by
   DELETIONS, checking the set's contents for correctness after each
   operation.  */
static void
test_insert_delete (const int insertions[],
                    const int deletions[],
                    size_t cnt)
{
  struct string_set set;
  size_t i;

  string_set_init (&set);
  check_string_set (&set, NULL, 0);
  for (i = 0; i < cnt; i++)
    {
      check (string_set_insert (&set, make_string (insertions[i])));
      check_string_set (&set, insertions, i + 1);
    }
  for (i = 0; i < cnt; i++)
    {
      check (string_set_delete (&set, make_string (deletions[i])));
      check_string_set (&set, deletions + i + 1, cnt - i - 1);
    }
  string_set_destroy (&set);
}