diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2013-10-14 17:59:10 +0200 |
---|---|---|
committer | David Ostrovsky <David.Ostrovsky@gmx.de> | 2013-10-20 06:07:48 +0000 |
commit | c92809c028b7591129487b276991d50e6acd3c26 (patch) | |
tree | 40aa56369d882e983b0cd4607532381cfb02f7dd | |
parent | 7c858e7d5353d08c3e5f57a340a5c31e5a498ec1 (diff) |
fdo#68657 bool->string conversion to 1/0, not "true"/"false
This matches what OO.org / older versions of LibreOffice did, and which was inadvertently changed in 2bd856e6
Change-Id: I1d45ea975a096c599a996caafc41e4aa06d35fcd
Reviewed-on: https://gerrit.libreoffice.org/6275
Reviewed-by: David Ostrovsky <David.Ostrovsky@gmx.de>
Tested-by: David Ostrovsky <David.Ostrovsky@gmx.de>
-rw-r--r-- | connectivity/qa/connectivity/commontools/FValue_test.cxx | 24 | ||||
-rw-r--r-- | connectivity/source/commontools/FValue.cxx | 9 |
2 files changed, 32 insertions, 1 deletions
diff --git a/connectivity/qa/connectivity/commontools/FValue_test.cxx b/connectivity/qa/connectivity/commontools/FValue_test.cxx index b460f646ded5..73b8af5f821f 100644 --- a/connectivity/qa/connectivity/commontools/FValue_test.cxx +++ b/connectivity/qa/connectivity/commontools/FValue_test.cxx @@ -46,6 +46,8 @@ public: void test_float(); void test_double(); + void test_getString(); + CPPUNIT_TEST_SUITE(FValueTest); CPPUNIT_TEST(test_Bool); @@ -65,6 +67,7 @@ public: CPPUNIT_TEST(test_float); CPPUNIT_TEST(test_double); + CPPUNIT_TEST(test_getString); CPPUNIT_TEST_SUITE_END(); }; @@ -283,6 +286,27 @@ void FValueTest::test_double() CPPUNIT_ASSERT_MESSAGE("double conversion from Any didn't work", src_double == trg_double); } +void FValueTest::test_getString() +{ + bool src_bool_1 = true; + ORowSetValue v_1(src_bool_1); + OUString trg_bool_1 = v_1.getString(); + + std::cerr << "src_bool_1" << src_bool_1 << std::endl; + std::cerr << "trg_bool_1: " << trg_bool_1 << std::endl; + + CPPUNIT_ASSERT_MESSAGE("bool to string conversion to ORowSetValue didn't work", trg_bool_1 == "1"); + + bool src_bool_0 = false; + ORowSetValue v_0(src_bool_0); + OUString trg_bool_0 = v_0.getString(); + + std::cerr << "src_bool_0" << src_bool_0 << std::endl; + std::cerr << "trg_bool_0: " << trg_bool_0 << std::endl; + + CPPUNIT_ASSERT_MESSAGE("bool to string conversion to ORowSetValue didn't work", trg_bool_0 == "0"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(FValueTest); }} diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx index 770b34ea43c9..0dd208ca1cc0 100644 --- a/connectivity/source/commontools/FValue.cxx +++ b/connectivity/source/commontools/FValue.cxx @@ -27,6 +27,8 @@ #include <com/sun/star/io/XInputStream.hpp> #include <rtl/ustrbuf.hxx> #include <rtl/logfile.hxx> +#include <boost/type_traits.hpp> +#include <boost/static_assert.hpp> using namespace ::dbtools; using namespace ::com::sun::star::sdbc; @@ -1007,7 +1009,12 @@ OUString ORowSetValue::getString( ) const break; case DataType::BIT: case DataType::BOOLEAN: - aRet = OUString::boolean(static_cast<bool>(*this)); + // This would be the natural choice, + // but historically it was converted to "0" or "1". + // For backwards compatibility, continue doing that. + // aRet = OUString::boolean(static_cast<bool>(*this)); + BOOST_STATIC_ASSERT((boost::is_same< sal_Bool, sal_uInt8 >::value)); + aRet = OUString::number(static_cast<sal_Bool>(*this)); break; case DataType::TINYINT: case DataType::SMALLINT: |