2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
23 @copyright Intra2net AG
26 #define BOOST_TEST_DYN_LINK
27 #include <boost/test/unit_test.hpp>
35 BOOST_AUTO_TEST_SUITE(TestI18n)
37 BOOST_AUTO_TEST_CASE(GetString)
40 data.push_back("dummy");
42 string result = i18n_get_string("$0 test string", data);
44 BOOST_CHECK_EQUAL("dummy test string", result);
47 BOOST_AUTO_TEST_CASE(MissingParameter)
50 string result = i18n_get_string("$0 test string", data);
52 BOOST_CHECK_EQUAL("i18n parameter error: missing variable ->$0<- in string ->$0 test string<-", result);
55 BOOST_AUTO_TEST_CASE(MissingNumberAfterDollar)
58 string result = i18n_get_string("$ test string", data);
60 BOOST_CHECK_EQUAL("i18n syntax error: $ without number at pos ->0<- in string ->$ test string<-", result);
63 BOOST_AUTO_TEST_CASE(MissingNumberAfterDollar2)
66 string result = i18n_get_string("$x test string", data);
68 BOOST_CHECK_EQUAL("i18n syntax error: $ without number at pos ->0<- in string ->$x test string<-", result);
71 BOOST_AUTO_TEST_CASE(BrokenNumberAfterDollar)
74 string result = i18n_get_string("$x test string", data);
76 BOOST_CHECK_EQUAL("i18n syntax error: $ without number at pos ->0<- in string ->$x test string<-", result);
79 BOOST_AUTO_TEST_CASE(KeepEscapedDollarSign)
82 data.push_back("dummy");
84 string result = i18n_get_string("$0 $$ test string", data);
86 BOOST_CHECK_EQUAL("dummy $ test string", result);
89 BOOST_AUTO_TEST_CASE(StdStringInput)
92 data.push_back("dummy");
94 const string input = "$0 test string";
95 string result = i18n_get_string(input, data);
97 BOOST_CHECK_EQUAL("dummy test string", result);
100 BOOST_AUTO_TEST_CASE(PluralString0)
102 // Zero elements get the plural message (in the default "plural" configuration)
103 BOOST_CHECK_EQUAL("xxx new messages", i18n_plural("One new message", "xxx new messages", 0));
106 BOOST_AUTO_TEST_CASE(PluralString1)
108 BOOST_CHECK_EQUAL("One new message", i18n_plural("One new message", "xxx new messages", 1));
111 BOOST_AUTO_TEST_CASE(PluralString2)
113 BOOST_CHECK_EQUAL("xxx new messages", i18n_plural("One new message", "xxx new messages", 2));
116 BOOST_AUTO_TEST_CASE(PluralStringWithParamter1)
121 BOOST_CHECK_EQUAL("1 new message", i18n_get_string(i18n_plural("$0 new message", "$0 new messages", 1), data));
124 BOOST_AUTO_TEST_CASE(PluralStringWithParamter2)
127 data.push_back("500");
129 BOOST_CHECK_EQUAL("500 new messages", i18n_get_string(i18n_plural("$0 new message", "$0 new messages", 500), data));
132 BOOST_AUTO_TEST_CASE(Convenience0)
134 string result = i18n_get_string("$0!", "Energize");
135 BOOST_CHECK_EQUAL("Energize!", result);
138 BOOST_AUTO_TEST_CASE(Convenience1)
140 string result = i18n_get_string("Make $0 $1!", "it", "so");
141 BOOST_CHECK_EQUAL("Make it so!", result);
144 BOOST_AUTO_TEST_CASE(Convenience2)
146 string result = i18n_get_string("$0, $1, $2!", "Tea", "Earl Grey", "hot");
147 BOOST_CHECK_EQUAL("Tea, Earl Grey, hot!", result);
150 BOOST_AUTO_TEST_CASE(Noop)
152 BOOST_CHECK_EQUAL(i18n_noop("Test"), "Test");
153 BOOST_CHECK_EQUAL(i18n_noop(" Test "), " Test ");
156 BOOST_AUTO_TEST_SUITE_END()