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>
15 namespace test::strings
{
17 class valueX
: public CppUnit::TestFixture
{
26 CPPUNIT_TEST_SUITE(valueX
);
27 CPPUNIT_TEST(testOBoolean
);
28 CPPUNIT_TEST(testOUBoolean
);
29 CPPUNIT_TEST(testOUInt
);
30 CPPUNIT_TEST(testOInt
);
31 CPPUNIT_TEST(testOUFloat
);
32 CPPUNIT_TEST(testOFloat
);
33 CPPUNIT_TEST_SUITE_END();
38 CPPUNIT_TEST_SUITE_REGISTRATION(test::strings::valueX
);
42 template< typename T
>
44 CPPUNIT_ASSERT_EQUAL( T( "false" ), T(T::boolean( false )) );
45 CPPUNIT_ASSERT_EQUAL( T( "true" ), T(T::boolean( true )) );
50 void test::strings::valueX::testOBoolean() {
51 testBoolean
<OString
>();
54 void test::strings::valueX::testOUBoolean() {
55 testBoolean
<OUString
>();
58 template< typename T
>
59 static void testInt() {
60 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( 30039062 )));
62 // test the overloading resolution
64 CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< signed char >( 30 ))));
65 CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< unsigned char >( 30 ))));
66 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< short >( 30039 ))));
67 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< unsigned short >( 30039 ))));
68 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< int >( 30039062 ))));
69 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< unsigned int >( 30039062 ))));
70 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< long >( 30039062 ))));
71 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< unsigned long >( 30039062 ))));
72 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< long long >( 30039062 ))));
73 // The highest bit set in unsigned long long may not actually work.
74 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< unsigned long long >( 30039062 ))));
76 CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< sal_Int8
>( 30 ))));
77 CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< sal_uInt8
>( 30 ))));
78 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< sal_Int16
>( 30039 ))));
79 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< sal_uInt16
>( 30039 ))));
80 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_Int32
>( 30039062 ))));
81 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_uInt32
>( 30039062 ))));
82 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_Int64
>( 30039062 ))));
83 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_uInt64
>( 30039062 ))));
85 // The implementation internally uses sal_Int64 etc. types, so check ranges.
86 assert( sizeof( int ) <= sizeof( sal_Int32
));
87 assert( sizeof( long ) <= sizeof( sal_Int64
));
88 assert( sizeof( long long ) <= sizeof( sal_Int64
));
89 assert( sizeof( unsigned int ) < sizeof( sal_Int64
));
92 void test::strings::valueX::testOUInt() {
96 void test::strings::valueX::testOInt() {
100 template< typename T
>
101 static void testFloat() {
102 CPPUNIT_ASSERT_EQUAL( T( "39062.2" ), T( T::number( 39062.2f
)));
103 CPPUNIT_ASSERT_EQUAL( T( "30039062.2" ), T( T::number( 30039062.2 )));
104 // long double not supported
107 void test::strings::valueX::testOUFloat() {
108 testFloat
<OUString
>();
111 void test::strings::valueX::testOFloat() {
112 testFloat
<OString
>();
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */