Path: blob/main/contrib/libcbor/test/stream_expectations.h
39481 views
#ifndef STREAM_EXPECTATIONS_H_1#define STREAM_EXPECTATIONS_H_23#include "assertions.h"4#include "cbor.h"56#define MAX_QUEUE_ITEMS 3078// Utilities to test `cbor_stream_decode`. See `cbor_stream_decode_test.cc`.9//10// Usage:11// - The `assert_` helpers build a queue of `test_assertion`s12// (`assertions_queue` in the implementation file), specifying13// - Which callback is expected (`test_expectation`)14// - And what is the expected argument value (if applicable,15// `test_expectation_data`)16// - `decode` will invoke `cbor_stream_decode` (test subject)17// - `cbor_stream_decode` will invoke one of the `_callback` functions, which18// will check the passed data against the `assertions_queue`1920enum test_expectation {21UINT8_EQ,22UINT16_EQ,23UINT32_EQ,24UINT64_EQ,2526NEGINT8_EQ,27NEGINT16_EQ,28NEGINT32_EQ,29NEGINT64_EQ,3031// Matches length and memory address for definite strings32BSTRING_MEM_EQ,33BSTRING_INDEF_START,3435STRING_MEM_EQ,36STRING_INDEF_START,3738ARRAY_START, /* Definite arrays only */39ARRAY_INDEF_START,4041MAP_START, /* Definite maps only */42MAP_INDEF_START,4344TAG_EQ,4546HALF_EQ,47FLOAT_EQ,48DOUBLE_EQ,49BOOL_EQ,50NIL,51UNDEF,52INDEF_BREAK /* Expect "Break" */53};5455union test_expectation_data {56uint8_t int8;57uint16_t int16;58uint32_t int32;59uint64_t int64;60struct string {61cbor_data address;62size_t length;63} string;64size_t length;65float float2;66float float4;67double float8;68bool boolean;69};7071struct test_assertion {72enum test_expectation expectation;73union test_expectation_data data;74};7576/* Test harness -- calls `cbor_stream_decode` and checks assertions */77struct cbor_decoder_result decode(cbor_data, size_t);7879/* Verify all assertions were applied and clean up */80int clean_up_stream_assertions(void **);8182/* Assertions builders */83void assert_uint8_eq(uint8_t);84void assert_uint16_eq(uint16_t);85void assert_uint32_eq(uint32_t);86void assert_uint64_eq(uint64_t);8788void assert_negint8_eq(uint8_t);89void assert_negint16_eq(uint16_t);90void assert_negint32_eq(uint32_t);91void assert_negint64_eq(uint64_t);9293void assert_bstring_mem_eq(cbor_data, size_t);94void assert_bstring_indef_start(void);9596void assert_string_mem_eq(cbor_data, size_t);97void assert_string_indef_start(void);9899void assert_array_start(size_t);100void assert_indef_array_start(void);101102void assert_map_start(size_t);103void assert_indef_map_start(void);104105void assert_tag_eq(uint64_t);106107void assert_half(float);108void assert_float(float);109void assert_double(double);110111void assert_bool(bool);112void assert_nil(void); /* assert_null already exists */113void assert_undef(void);114115void assert_indef_break(void);116117/* Assertions verifying callbacks */118void uint8_callback(void *, uint8_t);119void uint16_callback(void *, uint16_t);120void uint32_callback(void *, uint32_t);121void uint64_callback(void *, uint64_t);122123void negint8_callback(void *, uint8_t);124void negint16_callback(void *, uint16_t);125void negint32_callback(void *, uint32_t);126void negint64_callback(void *, uint64_t);127128void byte_string_callback(void *, cbor_data, uint64_t);129void byte_string_start_callback(void *);130131void string_callback(void *, cbor_data, uint64_t);132void string_start_callback(void *);133134void array_start_callback(void *, uint64_t);135void indef_array_start_callback(void *);136137void map_start_callback(void *, uint64_t);138void indef_map_start_callback(void *);139140void tag_callback(void *, uint64_t);141142void half_callback(void *, float);143void float_callback(void *, float);144void double_callback(void *, double);145void indef_break_callback(void *);146147void bool_callback(void *, bool);148void null_callback(void *);149void undef_callback(void *);150151#endif152153154