tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / desktop / qa / unit / desktop-lok-init.cxx
blob90c645c07781b3d02a33c2d9fb62a2a1d3613efb
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 <cppunit/TestFixture.h>
11 #include <cppunit/plugin/TestPlugIn.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include <comphelper/anytostring.hxx>
14 #include <comphelper/propertyvalue.hxx>
15 #include <comphelper/sequence.hxx>
17 #include <tools/color.hxx>
19 #include <lib/init.hxx>
21 #include <com/sun/star/table/BorderLine2.hpp>
22 #include <com/sun/star/table/BorderLineStyle.hpp>
24 using namespace css;
26 /// Unit tests for desktop/source/lib/init.cxx internals.
27 class LOKInitTest : public ::CppUnit::TestFixture
29 public:
30 LOKInitTest() {}
32 void testJsonToPropertyValues();
33 void testJsonToPropertyValuesBorder();
35 CPPUNIT_TEST_SUITE(LOKInitTest);
36 CPPUNIT_TEST(testJsonToPropertyValues);
37 CPPUNIT_TEST(testJsonToPropertyValuesBorder);
38 CPPUNIT_TEST_SUITE_END();
41 namespace
43 void assertSequencesEqual(const uno::Sequence<beans::PropertyValue>& expected,
44 const uno::Sequence<beans::PropertyValue>& actual)
46 CPPUNIT_ASSERT_EQUAL_MESSAGE("The sequences should have the same length", expected.getLength(),
47 actual.getLength());
48 for (int i = 0; i < expected.getLength(); ++i)
50 CPPUNIT_ASSERT_EQUAL(expected[i].Name, actual[i].Name);
51 CPPUNIT_ASSERT_EQUAL(comphelper::anyToString(expected[i].Value),
52 comphelper::anyToString(actual[i].Value));
55 } // namespace
57 void LOKInitTest::testJsonToPropertyValues()
59 const char arguments[] = "{"
60 "\"FileName\":{"
61 "\"type\":\"string\","
62 "\"value\":\"something.odt\""
63 "}}";
65 uno::Sequence aArgs{ comphelper::makePropertyValue(u"FileName"_ustr, u"something.odt"_ustr) };
67 assertSequencesEqual(
68 aArgs, comphelper::containerToSequence(desktop::jsonToPropertyValuesVector(arguments)));
71 void LOKInitTest::testJsonToPropertyValuesBorder()
73 const char arguments[]
74 = "{"
75 "\"OuterBorder\": {"
76 "\"type\" : \"[]any\","
77 "\"value\" : ["
78 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
79 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
80 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
81 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
82 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
83 "\"value\" : 1 } } },"
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\" : \"long\", \"value\" : 0 },"
103 "{ \"type\" : \"long\", \"value\" : 0 },"
104 "{ \"type\" : \"long\", \"value\" : 0 },"
105 "{ \"type\" : \"long\", \"value\" : 0 },"
106 "{ \"type\" : \"long\", \"value\" : 0 }"
108 "},"
109 "\"InnerBorder\":{"
110 "\"type\" : \"[]any\","
111 "\"value\" : ["
112 "{ \"type\" : \"com.sun.star.table.BorderLine2\", \"value\" : { \"Color\" : { \"type\" : "
113 "\"com.sun.star.util.Color\", \"value\" : 0 }, \"InnerLineWidth\" : { \"type\" : "
114 "\"short\", \"value\" : 0 }, \"OuterLineWidth\" : { \"type\" : \"short\", \"value\" : 1 "
115 "}, \"LineDistance\" : { \"type\" : \"short\", \"value\" : 0 }, \"LineStyle\" : { "
116 "\"type\" : \"short\", \"value\" : 0 }, \"LineWidth\" : { \"type\" : \"unsigned long\", "
117 "\"value\" : 1 } } },"
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\" : \"short\", \"value\" : 0 },"
125 "{ \"type\" : \"short\", \"value\" : 127 },"
126 "{ \"type\" : \"long\", \"value\" : 0 }"
128 "}}";
130 // see SvxBoxItem::QueryValue for details
131 table::BorderLine2 aLine(sal_Int32(COL_BLACK), 0, 1, 0, table::BorderLineStyle::SOLID, 1);
132 uno::Sequence<uno::Any> aOuterSeq{ uno::Any(aLine), // left
133 uno::Any(aLine), // right
134 uno::Any(aLine), // bottom
135 uno::Any(aLine), // top
136 uno::Any(static_cast<sal_Int32>(0)),
137 uno::Any(static_cast<sal_Int32>(0)),
138 uno::Any(static_cast<sal_Int32>(0)),
139 uno::Any(static_cast<sal_Int32>(0)),
140 uno::Any(static_cast<sal_Int32>(0)) };
142 // see SvxBoxInfoItem::QueryValue() for details
143 uno::Sequence<uno::Any> aInnerSeq{ uno::Any(aLine), // horizontal
144 uno::Any(aLine), // vertical
145 uno::Any(static_cast<sal_Int16>(0)),
146 uno::Any(static_cast<sal_Int16>(0x7F)),
147 uno::Any(static_cast<sal_Int32>(0)) };
149 uno::Sequence aArgs{ comphelper::makePropertyValue(u"OuterBorder"_ustr, aOuterSeq),
150 comphelper::makePropertyValue(u"InnerBorder"_ustr, aInnerSeq) };
152 assertSequencesEqual(
153 aArgs, comphelper::containerToSequence(desktop::jsonToPropertyValuesVector(arguments)));
156 CPPUNIT_TEST_SUITE_REGISTRATION(LOKInitTest);
158 CPPUNIT_PLUGIN_IMPLEMENT();
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */