1*5d3e7166SEd Maste /*
2*5d3e7166SEd Maste * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
3*5d3e7166SEd Maste *
4*5d3e7166SEd Maste * libcbor is free software; you can redistribute it and/or modify
5*5d3e7166SEd Maste * it under the terms of the MIT license. See LICENSE for details.
6*5d3e7166SEd Maste */
7*5d3e7166SEd Maste
8*5d3e7166SEd Maste #include "assertions.h"
9*5d3e7166SEd Maste
10*5d3e7166SEd Maste #include "cbor.h"
11*5d3e7166SEd Maste
12*5d3e7166SEd Maste unsigned char buffer[512];
13*5d3e7166SEd Maste
test_embedded_bytestring_start(void ** _CBOR_UNUSED (_state))14*5d3e7166SEd Maste static void test_embedded_bytestring_start(void **_CBOR_UNUSED(_state)) {
15*5d3e7166SEd Maste assert_size_equal(1, cbor_encode_bytestring_start(1, buffer, 512));
16*5d3e7166SEd Maste assert_memory_equal(buffer, ((unsigned char[]){0x41}), 1);
17*5d3e7166SEd Maste }
18*5d3e7166SEd Maste
test_bytestring_start(void ** _CBOR_UNUSED (_state))19*5d3e7166SEd Maste static void test_bytestring_start(void **_CBOR_UNUSED(_state)) {
20*5d3e7166SEd Maste assert_size_equal(5, cbor_encode_bytestring_start(1000000, buffer, 512));
21*5d3e7166SEd Maste assert_memory_equal(buffer, ((unsigned char[]){0x5A, 0x00, 0x0F, 0x42, 0x40}),
22*5d3e7166SEd Maste 5);
23*5d3e7166SEd Maste }
24*5d3e7166SEd Maste
test_indef_bytestring_start(void ** _CBOR_UNUSED (_state))25*5d3e7166SEd Maste static void test_indef_bytestring_start(void **_CBOR_UNUSED(_state)) {
26*5d3e7166SEd Maste assert_size_equal(0, cbor_encode_indef_bytestring_start(buffer, 0));
27*5d3e7166SEd Maste assert_size_equal(1, cbor_encode_indef_bytestring_start(buffer, 512));
28*5d3e7166SEd Maste assert_memory_equal(buffer, ((unsigned char[]){0x5F}), 1);
29*5d3e7166SEd Maste }
30*5d3e7166SEd Maste
main(void)31*5d3e7166SEd Maste int main(void) {
32*5d3e7166SEd Maste const struct CMUnitTest tests[] = {
33*5d3e7166SEd Maste cmocka_unit_test(test_embedded_bytestring_start),
34*5d3e7166SEd Maste cmocka_unit_test(test_bytestring_start),
35*5d3e7166SEd Maste cmocka_unit_test(test_indef_bytestring_start)};
36*5d3e7166SEd Maste return cmocka_run_group_tests(tests, NULL, NULL);
37*5d3e7166SEd Maste }
38