@@ -317,18 +317,18 @@ static int test_mp_fread_fwrite(void)
317
317
318
318
#if (!(defined LTM_NOTHING ) && !(defined MP_NO_FILE ) && (defined __GLIBC__ ))
319
319
#include <printf.h>
320
- #define LTM_TEST_BUFSIZ 1024
320
+ #define MP_TEST_BUFSIZ 1024
321
321
static int test_mp_printf_extension (void )
322
322
{
323
323
FILE * test_file = NULL ;
324
324
325
- char line_buffer [LTM_TEST_BUFSIZ ] = {0 };
325
+ char line_buffer [MP_TEST_BUFSIZ ] = {0 };
326
326
bool write_only = false;
327
327
size_t slen = 0 ;
328
328
int characters_printed = 0 ;
329
329
char * fgets_return ;
330
330
int idx = 0 ;
331
-
331
+ /* TODO: test printing of all three flavours of mp_digit and the array */
332
332
const char * test_values [41 ] = {
333
333
"4DDCFDE0D20EF8663B34D19F829FDD" ,
334
334
"-51D9769BDAE5B38121F2A31D881E5F"
@@ -395,72 +395,72 @@ static int test_mp_printf_extension(void)
395
395
};
396
396
397
397
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" ,
418
418
/* 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" ,
439
439
440
440
/* 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" ,
445
445
/* 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"
464
464
};
465
465
466
466
mp_int p , q ;
@@ -477,7 +477,7 @@ static int test_mp_printf_extension(void)
477
477
DO (mp_read_radix (& p , test_values [0 ], 16 ));
478
478
DO (mp_read_radix (& q , test_values [1 ], 16 ));
479
479
480
- DO (mp_printf_extension ());
480
+ DO (mp_printf_extension_init ());
481
481
482
482
for (idx = 0 ; idx < 52 ; idx ++ ) {
483
483
if (idx == 18 ) {
@@ -492,6 +492,7 @@ static int test_mp_printf_extension(void)
492
492
characters_printed = fprintf (test_file , print_strings [idx ], & p );
493
493
slen = strlen (test_strings [idx ]);
494
494
if ((characters_printed - (int )slen ) != 0 ) {
495
+ mp_printf_extension_clear ();
495
496
fprintf (stderr , "%d test_mp_print_extension: failed to print o:%zu t:%d\n" ,
496
497
idx , slen , characters_printed );
497
498
fprintf (stderr ,"\"%s\"\n" ,test_strings [idx ]);
@@ -500,12 +501,14 @@ static int test_mp_printf_extension(void)
500
501
}
501
502
if (!write_only ) {
502
503
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 );
504
505
if (fgets_return == NULL ) {
506
+ mp_printf_extension_clear ();
505
507
fprintf (stderr , "%d test_mp_fprintf: failed to read from file\n" , idx );
506
508
goto LBL_ERR ;
507
509
}
508
510
if (strcmp (line_buffer , test_strings [idx ]) != 0 ) {
511
+ mp_printf_extension_clear ();
509
512
fprintf (stderr , "test_mp_fprintf: file content is not equal to test string #%d\n" ,idx );
510
513
goto LBL_ERR ;
511
514
}
@@ -514,21 +517,23 @@ static int test_mp_printf_extension(void)
514
517
test_file = freopen ("ltm_testing_mp_fprintf_88a43603fcfc2f7e7c6646cd4b89180a" ,"w+" , test_file );
515
518
if (test_file == NULL ) {
516
519
/* use logfile instead to have at least sth. in case of an error */
517
- test_file = stdout ;
520
+ test_file = stderr ;
518
521
write_only = true;
519
522
}
520
523
}
521
524
522
525
mp_clear_multi (& p , & q , NULL );
523
526
fclose (test_file );
527
+ mp_printf_extension_clear ();
524
528
if (remove ("ltm_testing_mp_fprintf_88a43603fcfc2f7e7c6646cd4b89180a" ) != 0 ) {
525
529
fprintf (stderr , "Could not delete file ltm_testing_mp_fprintf_88a43603fcfc2f7e7c6646cd4b89180a\n" );
526
530
}
527
531
return EXIT_SUCCESS ;
528
532
LBL_ERR :
529
533
mp_clear_multi (& p , & q , NULL );
530
534
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. */
532
537
return EXIT_FAILURE ;
533
538
}
534
539
#endif
0 commit comments