Esempio n. 1
0
void test_art_insert_delete(void) {
  art_tree t;
  int res = art_tree_init(&t);
  int len;
  char buf[512];
  FILE *f = fopen("thirdparty/libart/tests/words.txt", "r");

  uintptr_t line = 1, nlines;
  fail_unless(res == 0);
  while (fgets(buf, sizeof buf, f)) {
    len = (int)strlen(buf);
    buf[len - 1] = '\0';
    if (art_insert(&t, (unsigned char *)buf, len, (void *)line)) {
      fail("art_insert didn't return NULL");
    }
    line++;
  }

  nlines = line - 1;

  // Seek back to the start
  fseek(f, 0, SEEK_SET);

  // Search for each line
  line = 1;
  while (fgets(buf, sizeof buf, f)) {
    uintptr_t val;
    len = (int)strlen(buf);
    buf[len - 1] = '\0';

    // Search first, ensure all entries still
    // visible
    val = (uintptr_t)art_search(&t, (unsigned char *)buf, len);
    if (line != val) {
      fail("Line: %d Val: %" PRIuPTR " Str: %s", line, val, buf);
    }

    // Delete, should get lineno back
    val = (uintptr_t)art_delete(&t, (unsigned char *)buf, len);
    if (line != val) {
      fail("Line: %d Val: %" PRIuPTR " Str: %s", line, val, buf);
    }

    // Check the size
    if (art_size(&t) != nlines - line) {
      fail("bad size after delete");
    }
    line++;
  }

  // Check the minimum and maximum
  fail_unless(!art_minimum(&t));
  fail_unless(!art_maximum(&t));

  res = art_tree_destroy(&t);
  fail_unless(res == 0);
}
Esempio n. 2
0
END_TEST

START_TEST(test_art_insert_delete)
{
    art_tree t;
    int res = art_tree_init(&t);
    fail_unless(res == 0);

    int len;
    char buf[512];
    FILE *f = fopen("tests/words.txt", "r");

    uintptr_t line = 1, nlines;
    while (fgets(buf, sizeof buf, f)) {
        len = strlen(buf);
        buf[len-1] = '\0';
        fail_unless(NULL ==
            art_insert(&t, (unsigned char*)buf, len, (void*)line));
        line++;
    }

    nlines = line - 1;

    // Seek back to the start
    fseek(f, 0, SEEK_SET);

    // Search for each line
    line = 1;
    while (fgets(buf, sizeof buf, f)) {
        len = strlen(buf);
        buf[len-1] = '\0';

        // Search first, ensure all entries still
        // visible
        uintptr_t val = (uintptr_t)art_search(&t, (unsigned char*)buf, len);
	fail_unless(line == val, "Line: %d Val: %" PRIuPTR " Str: %s\n", line,
	    val, buf);

        // Delete, should get lineno back
        val = (uintptr_t)art_delete(&t, (unsigned char*)buf, len);
	fail_unless(line == val, "Line: %d Val: %" PRIuPTR " Str: %s\n", line,
	    val, buf);

        // Check the size
        fail_unless(art_size(&t) == nlines - line);
        line++;
    }

    // Check the minimum and maximum
    fail_unless(!art_minimum(&t));
    fail_unless(!art_maximum(&t));

    res = art_tree_destroy(&t);
    fail_unless(res == 0);
}
Esempio n. 3
0
void test_art_insert_search_uuid(void) {
  art_tree t;
  art_leaf *l;
  int res = art_tree_init(&t);
  int len;
  char buf[512];
  FILE *f = fopen("thirdparty/libart/tests/uuid.txt", "r");
  uintptr_t line = 1;

  fail_unless(res == 0);
  while (fgets(buf, sizeof buf, f)) {
    len = (int)strlen(buf);
    buf[len - 1] = '\0';
    if (art_insert(&t, (unsigned char *)buf, len, (void *)line)) {
      fail("art_insert didn't return NULL");
    }
    line++;
  }

  // Seek back to the start
  fseek(f, 0, SEEK_SET);

  // Search for each line
  line = 1;
  while (fgets(buf, sizeof buf, f)) {
    uintptr_t val;
    len = (int)strlen(buf);
    buf[len - 1] = '\0';

    val = (uintptr_t)art_search(&t, (unsigned char *)buf, len);
    if (line != val) {
      fail("Line: %d Val: %" PRIuPTR " Str: %s\n", line, val, buf);
    }
    line++;
  }

  // Check the minimum
  l = art_minimum(&t);
  diag("minimum is %s", l->key);
  fail_unless(
      l && strcmp((char *)l->key, "00026bda-e0ea-4cda-8245-522764e9f325") == 0);

  // Check the maximum
  l = art_maximum(&t);
  diag("maximum is %s", l->key);
  fail_unless(
      l && strcmp((char *)l->key, "ffffcb46-a92e-4822-82af-a7190f9c1ec5") == 0);

  res = art_tree_destroy(&t);
  fail_unless(res == 0);
}
Esempio n. 4
0
void test_art_insert_search(void) {
  art_tree t;
  int res = art_tree_init(&t);
  int len;
  char buf[512];
  FILE *f = fopen("thirdparty/libart/tests/words.txt", "r");
  uintptr_t line = 1;
  art_leaf *l;

  fail_unless(res == 0);
  while (fgets(buf, sizeof buf, f)) {
    len = (int)strlen(buf);
    buf[len - 1] = '\0';
    if (art_insert(&t, (unsigned char *)buf, len, (void *)line)) {
      fail("art_insert didn't return NULL");
    }
    line++;
  }

  // Seek back to the start
  fseek(f, 0, SEEK_SET);

  // Search for each line
  line = 1;
  while (fgets(buf, sizeof buf, f)) {
    len = (int)strlen(buf);
    buf[len - 1] = '\0';

    {
      uintptr_t val = (uintptr_t)art_search(&t, (unsigned char *)buf, len);
      if (line != val) {
        fail("Line: %d Val: %" PRIuPTR " Str: %s", line, val, buf);
      }
    }
    line++;
  }

  // Check the minimum
  l = art_minimum(&t);
  fail_unless(l && strcmp((char *)l->key, "A") == 0);

  // Check the maximum
  l = art_maximum(&t);
  fail_unless(l && strcmp((char *)l->key, "zythum") == 0);

  res = art_tree_destroy(&t);
  fail_unless(res == 0);
}
Esempio n. 5
0
END_TEST

