fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / qa / extras / rowsetclones.cxx
blob36b6db4f2163941550825d46e086d183fd60c424
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/bootstrapfixture.hxx>
12 #include <test/unoapi_test.hxx>
13 #include <rtl/strbuf.hxx>
14 #include <osl/file.hxx>
15 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
16 #include <com/sun/star/frame/Desktop.hpp>
17 #include <com/sun/star/lang/XComponent.hpp>
18 #include <com/sun/star/sdb/CommandType.hpp>
19 #include <com/sun/star/sdbc/XConnection.hpp>
20 #include <com/sun/star/sdbc/XResultSet.hpp>
21 #include <com/sun/star/sdbc/XRow.hpp>
22 #include <com/sun/star/sdbcx/XRowLocate.hpp>
23 #include <com/sun/star/sdbc/XRowSet.hpp>
24 #include <com/sun/star/sdb/XResultSetAccess.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <sfx2/app.hxx>
28 #include <sfx2/docfilt.hxx>
29 #include <sfx2/docfile.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <sfx2/sfxmodelfactory.hxx>
32 #include <svl/intitem.hxx>
33 #include <comphelper/processfactory.hxx>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::sdb;
39 using namespace ::com::sun::star::sdbc;
40 using namespace ::com::sun::star::sdbcx;
42 class RowSetClones : public UnoApiTest
44 public:
45 RowSetClones();
47 void test();
49 CPPUNIT_TEST_SUITE(RowSetClones);
50 CPPUNIT_TEST(test);
51 CPPUNIT_TEST_SUITE_END();
56 RowSetClones::RowSetClones()
57 : UnoApiTest("")
61 void RowSetClones::test()
63 const OUString sFilePath(getURLFromWorkdir("CppunitTest/RowSetClones.odb"));
65 uno::Reference< lang::XComponent > xComponent (loadFromDesktop(sFilePath));
66 CPPUNIT_ASSERT(xComponent.is());
68 uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY);
69 CPPUNIT_ASSERT(xDocument.is());
71 uno::Reference< XDataSource > xDataSource = xDocument->getDataSource();
72 CPPUNIT_ASSERT(xDataSource.is());
74 uno::Reference< XConnection > xConnection = xDataSource->getConnection("","");
75 CPPUNIT_ASSERT(xConnection.is());
77 uno::Reference< XRowSet > xRowSet (getMultiServiceFactory()->createInstance("com.sun.star.sdb.RowSet" ), UNO_QUERY);
78 CPPUNIT_ASSERT(xRowSet.is());
79 uno::Reference< XPropertySet > rowSetProperties ( xRowSet, UNO_QUERY );
80 CPPUNIT_ASSERT(rowSetProperties.is());
81 rowSetProperties->setPropertyValue("Command", Any(OUString("SELECT * FROM Assets ORDER BY AssetID")));
82 rowSetProperties->setPropertyValue("CommandType", Any(CommandType::COMMAND));
83 rowSetProperties->setPropertyValue("ActiveConnection", Any(xConnection));
85 xRowSet->execute();
86 uno::Reference< XResultSet > xResultSet(xRowSet, UNO_QUERY);
87 CPPUNIT_ASSERT(xResultSet.is());
88 // always starts at BeforeFirst position
89 CPPUNIT_ASSERT(xResultSet->isBeforeFirst());
90 CPPUNIT_ASSERT(xResultSet->next());
91 CPPUNIT_ASSERT(xResultSet->isFirst());
92 CPPUNIT_ASSERT(xResultSet->getRow() == 1);
94 uno::Reference< XRow > xRow(xResultSet, UNO_QUERY);
95 CPPUNIT_ASSERT(xRow.is());
96 CPPUNIT_ASSERT(xRow->getInt(1) == 1);
98 uno::Reference< XResultSetAccess > xResultSetAccess(xResultSet, UNO_QUERY);
99 CPPUNIT_ASSERT(xResultSetAccess.is());
100 uno::Reference< XResultSet > xResultSetClone = xResultSetAccess->createResultSet();
101 CPPUNIT_ASSERT(xResultSetClone.is());
103 uno::Reference< XRow > xRowClone(xResultSetClone, UNO_QUERY);
104 CPPUNIT_ASSERT(xRowClone.is());
106 // the clone starts at same position as what it is cloned from,
107 // and does not move its source.
108 CPPUNIT_ASSERT(xResultSetClone->isFirst());
109 CPPUNIT_ASSERT(xResultSet->isFirst());
110 CPPUNIT_ASSERT(xResultSet->getRow() == 1);
111 CPPUNIT_ASSERT(xResultSetClone->getRow() == 1);
112 CPPUNIT_ASSERT(xRow->getInt(1) == 1);
113 CPPUNIT_ASSERT(xRowClone->getInt(1) == 1);
115 // if we move the source, the clone does not move
116 CPPUNIT_ASSERT(xResultSet->next());
117 CPPUNIT_ASSERT(xResultSetClone->isFirst());
118 CPPUNIT_ASSERT(xResultSet->getRow() == 2);
119 CPPUNIT_ASSERT(xResultSetClone->getRow() == 1);
120 CPPUNIT_ASSERT(xRow->getInt(1) == 2);
121 CPPUNIT_ASSERT(xRowClone->getInt(1) == 1);
123 CPPUNIT_ASSERT(xResultSet->last());
124 CPPUNIT_ASSERT(xResultSet->isLast());
125 CPPUNIT_ASSERT(xResultSetClone->isFirst());
126 CPPUNIT_ASSERT(xRowClone->getInt(1) == 1);
128 // and the other way round
129 CPPUNIT_ASSERT(xResultSet->first());
130 CPPUNIT_ASSERT(xResultSetClone->next());
131 CPPUNIT_ASSERT(xResultSet->isFirst());
132 CPPUNIT_ASSERT(xResultSetClone->getRow() == 2);
133 CPPUNIT_ASSERT(xRowClone->getInt(1) == 2);
134 CPPUNIT_ASSERT(xRow->getInt(1) == 1);
136 CPPUNIT_ASSERT(xResultSetClone->last());
137 CPPUNIT_ASSERT(xResultSetClone->isLast());
138 CPPUNIT_ASSERT(xResultSet->isFirst());
139 CPPUNIT_ASSERT(xRow->getInt(1) == 1);
141 closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
144 CPPUNIT_TEST_SUITE_REGISTRATION(RowSetClones);
146 CPPUNIT_PLUGIN_IMPLEMENT();
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */