END_TEST START_TEST (_add_doesnt_fit) { ret_t ret; hpack_header_table_t *table; hpack_set_t evicted_set; hpack_header_field_t field; ret = hpack_header_table_new (&table); ch_assert (ret == ret_ok); hpack_header_field_init (&field); ret = chula_buffer_ensure_size (&field.name, (size_t) (table->max_data/2)); ch_assert (ret_ok == ret); ret = chula_buffer_ensure_size (&field.value, (size_t) (table->max_data/2)); ch_assert (ret_ok == ret); for (unsigned int i=0; i<field.name.len; ++i) { ret = chula_buffer_add_char (&field.name, '0' + (i%10)); ch_assert (ret_ok == ret); ret = chula_buffer_add_char (&field.value, '9' - (i%10)); ch_assert (ret_ok == ret); } ret = hpack_header_table_add (table, &field, evicted_set); ch_assert (ret_ok == ret); hpack_set_is_full (evicted_set); /* Clean up */ hpack_header_field_mrproper (&field); hpack_header_table_free (table); }
END_TEST START_TEST (_set_max_no_table_evict_all) { ret_t ret; hpack_header_table_t *table; hpack_header_field_t field; hpack_set_t evicted; ret = hpack_header_table_new (&table); ch_assert (ret == ret_ok); hpack_header_field_init (&field); chula_buffer_add_str (&field.name, "custom-key"); chula_buffer_add_str (&field.value, "custom-header"); for (int i=0; i<10; ++i) { ret = hpack_header_table_add (table, &field, evicted); ch_assert (ret_ok == ret); ch_assert (hpack_set_is_empty(evicted)); } ret = hpack_header_table_set_max (table, 0, evicted); ch_assert (ret == ret_ok); hpack_set_is_full(evicted); ch_assert (table->max_data == 0); check_table_empty (table); hpack_header_field_mrproper (&field); hpack_header_table_free (table); }
END_TEST START_TEST (_iter_all) { hpack_set_t b_set; hpack_set_iterator_t iter; int i; int i_next; hpack_set_init (b_set, true); i = 0; hpack_set_iter_init (&iter, b_set); do { i_next = hpack_set_iter_next (&iter); if (HPACK_MAX_HEADER_TABLE_ENTRIES == i) { ch_assert (-1 == i_next); } else { ch_assert (i_next == i); } ++i; } while (-1 != i_next); /* Confirm that the original set is unaltered */ ch_assert (hpack_set_is_full (b_set)); }
END_TEST START_TEST (_is_full) { hpack_set_t b_set; hpack_set_init (b_set, true); ch_assert (hpack_set_is_full (b_set)); }
END_TEST START_TEST (_complement) { hpack_set_t b_set1; hpack_set_init (b_set1, false); hpack_set_complement (b_set1); ck_assert (hpack_set_is_full (b_set1)); hpack_set_complement (b_set1); ck_assert (hpack_set_is_empty (b_set1)); }
END_TEST START_TEST (_add_all) { ret_t ret; hpack_set_t b_set; hpack_set_init (b_set, false); for (int i=0; i < HPACK_MAX_HEADER_TABLE_ENTRIES; ++i) { ret = hpack_set_add (b_set, i); ch_assert (ret == ret_ok); } ch_assert (hpack_set_is_full (b_set)); }
END_TEST START_TEST (_union) { ret_t ret; hpack_set_t b_set1; hpack_set_t b_set2; hpack_set_t b_set3; hpack_set_init (b_set1, false); hpack_set_init (b_set2, false); hpack_set_init (b_set3, false); for (int i=0; i < HPACK_MAX_HEADER_TABLE_ENTRIES; ++i) { ret = hpack_set_add (i&1?b_set1:b_set2, i); ck_assert (ret == ret_ok); } hpack_set_union (b_set3, b_set1); hpack_set_union (b_set3, b_set2); ck_assert (hpack_set_is_full (b_set3)); }