@@ -455,41 +455,48 @@ void commonTests(JsonParser &jsonParser, const char* pvname, const char * testPr
455455
456456 // Test if is Json terminated with newline
457457 testOk (*jsonParser.jsonLogMsg .rbegin () == *" \n " ,
458- " %s - %s" , testPrefix, " New line terminator check" );
458+ " %s - %s - exp %#02x (\\ n) act %#02x" , testPrefix, " New line terminator check" ,
459+ ' \n ' , *jsonParser.jsonLogMsg .rbegin ());
459460
460461 // Test prefix
461462 testOk (!jsonParser.prefix .compare (logMsgPrefix),
462- " %s - %s" , testPrefix, " Prefix check" );
463+ " %s - %s - exp '%s' act '%s'" , testPrefix, " Prefix check" ,
464+ logMsgPrefix, jsonParser.prefix .c_str ());
463465
464466 // Test date format
465467 testOk (jsonParser.date .length () == 10 &&
466468 jsonParser.date .at (4 ) == *" -" &&
467469 jsonParser.date .at (7 ) == *" -" ,
468- " %s - %s" , testPrefix, " Date format check" );
470+ " %s - %s - exp '%s' act '%s'" , testPrefix, " Date format check" ,
471+ " YYYY-MM-DD" , jsonParser.date .c_str ());
469472
470473 // Test time format
471474 testOk (jsonParser.time .length () == 12 &&
472475 jsonParser.time .at (2 ) == *" :" &&
473476 jsonParser.time .at (5 ) == *" :" &&
474477 jsonParser.time .at (8 ) == *" ." ,
475- " %s - %s" , testPrefix, " Time format check" );
478+ " %s - %s - exp '%s' act '%s'" , testPrefix, " Time format check" ,
479+ " HH:MM:SS.ddd" , jsonParser.time .c_str ());
476480
477481 // Test hostname
478482 char hostname[1024 ];
479483 gethostname (hostname, 1024 );
480484
481485 // asLibRoutines changes the hostnames to lower-case; some OSs are not so kind.
482486 testOk (!epicsStrCaseCmp (hostname, jsonParser.host .c_str ()),
483- " %s - %s" , testPrefix, " Hostname check" );
487+ " %s - %s - exp '%s' act '%s'" , testPrefix, " Hostname check" ,
488+ hostname, jsonParser.host .c_str ());
484489
485490 // Test username
486491 char username[1024 ];
487492 osiGetUserName (username, 1024 );
488493 testOk (!jsonParser.user .compare (username),
489- " %s - %s" , testPrefix, " Username check" );
494+ " %s - %s - exp '%s' act '%s'" , testPrefix, " Username check" ,
495+ username, jsonParser.user .c_str ());
490496
491497 testOk (!jsonParser.pv .compare (pvname),
492- " %s - %s" , testPrefix, " PV name check" );
498+ " %s - %s - exp '%s' act '%s'" , testPrefix, " PV name check" ,
499+ pvname, jsonParser.pv .c_str ());
493500
494501 // Test Metadata
495502 testOk (metadata_compare (jsonParser.metadata , logger->getMetadata ()),
@@ -526,19 +533,23 @@ void testDbf(const char *pv, chtype type,
526533 for (size_t i = 0 ; i < json.newVal .size (); i++) {
527534 if (isnan (*(value1 + i))) {
528535 testOk (!json.newVal .at (i).compare (" Nan" ),
529- " %s - %s" , testPrefix, " New value check" );
536+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 1" ,
537+ i, " Nan" , json.newVal .at (i).c_str ());
530538 }
531539 else if (isinf (*(value1 + i) && *(value1 + i) > 0 )) {
532540 testOk (!json.newVal .at (i).compare (" Infinity" ),
533- " %s - %s" , testPrefix, " New value check" );
541+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 1" ,
542+ i, " Infinity" , json.newVal .at (i).c_str ());
534543 }
535544 else if (isinf (*(value1 + i) && *(value1 + i) < 0 )) {
536545 testOk (!json.newVal .at (i).compare (" -Infinity" ),
537- " %s - %s" , testPrefix, " New value check" );
546+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 1" ,
547+ i, " -Infinity" , json.newVal .at (i).c_str ());
538548 }
539549 else {
540550 testOk (!json.newVal .at (i).compare (toString (*(value1 + i))),
541- " %s - %s" , testPrefix, " New value check" );
551+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 1" ,
552+ i, toString (*(value1 + i)).c_str (), json.newVal .at (i).c_str ());
542553 }
543554 }
544555 }
@@ -562,39 +573,47 @@ void testDbf(const char *pv, chtype type,
562573 for (size_t i = 0 ; i < json.newVal .size (); i++) {
563574 if (isnan (*(value2 + i))) {
564575 testOk (!json.newVal .at (i).compare (" Nan" ),
565- " %s - %s" , testPrefix, " New value check" );
576+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 2" ,
577+ i, " Nan" , json.newVal .at (i).c_str ());
566578 }
567579 else if (isinf (*(value2 + i)) && *(value2 + i) > 0 ) {
568580 testOk (!json.newVal .at (i).compare (" Infinity" ),
569- " %s - %s" , testPrefix, " New value check" );
581+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 2" ,
582+ i, " Infinity" , json.newVal .at (i).c_str ());
570583 }
571584 else if (isinf (*(value2 + i)) && *(value2 + i) < 0 ) {
572585 testOk (!json.newVal .at (i).compare (" -Infinity" ),
573- " %s - %s" , testPrefix, " New value check" );
586+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 2" ,
587+ i, " -Infinity" , json.newVal .at (i).c_str ());
574588 }
575589 else {
576590 testOk (!json.newVal .at (i).compare (toString (*(value2 + i))),
577- " %s - %s" , testPrefix, " New value check" );
591+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 2" ,
592+ i, toString (*(value2 + i)).c_str (), json.newVal .at (i).c_str ());
578593 }
579594 }
580595
581596 // Old Value check
582597 for (size_t i = 0 ; i < json.oldVal .size (); i++) {
583598 if (isnan (*(value1 + i))) {
584599 testOk (!json.oldVal .at (i).compare (" Nan" ),
585- " %s - %s" , testPrefix, " New value check" );
600+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " Old value check" ,
601+ i, " Nan" , json.oldVal .at (i).c_str ());
586602 }
587603 else if (isinf (*(value1 + i) && *(value1 + i) > 0 )) {
588604 testOk (!json.oldVal .at (i).compare (" Infinity" ),
589- " %s - %s" , testPrefix, " New value check" );
605+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " Old value check" ,
606+ i, " Infinity" , json.oldVal .at (i).c_str ());
590607 }
591608 else if (isinf (*(value1 + i) && *(value1 + i) < 0 )) {
592609 testOk (!json.oldVal .at (i).compare (" -Infinity" ),
593- " %s - %s" , testPrefix, " New value check" );
610+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " Old value check" ,
611+ i, " -Infinity" , json.oldVal .at (i).c_str ());
594612 }
595613 else {
596614 testOk (!json.oldVal .at (i).compare (toString (*(value1 + i))),
597- " %s - %s" , testPrefix, " New value check" );
615+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " Old value check" ,
616+ i, toString (*(value1 + i)).c_str (), json.oldVal .at (i).c_str ());
598617 }
599618 }
600619 }
@@ -627,8 +646,11 @@ void testDbf<dbr_string_t>(const char *pv, chtype type,
627646
628647 // New Value check
629648 for (size_t i = 0 ; i < json.newVal .size (); i++) {
630- testOk (!json.newVal .at (i).compare (value1 + i*MAX_STRING_SIZE),
631- " %s - %s" , testPrefix, " New value check" );
649+ char *cval = value1 + i*MAX_STRING_SIZE;
650+ std::string sval (cval, std::min<size_t >(MAX_STRING_SIZE, strlen (cval)));
651+ testOk (!json.newVal .at (i).compare (sval),
652+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 1" ,
653+ i, sval.c_str (), json.newVal .at (i).c_str ());
632654 }
633655 }
634656
@@ -649,14 +671,20 @@ void testDbf<dbr_string_t>(const char *pv, chtype type,
649671
650672 // New Value check
651673 for (size_t i = 0 ; i < json.newVal .size (); i++) {
652- testOk (!json.newVal .at (i).compare (value2 + i*MAX_STRING_SIZE),
653- " %s - %s" , testPrefix, " New value check" );
674+ char *cval = value2 + i*MAX_STRING_SIZE;
675+ std::string sval (cval, std::min<size_t >(MAX_STRING_SIZE, strlen (cval)));
676+ testOk (!json.newVal .at (i).compare (sval),
677+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " New value check 2" ,
678+ i, sval.c_str (), json.newVal .at (i).c_str ());
654679 }
655680
656681 // Old Value check
657682 for (size_t i = 0 ; i < json.newVal .size (); i++) {
658- testOk (!json.oldVal .at (i).compare (value1 + i*MAX_STRING_SIZE),
659- " %s - %s" , testPrefix, " Old value check" );
683+ char *cval = value1 + i*MAX_STRING_SIZE;
684+ std::string sval (cval, std::min<size_t >(MAX_STRING_SIZE, strlen (cval)));
685+ testOk (!json.oldVal .at (i).compare (sval),
686+ " %s - %s - elem %lu exp '%s' act '%s'" , testPrefix, " Old value check" ,
687+ i, sval.c_str (), json.oldVal .at (i).c_str ());
660688 }
661689 }
662690}
@@ -688,7 +716,8 @@ void testDbf(const char *pv, chtype type,
688716
689717 // New Value check
690718 testOk (!json.newVal .at (0 ).compare (std::string (value1, value1Size)),
691- " %s - %s" , testPrefix, " New value check" );
719+ " %s - %s - exp '%s' act '%s'" , testPrefix, " New value check 1" ,
720+ std::string (value1, value1Size).c_str (), json.newVal .at (0 ).c_str ());
692721 }
693722
694723 // Second put -> we check new and old value
@@ -708,11 +737,13 @@ void testDbf(const char *pv, chtype type,
708737
709738 // New Value check
710739 testOk (!json.newVal .at (0 ).compare (std::string (value2, value2Size)),
711- " %s - %s" , testPrefix, " New value check" );
740+ " %s - %s - exp '%s' act '%s'" , testPrefix, " New value check 2" ,
741+ std::string (value2, value2Size).c_str (), json.newVal .at (0 ).c_str ());
712742
713743 // Old Value check
714744 testOk (!json.oldVal .at (0 ).compare (std::string (value1, value1Size)),
715- " %s - %s" , testPrefix, " New value check" );
745+ " %s - %s - exp '%s' act '%s'" , testPrefix, " Old value check" ,
746+ std::string (value1, value1Size).c_str (), json.oldVal .at (0 ).c_str ());
716747 }
717748}
718749
0 commit comments