fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / basegfx / test / clipstate.cxx
blobf2b0ef0e94b75bb96ff9561f3af5ca1e89f3c283
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/types.h>
21 #include "cppunit/TestAssert.h"
22 #include "cppunit/TestFixture.h"
23 #include "cppunit/extensions/HelperMacros.h"
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>
33 using namespace ::basegfx;
36 namespace basegfx2d
39 class clipstate : public CppUnit::TestFixture
41 private:
42 tools::B2DClipState aUnion1;
43 tools::B2DClipState aUnion2;
44 tools::B2DClipState aIntersect;
45 tools::B2DClipState aXor;
46 tools::B2DClipState aSubtract;
48 public:
49 void setUp()
51 B2DRange aCenter(100, 100, -100, -100);
52 B2DRange aNorth(-10, -110, 10, -90);
53 B2DRange aWest(-110, -10, -90, 10);
54 B2DRange aSouth(-10, 110, 10, 90);
55 B2DRange aEast(110, -10, 90, 10);
57 aUnion1.unionRange(aCenter);
58 aUnion1.unionRange(aNorth);
59 aUnion1.unionRange(aWest);
60 aUnion1.unionRange(aSouth);
61 aUnion1.unionRange(aEast);
63 aUnion2.makeNull();
64 aUnion2.unionRange(aCenter);
65 aUnion2.unionRange(aNorth);
66 aUnion2.unionRange(aWest);
67 aUnion2.unionRange(aSouth);
68 aUnion2.unionRange(aEast);
70 aIntersect.intersectRange(aCenter);
71 aIntersect.intersectRange(aNorth);
72 aIntersect.intersectRange(aWest);
73 aIntersect.intersectRange(aSouth);
74 aIntersect.intersectRange(aEast);
76 aXor.makeNull();
77 aXor.xorRange(aCenter);
78 aXor.xorRange(aNorth);
79 aXor.xorRange(aWest);
80 aXor.xorRange(aSouth);
81 aXor.xorRange(aEast);
83 aSubtract.intersectRange(aCenter);
84 aSubtract.subtractRange(aNorth);
85 aSubtract.subtractRange(aWest);
86 aSubtract.subtractRange(aSouth);
87 aSubtract.subtractRange(aEast);
90 void tearDown()
93 void verifyPoly(const char* sName, const char* sSvg, const tools::B2DClipState& toTest)
95 #if OSL_DEBUG_LEVEL > 2
96 fprintf(stderr, "%s - svg:d=\"%s\"\n",
97 sName, OUStringToOString(
98 basegfx::tools::exportToSvgD(toTest.getClipPoly()),
99 RTL_TEXTENCODING_UTF8).getStr() );
100 #endif
102 B2DPolyPolygon aTmp1;
103 CPPUNIT_ASSERT_MESSAGE(sName,
104 tools::importFromSvgD(
105 aTmp1,
106 OUString::createFromAscii(sSvg)));
108 const OUString aSvg=
109 tools::exportToSvgD(toTest.getClipPoly());
110 B2DPolyPolygon aTmp2;
111 CPPUNIT_ASSERT_MESSAGE(sName,
112 tools::importFromSvgD(
113 aTmp2,
114 aSvg));
116 CPPUNIT_ASSERT_MESSAGE(
117 sName,
118 aTmp2 == aTmp1);
121 void verifySimpleRange()
123 const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
124 const char* intersectSvg="m-100 10v-20h10v20zm90 90v-10h20v10zm0-190v-10h20v10zm100 100v-20h10v20z";
125 const char* xorSvg="m-100 10h10v-20h-10zm90 90h20v-10h-20zm0-190h20v-10h-20zm100 100h10v-20h-10z"
126 "m10 0v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
127 const char* subtractSvg="m-90 10v-20h-10v-90h90v10h20v-10h90v90h-10v20h10v90h-90v-10h-20v10h-90v-90z";
129 CPPUNIT_ASSERT_MESSAGE("cleared clip stays empty under union operation",
130 aUnion1.isCleared());
131 verifyPoly("union", unionSvg, aUnion2);
132 verifyPoly("intersect", intersectSvg, aIntersect);
133 verifyPoly("xor", xorSvg, aXor);
134 verifyPoly("subtract", subtractSvg, aSubtract);
137 void verifyMixedClips()
139 tools::B2DClipState aMixedClip;
141 const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
143 B2DPolyPolygon aTmp1;
144 tools::importFromSvgD(
145 aTmp1,
146 OUString::createFromAscii(unionSvg));
148 aMixedClip.intersectPolyPolygon(aTmp1);
149 aMixedClip.subtractRange(B2DRange(-20,-150,20,0));
150 aMixedClip.subtractRange(B2DRange(-150,-20,0,20));
151 aMixedClip.xorRange(B2DRange(-150,-150,150,150));
153 const char* mixedClipSvg="m0 0v20h-100v80h90v10h20v-10h90v-90h10v-20h-10v-90h-80v100zm-20-20v-80h-80v80zm-130 170v-300h300v300z";
154 verifyPoly("mixed clip", mixedClipSvg, aMixedClip);
157 CPPUNIT_TEST_SUITE(clipstate);
158 CPPUNIT_TEST(verifySimpleRange);
159 CPPUNIT_TEST(verifyMixedClips);
160 CPPUNIT_TEST_SUITE_END();
163 // -----------------------------------------------------------------------------
164 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::clipstate);
165 } // namespace basegfx2d
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */