Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Capture cross-type data-wrapper divisibility failures
5 : : *
6 : : * The helper should reject both append and replace when the full source
7 : : * payload leaves a partial destination element tail
8 : : *
9 : : * @return Return describing success or failure
10 : : */
11 : 1 : static Return capture_libmem_core_data_non_divisible_cross_type_cases(void)
12 : : {
13 : 1 : INITTEST;
14 : :
15 : 1 : m_create(unsigned char,byte_buffer);
16 : 1 : m_create(unsigned short,word_buffer);
17 : 1 : m_create(mem_core_data_rgb,rgb_buffer);
18 : 1 : m_create(uint32_t,dword_buffer);
19 : 1 : m_create(uint64_t,qword_buffer);
20 : :
21 : 1 : memory *descriptors[] = {
22 : : byte_buffer,
23 : : word_buffer,
24 : : rgb_buffer,
25 : : dword_buffer,
26 : : qword_buffer
27 : : };
28 : :
29 : 1 : const unsigned char word_seed[] = {
30 : : (unsigned char)0x10,
31 : : (unsigned char)0x11
32 : : };
33 : 1 : const unsigned char rgb_seed[] = {
34 : : (unsigned char)0x20,
35 : : (unsigned char)0x21,
36 : : (unsigned char)0x22
37 : : };
38 : 1 : const unsigned char dword_seed[] = {
39 : : (unsigned char)0x30,
40 : : (unsigned char)0x31,
41 : : (unsigned char)0x32,
42 : : (unsigned char)0x33
43 : : };
44 : 1 : const unsigned char qword_seed[] = {
45 : : (unsigned char)0x40,
46 : : (unsigned char)0x41,
47 : : (unsigned char)0x42,
48 : : (unsigned char)0x43,
49 : : (unsigned char)0x44,
50 : : (unsigned char)0x45,
51 : : (unsigned char)0x46,
52 : : (unsigned char)0x47
53 : : };
54 : 1 : const unsigned char invalid_byte_source[] = {
55 : : (unsigned char)0x50,
56 : : (unsigned char)0x51,
57 : : (unsigned char)0x52
58 : : };
59 : 1 : const unsigned char invalid_word_source[] = {
60 : : (unsigned char)0x60,
61 : : (unsigned char)0x61,
62 : : (unsigned char)0x62,
63 : : (unsigned char)0x63
64 : : };
65 : 1 : const unsigned char invalid_rgb_source[] = {
66 : : (unsigned char)0x70,
67 : : (unsigned char)0x71,
68 : : (unsigned char)0x72,
69 : : (unsigned char)0x73,
70 : : (unsigned char)0x74,
71 : : (unsigned char)0x75
72 : : };
73 : 1 : const unsigned char invalid_dword_source[] = {
74 : : (unsigned char)0x80,
75 : : (unsigned char)0x81,
76 : : (unsigned char)0x82,
77 : : (unsigned char)0x83
78 : : };
79 : 1 : const unsigned char invalid_qword_source[] = {
80 : : (unsigned char)0x90,
81 : : (unsigned char)0x91,
82 : : (unsigned char)0x92,
83 : : (unsigned char)0x93,
84 : : (unsigned char)0x94,
85 : : (unsigned char)0x95,
86 : : (unsigned char)0x96,
87 : : (unsigned char)0x97
88 : : };
89 : :
90 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(word_buffer,word_seed,sizeof(word_seed)));
91 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(byte_buffer,invalid_byte_source,sizeof(invalid_byte_source)));
92 : 1 : ASSERT(FAILURE == m_copy_data(word_buffer,byte_buffer));
93 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(word_buffer,word_seed,sizeof(word_seed),1));
94 : 1 : ASSERT(FAILURE == m_concat_data(word_buffer,byte_buffer));
95 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(word_buffer,word_seed,sizeof(word_seed),1));
96 : :
97 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(rgb_buffer,rgb_seed,sizeof(rgb_seed)));
98 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(word_buffer,invalid_word_source,sizeof(invalid_word_source)));
99 : 1 : ASSERT(FAILURE == m_copy_data(rgb_buffer,word_buffer));
100 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(rgb_buffer,rgb_seed,sizeof(rgb_seed),1));
101 : 1 : ASSERT(FAILURE == m_concat_data(rgb_buffer,word_buffer));
102 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(rgb_buffer,rgb_seed,sizeof(rgb_seed),1));
103 : :
104 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(dword_buffer,dword_seed,sizeof(dword_seed)));
105 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(rgb_buffer,invalid_rgb_source,sizeof(invalid_rgb_source)));
106 : 1 : ASSERT(FAILURE == m_copy_data(dword_buffer,rgb_buffer));
107 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(dword_buffer,dword_seed,sizeof(dword_seed),1));
108 : 1 : ASSERT(FAILURE == m_concat_data(dword_buffer,rgb_buffer));
109 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(dword_buffer,dword_seed,sizeof(dword_seed),1));
110 : :
111 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(qword_buffer,qword_seed,sizeof(qword_seed)));
112 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(dword_buffer,invalid_dword_source,sizeof(invalid_dword_source)));
113 : 1 : ASSERT(FAILURE == m_copy_data(qword_buffer,dword_buffer));
114 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(qword_buffer,qword_seed,sizeof(qword_seed),1));
115 : 1 : ASSERT(FAILURE == m_concat_data(qword_buffer,dword_buffer));
116 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(qword_buffer,qword_seed,sizeof(qword_seed),1));
117 : :
118 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(rgb_buffer,rgb_seed,sizeof(rgb_seed)));
119 : 1 : ASSERT(SUCCESS == set_raw_descriptor_bytes(qword_buffer,invalid_qword_source,sizeof(invalid_qword_source)));
120 : 1 : ASSERT(FAILURE == m_copy_data(rgb_buffer,qword_buffer));
121 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(rgb_buffer,rgb_seed,sizeof(rgb_seed),1));
122 : 1 : ASSERT(FAILURE == m_concat_data(rgb_buffer,qword_buffer));
123 : 1 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(rgb_buffer,rgb_seed,sizeof(rgb_seed),1));
124 : :
125 [ + + ]: 6 : for(size_t descriptor_index = 0; descriptor_index < (sizeof(descriptors) / sizeof(descriptors[0])); ++descriptor_index)
126 : : {
127 : 5 : call(m_del(descriptors[descriptor_index]));
128 : : }
129 : :
130 : 1 : deliver(status);
131 : : }
132 : :
133 : : /**
134 : : * @brief Check data wrappers reject five incompatible cross-type payloads
135 : : *
136 : : * @return Return describing success or failure
137 : : */
138 : 1 : Return test_libmem_0062(void)
139 : : {
140 : 1 : INITTEST;
141 : :
142 : : static const char expected_stderr_pattern_libmem_0062[] =
143 : : "\\A.*Source byte count 3 is not divisible by destination element size 2"
144 : : ".*Source byte count 4 is not divisible by destination element size 3"
145 : : ".*Source byte count 6 is not divisible by destination element size 4"
146 : : ".*Source byte count 4 is not divisible by destination element size 8"
147 : : ".*Source byte count 8 is not divisible by destination element size 3.*\\Z";
148 : :
149 : 1 : ASSERT(SUCCESS == match_function_output(NULL,expected_stderr_pattern_libmem_0062,capture_libmem_core_data_non_divisible_cross_type_cases));
150 : :
151 : 1 : RETURN_STATUS;
152 : : }
|