2017-01-24 22:04:05 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.test;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils;
|
|
|
|
|
2017-03-05 19:44:31 +01:00
|
|
|
import static org.junit.Assert.assertEquals;
|
2017-01-24 22:04:05 +01:00
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests LanguageUtils
|
|
|
|
*/
|
|
|
|
public class LanguageUtilsTest extends TestBase {
|
|
|
|
@Test
|
2017-03-04 22:08:24 +01:00
|
|
|
public void testStringTransliterateCyrillic() throws Exception {
|
2017-01-24 22:04:05 +01:00
|
|
|
//input with cyrillic and diacritic letters
|
|
|
|
String input = "Прõсто текčт";
|
|
|
|
String output = LanguageUtils.transliterate(input);
|
|
|
|
String result = "Prosto tekct";
|
|
|
|
|
2017-03-05 19:44:31 +01:00
|
|
|
assertEquals("Transliteration failed", result, output);
|
2017-01-24 22:04:05 +01:00
|
|
|
}
|
2017-03-04 22:08:24 +01:00
|
|
|
|
|
|
|
@Test
|
2017-03-04 22:46:41 +01:00
|
|
|
public void testStringTransliterateHebrew() throws Exception {
|
2017-03-04 22:08:24 +01:00
|
|
|
String input = "בדיקה עברית";
|
|
|
|
String output = LanguageUtils.transliterate(input);
|
2017-03-05 19:44:31 +01:00
|
|
|
String result = "bdykh 'bryth";
|
2017-03-04 22:08:24 +01:00
|
|
|
|
2017-03-05 19:44:31 +01:00
|
|
|
assertEquals("Transliteration failed", result, output);
|
2017-03-04 22:08:24 +01:00
|
|
|
}
|
2017-01-24 22:04:05 +01:00
|
|
|
|
2017-12-02 06:26:00 +01:00
|
|
|
@Test
|
|
|
|
public void testStringTransliterateArabic() {
|
|
|
|
String pangram = "نص حكيم له سر قاطع وذو شأن عظيم مكتوب على ثوب أخضر ومغلف بجلد أزرق";
|
|
|
|
String pangramExpected = "n9 7kym lh sr qa63 wthw sh2n 36'ym mktwb 3la thwb 259'r wm3'lf bjld 2zrq";
|
|
|
|
String pangramActual = LanguageUtils.transliterate(pangram);
|
2018-02-26 07:51:14 +01:00
|
|
|
assertEquals("pangram transliteration failed", pangramExpected, pangramActual);
|
|
|
|
|
|
|
|
String taMarbutah = "ﺓ";
|
|
|
|
String taMarbutahExpected = "";
|
|
|
|
String taMarbutahActual = LanguageUtils.transliterate(taMarbutah);
|
|
|
|
assertEquals("ta marbutah transliteration failed", taMarbutahExpected, taMarbutahActual);
|
2017-12-02 06:26:00 +01:00
|
|
|
|
|
|
|
String hamza = "ءأؤإئآ";
|
|
|
|
String hamzaExpected = "222222";
|
|
|
|
String hamzaActual = LanguageUtils.transliterate(hamza);
|
|
|
|
assertEquals("hamza transliteration failed", hamzaExpected, hamzaActual);
|
|
|
|
|
|
|
|
String farsi = "پچڜڤڥڨگݣ";
|
|
|
|
String farsiExpected = "pchchvvggg";
|
|
|
|
String farsiActual = LanguageUtils.transliterate(farsi);
|
|
|
|
assertEquals("Farsi transiteration failed", farsiExpected, farsiActual);
|
|
|
|
}
|
|
|
|
|
2017-11-22 18:57:05 +01:00
|
|
|
public void testStringTransliterateBengali() throws Exception {
|
|
|
|
//input with cyrillic and diacritic letters
|
|
|
|
String input = "অনিরুদ্ধ";
|
|
|
|
String output = LanguageUtils.transliterate(input);
|
|
|
|
String result = "oniruddho";
|
|
|
|
|
|
|
|
assertEquals("Transliteration failed", result, output);
|
|
|
|
}
|
|
|
|
|
2018-08-12 10:31:35 +02:00
|
|
|
@Test
|
|
|
|
public void testStringTransliterateLithuanian() {
|
|
|
|
String input = "ą č ę ė į š ų ū ž";
|
|
|
|
String output = LanguageUtils.transliterate(input);
|
|
|
|
String expected = "a c e e i s u u z";
|
|
|
|
assertEquals("lithuanian translation failed", expected, output);
|
|
|
|
|
|
|
|
input = "aąa cčc eęe eėe iįi sšs uųu uūu zžz";
|
|
|
|
output = LanguageUtils.transliterate(input);
|
|
|
|
expected = "aaa ccc eee eee iii sss uuu uuu zzz";
|
|
|
|
assertEquals("lithuanian translation failed", expected, output);
|
|
|
|
}
|
|
|
|
|
2017-01-24 22:04:05 +01:00
|
|
|
@Test
|
|
|
|
public void testTransliterateOption() throws Exception {
|
2017-04-08 23:59:00 +02:00
|
|
|
setDefaultTransliteration();
|
2017-01-24 22:04:05 +01:00
|
|
|
assertFalse("Transliteration option fail! Expected 'Off' by default, but result is 'On'", LanguageUtils.transliterate());
|
|
|
|
|
2017-04-08 23:59:00 +02:00
|
|
|
enableTransliteration(true);
|
|
|
|
assertTrue("Transliteration option fail! Expected 'On', but result is 'Off'", LanguageUtils.transliterate());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setDefaultTransliteration() {
|
2017-01-24 22:04:05 +01:00
|
|
|
SharedPreferences settings = GBApplication.getPrefs().getPreferences();
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
2017-04-08 23:59:00 +02:00
|
|
|
editor.remove("transliteration");
|
2017-03-04 22:46:41 +01:00
|
|
|
editor.apply();
|
2017-04-08 23:59:00 +02:00
|
|
|
}
|
2017-01-24 22:04:05 +01:00
|
|
|
|
2017-04-08 23:59:00 +02:00
|
|
|
private void enableTransliteration(boolean enable) {
|
|
|
|
SharedPreferences settings = GBApplication.getPrefs().getPreferences();
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
editor.putBoolean("transliteration", enable);
|
|
|
|
editor.apply();
|
2017-01-24 22:04:05 +01:00
|
|
|
}
|
|
|
|
}
|