/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ /** i18n unit tests @copyright Intra2net AG */ #define BOOST_TEST_DYN_LINK #include #include "i18n.h" #include #include using namespace std; BOOST_AUTO_TEST_SUITE(TestI18n) BOOST_AUTO_TEST_CASE(GetString) { vector data; data.push_back("dummy"); string result = i18n_get_string("$0 test string", data); BOOST_CHECK_EQUAL("dummy test string", result); } BOOST_AUTO_TEST_CASE(MissingParameter) { vector data; string result = i18n_get_string("$0 test string", data); BOOST_CHECK_EQUAL("i18n parameter error: missing variable ->$0<- in string ->$0 test string<-", result); } BOOST_AUTO_TEST_CASE(MissingNumberAfterDollar) { vector data; string result = i18n_get_string("$ test string", data); BOOST_CHECK_EQUAL("i18n syntax error: $ without number at pos ->0<- in string ->$ test string<-", result); } BOOST_AUTO_TEST_CASE(MissingNumberAfterDollar2) { vector data; string result = i18n_get_string("$x test string", data); BOOST_CHECK_EQUAL("i18n syntax error: $ without number at pos ->0<- in string ->$x test string<-", result); } BOOST_AUTO_TEST_CASE(BrokenNumberAfterDollar) { vector data; string result = i18n_get_string("$x test string", data); BOOST_CHECK_EQUAL("i18n syntax error: $ without number at pos ->0<- in string ->$x test string<-", result); } BOOST_AUTO_TEST_CASE(KeepEscapedDollarSign) { vector data; data.push_back("dummy"); string result = i18n_get_string("$0 $$ test string", data); BOOST_CHECK_EQUAL("dummy $ test string", result); } BOOST_AUTO_TEST_CASE(StdStringInput) { vector data; data.push_back("dummy"); const string input = "$0 test string"; string result = i18n_get_string(input, data); BOOST_CHECK_EQUAL("dummy test string", result); } BOOST_AUTO_TEST_CASE(PluralString0) { // Zero elements get the plural message (in the default "plural" configuration) BOOST_CHECK_EQUAL("xxx new messages", i18n_plural("One new message", "xxx new messages", 0)); } BOOST_AUTO_TEST_CASE(PluralString1) { BOOST_CHECK_EQUAL("One new message", i18n_plural("One new message", "xxx new messages", 1)); } BOOST_AUTO_TEST_CASE(PluralString2) { BOOST_CHECK_EQUAL("xxx new messages", i18n_plural("One new message", "xxx new messages", 2)); } BOOST_AUTO_TEST_CASE(PluralStringWithParamter1) { vector data; data.push_back("1"); BOOST_CHECK_EQUAL("1 new message", i18n_get_string(i18n_plural("$0 new message", "$0 new messages", 1), data)); } BOOST_AUTO_TEST_CASE(PluralStringWithParamter2) { vector data; data.push_back("500"); BOOST_CHECK_EQUAL("500 new messages", i18n_get_string(i18n_plural("$0 new message", "$0 new messages", 500), data)); } BOOST_AUTO_TEST_CASE(Convenience0) { string result = i18n_get_string("$0!", "Energize"); BOOST_CHECK_EQUAL("Energize!", result); } BOOST_AUTO_TEST_CASE(Convenience1) { string result = i18n_get_string("Make $0 $1!", "it", "so"); BOOST_CHECK_EQUAL("Make it so!", result); } BOOST_AUTO_TEST_CASE(Convenience2) { string result = i18n_get_string("$0, $1, $2!", "Tea", "Earl Grey", "hot"); BOOST_CHECK_EQUAL("Tea, Earl Grey, hot!", result); } BOOST_AUTO_TEST_CASE(Noop) { BOOST_CHECK_EQUAL(i18n_noop("Test"), "Test"); BOOST_CHECK_EQUAL(i18n_noop(" Test "), " Test "); } BOOST_AUTO_TEST_SUITE_END()