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 <test/sheet/databaseimportdescriptor.hxx>
12 #include <com/sun/star/beans/PropertyValue.hpp>
13 #include <com/sun/star/beans/XPropertySet.hpp>
14 #include <com/sun/star/sheet/DataImportMode.hpp>
15 #include <com/sun/star/util/XImportable.hpp>
16 #include <com/sun/star/uno/Any.hxx>
17 #include <com/sun/star/uno/Reference.hxx>
18 #include <com/sun/star/uno/Sequence.hxx>
20 #include <cppunit/TestAssert.h>
22 using namespace com::sun::star
;
23 using namespace com::sun::star::uno
;
27 void DatabaseImportDescriptor::testDatabaseImportDescriptorProperties()
29 uno::Reference
<beans::XPropertySet
> xDatabaseImportDescriptor(init(), UNO_QUERY_THROW
);
30 uno::Reference
<util::XImportable
> xImportable(getXImportable(), UNO_QUERY_THROW
);
31 uno::Sequence
<beans::PropertyValue
> aPropValues
= xImportable
->createImportDescriptor(true);
33 for (auto& rPropValue
: asNonConstRange(aPropValues
))
37 if (rPropValue
.Name
== "DatabaseName" || rPropValue
.Name
== "SourceObject"
38 || rPropValue
.Name
== "ConnectionResource")
41 aOldValue
= rPropValue
.Value
;
43 OString aMsgGet
= "Unable to get PropertyValue "
44 + OUStringToOString(rPropValue
.Name
, RTL_TEXTENCODING_UTF8
);
45 CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgGet
.getStr(), OUString(""), aValue
);
47 aNewValue
<<= OUString("New");
48 rPropValue
.Value
= aNewValue
;
50 aOldValue
= rPropValue
.Value
;
52 OString aMsgSet
= "Unable to set PropertyValue "
53 + OUStringToOString(rPropValue
.Name
, RTL_TEXTENCODING_UTF8
);
54 CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgSet
.getStr(), OUString("New"), aValue
);
56 else if (rPropValue
.Name
== "IsNative")
59 aOldValue
= rPropValue
.Value
;
61 OString aMsgGet
= "Unable to get PropertyValue "
62 + OUStringToOString(rPropValue
.Name
, RTL_TEXTENCODING_UTF8
);
63 CPPUNIT_ASSERT_MESSAGE(aMsgGet
.getStr(), !aValue
);
66 rPropValue
.Value
= aNewValue
;
68 aOldValue
= rPropValue
.Value
;
70 OString aMsgSet
= "Unable to set PropertyValue "
71 + OUStringToOString(rPropValue
.Name
, RTL_TEXTENCODING_UTF8
);
72 CPPUNIT_ASSERT_MESSAGE(aMsgSet
.getStr(), aValue
);
74 else if (rPropValue
.Name
== "SourceType")
76 sheet::DataImportMode aValue
;
77 aOldValue
= rPropValue
.Value
;
79 OString aMsgGet
= "Unable to get PropertyValue "
80 + OUStringToOString(rPropValue
.Name
, RTL_TEXTENCODING_UTF8
);
81 CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgGet
.getStr(), sheet::DataImportMode_NONE
, aValue
);
83 aNewValue
<<= sheet::DataImportMode_SQL
;
84 rPropValue
.Value
= aNewValue
;
86 aOldValue
= rPropValue
.Value
;
88 OString aMsgSet
= "Unable to set PropertyValue "
89 + OUStringToOString(rPropValue
.Name
, RTL_TEXTENCODING_UTF8
);
90 CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgSet
.getStr(), sheet::DataImportMode_SQL
, aValue
);
94 OString aMsg
= "Unsupported PropertyValue "
95 + OUStringToOString(rPropValue
.Name
, RTL_TEXTENCODING_UTF8
);
96 CPPUNIT_FAIL(aMsg
.getStr());
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */