Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Jan 12, 2025
1 parent 1d7e532 commit 1923158
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions t/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,60 @@ quicly_stream_callbacks_t stream_callbacks = {
on_destroy, quicly_streambuf_egress_shift, quicly_streambuf_egress_emit, on_egress_stop, on_ingress_receive, on_ingress_reset};
size_t on_destroy_callcnt;

static void test_error_codes(void)
{
quicly_error_t a;

a = QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0);
ok(QUICLY_ERROR_IS_QUIC(a));
ok(QUICLY_ERROR_IS_QUIC_TRANSPORT(a));
ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a));
ok(QUICLY_ERROR_GET_ERROR_CODE(a) == 0);

a = QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x3fffffffffffffff);
ok(QUICLY_ERROR_IS_QUIC(a));
ok(QUICLY_ERROR_IS_QUIC_TRANSPORT(a));
ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a));
ok(QUICLY_ERROR_GET_ERROR_CODE(a) == 0x3fffffffffffffff);

a = QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0);
ok(QUICLY_ERROR_IS_QUIC(a));
ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a));
ok(QUICLY_ERROR_IS_QUIC_APPLICATION(a));
ok(QUICLY_ERROR_GET_ERROR_CODE(a) == 0);

a = QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x3fffffffffffffff);
ok(QUICLY_ERROR_IS_QUIC(a));
ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a));
ok(QUICLY_ERROR_IS_QUIC_APPLICATION(a));
ok(QUICLY_ERROR_GET_ERROR_CODE(a) == 0x3fffffffffffffff);

a = 0;
ok(!QUICLY_ERROR_IS_QUIC(a));
ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a));
ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a));

a = PTLS_ALERT_UNKNOWN_CA; /* arbitrary alert */
ok(!QUICLY_ERROR_IS_QUIC(a));
ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a));
ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a));

a = 0x2ffff; /* max outside QUIC errors */
ok(!QUICLY_ERROR_IS_QUIC(a));
ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a));
ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a));

a = (int64_t)0x8000000000030000; /* min outside QUIC errors */
ok(!QUICLY_ERROR_IS_QUIC(a));
ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a));
ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a));

a = QUICLY_ERROR_PACKET_IGNORED; /* arbrary internal error */
ok(!QUICLY_ERROR_IS_QUIC(a));
ok(!QUICLY_ERROR_IS_QUIC_TRANSPORT(a));
ok(!QUICLY_ERROR_IS_QUIC_APPLICATION(a));
}

static void test_adjust_stream_frame_layout(void)
{
#define TEST(_is_crypto, _capacity, check) \
Expand Down Expand Up @@ -872,6 +926,7 @@ int main(int argc, char **argv)

quicly_amend_ptls_context(quic_ctx.tls);

subtest("error-codes", test_error_codes);
subtest("next-packet-number", test_next_packet_number);
subtest("address-token-codec", test_address_token_codec);
subtest("ranges", test_ranges);
Expand Down

0 comments on commit 1923158

Please sign in to comment.