Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Check the overloaded m_copy_string macro for unbounded and bounded replacement
5 : : *
6 : : * @return Return describing success or failure
7 : : */
8 : 1 : Return test_libmem_0046(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 unbounded_source[] = "alpha";
19 : 1 : const char bounded_source[] = {'b','e','t','a','\0','x'};
20 : 1 : const uint32_t wide_bounded_source[] = {
21 : : UINT32_C(10),
22 : : UINT32_C(20),
23 : : UINT32_C(0),
24 : : UINT32_C(777)
25 : : };
26 : :
27 : 1 : ASSERT(SUCCESS == m_copy_string(string_buffer,unbounded_source));
28 : 1 : ASSERT(0 == strcmp(m_text(string_buffer),"alpha"));
29 : 1 : ASSERT(string_buffer->string_length == strlen("alpha"));
30 : 1 : ASSERT(string_buffer->is_string == true);
31 : :
32 : 1 : ASSERT(SUCCESS == m_copy_string(string_buffer,sizeof(bounded_source),bounded_source));
33 : 1 : ASSERT(0 == strcmp(m_text(string_buffer),"beta"));
34 : 1 : ASSERT(string_buffer->string_length == strlen("beta"));
35 : 1 : ASSERT(string_buffer->is_string == true);
36 : :
37 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(string_buffer,sizeof(abcdef_text),abcdef_text));
38 : :
39 : 1 : const char *aliased_source = m_text(string_buffer);
40 : 1 : ASSERT(aliased_source != NULL);
41 : :
42 : 1 : IF(aliased_source != NULL)
43 : : {
44 : 1 : aliased_source += 2;
45 : 1 : ASSERT(SUCCESS == m_copy_string(string_buffer,aliased_source));
46 : : }
47 : :
48 : 1 : ASSERT(string_buffer->length == 5);
49 : 1 : ASSERT(string_buffer->string_length == 4);
50 : 1 : ASSERT(string_buffer->is_string == true);
51 : 1 : ASSERT(0 == strcmp(m_text(string_buffer),"cdef"));
52 : :
53 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(string_buffer,sizeof(abcdef_text),abcdef_text));
54 : :
55 : 1 : aliased_source = m_text(string_buffer);
56 : 1 : ASSERT(aliased_source != NULL);
57 : :
58 : 1 : IF(aliased_source != NULL)
59 : : {
60 : 1 : aliased_source += 2;
61 : 1 : ASSERT(SUCCESS == m_copy_string(string_buffer,string_buffer->length - 2,aliased_source));
62 : : }
63 : :
64 : 1 : ASSERT(string_buffer->length == 5);
65 : 1 : ASSERT(string_buffer->string_length == 4);
66 : 1 : ASSERT(string_buffer->is_string == true);
67 : 1 : ASSERT(0 == strcmp(m_text(string_buffer),"cdef"));
68 : :
69 : 1 : ASSERT(SUCCESS == m_copy_string(wide_buffer,sizeof(wide_bounded_source),wide_bounded_source));
70 : 1 : ASSERT(wide_buffer->length == 3);
71 : 1 : ASSERT(wide_buffer->string_length == 2);
72 : 1 : ASSERT(wide_buffer->is_string == true);
73 : :
74 : 1 : const uint32_t *wide_view = m_data_ro(uint32_t,wide_buffer);
75 : 1 : ASSERT(wide_view != NULL);
76 : :
77 : 1 : IF(wide_view != NULL)
78 : : {
79 : 1 : ASSERT(wide_view[0] == UINT32_C(10));
80 : 1 : ASSERT(wide_view[1] == UINT32_C(20));
81 : 1 : ASSERT(wide_view[2] == UINT32_C(0));
82 : : }
83 : :
84 : 1 : call(m_del(wide_buffer));
85 : 1 : call(m_del(string_buffer));
86 : :
87 : 1 : RETURN_STATUS;
88 : : }
|