root/lib/common/tests/strings/pcmk__compress_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. simple_compress
  2. max_too_small
  3. main

   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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 }

/* [previous][next][first][last][top][bottom][index][help] */