Path: blob/main/contrib/libcbor/test/map_encoders_test.c
39536 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"8#include "cbor.h"910unsigned char buffer[512];1112static void test_embedded_map_start(void **_CBOR_UNUSED(_state)) {13assert_size_equal(1, cbor_encode_map_start(1, buffer, 512));14assert_memory_equal(buffer, ((unsigned char[]){0xA1}), 1);15}1617static void test_map_start(void **_CBOR_UNUSED(_state)) {18assert_size_equal(5, cbor_encode_map_start(1000000, buffer, 512));19assert_memory_equal(buffer, ((unsigned char[]){0xBA, 0x00, 0x0F, 0x42, 0x40}),205);21}2223static void test_indef_map_start(void **_CBOR_UNUSED(_state)) {24assert_size_equal(1, cbor_encode_indef_map_start(buffer, 512));25assert_size_equal(0, cbor_encode_indef_map_start(buffer, 0));26assert_memory_equal(buffer, ((unsigned char[]){0xBF}), 1);27}2829int main(void) {30const struct CMUnitTest tests[] = {cmocka_unit_test(test_embedded_map_start),31cmocka_unit_test(test_map_start),32cmocka_unit_test(test_indef_map_start)};33return cmocka_run_group_tests(tests, NULL, NULL);34}353637