@@ -34,68 +34,84 @@ int nrTests = 0, nrErrors = 0, nrWarnings = 0;
3434
3535// test the alphabet conversion routines
3636static void alphabet_tests () {
37- int i ;
37+ int i , j ;
3838 const char * str , * expect ;
39+ static const char * testpairs [] = {
40+ ".123" ,".123" ,
41+ "" ,"" ,
42+ "-" ,"-" ,
43+ "." ,"." ,
44+ "-123" ,"-123" ,
45+ "-xyz" ,"-XYZ" ,
46+ ".xyz" ,".XYZ" ,
47+ "12.34" ,"12.34" ,
48+ "OEUoi OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789euEUABCDFGHJKLMNPQRSTVWXYZ" , "OEUoi OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789EUEUABCDFGHJ" ,
49+ "OEUoi OIoi#%?abcdfghjklmnpqrstvwxyz0123456789euEUABCDFGHJKLMNPQRSTVWXYZ" , "OEUoi OIOI#%?ABCDFGHJKLMNPQRSTVWXYZ0123456789EUEUABCDFGHJKL" ,
50+ " Oio 12.AU " ,"Oio 12.AU" ,
51+ "OMN 112.3EU" ,"OMN 112.3EU" ,
52+ "49.4V" ,"49.4V" ,
53+ "NLD 49.4V-xx123" ,"NLD 49.4V-XX123" ,
54+ "xx.xx" ,"XX.XX" ,
55+ "xx.xxx" ,"XX.XXX" ,
56+ "xxx.xx" ,"XXX.XX" ,
57+ "xx.xxxx" ,"XX.XXXX" ,
58+ "xxx.xxx" ,"XXX.XXX" ,
59+ "xxxx.xx" ,"XXXX.XX" ,
60+ "xxx.xxxx" ,"XXX.XXXX" ,
61+ "xxxx.xxx" ,"XXXX.XXX" ,
62+ "xxxx.xxxx" ,"XXXX.XXXX" ,
63+ "xxxxx.xxxx" ,"XXXXX.XXXX" ,
64+ "pq.rs" ,"PQ.RS" ,
65+ "bc.123" ,"BC.123" ,
66+ "123.xy" ,"123.XY" ,
67+ " nld 12.34E0" ,"nld 12.34E0" ,
68+ "VVX.xxx" ,"VVX.XXX" ,
69+ "x123.xx" ,"X123.XX" ,
70+ "xxx.xxxx" ,"XXX.XXXX" ,
71+ "12xx.xxx" ,"12XX.XXX" ,
72+ "xxxx.xx12" ,"XXXX.XX12" ,
73+ "99zxx.xxxx" ,"99ZXX.XXXX" ,
74+ "xx.xx-P" ,"XX.XX-P" ,
75+ "xx.xxx-pq" ,"XX.XXX-PQ" ,
76+ "xxx.xx-123" ,"XXX.XX-123" ,
77+ "xx.xxxx-pqRS" ,"XX.XXXX-PQRS" ,
78+ "xxx.xxx-PQRSTUVW" ,"XXX.XXX-PQRSTUVW" ,
79+ "xxxx.xx-pqrstuvw" ,"XXXX.XX-PQRSTUVW" ,
80+ "xxx.xxxx-PQrsTU" ,"XXX.XXXX-PQRSTU" ,
81+ "xxxx.xxx-09876543" ,"XXXX.XXX-09876543" ,
82+ "xxxx.xxxx-PQRSTUVW" ,"XXXX.XXXX-PQRSTUVW" ,
83+ "xxxxx.xxxx-PQRSTUVW" ,"XXXXX.XXXX-PQRSTUVW" ,
84+ "pq.rs-PQRSTUVW" ,"PQ.RS-PQRSTUVW" ,
85+ "bc.123-PQRSTUVW" ,"BC.123-PQRSTUVW" ,
86+ "123.xy-PQRSTUVW" ,"123.XY-PQRSTUVW" ,
87+ "12.34E0-PQRSTUVW" ,"12.34E0-PQRSTUVW" ,
88+ "VVX.xxx-PQRSTUVW" ,"VVX.XXX-PQRSTUVW" ,
89+ "x123.xx-PQRSTUVW" ,"X123.XX-PQRSTUVW" ,
90+ "xxx.xxxx-PQRSTUVW" ,"XXX.XXXX-PQRSTUVW" ,
91+ "12xx.xxx-PQRSTUVW" ,"12XX.XXX-PQRSTUVW" ,
92+ "xxxx.xx12-PQRSTUVW" ,"XXXX.XX12-PQRSTUVW" ,
93+ "99zxx.xxxx-PQRSTUVW" ,"99ZXX.XXXX-PQRSTUVW" ,
94+ NULL
95+ };
3996
4097 printf ("%d alphabets\n" , MAPCODE_ALPHABETS_TOTAL );
4198
42- for (i = 0 ; i < MAPCODE_ALPHABETS_TOTAL ; i ++ ) {
43- UWORD enc [64 ];
44- char dec [64 ];
45-
46- // see if convertToAlphabet survives empty string
47- nrTests ++ ;
48- str = "" ;
49- convertToAlphabet (enc , 64 , str , i );
50- if (* enc ) {
51- nrErrors ++ ;
52- printf ("*** ERROR *** convertToAlphabet(\"%s\",%d) = \"%s\"\n" , str , i , dec );
53- }
54- else {
55- // see if empty UTF16 converts to empty string
99+ for (j = 0 ;testpairs [j ]!= NULL ;j += 2 )
100+ {
101+ for (i = 0 ; i < MAPCODE_ALPHABETS_TOTAL ; i ++ ) {
102+ UWORD enc [64 ];
103+ char dec [64 ];
104+ // see if alphabets (re)convert as expected
105+ str = testpairs [j ];
106+ expect = testpairs [j + 1 ];
107+ convertToAlphabet (enc , 64 , str , i );
108+ convertToRoman (dec , 60 , enc );
56109 nrTests ++ ;
57- convertToRoman (dec , 64 , enc );
58- if (* dec ) {
110+ if (strcmp (dec , expect )) {
59111 nrErrors ++ ;
60- printf ("*** ERROR *** convertToRoman(\"\") = \"%s\"\n" , dec );
61- }
62- }
63-
64- // see if alphabets (re)convert as expected
65- str = "OEUoi OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789ABCDFGHJKLMNPQRSTVWXYZ" ;
66- expect = "OEUoi OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789ABCDFGHJKLMN" ;
67- convertToAlphabet (enc , 64 , str , i );
68- convertToRoman (dec , 60 , enc );
69- nrTests ++ ;
70- if (strlen (dec ) != 59 || strcmp (dec , expect )) {
71- nrErrors ++ ;
72- printf ("*** ERROR *** convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\", expect=\"%s\"\n" , str , i , dec , expect );
73- }
74-
75- // see if E/U voweled mapcodes (re)convert as expected
76- str = "OMN 112.3EU" ;
77- convertToAlphabet (enc , 64 , str , i );
78- convertToRoman (dec , 64 , enc );
79- nrTests ++ ;
80- if (strcmp (dec , str ) != 0 ) {
81- nrErrors ++ ;
82- printf ("*** ERROR *** convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\"\n" , str , i , dec );
83- }
84- else {
85- nrTests ++ ;
86- {
87- str = " Oio 112.3AU " ;
88- convertToAlphabet (enc , 64 , str , i );
89- convertToRoman (dec , 64 , enc );
90- nrTests ++ ;
91- if (strcmp (dec , "Oio 112.3AU" ) != 0 ) {
92- nrErrors ++ ;
93- printf ("*** ERROR *** convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\"\n" , str , i , dec );
94- }
112+ printf ("convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\"\n" , str , i , dec );
95113 }
96114 }
97-
98-
99115 }
100116}
101117
@@ -251,8 +267,8 @@ static void testEncodeAndDecode(const char *str, double y, double x, int localso
251267 int tc2 = -1 ;
252268 int tcParent = -1 ;
253269 int j ;
254- found = 0 ;
255270 char * e = strchr (strResult , ' ' );
271+ found = 0 ;
256272 if (e ) {
257273 * e = 0 ;
258274 tc2 = convertTerritoryIsoNameToCode (strResult , 0 );
0 commit comments