(root)/
libredwg-0.13/
test/
unit-testing/
decode_test.c
       1  #define DECODE_TEST_C
       2  #define _DEFAULT_SOURCE 1
       3  #if defined(__linux__)
       4  #  define _GNU_SOURCE 1 /* for memmem on linux */
       5  #endif
       6  #define _BSD_SOURCE 1
       7  #ifdef __STDC_ALLOC_LIB__
       8  #  define __STDC_WANT_LIB_EXT2__ 1 /* for strdup */
       9  #else
      10  #  define _USE_BSD 1
      11  #endif
      12  
      13  #define IS_DECODER
      14  #include <stdlib.h>
      15  #include "../../src/common.h"
      16  // CLANG_DIAG_IGNORE (-Wpragma-pack)
      17  #include "decode.c"
      18  // CLANG_DIAG_RESTORE
      19  #include "tests_common.h"
      20  
      21  void read_literal_length_tests (void);
      22  void read_long_compression_offset_tests (void);
      23  void read_two_byte_offset_tests (void);
      24  
      25  void
      26  read_literal_length_tests (void)
      27  {
      28    // Prepare the sample data
      29    Bit_Chain bitchain = strtobt ("00000101");
      30    unsigned char opcode = 0x05;
      31    if (read_literal_length (&bitchain, &opcode) == 0x08)
      32      ok ("read_literal_length");
      33    else
      34      fail ("read_literal_length");
      35    bitfree (&bitchain);
      36  }
      37  
      38  void
      39  read_long_compression_offset_tests (void)
      40  {
      41    Bit_Chain bitchain = strtobt ("11011101");
      42    if (read_long_compression_offset (&bitchain) == 0xDD)
      43      pass ();
      44    else
      45      fail ("read_long_compression_offset");
      46    bitfree (&bitchain);
      47  }
      48  
      49  /* This functions calls tests for read_two_byte_offset()
      50   */
      51  void
      52  read_two_byte_offset_tests (void)
      53  {
      54    Bit_Chain bitchain = strtobt ("1111000000000111");
      55    unsigned int litlength = 0x03;
      56    int result = read_two_byte_offset (&bitchain, &litlength);
      57    if (result == 508 && litlength == 0)
      58      pass ();
      59    else
      60      fail ("read_two_byte_offset");
      61    bitfree (&bitchain);
      62  }
      63  
      64  int
      65  main (int argc, char const *argv[])
      66  {
      67    loglevel = is_make_silent () ? 0 : 2;
      68  
      69    read_literal_length_tests ();
      70    read_long_compression_offset_tests ();
      71    read_two_byte_offset_tests ();
      72  
      73    return 0;
      74  }