@@ -205,7 +205,7 @@ bool test_sxbp_plot_spiral() {
205205 }
206206
207207 // call plot_spiral on spiral
208- sxbp_plot_spiral (& spiral , 1 , 16 , NULL );
208+ sxbp_plot_spiral (& spiral , 1 , 16 , NULL , NULL );
209209
210210 // check solved count
211211 if (spiral .solved_count != expected .solved_count ) {
@@ -249,7 +249,7 @@ bool test_sxbp_plot_spiral_partial() {
249249 }
250250
251251 // call plot_spiral on spiral, with instruction to only plot up to line 9
252- sxbp_plot_spiral (& spiral , 1 , 9 , NULL );
252+ sxbp_plot_spiral (& spiral , 1 , 9 , NULL , NULL );
253253
254254 // check solved count
255255 if (spiral .solved_count != expected .solved_count ) {
@@ -270,6 +270,58 @@ bool test_sxbp_plot_spiral_partial() {
270270 return result ;
271271}
272272
273+ /*
274+ * disable GCC warning about the unused parameters as this function by necessity
275+ * requires these arguments in its signature, but it needn't use all of them.
276+ */
277+ #pragma GCC diagnostic push
278+ #pragma GCC diagnostic ignored "-Wunused-parameter"
279+ // test callback for next test case
280+ static void test_progress_callback (
281+ sxbp_spiral_t * spiral , uint64_t latest_line , uint64_t target_line ,
282+ void * progress_callback_user_data
283+ ) {
284+ // cast user data from void pointer to uint16_t pointer, deref and multiply
285+ * (uint16_t * )progress_callback_user_data *= 13 ;
286+ }
287+ // re-enable all warnings
288+ #pragma GCC diagnostic pop
289+
290+ bool test_sxbp_plot_spiral_progress_callback () {
291+ // success / failure variable
292+ bool result = true;
293+ // build input structs
294+ sxbp_spiral_t spiral = { .size = 16 , };
295+ spiral .lines = calloc (sizeof (sxbp_line_t ), 16 );
296+ sxbp_direction_t directions [16 ] = {
297+ SXBP_UP , SXBP_LEFT , SXBP_DOWN , SXBP_LEFT , SXBP_DOWN , SXBP_RIGHT ,
298+ SXBP_DOWN , SXBP_RIGHT , SXBP_UP , SXBP_LEFT , SXBP_UP , SXBP_RIGHT ,
299+ SXBP_DOWN , SXBP_RIGHT , SXBP_UP , SXBP_LEFT ,
300+ };
301+ for (uint8_t i = 0 ; i < 16 ; i ++ ) {
302+ spiral .lines [i ].direction = directions [i ];
303+ spiral .lines [i ].length = 0 ;
304+ }
305+ // create user data variable
306+ uint16_t user_data = 17 ;
307+
308+ /*
309+ * call plot_spiral on spiral, with instruction to only plot up to line 1
310+ * supply our progress_callback function and a user data variable
311+ */
312+ sxbp_plot_spiral (& spiral , 1 , 1 , test_progress_callback , (void * )& user_data );
313+
314+ // user data variable should have been set to 221 (17 * 13) by callback
315+ if (user_data != 221 ) {
316+ result = false;
317+ }
318+
319+ // free memory
320+ free (spiral .lines );
321+
322+ return result ;
323+ }
324+
273325bool test_sxbp_load_spiral () {
274326 // success / failure variable
275327 bool result = true;
@@ -599,6 +651,10 @@ int main() {
599651 result = run_test_case (
600652 result , test_sxbp_plot_spiral_partial , "test_sxbp_plot_spiral_partial"
601653 );
654+ result = run_test_case (
655+ result , test_sxbp_plot_spiral_progress_callback ,
656+ "test_sxbp_plot_spiral_progress_callback"
657+ );
602658 result = run_test_case (
603659 result , test_sxbp_load_spiral , "test_sxbp_load_spiral"
604660 );
0 commit comments