LCOV - code coverage report
Current view: top level - sc/qa/extras - sceditfieldobj-header.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 55 55 100.0 %
Date: 2015-06-13 12:38:46 Functions: 18 19 94.7 %
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/calc_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 CalcUnoApiTest, apitest::XTextContent, apitest::XPropertySet
      34             : {
      35             : public:
      36             :     ScEditFieldObj_Header();
      37             : 
      38             :     virtual void setUp() SAL_OVERRIDE;
      39             :     virtual void tearDown() SAL_OVERRIDE;
      40             :     virtual uno::Reference<uno::XInterface> init() SAL_OVERRIDE;
      41             :     virtual uno::Reference<text::XTextContent> getTextContent() SAL_OVERRIDE;
      42             :     virtual uno::Reference<text::XTextRange> getTextRange() SAL_OVERRIDE;
      43           1 :     virtual bool isAttachSupported() SAL_OVERRIDE { 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           5 :     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 :      : CalcUnoApiTest("/sc/qa/extras/testdocuments")
      71             : {
      72           5 : }
      73             : 
      74           5 : void ScEditFieldObj_Header::setUp()
      75             : {
      76           5 :     ++nTest;
      77           5 :     CalcUnoApiTest::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           1 :         mxComponent.clear();
      89             :     }
      90             : 
      91           5 :     CalcUnoApiTest::tearDown();
      92           5 : }
      93             : 
      94          18 : uno::Reference<uno::XInterface> ScEditFieldObj_Header::init()
      95             : {
      96             :     // Return a field that's already in the header.
      97          18 :     if (!mxField.is())
      98             :     {
      99           1 :         if (!mxComponent.is())
     100             :             // Load an empty document.
     101           1 :             mxComponent = loadFromDesktop("private:factory/scalc");
     102             : 
     103           1 :         uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW);
     104             : 
     105             :         // Create a new URL field object, and populate it with name and URL.
     106           1 :         mxField.set(xSM->createInstance("com.sun.star.text.TextField.Time"), UNO_QUERY_THROW);
     107             : 
     108           2 :         uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, UNO_QUERY_THROW);
     109           2 :         uno::Reference<container::XNameAccess> xStyleFamilies(xSFS->getStyleFamilies(), UNO_QUERY_THROW);
     110           2 :         uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"), UNO_QUERY_THROW);
     111           2 :         uno::Reference<beans::XPropertySet> xPropSet(xPageStyles->getByName("Default"), UNO_QUERY_THROW);
     112             : 
     113             :         uno::Reference<sheet::XHeaderFooterContent> xHeaderContent(
     114           2 :             xPropSet->getPropertyValue("RightPageHeaderContent"), UNO_QUERY_THROW);
     115             : 
     116             :         // Use the left header text.
     117           2 :         uno::Reference<text::XText> xText = xHeaderContent->getLeftText();
     118           2 :         uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
     119           2 :         uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW);
     120           2 :         uno::Reference<text::XTextContent> xContent(mxField, UNO_QUERY_THROW);
     121           1 :         xText->insertTextContent(xRange, xContent, sal_False);
     122             : 
     123           1 :         xPropSet->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHeaderContent));
     124             : 
     125           2 :         mxRightText = xHeaderContent->getRightText();
     126             :     }
     127             : 
     128          18 :     return mxField;
     129             : }
     130             : 
     131           1 : uno::Reference<text::XTextContent> ScEditFieldObj_Header::getTextContent()
     132             : {
     133             :     // Return a field object that's not yet inserted.
     134           1 :     uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW);
     135             :     uno::Reference<text::XTextContent> xField(
     136           1 :         xSM->createInstance("com.sun.star.text.TextField.Date"), UNO_QUERY_THROW);
     137           1 :     return xField;
     138             : }
     139             : 
     140           1 : uno::Reference<text::XTextRange> ScEditFieldObj_Header::getTextRange()
     141             : {
     142             :     // Use the right header text for this.
     143           1 :     uno::Reference<text::XTextRange> xRange(mxRightText, UNO_QUERY_THROW);
     144           1 :     return xRange;
     145             : }
     146             : 
     147           1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header);
     148             : 
     149             : }
     150             : 
     151           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11