Add test for nghttp2_nv_array_from_cstr
This commit is contained in:
parent
b7ff05c4c6
commit
0000d3e7f9
|
@ -697,7 +697,8 @@ ssize_t nghttp2_nv_array_from_cstr(nghttp2_nv **nva_ptr, const char **nv)
|
||||||
buflen += len;
|
buflen += len;
|
||||||
}
|
}
|
||||||
nvlen = i/2;
|
nvlen = i/2;
|
||||||
if(nvlen == 0) {
|
/* If all name/value pair is 0-length, remove them */
|
||||||
|
if(nvlen == 0 || buflen == 0) {
|
||||||
*nva_ptr = NULL;
|
*nva_ptr = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,8 @@ int main(int argc, char* argv[])
|
||||||
test_nghttp2_frame_pack_goaway) ||
|
test_nghttp2_frame_pack_goaway) ||
|
||||||
!CU_add_test(pSuite, "frame_pack_window_update",
|
!CU_add_test(pSuite, "frame_pack_window_update",
|
||||||
test_nghttp2_frame_pack_window_update) ||
|
test_nghttp2_frame_pack_window_update) ||
|
||||||
|
!CU_add_test(pSuite, "nv_array_from_cstr",
|
||||||
|
test_nghttp2_nv_array_from_cstr) ||
|
||||||
!CU_add_test(pSuite, "hd_deflate", test_nghttp2_hd_deflate) ||
|
!CU_add_test(pSuite, "hd_deflate", test_nghttp2_hd_deflate) ||
|
||||||
!CU_add_test(pSuite, "hd_inflate_indname_inc",
|
!CU_add_test(pSuite, "hd_inflate_indname_inc",
|
||||||
test_nghttp2_hd_inflate_indname_inc) ||
|
test_nghttp2_hd_inflate_indname_inc) ||
|
||||||
|
|
|
@ -334,3 +334,45 @@ void test_nghttp2_frame_pack_window_update(void)
|
||||||
nghttp2_frame_window_update_free(&oframe);
|
nghttp2_frame_window_update_free(&oframe);
|
||||||
nghttp2_frame_window_update_free(&frame);
|
nghttp2_frame_window_update_free(&frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_nghttp2_nv_array_from_cstr(void)
|
||||||
|
{
|
||||||
|
const char *empty[] = {NULL};
|
||||||
|
const char *emptynv[] = {"", "", "", "", NULL};
|
||||||
|
const char *nv[] = {"alpha", "bravo", "charlie", "delta", NULL};
|
||||||
|
const char *bignv[] = {"echo", NULL, NULL};
|
||||||
|
size_t bigvallen = 64*1024;
|
||||||
|
char *bigval = malloc(bigvallen+1);
|
||||||
|
nghttp2_nv *nva;
|
||||||
|
ssize_t rv;
|
||||||
|
|
||||||
|
memset(bigval, '0', bigvallen);
|
||||||
|
bigval[bigvallen] = '\0';
|
||||||
|
bignv[1] = bigval;
|
||||||
|
|
||||||
|
rv = nghttp2_nv_array_from_cstr(&nva, empty);
|
||||||
|
CU_ASSERT(0 == rv);
|
||||||
|
CU_ASSERT(NULL == nva);
|
||||||
|
|
||||||
|
rv = nghttp2_nv_array_from_cstr(&nva, emptynv);
|
||||||
|
CU_ASSERT(0 == rv);
|
||||||
|
CU_ASSERT(NULL == nva);
|
||||||
|
|
||||||
|
rv = nghttp2_nv_array_from_cstr(&nva, nv);
|
||||||
|
CU_ASSERT(2 == rv);
|
||||||
|
CU_ASSERT(nva[0].namelen == 5);
|
||||||
|
CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5));
|
||||||
|
CU_ASSERT(nva[0].valuelen = 5);
|
||||||
|
CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5));
|
||||||
|
CU_ASSERT(nva[1].namelen == 7);
|
||||||
|
CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7));
|
||||||
|
CU_ASSERT(nva[1].valuelen == 5);
|
||||||
|
CU_ASSERT(0 == memcmp("delta", nva[1].value, 5));
|
||||||
|
|
||||||
|
nghttp2_nv_array_del(nva);
|
||||||
|
|
||||||
|
rv = nghttp2_nv_array_from_cstr(&nva, bignv);
|
||||||
|
CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv);
|
||||||
|
|
||||||
|
free(bigval);
|
||||||
|
}
|
||||||
|
|
|
@ -36,5 +36,6 @@ void test_nghttp2_frame_pack_settings(void);
|
||||||
void test_nghttp2_frame_pack_ping(void);
|
void test_nghttp2_frame_pack_ping(void);
|
||||||
void test_nghttp2_frame_pack_goaway(void);
|
void test_nghttp2_frame_pack_goaway(void);
|
||||||
void test_nghttp2_frame_pack_window_update(void);
|
void test_nghttp2_frame_pack_window_update(void);
|
||||||
|
void test_nghttp2_nv_array_from_cstr(void);
|
||||||
|
|
||||||
#endif /* NGHTTP2_FRAME_TEST_H */
|
#endif /* NGHTTP2_FRAME_TEST_H */
|
||||||
|
|
Loading…
Reference in New Issue