Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / qa / unit / common_functor_test.cxx
blobeaa5a29fc08a86752a6ed81c7347e2fc9e988a8d
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/.
8 */
10 #include <cppunit/TestAssert.h>
11 #include <cppunit/TestFixture.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include <cppunit/plugin/TestPlugIn.h>
15 #include <com/sun/star/uno/Any.h>
16 #include <rtl/ustring.hxx>
18 #include <iterator>
19 #include <vector>
21 #include <CommonFunctors.hxx>
24 class CommonFunctorsTest : public CppUnit::TestFixture
26 public:
27 CPPUNIT_TEST_SUITE(CommonFunctorsTest);
28 CPPUNIT_TEST(testAnyToString);
29 CPPUNIT_TEST(testDoubleToString);
30 CPPUNIT_TEST_SUITE_END();
32 void testAnyToString();
33 void testDoubleToString();
35 private:
38 void CommonFunctorsTest::testAnyToString()
40 std::vector<css::uno::Any> aInput;
41 aInput.emplace_back(2.0);
42 aInput.emplace_back(10.0);
43 aInput.emplace_back(12.0);
44 aInput.emplace_back(15.0);
45 aInput.emplace_back(25.234);
46 aInput.emplace_back(123.456);
47 aInput.emplace_back(0.123450);
49 std::vector<OUString> aOutput;
50 std::transform(aInput.begin(), aInput.end(),
51 std::back_inserter(aOutput), chart::CommonFunctors::AnyToString());
53 CPPUNIT_ASSERT_EQUAL(OUString("2"), aOutput[0]);
54 CPPUNIT_ASSERT_EQUAL(OUString("10"), aOutput[1]);
55 CPPUNIT_ASSERT_EQUAL(OUString("12"), aOutput[2]);
56 CPPUNIT_ASSERT_EQUAL(OUString("15"), aOutput[3]);
57 CPPUNIT_ASSERT_EQUAL(OUString("25.234"), aOutput[4]);
58 CPPUNIT_ASSERT_EQUAL(OUString("123.456"), aOutput[5]);
59 CPPUNIT_ASSERT_EQUAL(OUString("0.12345"), aOutput[6]);
62 void CommonFunctorsTest::testDoubleToString()
64 std::vector<double> aInput;
65 aInput.push_back(2.0);
66 aInput.push_back(10.0);
67 aInput.push_back(12.0);
68 aInput.push_back(15.0);
69 aInput.push_back(25.234);
70 aInput.push_back(123.456);
71 aInput.push_back(0.123450);
73 std::vector<OUString> aOutput;
74 std::transform(aInput.begin(), aInput.end(),
75 std::back_inserter(aOutput), chart::CommonFunctors::DoubleToOUString());
77 CPPUNIT_ASSERT_EQUAL(OUString("2"), aOutput[0]);
78 CPPUNIT_ASSERT_EQUAL(OUString("10"), aOutput[1]);
79 CPPUNIT_ASSERT_EQUAL(OUString("12"), aOutput[2]);
80 CPPUNIT_ASSERT_EQUAL(OUString("15"), aOutput[3]);
81 CPPUNIT_ASSERT_EQUAL(OUString("25.234"), aOutput[4]);
82 CPPUNIT_ASSERT_EQUAL(OUString("123.456"), aOutput[5]);
83 CPPUNIT_ASSERT_EQUAL(OUString("0.12345"), aOutput[6]);
86 CPPUNIT_TEST_SUITE_REGISTRATION(CommonFunctorsTest);
88 CPPUNIT_PLUGIN_IMPLEMENT();
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */