pacemaker  2.1.4-dc6eb4362
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 
20 const char *SIMPLE_COMPRESSED = "BZh41AY&SYO\x1ai";
21 
22 static void
23 simple_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 
32 static void
33 max_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 
41 int
42 main(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 }
const char * SIMPLE_COMPRESSED
int pcmk__compress(const char *data, unsigned int length, unsigned int max, char **result, unsigned int *result_len)
Definition: strings.c:749
pcmk__action_result_t result
Definition: pcmk_fence.c:34
int main(int argc, char **argv)
#define SIMPLE_DATA