コード例 #1
0
ファイル: spdylay_map_test.c プロジェクト: MacTop/spdylay
void test_spdylay_map(void)
{
  strentry foo, FOO, bar, baz, shrubbery;
  spdylay_map map;
  spdylay_map_init(&map);

  strentry_init(&foo, 1, "foo");
  strentry_init(&FOO, 1, "FOO");
  strentry_init(&bar, 2, "bar");
  strentry_init(&baz, 3, "baz");
  strentry_init(&shrubbery, 4, "shrubbery");

  CU_ASSERT(0 == spdylay_map_insert(&map, &foo.map_entry));
  CU_ASSERT(strcmp("foo", ((strentry*)spdylay_map_find(&map, 1))->str) == 0);
  CU_ASSERT(1 == spdylay_map_size(&map));

  CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT ==
            spdylay_map_insert(&map, &FOO.map_entry));

  CU_ASSERT(1 == spdylay_map_size(&map));
  CU_ASSERT(strcmp("foo", ((strentry*)spdylay_map_find(&map, 1))->str) == 0);

  CU_ASSERT(0 == spdylay_map_insert(&map, &bar.map_entry));
  CU_ASSERT(2 == spdylay_map_size(&map));

  CU_ASSERT(0 == spdylay_map_insert(&map, &baz.map_entry));
  CU_ASSERT(3 == spdylay_map_size(&map));

  CU_ASSERT(0 == spdylay_map_insert(&map, &shrubbery.map_entry));
  CU_ASSERT(4 == spdylay_map_size(&map));

  CU_ASSERT(strcmp("baz", ((strentry*)spdylay_map_find(&map, 3))->str) == 0);

  spdylay_map_remove(&map, 3);
  CU_ASSERT(3 == spdylay_map_size(&map));
  CU_ASSERT(NULL == spdylay_map_find(&map, 3));

  spdylay_map_remove(&map, 1);
  CU_ASSERT(2 == spdylay_map_size(&map));
  CU_ASSERT(NULL == spdylay_map_find(&map, 1));

  /* Erasing non-existent entry */
  spdylay_map_remove(&map, 1);
  CU_ASSERT(2 == spdylay_map_size(&map));
  CU_ASSERT(NULL == spdylay_map_find(&map, 1));

  CU_ASSERT(strcmp("bar", ((strentry*)spdylay_map_find(&map, 2))->str) == 0);
  CU_ASSERT(strcmp("shrubbery",
                   ((strentry*)spdylay_map_find(&map, 4))->str) == 0);

  spdylay_map_free(&map);
}
コード例 #2
0
ファイル: spdylay_map_test.c プロジェクト: MacTop/spdylay
void test_spdylay_map_functional(void)
{
  spdylay_map map;
  int i;

  spdylay_map_init(&map);
  for(i = 0; i < NUM_ENT; ++i) {
    strentry_init(&arr[i], i + 1, "foo");
    order[i] = i + 1;
  }
  /* insertion */
  shuffle(order, NUM_ENT);
  for(i = 0; i < NUM_ENT; ++i) {
    CU_ASSERT(0 == spdylay_map_insert(&map, &arr[order[i] - 1].map_entry));
  }
  /* traverse */
  spdylay_map_each(&map, eachfun, NULL);
  /* find */
  shuffle(order, NUM_ENT);
  for(i = 0; i < NUM_ENT; ++i) {
    spdylay_map_find(&map, order[i]);
  }
  /* remove */
  shuffle(order, NUM_ENT);
  for(i = 0; i < NUM_ENT; ++i) {
    CU_ASSERT(0 == spdylay_map_remove(&map, order[i]));
  }

  /* each_free (but no op function for testing purpose) */
  for(i = 0; i < NUM_ENT; ++i) {
    strentry_init(&arr[i], i + 1, "foo");
  }
  /* insert once again */
  for(i = 0; i < NUM_ENT; ++i) {
    CU_ASSERT(0 == spdylay_map_insert(&map, &arr[i].map_entry));
  }
  spdylay_map_each_free(&map, eachfun, NULL);
  spdylay_map_free(&map);
}
コード例 #3
0
ファイル: spdylay_map_test.c プロジェクト: MacTop/spdylay
void test_spdylay_map_each_free(void)
{
  strentry *foo = malloc(sizeof(strentry)),
    *bar = malloc(sizeof(strentry)),
    *baz = malloc(sizeof(strentry)),
    *shrubbery = malloc(sizeof(strentry));
  spdylay_map map;
  spdylay_map_init(&map);

  strentry_init(foo, 1, "foo");
  strentry_init(bar, 2, "bar");
  strentry_init(baz, 3, "baz");
  strentry_init(shrubbery, 4, "shrubbery");

  spdylay_map_insert(&map, &foo->map_entry);
  spdylay_map_insert(&map, &bar->map_entry);
  spdylay_map_insert(&map, &baz->map_entry);
  spdylay_map_insert(&map, &shrubbery->map_entry);

  spdylay_map_each_free(&map, entry_free, NULL);
  spdylay_map_free(&map);
}
コード例 #4
0
void test_spdylay_map(void)
{
  spdylay_map map;
  spdylay_map_init(&map);
  CU_ASSERT(0 == spdylay_map_insert(&map, 1, (void*)"foo"));
  CU_ASSERT(strcmp("foo", spdylay_map_find(&map, 1)) == 0);
  CU_ASSERT(1 == spdylay_map_size(&map));
  CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == spdylay_map_insert(&map, 1,
                                                               (void*)"FOO"));
  CU_ASSERT(1 == spdylay_map_size(&map));
  CU_ASSERT(strcmp("foo", spdylay_map_find(&map, 1)) == 0);
  CU_ASSERT(0 == spdylay_map_insert(&map, 2, (void*)"bar"));
  CU_ASSERT(2 == spdylay_map_size(&map));
  CU_ASSERT(0 == spdylay_map_insert(&map, 3, (void*)"baz"));
  CU_ASSERT(3 == spdylay_map_size(&map));
  CU_ASSERT(0 == spdylay_map_insert(&map, 4, (void*)"shrubbery"));
  CU_ASSERT(4 == spdylay_map_size(&map));
  CU_ASSERT(strcmp("baz", spdylay_map_find(&map, 3)) == 0);

  spdylay_map_erase(&map, 3);
  CU_ASSERT(3 == spdylay_map_size(&map));
  CU_ASSERT(NULL == spdylay_map_find(&map, 3));
  spdylay_map_erase(&map, 1);
  CU_ASSERT(2 == spdylay_map_size(&map));
  CU_ASSERT(NULL == spdylay_map_find(&map, 1));

  /* Erasing non-existent entry */
  spdylay_map_erase(&map, 1);
  CU_ASSERT(2 == spdylay_map_size(&map));
  CU_ASSERT(NULL == spdylay_map_find(&map, 1));

  CU_ASSERT(strcmp("bar", spdylay_map_find(&map, 2)) == 0);
  CU_ASSERT(strcmp("shrubbery", spdylay_map_find(&map, 4)) == 0);

  spdylay_map_free(&map);
}