Rizin
unix-like reverse engineering framework and cli tools
tests.h File Reference

Common definitions for test applications. More...

#include "sysdefs.h"
#include "tuklib_integer.h"
#include "lzma.h"
#include <stdio.h>

Go to the source code of this file.

Macros

#define memcrap(buf, size)   memset(buf, 0xFD, size)
 
#define expect(test)
 
#define succeed(test)   expect(!(test))
 
#define fail(test)   expect(test)
 

Functions

static const char * lzma_ret_sym (lzma_ret ret)
 
static bool coder_loop (lzma_stream *strm, uint8_t *in, size_t in_size, uint8_t *out, size_t out_size, lzma_ret expected_ret, lzma_action finishing_action)
 
static bool decoder_loop_ret (lzma_stream *strm, uint8_t *in, size_t in_size, lzma_ret expected_ret)
 
static bool decoder_loop (lzma_stream *strm, uint8_t *in, size_t in_size)
 

Detailed Description

Common definitions for test applications.

Definition in file tests.h.

Macro Definition Documentation

◆ expect

#define expect (   test)
Value:
((test) ? 0 : (fprintf(stderr, "%s:%d: %s\n", \
__FILE__, __LINE__, #test), abort(), 0))
-lz4-versions

Definition at line 24 of file tests.h.

◆ fail

#define fail (   test)    expect(test)

Definition at line 29 of file tests.h.

◆ memcrap

#define memcrap (   buf,
  size 
)    memset(buf, 0xFD, size)

Definition at line 22 of file tests.h.

◆ succeed

#define succeed (   test)    expect(!(test))

Definition at line 27 of file tests.h.

Function Documentation

◆ coder_loop()

static bool coder_loop ( lzma_stream strm,
uint8_t in,
size_t  in_size,
uint8_t out,
size_t  out_size,
lzma_ret  expected_ret,
lzma_action  finishing_action 
)
inlinestatic

Definition at line 58 of file tests.h.

61 {
62  size_t in_left = in_size;
63  size_t out_left = out_size > 0 ? out_size + 1 : 0;
65  lzma_ret ret;
66 
67  strm->next_in = NULL;
68  strm->avail_in = 0;
69  strm->next_out = NULL;
70  strm->avail_out = 0;
71 
72  while (true) {
73  if (in_left > 0) {
74  if (--in_left == 0)
75  action = finishing_action;
76 
77  strm->next_in = in++;
78  strm->avail_in = 1;
79  }
80 
81  if (out_left > 0) {
82  --out_left;
83  strm->next_out = out++;
84  strm->avail_out = 1;
85  }
86 
87  ret = lzma_code(strm, action);
88  if (ret != LZMA_OK)
89  break;
90  }
91 
92  bool error = false;
93 
94  if (ret != expected_ret)
95  error = true;
96 
97  if (strm->total_in != in_size || strm->total_out != out_size)
98  error = true;
99 
100  return error;
101 }
const lzma_allocator const uint8_t size_t in_size
Definition: block.h:527
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define NULL
Definition: cris-opc.c:27
static lzma_stream strm
Definition: full_flush.c:20
uint8_t * next_out
Definition: base.h:490
uint64_t total_in
Definition: base.h:488
size_t avail_out
Definition: base.h:491
const uint8_t * next_in
Definition: base.h:486
uint64_t total_out
Definition: base.h:492
size_t avail_in
Definition: base.h:487
void error(const char *msg)
Definition: untgz.c:593
lzma_ret
Return values used by several functions in liblzma.
Definition: base.h:57
@ LZMA_OK
Operation completed successfully.
Definition: base.h:58
lzma_action
The ‘action’ argument for lzma_code()
Definition: base.h:250
@ LZMA_RUN
Continue coding.
Definition: base.h:251

References test-lz4-speed::action, lzma_stream::avail_in, lzma_stream::avail_out, error(), in, in_size, LZMA_OK, LZMA_RUN, lzma_stream::next_in, lzma_stream::next_out, NULL, out, strm, lzma_stream::total_in, and lzma_stream::total_out.

Referenced by decoder_loop(), decoder_loop_ret(), test_code(), and test_corrupt().

◆ decoder_loop()

static bool decoder_loop ( lzma_stream strm,
uint8_t in,
size_t  in_size 
)
inlinestatic

Definition at line 113 of file tests.h.

114 {
115  return coder_loop(strm, in, in_size, NULL, 0,
117 }
static bool coder_loop(lzma_stream *strm, uint8_t *in, size_t in_size, uint8_t *out, size_t out_size, lzma_ret expected_ret, lzma_action finishing_action)
Definition: tests.h:58
@ LZMA_STREAM_END
End of stream was reached.
Definition: base.h:63

References coder_loop(), in, in_size, LZMA_RUN, LZMA_STREAM_END, NULL, and strm.

Referenced by test_code().

◆ decoder_loop_ret()

static bool decoder_loop_ret ( lzma_stream strm,
uint8_t in,
size_t  in_size,
lzma_ret  expected_ret 
)
inlinestatic

Definition at line 105 of file tests.h.

107 {
108  return coder_loop(strm, in, in_size, NULL, 0, expected_ret, LZMA_RUN);
109 }

References coder_loop(), in, in_size, LZMA_RUN, NULL, and strm.

Referenced by test_corrupt().

◆ lzma_ret_sym()

static const char* lzma_ret_sym ( lzma_ret  ret)
inlinestatic

Definition at line 33 of file tests.h.

34 {
35  if ((unsigned int)(ret) > LZMA_PROG_ERROR)
36  return "UNKNOWN_ERROR";
37 
38  static const char *msgs[] = {
39  "LZMA_OK",
40  "LZMA_STREAM_END",
41  "LZMA_NO_CHECK",
42  "LZMA_UNSUPPORTED_CHECK",
43  "LZMA_GET_CHECK",
44  "LZMA_MEM_ERROR",
45  "LZMA_MEMLIMIT_ERROR",
46  "LZMA_FORMAT_ERROR",
47  "LZMA_OPTIONS_ERROR",
48  "LZMA_DATA_ERROR",
49  "LZMA_BUF_ERROR",
50  "LZMA_PROG_ERROR"
51  };
52 
53  return msgs[ret];
54 }
@ LZMA_PROG_ERROR
Programming error.
Definition: base.h:218

References LZMA_PROG_ERROR.