summaryrefslogtreecommitdiff
path: root/connectivity/qa
diff options
context:
space:
mode:
authorDavid Ostrovsky <david@ostrovsky.org>2013-02-04 11:12:57 +0100
committerLionel Elie Mamane <lionel@mamane.lu>2013-02-05 15:46:17 +0100
commit2bd856e643ef526c1283475c19cd355f7ef840f4 (patch)
treed6ff071ff68de3402b35bec4f8fc82d6c3587533 /connectivity/qa
parent5e50b4d6616fa3831b3a7c72969ac81815768f7a (diff)
ORowSetValue: clean up sign/unsigned union member
Also switch BOOLEAN constructor from sal_Bool to bool. old/new signed/unsigned storage situation: ------------------------------------------------------- SQL type | signed | unsigned old | unsigned new ------------------------------------------------------- TINYINT | sal_Int8 | sal_Int16 | sal_uInt8 SMALLINT | sal_Int16 | sal_Int32 | sal_uInt16 INTEGER | sal_Int32 | sal_Int64 | sal_uInt32 BIGINT | sal_Int64 | pValue (String*) | sal_uInt64 ------------------------------------------------------- When sticking an UNSIGNED TINYINT into an Any, silently promote it to UNSIGNED SMALLINT (that is sal_uInt16), else Any would take it as a sal_Bool and normalise to sal_True (1) or sal_False (0). When constructing an ORowSetValue from a sal_Bool, silently keep it as an unsigned 8 bit integer (that is understand it as a sal_uInt8). This will work in most cases, since when asked back for a bool or sal_Bool, we'll give back the right value. Only code looking at the type tag could possibly make a "wrong" decision. The main (hopefully only?) path through which this would happen is through an implementation of XParameters::setBoolean XRowUpdate::updateBoolean that would use its sal_Bool argument to construct an ORowSetValue. So make sure each implementation constructs a proper BOOLEAN so as not to get confused. For authorship/copyright purposes, this patch is a cooperation between Lionel Elie Mamane <lionel@mamane.lu> and David Ostrovsky <david@ostrovsky.org> Change-Id: I3f1f08716127147f077bff4edb6ec558b1b09e09
Diffstat (limited to 'connectivity/qa')
-rw-r--r--connectivity/qa/connectivity/commontools/FValue_test.cxx248
1 files changed, 248 insertions, 0 deletions
diff --git a/connectivity/qa/connectivity/commontools/FValue_test.cxx b/connectivity/qa/connectivity/commontools/FValue_test.cxx
new file mode 100644
index 000000000000..be3024e32c9d
--- /dev/null
+++ b/connectivity/qa/connectivity/commontools/FValue_test.cxx
@@ -0,0 +1,248 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <test/bootstrapfixture.hxx>
+
+#include "connectivity/FValue.hxx"
+using namespace ::com::sun::star::uno;
+
+namespace connectivity { namespace commontools {
+
+class FValueTest: public test::BootstrapFixture
+{
+public:
+ FValueTest() : test::BootstrapFixture(false, false) {};
+
+ void test_Bool();
+
+ void test_Int8();
+ void test_uInt8();
+
+ void test_Int16();
+ void test_uInt16();
+
+ void test_Int32();
+ void test_uInt32();
+
+ void test_Int64();
+ void test_uInt64();
+
+ CPPUNIT_TEST_SUITE(FValueTest);
+
+ CPPUNIT_TEST(test_Bool);
+
+ CPPUNIT_TEST(test_Int8);
+ CPPUNIT_TEST(test_uInt8);
+
+ CPPUNIT_TEST(test_Int16);
+ CPPUNIT_TEST(test_uInt16);
+
+ CPPUNIT_TEST(test_Int32);
+ CPPUNIT_TEST(test_uInt32);
+
+ CPPUNIT_TEST(test_Int64);
+ CPPUNIT_TEST(test_uInt64);
+
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void FValueTest::test_Bool()
+{
+ bool src_Bool = true;
+ ORowSetValue v(src_Bool);
+ bool trg_Bool = v.getBool();
+
+ std::cerr << "src_Bool: " << src_Bool << std::endl;
+ std::cerr << "trg_Bool: " << trg_Bool << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("bool conversion to ORowSetValue didn't work", src_Bool == trg_Bool);
+
+ Any any_Bool = v.makeAny();
+ ORowSetValue t;
+ t.fill(any_Bool);
+ trg_Bool = t.getBool();
+
+ std::cerr << "trg_Bool: " << trg_Bool << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("bool conversion from Any didn't work", src_Bool == trg_Bool);
+}
+
+void FValueTest::test_Int8()
+{
+ sal_Int8 src_salInt8 = 127;
+ ORowSetValue v(src_salInt8);
+ sal_Int8 trg_salInt8 = v.getInt8();
+
+ std::cerr << "src_salInt8: " << static_cast<short>(src_salInt8) << std::endl;
+ std::cerr << "trg_salInt8: " << static_cast<short>(trg_salInt8) << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_Int8 conversion to ORowSetValue didn't work", src_salInt8 == trg_salInt8);
+
+ Any any_Int8 = v.makeAny();
+ ORowSetValue t;
+ t.fill(any_Int8);
+ trg_salInt8 = t.getInt8();
+
+ std::cerr << "trg_salInt8: " << static_cast<short>(trg_salInt8) << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_Int8 conversion from Any didn't work", src_salInt8 == trg_salInt8);
+}
+
+void FValueTest::test_uInt8()
+{
+ sal_uInt8 src_saluInt8 = 255;
+ ORowSetValue v(src_saluInt8);
+ sal_uInt8 trg_saluInt8 = v.getUInt8();
+
+ std::cerr << "src_saluInt8: " << static_cast<short>(src_saluInt8) << std::endl;
+ std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_uInt8 conversion to ORowSetValue didn't work", src_saluInt8 == trg_saluInt8);
+
+ Any any_uInt8 = v.makeAny();
+ ORowSetValue t;
+ t.fill(any_uInt8);
+ trg_saluInt8 = t.getUInt8();
+
+ std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_uInt8 conversion from Any didn't work", src_saluInt8 == trg_saluInt8);
+}
+
+void FValueTest::test_Int16()
+{
+ sal_Int16 src_salInt16 = -10001;
+ ORowSetValue v(src_salInt16);
+ sal_Int16 trg_salInt16 = v.getInt16();
+
+ std::cerr << "src_salInt16: " << src_salInt16 << std::endl;
+ std::cerr << "trg_salInt16: " << trg_salInt16 << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_Int16 conversion to ORowSetValue didn't work", src_salInt16 == trg_salInt16);
+
+ Any any_Int16 = v.makeAny();
+ ORowSetValue t;
+ t.fill(any_Int16);
+ trg_salInt16 = t.getInt16();
+
+ CPPUNIT_ASSERT_MESSAGE("sal_Int16 conversion from Any didn't work", src_salInt16 == trg_salInt16);
+}
+
+void FValueTest::test_uInt16()
+{
+ sal_uInt16 src_saluInt16 = 10001;
+ ORowSetValue v(src_saluInt16);
+ sal_uInt16 trg_saluInt16 = v.getUInt16();
+
+ std::cerr << "src_saluInt16: " << src_saluInt16 << std::endl;
+ std::cerr << "trg_saluInt16: " << trg_saluInt16 << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_uInt16 conversion to ORowSetValue didn't work", src_saluInt16 == trg_saluInt16);
+
+ Any any_uInt16 = v.makeAny();
+ ORowSetValue t;
+ t.fill(any_uInt16);
+ trg_saluInt16 = t.getUInt16();
+
+ CPPUNIT_ASSERT_MESSAGE("sal_uInt16 conversion from Any didn't work", src_saluInt16 == trg_saluInt16);
+}
+
+void FValueTest::test_Int32()
+{
+ sal_Int32 src_salInt32 = -10000001;
+ ORowSetValue v(src_salInt32);
+ sal_Int32 trg_salInt32 = v.getInt32();
+
+ std::cerr << "src_salInt32: " << src_salInt32 << std::endl;
+ std::cerr << "trg_salInt32: " << trg_salInt32 << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_Int32 conversion to ORowSetValue didn't work", src_salInt32 == trg_salInt32);
+
+ Any any_Int32 = v.makeAny();
+ ORowSetValue t;
+ t.fill(any_Int32);
+ trg_salInt32 = t.getInt32();
+
+ CPPUNIT_ASSERT_MESSAGE("sal_Int32 conversion from Any didn't work", src_salInt32 == trg_salInt32);
+}
+
+void FValueTest::test_uInt32()
+{
+ sal_uInt32 src_saluInt32 = 100000001;
+ ORowSetValue v(src_saluInt32);
+ sal_uInt32 trg_saluInt32 = v.getUInt32();
+
+ std::cerr << "src_saluInt32: " << src_saluInt32 << std::endl;
+ std::cerr << "trg_saluInt32: " << trg_saluInt32 << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_uInt32 conversion to ORowSetValue didn't work", src_saluInt32 == trg_saluInt32);
+
+ Any any_uInt32 = v.makeAny();
+ ORowSetValue t;
+ t.fill(any_uInt32);
+ trg_saluInt32 = t.getUInt32();
+
+ CPPUNIT_ASSERT_MESSAGE("sal_uInt32 conversion from Any didn't work", src_saluInt32 == trg_saluInt32);
+}
+
+void FValueTest::test_Int64()
+{
+ sal_Int64 src_salInt64 = -1000000000000000001LL;
+ ORowSetValue v(src_salInt64);
+ sal_Int64 trg_salInt64 = v.getLong();
+
+ std::cerr << "src_salInt64: " << src_salInt64 << std::endl;
+ std::cerr << "trg_salInt64: " << trg_salInt64 << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_Int64 conversion to ORowSetValue didn't work", src_salInt64 == trg_salInt64);
+
+ Any any_Int64 = v.makeAny();
+ ORowSetValue t;
+ t.fill(any_Int64);
+ trg_salInt64 = t.getLong();
+
+ CPPUNIT_ASSERT_MESSAGE("sal_Int64 conversion from Any didn't work", src_salInt64 == trg_salInt64);
+}
+
+void FValueTest::test_uInt64()
+{
+ sal_uInt64 src_saluInt64 = 10000000000000000001ULL;
+ ORowSetValue v(src_saluInt64);
+ sal_uInt64 trg_saluInt64 = v.getULong();
+
+ std::cerr << "src_saluInt64: " << src_saluInt64 << std::endl;
+ std::cerr << "trg_saluInt64: " << trg_saluInt64 << std::endl;
+
+ CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion to ORowSetValue didn't work", src_saluInt64 == trg_saluInt64);
+
+ Any any_uInt64 = v.makeAny();
+ ORowSetValue t;
+ t.fill(any_uInt64);
+ trg_saluInt64 = t.getULong();
+
+ CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion from Any didn't work", src_saluInt64 == trg_saluInt64);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(FValueTest);
+
+}}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */