1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
21 #include <CommonFunctors.hxx>
24 class CommonFunctorsTest
: public CppUnit::TestFixture
27 CPPUNIT_TEST_SUITE(CommonFunctorsTest
);
28 CPPUNIT_TEST(testAnyToString
);
29 CPPUNIT_TEST(testDoubleToString
);
30 CPPUNIT_TEST_SUITE_END();
32 void testAnyToString();
33 void testDoubleToString();
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
{ 2.0, 10.0, 12.0, 15.0, 25.234, 123.456, 0.123450 };
66 std::vector
<OUString
> aOutput
;
67 std::transform(aInput
.begin(), aInput
.end(),
68 std::back_inserter(aOutput
), chart::CommonFunctors::DoubleToOUString());
70 CPPUNIT_ASSERT_EQUAL(OUString("2"), aOutput
[0]);
71 CPPUNIT_ASSERT_EQUAL(OUString("10"), aOutput
[1]);
72 CPPUNIT_ASSERT_EQUAL(OUString("12"), aOutput
[2]);
73 CPPUNIT_ASSERT_EQUAL(OUString("15"), aOutput
[3]);
74 CPPUNIT_ASSERT_EQUAL(OUString("25.234"), aOutput
[4]);
75 CPPUNIT_ASSERT_EQUAL(OUString("123.456"), aOutput
[5]);
76 CPPUNIT_ASSERT_EQUAL(OUString("0.12345"), aOutput
[6]);
79 CPPUNIT_TEST_SUITE_REGISTRATION(CommonFunctorsTest
);
81 CPPUNIT_PLUGIN_IMPLEMENT();
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */