crashtesting: use after free
[LibreOffice.git] / basegfx / test / B2DRangeTest.cxx
blob59384e26b697243f34534a187db76e618b71767a
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>
23 #include <cppunit/plugin/TestPlugIn.h>
25 #include <basegfx/range/b2drange.hxx>
26 #include <basegfx/range/b2irange.hxx>
28 class B2DRangeTest : public CppUnit::TestFixture
30 void testCreation()
32 basegfx::B2DRange aRange(1.2, 2.3, 3.5, 4.8);
34 CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(1.2, 2.3, 3.5, 4.8), aRange);
36 CPPUNIT_ASSERT_EQUAL(1.2, aRange.getMinX());
37 CPPUNIT_ASSERT_EQUAL(3.5, aRange.getMaxX());
38 CPPUNIT_ASSERT_EQUAL(2.3, aRange.getMinY());
39 CPPUNIT_ASSERT_EQUAL(4.8, aRange.getMaxY());
41 CPPUNIT_ASSERT_EQUAL(2.3, aRange.getWidth());
42 CPPUNIT_ASSERT_EQUAL(2.5, aRange.getHeight());
44 // wrong order of the interval
45 basegfx::B2DRange aRange2(1.0, 1.0, 0.0, 0.0);
47 CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(1.0, 1.0, 0.0, 0.0), aRange2);
48 CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), aRange2);
50 CPPUNIT_ASSERT_EQUAL(0.0, aRange2.getMinX());
51 CPPUNIT_ASSERT_EQUAL(0.0, aRange2.getMinY());
52 CPPUNIT_ASSERT_EQUAL(1.0, aRange2.getMaxX());
53 CPPUNIT_ASSERT_EQUAL(1.0, aRange2.getMaxY());
55 CPPUNIT_ASSERT_EQUAL(1.0, aRange2.getWidth());
56 CPPUNIT_ASSERT_EQUAL(1.0, aRange2.getHeight());
59 void testRound()
61 basegfx::B2DRange aRange(1.2, 2.3, 3.5, 4.8);
62 CPPUNIT_ASSERT_EQUAL_MESSAGE("simple range rounding from double to integer",
63 basegfx::B2IRange(1, 2, 4, 5), fround(aRange));
66 void testCenter()
68 basegfx::B2DRange aRange(1.0, 2.0, 2.0, 3.0);
69 CPPUNIT_ASSERT_EQUAL(1.5, aRange.getCenterX());
70 CPPUNIT_ASSERT_EQUAL(2.5, aRange.getCenterY());
73 void testIntersect()
75 basegfx::B2DRange aRange(1.0, 1.0, 4.0, 4.0);
76 aRange.intersect(basegfx::B2DRange(0.0, 0.0, 2.0, 2.0));
78 CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(1.0, 1.0, 2.0, 2.0), aRange);
81 CPPUNIT_TEST_SUITE(B2DRangeTest);
82 CPPUNIT_TEST(testCreation);
83 CPPUNIT_TEST(testRound);
84 CPPUNIT_TEST(testCenter);
85 CPPUNIT_TEST(testIntersect);
86 CPPUNIT_TEST_SUITE_END();
89 CPPUNIT_TEST_SUITE_REGISTRATION(B2DRangeTest);
91 CPPUNIT_PLUGIN_IMPLEMENT();
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */