LCOV - code coverage report
Current view: top level - dbaccess/qa/extras - rowsetclones.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 70 70 100.0 %
Date: 2015-06-13 12:38:46 Functions: 13 14 92.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       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             : 
      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>
      26             : 
      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>
      34             : 
      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;
      41             : 
      42           2 : class RowSetClones : public UnoApiTest
      43             : {
      44             : public:
      45             :     RowSetClones();
      46             : 
      47             :     void test();
      48             : 
      49           2 :     CPPUNIT_TEST_SUITE(RowSetClones);
      50           1 :     CPPUNIT_TEST(test);
      51           5 :     CPPUNIT_TEST_SUITE_END();
      52             : 
      53             : };
      54             : 
      55             : 
      56           1 : RowSetClones::RowSetClones()
      57           1 :     : UnoApiTest("")
      58             : {
      59           1 : }
      60             : 
      61           1 : void RowSetClones::test()
      62             : {
      63           1 :     const OUString sFilePath(getURLFromWorkdir("CppunitTest/RowSetClones.odb"));
      64             : 
      65           2 :     uno::Reference< lang::XComponent > xComponent (loadFromDesktop(sFilePath));
      66           1 :     CPPUNIT_ASSERT(xComponent.is());
      67             : 
      68           2 :     uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY);
      69           1 :     CPPUNIT_ASSERT(xDocument.is());
      70             : 
      71           2 :     uno::Reference< XDataSource > xDataSource = xDocument->getDataSource();
      72           1 :     CPPUNIT_ASSERT(xDataSource.is());
      73             : 
      74           2 :     uno::Reference< XConnection > xConnection = xDataSource->getConnection("","");
      75           1 :     CPPUNIT_ASSERT(xConnection.is());
      76             : 
      77           2 :     uno::Reference< XRowSet > xRowSet (getMultiServiceFactory()->createInstance("com.sun.star.sdb.RowSet" ), UNO_QUERY);
      78           1 :     CPPUNIT_ASSERT(xRowSet.is());
      79           2 :     uno::Reference< XPropertySet > rowSetProperties ( xRowSet, UNO_QUERY );
      80           1 :     CPPUNIT_ASSERT(rowSetProperties.is());
      81           1 :     rowSetProperties->setPropertyValue("Command", Any(OUString("SELECT * FROM Assets ORDER BY AssetID")));
      82           1 :     rowSetProperties->setPropertyValue("CommandType", Any(CommandType::COMMAND));
      83           1 :     rowSetProperties->setPropertyValue("ActiveConnection", Any(xConnection));
      84             : 
      85           1 :     xRowSet->execute();
      86           2 :     uno::Reference< XResultSet > xResultSet(xRowSet, UNO_QUERY);
      87           1 :     CPPUNIT_ASSERT(xResultSet.is());
      88             :     // always starts at BeforeFirst position
      89           1 :     CPPUNIT_ASSERT(xResultSet->isBeforeFirst());
      90           1 :     CPPUNIT_ASSERT(xResultSet->next());
      91           1 :     CPPUNIT_ASSERT(xResultSet->isFirst());
      92           1 :     CPPUNIT_ASSERT(xResultSet->getRow() == 1);
      93             : 
      94           2 :     uno::Reference< XRow > xRow(xResultSet, UNO_QUERY);
      95           1 :     CPPUNIT_ASSERT(xRow.is());
      96           1 :     CPPUNIT_ASSERT(xRow->getInt(1) == 1);
      97             : 
      98           2 :     uno::Reference< XResultSetAccess > xResultSetAccess(xResultSet, UNO_QUERY);
      99           1 :     CPPUNIT_ASSERT(xResultSetAccess.is());
     100           2 :     uno::Reference< XResultSet > xResultSetClone = xResultSetAccess->createResultSet();
     101           1 :     CPPUNIT_ASSERT(xResultSetClone.is());
     102             : 
     103           2 :     uno::Reference< XRow > xRowClone(xResultSetClone, UNO_QUERY);
     104           1 :     CPPUNIT_ASSERT(xRowClone.is());
     105             : 
     106             :     // the clone starts at same position as what it is cloned from,
     107             :     // and does not move its source.
     108           1 :     CPPUNIT_ASSERT(xResultSetClone->isFirst());
     109           1 :     CPPUNIT_ASSERT(xResultSet->isFirst());
     110           1 :     CPPUNIT_ASSERT(xResultSet->getRow() == 1);
     111           1 :     CPPUNIT_ASSERT(xResultSetClone->getRow() == 1);
     112           1 :     CPPUNIT_ASSERT(xRow->getInt(1) == 1);
     113           1 :     CPPUNIT_ASSERT(xRowClone->getInt(1) == 1);
     114             : 
     115             :     // if we move the source, the clone does not move
     116           1 :     CPPUNIT_ASSERT(xResultSet->next());
     117           1 :     CPPUNIT_ASSERT(xResultSetClone->isFirst());
     118           1 :     CPPUNIT_ASSERT(xResultSet->getRow() == 2);
     119           1 :     CPPUNIT_ASSERT(xResultSetClone->getRow() == 1);
     120           1 :     CPPUNIT_ASSERT(xRow->getInt(1) == 2);
     121           1 :     CPPUNIT_ASSERT(xRowClone->getInt(1) == 1);
     122             : 
     123           1 :     CPPUNIT_ASSERT(xResultSet->last());
     124           1 :     CPPUNIT_ASSERT(xResultSet->isLast());
     125           1 :     CPPUNIT_ASSERT(xResultSetClone->isFirst());
     126           1 :     CPPUNIT_ASSERT(xRowClone->getInt(1) == 1);
     127             : 
     128             :     // and the other way round
     129           1 :     CPPUNIT_ASSERT(xResultSet->first());
     130           1 :     CPPUNIT_ASSERT(xResultSetClone->next());
     131           1 :     CPPUNIT_ASSERT(xResultSet->isFirst());
     132           1 :     CPPUNIT_ASSERT(xResultSetClone->getRow() == 2);
     133           1 :     CPPUNIT_ASSERT(xRowClone->getInt(1) == 2);
     134           1 :     CPPUNIT_ASSERT(xRow->getInt(1) == 1);
     135             : 
     136           1 :     CPPUNIT_ASSERT(xResultSetClone->last());
     137           1 :     CPPUNIT_ASSERT(xResultSetClone->isLast());
     138           1 :     CPPUNIT_ASSERT(xResultSet->isFirst());
     139           1 :     CPPUNIT_ASSERT(xRow->getInt(1) == 1);
     140             : 
     141           2 :     closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
     142           1 : }
     143             : 
     144           1 : CPPUNIT_TEST_SUITE_REGISTRATION(RowSetClones);
     145             : 
     146           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11