@@ -581,6 +581,50 @@ void test_territory_insides() {
581581 }
582582}
583583
584+ void territory_code_tests () {
585+ int i ;
586+
587+ static const struct {
588+ int expectedresult ;
589+ int context ;
590+ const char * inputstring ;
591+ } tcTestData [] = {
592+ {319 , 0 , "AL" }, //
593+ {483 ,497 , "AL" }, // 497=rus
594+ {483 ,431 , "AL" }, // 431=ru-tam
595+ {365 ,411 , "AL" }, // 411=usa
596+ {365 ,392 , "AL" }, // 392=us-ca
597+ { -1 , 0 , "" },
598+ { -1 , 0 , "R" },
599+ { -1 , 0 , "RX" },
600+ { -1 , 0 , "RXX" },
601+ {497 , 0 , "RUS" },
602+ { -1 , 0 , "RUSSIA" },
603+ {411 , 0 , "US" },
604+ {411 , 0 , "USA" },
605+ {411 , 0 , "usa" },
606+ { -1 , 0 , "US-TEST" },
607+ {411 , 0 , "US TEST" },
608+ {392 , 0 , "US-CA" },
609+ {392 , 0 , "US-CA TEST" },
610+ {392 , 0 , "USA-CA" },
611+ {431 , 0 , "RUS-TAM" },
612+ { -1 , 0 , "RUS-TAMX" },
613+ {431 , 0 , "RUS-TAM X" },
614+ {0 ,0 ,NULL }
615+ };
616+
617+ for (i = 0 ; tcTestData [i ].inputstring != NULL ; i ++ ) {
618+ int tc = getTerritoryCode (tcTestData [i ].inputstring , tcTestData [i ].context );
619+ nrTests ++ ;
620+ if (tc != tcTestData [i ].expectedresult ) {
621+ nrErrors ++ ;
622+ printf ("*** ERROR *** getTerritoryCode(%s)=%d, expected %d\n" ,
623+ tcTestData [i ].inputstring , tc , tcTestData [i ].expectedresult );
624+ }
625+ }
626+ }
627+
584628
585629void main () {
586630#ifdef XSIDE3
@@ -598,6 +642,7 @@ void main() {
598642 printf ("-----------------------------------------------------------\nTerritory tests\n" );
599643 printf ("%d territories\n" , MAX_CCODE );
600644 test_territories ();
645+ territory_code_tests ();
601646 test_territory_insides ();
602647
603648 printf ("-----------------------------------------------------------\nFailing decode tests\n" );
0 commit comments