android: Update app-specific/MIME type icons
[LibreOffice.git] / writerfilter / qa / cppunittests / misc / misc.cxx
blob845e43b053e8f38de518dacebf7d01b0ec3af25a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <tuple>
11 #include <vector>
13 #include <cppunit/TestAssert.h>
14 #include <cppunit/TestFixture.h>
15 #include <cppunit/extensions/HelperMacros.h>
16 #include <cppunit/plugin/TestPlugIn.h>
18 #include <sal/types.h>
20 #include <rtl/ustring.hxx>
21 #include <dmapper/ConversionHelper.hxx>
22 #include <dmapper/DomainMapperFactory.hxx>
24 namespace
26 class WriterfilterMiscTest : public ::CppUnit::TestFixture
28 public:
29 void testTwipConversions();
30 void testFieldParameters();
32 CPPUNIT_TEST_SUITE(WriterfilterMiscTest);
33 CPPUNIT_TEST(testTwipConversions);
34 CPPUNIT_TEST(testFieldParameters);
35 CPPUNIT_TEST_SUITE_END();
38 void WriterfilterMiscTest::testTwipConversions()
40 using writerfilter::dmapper::ConversionHelper::convertTwipToMM100;
41 using writerfilter::dmapper::ConversionHelper::convertTwipToMM100Unsigned;
43 CPPUNIT_ASSERT_EQUAL(sal_Int32(-2), convertTwipToMM100(-1));
44 CPPUNIT_ASSERT_EQUAL(sal_Int32(-17639), convertTwipToMM100(-10000));
45 CPPUNIT_ASSERT_EQUAL(sal_Int32(-70556), convertTwipToMM100(-40000));
46 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), convertTwipToMM100(1));
47 CPPUNIT_ASSERT_EQUAL(sal_Int32(17639), convertTwipToMM100(10000));
48 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), convertTwipToMM100(40000));
50 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-1));
51 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-10000));
52 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-40000));
53 CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), convertTwipToMM100Unsigned(1));
54 CPPUNIT_ASSERT_EQUAL(sal_uInt32(17639), convertTwipToMM100Unsigned(10000));
55 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(40000));
58 void WriterfilterMiscTest::testFieldParameters()
60 using writerfilter::dmapper::splitFieldCommand;
61 std::tuple<OUString, std::vector<OUString>, std::vector<OUString>> result;
63 result = splitFieldCommand(u"PAGEREF last_page");
64 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
65 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
66 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
67 CPPUNIT_ASSERT(std::get<2>(result).empty());
69 result = splitFieldCommand(u" PAGEREF last_page ");
70 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
71 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
72 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
74 result = splitFieldCommand(u"pageref last_page");
75 CPPUNIT_ASSERT(std::get<2>(result).empty());
76 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
77 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
78 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
79 CPPUNIT_ASSERT(std::get<2>(result).empty());
81 result = splitFieldCommand(u"pageref \"last_page\"");
82 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
83 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
84 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
85 CPPUNIT_ASSERT(std::get<2>(result).empty());
87 result = splitFieldCommand(u"\"PAGEREF\" \"last_page\" \"\" ");
88 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
89 CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<1>(result).size());
90 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
91 CPPUNIT_ASSERT_EQUAL(OUString(), std::get<1>(result)[1]);
92 CPPUNIT_ASSERT(std::get<2>(result).empty());
94 result = splitFieldCommand(u"\"PAGEREF\"\"last_page\" ");
95 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
96 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
97 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
98 CPPUNIT_ASSERT(std::get<2>(result).empty());
100 result = splitFieldCommand(u"PAGEREF\"last_page\" ");
101 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
102 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
103 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
104 CPPUNIT_ASSERT(std::get<2>(result).empty());
106 result = splitFieldCommand(u"\"PAGEREF\"last_page \"\"");
107 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
108 CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<1>(result).size());
109 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
110 CPPUNIT_ASSERT_EQUAL(OUString(), std::get<1>(result)[1]);
111 CPPUNIT_ASSERT(std::get<2>(result).empty());
113 result = splitFieldCommand(u"\"PAGEREF\"last_page \"\"");
114 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
115 CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<1>(result).size());
116 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
117 CPPUNIT_ASSERT_EQUAL(OUString(), std::get<1>(result)[1]);
118 CPPUNIT_ASSERT(std::get<2>(result).empty());
120 result = splitFieldCommand(u"pageref \"last\\\\pa\\\"ge\"");
121 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
122 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
123 CPPUNIT_ASSERT_EQUAL(OUString("last\\pa\"ge"), std::get<1>(result)[0]);
124 CPPUNIT_ASSERT(std::get<2>(result).empty());
126 result = splitFieldCommand(u"PAGEREF\"last_page\"\\*");
127 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
128 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
129 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
130 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<2>(result).size());
131 CPPUNIT_ASSERT_EQUAL(OUString("\\*"), std::get<2>(result)[0]);
133 result = splitFieldCommand(u"PAGEREF last_page \\b foobar ");
134 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
135 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
136 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
137 CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<2>(result).size());
138 CPPUNIT_ASSERT_EQUAL(OUString("\\B"), std::get<2>(result)[0]);
139 CPPUNIT_ASSERT_EQUAL(OUString("foobar"), std::get<2>(result)[1]);
141 result = splitFieldCommand(u"PAGEREF\\bfoobar\\A\"\"");
142 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
143 CPPUNIT_ASSERT(std::get<1>(result).empty());
144 CPPUNIT_ASSERT_EQUAL(size_t(4), std::get<2>(result).size());
145 CPPUNIT_ASSERT_EQUAL(OUString("\\B"), std::get<2>(result)[0]);
146 CPPUNIT_ASSERT_EQUAL(OUString("foobar"), std::get<2>(result)[1]);
147 CPPUNIT_ASSERT_EQUAL(OUString("\\A"), std::get<2>(result)[2]);
148 CPPUNIT_ASSERT_EQUAL(OUString(), std::get<2>(result)[3]);
150 for (auto prefix : { "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", ":",
151 ";", "<", ">", "?", "@", "[", "]", "^", "_", "`", "{", "|", "}", "~" })
153 OUString test(OUString::createFromAscii(prefix) + "PAGE");
154 result = splitFieldCommand(Concat2View(test + " "));
155 CPPUNIT_ASSERT_EQUAL(test, std::get<0>(result));
157 result = splitFieldCommand(u"\\PAGE ");
158 CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), std::get<0>(result));
159 result = splitFieldCommand(u"\\ PAGE ");
160 CPPUNIT_ASSERT_EQUAL(OUString("\\ "), std::get<0>(result));
161 CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), std::get<1>(result)[0]);
162 result = splitFieldCommand(u"\\\\PAGE ");
163 CPPUNIT_ASSERT_EQUAL(OUString("\\PAGE"), std::get<0>(result));
164 result = splitFieldCommand(u"\"PAGE\" ");
165 CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), std::get<0>(result));
166 result = splitFieldCommand(u"\"PAGE ");
167 CPPUNIT_ASSERT_EQUAL(OUString("PAGE "), std::get<0>(result));
170 CPPUNIT_TEST_SUITE_REGISTRATION(WriterfilterMiscTest);
173 CPPUNIT_PLUGIN_IMPLEMENT();
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */