mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Moved currently unused i18n code out of build path.
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
<test name='net.sf.briar.db.BasicH2Test'/>
|
||||
<test name='net.sf.briar.db.DatabaseCleanerImplTest'/>
|
||||
<test name='net.sf.briar.db.DatabaseComponentImplTest'/>
|
||||
<test name='net.sf.briar.i18n.I18nTest'/>
|
||||
<test name='net.sf.briar.lifecycle.ShutdownManagerImplTest'/>
|
||||
<test name='net.sf.briar.lifecycle.WindowsShutdownManagerImplTest'/>
|
||||
<test name='net.sf.briar.plugins.PluginManagerImplTest'/>
|
||||
@@ -70,7 +69,6 @@
|
||||
</classpath>
|
||||
<jvmarg value='-Djava.library.path=../libs'/>
|
||||
<test name='net.sf.briar.db.H2DatabaseTest'/>
|
||||
<test name='net.sf.briar.i18n.FontManagerTest'/>
|
||||
<test name='net.sf.briar.plugins.tor.TorPluginTest'/>
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package net.sf.briar.i18n;
|
||||
import java.awt.Font;
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.i18n.FontManager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class FontManagerTest extends BriarTestCase {
|
||||
|
||||
private final File fontDir = TestUtils.getFontDirectory();
|
||||
|
||||
@Test
|
||||
public void testBundledFontsAreLoaded() {
|
||||
FontManager fontManager = new FontManagerImpl();
|
||||
fontManager.initialize(Locale.UK, fontDir);
|
||||
|
||||
Font font = fontManager.getFontForLanguage("en"); // English
|
||||
assertEquals(12, font.getSize());
|
||||
|
||||
// The exact font names vary by platform, so just check how they start
|
||||
font = fontManager.getFontForLanguage("bo"); // Tibetan
|
||||
assertTrue(font.getFamily().startsWith("Tibetan"));
|
||||
assertEquals(14, font.getSize());
|
||||
|
||||
font = fontManager.getFontForLanguage("my"); // Burmese
|
||||
assertTrue(font.getFamily().startsWith("Padauk"));
|
||||
assertEquals(14, font.getSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInternationalCharactersCanBeDisplayed() {
|
||||
FontManager fontManager = new FontManagerImpl();
|
||||
fontManager.initialize(Locale.UK, fontDir);
|
||||
|
||||
Font font = fontManager.getFontForLanguage("en"); // English
|
||||
assertTrue(font.canDisplay('a'));
|
||||
|
||||
font = fontManager.getFontForLanguage("ar"); // Arabic
|
||||
assertTrue(font.canDisplay('\u0627')); // An Arabic character
|
||||
|
||||
font = fontManager.getFontForLanguage("bo"); // Tibetan
|
||||
assertTrue(font.canDisplay('\u0f00')); // A Tibetan character
|
||||
|
||||
font = fontManager.getFontForLanguage("fa"); // Persian
|
||||
assertTrue(font.canDisplay('\ufb56')); // A Persian character
|
||||
|
||||
font = fontManager.getFontForLanguage("my"); // Burmese
|
||||
assertTrue(font.canDisplay('\u1000')); // A Burmese character
|
||||
|
||||
font = fontManager.getFontForLanguage("zh"); // Chinese
|
||||
assertTrue(font.canDisplay('\u4e00')); // A Chinese character
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetUiFont() {
|
||||
FontManager fontManager = new FontManagerImpl();
|
||||
fontManager.initialize(Locale.UK, fontDir);
|
||||
Font font = fontManager.getUiFont();
|
||||
assertEquals(12, font.getSize());
|
||||
|
||||
fontManager.setUiFontForLanguage("bo");
|
||||
font = fontManager.getUiFont();
|
||||
assertTrue(font.getFamily().startsWith("Tibetan"));
|
||||
assertEquals(14, font.getSize());
|
||||
|
||||
fontManager.setUiFontForLanguage("en");
|
||||
font = fontManager.getUiFont();
|
||||
assertEquals(12, font.getSize());
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package net.sf.briar.i18n;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.i18n.FontManager;
|
||||
import net.sf.briar.api.i18n.I18n;
|
||||
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class I18nTest extends BriarTestCase {
|
||||
|
||||
private final File base =
|
||||
new File(TestUtils.getBuildDirectory(), "i18n.properties");
|
||||
private final File french =
|
||||
new File(TestUtils.getBuildDirectory(), "i18n_fr.properties");
|
||||
private final File testDir = TestUtils.getTestDirectory();
|
||||
|
||||
FontManager fontManager = null;
|
||||
I18n i18n = null;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
TestUtils.createFile(base, "FOO=foo\r\nBAR=bar\r\n");
|
||||
TestUtils.createFile(french, "FOO=le foo\r\nBAR=la bar\r\n");
|
||||
fontManager = new FontManagerImpl();
|
||||
fontManager.initialize(Locale.UK, TestUtils.getFontDirectory());
|
||||
i18n = new I18nImpl(fontManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTr() {
|
||||
i18n.setLocale(Locale.UK);
|
||||
assertEquals("foo", i18n.tr("FOO"));
|
||||
i18n.setLocale(Locale.FRANCE);
|
||||
assertEquals("le foo", i18n.tr("FOO"));
|
||||
i18n.setLocale(Locale.CHINA); // No translation - use default
|
||||
assertEquals("foo", i18n.tr("FOO"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettingLocaleAffectsComponentOrientation() {
|
||||
i18n.setLocale(new Locale("en")); // English
|
||||
assertTrue(i18n.getComponentOrientation().isLeftToRight());
|
||||
i18n.setLocale(new Locale("ar")); // Arabic
|
||||
assertFalse(i18n.getComponentOrientation().isLeftToRight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListenersAreInformedOfLocaleChanges() {
|
||||
final Font englishFont = fontManager.getFontForLanguage("en");
|
||||
final Font tibetanFont = fontManager.getFontForLanguage("bo");
|
||||
|
||||
Mockery context = new Mockery();
|
||||
final I18n.Listener listener = context.mock(I18n.Listener.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Listener should be called once when registered
|
||||
oneOf(listener).localeChanged(englishFont);
|
||||
// Listener should be called again when locale changes
|
||||
oneOf(listener).localeChanged(tibetanFont);
|
||||
}});
|
||||
|
||||
i18n.setLocale(new Locale("en"));
|
||||
i18n.addListener(listener);
|
||||
i18n.setLocale(new Locale("bo"));
|
||||
i18n.removeListener(listener);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveAndLoadLocale() throws IOException {
|
||||
testDir.mkdirs();
|
||||
File f = new File(testDir, "locale.cfg");
|
||||
i18n.setLocale(new Locale("fr"));
|
||||
assertEquals("le foo", i18n.tr("FOO"));
|
||||
i18n.saveLocale(f);
|
||||
i18n.setLocale(new Locale("zh")); // No translation - use default
|
||||
assertEquals("foo", i18n.tr("FOO"));
|
||||
i18n.loadLocale(f);
|
||||
assertEquals("le foo", i18n.tr("FOO"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
TestUtils.delete(base);
|
||||
TestUtils.delete(french);
|
||||
TestUtils.deleteTestDirectory(testDir);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user