File: stream_expectations.h

package info (click to toggle)
mysql-8.0 8.0.43-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,904 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,184; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,196; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (152 lines) | stat: -rw-r--r-- 3,653 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef STREAM_EXPECTATIONS_H_
#define STREAM_EXPECTATIONS_H_

#include "assertions.h"
#include "cbor.h"

#define MAX_QUEUE_ITEMS 30

// Utilities to test `cbor_stream_decode`.  See `cbor_stream_decode_test.cc`.
//
// Usage:
// - The `assert_` helpers build a queue of `test_assertion`s
//   (`assertions_queue` in the implementation file), specifying
//  - Which callback is expected (`test_expectation`)
//  - And what is the expected argument value (if applicable,
//    `test_expectation_data`)
// - `decode` will invoke `cbor_stream_decode` (test subject)
// - `cbor_stream_decode` will invoke one of the `_callback` functions, which
//   will check the passed data against the `assertions_queue`

enum test_expectation {
  UINT8_EQ,
  UINT16_EQ,
  UINT32_EQ,
  UINT64_EQ,

  NEGINT8_EQ,
  NEGINT16_EQ,
  NEGINT32_EQ,
  NEGINT64_EQ,

  // Matches length and memory address for definite strings
  BSTRING_MEM_EQ,
  BSTRING_INDEF_START,

  STRING_MEM_EQ,
  STRING_INDEF_START,

  ARRAY_START, /* Definite arrays only */
  ARRAY_INDEF_START,

  MAP_START, /* Definite maps only */
  MAP_INDEF_START,

  TAG_EQ,

  HALF_EQ,
  FLOAT_EQ,
  DOUBLE_EQ,
  BOOL_EQ,
  NIL,
  UNDEF,
  INDEF_BREAK /* Expect "Break" */
};

union test_expectation_data {
  uint8_t int8;
  uint16_t int16;
  uint32_t int32;
  uint64_t int64;
  struct string {
    cbor_data address;
    size_t length;
  } string;
  size_t length;
  float float2;
  float float4;
  double float8;
  bool boolean;
};

struct test_assertion {
  enum test_expectation expectation;
  union test_expectation_data data;
};

/* Test harness -- calls `cbor_stream_decode` and checks assertions */
struct cbor_decoder_result decode(cbor_data, size_t);

/* Verify all assertions were applied and clean up */
int clean_up_stream_assertions(void **);

/* Assertions builders */
void assert_uint8_eq(uint8_t);
void assert_uint16_eq(uint16_t);
void assert_uint32_eq(uint32_t);
void assert_uint64_eq(uint64_t);

void assert_negint8_eq(uint8_t);
void assert_negint16_eq(uint16_t);
void assert_negint32_eq(uint32_t);
void assert_negint64_eq(uint64_t);

void assert_bstring_mem_eq(cbor_data, size_t);
void assert_bstring_indef_start(void);

void assert_string_mem_eq(cbor_data, size_t);
void assert_string_indef_start(void);

void assert_array_start(size_t);
void assert_indef_array_start(void);

void assert_map_start(size_t);
void assert_indef_map_start(void);

void assert_tag_eq(uint64_t);

void assert_half(float);
void assert_float(float);
void assert_double(double);

void assert_bool(bool);
void assert_nil(void); /* assert_null already exists */
void assert_undef(void);

void assert_indef_break(void);

/* Assertions verifying callbacks */
void uint8_callback(void *, uint8_t);
void uint16_callback(void *, uint16_t);
void uint32_callback(void *, uint32_t);
void uint64_callback(void *, uint64_t);

void negint8_callback(void *, uint8_t);
void negint16_callback(void *, uint16_t);
void negint32_callback(void *, uint32_t);
void negint64_callback(void *, uint64_t);

void byte_string_callback(void *, cbor_data, uint64_t);
void byte_string_start_callback(void *);

void string_callback(void *, cbor_data, uint64_t);
void string_start_callback(void *);

void array_start_callback(void *, uint64_t);
void indef_array_start_callback(void *);

void map_start_callback(void *, uint64_t);
void indef_map_start_callback(void *);

void tag_callback(void *, uint64_t);

void half_callback(void *, float);
void float_callback(void *, float);
void double_callback(void *, double);
void indef_break_callback(void *);

void bool_callback(void *, bool);
void null_callback(void *);
void undef_callback(void *);

#endif