5050
5151#include <pthread.h>
5252
53- static const double METERS_PER_DEGREE_LAT = 110946.252133 ;
54- static const double METERS_PER_DEGREE_LON = 111319.490793 ;
55-
5653#define MAX_THREADS 16 // Optimal: not too much, approx. nr of cores * 2, better no more than 32.
5754static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER ;
5855#endif
@@ -1026,9 +1023,11 @@ static void testDistance(double d1, double d2) {
10261023
10271024
10281025static int testDistances (void ) {
1026+ static const double METERS_PER_DEGREE_LAT = 110946.252133 ;
1027+ static const double METERS_PER_DEGREE_LON = 111319.490793 ;
10291028 int nrTests = 0 ;
10301029 int i ;
1031- const double coordpairs [] = {
1030+ static const double coordpairs [] = {
10321031 // lat1, lon1, lat2, lon2, expected distance * 100000
10331032 1 , 1 , 1 , 1 , 0 ,
10341033 0 , 0 , 0 , 1 , 11131949079 ,
@@ -1380,6 +1379,7 @@ static int testCorrectDecode(char *mc, enum Territory tc) {
13801379 double lon1 ;
13811380 double lat2 ;
13821381 double lon2 ;
1382+ UWORD utf16 [MAX_CLEAN_MAPCODE_LEN + 1 ];
13831383 int rc = decodeMapcodeToLatLonUtf8 (& lat1 , & lon1 , mc , tc , NULL );
13841384 if (rc < 0 ) {
13851385 foundError ();
@@ -1391,7 +1391,6 @@ static int testCorrectDecode(char *mc, enum Territory tc) {
13911391 printf ("*** ERROR *** decodeMapcodeToLatLonUtf8 returns '%d' (should be 0) for mapcode='%s'\n" , rc , mc );
13921392 }
13931393
1394- UWORD utf16 [MAX_CLEAN_MAPCODE_LEN + 1 ];
13951394 convertMapcodeToAlphabetUtf16 (utf16 , mc , ALPHABET_ARABIC );
13961395 rc = decodeMapcodeToLatLonUtf16 (& lat2 , & lon2 , utf16 , tc , NULL );
13971396 if (rc < 0 ) {
@@ -1876,6 +1875,33 @@ static int testAlphabets(void) {
18761875 int j ;
18771876 const char * str , * expect ;
18781877 static const char * TEST_PAIRS [] = {
1878+ "irl xx.xxxx" , "IRL XX.XXXX" , // Grid24
1879+ "cck XX.XX" , "CCK XX.XX" , // nameless22
1880+ "cze XX.XXX" , "CZE XX.XXX" , // nameless23
1881+ "NLD XXX.XX" , "NLD XXX.XX" , // nameless32
1882+ "VAT 5d.dd" , "VAT 5D.DD" , // Grid22
1883+ "NLD XX.XXX" , "NLD XX.XXX" , // Grid23
1884+ "bhr xxx.xx" , "BHR XXX.XX" , // Grid32
1885+ "FRA XXX.XXX" , "FRA XXX.XXX" , // Grid33
1886+ "irl xx.xxxx" , "IRL XX.XXXX" , // Grid24
1887+ "cub xxxx.xx" , "CUB XXXX.XX" , // Grid42
1888+ "ben xxxx.xxx" , "BEN XXXX.XXX" , // Grid34
1889+ "USA xxxx.xxxx" , "USA XXXX.XXXX" , // Grid44
1890+ "US-AZ hhh.hh" , "US-AZ HHH.HH" , // HGrid32
1891+ "Bel hhh.hhh" , "BEL HHH.HHH" , // HGrid33
1892+ "PAN hh.hhhh" , "PAN HH.HHHH" , // HGrid24
1893+ "GRC hhhh.hh" , "GRC HHHH.HH" , // HGrid42
1894+ "NZL hhhh.hhh" , "NZL HHHH.HHH" , // HGrid43
1895+ "KAZ hhh.hhhh" , "KAZ HHH.HHHH" , // HGrid34
1896+ "RUS xxxx.xxxx" , "RUS XXXX.XXXX" , // HGrid44
1897+ "CN-SH hhhh.hhhh" , "CN-SH HHHH.HHHH" , // HGrid44
1898+ "VAT hhhhh.hhhh" , "VAT HHHHH.HHHH" , // HGrid54
1899+ "hhhhh.hhhh" , "HHHHH.HHHH" , // HGrid54
1900+ "TUV hh.hhh" , "TUV HH.HHH" , // AutoHeader23
1901+ "LVA L88.ZVR" , "LVA L88.ZVR" , // AutoHeader33
1902+ "WLF XLG.3GP" , "WLF XLG.3GP" , // HGrid33 R
1903+ "VAT j0q3.27r" , "VAT J0Q3.27R" , // HGrid43 R
1904+ "PAK hhhh.hhhh" , "PAK HHHH.HHHH" , // HGrid44 R
18791905 "xxx.xxxx" , "XXX.XXXX" ,
18801906 "nld XX.XX" , "NLD XX.XX" ,
18811907 ".123" , "" ,
@@ -1944,6 +1970,20 @@ static int testAlphabets(void) {
19441970 str = TEST_PAIRS [j ];
19451971 expect = TEST_PAIRS [j + 1 ];
19461972 convertMapcodeToAlphabetUtf16 (enc , str , i );
1973+ {
1974+ char utf8 [3 * MAX_MAPCODE_RESULT_LEN + 1 ];
1975+ MapcodeElements mapcodeElements ;
1976+ double lat1 , lon1 , lat2 , lon2 , lat3 , lon3 ;
1977+ convertMapcodeToAlphabetUtf8 (utf8 , str , i );
1978+ decodeMapcodeToLatLonUtf16 (& lat1 , & lon1 , enc , TERRITORY_FRA , & mapcodeElements );
1979+ decodeMapcodeToLatLonUtf8 (& lat2 , & lon2 , utf8 , TERRITORY_FRA , & mapcodeElements );
1980+ decodeMapcodeToLatLonUtf8 (& lat3 , & lon3 , str , TERRITORY_FRA , & mapcodeElements );
1981+ ++ nrTests ;
1982+ if (lat1 != lat2 || lon1 != lon2 || lat1 != lat3 || lon1 != lon3 ) {
1983+ foundError ();
1984+ printf ("*** ERROR *** Difference in ascii/utf8/utf16 decoding %s\n" , str );
1985+ }
1986+ }
19471987 myConvertToRoman (dec , enc );
19481988 ++ nrTests ;
19491989 if (strcmp (dec , expect )) {
0 commit comments