mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +01:00
Unit tests and bug fixes for international dialling.
This commit is contained in:
@@ -189,7 +189,7 @@ class CountryCodes {
|
|||||||
new Country("RE", "Reunion", "262", "00", "0"),
|
new Country("RE", "Reunion", "262", "00", "0"),
|
||||||
new Country("RO", "Romania", "40", "00", "0"),
|
new Country("RO", "Romania", "40", "00", "0"),
|
||||||
new Country("RS", "Serbia", "381", "99", "0"),
|
new Country("RS", "Serbia", "381", "99", "0"),
|
||||||
new Country("RU", "Russia", "7", " 8**10", "8"),
|
new Country("RU", "Russia", "7", "8**10", "8"),
|
||||||
new Country("RW", "Rwanda", "250", "00", "0"),
|
new Country("RW", "Rwanda", "250", "00", "0"),
|
||||||
new Country("SA", "Saudi Arabia", "966", "00", "0"),
|
new Country("SA", "Saudi Arabia", "966", "00", "0"),
|
||||||
new Country("SB", "Solomon Islands", "677", "00", ""),
|
new Country("SB", "Solomon Islands", "677", "00", ""),
|
||||||
@@ -264,20 +264,20 @@ class CountryCodes {
|
|||||||
// Strip the NDD prefix from the number if present
|
// Strip the NDD prefix from the number if present
|
||||||
if(number.startsWith(to.ndd))
|
if(number.startsWith(to.ndd))
|
||||||
number = number.substring(to.ndd.length());
|
number = number.substring(to.ndd.length());
|
||||||
if(from == to) return from.ndd + number;
|
if(from == to) return from.ndd + number; // National
|
||||||
return from.idd + to.countryCode + number;
|
return from.idd + to.countryCode + number; // International
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Country {
|
private static class Country {
|
||||||
|
|
||||||
private final String iso3166, countryCode, ndd, idd;
|
private final String iso3166, countryCode, idd, ndd;
|
||||||
|
|
||||||
private Country(String iso3166, String englishName, String countryCode,
|
private Country(String iso3166, String englishName, String countryCode,
|
||||||
String ndd, String idd) {
|
String idd, String ndd) {
|
||||||
this.iso3166 = iso3166;
|
this.iso3166 = iso3166;
|
||||||
this.countryCode = countryCode;
|
this.countryCode = countryCode;
|
||||||
this.ndd = ndd;
|
|
||||||
this.idd = idd;
|
this.idd = idd;
|
||||||
|
this.ndd = ndd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +85,7 @@
|
|||||||
<test name='net.sf.briar.plugins.file.PollingRemovableDriveMonitorTest'/>
|
<test name='net.sf.briar.plugins.file.PollingRemovableDriveMonitorTest'/>
|
||||||
<test name='net.sf.briar.plugins.file.RemovableDrivePluginTest'/>
|
<test name='net.sf.briar.plugins.file.RemovableDrivePluginTest'/>
|
||||||
<test name='net.sf.briar.plugins.file.UnixRemovableDriveMonitorTest'/>
|
<test name='net.sf.briar.plugins.file.UnixRemovableDriveMonitorTest'/>
|
||||||
|
<test name='net.sf.briar.plugins.modem.CountryCodesTest'/>
|
||||||
<test name='net.sf.briar.plugins.tcp.LanTcpPluginTest'/>
|
<test name='net.sf.briar.plugins.tcp.LanTcpPluginTest'/>
|
||||||
<test name='net.sf.briar.protocol.AckReaderTest'/>
|
<test name='net.sf.briar.protocol.AckReaderTest'/>
|
||||||
<test name='net.sf.briar.protocol.BatchReaderTest'/>
|
<test name='net.sf.briar.protocol.BatchReaderTest'/>
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package net.sf.briar.plugins.modem;
|
||||||
|
|
||||||
|
import net.sf.briar.BriarTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class CountryCodesTest extends BriarTestCase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTranslation() {
|
||||||
|
// Unknown country for caller
|
||||||
|
assertNull(CountryCodes.translate("02012345678", "ZZ", "GB"));
|
||||||
|
// Unknown country for callee
|
||||||
|
assertNull(CountryCodes.translate("02012345678", "GB", "ZZ"));
|
||||||
|
// GB to GB, callee has included NDD prefix
|
||||||
|
assertEquals("02012345678",
|
||||||
|
CountryCodes.translate("02012345678", "GB", "GB"));
|
||||||
|
// GB to GB, callee has included IDD prefix and country code
|
||||||
|
assertEquals("02012345678",
|
||||||
|
CountryCodes.translate("00442012345678", "GB", "GB"));
|
||||||
|
// GB to GB, callee has not included a prefix
|
||||||
|
assertEquals("02012345678",
|
||||||
|
CountryCodes.translate("2012345678", "GB", "GB"));
|
||||||
|
// Russia to GB, callee has included NDD prefix
|
||||||
|
assertEquals("8**10442012345678",
|
||||||
|
CountryCodes.translate("02012345678", "RU", "GB"));
|
||||||
|
// Russia to GB, callee has included IDD prefix and country code
|
||||||
|
assertEquals("8**10442012345678",
|
||||||
|
CountryCodes.translate("00442012345678", "RU", "GB"));
|
||||||
|
// Russia to GB, callee has not included a prefix
|
||||||
|
assertEquals("8**10442012345678",
|
||||||
|
CountryCodes.translate("2012345678", "RU", "GB"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user