Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : #if SHOW_TEST
4 : : /**
5 : : * @brief Prints SHA-512 hash in hexadecimal format
6 : : * @details Outputs each byte of the hash as a two-digit hexadecimal number
7 : : *
8 : : * @param hash Pointer to SHA-512 hash array to be printed
9 : : *
10 : : * @note Only compiled when SHOW_TEST is set to 1
11 : : * @note Requires STDERR to be properly initialized
12 : : */
13 : : void print_hash(const unsigned char *hash)
14 : : {
15 : : for(int i = 0; i < SHA512_DIGEST_LENGTH; i++)
16 : : {
17 : : echo(STDERR,"%02x",hash[i]);
18 : : }
19 : : echo(STDERR,"\n");
20 : : }
21 : : #endif
22 : :
23 : : /**
24 : : * @brief Fill the descriptor with sequential point data
25 : : *
26 : : * @param points Descriptor to populate
27 : : * @return Return describing success or failure
28 : : */
29 : 5 : Return fill_points(memory *points)
30 : : {
31 : : /* Status returned by this function through provide()
32 : : Default value assumes successful completion */
33 : 5 : Return status = SUCCESS;
34 : 5 : point *typed_points = m_data(point,points);
35 : :
36 [ - + ]: 5 : if(typed_points == NULL)
37 : : {
38 : 0 : provide(FAILURE);
39 : : }
40 : :
41 [ + + ]: 1046 : for(size_t point_index = 0; point_index < points->length; ++point_index)
42 : : {
43 : 1041 : typed_points[point_index] = (point){
44 : 1041 : (int)(point_index * 2 + 1),
45 : 1041 : (int)(point_index * 2 + 2)
46 : : };
47 : : }
48 : :
49 : 5 : provide(status);
50 : : }
51 : :
52 : : /**
53 : : * @brief Load exact bytes into a data descriptor
54 : : *
55 : : * @param descriptor Destination descriptor in data mode
56 : : * @param bytes Exact source bytes
57 : : * @param byte_count Number of bytes to import
58 : : * @return Return describing success or failure
59 : : */
60 : 30 : Return set_raw_descriptor_bytes(
61 : : memory *descriptor,
62 : : const unsigned char *bytes,
63 : : size_t byte_count)
64 : : {
65 : 30 : Return status = SUCCESS;
66 : :
67 : 30 : ASSERT(SUCCESS == m_copy_buffer(descriptor,byte_count,bytes));
68 : :
69 : 30 : return(status);
70 : : }
71 : :
72 : : /**
73 : : * @brief Check raw descriptor state against an expected byte sequence
74 : : *
75 : : * @param descriptor Descriptor to validate
76 : : * @param expected_bytes Expected raw payload bytes
77 : : * @param expected_size Expected raw payload size in bytes
78 : : * @param expected_length Expected descriptor length in destination elements
79 : : * @return Return describing success or failure
80 : : */
81 : 20 : Return expect_raw_descriptor_bytes(
82 : : const memory *descriptor,
83 : : const unsigned char *expected_bytes,
84 : : size_t expected_size,
85 : : size_t expected_length)
86 : : {
87 : 20 : Return status = SUCCESS;
88 : :
89 : 20 : size_t actual_size = 0;
90 : :
91 : 20 : ASSERT(descriptor != NULL);
92 : 20 : ASSERT(descriptor->length == expected_length);
93 : 20 : ASSERT(descriptor->string_length == 0);
94 : 20 : ASSERT(descriptor->is_string == false);
95 : 20 : ASSERT(SUCCESS == m_guarded_byte_size(descriptor,descriptor->length,&actual_size));
96 : 20 : ASSERT(actual_size == expected_size);
97 : :
98 [ + - ]: 20 : if(expected_size > 0)
99 : : {
100 : 20 : const unsigned char *actual_bytes = (const unsigned char *)m_raw_data_ro(descriptor);
101 : 20 : ASSERT(actual_bytes != NULL);
102 : :
103 : 20 : IF(actual_bytes != NULL)
104 : : {
105 : 20 : ASSERT(0 == memcmp(actual_bytes,expected_bytes,expected_size));
106 : : }
107 : : }
108 : :
109 : 20 : return(status);
110 : : }
111 : :
112 : : /**
113 : : * @brief Run one raw cross-type data-wrapper scenario
114 : : *
115 : : * @param descriptors Descriptor table indexed by the local type enum
116 : : * @param case_data Scenario description
117 : : * @return Return describing success or failure
118 : : */
119 : 10 : Return run_mem_core_data_case(
120 : : memory * const descriptors[],
121 : : const mem_core_data_case *case_data)
122 : : {
123 : 10 : Return status = SUCCESS;
124 : :
125 : 10 : ASSERT(descriptors != NULL);
126 : 10 : ASSERT(case_data != NULL);
127 : 10 : ASSERT(SUCCESS == set_raw_descriptor_bytes(descriptors[case_data->destination_index],case_data->destination_seed_bytes,case_data->destination_seed_size));
128 : 10 : ASSERT(SUCCESS == set_raw_descriptor_bytes(descriptors[case_data->source_index],case_data->source_bytes,case_data->source_size_bytes));
129 : 10 : ASSERT(SUCCESS == case_data->operation(descriptors[case_data->destination_index],descriptors[case_data->source_index]));
130 : 10 : ASSERT(SUCCESS == expect_raw_descriptor_bytes(descriptors[case_data->destination_index],case_data->expected_bytes,case_data->expected_size,case_data->expected_length));
131 : :
132 : 10 : return(status);
133 : : }
|