File: I18nTest.cpp

package info (click to toggle)
xournalpp 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,036 kB
  • sloc: cpp: 64,137; xml: 939; sh: 752; ansic: 362; python: 338; php: 74; makefile: 15
file content (81 lines) | stat: -rw-r--r-- 2,082 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * Xournal++
 *
 * This file is part of the Xournal UnitTests
 *
 * @author Xournal++ Team
 * https://github.com/xournalpp/xournalpp
 *
 * @license GNU GPLv2 or later
 */

#include <cstdlib>
#include <ctime>

#include <gtest/gtest.h>

#include "util/i18n.h"

#include "config-test.h"


using namespace std;


TEST(UtilI18n, testNoPlaceholder) {
    string msg = FS(FORMAT_STR("test123") % 1 % 2 % 3);

    EXPECT_EQ(std::string("test123"), msg);
}

TEST(UtilI18n, testEscape) {
    string msg = FS(FORMAT_STR("test{{123") % 1 % 2 % 3);

    EXPECT_EQ(std::string("test{123"), msg);
}

TEST(UtilI18n, testReplace) {
    string msg = FS(FORMAT_STR("aa {1} bb {1} {2}") % 1 % 2 % 3);

    EXPECT_EQ(std::string("aa 1 bb 1 2"), msg);
}

TEST(UtilI18n, testMissing) {
    string msg = FS(FORMAT_STR("aa {1} bb {1} {2}"));

    EXPECT_EQ(std::string("aa {1} bb {1} {2}"), msg);
}

TEST(UtilI18n, testOrder) {
    string msg = FS(FORMAT_STR(".. {2} .. {1} -- {2} {1}") % "a" % "b");

    EXPECT_EQ(std::string(".. b .. a -- b a"), msg);
}

TEST(UtilI18n, testLatexString) {
    string command =
            FS(FORMAT_STR("{1} -m 0 \"\\png\\usepackage{{color}}\\color{{{2}}}\\dpi{{{3}}}\\normalsize {4}\" -o {5}") %
               "abc" % "red" % 45 % "asdf" % "asdf.png");
    EXPECT_EQ(std::string("abc -m 0 \"\\png\\usepackage{color}\\color{red}\\dpi{45}\\normalsize asdf\" -o asdf.png"),
              command);
}

TEST(UtilI18n, test3) {
    string msg = FS(FORMAT_STR(" of {1}{2}") % 5 % 6);
    EXPECT_EQ(std::string(" of 56"), msg);
}

TEST(UtilI18n, test16bit) {
    string msg = FS(FORMAT_STR("{1} = {2} and {3}") % 60123 % 60123U % -65536);
    EXPECT_EQ(std::string("60123 = 60123 and -65536"), msg);
}

TEST(UtilI18n, test32bit) {
    string msg = FS(FORMAT_STR("{1} and {2}") % 4294967295U % -12345678);
    EXPECT_EQ(std::string("4294967295 and -12345678"), msg);
}

TEST(UtilI18n, test64bit) {
    string msg = FS(FORMAT_STR("{1} and {2}") % 1234567890123456789U % -1234567890123456789);
    EXPECT_EQ(std::string("1234567890123456789 and -1234567890123456789"), msg);
}