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 "../src/cbor/internal/unicode.h" 11 struct _cbor_unicode_status status; 12 13 unsigned char missing_bytes_data[] = {0xC4, 0x8C}; 14 15 /* Capital accented C */ 16 static void test_missing_bytes(void **_CBOR_UNUSED(_state)) { 17 assert_true(_cbor_unicode_codepoint_count(missing_bytes_data, 1, &status) == 18 0); 19 assert_true(status.status == _CBOR_UNICODE_BADCP); 20 assert_true(status.location == 1); 21 22 assert_true(_cbor_unicode_codepoint_count(missing_bytes_data, 2, &status) == 23 1); 24 assert_true(status.status == _CBOR_UNICODE_OK); 25 assert_true(status.location == 0); 26 } 27 28 unsigned char invalid_sequence_data[] = {0x65, 0xC4, 0x00}; 29 30 /* e, invalid seq */ 31 static void test_invalid_sequence(void **_CBOR_UNUSED(_state)) { 32 assert_true( 33 _cbor_unicode_codepoint_count(invalid_sequence_data, 3, &status) == 0); 34 assert_true(status.status == _CBOR_UNICODE_BADCP); 35 assert_true(status.location == 2); 36 } 37 38 int main(void) { 39 const struct CMUnitTest tests[] = {cmocka_unit_test(test_missing_bytes), 40 cmocka_unit_test(test_invalid_sequence)}; 41 return cmocka_run_group_tests(tests, NULL, NULL); 42 } 43