1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #include <cppunit/TestAssert.h>
11 #include <cppunit/TestFixture.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include <cppunit/plugin/TestPlugIn.h>
14 
15 #include <com/sun/star/uno/Any.h>
16 #include <rtl/ustring.hxx>
17 
18 #include <iterator>
19 #include <vector>
20 
21 #include <CommonFunctors.hxx>
22 
23 
24 class CommonFunctorsTest : public CppUnit::TestFixture
25 {
26 public:
27      CPPUNIT_TEST_SUITE(CommonFunctorsTest);
28      CPPUNIT_TEST(testAnyToString);
29      CPPUNIT_TEST(testDoubleToString);
30      CPPUNIT_TEST_SUITE_END();
31 
32      void testAnyToString();
33      void testDoubleToString();
34 
35 private:
36 };
37 
testAnyToString()38 void CommonFunctorsTest::testAnyToString()
39 {
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);
48 
49     std::vector<OUString> aOutput;
50     std::transform(aInput.begin(), aInput.end(),
51             std::back_inserter(aOutput), chart::CommonFunctors::AnyToString());
52 
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]);
60 }
61 
testDoubleToString()62 void CommonFunctorsTest::testDoubleToString()
63 {
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);
72 
73     std::vector<OUString> aOutput;
74     std::transform(aInput.begin(), aInput.end(),
75             std::back_inserter(aOutput), chart::CommonFunctors::DoubleToOUString());
76 
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]);
84 }
85 
86 CPPUNIT_TEST_SUITE_REGISTRATION(CommonFunctorsTest);
87 
88 CPPUNIT_PLUGIN_IMPLEMENT();
89 
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
91