1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <sal/config.h>
12 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
13 #include <com/sun/star/reflection/Dump.hpp>
14 #include <com/sun/star/uno/Any.hxx>
15 #include <com/sun/star/uno/Reference.hxx>
16 #include <com/sun/star/uno/TypeClass.hpp>
17 #include <cppuhelper/bootstrap.hxx>
18 #include <cppunit/TestAssert.h>
19 #include <cppunit/TestFixture.h>
20 #include <cppunit/extensions/HelperMacros.h>
21 #include <cppunit/plugin/TestPlugIn.h>
22 #include <test/codemaker/cppumaker/ByteBits.hpp>
23 #include <test/codemaker/cppumaker/Constants.hpp>
24 #include <test/codemaker/cppumaker/ShortBits.hpp>
25 #include <test/codemaker/cppumaker/UnsignedHyperBits.hpp>
29 class Dump
: public CppUnit::TestFixture
34 dump_
= css::reflection::Dump::get(cppu::defaultBootstrap_InitialComponentContext());
39 CPPUNIT_ASSERT_EQUAL(OUString("[]"),
40 dump_
->dumpValue(css::uno::Any(css::uno::Sequence
<sal_Int32
>{})));
41 CPPUNIT_ASSERT_EQUAL(OUString("[1]"),
42 dump_
->dumpValue(css::uno::Any(css::uno::Sequence
<sal_Int32
>{ 1 })));
43 CPPUNIT_ASSERT_EQUAL(OUString("[1, 2, 3]"), dump_
->dumpValue(css::uno::Any(
44 css::uno::Sequence
<sal_Int32
>{ 1, 2, 3 })));
45 CPPUNIT_ASSERT_EQUAL(OUString("[[long: 1], [string: \"2\"], [[]long: [1, 2]]]"),
46 (dump_
->dumpValue(css::uno::Any(css::uno::Sequence
<css::uno::Any
>{
47 css::uno::Any(sal_Int32(1)), css::uno::Any(OUString("2")),
48 css::uno::Any(css::uno::Sequence
<sal_Int32
>{ 1, 2 }) }))));
53 CPPUNIT_ASSERT_EQUAL(OUString("ENUM"),
54 dump_
->dumpValue(css::uno::Any(css::uno::TypeClass_ENUM
)));
55 CPPUNIT_ASSERT_EQUAL(OUString("-1"),
56 dump_
->dumpValue(css::uno::Any(css::uno::TypeClass(-1))));
57 CPPUNIT_ASSERT_EQUAL(OUString("12345"),
58 dump_
->dumpValue(css::uno::Any(css::uno::TypeClass(12345))));
64 OUString("[Source: null, PropertyName: \"test\", Further: false, PropertyHandle: 3, "
65 "OldValue: [void: void], NewValue: [long: 5]]"),
66 dump_
->dumpValue(css::uno::Any(css::beans::PropertyChangeEvent(
67 {}, "test", false, 3, {}, css::uno::Any(sal_Int32(5))))));
70 void testConstantsGroup()
72 CPPUNIT_ASSERT_EQUAL(OUString("byteMin"),
73 dump_
->dumpConstant("test.codemaker.cppumaker.Constants",
74 css::uno::Any(sal_Int8(-128))));
75 CPPUNIT_ASSERT_EQUAL(OUString("byteMax"),
76 dump_
->dumpConstant("test.codemaker.cppumaker.Constants",
77 css::uno::Any(sal_Int8(127))));
78 CPPUNIT_ASSERT_EQUAL(OUString("longMin"),
79 dump_
->dumpConstant("test.codemaker.cppumaker.Constants",
80 css::uno::Any(sal_Int32(-2147483648))));
81 CPPUNIT_ASSERT_EQUAL(OUString("longMax"),
82 dump_
->dumpConstant("test.codemaker.cppumaker.Constants",
83 css::uno::Any(sal_Int32(2147483647))));
84 CPPUNIT_ASSERT_EQUAL(OUString("hyperMin"),
85 dump_
->dumpConstant("test.codemaker.cppumaker.Constants",
86 css::uno::Any(SAL_MIN_INT64
)));
87 CPPUNIT_ASSERT_EQUAL(OUString("hyperMax"),
88 dump_
->dumpConstant("test.codemaker.cppumaker.Constants",
89 css::uno::Any(SAL_MAX_INT64
)));
90 CPPUNIT_ASSERT_EQUAL(OUString("17"),
91 dump_
->dumpConstant("test.codemaker.cppumaker.Constants",
92 css::uno::Any(sal_Int32(17))));
93 CPPUNIT_ASSERT_EQUAL(OUString("2147483646"),
94 dump_
->dumpConstant("test.codemaker.cppumaker.Constants",
95 css::uno::Any(sal_Int32(2147483646))));
97 CPPUNIT_ASSERT_EQUAL(OUString("0"), dump_
->dumpConstant("test.codemaker.cppumaker.ByteBits",
98 css::uno::Any(sal_Int8(0))));
100 OUString("BIT0+BIT2"),
101 dump_
->dumpConstant("test.codemaker.cppumaker.ByteBits", css::uno::Any(sal_Int8(5))));
102 CPPUNIT_ASSERT_EQUAL(
104 dump_
->dumpConstant("test.codemaker.cppumaker.ByteBits", css::uno::Any(sal_Int8(16))));
105 CPPUNIT_ASSERT_EQUAL(
106 OUString("BIT0+BIT4"),
107 dump_
->dumpConstant("test.codemaker.cppumaker.ByteBits", css::uno::Any(sal_Int8(17))));
108 CPPUNIT_ASSERT_EQUAL(OUString("BIT7"),
109 dump_
->dumpConstant("test.codemaker.cppumaker.ByteBits",
110 css::uno::Any(sal_Int8(-128))));
111 CPPUNIT_ASSERT_EQUAL(
113 dump_
->dumpConstant("test.codemaker.cppumaker.ByteBits", css::uno::Any(sal_Int8(-1))));
115 CPPUNIT_ASSERT_EQUAL(OUString("BIT7"),
116 dump_
->dumpConstant("test.codemaker.cppumaker.ShortBits",
117 css::uno::Any(sal_Int16(128))));
118 CPPUNIT_ASSERT_EQUAL(OUString("ALL"),
119 dump_
->dumpConstant("test.codemaker.cppumaker.ShortBits",
120 css::uno::Any(sal_Int16(-1))));
122 CPPUNIT_ASSERT_EQUAL(OUString("BIT63"),
123 dump_
->dumpConstant("test.codemaker.cppumaker.UnsignedHyperBits",
124 css::uno::Any(sal_uInt64(9223372036854775808u))));
125 CPPUNIT_ASSERT_EQUAL(OUString("BIT0+BIT62"),
126 dump_
->dumpConstant("test.codemaker.cppumaker.UnsignedHyperBits",
127 css::uno::Any(sal_uInt64(4611686018427387905))));
128 CPPUNIT_ASSERT_EQUAL(OUString("BIT0+BIT63"),
129 dump_
->dumpConstant("test.codemaker.cppumaker.UnsignedHyperBits",
130 css::uno::Any(sal_uInt64(9223372036854775809u))));
131 CPPUNIT_ASSERT_EQUAL(OUString("ALL"),
132 dump_
->dumpConstant("test.codemaker.cppumaker.UnsignedHyperBits",
133 css::uno::Any(SAL_MAX_UINT64
)));
136 CPPUNIT_TEST_SUITE(Dump
);
137 CPPUNIT_TEST(testSequence
);
138 CPPUNIT_TEST(testEnum
);
139 CPPUNIT_TEST(testStruct
);
140 CPPUNIT_TEST(testConstantsGroup
);
141 CPPUNIT_TEST_SUITE_END();
144 css::uno::Reference
<css::reflection::XDump
> dump_
;
147 CPPUNIT_TEST_SUITE_REGISTRATION(Dump
);
150 CPPUNIT_PLUGIN_IMPLEMENT();
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */