| 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 <sal/types.h> |
| 11 |
#include <cppunit/TestFixture.h> |
| 12 |
#include <cppunit/extensions/HelperMacros.h> |
| 13 |
#include <rtl/ustring.hxx> |
| 14 |
|
| 15 |
namespace test::strings { |
| 16 |
|
| 17 |
class valueX : public CppUnit::TestFixture { |
| 18 |
public: |
| 19 |
void testOBoolean(); |
| 20 |
void testOUBoolean(); |
| 21 |
void testOUInt(); |
| 22 |
void testOInt(); |
| 23 |
void testOUFloat(); |
| 24 |
void testOFloat(); |
| 25 |
|
| 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(); |
| 34 |
}; |
| 35 |
|
| 36 |
} |
| 37 |
|
| 38 |
CPPUNIT_TEST_SUITE_REGISTRATION(test::strings::valueX); |
| 39 |
|
| 40 |
namespace { |
| 41 |
|
| 42 |
template< typename T > |
| 43 |
void testBoolean() { |
| 44 |
CPPUNIT_ASSERT_EQUAL( T( "false" ), T(T::boolean( false )) ); |
| 45 |
CPPUNIT_ASSERT_EQUAL( T( "true" ), T(T::boolean( true )) ); |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
void test::strings::valueX::testOBoolean() { |
| 51 |
testBoolean<OString>(); |
| 52 |
} |
| 53 |
|
| 54 |
void test::strings::valueX::testOUBoolean() { |
| 55 |
testBoolean<OUString>(); |
| 56 |
} |
| 57 |
|
| 58 |
template< typename T > |
| 59 |
static void testInt() { |
| 60 |
CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( 30039062 ))); |
| 61 |
|
| 62 |
// test the overloading resolution |
| 63 |
|
| 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 )))); |
| 75 |
|
| 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 )))); |
| 84 |
|
| 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 )); |
| 90 |
} |
| 91 |
|
| 92 |
void test::strings::valueX::testOUInt() { |
| 93 |
testInt<OUString>(); |
| 94 |
} |
| 95 |
|
| 96 |
void test::strings::valueX::testOInt() { |
| 97 |
testInt<OString>(); |
| 98 |
} |
| 99 |
|
| 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 |
| 105 |
} |
| 106 |
|
| 107 |
void test::strings::valueX::testOUFloat() { |
| 108 |
testFloat<OUString>(); |
| 109 |
} |
| 110 |
|
| 111 |
void test::strings::valueX::testOFloat() { |
| 112 |
testFloat<OString>(); |
| 113 |
} |
| 114 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |