Debian Codegraph @

crt/aws-c-compression/include/aws/compression/private/huffman_testing.h

raw symbols SCIP
1 #ifndef AWS_COMPRESSION_HUFFMAN_TESTING_H
2 #define AWS_COMPRESSION_HUFFMAN_TESTING_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 #include <aws/compression/huffman.h>
10
11 /**
12 * The intended use of file is to allow testing of huffman character coders.
13 * By doing the following, you can ensure the output of encoders decoders are
14 * correct:
15 *
16 * \code{c}
17 * static struct huffman_test_code_point code_points[] = {
18 * #include "test_huffman_static_table.def"
19 * };
20 * \endcode
21 *
22 * You may then iterate over each code point in the array, and test the
23 * following (pseudo-code):
24 *
25 * \code{c} for (cp in code_points) {
26 * AWS_ASSERT(my_coder->encode(cp.symbol) == cp.pattern);
27 * AWS_ASSERT(my_coder->decode(cp.pattern) == cp.symbol);
28 * }
29 * \endcode
30 */
31
32 /**
33 * Structure containing all relevant information about a code point
34 */
35 struct huffman_test_code_point {
36 uint8_t symbol;
37 struct aws_huffman_code code;
38 };
39
40 /**
41 * Macro to be used when including a table def file, populates an array of
42 * huffman_test_code_points
43 */
44 #define HUFFMAN_CODE(psymbol, pbit_string, pbit_pattern, pnum_bits) \
45 { \
46 .symbol = (psymbol), \
47 .code = \
48 { \
49 .pattern = (pbit_pattern), \
50 .num_bits = (pnum_bits), \
51 }, \
52 },
53
54 /**
55 * Function to test a huffman coder to ensure the transitive property applies
56 * (input == decode(incode(input)))
57 *
58 * \param[in] coder The symbol coder to test
59 * \param[in] input The buffer to test
60 * \param[in] size The size of input
61 * \param[in] encoded_size The length of the encoded buffer. Pass 0 to skip check.
62 * \param[out] error_string In case of failure, the error string to report
63 *
64 * \return AWS_OP_SUCCESS on success, AWS_OP_FAILURE on failure (error_string
65 * will be set)
66 */
67 AWS_COMPRESSION_API
68 int huffman_test_transitive(
69 struct aws_huffman_symbol_coder *coder,
70 const char *input,
71 size_t size,
72 size_t encoded_size,
73 const char **error_string);
74
75 /**
76 * Function to test a huffman coder to ensure the transitive property applies
77 * when doing partial encodes/decodes (input == decode(incode(input)))
78 *
79 * \param[in] coder The symbol coder to test
80 * \param[in] input The buffer to test
81 * \param[in] size The size of input
82 * \param[in] encoded_size The length of the encoded buffer. Pass 0 to skip check.
83 * \param[in] output_chunk_size The amount of output to write at once
84 * \param[out] error_string In case of failure, the error string to
85 * report
86 *
87 * \return AWS_OP_SUCCESS on success, AWS_OP_FAILURE on failure (error_string
88 * will be set)
89 */
90 AWS_COMPRESSION_API
91 int huffman_test_transitive_chunked(
92 struct aws_huffman_symbol_coder *coder,
93 const char *input,
94 size_t size,
95 size_t encoded_size,
96 size_t output_chunk_size,
97 const char **error_string);
98
99 #endif /* AWS_COMPRESSION_HUFFMAN_TESTING_H */