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 <sal/types.h>
11 #include <cppunit/TestFixture.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include "rtl/ustring.hxx"
16 namespace test
{ namespace strings
{
18 class valueX
: public CppUnit::TestFixture
{
27 CPPUNIT_TEST_SUITE(valueX
);
28 CPPUNIT_TEST(testOBoolean
);
29 CPPUNIT_TEST(testOUBoolean
);
30 CPPUNIT_TEST(testOUInt
);
31 CPPUNIT_TEST(testOInt
);
32 CPPUNIT_TEST(testOUFloat
);
33 CPPUNIT_TEST(testOFloat
);
34 CPPUNIT_TEST_SUITE_END();
39 CPPUNIT_TEST_SUITE_REGISTRATION(test::strings::valueX
);
43 template< typename T
>
45 CPPUNIT_ASSERT_EQUAL( T( "false" ), T::boolean( false ) );
46 CPPUNIT_ASSERT_EQUAL( T( "false" ), T::boolean( sal_False
) );
47 CPPUNIT_ASSERT_EQUAL( T( "true" ), T::boolean( true ) );
48 CPPUNIT_ASSERT_EQUAL( T( "true" ), T::boolean( sal_True
) );
53 void test::strings::valueX::testOBoolean() {
54 testBoolean
<rtl::OString
>();
57 void test::strings::valueX::testOUBoolean() {
58 testBoolean
<rtl::OUString
>();
61 template< typename T
>
63 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( 30039062 ));
65 // test the overloading resolution
67 CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< signed char >( 30 )));
68 CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< unsigned char >( 30 )));
69 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< short >( 30039 )));
70 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< unsigned short >( 30039 )));
71 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< int >( 30039062 )));
72 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned int >( 30039062 )));
73 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< long >( 30039062 )));
74 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned long >( 30039062 )));
75 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< long long >( 30039062 )));
76 // The highest bit set in unsigned long long may not actually work.
77 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned long long >( 30039062 )));
79 CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< sal_Int8
>( 30 )));
80 CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< sal_uInt8
>( 30 )));
81 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< sal_Int16
>( 30039 )));
82 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< sal_uInt16
>( 30039 )));
83 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_Int32
>( 30039062 )));
84 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_uInt32
>( 30039062 )));
85 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_Int64
>( 30039062 )));
86 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_uInt64
>( 30039062 )));
88 // The implementation internally uses sal_Int64 etc. types, so check ranges.
89 assert( sizeof( int ) <= sizeof( sal_Int32
));
90 assert( sizeof( long ) <= sizeof( sal_Int64
));
91 assert( sizeof( long long ) <= sizeof( sal_Int64
));
92 assert( sizeof( unsigned int ) < sizeof( sal_Int64
));
95 void test::strings::valueX::testOUInt() {
96 testInt
<rtl::OUString
>();
99 void test::strings::valueX::testOInt() {
100 testInt
<rtl::OString
>();
103 template< typename T
>
105 CPPUNIT_ASSERT_EQUAL( T( "39062.2" ), T::number( 39062.2f
));
106 CPPUNIT_ASSERT_EQUAL( T( "30039062.2" ), T::number( 30039062.2 ));
107 // long double not supported
110 void test::strings::valueX::testOUFloat() {
111 testFloat
<rtl::OUString
>();
114 void test::strings::valueX::testOFloat() {
115 testFloat
<rtl::OString
>();
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */