Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Check bounded raw and bounded string concat helpers directly
5 : : *
6 : : * @return Return describing success or failure
7 : : */
8 : 1 : Return test_libmem_0064(void)
9 : : {
10 : 1 : INITTEST;
11 : :
12 : : static const char pre_text[] = "pre";
13 : : static const char go_text[] = "go";
14 : :
15 : 1 : m_create(char,raw_destination);
16 : 1 : m_create(char,string_destination);
17 : 1 : ASSERT(SUCCESS == m_to_string(string_destination));
18 : 1 : m_create(char,raw_wrapper_destination);
19 : 1 : m_create(char,string_wrapper_destination);
20 : 1 : ASSERT(SUCCESS == m_to_string(string_wrapper_destination));
21 : :
22 : 1 : const char raw_prefix[] = {'a','b','\0'};
23 : 1 : const char raw_suffix[] = {'c','\0','d'};
24 : 1 : const char bounded_string_with_terminator[] = {'-','x','\0','z'};
25 : 1 : const char bounded_string_without_terminator[] = {'-','o','k'};
26 : 1 : const char wrapper_raw_suffix[] = {'1','\0','2'};
27 : 1 : const char wrapper_string_suffix[] = {'!','?','\0','x'};
28 : :
29 : 1 : ASSERT(SUCCESS == m_copy_buffer(raw_destination,sizeof(raw_prefix),raw_prefix));
30 : 1 : ASSERT(SUCCESS == m_concat_buffer(raw_destination,sizeof(raw_suffix),raw_suffix));
31 : 1 : ASSERT(raw_destination->string_length == 0);
32 : 1 : ASSERT(raw_destination->is_string == false);
33 : 1 : ASSERT(raw_destination->length == sizeof(raw_prefix) + sizeof(raw_suffix));
34 : :
35 : 1 : const unsigned char *aliased_raw_suffix = (const unsigned char *)m_raw_data_ro(raw_destination) + 1;
36 : 1 : ASSERT(SUCCESS == m_concat_buffer(raw_destination,4,aliased_raw_suffix));
37 : 1 : ASSERT(raw_destination->string_length == 0);
38 : 1 : ASSERT(raw_destination->is_string == false);
39 : 1 : ASSERT(raw_destination->length == sizeof(raw_prefix) + sizeof(raw_suffix) + 4);
40 : :
41 : 1 : const unsigned char *raw_view = (const unsigned char *)m_raw_data_ro(raw_destination);
42 : 1 : ASSERT(raw_view != NULL);
43 : :
44 : 1 : IF(raw_view != NULL)
45 : : {
46 : 1 : ASSERT(raw_view[0] == (unsigned char)'a');
47 : 1 : ASSERT(raw_view[1] == (unsigned char)'b');
48 : 1 : ASSERT(raw_view[2] == (unsigned char)'\0');
49 : 1 : ASSERT(raw_view[3] == (unsigned char)'c');
50 : 1 : ASSERT(raw_view[4] == (unsigned char)'\0');
51 : 1 : ASSERT(raw_view[5] == (unsigned char)'d');
52 : 1 : ASSERT(raw_view[6] == (unsigned char)'b');
53 : 1 : ASSERT(raw_view[7] == (unsigned char)'\0');
54 : 1 : ASSERT(raw_view[8] == (unsigned char)'c');
55 : 1 : ASSERT(raw_view[9] == (unsigned char)'\0');
56 : : }
57 : :
58 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(string_destination,sizeof(pre_text),pre_text));
59 : 1 : ASSERT(SUCCESS == m_concat_string(string_destination,sizeof(bounded_string_with_terminator),bounded_string_with_terminator));
60 : 1 : ASSERT(string_destination->string_length == 5);
61 : 1 : ASSERT(string_destination->is_string == true);
62 : 1 : ASSERT(0 == strcmp(m_text(string_destination),"pre-x"));
63 : 1 : ASSERT(SUCCESS == m_concat_string(string_destination,sizeof(bounded_string_without_terminator),bounded_string_without_terminator));
64 : 1 : ASSERT(string_destination->string_length == 8);
65 : 1 : ASSERT(string_destination->is_string == true);
66 : 1 : ASSERT(0 == strcmp(m_text(string_destination),"pre-x-ok"));
67 : :
68 : 1 : const char *aliased_string_suffix = m_text(string_destination) + 4;
69 : 1 : ASSERT(SUCCESS == m_concat_string(string_destination,string_destination->length - 4,aliased_string_suffix));
70 : 1 : ASSERT(string_destination->string_length == 12);
71 : 1 : ASSERT(string_destination->is_string == true);
72 : 1 : ASSERT(0 == strcmp(m_text(string_destination),"pre-x-okx-ok"));
73 : :
74 : 1 : ASSERT(SUCCESS == m_copy_buffer(raw_wrapper_destination,sizeof(raw_prefix),raw_prefix));
75 : 1 : ASSERT(SUCCESS == m_concat_buffer(raw_wrapper_destination,sizeof(wrapper_raw_suffix),wrapper_raw_suffix));
76 : 1 : ASSERT(raw_wrapper_destination->string_length == 0);
77 : 1 : ASSERT(raw_wrapper_destination->is_string == false);
78 : 1 : ASSERT(raw_wrapper_destination->length == sizeof(raw_prefix) + sizeof(wrapper_raw_suffix));
79 : :
80 : 1 : const unsigned char *raw_wrapper_view = (const unsigned char *)m_raw_data_ro(raw_wrapper_destination);
81 : 1 : ASSERT(raw_wrapper_view != NULL);
82 : :
83 : 1 : IF(raw_wrapper_view != NULL)
84 : : {
85 : 1 : ASSERT(raw_wrapper_view[0] == (unsigned char)'a');
86 : 1 : ASSERT(raw_wrapper_view[1] == (unsigned char)'b');
87 : 1 : ASSERT(raw_wrapper_view[2] == (unsigned char)'\0');
88 : 1 : ASSERT(raw_wrapper_view[3] == (unsigned char)'1');
89 : 1 : ASSERT(raw_wrapper_view[4] == (unsigned char)'\0');
90 : 1 : ASSERT(raw_wrapper_view[5] == (unsigned char)'2');
91 : : }
92 : :
93 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(string_wrapper_destination,sizeof(go_text),go_text));
94 : 1 : ASSERT(SUCCESS == m_concat_string(string_wrapper_destination,sizeof(wrapper_string_suffix),wrapper_string_suffix));
95 : 1 : ASSERT(string_wrapper_destination->string_length == 4);
96 : 1 : ASSERT(string_wrapper_destination->is_string == true);
97 : 1 : ASSERT(0 == strcmp(m_text(string_wrapper_destination),"go!?"));
98 : :
99 : 1 : call(m_del(raw_destination));
100 : 1 : call(m_del(string_destination));
101 : 1 : call(m_del(raw_wrapper_destination));
102 : 1 : call(m_del(string_wrapper_destination));
103 : :
104 : 1 : RETURN_STATUS;
105 : : }
|