LibreOffice Module test (master)  1
databaseimportdescriptor.cxx
Go to the documentation of this file.
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.
4  *
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  */
9 
11 
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>
19 
20 #include <cppunit/TestAssert.h>
21 
22 using namespace com::sun::star;
23 using namespace com::sun::star::uno;
24 
25 namespace apitest
26 {
27 void DatabaseImportDescriptor::testDatabaseImportDescriptorProperties()
28 {
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);
32 
33  for (auto& rPropValue : aPropValues)
34  {
35  uno::Any aOldValue;
36  uno::Any aNewValue;
37  if (rPropValue.Name == "DatabaseName" || rPropValue.Name == "SourceObject"
38  || rPropValue.Name == "ConnectionResource")
39  {
40  OUString aValue;
41  aOldValue = rPropValue.Value;
42  aOldValue >>= aValue;
43  OString aMsgGet = "Unable to get PropertyValue "
44  + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8);
45  CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgGet.getStr(), OUString(""), aValue);
46 
47  aNewValue <<= OUString("New");
48  rPropValue.Value = aNewValue;
49 
50  aOldValue = rPropValue.Value;
51  aOldValue >>= aValue;
52  OString aMsgSet = "Unable to set PropertyValue "
53  + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8);
54  CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgSet.getStr(), OUString("New"), aValue);
55  }
56  else if (rPropValue.Name == "IsNative")
57  {
58  bool aValue = true;
59  aOldValue = rPropValue.Value;
60  aOldValue >>= aValue;
61  OString aMsgGet = "Unable to get PropertyValue "
62  + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8);
63  CPPUNIT_ASSERT_MESSAGE(aMsgGet.getStr(), !aValue);
64 
65  aNewValue <<= true;
66  rPropValue.Value = aNewValue;
67 
68  aOldValue = rPropValue.Value;
69  aOldValue >>= aValue;
70  OString aMsgSet = "Unable to set PropertyValue "
71  + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8);
72  CPPUNIT_ASSERT_MESSAGE(aMsgSet.getStr(), aValue);
73  }
74  else if (rPropValue.Name == "SourceType")
75  {
76  sheet::DataImportMode aValue;
77  aOldValue = rPropValue.Value;
78  aOldValue >>= aValue;
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);
82 
83  aNewValue <<= sheet::DataImportMode_SQL;
84  rPropValue.Value = aNewValue;
85 
86  aOldValue = rPropValue.Value;
87  aOldValue >>= aValue;
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);
91  }
92  else
93  {
94  OString aMsg = "Unsupported PropertyValue "
95  + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8);
96  CPPUNIT_FAIL(aMsg.getStr());
97  }
98  }
99 }
100 }
101 
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Object Value
FILE * init(int, char **)