1 | /*
|
---|
2 | * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use
|
---|
5 | * this file except in compliance with the License. You can obtain a copy
|
---|
6 | * in the file LICENSE in the source distribution or at
|
---|
7 | * https://www.openssl.org/source/license.html
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include "internal/packet.h"
|
---|
11 | #include "internal/quic_txpim.h"
|
---|
12 | #include "testutil.h"
|
---|
13 |
|
---|
14 | static int test_txpim(void)
|
---|
15 | {
|
---|
16 | int testresult = 0;
|
---|
17 | QUIC_TXPIM *txpim;
|
---|
18 | size_t i, j;
|
---|
19 | QUIC_TXPIM_PKT *pkts[10] = {NULL};
|
---|
20 | QUIC_TXPIM_CHUNK chunks[3];
|
---|
21 | const QUIC_TXPIM_CHUNK *rchunks;
|
---|
22 |
|
---|
23 | if (!TEST_ptr(txpim = ossl_quic_txpim_new()))
|
---|
24 | goto err;
|
---|
25 |
|
---|
26 | for (i = 0; i < OSSL_NELEM(pkts); ++i) {
|
---|
27 | if (!TEST_ptr(pkts[i] = ossl_quic_txpim_pkt_alloc(txpim)))
|
---|
28 | goto err;
|
---|
29 |
|
---|
30 | if (!TEST_size_t_eq(ossl_quic_txpim_pkt_get_num_chunks(pkts[i]), 0))
|
---|
31 | goto err;
|
---|
32 |
|
---|
33 | for (j = 0; j < OSSL_NELEM(chunks); ++j) {
|
---|
34 | chunks[j].stream_id = 100 - j;
|
---|
35 | chunks[j].start = 1000 * i + j * 10;
|
---|
36 | chunks[j].end = chunks[j].start + 5;
|
---|
37 |
|
---|
38 | if (!TEST_true(ossl_quic_txpim_pkt_append_chunk(pkts[i], chunks + j)))
|
---|
39 | goto err;
|
---|
40 | }
|
---|
41 |
|
---|
42 | if (!TEST_size_t_eq(ossl_quic_txpim_pkt_get_num_chunks(pkts[i]),
|
---|
43 | OSSL_NELEM(chunks)))
|
---|
44 | goto err;
|
---|
45 |
|
---|
46 | rchunks = ossl_quic_txpim_pkt_get_chunks(pkts[i]);
|
---|
47 | if (!TEST_uint64_t_eq(rchunks[0].stream_id, 98)
|
---|
48 | || !TEST_uint64_t_eq(rchunks[1].stream_id, 99)
|
---|
49 | || !TEST_uint64_t_eq(rchunks[2].stream_id, 100))
|
---|
50 | goto err;
|
---|
51 | }
|
---|
52 |
|
---|
53 | testresult = 1;
|
---|
54 | err:
|
---|
55 | for (i = 0; i < OSSL_NELEM(pkts); ++i)
|
---|
56 | if (txpim != NULL && pkts[i] != NULL)
|
---|
57 | ossl_quic_txpim_pkt_release(txpim, pkts[i]);
|
---|
58 |
|
---|
59 | ossl_quic_txpim_free(txpim);
|
---|
60 | return testresult;
|
---|
61 | }
|
---|
62 |
|
---|
63 | int setup_tests(void)
|
---|
64 | {
|
---|
65 | ADD_TEST(test_txpim);
|
---|
66 | return 1;
|
---|
67 | }
|
---|