Path: blob/main/contrib/libcbor/test/bytestring_encoders_test.c
39481 views
/*1* Copyright (c) 2014-2020 Pavel Kalvoda <[email protected]>2*3* libcbor is free software; you can redistribute it and/or modify4* it under the terms of the MIT license. See LICENSE for details.5*/67#include "assertions.h"89#include "cbor.h"1011unsigned char buffer[512];1213static void test_embedded_bytestring_start(void **_CBOR_UNUSED(_state)) {14assert_size_equal(1, cbor_encode_bytestring_start(1, buffer, 512));15assert_memory_equal(buffer, ((unsigned char[]){0x41}), 1);16}1718static void test_bytestring_start(void **_CBOR_UNUSED(_state)) {19assert_size_equal(5, cbor_encode_bytestring_start(1000000, buffer, 512));20assert_memory_equal(buffer, ((unsigned char[]){0x5A, 0x00, 0x0F, 0x42, 0x40}),215);22}2324static void test_indef_bytestring_start(void **_CBOR_UNUSED(_state)) {25assert_size_equal(0, cbor_encode_indef_bytestring_start(buffer, 0));26assert_size_equal(1, cbor_encode_indef_bytestring_start(buffer, 512));27assert_memory_equal(buffer, ((unsigned char[]){0x5F}), 1);28}2930int main(void) {31const struct CMUnitTest tests[] = {32cmocka_unit_test(test_embedded_bytestring_start),33cmocka_unit_test(test_bytestring_start),34cmocka_unit_test(test_indef_bytestring_start)};35return cmocka_run_group_tests(tests, NULL, NULL);36}373839