LCOV - code coverage report
Current view: top level - test/source/sheet - xsheetoutline.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 112 112 100.0 %
Date: 2015-06-13 12:38:46 Functions: 10 10 100.0 %
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 <test/sheet/xsheetoutline.hxx>
      11             : 
      12             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      13             : #include <com/sun/star/table/CellRangeAddress.hpp>
      14             : #include <com/sun/star/table/XCellRange.hpp>
      15             : 
      16             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      17             : #include <com/sun/star/table/TableOrientation.hpp>
      18             : 
      19             : #include <com/sun/star/sheet/XSheetCellRanges.hpp>
      20             : #include <com/sun/star/sheet/XCellRangesQuery.hpp>
      21             : 
      22             : #include "cppunit/extensions/HelperMacros.h"
      23             : #include <rtl/ustring.hxx>
      24             : 
      25             : using namespace css;
      26             : using namespace css::uno;
      27             : 
      28             : namespace apitest {
      29             : 
      30          30 : const OUString colLevel1 = "OutlineSheet.A1:Z1";
      31          30 : const OUString colLevel2 = "OutlineSheet.C1:W1";
      32          30 : const OUString colLevel3 = "OutlineSheet.E1:U1";
      33          30 : const OUString colLevel4 = "OutlineSheet.G1:S1";
      34             : 
      35          30 : const OUString rowLevel1 = "OutlineSheet.A1:A30";
      36          30 : const OUString rowLevel2 = "OutlineSheet.A3:A27";
      37          30 : const OUString rowLevel3 = "OutlineSheet.A5:A24";
      38          30 : const OUString rowLevel4 = "OutlineSheet.A7:A21";
      39             : 
      40          14 : OUString getVisibleAdress(
      41             :     uno::Reference<sheet::XSpreadsheet> const& xSheet,
      42             :     const OUString& aLevelRangeString)
      43             : {
      44             : 
      45          14 :     uno::Reference<table::XCellRange> aSheetRangeAccess(xSheet, UNO_QUERY_THROW);
      46          28 :     uno::Reference<table::XCellRange> aLevelRange = aSheetRangeAccess->getCellRangeByName(aLevelRangeString);
      47             : 
      48          28 :     uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(aLevelRange,UNO_QUERY_THROW);
      49          28 :     uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryVisibleCells();
      50          14 :     OUString aResult = xRanges->getRangeAddressesAsString();
      51             : 
      52          28 :     return aResult;
      53             : 
      54             : }
      55             : 
      56          19 : table::CellRangeAddress getAddressFromRangeString(
      57             :     uno::Reference<sheet::XSpreadsheet> const& xSheet,
      58             :     const OUString& aStringAddress)
      59             : {
      60             : 
      61          19 :     uno::Reference< table::XCellRange > aSheetRangeAccess(xSheet, UNO_QUERY_THROW);
      62          38 :     uno::Reference<table::XCellRange> aRange = aSheetRangeAccess->getCellRangeByName(aStringAddress);
      63             : 
      64          38 :     uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(aRange, UNO_QUERY_THROW);
      65          19 :     table::CellRangeAddress aLevelRangeAddress = xCellRangeAddressable->getRangeAddress();
      66             : 
      67          38 :     return aLevelRangeAddress;
      68             : 
      69             : }
      70             : 
      71           1 : void XSheetOutline::testHideDetail()
      72             : {
      73             : 
      74           1 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
      75           2 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
      76             : 
      77             :     // Column level 2
      78           1 :     table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2);
      79           1 :     aSheetOutline->hideDetail(aLevelRangeAddress);
      80             : 
      81           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 not hidden",
      82           1 :             getVisibleAdress(aSheet, colLevel2), OUString(""));
      83             : 
      84             :     // Row Level 2
      85           1 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2);
      86           1 :     aSheetOutline->hideDetail(aLevelRangeAddress);
      87             : 
      88           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 not hidden",
      89           2 :             getVisibleAdress(aSheet, rowLevel2), OUString(""));
      90             : 
      91           1 : }
      92             : 
      93           1 : void XSheetOutline::testShowDetail()
      94             : {
      95           1 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
      96           2 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
      97             : 
      98           1 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1));
      99           1 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1));
     100             : 
     101             :     // Row Level 2
     102           1 :     table::CellRangeAddress  aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2);
     103           1 :     aSheetOutline->showDetail(aLevelRangeAddress);
     104             : 
     105           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 still hidden",
     106           1 :             getVisibleAdress(aSheet, rowLevel2), rowLevel2);
     107             : 
     108             :     // Column Level 2
     109           1 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2);
     110           1 :     aSheetOutline->showDetail(aLevelRangeAddress);
     111             : 
     112           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 still hidden",
     113           2 :             getVisibleAdress(aSheet, colLevel2), colLevel2);
     114             : 
     115           1 : }
     116             : 
     117           1 : void XSheetOutline::testShowLevel()
     118             : {
     119             : 
     120           1 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
     121           2 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
     122             : 
     123           1 :     table::CellRangeAddress aLevelRangeAddress;
     124             : 
     125             :     // test columns
     126             : 
     127           1 :     table::CellRangeAddress aLevel1 = getAddressFromRangeString(aSheet, colLevel1);
     128           1 :     table::CellRangeAddress aLevel2 = getAddressFromRangeString(aSheet, colLevel2);
     129           1 :     table::CellRangeAddress aLevel3 = getAddressFromRangeString(aSheet, colLevel3);
     130           1 :     table::CellRangeAddress aLevel4 = getAddressFromRangeString(aSheet, colLevel4);
     131             : 
     132           1 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1));
     133           1 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel2));
     134           1 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1));
     135             : 
     136           1 :     aSheetOutline->hideDetail(aLevel1);
     137           1 :     aSheetOutline->hideDetail(aLevel2);
     138           1 :     aSheetOutline->hideDetail(aLevel3);
     139           1 :     aSheetOutline->hideDetail(aLevel4);
     140             : 
     141           1 :     aSheetOutline->showLevel(2, table::TableOrientation_COLUMNS);
     142             : 
     143           1 :     std::cout << " verifiy showLevel col apres" << OUStringToOString(getVisibleAdress(aSheet, "OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
     144             : 
     145             :     // verify that level 2 and level 1 are shown --> column 0..3 & column 22..26
     146             :     // level 3 & 4 are hidden --> column 4..19
     147             : 
     148           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.A1:D1"), getVisibleAdress(aSheet, "OutlineSheet.A1:D1"));
     149           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.V1:Z1"), getVisibleAdress(aSheet, "OutlineSheet.V1:Z1"));
     150           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString(""), getVisibleAdress(aSheet, colLevel3));
     151             : 
     152             : /* FIXME !!
     153             : 
     154             :     // test Rows
     155             : 
     156             :     aLevel1 = getAddressFromRangeString(rowLevel1);
     157             :     aLevel2 = getAddressFromRangeString(rowLevel2);
     158             :     aLevel3 = getAddressFromRangeString(rowLevel3);
     159             :     aLevel4 = getAddressFromRangeString(rowLevel4);
     160             : 
     161             :     aSheetOutline->showDetail(getAddressFromRangeString(colLevel1));
     162             :     aSheetOutline->showDetail(getAddressFromRangeString(rowLevel1));
     163             :     aSheetOutline->showDetail(getAddressFromRangeString(rowLevel2));
     164             : 
     165             :     std::cout << " verifiy showLevel row avant" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
     166             : 
     167             :     aSheetOutline->hideDetail(aLevel1);
     168             :     aSheetOutline->hideDetail(aLevel2);
     169             :     aSheetOutline->hideDetail(aLevel3);
     170             :     aSheetOutline->hideDetail(aLevel4);
     171             : 
     172             :     std::cout << " verifiy showLevel row juste avant" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
     173             : 
     174             :     aSheetOutline->showLevel(2, table::TableOrientation_ROWS);
     175             : 
     176             :     std::cout << " verifiy showLevel row apres" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
     177             : 
     178             :     // verify rows visible 0..3 & 24..29
     179             :     // verfiy rows hidden 4..23
     180             : 
     181             :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A1:A4"), getVisibleAdress("OutlineSheet.A1:A4"));
     182             :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A25:A30"), getVisibleAdress("OutlineSheet.A25:A30"));
     183             :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString(""), getVisibleAdress(rowLevel3));
     184             : 
     185             : */
     186             : 
     187           1 : }
     188             : 
     189           1 : void XSheetOutline::testGroup()
     190             : {
     191             : 
     192           1 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
     193           2 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
     194             : 
     195             :     // Column level 2
     196           2 :     OUString aNewString = "OutlineSheet.AB1:AG1";
     197           1 :     table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
     198           1 :     aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS);
     199             : 
     200           1 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     201             : 
     202           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Column still visible", getVisibleAdress(aSheet, aNewString), OUString(""));
     203             : 
     204             :     // Row Level 2
     205           1 :     aNewString = "OutlineSheet.A50:A60";
     206           1 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
     207           1 :     aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS);
     208             : 
     209           1 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     210             : 
     211           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Row still visible", getVisibleAdress(aSheet, aNewString), OUString(""));
     212             : 
     213           1 : }
     214             : 
     215           1 : void XSheetOutline::testUngroup()
     216             : {
     217           1 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
     218           2 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
     219             : 
     220             :     // New Column level
     221           2 :     OUString aNewString = "OutlineSheet.BB1:BG1";
     222           1 :     table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
     223           1 :     aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS);
     224           1 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     225             : 
     226           1 :     aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_COLUMNS);
     227             : 
     228           1 :     aSheetOutline->showDetail(aLevelRangeAddress);
     229             :     // should remain hidden ?
     230             : 
     231           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Column becomes visible after ungroup", getVisibleAdress(aSheet, aNewString), OUString(""));
     232             : 
     233             :     // New Row level
     234           1 :     aNewString = "OutlineSheet.A70:A80";
     235           1 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
     236           1 :     aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS);
     237           1 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     238             : 
     239           1 :     aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_ROWS);
     240             : 
     241           1 :     aSheetOutline->showDetail(aLevelRangeAddress);
     242             :     // should remain hidden ?
     243             : 
     244           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Row becomes visible after ungroup", getVisibleAdress(aSheet, aNewString), OUString(""));
     245             : 
     246           1 : }
     247             : 
     248           1 : void XSheetOutline::testClearOutline()
     249             : {
     250           1 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
     251           2 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
     252             : 
     253           1 :     aSheetOutline->clearOutline();
     254             : 
     255           1 :     table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel1);
     256           1 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     257           1 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel1);
     258           1 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     259             : 
     260           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Columns are hidden after clear", getVisibleAdress(aSheet, colLevel1), colLevel1);
     261           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Rows are hidden after clear", getVisibleAdress(aSheet, rowLevel1), rowLevel1);
     262             : 
     263           1 : }
     264             : 
     265          90 : }
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11