START_TEST(test_art_insert_search)
{
    art_tree t;
    int res = art_tree_init(&t);
    fail_unless(res == 0);

    int len;
    char buf[512];
    FILE *f = fopen("tests/words.txt", "r");

    uintptr_t line = 1;
    while (fgets(buf, sizeof buf, f)) {
        len = strlen(buf);
        buf[len-1] = '\0';
        fail_unless(NULL ==
            art_insert(&t, (unsigned char*)buf, len, (void*)line));
        line++;
    }

    // Seek back to the start
    fseek(f, 0, SEEK_SET);

    // Search for each line
    line = 1;
    while (fgets(buf, sizeof buf, f)) {
        len = strlen(buf);
        buf[len-1] = '\0';

        uintptr_t val = (uintptr_t)art_search(&t, (unsigned char*)buf, len);
	fail_unless(line == val, "Line: %d Val: %" PRIuPTR " Str: %s\n", line,
	    val, buf);
        line++;
    }

    // Check the minimum
    art_leaf *l = art_minimum(&t);
    fail_unless(l && strcmp((char*)l->key, "A") == 0);

    // Check the maximum
    l = art_maximum(&t);
    fail_unless(l && strcmp((char*)l->key, "zythum") == 0);

    res = art_tree_destroy(&t);
    fail_unless(res == 0);
}
Esempio n. 6
0
END_TEST

START_TEST(test_art_insert_search_uuid)
{
    art_tree t;
    int res = art_tree_init(&t);
    fail_unless(res == 0);

    int len;
    char buf[512];
    FILE *f = fopen("tests/uuid.txt", "r");

    uintptr_t line = 1;
    while (fgets(buf, sizeof buf, f)) {
        len = strlen(buf);
        buf[len-1] = '\0';
        fail_unless(NULL ==
            art_insert(&t, (unsigned char*)buf, len, (void*)line));
        line++;
    }

    // Seek back to the start
    fseek(f, 0, SEEK_SET);

    // Search for each line
    line = 1;
    while (fgets(buf, sizeof buf, f)) {
        len = strlen(buf);
        buf[len-1] = '\0';

        uintptr_t val = (uintptr_t)art_search(&t, (unsigned char*)buf, len);
	fail_unless(line == val, "Line: %d Val: %" PRIuPTR " Str: %s\n", line,
	    val, buf);
        line++;
    }

    // Check the minimum
    art_leaf *l = art_minimum(&t);
    fail_unless(l && strcmp((char*)l->key, "00026bda-e0ea-4cda-8245-522764e9f325") == 0);

    // Check the maximum
    l = art_maximum(&t);
    fail_unless(l && strcmp((char*)l->key, "ffffcb46-a92e-4822-82af-a7190f9c1ec5") == 0);

    res = art_tree_destroy(&t);
    fail_unless(res == 0);
}