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/.
11 #include <boost/property_tree/json_parser.hpp>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/plugin/TestPlugIn.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <comphelper/anytostring.hxx>
16 #include <comphelper/sequence.hxx>
21 #include <tools/color.hxx>
23 #include <lib/init.hxx>
25 #include <com/sun/star/table/BorderLine2.hpp>
26 #include <com/sun/star/table/BorderLineStyle.hpp>
30 /// Unit tests for desktop/source/lib/init.cxx internals.
31 class LOKInitTest
: public ::CppUnit::TestFixture
36 void testJsonToPropertyValues();
37 void testJsonToPropertyValuesBorder();
39 CPPUNIT_TEST_SUITE(LOKInitTest
);
40 CPPUNIT_TEST(testJsonToPropertyValues
);
41 CPPUNIT_TEST(testJsonToPropertyValuesBorder
);
42 CPPUNIT_TEST_SUITE_END();
47 void assertSequencesEqual(const uno::Sequence
<beans::PropertyValue
>& expected
,
48 const uno::Sequence
<beans::PropertyValue
>& actual
)
50 CPPUNIT_ASSERT_EQUAL_MESSAGE("The sequences should have the same length", expected
.getLength(),
52 for (int i
= 0; i
< expected
.getLength(); ++i
)
54 CPPUNIT_ASSERT_EQUAL(expected
[i
].Name
, actual
[i
].Name
);
55 CPPUNIT_ASSERT_EQUAL(comphelper::anyToString(expected
[i
].Value
),
56 comphelper::anyToString(actual
[i
].Value
));
61 void LOKInitTest::testJsonToPropertyValues()
63 const char arguments
[] = "{"
65 "\"type\":\"string\","
66 "\"value\":\"something.odt\""
69 uno::Sequence
<beans::PropertyValue
> aArgs(1);
70 aArgs
[0].Name
= "FileName";
71 aArgs
[0].Value
<<= OUString("something.odt");
74 aArgs
, comphelper::containerToSequence(desktop::jsonToPropertyValuesVector(arguments
)));
77 void LOKInitTest::testJsonToPropertyValuesBorder()
79 const char arguments
[]
82 "\"type\" : \"[]any\","
84 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
85 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
86 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
87 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
88 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
89 "\"value\" : 1 } } },"
90 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
91 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
92 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
93 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
94 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
95 "\"value\" : 1 } } },"
96 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
97 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
98 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
99 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
100 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
101 "\"value\" : 1 } } },"
102 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
103 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
104 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
105 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
106 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
107 "\"value\" : 1 } } },"
108 "{ \"type\" : \"long\", \"value\" : 0 },"
109 "{ \"type\" : \"long\", \"value\" : 0 },"
110 "{ \"type\" : \"long\", \"value\" : 0 },"
111 "{ \"type\" : \"long\", \"value\" : 0 },"
112 "{ \"type\" : \"long\", \"value\" : 0 }"
116 "\"type\" : \"[]any\","
118 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
119 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
120 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
121 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
122 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
123 "\"value\" : 1 } } },"
124 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
125 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
126 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
127 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
128 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
129 "\"value\" : 1 } } },"
130 "{ \"type\" : \"short\", \"value\" : 0 },"
131 "{ \"type\" : \"short\", \"value\" : 127 },"
132 "{ \"type\" : \"long\", \"value\" : 0 }"
136 // see SvxBoxItem::QueryValue for details
137 uno::Sequence
<uno::Any
> aOuterSeq(9);
138 table::BorderLine2
aLine(sal_Int32(COL_BLACK
), 0, 1, 0, table::BorderLineStyle::SOLID
, 1);
139 aOuterSeq
[0] <<= aLine
; // left
140 aOuterSeq
[1] <<= aLine
; // right
141 aOuterSeq
[2] <<= aLine
; // bottom
142 aOuterSeq
[3] <<= aLine
; // top
143 aOuterSeq
[4] <<= static_cast<sal_Int32
>(0);
144 aOuterSeq
[5] <<= static_cast<sal_Int32
>(0);
145 aOuterSeq
[6] <<= static_cast<sal_Int32
>(0);
146 aOuterSeq
[7] <<= static_cast<sal_Int32
>(0);
147 aOuterSeq
[8] <<= static_cast<sal_Int32
>(0);
149 // see SvxBoxInfoItem::QueryValue() for details
150 uno::Sequence
<uno::Any
> aInnerSeq(5);
151 aInnerSeq
[0] <<= aLine
; // horizontal
152 aInnerSeq
[1] <<= aLine
; // vertical
153 aInnerSeq
[2] <<= static_cast<sal_Int16
>(0);
154 aInnerSeq
[3] <<= static_cast<sal_Int16
>(0x7F);
155 aInnerSeq
[4] <<= static_cast<sal_Int32
>(0);
157 uno::Sequence
<beans::PropertyValue
> aArgs(2);
158 aArgs
[0].Name
= "OuterBorder";
159 aArgs
[0].Value
<<= aOuterSeq
;
160 aArgs
[1].Name
= "InnerBorder";
161 aArgs
[1].Value
<<= aInnerSeq
;
163 assertSequencesEqual(
164 aArgs
, comphelper::containerToSequence(desktop::jsonToPropertyValuesVector(arguments
)));
167 CPPUNIT_TEST_SUITE_REGISTRATION(LOKInitTest
);
169 CPPUNIT_PLUGIN_IMPLEMENT();
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */