Browse Source

Merge pull request #7230 from OTAkeys/pr/cbor

sys/cbor: remove default configuration and allow apps to enable features
master
Martine Lenders 6 years ago committed by GitHub
parent
commit
7a62a33ab2
  1. 3
      makefiles/pseudomodules.inc.mk
  2. 6
      sys/cbor/Makefile
  3. 77
      sys/cbor/cbor.c
  4. 18
      sys/include/cbor.h
  5. 26
      tests/cbor/Makefile
  6. 81
      tests/cbor/main.c
  7. 54
      tests/cbor/tests/01-run.py
  8. 6
      tests/unittests/tests-cbor/Makefile
  9. 3
      tests/unittests/tests-cbor/Makefile.include
  10. 98
      tests/unittests/tests-cbor/tests-cbor.c

3
makefiles/pseudomodules.inc.mk

@ -2,6 +2,9 @@ PSEUDOMODULES += auto_init_gnrc_rpl
PSEUDOMODULES += can_mbox
PSEUDOMODULES += can_pm
PSEUDOMODULES += can_raw
PSEUDOMODULES += cbor_ctime
PSEUDOMODULES += cbor_float
PSEUDOMODULES += cbor_semantic_tagging
PSEUDOMODULES += conn_can_isotp_multi
PSEUDOMODULES += core_%
PSEUDOMODULES += emb6_router

6
sys/cbor/Makefile

@ -1,13 +1,7 @@
MODULE = cbor
CFLAGS += -DCBOR_NO_PRINT
ifneq ($(shell uname -s),Darwin)
CFLAGS += -D_XOPEN_SOURCE=600
endif
ifeq (,$(filter native,$(BOARD)))
# build the minimal subset for non-native
CFLAGS += -DCBOR_NO_FLOAT -DCBOR_NO_PRINT -DCBOR_NO_SEMANTIC_TAGGING
endif
include $(RIOTBASE)/Makefile.base

77
sys/cbor/cbor.c

@ -24,11 +24,8 @@
#include <stdlib.h>
#include <string.h>
/* Automatically enable/disable ENABLE_DEBUG based on CBOR_NO_PRINT */
#ifndef CBOR_NO_PRINT
#define ENABLE_DEBUG (1)
#define ENABLE_DEBUG (0)
#include "debug.h"
#endif
#define CBOR_TYPE_MASK 0xE0 /* top 3 bits */
#define CBOR_INFO_MASK 0x1F /* low 5 bits */
@ -107,7 +104,7 @@ typedef struct __attribute__((packed)) {
} u;
} cast_align_u8_t;
#ifndef CBOR_NO_FLOAT
#ifdef MODULE_CBOR_FLOAT
/**
* Convert float @p x to network format
@ -224,9 +221,8 @@ static uint16_t encode_float_half(float x)
bits += m & 1;
return bits;
}
#endif /* CBOR_NO_FLOAT */
#endif /* MODULE_CBOR_FLOAT */
#ifndef CBOR_NO_PRINT
/**
* Print @p size bytes at @p data in hexadecimal display format
*/
@ -236,14 +232,13 @@ void dump_memory(const unsigned char *data, size_t size)
return;
}
DEBUG("0x");
printf("0x");
for (size_t i = 0; i < size; ++i) {
DEBUG("%02X", data[i]);
printf("%02X", data[i]);
}
DEBUG("\n");
puts("");
}
#endif /* CBOR_NO_PRINT */
void cbor_init(cbor_stream_t *stream, unsigned char *buffer, size_t size)
{
@ -542,7 +537,7 @@ size_t cbor_serialize_bool(cbor_stream_t *s, bool val)
return 1;
}
#ifndef CBOR_NO_FLOAT
#ifdef MODULE_CBOR_FLOAT
size_t cbor_deserialize_float_half(const cbor_stream_t *stream, size_t offset, float *val)
{
if (CBOR_TYPE(stream, offset) != CBOR_7 || !val) {
@ -623,7 +618,7 @@ size_t cbor_serialize_double(cbor_stream_t *s, double val)
s->pos += 8;
return 9;
}
#endif /* CBOR_NO_FLOAT */
#endif /* MODULE_CBOR_FLOAT */
size_t cbor_deserialize_byte_string(const cbor_stream_t *stream, size_t offset, char *val,
size_t length)
@ -757,8 +752,8 @@ size_t cbor_serialize_map(cbor_stream_t *s, size_t map_length)
return encode_int(CBOR_MAP, s, map_length);
}
#ifndef CBOR_NO_SEMANTIC_TAGGING
#ifndef CBOR_NO_CTIME
#ifdef MODULE_CBOR_SEMANTIC_TAGGING
#ifdef MODULE_CBOR_CTIME
size_t cbor_deserialize_date_time(const cbor_stream_t *stream, size_t offset, struct tm *val)
{
if ((CBOR_TYPE(stream, offset) != CBOR_TAG)
@ -840,7 +835,7 @@ size_t cbor_serialize_date_time_epoch(cbor_stream_t *stream, time_t val)
size_t written_bytes = encode_int(CBOR_UINT, stream, time);
return written_bytes + 1; /* + 1 tag byte */
}
#endif /* CBOR_NO_CTIME */
#endif /* MODULE_CBOR_CTIME */
size_t cbor_write_tag(cbor_stream_t *s, unsigned char tag)
@ -854,7 +849,7 @@ bool cbor_at_tag(const cbor_stream_t *s, size_t offset)
{
return cbor_at_end(s, offset) || CBOR_TYPE(s, offset) == CBOR_TAG;
}
#endif /* CBOR_NO_SEMANTIC_TAGGING */
#endif /* MODULE_CBOR_SEMANTIC_TAGGING */
size_t cbor_write_break(cbor_stream_t *s)
{
@ -874,7 +869,6 @@ bool cbor_at_end(const cbor_stream_t *s, size_t offset)
return s ? offset >= s->pos - 1 : true;
}
#ifndef CBOR_NO_PRINT
/* BEGIN: Printers */
void cbor_stream_print(const cbor_stream_t *stream)
{
@ -901,9 +895,9 @@ static size_t cbor_stream_decode_skip(cbor_stream_t *stream, size_t offset)
break;
}
DEBUG("(unsupported, ");
printf("(unsupported, ");
dump_memory(stream->data + offset, consume_bytes);
DEBUG(")\n");
puts(")");
return consume_bytes;
}
@ -917,11 +911,11 @@ static size_t cbor_stream_decode_at(cbor_stream_t *stream, size_t offset, int in
#define DESERIALIZE_AND_PRINT(type, suffix, format_string) { \
type val; \
size_t read_bytes = cbor_deserialize_##suffix(stream, offset, &val); \
DEBUG("("#type", "format_string")\n", val); \
printf("("#type", "format_string")\n", val); \
return read_bytes; \
}
DEBUG("%*s", indent, "");
printf("%*s", indent, "");
switch (CBOR_TYPE(stream, offset)) {
case CBOR_UINT:
@ -931,29 +925,29 @@ static size_t cbor_stream_decode_at(cbor_stream_t *stream, size_t offset, int in
case CBOR_BYTES: {
char buffer[CBOR_STREAM_PRINT_BUFFERSIZE];
size_t read_bytes = cbor_deserialize_byte_string(stream, offset, buffer, sizeof(buffer));
DEBUG("(byte string, \"%s\")\n", buffer);
printf("(byte string, \"%s\")\n", buffer);
return read_bytes;
}
case CBOR_TEXT: {
char buffer[CBOR_STREAM_PRINT_BUFFERSIZE];
size_t read_bytes = cbor_deserialize_unicode_string(stream, offset, buffer, sizeof(buffer));
DEBUG("(unicode string, \"%s\")\n", buffer);
printf("(unicode string, \"%s\")\n", buffer);
return read_bytes;
}
case CBOR_ARRAY: {
const bool is_indefinite = (stream->data[offset] == (CBOR_ARRAY | CBOR_VAR_FOLLOWS));
uint64_t array_length;
uint64_t array_length = 0;
size_t read_bytes;
if (is_indefinite) {
offset += read_bytes = cbor_deserialize_array_indefinite(stream, offset);
DEBUG("(array, length: [indefinite])\n");
puts("(array, length: [indefinite])");
}
else {
offset += read_bytes = decode_int(stream, offset, &array_length);
DEBUG("(array, length: %"PRIu64")\n", array_length);
printf("(array, length: %"PRIu64")\n", array_length);
}
size_t i = 0;
@ -977,16 +971,16 @@ static size_t cbor_stream_decode_at(cbor_stream_t *stream, size_t offset, int in
case CBOR_MAP: {
const bool is_indefinite = (stream->data[offset] == (CBOR_MAP | CBOR_VAR_FOLLOWS));
uint64_t map_length;
uint64_t map_length = 0;
size_t read_bytes;
if (is_indefinite) {
offset += read_bytes = cbor_deserialize_map_indefinite(stream, offset);
DEBUG("(map, length: [indefinite])\n");
puts("(map, length: [indefinite])");
}
else {
offset += read_bytes = decode_int(stream, offset, &map_length);
DEBUG("(map, length: %"PRIu64")\n", map_length);
printf("(map, length: %"PRIu64")\n", map_length);
}
size_t i = 0;
@ -1008,50 +1002,52 @@ static size_t cbor_stream_decode_at(cbor_stream_t *stream, size_t offset, int in
read_bytes += cbor_at_break(stream, offset);
return read_bytes;
}
#ifdef MODULE_CBOR_SEMANTIC_TAGGING
case CBOR_TAG: {
unsigned char tag = CBOR_ADDITIONAL_INFO(stream, offset);
switch (tag) {
/* Non-native builds likely don't have support for ctime (hence disable it there)
* TODO: Better check for availability of ctime functions? */
#ifndef CBOR_NO_CTIME
#ifdef MODULE_CBOR_CTIME
case CBOR_DATETIME_STRING_FOLLOWS: {
char buf[64];
struct tm timeinfo;
size_t read_bytes = cbor_deserialize_date_time(stream, offset, &timeinfo);
strftime(buf, sizeof(buf), "%c", &timeinfo);
DEBUG("(tag: %u, date/time string: \"%s\")\n", tag, buf);
printf("(tag: %u, date/time string: \"%s\")\n", tag, buf);
return read_bytes;
}
case CBOR_DATETIME_EPOCH_FOLLOWS: {
time_t time;
size_t read_bytes = cbor_deserialize_date_time_epoch(stream, offset, &time);
DEBUG("(tag: %u, date/time epoch: %d)\n", tag, (int)time);
printf("(tag: %u, date/time epoch: %d)\n", tag, (int)time);
return read_bytes;
}
#endif /* CBOR_NO_CTIME */
#endif /* MODULE_CBOR_CTIME */
default:
break;
}
break;
}
#endif /* MODULE_CBOR_SEMANTIC_TAGGING */
case CBOR_7: {
switch (stream->data[offset]) {
case CBOR_FALSE:
case CBOR_TRUE:
DESERIALIZE_AND_PRINT(bool, bool, "%d")
#ifndef CBOR_NO_FLOAT
#ifdef MODULE_CBOR_FLOAT
case CBOR_FLOAT16:
DESERIALIZE_AND_PRINT(float, float_half, "%f")
case CBOR_FLOAT32:
DESERIALIZE_AND_PRINT(float, float, "%f")
case CBOR_FLOAT64:
DESERIALIZE_AND_PRINT(double, double, "%lf")
#endif /* CBOR_NO_FLOAT */
#endif /* MODULE_CBOR_FLOAT */
default:
break;
}
@ -1067,7 +1063,7 @@ static size_t cbor_stream_decode_at(cbor_stream_t *stream, size_t offset, int in
void cbor_stream_decode(cbor_stream_t *stream)
{
DEBUG("Data:\n");
puts("Data:");
size_t offset = 0;
while (offset < stream->pos) {
@ -1082,9 +1078,6 @@ void cbor_stream_decode(cbor_stream_t *stream)
offset += read_bytes;
}
DEBUG("\n");
puts("");
}
#endif /* CBOR_NO_PRINT */
/* END: Printers */

18
sys/include/cbor.h

@ -120,9 +120,9 @@
#include <stdint.h>
#include <stdlib.h>
#ifndef CBOR_NO_CTIME
#ifdef MODULE_CBOR_CTIME
#include <time.h>
#endif /* CBOR_NO_CTIME */
#endif /* MODULE_CBOR_CTIME */
#ifdef __cplusplus
extern "C" {
@ -183,7 +183,6 @@ void cbor_clear(cbor_stream_t *stream);
*/
void cbor_destroy(cbor_stream_t *stream);
#ifndef CBOR_NO_PRINT
/**
* @brief Print @p stream in hex representation
*
@ -210,7 +209,6 @@ void cbor_stream_print(const cbor_stream_t *stream);
* @param[in] stream Pointer to the cbor struct
*/
void cbor_stream_decode(cbor_stream_t *stream);
#endif /* CBOR_NO_PRINT */
/**
* @brief Serializes an integer
@ -300,7 +298,7 @@ size_t cbor_serialize_bool(cbor_stream_t *stream, bool val);
size_t cbor_deserialize_bool(const cbor_stream_t *stream, size_t offset,
bool *val);
#ifndef CBOR_NO_FLOAT
#ifdef MODULE_CBOR_FLOAT
/**
* @brief Serializes a half-width floating point value
*
@ -366,7 +364,7 @@ size_t cbor_serialize_double(cbor_stream_t *stream, double val);
*/
size_t cbor_deserialize_double(const cbor_stream_t *stream, size_t offset,
double *val);
#endif /* CBOR_NO_FLOAT */
#endif /* MODULE_CBOR_FLOAT */
/**
* @brief Serializes a signed 64 bit value
@ -580,8 +578,8 @@ size_t cbor_serialize_map_indefinite(cbor_stream_t *stream);
*/
size_t cbor_deserialize_map_indefinite(const cbor_stream_t *stream, size_t offset);
#ifndef CBOR_NO_SEMANTIC_TAGGING
#ifndef CBOR_NO_CTIME
#ifdef MODULE_CBOR_SEMANTIC_TAGGING
#ifdef MODULE_CBOR_CTIME
/**
* @brief Serialize date and time
*
@ -643,7 +641,7 @@ size_t cbor_serialize_date_time_epoch(cbor_stream_t *stream, time_t val);
*/
size_t cbor_deserialize_date_time_epoch(const cbor_stream_t *stream, size_t offset, time_t *val);
#endif /* CBOR_NO_CTIME */
#endif /* MODULE_CBOR_CTIME */
/**
* @brief Write a tag to give the next CBOR item additional semantics
@ -667,7 +665,7 @@ size_t cbor_write_tag(cbor_stream_t *stream, unsigned char tag);
*/
bool cbor_at_tag(const cbor_stream_t *stream, size_t offset);
#endif /* CBOR_NO_SEMANTIC_TAGGING */
#endif /* MODULE_CBOR_SEMANTIC_TAGGING */
/**
* @brief Write a break symbol at the current offset in stream @p stream

26
tests/cbor/Makefile

@ -0,0 +1,26 @@
APPLICATION = cbor
include ../Makefile.tests_common
BOARD_BLACKLIST := arduino-duemilanove arduino-mega2560 arduino-uno
BOARD_BLACKLIST += chronos
BOARD_BLACKLIST += mips-malta
BOARD_BLACKLIST += msb-430 msb-430h
BOARD_BLACKLIST += nucleo32-f031
BOARD_BLACKLIST += pic32-clicker pic32-wifire
BOARD_BLACKLIST += qemu-i386
BOARD_BLACKLIST += telosb
BOARD_BLACKLIST += waspmote-pro
BOARD_BLACKLIST += wsn430-v1_3b wsn430-v1_4
BOARD_BLACKLIST += z1
USEMODULE += cbor
USEMODULE += cbor_ctime
USEMODULE += cbor_float
USEMODULE += cbor_semantic_tagging
include $(RIOTBASE)/Makefile.include
test:
# `testrunner` calls `make term` recursively, results in duplicated `TERMFLAGS`.
# So clears `TERMFLAGS` before run.
TERMFLAGS= tests/01-run.py

81
tests/cbor/main.c

@ -0,0 +1,81 @@
/*
* Copyright (C) 2017 OTA keys S.A.
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief cbor stream decode test application
*
* @author Pieter Willemsen <pieter.willemsen@altran.com>
*
* @}
*/
#include <stdio.h>
#include "cbor.h"
static unsigned char stream_data[1024];
static cbor_stream_t stream = {stream_data, sizeof(stream_data), 0};
void test_stream_decode(void)
{
cbor_clear(&stream);
cbor_serialize_int(&stream, 1);
cbor_serialize_uint64_t(&stream, 2llu);
cbor_serialize_int64_t(&stream, 3);
cbor_serialize_int64_t(&stream, -5);
cbor_serialize_bool(&stream, true);
cbor_serialize_float_half(&stream, 1.1f);
cbor_serialize_float(&stream, 1.5f);
cbor_serialize_double(&stream, 2.0);
cbor_serialize_byte_string(&stream, "abc");
cbor_serialize_unicode_string(&stream, "def");
cbor_serialize_array(&stream, 2);
cbor_serialize_int(&stream, 0);
cbor_serialize_int(&stream, 1);
cbor_serialize_array_indefinite(&stream);
cbor_serialize_int(&stream, 10);
cbor_serialize_int(&stream, 11);
cbor_write_break(&stream);
cbor_serialize_map(&stream, 2);
cbor_serialize_int(&stream, 1);
cbor_serialize_byte_string(&stream, "1");
cbor_serialize_int(&stream, 2);
cbor_serialize_byte_string(&stream, "2");
cbor_serialize_map_indefinite(&stream);
cbor_serialize_int(&stream, 10);
cbor_serialize_byte_string(&stream, "10");
cbor_serialize_int(&stream, 11);
cbor_serialize_byte_string(&stream, "11");
cbor_write_break(&stream);
time_t rawtime;
time(&rawtime);
struct tm *timeinfo = localtime(&rawtime);
cbor_serialize_date_time(&stream, timeinfo);
cbor_serialize_date_time_epoch(&stream, rawtime);
/* decoder should skip the tag and print 'unsupported' here */
cbor_write_tag(&stream, 2);
cbor_serialize_byte_string(&stream, "1");
cbor_stream_decode(&stream);
}
int main(void)
{
test_stream_decode();
return 0;
}

54
tests/cbor/tests/01-run.py

@ -0,0 +1,54 @@
#!/usr/bin/env python3
# Copyright (C) 2017 OTA keys S.A.
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import os
import sys
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner
ACCEPTED_ERROR = 20
def testfunc(child):
child.expect_exact('Data:')
child.expect_exact('(uint64_t, 1)')
child.expect_exact('(uint64_t, 2)')
child.expect_exact('(uint64_t, 3)')
child.expect_exact('(int64_t, -5)')
child.expect_exact('(bool, 1)')
child.expect_exact('(float, 1.099609)')
child.expect_exact('(float, 1.500000)')
child.expect_exact('(double, 2.000000)')
child.expect_exact('(byte string, "abc")')
child.expect_exact('(unicode string, "def")')
child.expect_exact('(array, length: 2)')
child.expect_exact(' (uint64_t, 0)')
child.expect_exact(' (uint64_t, 1)')
child.expect_exact('(array, length: [indefinite])')
child.expect_exact(' (uint64_t, 10)')
child.expect_exact(' (uint64_t, 11)')
child.expect_exact('(map, length: 2)')
child.expect_exact(' (uint64_t, 1)')
child.expect_exact(' (byte string, "1")')
child.expect_exact(' (uint64_t, 2)')
child.expect_exact(' (byte string, "2")')
child.expect_exact('(map, length: [indefinite])')
child.expect_exact(' (uint64_t, 10)')
child.expect_exact(' (byte string, "10")')
child.expect_exact(' (uint64_t, 11)')
child.expect_exact(' (byte string, "11")')
child.expect(r'\(tag: 0, date/time string: "[\w :]+"\)')
child.expect(r'\(tag: 1, date/time epoch: \d+\)')
child.expect_exact('(unsupported, 0xC2')
child.expect_exact(')')
child.expect_exact('(byte string, "1")')
print("All tests successful")
if __name__ == "__main__":
sys.exit(testrunner.run(testfunc, echo=False))

6
tests/unittests/tests-cbor/Makefile

@ -1,7 +1 @@
CFLAGS += -DCBOR_NO_PRINT
ifeq (,$(filter native,$(BOARD)))
CFLAGS += -DCBOR_NO_FLOAT -DCBOR_NO_PRINT -DCBOR_NO_SEMANTIC_TAGGING
endif
include $(RIOTBASE)/Makefile.base

3
tests/unittests/tests-cbor/Makefile.include

@ -1 +1,4 @@
USEMODULE += cbor
USEMODULE += cbor_ctime
USEMODULE += cbor_float
USEMODULE += cbor_semantic_tagging

98
tests/unittests/tests-cbor/tests-cbor.c

@ -25,18 +25,13 @@
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#ifndef CBOR_NO_CTIME
#ifdef MODULE_CBOR_CTIME
#include <time.h>
#endif /* CBOR_NO_CTIME */
#endif /* MODULE_CBOR_CTIME */
static void my_cbor_print(const cbor_stream_t *stream)
{
#ifndef CBOR_NO_PRINT
cbor_stream_print(stream);
#else
(void)stream;
printf("<no print support>");
#endif
}
#define CBOR_CHECK_SERIALIZED(stream, expected_value, expected_value_size) do { \
@ -573,7 +568,7 @@ static void test_map_invalid(void)
}
}
#ifndef CBOR_NO_SEMANTIC_TAGGING
#ifdef MODULE_CBOR_SEMANTIC_TAGGING
static void test_semantic_tagging(void)
{
char buffer[128];
@ -592,7 +587,7 @@ static void test_semantic_tagging(void)
CBOR_CHECK_DESERIALIZED(input, buffer, EQUAL_STRING);
}
#ifndef CBOR_NO_CTIME
#ifdef MODULE_CBOR_CTIME
static void test_date_time(void)
{
/* CBOR: UTF-8 string marked with a tag 0 to indicate it is a standard date/time string */
@ -634,8 +629,8 @@ static void test_date_time_epoch(void)
TEST_ASSERT(cbor_deserialize_date_time_epoch(&stream, 0, &val2));
CBOR_CHECK_DESERIALIZED(val, val2, EQUAL_INT);
}
#endif /* CBOR_NO_CTIME */
#endif /* CBOR_NO_SEMANTIC_TAGGING */
#endif /* MODULE_CBOR_CTIME */
#endif /* MODULE_CBOR_SEMANTIC_TAGGING */
static void test_bool(void)
{
@ -652,7 +647,7 @@ static void test_bool_invalid(void)
TEST_ASSERT_EQUAL_INT(0, cbor_deserialize_bool(&invalid_stream, 0, &val_bool));
}
#ifndef CBOR_NO_FLOAT
#ifdef MODULE_CBOR_FLOAT
static void test_float_half(void)
{
/* check border conditions */
@ -751,68 +746,7 @@ static void test_double_invalid(void)
double val_double = 0;
TEST_ASSERT_EQUAL_INT(0, cbor_deserialize_double(&invalid_stream, 0, &val_double));
}
#endif /* CBOR_NO_FLOAT */
#ifndef CBOR_NO_PRINT
/**
* Manual test for testing the cbor_stream_decode function
*/
void test_stream_decode(void)
{
cbor_clear(&stream);
cbor_serialize_int(&stream, 1);
cbor_serialize_uint64_t(&stream, 2llu);
cbor_serialize_int64_t(&stream, 3);
cbor_serialize_int64_t(&stream, -5);
cbor_serialize_bool(&stream, true);
#ifndef CBOR_NO_FLOAT
cbor_serialize_float_half(&stream, 1.1f);
cbor_serialize_float(&stream, 1.5f);
cbor_serialize_double(&stream, 2.0);
#endif /* CBOR_NO_FLOAT */
cbor_serialize_byte_string(&stream, "abc");
cbor_serialize_unicode_string(&stream, "def");
cbor_serialize_array(&stream, 2);
cbor_serialize_int(&stream, 0);
cbor_serialize_int(&stream, 1);
cbor_serialize_array_indefinite(&stream);
cbor_serialize_int(&stream, 10);
cbor_serialize_int(&stream, 11);
cbor_write_break(&stream);
cbor_serialize_map(&stream, 2);
cbor_serialize_int(&stream, 1);
cbor_serialize_byte_string(&stream, "1");
cbor_serialize_int(&stream, 2);
cbor_serialize_byte_string(&stream, "2");
cbor_serialize_map_indefinite(&stream);
cbor_serialize_int(&stream, 10);
cbor_serialize_byte_string(&stream, "10");
cbor_serialize_int(&stream, 11);
cbor_serialize_byte_string(&stream, "11");
cbor_write_break(&stream);
#ifndef CBOR_NO_SEMANTIC_TAGGING
#ifndef CBOR_NO_CTIME
time_t rawtime;
time(&rawtime);
struct tm *timeinfo = localtime(&rawtime);
cbor_serialize_date_time(&stream, timeinfo);
cbor_serialize_date_time_epoch(&stream, rawtime);
#endif /* CBOR_NO_CTIME */
/* decoder should skip the tag and print 'unsupported' here */
cbor_write_tag(&stream, 2);
cbor_serialize_byte_string(&stream, "1");
#endif /* CBOR_NO_SEMANTIC_TAGGING */
cbor_stream_decode(&stream);
}
#endif /* CBOR_NO_PRINT */
#endif /* MODULE_CBOR_FLOAT */
/**
* See examples from CBOR RFC (cf. Appendix A. Examples)
@ -838,23 +772,23 @@ TestRef tests_cbor_all(void)
new_TestFixture(test_map),
new_TestFixture(test_map_indefinite),
new_TestFixture(test_map_invalid),
#ifndef CBOR_NO_SEMANTIC_TAGGING
#ifdef MODULE_CBOR_SEMANTIC_TAGGING
new_TestFixture(test_semantic_tagging),
#ifndef CBOR_NO_CTIME
#ifdef MODULE_CBOR_CTIME
new_TestFixture(test_date_time),
new_TestFixture(test_date_time_epoch),
#endif /* CBOR_NO_CTIME */
#endif /* CBOR_NO_SEMANTIC_TAGGING */
#endif /* MODULE_CBOR_CTIME */
#endif /* MODULE_CBOR_SEMANTIC_TAGGING */
new_TestFixture(test_bool),
new_TestFixture(test_bool_invalid),
#ifndef CBOR_NO_FLOAT
#ifdef MODULE_CBOR_FLOAT
new_TestFixture(test_float_half),
new_TestFixture(test_float_half_invalid),
new_TestFixture(test_float),
new_TestFixture(test_float_invalid),
new_TestFixture(test_double),
new_TestFixture(test_double_invalid),
#endif /* CBOR_NO_FLOAT */
#endif /* MODULE_CBOR_FLOAT */
};
EMB_UNIT_TESTCALLER(CborTest, setUp, tearDown, fixtures);
@ -863,9 +797,5 @@ TestRef tests_cbor_all(void)
void tests_cbor(void)
{
#ifndef CBOR_NO_PRINT
test_stream_decode();
#endif /* CBOR_NO_PRINT */
TESTS_RUN(tests_cbor_all());
}

Loading…
Cancel
Save