Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Capture the m_string_truncate negative case for data-mode descriptors
5 : : *
6 : : * @return Return describing success or failure
7 : : */
8 : 1 : static Return capture_libmem_invalid_string_truncate_mode(void)
9 : : {
10 : 1 : INITTEST;
11 : :
12 : 1 : m_create(char,data_buffer);
13 : :
14 : 1 : ASSERT(SUCCESS == m_copy_buffer(data_buffer,sizeof("raw"),"raw"));
15 : 1 : ASSERT(FAILURE == m_string_truncate(data_buffer,1));
16 : 1 : call(m_del(data_buffer));
17 : :
18 : 1 : deliver(status);
19 : : }
20 : :
21 : : /**
22 : : * @brief Check multi-byte truncation and reject data-mode descriptors
23 : : *
24 : : * @return Return describing success or failure
25 : : */
26 : 1 : Return test_libmem_0037(void)
27 : : {
28 : 1 : INITTEST;
29 : :
30 : : static const char expected_stderr_pattern_libmem_0037[] =
31 : : "\\A.*string truncate requires a string descriptor.*\\Z";
32 : :
33 : 1 : m_create(uint32_t,code_units);
34 : :
35 : 1 : const uint32_t source_units[] = {
36 : : UINT32_C(10),
37 : : UINT32_C(20),
38 : : UINT32_C(30),
39 : : UINT32_C(40),
40 : : UINT32_C(0)
41 : : };
42 : :
43 : 1 : ASSERT(SUCCESS == m_copy_buffer(code_units,sizeof(source_units),source_units));
44 : 1 : ASSERT(SUCCESS == m_to_string(code_units));
45 : :
46 : 1 : const size_t original_length = code_units->length;
47 : :
48 : 1 : ASSERT(SUCCESS == m_string_truncate(code_units,2));
49 : 1 : ASSERT(code_units->length == original_length);
50 : 1 : ASSERT(code_units->string_length == 2);
51 : 1 : ASSERT(code_units->is_string == true);
52 : :
53 : 1 : const uint32_t *truncated_view = m_data_ro(uint32_t,code_units);
54 : 1 : ASSERT(truncated_view != NULL);
55 : :
56 : 1 : IF(truncated_view != NULL)
57 : : {
58 : 1 : ASSERT(truncated_view[0] == UINT32_C(10));
59 : 1 : ASSERT(truncated_view[1] == UINT32_C(20));
60 : 1 : ASSERT(truncated_view[2] == UINT32_C(0));
61 : : }
62 : :
63 : 1 : ASSERT(SUCCESS == m_string_truncate(code_units,8));
64 : 1 : ASSERT(code_units->string_length == 2);
65 : :
66 : 1 : ASSERT(SUCCESS == match_function_output(NULL,expected_stderr_pattern_libmem_0037,capture_libmem_invalid_string_truncate_mode));
67 : :
68 : 1 : call(m_del(code_units));
69 : :
70 : 1 : RETURN_STATUS;
71 : : }
|