android: Update app-specific/MIME type icons
[LibreOffice.git] / comphelper / qa / unit / propertyvalue.cxx
blob738022917e9da6a1108442500f83897c74b534ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <sal/config.h>
12 #include <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
16 #include <comphelper/propertyvalue.hxx>
17 #include <comphelper/propertysequence.hxx>
18 #include <cppu/unotype.hxx>
19 #include <o3tl/any.hxx>
21 using namespace com::sun::star;
23 namespace
25 class MakePropertyValueTest : public CppUnit::TestFixture
27 CPPUNIT_TEST_SUITE(MakePropertyValueTest);
28 CPPUNIT_TEST(testLvalue);
29 CPPUNIT_TEST(testRvalue);
30 CPPUNIT_TEST(testBitField);
31 CPPUNIT_TEST(testJson);
32 CPPUNIT_TEST_SUITE_END();
34 void testLvalue()
36 sal_Int32 const i = 123;
37 auto const v = comphelper::makePropertyValue("test", i);
38 CPPUNIT_ASSERT_EQUAL(cppu::UnoType<sal_Int32>::get(), v.Value.getValueType());
39 CPPUNIT_ASSERT_EQUAL(sal_Int32(123), *o3tl::doAccess<sal_Int32>(v.Value));
42 void testRvalue()
44 auto const v = comphelper::makePropertyValue("test", sal_Int32(456));
45 CPPUNIT_ASSERT_EQUAL(cppu::UnoType<sal_Int32>::get(), v.Value.getValueType());
46 CPPUNIT_ASSERT_EQUAL(sal_Int32(456), *o3tl::doAccess<sal_Int32>(v.Value));
49 void testBitField()
51 struct
53 bool b : 1;
54 } s = { false };
55 auto const v = comphelper::makePropertyValue("test", s.b);
56 CPPUNIT_ASSERT_EQUAL(cppu::UnoType<bool>::get(), v.Value.getValueType());
57 CPPUNIT_ASSERT_EQUAL(false, *o3tl::doAccess<bool>(v.Value));
60 void testJson()
62 std::vector<beans::PropertyValue> aRet = comphelper::JsonToPropertyValues(R"json(
64 "FieldType": {
65 "type": "string",
66 "value": "vnd.oasis.opendocument.field.UNHANDLED"
68 "FieldCommandPrefix": {
69 "type": "string",
70 "value": "ADDIN ZOTERO_ITEM"
72 "Fields": {
73 "type": "[][]com.sun.star.beans.PropertyValue",
74 "value": [
76 "FieldType": {
77 "type": "string",
78 "value": "vnd.oasis.opendocument.field.UNHANDLED"
80 "FieldCommand": {
81 "type": "string",
82 "value": "ADDIN ZOTERO_ITEM new command 1"
84 "Fields": {
85 "type": "string",
86 "value": "new result 1"
90 "FieldType": {
91 "type": "string",
92 "value": "vnd.oasis.opendocument.field.UNHANDLED"
94 "FieldCommandPrefix": {
95 "type": "string",
96 "value": "ADDIN ZOTERO_ITEM new command 2"
98 "Fields": {
99 "type": "string",
100 "value": "new result 2"
106 )json");
107 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aRet.size());
108 beans::PropertyValue aFirst = aRet[0];
109 CPPUNIT_ASSERT_EQUAL(OUString("FieldType"), aFirst.Name);
110 CPPUNIT_ASSERT_EQUAL(OUString("vnd.oasis.opendocument.field.UNHANDLED"),
111 aFirst.Value.get<OUString>());
112 beans::PropertyValue aSecond = aRet[1];
113 CPPUNIT_ASSERT_EQUAL(OUString("FieldCommandPrefix"), aSecond.Name);
114 CPPUNIT_ASSERT_EQUAL(OUString("ADDIN ZOTERO_ITEM"), aSecond.Value.get<OUString>());
115 beans::PropertyValue aThird = aRet[2];
116 CPPUNIT_ASSERT_EQUAL(OUString("Fields"), aThird.Name);
117 uno::Sequence<uno::Sequence<beans::PropertyValue>> aSeqs;
118 aThird.Value >>= aSeqs;
119 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aSeqs.getLength());
120 uno::Sequence<beans::PropertyValue> aFirstSeq = aSeqs[0];
121 CPPUNIT_ASSERT_EQUAL(OUString("FieldType"), aFirstSeq[0].Name);
122 CPPUNIT_ASSERT_EQUAL(OUString("FieldCommand"), aFirstSeq[1].Name);
123 CPPUNIT_ASSERT_EQUAL(OUString("ADDIN ZOTERO_ITEM new command 1"),
124 aFirstSeq[1].Value.get<OUString>());
128 CPPUNIT_TEST_SUITE_REGISTRATION(MakePropertyValueTest);
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */