c3cd21c1019731270e4b2b1886f61153d185a086
[libi2ncommon] / test / test_i18n.cpp
1 /*
2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
4
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
7
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.
13
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.
16
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.
19 */
20 /**
21    i18n unit tests
22
23    @copyright Intra2net AG
24 */
25
26 #define BOOST_TEST_DYN_LINK
27 #include <boost/test/unit_test.hpp>
28
29 #include "i18n.h"
30 #include <vector>
31 #include <string>
32
33 using namespace std;
34
35 BOOST_AUTO_TEST_SUITE(TestI18n)
36
37 BOOST_AUTO_TEST_CASE(GetString)
38 {
39     vector<string> data;
40     data.push_back("dummy");
41
42     string result = i18n_get_string("$0 test string", data);
43
44     BOOST_CHECK_EQUAL("dummy test string", result);
45 }
46
47 BOOST_AUTO_TEST_CASE(MissingParameter)
48 {
49     vector<string> data;
50     string result = i18n_get_string("$0 test string", data);
51
52     BOOST_CHECK_EQUAL("i18n parameter error: missing variable ->$0<- in string ->$0 test string<-", result);
53 }
54
55 BOOST_AUTO_TEST_CASE(MissingNumberAfterDollar)
56 {
57     vector<string> data;
58     string result = i18n_get_string("$ test string", data);
59
60     BOOST_CHECK_EQUAL("i18n syntax error: $ without number at pos ->0<- in string ->$ test string<-", result);
61 }
62
63 BOOST_AUTO_TEST_CASE(MissingNumberAfterDollar2)
64 {
65     vector<string> data;
66     string result = i18n_get_string("$x test string", data);
67
68     BOOST_CHECK_EQUAL("i18n syntax error: $ without number at pos ->0<- in string ->$x test string<-", result);
69 }
70
71 BOOST_AUTO_TEST_CASE(BrokenNumberAfterDollar)
72 {
73     vector<string> data;
74     string result = i18n_get_string("$x test string", data);
75
76     BOOST_CHECK_EQUAL("i18n syntax error: $ without number at pos ->0<- in string ->$x test string<-", result);
77 }
78
79 BOOST_AUTO_TEST_CASE(KeepEscapedDollarSign)
80 {
81     vector<string> data;
82     data.push_back("dummy");
83
84     string result = i18n_get_string("$0 $$ test string", data);
85
86     BOOST_CHECK_EQUAL("dummy $ test string", result);
87 }
88
89 BOOST_AUTO_TEST_SUITE_END()