Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Truncate a string through direct buffer access using the cached length
5 : : *
6 : : * The descriptor is created as a string, modified via the writable pointer
7 : : * returned from m_data(...), and then finalized with a shorter length derived
8 : : * from the descriptor's own cached string_length. The terminator is written
9 : : * by the test before finalization, so the default flag is used
10 : : *
11 : : * @return Return describing success or failure
12 : : */
13 : 1 : Return test_libmem_0048(void)
14 : : {
15 : 1 : INITTEST;
16 : :
17 : : static const char drafting_text[] = "drafting";
18 : 1 : m_create(char,title,MEMORY_STRING);
19 : :
20 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(title,sizeof(drafting_text),drafting_text));
21 : 1 : ASSERT(title->string_length == 8);
22 : 1 : ASSERT(title->is_string == true);
23 : :
24 : 1 : char *title_view = m_data(char,title);
25 : 1 : ASSERT(title_view != NULL);
26 : :
27 : 1 : size_t title_length = 0U;
28 : 1 : ASSERT(SUCCESS == m_string_length(title,&title_length));
29 : :
30 : 1 : const size_t truncated_length = title_length - 3U;
31 : :
32 : 1 : IF(title_view != NULL)
33 : : {
34 : 1 : title_view[truncated_length] = '\0';
35 : : }
36 : :
37 : 1 : ASSERT(SUCCESS == m_finalize_string(title,truncated_length));
38 : 1 : ASSERT(title->string_length == 5);
39 : 1 : ASSERT(title->is_string == true);
40 : 1 : ASSERT(0 == strcmp(m_text(title),"draft"));
41 : 1 : call(m_del(title));
42 : :
43 : 1 : RETURN_STATUS;
44 : : }
|