LCOV - code coverage report
Current view: top level - basegfx/test - clipstate.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 78 78 100.0 %
Date: 2014-11-03 Functions: 13 13 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : #include <cppunit/TestAssert.h>
      22             : #include <cppunit/TestFixture.h>
      23             : #include <cppunit/extensions/HelperMacros.h>
      24             : 
      25             : #include <basegfx/tools/b2dclipstate.hxx>
      26             : #include <basegfx/range/b2dpolyrange.hxx>
      27             : #include <basegfx/polygon/b2dpolygon.hxx>
      28             : #include <basegfx/polygon/b2dpolygontools.hxx>
      29             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      30             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      31             : #include <basegfx/numeric/ftools.hxx>
      32             : 
      33             : using namespace ::basegfx;
      34             : 
      35             : namespace basegfx2d
      36             : {
      37             : 
      38          12 : class clipstate : public CppUnit::TestFixture
      39             : {
      40             : private:
      41             :     tools::B2DClipState aUnion1;
      42             :     tools::B2DClipState aUnion2;
      43             :     tools::B2DClipState aIntersect;
      44             :     tools::B2DClipState aXor;
      45             :     tools::B2DClipState aSubtract;
      46             : 
      47             : public:
      48           4 :     void setUp() SAL_OVERRIDE
      49             :     {
      50           4 :         B2DRange aCenter(100, 100, -100, -100);
      51           4 :         B2DRange aNorth(-10, -110, 10, -90);
      52           4 :         B2DRange aWest(-110, -10, -90, 10);
      53           4 :         B2DRange aSouth(-10, 110, 10, 90);
      54           4 :         B2DRange aEast(110, -10, 90, 10);
      55             : 
      56           4 :         aUnion1.unionRange(aCenter);
      57           4 :         aUnion1.unionRange(aNorth);
      58           4 :         aUnion1.unionRange(aWest);
      59           4 :         aUnion1.unionRange(aSouth);
      60           4 :         aUnion1.unionRange(aEast);
      61             : 
      62           4 :         aUnion2.makeNull();
      63           4 :         aUnion2.unionRange(aCenter);
      64           4 :         aUnion2.unionRange(aNorth);
      65           4 :         aUnion2.unionRange(aWest);
      66           4 :         aUnion2.unionRange(aSouth);
      67           4 :         aUnion2.unionRange(aEast);
      68             : 
      69           4 :         aIntersect.intersectRange(aCenter);
      70           4 :         aIntersect.intersectRange(aNorth);
      71           4 :         aIntersect.intersectRange(aWest);
      72           4 :         aIntersect.intersectRange(aSouth);
      73           4 :         aIntersect.intersectRange(aEast);
      74             : 
      75           4 :         aXor.makeNull();
      76           4 :         aXor.xorRange(aCenter);
      77           4 :         aXor.xorRange(aNorth);
      78           4 :         aXor.xorRange(aWest);
      79           4 :         aXor.xorRange(aSouth);
      80           4 :         aXor.xorRange(aEast);
      81             : 
      82           4 :         aSubtract.intersectRange(aCenter);
      83           4 :         aSubtract.subtractRange(aNorth);
      84           4 :         aSubtract.subtractRange(aWest);
      85           4 :         aSubtract.subtractRange(aSouth);
      86           4 :         aSubtract.subtractRange(aEast);
      87           4 :     }
      88             : 
      89           4 :     void tearDown() SAL_OVERRIDE
      90           4 :     {}
      91             : 
      92          10 :     void verifyPoly(const char* sName, const char* sSvg, const tools::B2DClipState& toTest)
      93             :     {
      94             : #if OSL_DEBUG_LEVEL > 2
      95             :         fprintf(stderr, "%s - svg:d=\"%s\"\n",
      96             :                 sName, OUStringToOString(
      97             :                     basegfx::tools::exportToSvgD(toTest.getClipPoly(), true, true, false),
      98             :                     RTL_TEXTENCODING_UTF8).getStr() );
      99             : #endif
     100             : 
     101          10 :         B2DPolyPolygon aTmp1;
     102          20 :         CPPUNIT_ASSERT_MESSAGE(sName,
     103             :                                tools::importFromSvgD(
     104          10 :                                    aTmp1, OUString::createFromAscii(sSvg), false, 0));
     105             : 
     106             :         const OUString aSvg=
     107          20 :             tools::exportToSvgD(toTest.getClipPoly(), true, true, false);
     108          20 :         B2DPolyPolygon aTmp2;
     109          20 :         CPPUNIT_ASSERT_MESSAGE(sName,
     110             :                                tools::importFromSvgD(
     111          10 :                                    aTmp2, aSvg, false, 0));
     112             : 
     113          20 :         CPPUNIT_ASSERT_MESSAGE(
     114             :             sName,
     115          20 :             aTmp2 == aTmp1);
     116          10 :     }
     117             : 
     118           2 :     void verifySimpleRange()
     119             :     {
     120           2 :         const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
     121           2 :         const char* intersectSvg="m-100 10v-20h10v20zm90 90v-10h20v10zm0-190v-10h20v10zm100 100v-20h10v20z";
     122             :         const char* xorSvg="m-100 10h10v-20h-10zm90 90h20v-10h-20zm0-190h20v-10h-20zm100 100h10v-20h-10z"
     123           2 :                            "m10 0v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
     124           2 :         const char* subtractSvg="m-90 10v-20h-10v-90h90v10h20v-10h90v90h-10v20h10v90h-90v-10h-20v10h-90v-90z";
     125             : 
     126           4 :         CPPUNIT_ASSERT_MESSAGE("cleared clip stays empty under union operation",
     127           2 :                                aUnion1.isCleared());
     128           2 :         verifyPoly("union", unionSvg, aUnion2);
     129           2 :         verifyPoly("intersect", intersectSvg, aIntersect);
     130           2 :         verifyPoly("xor", xorSvg, aXor);
     131           2 :         verifyPoly("subtract", subtractSvg, aSubtract);
     132           2 :     }
     133             : 
     134           2 :     void verifyMixedClips()
     135             :     {
     136           2 :         tools::B2DClipState aMixedClip;
     137             : 
     138           2 :         const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
     139             : 
     140           4 :         B2DPolyPolygon aTmp1;
     141             :         tools::importFromSvgD(
     142           2 :             aTmp1, OUString::createFromAscii(unionSvg), false, 0);
     143             : 
     144           2 :         aMixedClip.intersectPolyPolygon(aTmp1);
     145           2 :         aMixedClip.subtractRange(B2DRange(-20,-150,20,0));
     146           2 :         aMixedClip.subtractRange(B2DRange(-150,-20,0,20));
     147           2 :         aMixedClip.xorRange(B2DRange(-150,-150,150,150));
     148             : 
     149           2 :         const char* mixedClipSvg="m0 0v20h-100v80h90v10h20v-10h90v-90h10v-20h-10v-90h-80v100zm-20-20v-80h-80v80zm-130 170v-300h300v300z";
     150           4 :         verifyPoly("mixed clip", mixedClipSvg, aMixedClip);
     151           2 :     }
     152             : 
     153           4 :     CPPUNIT_TEST_SUITE(clipstate);
     154           2 :     CPPUNIT_TEST(verifySimpleRange);
     155           2 :     CPPUNIT_TEST(verifyMixedClips);
     156           4 :     CPPUNIT_TEST_SUITE_END();
     157             : };
     158             : 
     159           2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::clipstate);
     160           6 : } // namespace basegfx2d
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10