summaryrefslogtreecommitdiff
path: root/sal/qa
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 /sal/qa
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>
Diffstat (limited to 'sal/qa')
-rw-r--r--sal/qa/rtl/strings/test_strings_valuex.cxx117
1 files changed, 117 insertions, 0 deletions
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 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/types.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include "rtl/ustring.hxx"
+#include <iostream>
+
+namespace test { namespace strings {
+
+class valueX : public CppUnit::TestFixture {
+public:
+ void testOUInt();
+ void testOInt();
+ void testOUFloat();
+ void testOFloat();
+ void testOUDouble();
+ void testODouble();
+
+ CPPUNIT_TEST_SUITE(valueX);
+ CPPUNIT_TEST(testOUInt);
+ CPPUNIT_TEST(testOInt);
+ CPPUNIT_TEST(testOUFloat);
+ CPPUNIT_TEST(testOFloat);
+ CPPUNIT_TEST(testOUDouble);
+ CPPUNIT_TEST(testODouble);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+} }
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test::strings::valueX);
+
+template< typename T >
+void testInt() {
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( 30039062 ));
+
+ // test the overloading resolution
+
+ CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< signed char >( 30 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< unsigned char >( 30 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< short >( 30039 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< unsigned short >( 30039 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< int >( 30039062 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned int >( 30039062 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< long >( 30039062 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned long >( 30039062 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< long long >( 30039062 )));
+ // The highest bit set in unsigned long long may not actually work.
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned long long >( 30039062 )));
+
+ CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< sal_Int8 >( 30 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< sal_uInt8 >( 30 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< sal_Int16 >( 30039 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< sal_uInt16 >( 30039 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_Int32 >( 30039062 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_uInt32 >( 30039062 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_Int64 >( 30039062 )));
+ CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_uInt64 >( 30039062 )));
+
+ // The implementation internally uses sal_Int64 etc. types, so check ranges.
+ assert( sizeof( int ) <= sizeof( sal_Int32 ));
+ assert( sizeof( long ) <= sizeof( sal_Int64 ));
+ assert( sizeof( long long ) <= sizeof( sal_Int64 ));
+ assert( sizeof( unsigned int ) < sizeof( sal_Int64 ));
+ assert( sizeof( unsigned long ) < sizeof( sal_Int64 ));
+}
+
+void test::strings::valueX::testOUInt() {
+ testInt<rtl::OUString>();
+}
+
+void test::strings::valueX::testOInt() {
+ testInt<rtl::OString>();
+}
+
+template< typename T >
+void testFloat() {
+ T val1 = T::valueOf( 30039062.0f );
+ T val2 = T::number( 30039062.0f );
+ CPPUNIT_ASSERT_EQUAL( val1, val2 );
+
+ CPPUNIT_ASSERT_EQUAL( T( "39062.2" ), T::number( 39062.2f ));
+}
+
+void test::strings::valueX::testOUFloat() {
+ testFloat<rtl::OUString>();
+}
+
+void test::strings::valueX::testOFloat() {
+ testFloat<rtl::OString>();
+}
+
+template< typename T >
+void testDouble() {
+ T val1 = T::valueOf( 30039062.0 );
+ T val2 = T::number( 30039062.0 );
+ CPPUNIT_ASSERT_EQUAL( val1, val2 );
+
+ CPPUNIT_ASSERT_EQUAL( T( "30039062.2" ), T::number( 30039062.2 ));
+}
+
+void test::strings::valueX::testOUDouble() {
+ testDouble<rtl::OUString>();
+}
+
+void test::strings::valueX::testODouble() {
+ testDouble<rtl::OString>();
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */