Path: blob/main/contrib/libcbor/test/string_encoders_test.c
39535 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_string_start(void **_CBOR_UNUSED(_state)) {13assert_size_equal(1, cbor_encode_string_start(1, buffer, 512));14assert_memory_equal(buffer, ((unsigned char[]){0x61}), 1);15}1617static void test_string_start(void **_CBOR_UNUSED(_state)) {18assert_size_equal(5, cbor_encode_string_start(1000000, buffer, 512));19assert_memory_equal(buffer, ((unsigned char[]){0x7A, 0x00, 0x0F, 0x42, 0x40}),205);21}2223static void test_indef_string_start(void **_CBOR_UNUSED(_state)) {24assert_size_equal(1, cbor_encode_indef_string_start(buffer, 512));25assert_size_equal(0, cbor_encode_indef_string_start(buffer, 0));26assert_memory_equal(buffer, ((unsigned char[]){0x7F}), 1);27}2829int main(void) {30const struct CMUnitTest tests[] = {31cmocka_unit_test(test_embedded_string_start),32cmocka_unit_test(test_string_start),33cmocka_unit_test(test_indef_string_start)};34return cmocka_run_group_tests(tests, NULL, NULL);35}363738