93 |
93 |
94 cxBufferDestroy(&source); |
94 cxBufferDestroy(&source); |
95 cxBufferDestroy(&target); |
95 cxBufferDestroy(&target); |
96 } |
96 } |
97 |
97 |
98 CX_TEST(test_szmul) { |
|
99 size_t r; |
|
100 int e; |
|
101 |
|
102 CX_TEST_DO { |
|
103 e = cx_szmul(5, 7, &r); |
|
104 CX_TEST_ASSERT(e == 0); |
|
105 CX_TEST_ASSERT(r == 35); |
|
106 |
|
107 size_t s = SIZE_MAX & ~3; |
|
108 |
|
109 e = cx_szmul(s / 4, 2, &r); |
|
110 CX_TEST_ASSERT(e == 0); |
|
111 CX_TEST_ASSERT(r == s / 2); |
|
112 |
|
113 e = cx_szmul(2, s / 4, &r); |
|
114 CX_TEST_ASSERT(e == 0); |
|
115 CX_TEST_ASSERT(r == s / 2); |
|
116 |
|
117 e = cx_szmul(s / 4, 4, &r); |
|
118 CX_TEST_ASSERT(e == 0); |
|
119 CX_TEST_ASSERT(r == s); |
|
120 |
|
121 e = cx_szmul(4, s / 4, &r); |
|
122 CX_TEST_ASSERT(e == 0); |
|
123 CX_TEST_ASSERT(r == s); |
|
124 |
|
125 e = cx_szmul(s / 4, 5, &r); |
|
126 CX_TEST_ASSERT(e != 0); |
|
127 |
|
128 e = cx_szmul(5, s / 4, &r); |
|
129 CX_TEST_ASSERT(e != 0); |
|
130 |
|
131 e = cx_szmul(SIZE_MAX - 4, 0, &r); |
|
132 CX_TEST_ASSERT(e == 0); |
|
133 CX_TEST_ASSERT(r == 0); |
|
134 |
|
135 e = cx_szmul(0, SIZE_MAX - 1, &r); |
|
136 CX_TEST_ASSERT(e == 0); |
|
137 CX_TEST_ASSERT(r == 0); |
|
138 |
|
139 e = cx_szmul(SIZE_MAX, 0, &r); |
|
140 CX_TEST_ASSERT(e == 0); |
|
141 CX_TEST_ASSERT(r == 0); |
|
142 |
|
143 e = cx_szmul(0, SIZE_MAX, &r); |
|
144 CX_TEST_ASSERT(e == 0); |
|
145 CX_TEST_ASSERT(r == 0); |
|
146 |
|
147 e = cx_szmul(0, 0, &r); |
|
148 CX_TEST_ASSERT(e == 0); |
|
149 CX_TEST_ASSERT(r == 0); |
|
150 } |
|
151 } |
|
152 |
|
153 #ifdef CX_SZMUL_BUILTIN |
|
154 |
|
155 // also test the custom implementation |
|
156 #undef CX_SZMUL_BUILTIN |
|
157 |
|
158 #include "../src/szmul.c" |
|
159 |
|
160 #define CX_SZMUL_BUILTIN |
|
161 |
|
162 CX_TEST(test_szmul_impl) { |
|
163 size_t r; |
|
164 int e; |
|
165 |
|
166 CX_TEST_DO { |
|
167 e = cx_szmul_impl(5, 7, &r); |
|
168 CX_TEST_ASSERT(e == 0); |
|
169 CX_TEST_ASSERT(r == 35); |
|
170 |
|
171 size_t s = SIZE_MAX & ~3; |
|
172 |
|
173 e = cx_szmul_impl(s / 4, 2, &r); |
|
174 CX_TEST_ASSERT(e == 0); |
|
175 CX_TEST_ASSERT(r == s / 2); |
|
176 |
|
177 e = cx_szmul_impl(2, s / 4, &r); |
|
178 CX_TEST_ASSERT(e == 0); |
|
179 CX_TEST_ASSERT(r == s / 2); |
|
180 |
|
181 e = cx_szmul_impl(s / 4, 4, &r); |
|
182 CX_TEST_ASSERT(e == 0); |
|
183 CX_TEST_ASSERT(r == s); |
|
184 |
|
185 e = cx_szmul_impl(4, s / 4, &r); |
|
186 CX_TEST_ASSERT(e == 0); |
|
187 CX_TEST_ASSERT(r == s); |
|
188 |
|
189 e = cx_szmul_impl(s / 4, 5, &r); |
|
190 CX_TEST_ASSERT(e != 0); |
|
191 |
|
192 e = cx_szmul_impl(5, s / 4, &r); |
|
193 CX_TEST_ASSERT(e != 0); |
|
194 |
|
195 e = cx_szmul_impl(SIZE_MAX - 4, 0, &r); |
|
196 CX_TEST_ASSERT(e == 0); |
|
197 CX_TEST_ASSERT(r == 0); |
|
198 |
|
199 e = cx_szmul_impl(0, SIZE_MAX - 1, &r); |
|
200 CX_TEST_ASSERT(e == 0); |
|
201 CX_TEST_ASSERT(r == 0); |
|
202 |
|
203 e = cx_szmul_impl(SIZE_MAX, 0, &r); |
|
204 CX_TEST_ASSERT(e == 0); |
|
205 CX_TEST_ASSERT(r == 0); |
|
206 |
|
207 e = cx_szmul_impl(0, SIZE_MAX, &r); |
|
208 CX_TEST_ASSERT(e == 0); |
|
209 CX_TEST_ASSERT(r == 0); |
|
210 |
|
211 e = cx_szmul_impl(0, 0, &r); |
|
212 CX_TEST_ASSERT(e == 0); |
|
213 CX_TEST_ASSERT(r == 0); |
|
214 } |
|
215 } |
|
216 |
|
217 #endif // CX_SZMUL_BUILTIN |
|
218 |
|
219 |
|
220 CxTestSuite *cx_test_suite_utils(void) { |
98 CxTestSuite *cx_test_suite_utils(void) { |
221 CxTestSuite *suite = cx_test_suite_new("utils"); |
99 CxTestSuite *suite = cx_test_suite_new("utils"); |
222 |
100 |
223 cx_test_register(suite, test_stream_bncopy); |
101 cx_test_register(suite, test_stream_bncopy); |
224 cx_test_register(suite, test_stream_ncopy); |
102 cx_test_register(suite, test_stream_ncopy); |
225 cx_test_register(suite, test_szmul); |
|
226 #ifdef CX_SZMUL_BUILTIN |
|
227 cx_test_register(suite, test_szmul_impl); |
|
228 #endif |
|
229 |
103 |
230 return suite; |
104 return suite; |
231 } |
105 } |