Teach symstore more duplicated DLLs
[LibreOffice.git] / writerfilter / qa / cppunittests / misc / misc.cxx
blobf59695ae368fe5c85fbda5e8b87fb9339164425d
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 <limits>
11 #include <tuple>
12 #include <vector>
14 #include <cppunit/TestAssert.h>
15 #include <cppunit/TestFixture.h>
16 #include <cppunit/extensions/HelperMacros.h>
17 #include <cppunit/plugin/TestPlugIn.h>
19 #include <sal/types.h>
21 #include <rtl/ustring.hxx>
22 #include <dmapper/ConversionHelper.hxx>
23 #include <dmapper/DomainMapper_Impl.hxx>
25 namespace {
27 class WriterfilterMiscTest
28 : public ::CppUnit::TestFixture
30 public:
31 void testTwipConversions();
32 void testFieldParameters();
34 CPPUNIT_TEST_SUITE(WriterfilterMiscTest);
35 CPPUNIT_TEST(testTwipConversions);
36 CPPUNIT_TEST(testFieldParameters);
37 CPPUNIT_TEST_SUITE_END();
40 void WriterfilterMiscTest::testTwipConversions()
42 using writerfilter::dmapper::ConversionHelper::convertTwipToMM100;
43 using writerfilter::dmapper::ConversionHelper::convertTwipToMM100Unsigned;
45 CPPUNIT_ASSERT_EQUAL(sal_Int32(-2), convertTwipToMM100(-1));
46 CPPUNIT_ASSERT_EQUAL(sal_Int32(-17639), convertTwipToMM100(-10000));
47 CPPUNIT_ASSERT_EQUAL(sal_Int32(-70556), convertTwipToMM100(-40000));
48 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), convertTwipToMM100(1));
49 CPPUNIT_ASSERT_EQUAL(sal_Int32(17639), convertTwipToMM100(10000));
50 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), convertTwipToMM100(40000));
52 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-1));
53 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-10000));
54 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-40000));
55 CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), convertTwipToMM100Unsigned(1));
56 CPPUNIT_ASSERT_EQUAL(sal_uInt32(17639), convertTwipToMM100Unsigned(10000));
57 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(40000));
60 void WriterfilterMiscTest::testFieldParameters()
62 using writerfilter::dmapper::splitFieldCommand;
63 std::tuple<OUString, std::vector<OUString>, std::vector<OUString> > result;
65 result = splitFieldCommand("PAGEREF last_page");
66 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
67 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
68 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
69 CPPUNIT_ASSERT(std::get<2>(result).empty());
71 result = splitFieldCommand(" PAGEREF last_page ");
72 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
73 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
74 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
76 result = splitFieldCommand("pageref last_page");
77 CPPUNIT_ASSERT(std::get<2>(result).empty());
78 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
79 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
80 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
81 CPPUNIT_ASSERT(std::get<2>(result).empty());
83 result = splitFieldCommand("pageref \"last_page\"");
84 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
85 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
86 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
87 CPPUNIT_ASSERT(std::get<2>(result).empty());
89 result = splitFieldCommand("\"PAGEREF\" \"last_page\" \"\" ");
90 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
91 CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<1>(result).size());
92 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
93 CPPUNIT_ASSERT_EQUAL(OUString(), std::get<1>(result)[1]);
94 CPPUNIT_ASSERT(std::get<2>(result).empty());
96 result = splitFieldCommand("\"PAGEREF\"\"last_page\" ");
97 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
98 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
99 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
100 CPPUNIT_ASSERT(std::get<2>(result).empty());
102 result = splitFieldCommand("PAGEREF\"last_page\" ");
103 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
104 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
105 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
106 CPPUNIT_ASSERT(std::get<2>(result).empty());
108 result = splitFieldCommand("\"PAGEREF\"last_page \"\"");
109 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
110 CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<1>(result).size());
111 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
112 CPPUNIT_ASSERT_EQUAL(OUString(), std::get<1>(result)[1]);
113 CPPUNIT_ASSERT(std::get<2>(result).empty());
115 result = splitFieldCommand("\"PAGEREF\"last_page \"\"");
116 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
117 CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<1>(result).size());
118 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
119 CPPUNIT_ASSERT_EQUAL(OUString(), std::get<1>(result)[1]);
120 CPPUNIT_ASSERT(std::get<2>(result).empty());
122 result = splitFieldCommand("pageref \"last\\\\pa\\\"ge\"");
123 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
124 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
125 CPPUNIT_ASSERT_EQUAL(OUString("last\\pa\"ge"), std::get<1>(result)[0]);
126 CPPUNIT_ASSERT(std::get<2>(result).empty());
128 result = splitFieldCommand("PAGEREF\"last_page\"\\*");
129 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
130 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
131 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
132 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<2>(result).size());
133 CPPUNIT_ASSERT_EQUAL(OUString("\\*"), std::get<2>(result)[0]);
135 result = splitFieldCommand("PAGEREF last_page \\b foobar ");
136 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
137 CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size());
138 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]);
139 CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<2>(result).size());
140 CPPUNIT_ASSERT_EQUAL(OUString("\\B"), std::get<2>(result)[0]);
141 CPPUNIT_ASSERT_EQUAL(OUString("foobar"), std::get<2>(result)[1]);
143 result = splitFieldCommand("PAGEREF\\bfoobar\\A\"\"");
144 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result));
145 CPPUNIT_ASSERT(std::get<1>(result).empty());
146 CPPUNIT_ASSERT_EQUAL(size_t(4), std::get<2>(result).size());
147 CPPUNIT_ASSERT_EQUAL(OUString("\\B"), std::get<2>(result)[0]);
148 CPPUNIT_ASSERT_EQUAL(OUString("foobar"), std::get<2>(result)[1]);
149 CPPUNIT_ASSERT_EQUAL(OUString("\\A"), std::get<2>(result)[2]);
150 CPPUNIT_ASSERT_EQUAL(OUString(), std::get<2>(result)[3]);
152 for (auto prefix : {"#", "$", "%", "&", "'", "(", ")", "*", "+", ",",
153 "-", ".", "/", ":", ";", "<", ">", "?", "@", "[",
154 "]", "^", "_", "`", "{", "|", "}", "~"})
156 OUString test(OUString::createFromAscii(prefix) + "PAGE");
157 result = splitFieldCommand(test + " ");
158 CPPUNIT_ASSERT_EQUAL(test, std::get<0>(result));
160 result = splitFieldCommand("\\PAGE ");
161 CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), std::get<0>(result));
162 result = splitFieldCommand("\\ PAGE ");
163 CPPUNIT_ASSERT_EQUAL(OUString("\\ "), std::get<0>(result));
164 CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), std::get<1>(result)[0]);
165 result = splitFieldCommand("\\\\PAGE ");
166 CPPUNIT_ASSERT_EQUAL(OUString("\\PAGE"), std::get<0>(result));
167 result = splitFieldCommand("\"PAGE\" ");
168 CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), std::get<0>(result));
169 result = splitFieldCommand("\"PAGE ");
170 CPPUNIT_ASSERT_EQUAL(OUString("PAGE "), std::get<0>(result));
173 CPPUNIT_TEST_SUITE_REGISTRATION(WriterfilterMiscTest);
177 CPPUNIT_PLUGIN_IMPLEMENT();
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */