pacemaker 2.1.4-dc6eb4362e
Scalable High-Availability cluster resource manager
pcmk__compress_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2022 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
12#include <stdarg.h>
13#include <stddef.h>
14#include <stdint.h>
15#include <setjmp.h>
16#include <cmocka.h>
17
18#define SIMPLE_DATA "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
19
20const char *SIMPLE_COMPRESSED = "BZh41AY&SYO\x1ai";
21
22static void
23simple_compress(void **state)
24{
25 char *result = calloc(1024, sizeof(char));
26 unsigned int len;
27
28 assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 0, &result, &len), pcmk_rc_ok);
29 assert_memory_equal(result, SIMPLE_COMPRESSED, 13);
30}
31
32static void
33max_too_small(void **state)
34{
35 char *result = calloc(1024, sizeof(char));
36 unsigned int len;
37
38 assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 10, &result, &len), pcmk_rc_error);
39}
40
41int
42main(int argc, char **argv)
43{
44 const struct CMUnitTest tests[] = {
45 cmocka_unit_test(simple_compress),
46 cmocka_unit_test(max_too_small),
47 };
48
49 cmocka_set_message_output(CM_OUTPUT_TAP);
50 return cmocka_run_group_tests(tests, NULL, NULL);
51}
int main(int argc, char **argv)
const char * SIMPLE_COMPRESSED
#define SIMPLE_DATA
pcmk__action_result_t result
Definition: pcmk_fence.c:34
@ pcmk_rc_ok
Definition: results.h:146
@ pcmk_rc_error
Definition: results.h:142
int pcmk__compress(const char *data, unsigned int length, unsigned int max, char **result, unsigned int *result_len)
Definition: strings.c:749