@@ -317,18 +317,18 @@ static int test_mp_fread_fwrite(void)
317317
318318#if (!(defined LTM_NOTHING ) && !(defined MP_NO_FILE ) && (defined __GLIBC__ ))
319319#include <printf.h>
320- #define LTM_TEST_BUFSIZ 1024
320+ #define MP_TEST_BUFSIZ 1024
321321static int test_mp_printf_extension (void )
322322{
323323 FILE * test_file = NULL ;
324324
325- char line_buffer [LTM_TEST_BUFSIZ ] = {0 };
325+ char line_buffer [MP_TEST_BUFSIZ ] = {0 };
326326 bool write_only = false;
327327 size_t slen = 0 ;
328328 int characters_printed = 0 ;
329329 char * fgets_return ;
330330 int idx = 0 ;
331-
331+ /* TODO: test printing of all three flavours of mp_digit and the array */
332332 const char * test_values [41 ] = {
333333 "4DDCFDE0D20EF8663B34D19F829FDD" ,
334334 "-51D9769BDAE5B38121F2A31D881E5F"
@@ -395,72 +395,72 @@ static int test_mp_printf_extension(void)
395395 };
396396
397397 const char * print_strings [58 ] = {
398- "Right aligned AAA %50N BBB\n" ,
399- "Left aligned AAA %-50N BBB\n" ,
400- "Right aligned AAA %+50N BBB\n" ,
401- "Left aligned AAA %+-50N BBB\n" ,
402- "Right aligned AAA %' '50N BBB\n" ,
403- "Left aligned AAA %' '-50N BBB\n" ,
404-
405- "hex with right align AAA %50kN BBB\n" ,
406- "hex with left align AAA %-50kN BBB\n" ,
407- "hex with right align AAA %+50kN BBB\n" ,
408- "hex with left align AAA %+-50kN BBB\n" ,
409- "hex with right align AAA %' '50kN BBB\n" ,
410- "hex with left align AAA %' '-50kN BBB\n" ,
411-
412- "hex with right align AAA %#50kN BBB\n" ,
413- "hex with left align AAA %#-50kN BBB\n" ,
414- "hex with right align AAA %#+50kN BBB\n" ,
415- "hex with left align AAA %#+-50kN BBB\n" ,
416- "hex with right align AAA %#' '50kN BBB\n" ,
417- "hex with left align AAA %#' '-50kN BBB\n" ,
398+ "Right aligned AAA %50Zd BBB\n" ,
399+ "Left aligned AAA %-50Zd BBB\n" ,
400+ "Right aligned AAA %+50Zd BBB\n" ,
401+ "Left aligned AAA %+-50Zd BBB\n" ,
402+ "Right aligned AAA %' '50Zd BBB\n" ,
403+ "Left aligned AAA %' '-50Zd BBB\n" ,
404+
405+ "hex with right align AAA %50Zx BBB\n" ,
406+ "hex with left align AAA %-50Zx BBB\n" ,
407+ "hex with right align AAA %+50Zx BBB\n" ,
408+ "hex with left align AAA %+-50Zx BBB\n" ,
409+ "hex with right align AAA %' '50Zx BBB\n" ,
410+ "hex with left align AAA %' '-50Zx BBB\n" ,
411+
412+ "hex with right align AAA %#50Zx BBB\n" ,
413+ "hex with left align AAA %#-50Zx BBB\n" ,
414+ "hex with right align AAA %#+50Zx BBB\n" ,
415+ "hex with left align AAA %#+-50Zx BBB\n" ,
416+ "hex with right align AAA %#' '50Zx BBB\n" ,
417+ "hex with left align AAA %#' '-50Zx BBB\n" ,
418418 /* at idx == 18 mp_exch(&p,&q); */
419- "Right aligned AAA %50N BBB\n" ,
420- "Left aligned AAA %-50N BBB\n" ,
421- "Right aligned AAA %+50N BBB\n" ,
422- "Left aligned AAA %+-50N BBB\n" ,
423- "Right aligned AAA %' '50N BBB\n" ,
424- "Left aligned AAA %' '-50N BBB\n" ,
425-
426- "hex with right align AAA %50kN BBB\n" ,
427- "hex with left align AAA %-50kN BBB\n" ,
428- "hex with right align AAA %+50kN BBB\n" ,
429- "hex with left align AAA %+-50kN BBB\n" ,
430- "hex with right align AAA %' '50kN BBB\n" ,
431- "hex with left align AAA %' '-50kN BBB\n" ,
432-
433- "hex with right align AAA %#50kN BBB\n" ,
434- "hex with left align AAA %#-50kN BBB\n" ,
435- "hex with right align AAA %#+50kN BBB\n" ,
436- "hex with left align AAA %#+-50kN BBB\n" ,
437- "hex with right align AAA %#' '50kN BBB\n" ,
438- "hex with left align AAA %#' '-50kN BBB\n" ,
419+ "Right aligned AAA %50Zd BBB\n" ,
420+ "Left aligned AAA %-50Zd BBB\n" ,
421+ "Right aligned AAA %+50Zd BBB\n" ,
422+ "Left aligned AAA %+-50Zd BBB\n" ,
423+ "Right aligned AAA %' '50Zd BBB\n" ,
424+ "Left aligned AAA %' '-50Zd BBB\n" ,
425+
426+ "hex with right align AAA %50Zx BBB\n" ,
427+ "hex with left align AAA %-50Zx BBB\n" ,
428+ "hex with right align AAA %+50Zx BBB\n" ,
429+ "hex with left align AAA %+-50Zx BBB\n" ,
430+ "hex with right align AAA %' '50Zx BBB\n" ,
431+ "hex with left align AAA %' '-50Zx BBB\n" ,
432+
433+ "hex with right align AAA %#50Zx BBB\n" ,
434+ "hex with left align AAA %#-50Zx BBB\n" ,
435+ "hex with right align AAA %#+50Zx BBB\n" ,
436+ "hex with left align AAA %#+-50Zx BBB\n" ,
437+ "hex with right align AAA %#' '50Zx BBB\n" ,
438+ "hex with left align AAA %#' '-50Zx BBB\n" ,
439439
440440 /* at idx == 36 mp_zero(&p); */
441- "Right aligned AAA %50N BBB\n" ,
442- "Left aligned AAA %-50N BBB\n" ,
443- "hex with right align AAA %#50kN BBB\n" ,
444- "hex with left align AAA %#-50kN BBB\n" ,
441+ "Right aligned AAA %50Zd BBB\n" ,
442+ "Left aligned AAA %-50Zd BBB\n" ,
443+ "hex with right align AAA %#50Zx BBB\n" ,
444+ "hex with left align AAA %#-50Zx BBB\n" ,
445445 /* at idx == 40 mp_exch(&p,&q); */
446- "Right aligned AAA %50bN BBB\n" ,
447- "Left aligned AAA %-50bN BBB\n" ,
448- "Right aligned AAA %+50bN BBB\n" ,
449- "Left aligned AAA %+-50bN BBB\n" ,
450- "Right aligned AAA %' '50bN BBB\n" ,
451- "Left aligned AAA %' '-50bN BBB\n" ,
452- "Right aligned AAA %50@N BBB\n" ,
453- "Left aligned AAA %-50@N BBB\n" ,
454- "Right aligned AAA %+50@N BBB\n" ,
455- "Left aligned AAA %+-50@N BBB\n" ,
456- "Right aligned AAA %' '50@N BBB\n" ,
457- "Left aligned AAA %' '-50@N BBB\n" ,
458- "Right aligned AAA %#50@N BBB\n" ,
459- "Left aligned AAA %#-50@N BBB\n" ,
460- "Right aligned AAA %#+50@N BBB\n" ,
461- "Left aligned AAA %#+-50@N BBB\n" ,
462- "Right aligned AAA %#' '50@N BBB\n" ,
463- "Left aligned AAA %#' '-50@N BBB\n"
446+ "Right aligned AAA %50Zb BBB\n" ,
447+ "Left aligned AAA %-50Zb BBB\n" ,
448+ "Right aligned AAA %+50Zb BBB\n" ,
449+ "Left aligned AAA %+-50Zb BBB\n" ,
450+ "Right aligned AAA %' '50Zb BBB\n" ,
451+ "Left aligned AAA %' '-50Zb BBB\n" ,
452+ "Right aligned AAA %50Z@ BBB\n" ,
453+ "Left aligned AAA %-50Z@ BBB\n" ,
454+ "Right aligned AAA %+50Z@ BBB\n" ,
455+ "Left aligned AAA %+-50Z@ BBB\n" ,
456+ "Right aligned AAA %' '50Z@ BBB\n" ,
457+ "Left aligned AAA %' '-50Z@ BBB\n" ,
458+ "Right aligned AAA %#50Z@ BBB\n" ,
459+ "Left aligned AAA %#-50Z@ BBB\n" ,
460+ "Right aligned AAA %#+50Z@ BBB\n" ,
461+ "Left aligned AAA %#+-50Z@ BBB\n" ,
462+ "Right aligned AAA %#' '50Z@ BBB\n" ,
463+ "Left aligned AAA %#' '-50Z@ BBB\n"
464464 };
465465
466466 mp_int p , q ;
@@ -477,7 +477,7 @@ static int test_mp_printf_extension(void)
477477 DO (mp_read_radix (& p , test_values [0 ], 16 ));
478478 DO (mp_read_radix (& q , test_values [1 ], 16 ));
479479
480- DO (mp_printf_extension ());
480+ DO (mp_printf_extension_init ());
481481
482482 for (idx = 0 ; idx < 52 ; idx ++ ) {
483483 if (idx == 18 ) {
@@ -492,6 +492,7 @@ static int test_mp_printf_extension(void)
492492 characters_printed = fprintf (test_file , print_strings [idx ], & p );
493493 slen = strlen (test_strings [idx ]);
494494 if ((characters_printed - (int )slen ) != 0 ) {
495+ mp_printf_extension_clear ();
495496 fprintf (stderr , "%d test_mp_print_extension: failed to print o:%zu t:%d\n" ,
496497 idx , slen , characters_printed );
497498 fprintf (stderr ,"\"%s\"\n" ,test_strings [idx ]);
@@ -500,12 +501,14 @@ static int test_mp_printf_extension(void)
500501 }
501502 if (!write_only ) {
502503 rewind (test_file );
503- fgets_return = fgets (line_buffer , LTM_TEST_BUFSIZ , test_file );
504+ fgets_return = fgets (line_buffer , MP_TEST_BUFSIZ , test_file );
504505 if (fgets_return == NULL ) {
506+ mp_printf_extension_clear ();
505507 fprintf (stderr , "%d test_mp_fprintf: failed to read from file\n" , idx );
506508 goto LBL_ERR ;
507509 }
508510 if (strcmp (line_buffer , test_strings [idx ]) != 0 ) {
511+ mp_printf_extension_clear ();
509512 fprintf (stderr , "test_mp_fprintf: file content is not equal to test string #%d\n" ,idx );
510513 goto LBL_ERR ;
511514 }
@@ -514,21 +517,23 @@ static int test_mp_printf_extension(void)
514517 test_file = freopen ("ltm_testing_mp_fprintf_88a43603fcfc2f7e7c6646cd4b89180a" ,"w+" , test_file );
515518 if (test_file == NULL ) {
516519 /* use logfile instead to have at least sth. in case of an error */
517- test_file = stdout ;
520+ test_file = stderr ;
518521 write_only = true;
519522 }
520523 }
521524
522525 mp_clear_multi (& p , & q , NULL );
523526 fclose (test_file );
527+ mp_printf_extension_clear ();
524528 if (remove ("ltm_testing_mp_fprintf_88a43603fcfc2f7e7c6646cd4b89180a" ) != 0 ) {
525529 fprintf (stderr , "Could not delete file ltm_testing_mp_fprintf_88a43603fcfc2f7e7c6646cd4b89180a\n" );
526530 }
527531 return EXIT_SUCCESS ;
528532LBL_ERR :
529533 mp_clear_multi (& p , & q , NULL );
530534 fclose (test_file );
531- /* We don't delete the testfile in case of error, conrtent might be helpful. */
535+ mp_printf_extension_clear ();
536+ /* We don't delete the testfile in case of error, content might be helpful. */
532537 return EXIT_FAILURE ;
533538}
534539#endif
0 commit comments