From: Thomas Jarosch Date: Mon, 12 Dec 2011 16:31:33 +0000 (+0100) Subject: Unit test for i18n_get_string() X-Git-Tag: v2.6~24 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=8652a3dfc616bc6589a9ee85bc8f45f04e7069eb;p=libi2ncommon Unit test for i18n_get_string() --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2fd6fdb..d1de23e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,6 +13,7 @@ SET(cpp_sources test_cron_point.cpp test_filefunc.cpp test_global_config.cpp + test_i18n.cpp test_logging.cpp test_pidfile.cpp test_timefunc.cpp diff --git a/test/test_i18n.cpp b/test/test_i18n.cpp new file mode 100644 index 0000000..c3cd21c --- /dev/null +++ b/test/test_i18n.cpp @@ -0,0 +1,89 @@ +/* +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_SUITE_END()