Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : : /**
3 : : * @brief Check same-mode descriptor-to-descriptor transfers
4 : : *
5 : : * @return Return describing success or failure
6 : : */
7 : 1 : Return test_libmem_0063(void)
8 : : {
9 : 1 : INITTEST;
10 : :
11 : : static const char seed_text[] = "seed";
12 : : static const char xyz_text[] = "xyz";
13 : : static const char ab_text[] = "ab";
14 : : static const char cd_text[] = "cd";
15 : :
16 : 1 : m_create(char,source);
17 : 1 : ASSERT(SUCCESS == m_to_string(source));
18 : 1 : m_create(char,destination);
19 : 1 : ASSERT(SUCCESS == m_to_string(destination));
20 : 1 : m_create(char,left_binary);
21 : 1 : m_create(char,right_binary);
22 : :
23 : 1 : const char left_binary_bytes[] = {'a','b','\0'};
24 : 1 : const char right_binary_bytes[] = {'c','d','\0'};
25 : :
26 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(destination,sizeof(seed_text),seed_text));
27 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(source,sizeof(xyz_text),xyz_text));
28 : 1 : ASSERT(SUCCESS == m_resize(source,32));
29 : 1 : ASSERT(source->string_length == 3);
30 : 1 : ASSERT(source->length == 32);
31 : 1 : ASSERT(SUCCESS == m_copy(destination,source));
32 : 1 : ASSERT(destination->string_length == 3);
33 : 1 : ASSERT(destination->is_string == true);
34 : 1 : ASSERT(destination->length == 4);
35 : 1 : ASSERT(0 == strcmp(m_text(destination),"xyz"));
36 : :
37 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(source,sizeof(cd_text),cd_text));
38 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(destination,sizeof(ab_text),ab_text));
39 : 1 : ASSERT(SUCCESS == m_concat_strings(destination,source));
40 : 1 : ASSERT(destination->string_length == 4);
41 : 1 : ASSERT(destination->is_string == true);
42 : 1 : ASSERT(0 == strcmp(m_text(destination),"abcd"));
43 : :
44 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(source,sizeof(cd_text),cd_text));
45 : 1 : ASSERT(SUCCESS == m_resize(source,32));
46 : 1 : ASSERT(source->string_length == 2);
47 : 1 : ASSERT(source->length == 32);
48 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(destination,sizeof(ab_text),ab_text));
49 : 1 : ASSERT(SUCCESS == m_concat_strings(destination,source));
50 : 1 : ASSERT(destination->string_length == 4);
51 : 1 : ASSERT(destination->is_string == true);
52 : 1 : ASSERT(destination->length == 5);
53 : 1 : ASSERT(0 == strcmp(m_text(destination),"abcd"));
54 : :
55 : 1 : ASSERT(SUCCESS == m_copy_buffer(left_binary,sizeof(left_binary_bytes),left_binary_bytes));
56 : 1 : ASSERT(SUCCESS == m_copy_buffer(right_binary,sizeof(right_binary_bytes),right_binary_bytes));
57 : 1 : ASSERT(left_binary->string_length == 0);
58 : 1 : ASSERT(left_binary->is_string == false);
59 : 1 : ASSERT(right_binary->string_length == 0);
60 : 1 : ASSERT(right_binary->is_string == false);
61 : 1 : ASSERT(SUCCESS == m_concat_data(left_binary,right_binary));
62 : 1 : ASSERT(left_binary->string_length == 0);
63 : 1 : ASSERT(left_binary->is_string == false);
64 : 1 : ASSERT(left_binary->length == sizeof(left_binary_bytes) + sizeof(right_binary_bytes));
65 : :
66 : 1 : ASSERT(SUCCESS == m_copy(right_binary,left_binary));
67 : 1 : ASSERT(right_binary->string_length == 0);
68 : 1 : ASSERT(right_binary->is_string == false);
69 : 1 : ASSERT(right_binary->length == left_binary->length);
70 : :
71 : 1 : const unsigned char *binary_view = (const unsigned char *)m_raw_data_ro(left_binary);
72 : 1 : ASSERT(binary_view != NULL);
73 : :
74 : 1 : IF(binary_view != NULL)
75 : : {
76 : 1 : ASSERT(binary_view[0] == (unsigned char)'a');
77 : 1 : ASSERT(binary_view[1] == (unsigned char)'b');
78 : 1 : ASSERT(binary_view[2] == (unsigned char)'\0');
79 : 1 : ASSERT(binary_view[3] == (unsigned char)'c');
80 : 1 : ASSERT(binary_view[4] == (unsigned char)'d');
81 : 1 : ASSERT(binary_view[5] == (unsigned char)'\0');
82 : : }
83 : :
84 : 1 : const unsigned char *right_binary_view = (const unsigned char *)m_raw_data_ro(right_binary);
85 : 1 : ASSERT(right_binary_view != NULL);
86 : :
87 : 1 : IF(right_binary_view != NULL)
88 : : {
89 : 1 : ASSERT(right_binary_view[0] == (unsigned char)'a');
90 : 1 : ASSERT(right_binary_view[1] == (unsigned char)'b');
91 : 1 : ASSERT(right_binary_view[2] == (unsigned char)'\0');
92 : 1 : ASSERT(right_binary_view[3] == (unsigned char)'c');
93 : 1 : ASSERT(right_binary_view[4] == (unsigned char)'d');
94 : 1 : ASSERT(right_binary_view[5] == (unsigned char)'\0');
95 : : }
96 : :
97 : 1 : call(m_del(source));
98 : 1 : call(m_del(destination));
99 : 1 : call(m_del(left_binary));
100 : 1 : call(m_del(right_binary));
101 : :
102 : 1 : RETURN_STATUS;
103 : : }
|