summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2013-01-10 09:37:14 +0200
committerLuboš Luňák <l.lunak@suse.cz>2013-01-18 17:19:30 +0100
commit2b31e751db38e7ba0e2ec668520f50daf5eb25d5 (patch)
tree9f93c9eed71330e8fd2e6bfb234f0da340e3aeaf
parent6f6ed9c7e2212e5e7acb2c5b827e4e4f1e156ecd (diff)
Create OUString and OString number(*) methods.
API CHANGE: Adds new methods (several overloads) OString::number() OUString::number() and marks all of the existing fromValue() methods as deprecated. The purpose of this change is to clean up call sites by hiding the necessary casts. The casts are necessary because of overload resolution rules which are somewhat vague about which methods to choose when using integer types. See mailing list discussion here: http://nabble.documentfoundation.org/replacing-OUString-valueOf-static-cast-lt-sal-Int32-gt-td4027989.html Subject: "replacing OUString::valueOf(static_cast<sal_Int32>) ??" Change-Id: Id3d150a6525eb0334e41e2ec6640bb06cd790b43 Reviewed-on: https://gerrit.libreoffice.org/1625 Reviewed-by: Luboš Luňák <l.lunak@suse.cz> Tested-by: Luboš Luňák <l.lunak@suse.cz>
-rw-r--r--sal/CppunitTest_sal_rtl_strings.mk1
-rw-r--r--sal/inc/rtl/string.hxx138
-rw-r--r--sal/inc/rtl/ustring.hxx138
-rw-r--r--sal/qa/rtl/strings/test_strings_valuex.cxx117
4 files changed, 382 insertions, 12 deletions
diff --git a/sal/CppunitTest_sal_rtl_strings.mk b/sal/CppunitTest_sal_rtl_strings.mk
index a30bf70d30eb..222cedf17f49 100644
--- a/sal/CppunitTest_sal_rtl_strings.mk
+++ b/sal/CppunitTest_sal_rtl_strings.mk
@@ -38,6 +38,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_rtl_strings,\
38 sal/qa/rtl/strings/test_oustring_noadditional \ 38 sal/qa/rtl/strings/test_oustring_noadditional \
39 sal/qa/rtl/strings/test_oustring_startswith \ 39 sal/qa/rtl/strings/test_oustring_startswith \
40 sal/qa/rtl/strings/test_oustring_stringliterals \ 40 sal/qa/rtl/strings/test_oustring_stringliterals \
41 sal/qa/rtl/strings/test_strings_valuex \
41)) 42))
42 43
43$(eval $(call gb_CppunitTest_use_libraries,sal_rtl_strings,\ 44$(eval $(call gb_CppunitTest_use_libraries,sal_rtl_strings,\
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 8e33973729d7..325fe28af239 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -1399,8 +1399,9 @@ public:
1399 1399
1400 @param b a sal_Bool. 1400 @param b a sal_Bool.
1401 @return a string with the string representation of the argument. 1401 @return a string with the string representation of the argument.
1402 @deprecated there is no replacement, just code your own
1402 */ 1403 */
1403 static OString valueOf( sal_Bool b ) SAL_THROW(()) 1404 SAL_DEPRECATED_INTERNAL("just code your own") static OString valueOf( sal_Bool b ) SAL_THROW(())
1404 { 1405 {
1405 sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN]; 1406 sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
1406 rtl_String* pNewData = 0; 1407 rtl_String* pNewData = 0;
@@ -1413,8 +1414,9 @@ public:
1413 1414
1414 @param c a character. 1415 @param c a character.
1415 @return a string with the string representation of the argument. 1416 @return a string with the string representation of the argument.
1417 @deprecated just use the "+" or "+=" operator
1416 */ 1418 */
1417 static OString valueOf( sal_Char c ) SAL_THROW(()) 1419 SAL_DEPRECATED_INTERNAL("use the + or += operator") static OString valueOf( sal_Char c ) SAL_THROW(())
1418 { 1420 {
1419 return OString( &c, 1 ); 1421 return OString( &c, 1 );
1420 } 1422 }
@@ -1427,8 +1429,9 @@ public:
1427 @param i a int32. 1429 @param i a int32.
1428 @param radix the radix (between 2 and 36) 1430 @param radix the radix (between 2 and 36)
1429 @return a string with the string representation of the argument. 1431 @return a string with the string representation of the argument.
1432 @deprecated use number(sal_Int64,sal_Int16)
1430 */ 1433 */
1431 static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(()) 1434 SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
1432 { 1435 {
1433 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32]; 1436 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32];
1434 rtl_String* pNewData = 0; 1437 rtl_String* pNewData = 0;
@@ -1437,15 +1440,67 @@ public:
1437 } 1440 }
1438 1441
1439 /** 1442 /**
1443 Returns the string representation of the int argument.
1444
1445 This function can't be used for language specific conversion.
1446
1447 @param i a int32.
1448 @param radix the radix (between 2 and 36)
1449 @return a string with the string representation of the argument.
1450 */
1451 static OString number( int i, sal_Int16 radix = 10 )
1452 {
1453 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32];
1454 rtl_String* pNewData = 0;
1455 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt32( aBuf, i, radix ) );
1456 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1457 }
1458
1459 /**
1460 Returns the string representation of the int argument.
1461
1462 This function can't be used for language specific conversion.
1463
1464 @param i a int32.
1465 @param radix the radix (between 2 and 36)
1466 @return a string with the string representation of the argument.
1467 */
1468 static OString number( unsigned int i, sal_Int16 radix = 10 )
1469 {
1470 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
1471 rtl_String* pNewData = 0;
1472 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, i, radix ) );
1473 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1474 }
1475
1476 /**
1477 Returns the string representation of the long argument.
1478
1479 This function can't be used for language specific conversion.
1480
1481 @param ll a int64.
1482 @param radix the radix (between 2 and 36)
1483 @return a string with the string representation of the argument.
1484 @deprecated use number(sal_Int64,sal_Int16)
1485 */
1486 SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
1487 {
1488 return number( ll, radix );
1489 }
1490
1491 /**
1440 Returns the string representation of the long argument. 1492 Returns the string representation of the long argument.
1493 This is here because when choosing which conversion for overloaded
1494 functions is better, the standard treats all integer conversions the same.
1441 1495
1442 This function can't be used for language specific conversion. 1496 This function can't be used for language specific conversion.
1443 1497
1444 @param ll a int64. 1498 @param ll a int64.
1445 @param radix the radix (between 2 and 36) 1499 @param radix the radix (between 2 and 36)
1446 @return a string with the string representation of the argument. 1500 @return a string with the string representation of the argument.
1501 @since LibreOffice 4.1
1447 */ 1502 */
1448 static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(()) 1503 static OString number( long ll, sal_Int16 radix = 10 )
1449 { 1504 {
1450 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64]; 1505 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
1451 rtl_String* pNewData = 0; 1506 rtl_String* pNewData = 0;
@@ -1454,14 +1509,70 @@ public:
1454 } 1509 }
1455 1510
1456 /** 1511 /**
1512 Returns the string representation of the long argument.
1513 This is here because when choosing which conversion for overloaded
1514 functions is better, the standard treats all integer conversions the same.
1515
1516 This function can't be used for language specific conversion.
1517
1518 @param ll a int64.
1519 @param radix the radix (between 2 and 36)
1520 @return a string with the string representation of the argument.
1521 @since LibreOffice 4.1
1522 */
1523 static OString number( unsigned long ll, sal_Int16 radix = 10 )
1524 {
1525 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
1526 rtl_String* pNewData = 0;
1527 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
1528 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1529 }
1530
1531 /// @overload
1532 /// @since LibreOffice 4.1
1533 static OString number( long long ll, sal_Int16 radix = 10 )
1534 {
1535 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
1536 rtl_String* pNewData = 0;
1537 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
1538 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1539 }
1540
1541 /// @overload
1542 /// @since LibreOffice 4.1
1543 static OString number( unsigned long long ll, sal_Int16 radix = 10 )
1544 {
1545 assert( ll <= SAL_MAX_INT64 ); // valueOfInt64 may not be able to handle the highest bit
1546 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
1547 rtl_String* pNewData = 0;
1548 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
1549 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1550 }
1551
1552 /**
1553 Returns the string representation of the float argument.
1554
1555 This function can't be used for language specific conversion.
1556
1557 @param f a float.
1558 @return a string with the string representation of the argument.
1559 @deprecated use number(float)
1560 */
1561 SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( float f ) SAL_THROW(())
1562 {
1563 return number(f);
1564 }
1565
1566 /**
1457 Returns the string representation of the float argument. 1567 Returns the string representation of the float argument.
1458 1568
1459 This function can't be used for language specific conversion. 1569 This function can't be used for language specific conversion.
1460 1570
1461 @param f a float. 1571 @param f a float.
1462 @return a string with the string representation of the argument. 1572 @return a string with the string representation of the argument.
1573 @since LibreOffice 4.1
1463 */ 1574 */
1464 static OString valueOf( float f ) SAL_THROW(()) 1575 static OString number( float f )
1465 { 1576 {
1466 sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT]; 1577 sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
1467 rtl_String* pNewData = 0; 1578 rtl_String* pNewData = 0;
@@ -1476,8 +1587,23 @@ public:
1476 1587
1477 @param d a double. 1588 @param d a double.
1478 @return a string with the string representation of the argument. 1589 @return a string with the string representation of the argument.
1590 @deprecated use number(double)
1591 */
1592 SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( double d ) SAL_THROW(())
1593 {
1594 return number(d);
1595 }
1596
1597 /**
1598 Returns the string representation of the double argument.
1599
1600 This function can't be used for language specific conversion.
1601
1602 @param d a double.
1603 @return a string with the string representation of the argument.
1604 @since LibreOffice 4.1
1479 */ 1605 */
1480 static OString valueOf( double d ) SAL_THROW(()) 1606 static OString number( double d )
1481 { 1607 {
1482 sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE]; 1608 sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
1483 rtl_String* pNewData = 0; 1609 rtl_String* pNewData = 0;
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index c9fe25ec6131..c87978f4b067 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -2033,8 +2033,9 @@ public:
2033 2033
2034 @param b a sal_Bool. 2034 @param b a sal_Bool.
2035 @return a string with the string representation of the argument. 2035 @return a string with the string representation of the argument.
2036 @deprecated there is no replacement, just code your own
2036 */ 2037 */
2037 static OUString valueOf( sal_Bool b ) SAL_THROW(()) 2038 SAL_DEPRECATED_INTERNAL("just code your own") static OUString valueOf( sal_Bool b ) SAL_THROW(())
2038 { 2039 {
2039 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN]; 2040 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
2040 rtl_uString* pNewData = 0; 2041 rtl_uString* pNewData = 0;
@@ -2047,8 +2048,9 @@ public:
2047 2048
2048 @param c a character. 2049 @param c a character.
2049 @return a string with the string representation of the argument. 2050 @return a string with the string representation of the argument.
2051 @deprecated just use the '+' or '+'; operator
2050 */ 2052 */
2051 static OUString valueOf( sal_Unicode c ) SAL_THROW(()) 2053 SAL_DEPRECATED_INTERNAL("just use the '+' or '+'; operator") static OUString valueOf( sal_Unicode c ) SAL_THROW(())
2052 { 2054 {
2053 return OUString( &c, 1 ); 2055 return OUString( &c, 1 );
2054 } 2056 }
@@ -2061,8 +2063,9 @@ public:
2061 @param i a int32. 2063 @param i a int32.
2062 @param radix the radix (between 2 and 36) 2064 @param radix the radix (between 2 and 36)
2063 @return a string with the string representation of the argument. 2065 @return a string with the string representation of the argument.
2066 @deprecated use number(sal_Int64,sal_Int16)
2064 */ 2067 */
2065 static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(()) 2068 SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
2066 { 2069 {
2067 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32]; 2070 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
2068 rtl_uString* pNewData = 0; 2071 rtl_uString* pNewData = 0;
@@ -2071,6 +2074,40 @@ public:
2071 } 2074 }
2072 2075
2073 /** 2076 /**
2077 Returns the string representation of the int argument.
2078
2079 This function can't be used for language specific conversion.
2080
2081 @param i a int32.
2082 @param radix the radix (between 2 and 36)
2083 @return a string with the string representation of the argument.
2084 */
2085 static OUString number( int i, sal_Int16 radix = 10 )
2086 {
2087 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
2088 rtl_uString* pNewData = 0;
2089 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
2090 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
2091 }
2092
2093 /**
2094 Returns the string representation of the int argument.
2095
2096 This function can't be used for language specific conversion.
2097
2098 @param i a int32.
2099 @param radix the radix (between 2 and 36)
2100 @return a string with the string representation of the argument.
2101 */
2102 static OUString number( unsigned int i, sal_Int16 radix = 10 )
2103 {
2104 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
2105 rtl_uString* pNewData = 0;
2106 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, i, radix ) );
2107 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
2108 }
2109
2110 /**
2074 Returns the string representation of the long argument. 2111 Returns the string representation of the long argument.
2075 2112
2076 This function can't be used for language specific conversion. 2113 This function can't be used for language specific conversion.
@@ -2078,8 +2115,26 @@ public:
2078 @param ll a int64. 2115 @param ll a int64.
2079 @param radix the radix (between 2 and 36) 2116 @param radix the radix (between 2 and 36)
2080 @return a string with the string representation of the argument. 2117 @return a string with the string representation of the argument.
2118 @deprecated use number(sal_Int64,sal_Int16)
2081 */ 2119 */
2082 static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(()) 2120 SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
2121 {
2122 return number( ll, radix );
2123 }
2124
2125 /**
2126 Returns the string representation of the long argument.
2127 This is here because when choosing which conversion for overloaded
2128 functions is better, the standard treats all integer conversions the same.
2129
2130 This function can't be used for language specific conversion.
2131
2132 @param ll a int64.
2133 @param radix the radix (between 2 and 36)
2134 @return a string with the string representation of the argument.
2135 @since LibreOffice 4.1
2136 */
2137 static OUString number( long ll, sal_Int16 radix = 10)
2083 { 2138 {
2084 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64]; 2139 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
2085 rtl_uString* pNewData = 0; 2140 rtl_uString* pNewData = 0;
@@ -2088,14 +2143,70 @@ public:
2088 } 2143 }
2089 2144
2090 /** 2145 /**
2146 Returns the string representation of the long argument.
2147 This is here because when choosing which conversion for overloaded
2148 functions is better, the standard treats all integer conversions the same.
2149
2150 This function can't be used for language specific conversion.
2151
2152 @param ll a int64.
2153 @param radix the radix (between 2 and 36)
2154 @return a string with the string representation of the argument.
2155 @since LibreOffice 4.1
2156 */
2157 static OUString number( unsigned long ll, sal_Int16 radix = 10 )
2158 {
2159 sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
2160 rtl_uString* pNewData = 0;
2161 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
2162 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
2163 }
2164
2165 /// @overload
2166 /// @since LibreOffice 4.1
2167 static OUString number( long long ll, sal_Int16 radix = 10 )
2168 {
2169 sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
2170 rtl_uString* pNewData = 0;
2171 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
2172 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
2173 }
2174
2175 /// @overload
2176 /// @since LibreOffice 4.1
2177 static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
2178 {
2179 assert( ll <= SAL_MAX_INT64 ); // valueOfInt64 may not be able to handle the highest bit
2180 sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
2181 rtl_uString* pNewData = 0;
2182 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
2183 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
2184 }
2185
2186 /**
2187 Returns the string representation of the float argument.
2188
2189 This function can't be used for language specific conversion.
2190
2191 @param f a float.
2192 @return a string with the string representation of the argument.
2193 @deprecated use number(float)
2194 */
2195 SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( float f ) SAL_THROW(())
2196 {
2197 return number(f);
2198 }
2199
2200 /**
2091 Returns the string representation of the float argument. 2201 Returns the string representation of the float argument.
2092 2202
2093 This function can't be used for language specific conversion. 2203 This function can't be used for language specific conversion.
2094 2204
2095 @param f a float. 2205 @param f a float.
2096 @return a string with the string representation of the argument. 2206 @return a string with the string representation of the argument.
2207 @since LibreOffice 4.1
2097 */ 2208 */
2098 static OUString valueOf( float f ) SAL_THROW(()) 2209 static OUString number( float f )
2099 { 2210 {
2100 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT]; 2211 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
2101 rtl_uString* pNewData = 0; 2212 rtl_uString* pNewData = 0;
@@ -2110,8 +2221,23 @@ public:
2110 2221
2111 @param d a double. 2222 @param d a double.
2112 @return a string with the string representation of the argument. 2223 @return a string with the string representation of the argument.
2224 @deprecated use number(double)
2225 */
2226 SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( double d ) SAL_THROW(())
2227 {
2228 return number(d);
2229 }
2230
2231 /**
2232 Returns the string representation of the double argument.
2233
2234 This function can't be used for language specific conversion.
2235
2236 @param d a double.
2237 @return a string with the string representation of the argument.
2238 @since LibreOffice 4.1
2113 */ 2239 */
2114 static OUString valueOf( double d ) SAL_THROW(()) 2240 static OUString number( double d )
2115 { 2241 {
2116 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE]; 2242 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
2117 rtl_uString* pNewData = 0; 2243 rtl_uString* pNewData = 0;
diff --git a/sal/qa/rtl/strings/test_strings_valuex.cxx b/sal/qa/rtl/strings/test_strings_valuex.cxx
new file mode 100644
index 000000000000..d350b0fb401f
--- /dev/null
+++ b/sal/qa/rtl/strings/test_strings_valuex.cxx
@@ -0,0 +1,117 @@
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#include <iostream>
15
16namespace test { namespace strings {
17
18class valueX : public CppUnit::TestFixture {
19public:
20 void testOUInt();
21 void testOInt();
22 void testOUFloat();
23 void testOFloat();
24 void testOUDouble();
25 void testODouble();
26
27 CPPUNIT_TEST_SUITE(valueX);
28 CPPUNIT_TEST(testOUInt);
29 CPPUNIT_TEST(testOInt);
30 CPPUNIT_TEST(testOUFloat);
31 CPPUNIT_TEST(testOFloat);
32 CPPUNIT_TEST(testOUDouble);
33 CPPUNIT_TEST(testODouble);
34 CPPUNIT_TEST_SUITE_END();
35};
36
37} }
38
39CPPUNIT_TEST_SUITE_REGISTRATION(test::strings::valueX);
40
41template< typename T >
42void testInt() {
43 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( 30039062 ));
44
45 // test the overloading resolution
46
47 CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< signed char >( 30 )));
48 CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< unsigned char >( 30 )));
49 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< short >( 30039 )));
50 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< unsigned short >( 30039 )));
51 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< int >( 30039062 )));
52 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned int >( 30039062 )));
53 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< long >( 30039062 )));
54 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned long >( 30039062 )));
55 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< long long >( 30039062 )));
56 // The highest bit set in unsigned long long may not actually work.
57 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned long long >( 30039062 )));
58
59 CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< sal_Int8 >( 30 )));
60 CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< sal_uInt8 >( 30 )));
61 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< sal_Int16 >( 30039 )));
62 CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< sal_uInt16 >( 30039 )));
63 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_Int32 >( 30039062 )));
64 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_uInt32 >( 30039062 )));
65 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_Int64 >( 30039062 )));
66 CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_uInt64 >( 30039062 )));
67
68 // The implementation internally uses sal_Int64 etc. types, so check ranges.
69 assert( sizeof( int ) <= sizeof( sal_Int32 ));
70 assert( sizeof( long ) <= sizeof( sal_Int64 ));
71 assert( sizeof( long long ) <= sizeof( sal_Int64 ));
72 assert( sizeof( unsigned int ) < sizeof( sal_Int64 ));
73 assert( sizeof( unsigned long ) < sizeof( sal_Int64 ));
74}
75
76void test::strings::valueX::testOUInt() {
77 testInt<rtl::OUString>();
78}
79
80void test::strings::valueX::testOInt() {
81 testInt<rtl::OString>();
82}
83
84template< typename T >
85void testFloat() {
86 T val1 = T::valueOf( 30039062.0f );
87 T val2 = T::number( 30039062.0f );
88 CPPUNIT_ASSERT_EQUAL( val1, val2 );
89
90 CPPUNIT_ASSERT_EQUAL( T( "39062.2" ), T::number( 39062.2f ));
91}
92
93void test::strings::valueX::testOUFloat() {
94 testFloat<rtl::OUString>();
95}
96
97void test::strings::valueX::testOFloat() {
98 testFloat<rtl::OString>();
99}
100
101template< typename T >
102void testDouble() {
103 T val1 = T::valueOf( 30039062.0 );
104 T val2 = T::number( 30039062.0 );
105 CPPUNIT_ASSERT_EQUAL( val1, val2 );
106
107 CPPUNIT_ASSERT_EQUAL( T( "30039062.2" ), T::number( 30039062.2 ));
108}
109
110void test::strings::valueX::testOUDouble() {
111 testDouble<rtl::OUString>();
112}
113
114void test::strings::valueX::testODouble() {
115 testDouble<rtl::OString>();
116}
117/* vim:set shiftwidth=4 softtabstop=4 expandtab: */