forked from PJK/libcbor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_expectations.h
151 lines (117 loc) · 3.48 KB
/
stream_expectations.h
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
/*
* This file provides testing tools for the streaming decoder. The intended
* usage is as follows: 1) SE API wrapper is initialized 2) Client builds
* (ordered) series of expectations 3) The decoder is executed 4) SE checks all
* assertions 5) Go to 2) if desired
*/
#ifndef STREAM_EXPECTATIONS_H_
#define STREAM_EXPECTATIONS_H_
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <cmocka.h>
#include <stdint.h>
#include "cbor.h"
// TODO: This setup is overengineered, we currently use one assertion at a time
// TOOD: We never ensure that the queue is empty
#define MAX_QUEUE_ITEMS 30
enum test_expectation {
UINT8_EQ,
UINT16_EQ,
UINT32_EQ,
UINT64_EQ,
NEGINT8_EQ,
NEGINT16_EQ,
NEGINT32_EQ,
NEGINT64_EQ,
BSTRING_MEM_EQ, /* Matches length and memory address for definite byte strings
*/
BSTRING_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;
};
/* Tested function */
// TODO: This looks overengineered, we only ever use one (?) in the testsuite
typedef struct cbor_decoder_result decoder_t(cbor_data, size_t,
const struct cbor_callbacks *,
void *);
void set_decoder(decoder_t *);
struct cbor_decoder_result decode(cbor_data, size_t);
/* Test setup */
int clear_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 assert_array_start(size_t);
void assert_indef_array_start();
void assert_map_start(size_t);
void assert_indef_map_start();
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(); /* assert_null already exists */
void assert_undef();
void assert_indef_break();
/* 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, size_t);
void byte_string_start_callback(void *);
void array_start_callback(void *, size_t);
void indef_array_start_callback(void *);
void map_start_callback(void *, size_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