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