File: huffman_testing.h

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (99 lines) | stat: -rw-r--r-- 3,786 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef AWS_COMPRESSION_HUFFMAN_TESTING_H
#define AWS_COMPRESSION_HUFFMAN_TESTING_H

/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/compression/huffman.h>

/**
 * The intended use of file is to allow testing of huffman character coders.
 * By doing the following, you can ensure the output of encoders decoders are
 * correct:
 *
 * \code{c}
 * static struct huffman_test_code_point code_points[] = {
 * #include "test_huffman_static_table.def"
 * };
 * \endcode
 *
 * You may then iterate over each code point in the array, and test the
 * following (pseudo-code):
 *
 * \code{c} for (cp in code_points) {
 *     AWS_ASSERT(my_coder->encode(cp.symbol) == cp.pattern);
 *     AWS_ASSERT(my_coder->decode(cp.pattern) == cp.symbol);
 * }
 * \endcode
 */

/**
 * Structure containing all relevant information about a code point
 */
struct huffman_test_code_point {
    uint8_t symbol;
    struct aws_huffman_code code;
};

/**
 * Macro to be used when including a table def file, populates an array of
 * huffman_test_code_points
 */
#define HUFFMAN_CODE(psymbol, pbit_string, pbit_pattern, pnum_bits)                                                    \
    {                                                                                                                  \
        .symbol = (psymbol),                                                                                           \
        .code =                                                                                                        \
            {                                                                                                          \
                .pattern = (pbit_pattern),                                                                             \
                .num_bits = (pnum_bits),                                                                               \
            },                                                                                                         \
    },

/**
 * Function to test a huffman coder to ensure the transitive property applies
 * (input == decode(incode(input)))
 *
 * \param[in]   coder           The symbol coder to test
 * \param[in]   input           The buffer to test
 * \param[in]   size            The size of input
 * \param[in]   encoded_size    The length of the encoded buffer. Pass 0 to skip check.
 * \param[out]  error_string    In case of failure, the error string to report
 *
 * \return AWS_OP_SUCCESS on success, AWS_OP_FAILURE on failure (error_string
 * will be set)
 */
AWS_COMPRESSION_API
int huffman_test_transitive(
    struct aws_huffman_symbol_coder *coder,
    const char *input,
    size_t size,
    size_t encoded_size,
    const char **error_string);

/**
 * Function to test a huffman coder to ensure the transitive property applies
 * when doing partial encodes/decodes (input == decode(incode(input)))
 *
 * \param[in]   coder               The symbol coder to test
 * \param[in]   input               The buffer to test
 * \param[in]   size                The size of input
 * \param[in]   encoded_size        The length of the encoded buffer. Pass 0 to skip check.
 * \param[in]   output_chunk_size   The amount of output to write at once
 * \param[out]  error_string        In case of failure, the error string to
 * report
 *
 * \return AWS_OP_SUCCESS on success, AWS_OP_FAILURE on failure (error_string
 * will be set)
 */
AWS_COMPRESSION_API
int huffman_test_transitive_chunked(
    struct aws_huffman_symbol_coder *coder,
    const char *input,
    size_t size,
    size_t encoded_size,
    size_t output_chunk_size,
    const char **error_string);

#endif /* AWS_COMPRESSION_HUFFMAN_TESTING_H */