crashtesting: use after free
[LibreOffice.git] / basegfx / test / B1DRangeTest.cxx
blob7cc906b7d83e0479b64968faa5037396df7b4cad
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/range/b1drange.hxx>
26 namespace basegfx
28 class B1DRangeTest : public CppUnit::TestFixture
30 public:
31 void checkIntervalAxioms()
33 // test interval axioms
34 // (http://en.wikipedia.org/wiki/Interval_%28mathematics%29)
35 B1DRange aRange;
36 CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aRange.isEmpty());
37 CPPUNIT_ASSERT_EQUAL_MESSAGE("center - get cop-out value since range is empty", 0.0,
38 aRange.getCenter());
40 // degenerate interval
41 aRange.expand(1);
42 CPPUNIT_ASSERT_EQUAL(B1DRange(1.0, 1.0), aRange);
43 CPPUNIT_ASSERT_MESSAGE("degenerate range - still, not empty!", !aRange.isEmpty());
44 CPPUNIT_ASSERT_EQUAL_MESSAGE("degenerate range - size of 0", 0.0, aRange.getRange());
45 CPPUNIT_ASSERT_MESSAGE("same value as degenerate range - is inside range",
46 aRange.isInside(1.0));
47 CPPUNIT_ASSERT_EQUAL_MESSAGE("center - must be the single range value", 1.0,
48 aRange.getCenter());
50 // proper interval
51 aRange.expand(2.0);
52 CPPUNIT_ASSERT_EQUAL(B1DRange(1.0, 2.0), aRange);
53 CPPUNIT_ASSERT_EQUAL_MESSAGE("proper range - size of 1", 1.0, aRange.getRange());
54 CPPUNIT_ASSERT_MESSAGE("smaller value of range - is inside *closed* range",
55 aRange.isInside(1));
56 CPPUNIT_ASSERT_MESSAGE("larger value of range - is inside *closed* range",
57 aRange.isInside(2));
59 // center for proper interval that works for ints, too
60 aRange.expand(3.0);
61 CPPUNIT_ASSERT_EQUAL(B1DRange(1.0, 3.0), aRange);
62 CPPUNIT_ASSERT_EQUAL_MESSAGE("center - must be half of the range", 2.0, aRange.getCenter());
65 void checkOverlap()
67 B1DRange aRange(1.0, 3.0);
68 B1DRange aRange2(0.0, 1.0);
70 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound",
71 aRange.overlaps(aRange2));
72 CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound, but only barely",
73 !aRange.overlapsMore(aRange2));
75 B1DRange aRange3(0.0, 2.0);
76 CPPUNIT_ASSERT_MESSAGE("range overlapping is fully overlapping now",
77 aRange.overlapsMore(aRange3));
80 void checkIntersect()
82 B1DRange aRange(1.0, 3.0);
83 B1DRange aRange2(3.0, 4.0);
84 aRange.intersect(aRange2);
85 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding empty range!", !aRange.isEmpty());
87 B1DRange aRange3(5.0, 6.0);
88 aRange.intersect(aRange3);
89 CPPUNIT_ASSERT_MESSAGE("range intersection is yielding nonempty range!", aRange.isEmpty());
92 CPPUNIT_TEST_SUITE(B1DRangeTest);
93 CPPUNIT_TEST(checkIntervalAxioms);
94 CPPUNIT_TEST(checkOverlap);
95 CPPUNIT_TEST(checkIntersect);
96 CPPUNIT_TEST_SUITE_END();
99 } // namespace basegfx
101 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::B1DRangeTest);
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */