LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/qa/extras - sceditfieldobj-header.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 55 55 100.0 %
Date: 2013-07-09 Functions: 15 16 93.8 %
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/unoapi_test.hxx>
      11             : #include <test/beans/xpropertyset.hxx>
      12             : #include <test/text/xtextfield.hxx>
      13             : #include <test/text/xtextcontent.hxx>
      14             : 
      15             : #include <com/sun/star/beans/XPropertySet.hpp>
      16             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      17             : #include <com/sun/star/container/XNameAccess.hpp>
      18             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      19             : #include <com/sun/star/text/XText.hpp>
      20             : #include <com/sun/star/text/XTextField.hpp>
      21             : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
      22             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      23             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      24             : #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
      25             : 
      26             : #define NUMBER_OF_TESTS 5
      27             : 
      28             : using namespace css;
      29             : using namespace css::uno;
      30             : 
      31             : namespace sc_apitest {
      32             : 
      33          10 : class ScEditFieldObj_Header : public UnoApiTest, apitest::XTextContent, apitest::XPropertySet
      34             : {
      35             : public:
      36             :     ScEditFieldObj_Header();
      37             : 
      38             :     virtual void setUp();
      39             :     virtual void tearDown();
      40             :     virtual uno::Reference<uno::XInterface> init();
      41             :     virtual uno::Reference<text::XTextContent> getTextContent();
      42             :     virtual uno::Reference<text::XTextRange> getTextRange();
      43           1 :     virtual bool isAttachSupported() { return false; }
      44             : 
      45           2 :     CPPUNIT_TEST_SUITE(ScEditFieldObj_Header);
      46             : 
      47             :     // XPropertySet
      48           1 :     CPPUNIT_TEST(testGetPropertySetInfo);
      49           1 :     CPPUNIT_TEST(testGetPropertyValue);
      50           1 :     CPPUNIT_TEST(testSetPropertyValue);
      51             : 
      52             :     // XTextContent
      53           1 :     CPPUNIT_TEST(testGetAnchor);
      54           1 :     CPPUNIT_TEST(testAttach);
      55           2 :     CPPUNIT_TEST_SUITE_END();
      56             : 
      57             : private:
      58             :     static sal_Int32 nTest;
      59             :     static uno::Reference<lang::XComponent> mxComponent;
      60             :     static uno::Reference<text::XTextField> mxField;
      61             :     static uno::Reference<text::XText> mxRightText;
      62             : };
      63             : 
      64             : sal_Int32 ScEditFieldObj_Header::nTest = 0;
      65           1 : uno::Reference<lang::XComponent> ScEditFieldObj_Header::mxComponent;
      66           1 : uno::Reference<text::XTextField> ScEditFieldObj_Header::mxField;
      67           1 : uno::Reference<text::XText> ScEditFieldObj_Header::mxRightText;
      68             : 
      69           5 : ScEditFieldObj_Header::ScEditFieldObj_Header()
      70           5 :      : UnoApiTest("/sc/qa/extras/testdocuments")
      71             : {
      72           5 : }
      73             : 
      74           5 : void ScEditFieldObj_Header::setUp()
      75             : {
      76           5 :     ++nTest;
      77           5 :     UnoApiTest::setUp();
      78           5 : }
      79             : 
      80           5 : void ScEditFieldObj_Header::tearDown()
      81             : {
      82           5 :     if (nTest == NUMBER_OF_TESTS)
      83             :     {
      84             :         // Clear these before the component is destroyed.  This is important!
      85           1 :         mxField.clear();
      86           1 :         mxRightText.clear();
      87           1 :         closeDocument(mxComponent);
      88             :     }
      89             : 
      90           5 :     UnoApiTest::tearDown();
      91           5 : }
      92             : 
      93          18 : uno::Reference<uno::XInterface> ScEditFieldObj_Header::init()
      94             : {
      95             :     // Return a field that's already in the header.
      96          18 :     if (!mxField.is())
      97             :     {
      98           1 :         if (!mxComponent.is())
      99             :             // Load an empty document.
     100           1 :             mxComponent = loadFromDesktop("private:factory/scalc");
     101             : 
     102           1 :         uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW);
     103             : 
     104             :         // Create a new URL field object, and populate it with name and URL.
     105           1 :         mxField.set(xSM->createInstance("com.sun.star.text.TextField.Time"), UNO_QUERY_THROW);
     106             : 
     107           2 :         uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, UNO_QUERY_THROW);
     108           2 :         uno::Reference<container::XNameAccess> xStyleFamilies(xSFS->getStyleFamilies(), UNO_QUERY_THROW);
     109           2 :         uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"), UNO_QUERY_THROW);
     110           2 :         uno::Reference<beans::XPropertySet> xPropSet(xPageStyles->getByName("Default"), UNO_QUERY_THROW);
     111             : 
     112             :         uno::Reference<sheet::XHeaderFooterContent> xHeaderContent(
     113           2 :             xPropSet->getPropertyValue("RightPageHeaderContent"), UNO_QUERY_THROW);
     114             : 
     115             :         // Use the left header text.
     116           2 :         uno::Reference<text::XText> xText = xHeaderContent->getLeftText();
     117           2 :         uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
     118           2 :         uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW);
     119           2 :         uno::Reference<text::XTextContent> xContent(mxField, UNO_QUERY_THROW);
     120           1 :         xText->insertTextContent(xRange, xContent, sal_False);
     121             : 
     122           1 :         xPropSet->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHeaderContent));
     123             : 
     124           2 :         mxRightText = xHeaderContent->getRightText();
     125             :     }
     126             : 
     127          18 :     return mxField;
     128             : }
     129             : 
     130           1 : uno::Reference<text::XTextContent> ScEditFieldObj_Header::getTextContent()
     131             : {
     132             :     // Return a field object that's not yet inserted.
     133           1 :     uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW);
     134             :     uno::Reference<text::XTextContent> xField(
     135           1 :         xSM->createInstance("com.sun.star.text.TextField.Date"), UNO_QUERY_THROW);
     136           1 :     return xField;
     137             : }
     138             : 
     139           1 : uno::Reference<text::XTextRange> ScEditFieldObj_Header::getTextRange()
     140             : {
     141             :     // Use the right header text for this.
     142           1 :     uno::Reference<text::XTextRange> xRange(mxRightText, UNO_QUERY_THROW);
     143           1 :     return xRange;
     144             : }
     145             : 
     146           1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header);
     147             : 
     148           1 : CPPUNIT_PLUGIN_IMPLEMENT();
     149             : 
     150           3 : }
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10