Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Check fixed-string replacement wrappers and literal replacement sugar for byte and wide descriptors
5 : : *
6 : : * @return Return describing success or failure
7 : : */
8 : 1 : Return test_libmem_0047(void)
9 : : {
10 : 1 : INITTEST;
11 : :
12 : : static const char abcdef_text[] = "abcdef";
13 : 1 : m_create(char,string_buffer);
14 : 1 : ASSERT(SUCCESS == m_to_string(string_buffer));
15 : 1 : m_create(uint32_t,wide_buffer);
16 : 1 : ASSERT(SUCCESS == m_to_string(wide_buffer));
17 : :
18 : 1 : const char title_text[] = "draft";
19 : 1 : const uint32_t wide_literal[] = {
20 : : UINT32_C(100),
21 : : UINT32_C(200),
22 : : UINT32_C(0)
23 : : };
24 : :
25 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(string_buffer,sizeof(title_text),title_text));
26 : 1 : ASSERT(string_buffer->length == sizeof(title_text));
27 : 1 : ASSERT(string_buffer->string_length == strlen("draft"));
28 : 1 : ASSERT(string_buffer->is_string == true);
29 : 1 : ASSERT(0 == strcmp(m_text(string_buffer),"draft"));
30 : 1 : ASSERT(SUCCESS == m_copy_literal(string_buffer,"title"));
31 : 1 : ASSERT(string_buffer->length == sizeof("title"));
32 : 1 : ASSERT(string_buffer->string_length == strlen("title"));
33 : 1 : ASSERT(string_buffer->is_string == true);
34 : 1 : ASSERT(0 == strcmp(m_text(string_buffer),"title"));
35 : :
36 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(string_buffer,sizeof(abcdef_text),abcdef_text));
37 : :
38 : 1 : const char *aliased_literal = m_text(string_buffer);
39 : 1 : ASSERT(aliased_literal != NULL);
40 : :
41 : 1 : IF(aliased_literal != NULL)
42 : : {
43 : 1 : aliased_literal += 2;
44 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(string_buffer,string_buffer->length - 2,aliased_literal));
45 : : }
46 : :
47 : 1 : ASSERT(string_buffer->length == 5);
48 : 1 : ASSERT(string_buffer->string_length == 4);
49 : 1 : ASSERT(string_buffer->is_string == true);
50 : 1 : ASSERT(0 == strcmp(m_text(string_buffer),"cdef"));
51 : :
52 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(wide_buffer,sizeof(wide_literal),wide_literal));
53 : 1 : ASSERT(wide_buffer->length == 3);
54 : 1 : ASSERT(wide_buffer->string_length == 2);
55 : 1 : ASSERT(wide_buffer->is_string == true);
56 : :
57 : 1 : const uint32_t *wide_view = m_data_ro(uint32_t,wide_buffer);
58 : 1 : ASSERT(wide_view != NULL);
59 : :
60 : 1 : IF(wide_view != NULL)
61 : : {
62 : 1 : ASSERT(wide_view[0] == UINT32_C(100));
63 : 1 : ASSERT(wide_view[1] == UINT32_C(200));
64 : 1 : ASSERT(wide_view[2] == UINT32_C(0));
65 : : }
66 : :
67 : 1 : call(m_del(wide_buffer));
68 : 1 : call(m_del(string_buffer));
69 : :
70 : 1 : RETURN_STATUS;
71 : : }
|