1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <com/sun/star/beans/PropertyChangeEvent.hpp>
#include <com/sun/star/reflection/Dump.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/TypeClass.hpp>
#include <cppuhelper/bootstrap.hxx>
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <test/codemaker/cppumaker/ByteBits.hpp>
#include <test/codemaker/cppumaker/Constants.hpp>
#include <test/codemaker/cppumaker/ShortBits.hpp>
#include <test/codemaker/cppumaker/UnsignedHyperBits.hpp>
namespace
{
class Dump : public CppUnit::TestFixture
{
public:
void setUp() override
{
dump_ = css::reflection::Dump::get(cppu::defaultBootstrap_InitialComponentContext());
}
void testSequence()
{
CPPUNIT_ASSERT_EQUAL(OUString("[]"),
dump_->dumpValue(css::uno::Any(css::uno::Sequence<sal_Int32>{})));
CPPUNIT_ASSERT_EQUAL(OUString("[1]"),
dump_->dumpValue(css::uno::Any(css::uno::Sequence<sal_Int32>{ 1 })));
CPPUNIT_ASSERT_EQUAL(OUString("[1, 2, 3]"), dump_->dumpValue(css::uno::Any(
css::uno::Sequence<sal_Int32>{ 1, 2, 3 })));
CPPUNIT_ASSERT_EQUAL(OUString("[[long: 1], [string: \"2\"], [[]long: [1, 2]]]"),
(dump_->dumpValue(css::uno::Any(css::uno::Sequence<css::uno::Any>{
css::uno::Any(sal_Int32(1)), css::uno::Any(OUString("2")),
css::uno::Any(css::uno::Sequence<sal_Int32>{ 1, 2 }) }))));
}
void testEnum()
{
CPPUNIT_ASSERT_EQUAL(OUString("ENUM"),
dump_->dumpValue(css::uno::Any(css::uno::TypeClass_ENUM)));
CPPUNIT_ASSERT_EQUAL(OUString("-1"),
dump_->dumpValue(css::uno::Any(css::uno::TypeClass(-1))));
CPPUNIT_ASSERT_EQUAL(OUString("12345"),
dump_->dumpValue(css::uno::Any(css::uno::TypeClass(12345))));
}
void testStruct()
{
CPPUNIT_ASSERT_EQUAL(
OUString("[Source: null, PropertyName: \"test\", Further: false, PropertyHandle: 3, "
"OldValue: [void: void], NewValue: [long: 5]]"),
dump_->dumpValue(css::uno::Any(css::beans::PropertyChangeEvent(
{}, "test", false, 3, {}, css::uno::Any(sal_Int32(5))))));
}
void testConstantsGroup()
{
CPPUNIT_ASSERT_EQUAL(OUString("byteMin"),
dump_->dumpConstant("test.codemaker.cppumaker.Constants",
css::uno::Any(sal_Int8(-128))));
CPPUNIT_ASSERT_EQUAL(OUString("byteMax"),
dump_->dumpConstant("test.codemaker.cppumaker.Constants",
css::uno::Any(sal_Int8(127))));
CPPUNIT_ASSERT_EQUAL(OUString("longMin"),
dump_->dumpConstant("test.codemaker.cppumaker.Constants",
css::uno::Any(sal_Int32(-2147483648))));
CPPUNIT_ASSERT_EQUAL(OUString("longMax"),
dump_->dumpConstant("test.codemaker.cppumaker.Constants",
css::uno::Any(sal_Int32(2147483647))));
CPPUNIT_ASSERT_EQUAL(OUString("hyperMin"),
dump_->dumpConstant("test.codemaker.cppumaker.Constants",
css::uno::Any(SAL_MIN_INT64)));
CPPUNIT_ASSERT_EQUAL(OUString("hyperMax"),
dump_->dumpConstant("test.codemaker.cppumaker.Constants",
css::uno::Any(SAL_MAX_INT64)));
CPPUNIT_ASSERT_EQUAL(OUString("17"),
dump_->dumpConstant("test.codemaker.cppumaker.Constants",
css::uno::Any(sal_Int32(17))));
CPPUNIT_ASSERT_EQUAL(OUString("2147483646"),
dump_->dumpConstant("test.codemaker.cppumaker.Constants",
css::uno::Any(sal_Int32(2147483646))));
CPPUNIT_ASSERT_EQUAL(OUString("0"), dump_->dumpConstant("test.codemaker.cppumaker.ByteBits",
css::uno::Any(sal_Int8(0))));
CPPUNIT_ASSERT_EQUAL(
OUString("BIT0+BIT2"),
dump_->dumpConstant("test.codemaker.cppumaker.ByteBits", css::uno::Any(sal_Int8(5))));
CPPUNIT_ASSERT_EQUAL(
OUString("BIT4"),
dump_->dumpConstant("test.codemaker.cppumaker.ByteBits", css::uno::Any(sal_Int8(16))));
CPPUNIT_ASSERT_EQUAL(
OUString("BIT0+BIT4"),
dump_->dumpConstant("test.codemaker.cppumaker.ByteBits", css::uno::Any(sal_Int8(17))));
CPPUNIT_ASSERT_EQUAL(OUString("BIT7"),
dump_->dumpConstant("test.codemaker.cppumaker.ByteBits",
css::uno::Any(sal_Int8(-128))));
CPPUNIT_ASSERT_EQUAL(
OUString("ALL"),
dump_->dumpConstant("test.codemaker.cppumaker.ByteBits", css::uno::Any(sal_Int8(-1))));
CPPUNIT_ASSERT_EQUAL(OUString("BIT7"),
dump_->dumpConstant("test.codemaker.cppumaker.ShortBits",
css::uno::Any(sal_Int16(128))));
CPPUNIT_ASSERT_EQUAL(OUString("ALL"),
dump_->dumpConstant("test.codemaker.cppumaker.ShortBits",
css::uno::Any(sal_Int16(-1))));
CPPUNIT_ASSERT_EQUAL(OUString("BIT63"),
dump_->dumpConstant("test.codemaker.cppumaker.UnsignedHyperBits",
css::uno::Any(sal_uInt64(9223372036854775808u))));
CPPUNIT_ASSERT_EQUAL(OUString("BIT0+BIT62"),
dump_->dumpConstant("test.codemaker.cppumaker.UnsignedHyperBits",
css::uno::Any(sal_uInt64(4611686018427387905))));
CPPUNIT_ASSERT_EQUAL(OUString("BIT0+BIT63"),
dump_->dumpConstant("test.codemaker.cppumaker.UnsignedHyperBits",
css::uno::Any(sal_uInt64(9223372036854775809u))));
CPPUNIT_ASSERT_EQUAL(OUString("ALL"),
dump_->dumpConstant("test.codemaker.cppumaker.UnsignedHyperBits",
css::uno::Any(SAL_MAX_UINT64)));
}
CPPUNIT_TEST_SUITE(Dump);
CPPUNIT_TEST(testSequence);
CPPUNIT_TEST(testEnum);
CPPUNIT_TEST(testStruct);
CPPUNIT_TEST(testConstantsGroup);
CPPUNIT_TEST_SUITE_END();
private:
css::uno::Reference<css::reflection::XDump> dump_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(Dump);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|