LCOV - code coverage report
Current view: top level - test/source/sheet - xsheetoutline.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 112 114 98.2 %
Date: 2014-11-03 Functions: 10 11 90.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 <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          48 : const OUString colLevel1 = "OutlineSheet.A1:Z1";
      31          48 : const OUString colLevel2 = "OutlineSheet.C1:W1";
      32          48 : const OUString colLevel3 = "OutlineSheet.E1:U1";
      33          48 : const OUString colLevel4 = "OutlineSheet.G1:S1";
      34             : 
      35          48 : const OUString rowLevel1 = "OutlineSheet.A1:A30";
      36          48 : const OUString rowLevel2 = "OutlineSheet.A3:A27";
      37          48 : const OUString rowLevel3 = "OutlineSheet.A5:A24";
      38          48 : const OUString rowLevel4 = "OutlineSheet.A7:A21";
      39             : 
      40          28 : OUString getVisibleAdress(
      41             :     uno::Reference<sheet::XSpreadsheet> const& xSheet,
      42             :     const OUString& aLevelRangeString)
      43             : {
      44             : 
      45          28 :     uno::Reference<table::XCellRange> aSheetRangeAccess(xSheet, UNO_QUERY_THROW);
      46          56 :     uno::Reference<table::XCellRange> aLevelRange = aSheetRangeAccess->getCellRangeByName(aLevelRangeString);
      47             : 
      48          56 :     uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(aLevelRange,UNO_QUERY_THROW);
      49          56 :     uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryVisibleCells();
      50          28 :     OUString aResult = xRanges->getRangeAddressesAsString();
      51             : 
      52          56 :     return aResult;
      53             : 
      54             : }
      55             : 
      56          38 : table::CellRangeAddress getAddressFromRangeString(
      57             :     uno::Reference<sheet::XSpreadsheet> const& xSheet,
      58             :     const OUString& aStringAddress)
      59             : {
      60             : 
      61          38 :     uno::Reference< table::XCellRange > aSheetRangeAccess(xSheet, UNO_QUERY_THROW);
      62          76 :     uno::Reference<table::XCellRange> aRange = aSheetRangeAccess->getCellRangeByName(aStringAddress);
      63             : 
      64          76 :     uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(aRange, UNO_QUERY_THROW);
      65          38 :     table::CellRangeAddress aLevelRangeAddress = xCellRangeAddressable->getRangeAddress();
      66             : 
      67          76 :     return aLevelRangeAddress;
      68             : 
      69             : }
      70             : 
      71           2 : void XSheetOutline::testHideDetail()
      72             : {
      73             : 
      74           2 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
      75           4 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
      76             : 
      77             :     // Column level 2
      78           2 :     table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2);
      79           2 :     aSheetOutline->hideDetail(aLevelRangeAddress);
      80             : 
      81           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 not hidden",
      82           2 :             getVisibleAdress(aSheet, colLevel2), OUString(""));
      83             : 
      84             :     // Row Level 2
      85           2 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2);
      86           2 :     aSheetOutline->hideDetail(aLevelRangeAddress);
      87             : 
      88           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 not hidden",
      89           4 :             getVisibleAdress(aSheet, rowLevel2), OUString(""));
      90             : 
      91           2 : }
      92             : 
      93           2 : void XSheetOutline::testShowDetail()
      94             : {
      95           2 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
      96           4 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
      97             : 
      98           2 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1));
      99           2 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1));
     100             : 
     101             :     // Row Level 2
     102           2 :     table::CellRangeAddress  aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2);
     103           2 :     aSheetOutline->showDetail(aLevelRangeAddress);
     104             : 
     105           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 still hidden",
     106           2 :             getVisibleAdress(aSheet, rowLevel2), rowLevel2);
     107             : 
     108             :     // Column Level 2
     109           2 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2);
     110           2 :     aSheetOutline->showDetail(aLevelRangeAddress);
     111             : 
     112           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 still hidden",
     113           4 :             getVisibleAdress(aSheet, colLevel2), colLevel2);
     114             : 
     115           2 : }
     116             : 
     117           2 : void XSheetOutline::testShowLevel()
     118             : {
     119             : 
     120           2 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
     121           4 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
     122             : 
     123           2 :     table::CellRangeAddress aLevelRangeAddress;
     124             : 
     125             :     // test columns
     126             : 
     127           2 :     table::CellRangeAddress aLevel1 = getAddressFromRangeString(aSheet, colLevel1);
     128           2 :     table::CellRangeAddress aLevel2 = getAddressFromRangeString(aSheet, colLevel2);
     129           2 :     table::CellRangeAddress aLevel3 = getAddressFromRangeString(aSheet, colLevel3);
     130           2 :     table::CellRangeAddress aLevel4 = getAddressFromRangeString(aSheet, colLevel4);
     131             : 
     132           2 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1));
     133           2 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel2));
     134           2 :     aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1));
     135             : 
     136           2 :     aSheetOutline->hideDetail(aLevel1);
     137           2 :     aSheetOutline->hideDetail(aLevel2);
     138           2 :     aSheetOutline->hideDetail(aLevel3);
     139           2 :     aSheetOutline->hideDetail(aLevel4);
     140             : 
     141           2 :     aSheetOutline->showLevel(2, table::TableOrientation_COLUMNS);
     142             : 
     143           2 :     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           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.A1:D1"), getVisibleAdress(aSheet, "OutlineSheet.A1:D1"));
     149           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.V1:Z1"), getVisibleAdress(aSheet, "OutlineSheet.V1:Z1"));
     150           4 :     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           2 : }
     188             : 
     189           2 : void XSheetOutline::testGroup()
     190             : {
     191             : 
     192           2 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
     193           4 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
     194             : 
     195             :     // Column level 2
     196           4 :     OUString aNewString = "OutlineSheet.AB1:AG1";
     197           2 :     table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
     198           2 :     aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS);
     199             : 
     200           2 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     201             : 
     202           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Column still visible", getVisibleAdress(aSheet, aNewString), OUString(""));
     203             : 
     204             :     // Row Level 2
     205           2 :     aNewString = "OutlineSheet.A50:A60";
     206           2 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
     207           2 :     aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS);
     208             : 
     209           2 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     210             : 
     211           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Row still visible", getVisibleAdress(aSheet, aNewString), OUString(""));
     212             : 
     213           2 : }
     214             : 
     215           2 : void XSheetOutline::testUngroup()
     216             : {
     217           2 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
     218           4 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
     219             : 
     220             :     // New Column level
     221           4 :     OUString aNewString = "OutlineSheet.BB1:BG1";
     222           2 :     table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
     223           2 :     aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS);
     224           2 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     225             : 
     226           2 :     aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_COLUMNS);
     227             : 
     228           2 :     aSheetOutline->showDetail(aLevelRangeAddress);
     229             :     // should remain hidden ?
     230             : 
     231           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Column becomes visible after ungroup", getVisibleAdress(aSheet, aNewString), OUString(""));
     232             : 
     233             :     // New Row level
     234           2 :     aNewString = "OutlineSheet.A70:A80";
     235           2 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
     236           2 :     aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS);
     237           2 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     238             : 
     239           2 :     aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_ROWS);
     240             : 
     241           2 :     aSheetOutline->showDetail(aLevelRangeAddress);
     242             :     // should remain hidden ?
     243             : 
     244           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Row becomes visible after ungroup", getVisibleAdress(aSheet, aNewString), OUString(""));
     245             : 
     246           2 : }
     247             : 
     248           0 : void XSheetOutline::testAutoOutline()
     249             : {
     250           0 : }
     251             : 
     252           2 : void XSheetOutline::testClearOutline()
     253             : {
     254           2 :     uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
     255           4 :     uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
     256             : 
     257           2 :     aSheetOutline->clearOutline();
     258             : 
     259           2 :     table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel1);
     260           2 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     261           2 :     aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel1);
     262           2 :     aSheetOutline->hideDetail(aLevelRangeAddress);
     263             : 
     264           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Columns are hidden after clear", getVisibleAdress(aSheet, colLevel1), colLevel1);
     265           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Rows are hidden after clear", getVisibleAdress(aSheet, rowLevel1), rowLevel1);
     266             : 
     267           2 : }
     268             : 
     269         144 : }
     270             : 
     271             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10