-
Notifications
You must be signed in to change notification settings - Fork 0
/
hpack_table_test.cc
65 lines (57 loc) · 1.83 KB
/
hpack_table_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "HPACK.h"
#include "hpack_table.h"
#include "gtest/gtest.h"
TEST(find_header_test, NormalTest) {
Table *table = new Table();
int num_test = 4;
header test_headers[] = {
header("", ""),
header(":authority", ""),
header(":authority", "ami-GS"),
header("hhh", "ddd"),
};
int expect_index[] = {-1, 1, 1, -1};
bool expect_match[] = {false, true, false, false};
for (int i = 0; i < num_test; i++) {
int actual_index = 0;
bool actual_match = false;
actual_match = table->find_header(actual_index, test_headers[i]);
ASSERT_EQ(expect_match[i], actual_match);
ASSERT_EQ(expect_index[i], actual_index);
}
delete table;
}
TEST(get_header_test, NormalTest) {
Table *table = new Table();
int num_test = 2;
int test_indices[] = {1, 61};
header expect_headers[] = {
header(":authority", ""),
header("www-authenticate", ""),
};
for (int i = 0; i < num_test; i++) {
header actual_header = table->get_header(test_indices[i]);
ASSERT_EQ(expect_headers[i], actual_header);
}
delete table;
}
TEST(parse_header_test, NormalTest) {
Table *table = new Table();
int num_test = 3;
header expect_headers[] = {
header(":authority", ""),
header("www-authenticate", ""),
header("name", "val"),
};
uint8_t test_buf[] = {4, 110, 97, 109, 101, 3, 118, 97, 108};
int test_indices[] = {1, 61, 0};
bool test_indexed[] = {true, true, false};
int64_t expect_len[] = {0, 0, 9};
for (int i = 0; i < num_test; i++) {
header actual_header;
uint64_t len = table->parse_header(actual_header, test_indices[i], test_buf, test_indexed[i]);
ASSERT_EQ(expect_len[i], len);
ASSERT_EQ(expect_headers[i], actual_header);
}
delete table;
}