This source file includes following definitions.
- simple_compress
- max_too_small
- calloc_fails
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include "mock_private.h"
15
16 #define SIMPLE_DATA "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
17
18 const char *SIMPLE_COMPRESSED = "BZh41AY&SYO\x1ai";
19
20 static void
21 simple_compress(void **state)
22 {
23 char *result = calloc(1024, sizeof(char));
24 unsigned int len;
25
26 assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 0, &result, &len), pcmk_rc_ok);
27 assert_memory_equal(result, SIMPLE_COMPRESSED, 13);
28 }
29
30 static void
31 max_too_small(void **state)
32 {
33 char *result = calloc(1024, sizeof(char));
34 unsigned int len;
35
36 assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 10, &result, &len), pcmk_rc_error);
37 }
38
39 static void
40 calloc_fails(void **state) {
41 char *result = calloc(1024, sizeof(char));
42 unsigned int len;
43
44 pcmk__assert_asserts(
45 {
46 pcmk__mock_calloc = true;
47 expect_value(__wrap_calloc, nmemb, (size_t) ((40 * 1.01) + 601));
48 expect_value(__wrap_calloc, size, sizeof(char));
49 pcmk__compress(SIMPLE_DATA, 40, 0, &result, &len);
50 pcmk__mock_calloc = false;
51 }
52 );
53 }
54
55 PCMK__UNIT_TEST(NULL, NULL,
56 cmocka_unit_test(simple_compress),
57 cmocka_unit_test(max_too_small),
58 cmocka_unit_test(calloc_fails))