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/.
10 #include <cppunit/TestFixture.h>
11 #include <cppunit/plugin/TestPlugIn.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include <comphelper/anytostring.hxx>
14 #include <comphelper/sequence.hxx>
16 #include <tools/color.hxx>
18 #include <lib/init.hxx>
20 #include <com/sun/star/table/BorderLine2.hpp>
21 #include <com/sun/star/table/BorderLineStyle.hpp>
25 /// Unit tests for desktop/source/lib/init.cxx internals.
26 class LOKInitTest
: public ::CppUnit::TestFixture
31 void testJsonToPropertyValues();
32 void testJsonToPropertyValuesBorder();
34 CPPUNIT_TEST_SUITE(LOKInitTest
);
35 CPPUNIT_TEST(testJsonToPropertyValues
);
36 CPPUNIT_TEST(testJsonToPropertyValuesBorder
);
37 CPPUNIT_TEST_SUITE_END();
42 void assertSequencesEqual(const uno::Sequence
<beans::PropertyValue
>& expected
,
43 const uno::Sequence
<beans::PropertyValue
>& actual
)
45 CPPUNIT_ASSERT_EQUAL_MESSAGE("The sequences should have the same length", expected
.getLength(),
47 for (int i
= 0; i
< expected
.getLength(); ++i
)
49 CPPUNIT_ASSERT_EQUAL(expected
[i
].Name
, actual
[i
].Name
);
50 CPPUNIT_ASSERT_EQUAL(comphelper::anyToString(expected
[i
].Value
),
51 comphelper::anyToString(actual
[i
].Value
));
56 void LOKInitTest::testJsonToPropertyValues()
58 const char arguments
[] = "{"
60 "\"type\":\"string\","
61 "\"value\":\"something.odt\""
64 uno::Sequence
<beans::PropertyValue
> aArgs(1);
65 aArgs
[0].Name
= "FileName";
66 aArgs
[0].Value
<<= OUString("something.odt");
69 aArgs
, comphelper::containerToSequence(desktop::jsonToPropertyValuesVector(arguments
)));
72 void LOKInitTest::testJsonToPropertyValuesBorder()
74 const char arguments
[]
77 "\"type\" : \"[]any\","
79 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
80 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
81 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
82 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
83 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
84 "\"value\" : 1 } } },"
85 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
86 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
87 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
88 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
89 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
90 "\"value\" : 1 } } },"
91 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
92 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
93 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
94 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
95 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
96 "\"value\" : 1 } } },"
97 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
98 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
99 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
100 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
101 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
102 "\"value\" : 1 } } },"
103 "{ \"type\" : \"long\", \"value\" : 0 },"
104 "{ \"type\" : \"long\", \"value\" : 0 },"
105 "{ \"type\" : \"long\", \"value\" : 0 },"
106 "{ \"type\" : \"long\", \"value\" : 0 },"
107 "{ \"type\" : \"long\", \"value\" : 0 }"
111 "\"type\" : \"[]any\","
113 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
114 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
115 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
116 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
117 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
118 "\"value\" : 1 } } },"
119 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
120 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
121 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
122 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
123 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
124 "\"value\" : 1 } } },"
125 "{ \"type\" : \"short\", \"value\" : 0 },"
126 "{ \"type\" : \"short\", \"value\" : 127 },"
127 "{ \"type\" : \"long\", \"value\" : 0 }"
131 // see SvxBoxItem::QueryValue for details
132 uno::Sequence
<uno::Any
> aOuterSeq(9);
133 table::BorderLine2
aLine(sal_Int32(COL_BLACK
), 0, 1, 0, table::BorderLineStyle::SOLID
, 1);
134 aOuterSeq
[0] <<= aLine
; // left
135 aOuterSeq
[1] <<= aLine
; // right
136 aOuterSeq
[2] <<= aLine
; // bottom
137 aOuterSeq
[3] <<= aLine
; // top
138 aOuterSeq
[4] <<= static_cast<sal_Int32
>(0);
139 aOuterSeq
[5] <<= static_cast<sal_Int32
>(0);
140 aOuterSeq
[6] <<= static_cast<sal_Int32
>(0);
141 aOuterSeq
[7] <<= static_cast<sal_Int32
>(0);
142 aOuterSeq
[8] <<= static_cast<sal_Int32
>(0);
144 // see SvxBoxInfoItem::QueryValue() for details
145 uno::Sequence
<uno::Any
> aInnerSeq(5);
146 aInnerSeq
[0] <<= aLine
; // horizontal
147 aInnerSeq
[1] <<= aLine
; // vertical
148 aInnerSeq
[2] <<= static_cast<sal_Int16
>(0);
149 aInnerSeq
[3] <<= static_cast<sal_Int16
>(0x7F);
150 aInnerSeq
[4] <<= static_cast<sal_Int32
>(0);
152 uno::Sequence
<beans::PropertyValue
> aArgs(2);
153 aArgs
[0].Name
= "OuterBorder";
154 aArgs
[0].Value
<<= aOuterSeq
;
155 aArgs
[1].Name
= "InnerBorder";
156 aArgs
[1].Value
<<= aInnerSeq
;
158 assertSequencesEqual(
159 aArgs
, comphelper::containerToSequence(desktop::jsonToPropertyValuesVector(arguments
)));
162 CPPUNIT_TEST_SUITE_REGISTRATION(LOKInitTest
);
164 CPPUNIT_PLUGIN_IMPLEMENT();
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */