2
0

quic_txpim_test.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include "internal/packet.h"
  10. #include "internal/quic_txpim.h"
  11. #include "testutil.h"
  12. static int test_txpim(void)
  13. {
  14. int testresult = 0;
  15. QUIC_TXPIM *txpim;
  16. size_t i, j;
  17. QUIC_TXPIM_PKT *pkts[10] = {NULL};
  18. QUIC_TXPIM_CHUNK chunks[3];
  19. const QUIC_TXPIM_CHUNK *rchunks;
  20. if (!TEST_ptr(txpim = ossl_quic_txpim_new()))
  21. goto err;
  22. for (i = 0; i < OSSL_NELEM(pkts); ++i) {
  23. if (!TEST_ptr(pkts[i] = ossl_quic_txpim_pkt_alloc(txpim)))
  24. goto err;
  25. if (!TEST_size_t_eq(ossl_quic_txpim_pkt_get_num_chunks(pkts[i]), 0))
  26. goto err;
  27. for (j = 0; j < OSSL_NELEM(chunks); ++j) {
  28. chunks[j].stream_id = 100 - j;
  29. chunks[j].start = 1000 * i + j * 10;
  30. chunks[j].end = chunks[j].start + 5;
  31. if (!TEST_true(ossl_quic_txpim_pkt_append_chunk(pkts[i], chunks + j)))
  32. goto err;
  33. }
  34. if (!TEST_size_t_eq(ossl_quic_txpim_pkt_get_num_chunks(pkts[i]),
  35. OSSL_NELEM(chunks)))
  36. goto err;
  37. rchunks = ossl_quic_txpim_pkt_get_chunks(pkts[i]);
  38. if (!TEST_uint64_t_eq(rchunks[0].stream_id, 98)
  39. || !TEST_uint64_t_eq(rchunks[1].stream_id, 99)
  40. || !TEST_uint64_t_eq(rchunks[2].stream_id, 100))
  41. goto err;
  42. }
  43. testresult = 1;
  44. err:
  45. for (i = 0; i < OSSL_NELEM(pkts); ++i)
  46. if (txpim != NULL && pkts[i] != NULL)
  47. ossl_quic_txpim_pkt_release(txpim, pkts[i]);
  48. ossl_quic_txpim_free(txpim);
  49. return testresult;
  50. }
  51. int setup_tests(void)
  52. {
  53. ADD_TEST(test_txpim);
  54. return 1;
  55. }