@@ -488,18 +488,22 @@ static int32_t dummy_callback(
488
488
const uint8_t * rdata ,
489
489
void * user_data )
490
490
{
491
+ size_t * count = (size_t * )user_data ;
492
+
491
493
(void )parser ;
492
494
(void )owner ;
493
495
(void )type ;
494
496
(void )class ;
495
497
(void )ttl ;
496
498
(void )rdlength ;
497
499
(void )rdata ;
498
- (void )user_data ;
500
+
501
+ (* count )++ ;
502
+
499
503
return 0 ;
500
504
}
501
505
502
- static int32_t parse_text (const char * text )
506
+ static int32_t parse (const char * text , size_t * count )
503
507
{
504
508
zone_parser_t parser ;
505
509
zone_name_buffer_t name ;
@@ -515,7 +519,7 @@ static int32_t parse_text(const char *text)
515
519
options .default_class = 1 ;
516
520
517
521
fprintf (stderr , "INPUT: '%s'\n" , text );
518
- return zone_parse_string (& parser , & options , & buffers , text , strlen (text ), NULL );
522
+ return zone_parse_string (& parser , & options , & buffers , text , strlen (text ), count );
519
523
}
520
524
521
525
static char * generate_include (const char * text )
@@ -536,33 +540,78 @@ static char *generate_include(const char *text)
536
540
537
541
diagnostic_push ()
538
542
msvc_diagnostic_ignored (4996 )
539
-
540
- /*!cmocka */
541
- void quote_no_unquote (void * * state )
543
+ static void remove_include (const char * path )
542
544
{
543
- (void )state ;
545
+ unlink (path );
546
+ }
547
+ diagnostic_pop ()
544
548
549
+ static int32_t parse_as_include (const char * text , size_t * count )
550
+ {
545
551
int32_t code ;
546
- static const char * no_unquote = PAD ("foo. TXT \"unterminated string" );
547
-
548
- // verify unterminated strings are caught
549
- code = parse_text (no_unquote );
550
- assert_int_equal (code , ZONE_SYNTAX_ERROR );
551
-
552
- // verify unterminated strings are caught in included file
553
- char * path = generate_include (no_unquote );
552
+ char * path = generate_include (text );
554
553
assert_non_null (path );
555
554
char dummy [16 ];
556
555
int length = snprintf (dummy , sizeof (dummy ), "$INCLUDE \"%s\"\n" , path );
557
556
assert_true (length > 0 && length < INT_MAX - ZONE_PADDING_SIZE );
558
557
char * include = malloc ((size_t )length + 1 + ZONE_PADDING_SIZE );
559
558
assert_non_null (include );
560
559
(void )snprintf (include , (size_t )length + 1 , "$INCLUDE \"%s\"\n" , path );
561
- code = parse_text (include );
562
- assert_int_equal (code , ZONE_SYNTAX_ERROR );
560
+ code = parse (include , count );
563
561
free (include );
564
- unlink (path );
562
+ remove_include (path );
565
563
free (path );
564
+ return code ;
566
565
}
567
566
568
- diagnostic_pop ()
567
+ /*!cmocka */
568
+ void quote_no_unquote (void * * state )
569
+ {
570
+ (void )state ;
571
+
572
+ int32_t code ;
573
+ size_t count = 0 ;
574
+ static const char * no_unquote = PAD ("foo. TXT \"unterminated string" );
575
+
576
+ code = parse (no_unquote , & count );
577
+ assert_int_equal (code , ZONE_SYNTAX_ERROR );
578
+
579
+ code = parse_as_include (no_unquote , & count );
580
+ assert_int_equal (code , ZONE_SYNTAX_ERROR );
581
+ }
582
+
583
+ /*!cmocka */
584
+ void not_so_famous_last_words (void * * state )
585
+ {
586
+ (void )state ;
587
+
588
+ int32_t code ;
589
+ size_t count = 0 ;
590
+ static const char * last_words = PAD ("; not so famous last words" );
591
+
592
+ code = parse (last_words , & count );
593
+ assert_int_equal (code , ZONE_SUCCESS );
594
+ assert_true (count == 0 );
595
+
596
+ code = parse_as_include (last_words , & count );
597
+ assert_int_equal (code , ZONE_SUCCESS );
598
+ assert_true (count == 0 );
599
+ }
600
+
601
+ /*!cmocka */
602
+ void no_famous_last_words (void * * state )
603
+ {
604
+ (void )state ;
605
+
606
+ int32_t code ;
607
+ size_t count = 0 ;
608
+ static const char * empty = PAD (" " );
609
+
610
+ code = parse (empty , & count );
611
+ assert_int_equal (code , ZONE_SUCCESS );
612
+ assert_true (count == 0 );
613
+
614
+ code = parse_as_include (empty , & count );
615
+ assert_int_equal (code , ZONE_SUCCESS );
616
+ assert_true (count == 0 );
617
+ }
0 commit comments