Line data Source code
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 : #include <algorithm>
10 : #include <com/sun/star/i18n/XOrdinalSuffix.hpp>
11 : #include <com/sun/star/lang/Locale.hpp>
12 : #include <unotest/bootstrapfixturebase.hxx>
13 :
14 : using namespace com::sun::star;
15 :
16 12 : class TestOrdinalSuffix : public test::BootstrapFixtureBase
17 : {
18 : private:
19 : uno::Reference<i18n::XOrdinalSuffix> m_xOrdinal;
20 :
21 : public:
22 : virtual void setUp() SAL_OVERRIDE;
23 : virtual void tearDown() SAL_OVERRIDE;
24 :
25 : void testFrench();
26 : void testEnglish();
27 :
28 4 : CPPUNIT_TEST_SUITE(TestOrdinalSuffix);
29 2 : CPPUNIT_TEST(testFrench);
30 2 : CPPUNIT_TEST(testEnglish);
31 4 : CPPUNIT_TEST_SUITE_END();
32 : };
33 :
34 4 : void TestOrdinalSuffix::setUp()
35 : {
36 4 : BootstrapFixtureBase::setUp();
37 12 : m_xOrdinal = uno::Reference< i18n::XOrdinalSuffix >(m_xSFactory->createInstance(
38 8 : "com.sun.star.i18n.OrdinalSuffix"), uno::UNO_QUERY_THROW);
39 4 : }
40 :
41 4 : void TestOrdinalSuffix::tearDown()
42 : {
43 4 : m_xOrdinal.clear();
44 4 : BootstrapFixtureBase::tearDown();
45 4 : }
46 :
47 2 : void TestOrdinalSuffix::testFrench()
48 : {
49 2 : lang::Locale aLocale("fr", "LU", "");
50 4 : uno::Sequence< OUString > aSuffixes;
51 : OUString *pStart, *pEnd, *pFind;
52 :
53 : //1er
54 2 : aSuffixes = m_xOrdinal->getOrdinalSuffix(1, aLocale);
55 2 : pStart = aSuffixes.begin();
56 2 : pEnd = aSuffixes.end();
57 2 : pFind = std::find(pStart, pEnd, OUString("er"));
58 2 : CPPUNIT_ASSERT(pFind != pEnd);
59 :
60 : //2e, 3e, etc.
61 2 : aSuffixes = m_xOrdinal->getOrdinalSuffix(2, aLocale);
62 2 : pStart = aSuffixes.begin();
63 2 : pEnd = aSuffixes.end();
64 2 : pFind = std::find(pStart, pEnd, OUString("e"));
65 4 : CPPUNIT_ASSERT(pFind != pEnd);
66 2 : }
67 :
68 2 : void TestOrdinalSuffix::testEnglish()
69 : {
70 2 : lang::Locale aLocale("en", "US", "");
71 4 : uno::Sequence< OUString > aSuffixes;
72 : OUString *pStart, *pEnd, *pFind;
73 :
74 : //1st
75 2 : aSuffixes = m_xOrdinal->getOrdinalSuffix(1, aLocale);
76 2 : pStart = aSuffixes.begin();
77 2 : pEnd = aSuffixes.end();
78 2 : pFind = std::find(pStart, pEnd, OUString("st"));
79 2 : CPPUNIT_ASSERT(pFind != pEnd);
80 :
81 : //2nd
82 2 : aSuffixes = m_xOrdinal->getOrdinalSuffix(2, aLocale);
83 2 : pStart = aSuffixes.begin();
84 2 : pEnd = aSuffixes.end();
85 2 : pFind = std::find(pStart, pEnd, OUString("nd"));
86 2 : CPPUNIT_ASSERT(pFind != pEnd);
87 :
88 : //3rd
89 2 : aSuffixes = m_xOrdinal->getOrdinalSuffix(3, aLocale);
90 2 : pStart = aSuffixes.begin();
91 2 : pEnd = aSuffixes.end();
92 2 : pFind = std::find(pStart, pEnd, OUString("rd"));
93 4 : CPPUNIT_ASSERT(pFind != pEnd);
94 2 : }
95 :
96 :
97 2 : CPPUNIT_TEST_SUITE_REGISTRATION( TestOrdinalSuffix );
98 :
99 8 : CPPUNIT_PLUGIN_IMPLEMENT();
100 :
101 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|