1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
13 #include <boost/tuple/tuple.hpp>
15 #include <cppunit/TestAssert.h>
16 #include <cppunit/TestFixture.h>
17 #include <cppunit/extensions/HelperMacros.h>
18 #include <cppunit/plugin/TestPlugIn.h>
20 #include <sal/types.h>
22 #include <rtl/ustring.hxx>
23 #include <dmapper/ConversionHelper.hxx>
24 #include <dmapper/DomainMapper_Impl.hxx>
28 class WriterfilterMiscTest
29 : public ::CppUnit::TestFixture
32 virtual void setUp() SAL_OVERRIDE
;
33 virtual void tearDown() SAL_OVERRIDE
;
35 void testTwipConversions();
36 void testFieldParameters();
38 CPPUNIT_TEST_SUITE(WriterfilterMiscTest
);
39 CPPUNIT_TEST(testTwipConversions
);
40 CPPUNIT_TEST(testFieldParameters
);
41 CPPUNIT_TEST_SUITE_END();
44 void WriterfilterMiscTest::setUp()
48 void WriterfilterMiscTest::tearDown()
52 void WriterfilterMiscTest::testTwipConversions()
54 using writerfilter::dmapper::ConversionHelper::convertTwipToMM100
;
55 using writerfilter::dmapper::ConversionHelper::convertTwipToMM100Unsigned
;
57 CPPUNIT_ASSERT_EQUAL(sal_Int32(-2), convertTwipToMM100(-1));
58 CPPUNIT_ASSERT_EQUAL(sal_Int32(-17639), convertTwipToMM100(-10000));
59 CPPUNIT_ASSERT_EQUAL(sal_Int32(-70556), convertTwipToMM100(-40000));
60 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), convertTwipToMM100(1));
61 CPPUNIT_ASSERT_EQUAL(sal_Int32(17639), convertTwipToMM100(10000));
62 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), convertTwipToMM100(40000));
64 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-1));
65 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-10000));
66 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-40000));
67 CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), convertTwipToMM100Unsigned(1));
68 CPPUNIT_ASSERT_EQUAL(sal_uInt32(17639), convertTwipToMM100Unsigned(10000));
69 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(40000));
72 void WriterfilterMiscTest::testFieldParameters()
74 using writerfilter::dmapper::lcl_SplitFieldCommand
;
75 boost::tuple
<OUString
, std::vector
<OUString
>, std::vector
<OUString
> > result
;
77 result
= lcl_SplitFieldCommand("PAGEREF last_page");
78 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
79 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<1>(result
).size());
80 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
81 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
83 result
= lcl_SplitFieldCommand(" PAGEREF last_page ");
84 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
85 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<1>(result
).size());
86 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
88 result
= lcl_SplitFieldCommand("pageref last_page");
89 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
90 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
91 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<1>(result
).size());
92 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
93 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
95 result
= lcl_SplitFieldCommand("pageref \"last_page\"");
96 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
97 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<1>(result
).size());
98 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
99 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
101 result
= lcl_SplitFieldCommand("\"PAGEREF\" \"last_page\" \"\" ");
102 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
103 CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get
<1>(result
).size());
104 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
105 CPPUNIT_ASSERT_EQUAL(OUString(), boost::get
<1>(result
)[1]);
106 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
108 result
= lcl_SplitFieldCommand("\"PAGEREF\"\"last_page\" ");
109 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
110 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<1>(result
).size());
111 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
112 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
114 result
= lcl_SplitFieldCommand("PAGEREF\"last_page\" ");
115 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
116 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<1>(result
).size());
117 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
118 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
120 result
= lcl_SplitFieldCommand("\"PAGEREF\"last_page \"\"");
121 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
122 CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get
<1>(result
).size());
123 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
124 CPPUNIT_ASSERT_EQUAL(OUString(), boost::get
<1>(result
)[1]);
125 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
127 result
= lcl_SplitFieldCommand("\"PAGEREF\"last_page \"\"");
128 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
129 CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get
<1>(result
).size());
130 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
131 CPPUNIT_ASSERT_EQUAL(OUString(), boost::get
<1>(result
)[1]);
132 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
134 result
= lcl_SplitFieldCommand("pageref \"last\\\\pa\\\"ge\"");
135 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
136 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<1>(result
).size());
137 CPPUNIT_ASSERT_EQUAL(OUString("last\\pa\"ge"), boost::get
<1>(result
)[0]);
138 CPPUNIT_ASSERT(boost::get
<2>(result
).empty());
140 result
= lcl_SplitFieldCommand("PAGEREF\"last_page\"\\*");
141 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
142 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<1>(result
).size());
143 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
144 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<2>(result
).size());
145 CPPUNIT_ASSERT_EQUAL(OUString("\\*"), boost::get
<2>(result
)[0]);
147 result
= lcl_SplitFieldCommand("PAGEREF last_page \\b foobar ");
148 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
149 CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get
<1>(result
).size());
150 CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get
<1>(result
)[0]);
151 CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get
<2>(result
).size());
152 CPPUNIT_ASSERT_EQUAL(OUString("\\B"), boost::get
<2>(result
)[0]);
153 CPPUNIT_ASSERT_EQUAL(OUString("foobar"), boost::get
<2>(result
)[1]);
155 result
= lcl_SplitFieldCommand("PAGEREF\\bfoobar\\A\"\"");
156 CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get
<0>(result
));
157 CPPUNIT_ASSERT(boost::get
<1>(result
).empty());
158 CPPUNIT_ASSERT_EQUAL(size_t(4), boost::get
<2>(result
).size());
159 CPPUNIT_ASSERT_EQUAL(OUString("\\B"), boost::get
<2>(result
)[0]);
160 CPPUNIT_ASSERT_EQUAL(OUString("foobar"), boost::get
<2>(result
)[1]);
161 CPPUNIT_ASSERT_EQUAL(OUString("\\A"), boost::get
<2>(result
)[2]);
162 CPPUNIT_ASSERT_EQUAL(OUString(), boost::get
<2>(result
)[3]);
165 CPPUNIT_TEST_SUITE_REGISTRATION(WriterfilterMiscTest
);
169 CPPUNIT_PLUGIN_IMPLEMENT();
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */