1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include <fwk_assert.h>
9 #include <fwk_string.h>
10 #include <fwk_test.h>
11 
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <stdio.h>
15 
test_fwk_str_memset(void)16 void test_fwk_str_memset(void)
17 {
18     char dest[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
19     size_t count = 8;
20     int ch = 0x11;
21 
22     fwk_str_memset((void *)&dest[0], ch, count);
23 
24     for (size_t i = 0; i < count; i++) {
25         assert(dest[i] == ch);
26     }
27 }
28 
test_fwk_str_memcpy(void)29 static void test_fwk_str_memcpy(void)
30 {
31     const char src[8] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
32     char dest[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
33     size_t count = 8;
34 
35     fwk_str_memcpy((void *)&dest[0], (const void *)&src[0], count);
36 
37     for (size_t i = 0; i < count; i++) {
38         assert(dest[i] == src[i]);
39     }
40 }
41 
test_fwk_str_strncpy(void)42 static void test_fwk_str_strncpy(void)
43 {
44     const char src[] = "FWK_STRING_TEST";
45     size_t count = sizeof(src) - 1;
46     char dest[15];
47 
48     fwk_str_strncpy(&dest[0], &src[0], count);
49 
50     for (size_t i = 0; i < count; i++) {
51         assert(dest[i] == src[i]);
52     }
53 }
54 
55 static const struct fwk_test_case_desc test_case_table[] = {
56     FWK_TEST_CASE(test_fwk_str_memset),
57     FWK_TEST_CASE(test_fwk_str_memcpy),
58     FWK_TEST_CASE(test_fwk_str_strncpy),
59 };
60 
61 struct fwk_test_suite_desc test_suite = {
62     .name = "fwk_string",
63     .test_case_count = FWK_ARRAY_SIZE(test_case_table),
64     .test_case_table = test_case_table,
65 };
66