Resolves tdf#138051 - UI picker text blocks buttons
[LibreOffice.git] / basegfx / test / B2DPolygonTest.cxx
blob581108b960a5dcca8b3a436429756ca5143446cc
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 <cppunit/TestAssert.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <basegfx/polygon/b2dpolygon.hxx>
25 #include <basegfx/point/b2dpoint.hxx>
27 namespace basegfx
29 class b2dpolygon : public CppUnit::TestFixture
31 public:
32 void testCubicBezier()
34 B2DPolygon aPoly;
36 aPoly.appendBezierSegment(B2DPoint(1, 1), B2DPoint(2, 2), B2DPoint(3, 3));
38 CPPUNIT_ASSERT_EQUAL_MESSAGE("#1 first polygon point wrong", B2DPoint(3, 3),
39 aPoly.getB2DPoint(0));
40 CPPUNIT_ASSERT_EQUAL_MESSAGE("#1 first control point wrong", B2DPoint(2, 2),
41 aPoly.getPrevControlPoint(0));
42 CPPUNIT_ASSERT_EQUAL_MESSAGE("#1 second control point wrong", B2DPoint(3, 3),
43 aPoly.getNextControlPoint(0));
44 CPPUNIT_ASSERT_MESSAGE("next control point not used", !aPoly.isNextControlPointUsed(0));
46 aPoly.setNextControlPoint(0, B2DPoint(4, 4));
47 CPPUNIT_ASSERT_EQUAL_MESSAGE("#1.1 second control point wrong", B2DPoint(4, 4),
48 aPoly.getNextControlPoint(0));
49 CPPUNIT_ASSERT_MESSAGE("next control point used", aPoly.isNextControlPointUsed(0));
50 CPPUNIT_ASSERT_MESSAGE("areControlPointsUsed() wrong", aPoly.areControlPointsUsed());
51 CPPUNIT_ASSERT_EQUAL_MESSAGE("getContinuityInPoint() wrong", B2VectorContinuity::C2,
52 aPoly.getContinuityInPoint(0));
54 aPoly.resetControlPoints();
55 CPPUNIT_ASSERT_EQUAL_MESSAGE("resetControlPoints() did not clear", B2DPoint(3, 3),
56 aPoly.getB2DPoint(0));
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("resetControlPoints() did not clear", B2DPoint(3, 3),
58 aPoly.getPrevControlPoint(0));
59 CPPUNIT_ASSERT_EQUAL_MESSAGE("resetControlPoints() did not clear", B2DPoint(3, 3),
60 aPoly.getNextControlPoint(0));
61 CPPUNIT_ASSERT_MESSAGE("areControlPointsUsed() wrong #2", !aPoly.areControlPointsUsed());
63 aPoly.clear();
64 aPoly.append(B2DPoint(0, 0));
65 aPoly.appendBezierSegment(B2DPoint(1, 1), B2DPoint(2, 2), B2DPoint(3, 3));
67 CPPUNIT_ASSERT_EQUAL_MESSAGE("#2 first polygon point wrong", B2DPoint(0, 0),
68 aPoly.getB2DPoint(0));
69 CPPUNIT_ASSERT_EQUAL_MESSAGE("#2 first control point wrong", B2DPoint(0, 0),
70 aPoly.getPrevControlPoint(0));
71 CPPUNIT_ASSERT_EQUAL_MESSAGE("#2 second control point wrong", B2DPoint(1, 1),
72 aPoly.getNextControlPoint(0));
73 CPPUNIT_ASSERT_EQUAL_MESSAGE("#2 third control point wrong", B2DPoint(2, 2),
74 aPoly.getPrevControlPoint(1));
75 CPPUNIT_ASSERT_EQUAL_MESSAGE("#2 fourth control point wrong", B2DPoint(3, 3),
76 aPoly.getNextControlPoint(1));
77 CPPUNIT_ASSERT_EQUAL_MESSAGE("#2 second polygon point wrong", B2DPoint(3, 3),
78 aPoly.getB2DPoint(1));
81 void testQuadraticBezier()
83 B2DPolygon aPoly;
85 aPoly.appendQuadraticBezierSegment(B2DPoint(0, 0), B2DPoint(3, 3));
87 CPPUNIT_ASSERT_EQUAL_MESSAGE("polygon size is wrong", sal_uInt32(1), aPoly.count());
88 CPPUNIT_ASSERT_EQUAL_MESSAGE("first polygon point wrong", B2DPoint(3, 3),
89 aPoly.getB2DPoint(0));
90 CPPUNIT_ASSERT_EQUAL_MESSAGE("first control point wrong", B2DPoint(1, 1),
91 aPoly.getPrevControlPoint(0));
92 CPPUNIT_ASSERT_EQUAL_MESSAGE("second control point wrong", B2DPoint(3, 3),
93 aPoly.getNextControlPoint(0));
94 CPPUNIT_ASSERT_MESSAGE("next control point not used", !aPoly.isNextControlPointUsed(0));
97 // Change the following lines only, if you add, remove or rename
98 // member functions of the current class,
99 // because these macros are need by auto register mechanism.
101 CPPUNIT_TEST_SUITE(b2dpolygon);
102 CPPUNIT_TEST(testCubicBezier);
103 CPPUNIT_TEST(testQuadraticBezier);
104 CPPUNIT_TEST_SUITE_END();
105 }; // class b2dpolygon
107 } // namespace basegfx
109 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::b2dpolygon);
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */