diff options
Diffstat (limited to 'intl/strres/tests')
-rw-r--r-- | intl/strres/tests/unit/397093.properties | 4 | ||||
-rw-r--r-- | intl/strres/tests/unit/strres.properties | 14 | ||||
-rw-r--r-- | intl/strres/tests/unit/test_bug378839.js | 58 | ||||
-rw-r--r-- | intl/strres/tests/unit/test_bug397093.js | 39 | ||||
-rw-r--r-- | intl/strres/tests/unit/xpcshell.ini | 8 |
5 files changed, 123 insertions, 0 deletions
diff --git a/intl/strres/tests/unit/397093.properties b/intl/strres/tests/unit/397093.properties new file mode 100644 index 0000000000..88303d447a --- /dev/null +++ b/intl/strres/tests/unit/397093.properties @@ -0,0 +1,4 @@ +# Property file for test_bug397093.js +asciiProperty=Foo +utf8Property=Fòò +latin1Property=Fòò diff --git a/intl/strres/tests/unit/strres.properties b/intl/strres/tests/unit/strres.properties new file mode 100644 index 0000000000..388f5acff7 --- /dev/null +++ b/intl/strres/tests/unit/strres.properties @@ -0,0 +1,14 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +file=File +loyal=\u5fe0\u5fc3 +trout=é³Ÿéš +edit= Edit +view=View +go=\u0020Go +message=Message\u0020 +communicator=Communicator +help=Help +123=onetwothree +hello=Hello %S diff --git a/intl/strres/tests/unit/test_bug378839.js b/intl/strres/tests/unit/test_bug378839.js new file mode 100644 index 0000000000..b3bc76f3d6 --- /dev/null +++ b/intl/strres/tests/unit/test_bug378839.js @@ -0,0 +1,58 @@ +/* Tests getting properties from string bundles + */ + +const name_file = "file"; +const value_file = "File"; + +const name_loyal = "loyal"; +const value_loyal = "\u5fe0\u5fc3"; // tests escaped Unicode + +const name_trout = "trout"; +const value_trout = "\u9cdf\u9b5a"; // tests UTF-8 + +const name_edit = "edit"; +const value_edit = "Edit"; // tests literal leading spaces are stripped + +const name_view = "view"; +const value_view = "View"; // tests literal trailing spaces are stripped + +const name_go = "go"; +const value_go = " Go"; // tests escaped leading spaces are not stripped + +const name_message = "message"; +const value_message = "Message "; // tests escaped trailing spaces are not stripped + +const name_hello = "hello"; +const var_hello = "World"; +const value_hello = "Hello World"; // tests formatStringFromName with parameter + +function run_test() { + var StringBundle = Services.strings; + var bundleURI = Services.io.newFileURI(do_get_file("strres.properties")); + + var bundle = StringBundle.createBundle(bundleURI.spec); + + var bundle_file = bundle.GetStringFromName(name_file); + Assert.equal(bundle_file, value_file); + + var bundle_loyal = bundle.GetStringFromName(name_loyal); + Assert.equal(bundle_loyal, value_loyal); + + var bundle_trout = bundle.GetStringFromName(name_trout); + Assert.equal(bundle_trout, value_trout); + + var bundle_edit = bundle.GetStringFromName(name_edit); + Assert.equal(bundle_edit, value_edit); + + var bundle_view = bundle.GetStringFromName(name_view); + Assert.equal(bundle_view, value_view); + + var bundle_go = bundle.GetStringFromName(name_go); + Assert.equal(bundle_go, value_go); + + var bundle_message = bundle.GetStringFromName(name_message); + Assert.equal(bundle_message, value_message); + + var bundle_hello = bundle.formatStringFromName(name_hello, [var_hello]); + Assert.equal(bundle_hello, value_hello); +} diff --git a/intl/strres/tests/unit/test_bug397093.js b/intl/strres/tests/unit/test_bug397093.js new file mode 100644 index 0000000000..a2bb1eb236 --- /dev/null +++ b/intl/strres/tests/unit/test_bug397093.js @@ -0,0 +1,39 @@ +/* Tests getting properties from string bundles with incorrect encoding. + * The string bundle contains one ascii property, one UTF-8 and one Latin-1. + * Expected behaviour is that the whole string bundle should be rejected and + * all GetStringFromName calls should fail. + */ + +const name_ascii = "asciiProperty"; +const value_ascii = ""; + +const name_utf8 = "utf8Property"; +const value_utf8 = ""; + +const name_latin1 = "latin1"; +const value_latin1 = ""; + +function run_test() { + var StringBundle = Services.strings; + var bundleURI = Services.io.newFileURI(do_get_file("397093.properties")); + + var bundle = StringBundle.createBundle(bundleURI.spec); + + var bundle_ascii = "", + bundle_utf8 = "", + bundle_latin1 = ""; + try { + bundle_ascii = bundle.GetStringFromName(name_ascii); + } catch (e) {} + Assert.equal(bundle_ascii, value_ascii); + + try { + bundle_utf8 = bundle.GetStringFromName(name_utf8); + } catch (e) {} + Assert.equal(bundle_utf8, value_utf8); + + try { + bundle_latin1 = bundle.GetStringFromName(name_latin1); + } catch (e) {} + Assert.equal(bundle_latin1, value_latin1); +} diff --git a/intl/strres/tests/unit/xpcshell.ini b/intl/strres/tests/unit/xpcshell.ini new file mode 100644 index 0000000000..49840c144a --- /dev/null +++ b/intl/strres/tests/unit/xpcshell.ini @@ -0,0 +1,8 @@ +[DEFAULT] +head = +support-files = + 397093.properties + strres.properties + +[test_bug378839.js] +[test_bug397093.js] |