1/* 2 * Copyright (c) 2014-2019 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 <setjmp.h> 9#include <stdarg.h> 10#include <stddef.h> 11 12#include <cmocka.h> 13 14#include "cbor.h" 15 16unsigned char buffer[512]; 17 18static void test_embedded_bytestring_start(void **state) { 19 assert_int_equal(1, cbor_encode_bytestring_start(1, buffer, 512)); 20 assert_memory_equal(buffer, ((unsigned char[]){0x41}), 1); 21} 22 23static void test_bytestring_start(void **state) { 24 assert_int_equal(5, cbor_encode_bytestring_start(1000000, buffer, 512)); 25 assert_memory_equal(buffer, ((unsigned char[]){0x5A, 0x00, 0x0F, 0x42, 0x40}), 26 5); 27} 28 29static void test_indef_bytestring_start(void **state) { 30 assert_int_equal(0, cbor_encode_indef_bytestring_start(buffer, 0)); 31 assert_int_equal(1, cbor_encode_indef_bytestring_start(buffer, 512)); 32 assert_memory_equal(buffer, ((unsigned char[]){0x5F}), 1); 33} 34 35int main(void) { 36 const struct CMUnitTest tests[] = { 37 cmocka_unit_test(test_embedded_bytestring_start), 38 cmocka_unit_test(test_bytestring_start), 39 cmocka_unit_test(test_indef_bytestring_start)}; 40 return cmocka_run_group_tests(tests, NULL, NULL); 41} 42