@@ -323,18 +323,18 @@ static int test_mp_fread_fwrite(void)
323323
324324#if (!(defined LTM_NOTHING ) && !(defined MP_NO_FILE ) && (defined __GLIBC__ ))
325325#include <printf.h>
326- #define LTM_TEST_BUFSIZ 1024
326+ #define MP_TEST_BUFSIZ 1024
327327static int test_mp_printf_extension (void )
328328{
329329 FILE * test_file = NULL ;
330330
331- char line_buffer [LTM_TEST_BUFSIZ ] = {0 };
331+ char line_buffer [MP_TEST_BUFSIZ ] = {0 };
332332 bool write_only = false;
333333 size_t slen = 0 ;
334334 int characters_printed = 0 ;
335335 char * fgets_return ;
336336 int idx = 0 ;
337-
337+ /* TODO: test printing of all three flavours of mp_digit and the array */
338338 const char * test_values [41 ] = {
339339 "4DDCFDE0D20EF8663B34D19F829FDD" ,
340340 "-51D9769BDAE5B38121F2A31D881E5F"
@@ -401,72 +401,72 @@ static int test_mp_printf_extension(void)
401401 };
402402
403403 const char * print_strings [58 ] = {
404- "Right aligned AAA %50N BBB\n" ,
405- "Left aligned AAA %-50N BBB\n" ,
406- "Right aligned AAA %+50N BBB\n" ,
407- "Left aligned AAA %+-50N BBB\n" ,
408- "Right aligned AAA %' '50N BBB\n" ,
409- "Left aligned AAA %' '-50N BBB\n" ,
410-
411- "hex with right align AAA %50kN BBB\n" ,
412- "hex with left align AAA %-50kN BBB\n" ,
413- "hex with right align AAA %+50kN BBB\n" ,
414- "hex with left align AAA %+-50kN BBB\n" ,
415- "hex with right align AAA %' '50kN BBB\n" ,
416- "hex with left align AAA %' '-50kN BBB\n" ,
417-
418- "hex with right align AAA %#50kN BBB\n" ,
419- "hex with left align AAA %#-50kN BBB\n" ,
420- "hex with right align AAA %#+50kN BBB\n" ,
421- "hex with left align AAA %#+-50kN BBB\n" ,
422- "hex with right align AAA %#' '50kN BBB\n" ,
423- "hex with left align AAA %#' '-50kN BBB\n" ,
404+ "Right aligned AAA %50Zd BBB\n" ,
405+ "Left aligned AAA %-50Zd BBB\n" ,
406+ "Right aligned AAA %+50Zd BBB\n" ,
407+ "Left aligned AAA %+-50Zd BBB\n" ,
408+ "Right aligned AAA %' '50Zd BBB\n" ,
409+ "Left aligned AAA %' '-50Zd BBB\n" ,
410+
411+ "hex with right align AAA %50Zx BBB\n" ,
412+ "hex with left align AAA %-50Zx BBB\n" ,
413+ "hex with right align AAA %+50Zx BBB\n" ,
414+ "hex with left align AAA %+-50Zx BBB\n" ,
415+ "hex with right align AAA %' '50Zx BBB\n" ,
416+ "hex with left align AAA %' '-50Zx BBB\n" ,
417+
418+ "hex with right align AAA %#50Zx BBB\n" ,
419+ "hex with left align AAA %#-50Zx BBB\n" ,
420+ "hex with right align AAA %#+50Zx BBB\n" ,
421+ "hex with left align AAA %#+-50Zx BBB\n" ,
422+ "hex with right align AAA %#' '50Zx BBB\n" ,
423+ "hex with left align AAA %#' '-50Zx BBB\n" ,
424424 /* at idx == 18 mp_exch(&p,&q); */
425- "Right aligned AAA %50N BBB\n" ,
426- "Left aligned AAA %-50N BBB\n" ,
427- "Right aligned AAA %+50N BBB\n" ,
428- "Left aligned AAA %+-50N BBB\n" ,
429- "Right aligned AAA %' '50N BBB\n" ,
430- "Left aligned AAA %' '-50N BBB\n" ,
431-
432- "hex with right align AAA %50kN BBB\n" ,
433- "hex with left align AAA %-50kN BBB\n" ,
434- "hex with right align AAA %+50kN BBB\n" ,
435- "hex with left align AAA %+-50kN BBB\n" ,
436- "hex with right align AAA %' '50kN BBB\n" ,
437- "hex with left align AAA %' '-50kN BBB\n" ,
438-
439- "hex with right align AAA %#50kN BBB\n" ,
440- "hex with left align AAA %#-50kN BBB\n" ,
441- "hex with right align AAA %#+50kN BBB\n" ,
442- "hex with left align AAA %#+-50kN BBB\n" ,
443- "hex with right align AAA %#' '50kN BBB\n" ,
444- "hex with left align AAA %#' '-50kN BBB\n" ,
425+ "Right aligned AAA %50Zd BBB\n" ,
426+ "Left aligned AAA %-50Zd BBB\n" ,
427+ "Right aligned AAA %+50Zd BBB\n" ,
428+ "Left aligned AAA %+-50Zd BBB\n" ,
429+ "Right aligned AAA %' '50Zd BBB\n" ,
430+ "Left aligned AAA %' '-50Zd BBB\n" ,
431+
432+ "hex with right align AAA %50Zx BBB\n" ,
433+ "hex with left align AAA %-50Zx BBB\n" ,
434+ "hex with right align AAA %+50Zx BBB\n" ,
435+ "hex with left align AAA %+-50Zx BBB\n" ,
436+ "hex with right align AAA %' '50Zx BBB\n" ,
437+ "hex with left align AAA %' '-50Zx BBB\n" ,
438+
439+ "hex with right align AAA %#50Zx BBB\n" ,
440+ "hex with left align AAA %#-50Zx BBB\n" ,
441+ "hex with right align AAA %#+50Zx BBB\n" ,
442+ "hex with left align AAA %#+-50Zx BBB\n" ,
443+ "hex with right align AAA %#' '50Zx BBB\n" ,
444+ "hex with left align AAA %#' '-50Zx BBB\n" ,
445445
446446 /* at idx == 36 mp_zero(&p); */
447- "Right aligned AAA %50N BBB\n" ,
448- "Left aligned AAA %-50N BBB\n" ,
449- "hex with right align AAA %#50kN BBB\n" ,
450- "hex with left align AAA %#-50kN BBB\n" ,
447+ "Right aligned AAA %50Zd BBB\n" ,
448+ "Left aligned AAA %-50Zd BBB\n" ,
449+ "hex with right align AAA %#50Zx BBB\n" ,
450+ "hex with left align AAA %#-50Zx BBB\n" ,
451451 /* at idx == 40 mp_exch(&p,&q); */
452- "Right aligned AAA %50bN BBB\n" ,
453- "Left aligned AAA %-50bN BBB\n" ,
454- "Right aligned AAA %+50bN BBB\n" ,
455- "Left aligned AAA %+-50bN BBB\n" ,
456- "Right aligned AAA %' '50bN BBB\n" ,
457- "Left aligned AAA %' '-50bN 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" ,
464- "Right aligned AAA %#50@N BBB\n" ,
465- "Left aligned AAA %#-50@N BBB\n" ,
466- "Right aligned AAA %#+50@N BBB\n" ,
467- "Left aligned AAA %#+-50@N BBB\n" ,
468- "Right aligned AAA %#' '50@N BBB\n" ,
469- "Left aligned AAA %#' '-50@N BBB\n"
452+ "Right aligned AAA %50Zb BBB\n" ,
453+ "Left aligned AAA %-50Zb BBB\n" ,
454+ "Right aligned AAA %+50Zb BBB\n" ,
455+ "Left aligned AAA %+-50Zb BBB\n" ,
456+ "Right aligned AAA %' '50Zb BBB\n" ,
457+ "Left aligned AAA %' '-50Zb 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" ,
464+ "Right aligned AAA %#50Z@ BBB\n" ,
465+ "Left aligned AAA %#-50Z@ BBB\n" ,
466+ "Right aligned AAA %#+50Z@ BBB\n" ,
467+ "Left aligned AAA %#+-50Z@ BBB\n" ,
468+ "Right aligned AAA %#' '50Z@ BBB\n" ,
469+ "Left aligned AAA %#' '-50Z@ BBB\n"
470470 };
471471
472472 mp_int p , q ;
@@ -483,7 +483,7 @@ static int test_mp_printf_extension(void)
483483 DO (mp_read_radix (& p , test_values [0 ], 16 ));
484484 DO (mp_read_radix (& q , test_values [1 ], 16 ));
485485
486- DO (mp_printf_extension ());
486+ DO (mp_printf_extension_init ());
487487
488488 for (idx = 0 ; idx < 52 ; idx ++ ) {
489489 if (idx == 18 ) {
@@ -498,6 +498,7 @@ static int test_mp_printf_extension(void)
498498 characters_printed = fprintf (test_file , print_strings [idx ], & p );
499499 slen = strlen (test_strings [idx ]);
500500 if ((characters_printed - (int )slen ) != 0 ) {
501+ mp_printf_extension_clear ();
501502 fprintf (stderr , "%d test_mp_print_extension: failed to print o:%zu t:%d\n" ,
502503 idx , slen , characters_printed );
503504 fprintf (stderr ,"\"%s\"\n" ,test_strings [idx ]);
@@ -506,12 +507,14 @@ static int test_mp_printf_extension(void)
506507 }
507508 if (!write_only ) {
508509 rewind (test_file );
509- fgets_return = fgets (line_buffer , LTM_TEST_BUFSIZ , test_file );
510+ fgets_return = fgets (line_buffer , MP_TEST_BUFSIZ , test_file );
510511 if (fgets_return == NULL ) {
512+ mp_printf_extension_clear ();
511513 fprintf (stderr , "%d test_mp_fprintf: failed to read from file\n" , idx );
512514 goto LBL_ERR ;
513515 }
514516 if (strcmp (line_buffer , test_strings [idx ]) != 0 ) {
517+ mp_printf_extension_clear ();
515518 fprintf (stderr , "test_mp_fprintf: file content is not equal to test string #%d\n" ,idx );
516519 goto LBL_ERR ;
517520 }
@@ -520,21 +523,23 @@ static int test_mp_printf_extension(void)
520523 test_file = freopen ("ltm_testing_mp_fprintf_88a43603fcfc2f7e7c6646cd4b89180a" ,"w+" , test_file );
521524 if (test_file == NULL ) {
522525 /* use logfile instead to have at least sth. in case of an error */
523- test_file = stdout ;
526+ test_file = stderr ;
524527 write_only = true;
525528 }
526529 }
527530
528531 mp_clear_multi (& p , & q , NULL );
529532 fclose (test_file );
533+ mp_printf_extension_clear ();
530534 if (remove ("ltm_testing_mp_fprintf_88a43603fcfc2f7e7c6646cd4b89180a" ) != 0 ) {
531535 fprintf (stderr , "Could not delete file ltm_testing_mp_fprintf_88a43603fcfc2f7e7c6646cd4b89180a\n" );
532536 }
533537 return EXIT_SUCCESS ;
534538LBL_ERR :
535539 mp_clear_multi (& p , & q , NULL );
536540 fclose (test_file );
537- /* We don't delete the testfile in case of error, conrtent might be helpful. */
541+ mp_printf_extension_clear ();
542+ /* We don't delete the testfile in case of error, content might be helpful. */
538543 return EXIT_FAILURE ;
539544}
540545#endif
0 commit comments