LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / dbaccess / qa / extras / rowsetclones.cxx
blob21a30636961b79d6309c1739b49ed7afbf574e69
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
11 #include <test/unoapi_test.hxx>
12 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
13 #include <com/sun/star/lang/XComponent.hpp>
14 #include <com/sun/star/sdb/CommandType.hpp>
15 #include <com/sun/star/sdbc/XConnection.hpp>
16 #include <com/sun/star/sdbc/XResultSet.hpp>
17 #include <com/sun/star/sdbc/XRow.hpp>
18 #include <com/sun/star/sdbcx/XRowLocate.hpp>
19 #include <com/sun/star/sdbc/XRowSet.hpp>
20 #include <com/sun/star/sdb/XResultSetAccess.hpp>
21 #include <com/sun/star/beans/XPropertySet.hpp>
23 using namespace ::com::sun::star;
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star::beans;
26 using namespace ::com::sun::star::sdb;
27 using namespace ::com::sun::star::sdbc;
28 using namespace ::com::sun::star::sdbcx;
30 class RowSetClones : public UnoApiTest
32 public:
33 RowSetClones();
35 void test();
37 CPPUNIT_TEST_SUITE(RowSetClones);
38 CPPUNIT_TEST(test);
39 CPPUNIT_TEST_SUITE_END();
44 RowSetClones::RowSetClones()
45 : UnoApiTest("")
49 void RowSetClones::test()
51 const OUString sFilePath(m_directories.getURLFromWorkdir(u"CppunitTest/RowSetClones.odb"));
53 uno::Reference< lang::XComponent > xComponent (loadFromDesktop(sFilePath));
54 uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY);
55 CPPUNIT_ASSERT(xDocument.is());
57 uno::Reference< XDataSource > xDataSource = xDocument->getDataSource();
58 CPPUNIT_ASSERT(xDataSource.is());
60 uno::Reference< XConnection > xConnection = xDataSource->getConnection("","");
61 CPPUNIT_ASSERT(xConnection.is());
63 uno::Reference< XRowSet > xRowSet (getMultiServiceFactory()->createInstance("com.sun.star.sdb.RowSet" ), UNO_QUERY);
64 CPPUNIT_ASSERT(xRowSet.is());
65 uno::Reference< XPropertySet > rowSetProperties ( xRowSet, UNO_QUERY );
66 CPPUNIT_ASSERT(rowSetProperties.is());
67 rowSetProperties->setPropertyValue("Command", Any(OUString("SELECT * FROM Assets ORDER BY AssetID")));
68 rowSetProperties->setPropertyValue("CommandType", Any(CommandType::COMMAND));
69 rowSetProperties->setPropertyValue("ActiveConnection", Any(xConnection));
71 xRowSet->execute();
72 uno::Reference< XResultSet > xResultSet = xRowSet;
73 CPPUNIT_ASSERT(xResultSet.is());
74 // always starts at BeforeFirst position
75 CPPUNIT_ASSERT(xResultSet->isBeforeFirst());
76 CPPUNIT_ASSERT(xResultSet->next());
77 CPPUNIT_ASSERT(xResultSet->isFirst());
78 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xResultSet->getRow());
80 uno::Reference< XRow > xRow(xResultSet, UNO_QUERY);
81 CPPUNIT_ASSERT(xRow.is());
82 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRow->getInt(1));
84 uno::Reference< XResultSetAccess > xResultSetAccess(xResultSet, UNO_QUERY);
85 CPPUNIT_ASSERT(xResultSetAccess.is());
86 uno::Reference< XResultSet > xResultSetClone = xResultSetAccess->createResultSet();
87 CPPUNIT_ASSERT(xResultSetClone.is());
89 uno::Reference< XRow > xRowClone(xResultSetClone, UNO_QUERY);
90 CPPUNIT_ASSERT(xRowClone.is());
92 // the clone starts at same position as what it is cloned from,
93 // and does not move its source.
94 CPPUNIT_ASSERT(xResultSetClone->isFirst());
95 CPPUNIT_ASSERT(xResultSet->isFirst());
96 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xResultSet->getRow());
97 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xResultSetClone->getRow());
98 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRow->getInt(1));
99 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRowClone->getInt(1));
101 // if we move the source, the clone does not move
102 CPPUNIT_ASSERT(xResultSet->next());
103 CPPUNIT_ASSERT(xResultSetClone->isFirst());
104 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xResultSet->getRow());
105 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xResultSetClone->getRow());
106 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xRow->getInt(1));
107 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRowClone->getInt(1));
109 CPPUNIT_ASSERT(xResultSet->last());
110 CPPUNIT_ASSERT(xResultSet->isLast());
111 CPPUNIT_ASSERT(xResultSetClone->isFirst());
112 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRowClone->getInt(1));
114 // and the other way round
115 CPPUNIT_ASSERT(xResultSet->first());
116 CPPUNIT_ASSERT(xResultSetClone->next());
117 CPPUNIT_ASSERT(xResultSet->isFirst());
118 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xResultSetClone->getRow());
119 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xRowClone->getInt(1));
120 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRow->getInt(1));
122 CPPUNIT_ASSERT(xResultSetClone->last());
123 CPPUNIT_ASSERT(xResultSetClone->isLast());
124 CPPUNIT_ASSERT(xResultSet->isFirst());
125 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRow->getInt(1));
127 closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
130 CPPUNIT_TEST_SUITE_REGISTRATION(RowSetClones);
132 CPPUNIT_PLUGIN_IMPLEMENT();
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */