From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- chart2/qa/unit/common_functor_test.cxx | 90 ++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 chart2/qa/unit/common_functor_test.cxx (limited to 'chart2/qa/unit/common_functor_test.cxx') diff --git a/chart2/qa/unit/common_functor_test.cxx b/chart2/qa/unit/common_functor_test.cxx new file mode 100644 index 000000000..eaa5a29fc --- /dev/null +++ b/chart2/qa/unit/common_functor_test.cxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + + +class CommonFunctorsTest : public CppUnit::TestFixture +{ +public: + CPPUNIT_TEST_SUITE(CommonFunctorsTest); + CPPUNIT_TEST(testAnyToString); + CPPUNIT_TEST(testDoubleToString); + CPPUNIT_TEST_SUITE_END(); + + void testAnyToString(); + void testDoubleToString(); + +private: +}; + +void CommonFunctorsTest::testAnyToString() +{ + std::vector aInput; + aInput.emplace_back(2.0); + aInput.emplace_back(10.0); + aInput.emplace_back(12.0); + aInput.emplace_back(15.0); + aInput.emplace_back(25.234); + aInput.emplace_back(123.456); + aInput.emplace_back(0.123450); + + std::vector aOutput; + std::transform(aInput.begin(), aInput.end(), + std::back_inserter(aOutput), chart::CommonFunctors::AnyToString()); + + CPPUNIT_ASSERT_EQUAL(OUString("2"), aOutput[0]); + CPPUNIT_ASSERT_EQUAL(OUString("10"), aOutput[1]); + CPPUNIT_ASSERT_EQUAL(OUString("12"), aOutput[2]); + CPPUNIT_ASSERT_EQUAL(OUString("15"), aOutput[3]); + CPPUNIT_ASSERT_EQUAL(OUString("25.234"), aOutput[4]); + CPPUNIT_ASSERT_EQUAL(OUString("123.456"), aOutput[5]); + CPPUNIT_ASSERT_EQUAL(OUString("0.12345"), aOutput[6]); +} + +void CommonFunctorsTest::testDoubleToString() +{ + std::vector aInput; + aInput.push_back(2.0); + aInput.push_back(10.0); + aInput.push_back(12.0); + aInput.push_back(15.0); + aInput.push_back(25.234); + aInput.push_back(123.456); + aInput.push_back(0.123450); + + std::vector aOutput; + std::transform(aInput.begin(), aInput.end(), + std::back_inserter(aOutput), chart::CommonFunctors::DoubleToOUString()); + + CPPUNIT_ASSERT_EQUAL(OUString("2"), aOutput[0]); + CPPUNIT_ASSERT_EQUAL(OUString("10"), aOutput[1]); + CPPUNIT_ASSERT_EQUAL(OUString("12"), aOutput[2]); + CPPUNIT_ASSERT_EQUAL(OUString("15"), aOutput[3]); + CPPUNIT_ASSERT_EQUAL(OUString("25.234"), aOutput[4]); + CPPUNIT_ASSERT_EQUAL(OUString("123.456"), aOutput[5]); + CPPUNIT_ASSERT_EQUAL(OUString("0.12345"), aOutput[6]); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CommonFunctorsTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3