Unit test for i18n_get_string()
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 12 Dec 2011 16:31:33 +0000 (17:31 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 12 Dec 2011 16:31:33 +0000 (17:31 +0100)
test/CMakeLists.txt
test/test_i18n.cpp [new file with mode: 0644]

index 2fd6fdb..d1de23e 100644 (file)
@@ -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 (file)
index 0000000..c3cd21c
--- /dev/null
@@ -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 <boost/test/unit_test.hpp>
+
+#include "i18n.h"
+#include <vector>
+#include <string>
+
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(TestI18n)
+
+BOOST_AUTO_TEST_CASE(GetString)
+{
+    vector<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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()