crashtesting: use after free
[LibreOffice.git] / basegfx / test / basegfxtools.cxx
blob9c6075919333ae8da9769123e06a00e2884b95ce
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/utils/keystoplerp.hxx>
25 #include <basegfx/numeric/ftools.hxx>
27 using namespace ::basegfx;
29 namespace basegfxtools
31 class KeyStopLerpTest : public CppUnit::TestFixture
33 utils::KeyStopLerp maKeyStops;
35 static std::vector<double> getTestVector() { return { 0.1, 0.5, 0.9 }; }
37 public:
38 KeyStopLerpTest()
39 : maKeyStops(getTestVector())
43 void test()
45 double fAlpha;
46 std::ptrdiff_t nIndex;
48 std::tie(nIndex, fAlpha) = maKeyStops.lerp(-1.0);
49 CPPUNIT_ASSERT_EQUAL_MESSAGE("-1.0", std::ptrdiff_t(0), nIndex);
50 CPPUNIT_ASSERT_EQUAL_MESSAGE("-1.0", 0.0, fAlpha);
52 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.1);
53 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.1", std::ptrdiff_t(0), nIndex);
54 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.1", 0.0, fAlpha);
56 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.3);
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.3", std::ptrdiff_t(0), nIndex);
58 CPPUNIT_ASSERT_MESSAGE("0.3", fTools::equal(fAlpha, 0.5));
60 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.5);
61 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.5", std::ptrdiff_t(0), nIndex);
62 CPPUNIT_ASSERT_MESSAGE("0.5", fTools::equal(fAlpha, 1.0));
64 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.51);
65 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex);
66 CPPUNIT_ASSERT_MESSAGE("0.51", fTools::equal(fAlpha, 0.025));
68 std::tie(nIndex, fAlpha) = maKeyStops.lerp(0.9);
69 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex);
70 CPPUNIT_ASSERT_MESSAGE("0.51", fTools::equal(fAlpha, 1.0));
72 std::tie(nIndex, fAlpha) = maKeyStops.lerp(1.0);
73 CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex);
74 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("0.51", 1.0, fAlpha, 1E-12);
77 // Change the following lines only, if you add, remove or rename
78 // member functions of the current class,
79 // because these macros are need by auto register mechanism.
81 CPPUNIT_TEST_SUITE(KeyStopLerpTest);
82 CPPUNIT_TEST(test);
83 CPPUNIT_TEST_SUITE_END();
86 CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::KeyStopLerpTest);
87 } // namespace basegfxtools
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */