
4 changed files with 161 additions and 65 deletions
@ -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
|
@ -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; |
||||
} |
@ -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)) |
Loading…
Reference in new issue