@@ -387,31 +387,48 @@ static int test_mapcode_formats(void) {
387387
388388 NULL , NULL
389389 };
390+ int shouldSucceed = 29 ; // Number of calls to parse() that should be successful.
391+ int total = 0 ;
392+ int succeeded = 0 ;
390393 for (i = 0 ; testpairs [i ] != NULL ; i += 2 ) {
391394 char str [MAX_MAPCODE_RESULT_LEN + 16 ];
392- MapcodeElements mapcodeFormat ;
393- int err = parseMapcodeString (& mapcodeFormat , testpairs [i ], 1 , 0 );
395+ MapcodeElements mapcodeElements ;
396+ int result = parseMapcodeString (& mapcodeElements , testpairs [i ], 1 , 0 );
397+ int format = hasMapcodeFormat (testpairs [i ], 1 );
398+
394399 nrTests ++ ;
395- if (err == 0 ) {
400+ if ((!result && format ) || (result && !format )) {
401+ found_error ();
402+ printf ("*** ERROR *** parseMapcodeString=%d, hasMapcodeFormat=%d\n" , result , format );
403+ }
404+
405+ nrTests ++ ;
406+ ++ total ;
407+ if (result == 0 ) {
408+ ++ succeeded ;
396409 sprintf (str , "%s%s%s%s%s|%d" ,
397- mapcodeFormat .territoryISO ,
398- * mapcodeFormat .territoryISO ? " " : "" ,
399- mapcodeFormat .properMapcode ,
400- * mapcodeFormat .precisionExtension ? "-" : "" ,
401- mapcodeFormat .precisionExtension ,
402- (mapcodeFormat .indexOfDot * 9 ) + (int ) strlen (mapcodeFormat .properMapcode ) - 1 );
410+ mapcodeElements .territoryISO ,
411+ * mapcodeElements .territoryISO ? " " : "" ,
412+ mapcodeElements .properMapcode ,
413+ * mapcodeElements .precisionExtension ? "-" : "" ,
414+ mapcodeElements .precisionExtension ,
415+ (mapcodeElements .indexOfDot * 9 ) + (int ) strlen (mapcodeElements .properMapcode ) - 1 );
403416 if (strcmp (str , testpairs [i + 1 ]) != 0 ) {
404417 found_error ();
405- printf ("*** ERROR *** compareWithMapcodeFormat (\"%s\") succeeded with \"%s\"\n" , testpairs [i ], str );
418+ printf ("*** ERROR *** parseMapcodeString (\"%s\") succeeded with \"%s\"\n" , testpairs [i ], str );
406419 }
407420 } else {
408- sprintf (str , "%d" , err );
421+ sprintf (str , "%d" , result );
409422 if (testpairs [i + 1 ][0 ] != 0 && strcmp (str , testpairs [i + 1 ]) != 0 ) {
410423 found_error ();
411- printf ("*** ERROR *** compareWithMapcodeFormat (\"%s\") failed unexpectedly %d\n" , testpairs [i ], err );
424+ printf ("*** ERROR *** hasMapcodeFormat (\"%s\") failed unexpectedly %d\n" , testpairs [i ], result );
412425 }
413426 }
414427 }
428+ if (succeeded != shouldSucceed ) {
429+ found_error ();
430+ printf ("*** ERROR *** Too few parseMapcodeString() calls succeeded (%d of %d, expected %d)\n" , succeeded , total , shouldSucceed );
431+ }
415432 return nrTests ;
416433}
417434
0 commit comments