LCOV - code coverage report
Current view: top level - connectivity/qa/connectivity/commontools - FValue_test.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 224 224 100.0 %
Date: 2014-04-11 Functions: 23 24 95.8 %
Legend: Lines: hit not hit

          Line data    Source code
       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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <test/bootstrapfixture.hxx>
      21             : 
      22             : #include "connectivity/FValue.hxx"
      23             : #include <com/sun/star/sdbc/DataType.hpp>
      24             : using namespace ::com::sun::star::sdbc;
      25             : using namespace ::com::sun::star::uno;
      26             : 
      27             : namespace connectivity { namespace commontools {
      28             : 
      29          28 : class FValueTest: public test::BootstrapFixture
      30             : {
      31             : public:
      32          14 :     FValueTest() : test::BootstrapFixture(false, false) {};
      33             : 
      34             :     void test_Bool();
      35             : 
      36             :     void test_Int8();
      37             :     void test_uInt8();
      38             : 
      39             :     void test_Int16();
      40             :     void test_uInt16();
      41             : 
      42             :     void test_Int32();
      43             :     void test_uInt32();
      44             : 
      45             :     void test_Int64();
      46             :     void test_uInt64();
      47             : 
      48             :     void test_float();
      49             :     void test_double();
      50             : 
      51             :     void test_bool_getString();
      52             :     void test_bit_getString();
      53             : 
      54             :     void test_bool_creation();
      55             : 
      56           2 :     CPPUNIT_TEST_SUITE(FValueTest);
      57             : 
      58           1 :     CPPUNIT_TEST(test_Bool);
      59             : 
      60           1 :     CPPUNIT_TEST(test_Int8);
      61           1 :     CPPUNIT_TEST(test_uInt8);
      62             : 
      63           1 :     CPPUNIT_TEST(test_Int16);
      64           1 :     CPPUNIT_TEST(test_uInt16);
      65             : 
      66           1 :     CPPUNIT_TEST(test_Int32);
      67           1 :     CPPUNIT_TEST(test_uInt32);
      68             : 
      69           1 :     CPPUNIT_TEST(test_Int64);
      70           1 :     CPPUNIT_TEST(test_uInt64);
      71             : 
      72           1 :     CPPUNIT_TEST(test_float);
      73           1 :     CPPUNIT_TEST(test_double);
      74             : 
      75           1 :     CPPUNIT_TEST(test_bool_getString);
      76           1 :     CPPUNIT_TEST(test_bit_getString);
      77           1 :     CPPUNIT_TEST(test_bool_creation);
      78           2 :     CPPUNIT_TEST_SUITE_END();
      79             : };
      80             : 
      81           1 : void FValueTest::test_Bool()
      82             : {
      83           1 :     bool src_Bool = true;
      84           1 :     ORowSetValue v(src_Bool);
      85           1 :     bool trg_Bool = v.getBool();
      86             : 
      87           1 :     std::cerr << "src_Bool: " << src_Bool << std::endl;
      88           1 :     std::cerr << "trg_Bool: " << trg_Bool << std::endl;
      89             : 
      90           1 :     CPPUNIT_ASSERT_MESSAGE("bool conversion to ORowSetValue didn't work", src_Bool == trg_Bool);
      91             : 
      92           2 :     Any any_Bool = v.makeAny();
      93           2 :     ORowSetValue t;
      94           1 :     t.fill(any_Bool);
      95           1 :     trg_Bool = t.getBool();
      96             : 
      97           1 :     std::cerr << "trg_Bool: " << trg_Bool << std::endl;
      98             : 
      99           2 :     CPPUNIT_ASSERT_MESSAGE("bool conversion from Any didn't work", src_Bool == trg_Bool);
     100           1 : }
     101             : 
     102           1 : void FValueTest::test_Int8()
     103             : {
     104           1 :     sal_Int8 src_salInt8 = 127;
     105           1 :     ORowSetValue v(src_salInt8);
     106           1 :     sal_Int8 trg_salInt8 = v.getInt8();
     107             : 
     108           1 :     std::cerr << "src_salInt8: " << static_cast<short>(src_salInt8) << std::endl;
     109           1 :     std::cerr << "trg_salInt8: " << static_cast<short>(trg_salInt8) << std::endl;
     110             : 
     111           1 :     CPPUNIT_ASSERT_MESSAGE("sal_Int8 conversion to ORowSetValue didn't work", src_salInt8 == trg_salInt8);
     112             : 
     113           2 :     Any any_Int8 = v.makeAny();
     114           2 :     ORowSetValue t;
     115           1 :     t.fill(any_Int8);
     116           1 :     trg_salInt8 = t.getInt8();
     117             : 
     118           1 :     std::cerr << "trg_salInt8: " << static_cast<short>(trg_salInt8) << std::endl;
     119             : 
     120           2 :     CPPUNIT_ASSERT_MESSAGE("sal_Int8 conversion from Any didn't work", src_salInt8 == trg_salInt8);
     121           1 : }
     122             : 
     123           1 : void FValueTest::test_uInt8()
     124             : {
     125           1 :     sal_uInt8 src_saluInt8 = 255;
     126           1 :     ORowSetValue v(src_saluInt8);
     127           1 :     sal_uInt8 trg_saluInt8 = v.getUInt8();
     128             : 
     129           1 :     std::cerr << "src_saluInt8: " << static_cast<short>(src_saluInt8) << std::endl;
     130           1 :     std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl;
     131             : 
     132           1 :     CPPUNIT_ASSERT_MESSAGE("sal_uInt8 conversion to ORowSetValue didn't work", src_saluInt8 == trg_saluInt8);
     133             : 
     134           2 :     Any any_uInt8 = v.makeAny();
     135           2 :     ORowSetValue t;
     136           1 :     t.fill(any_uInt8);
     137           1 :     trg_saluInt8 = t.getUInt8();
     138             : 
     139           1 :     std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl;
     140             : 
     141           2 :     CPPUNIT_ASSERT_MESSAGE("sal_uInt8 conversion from Any didn't work", src_saluInt8 == trg_saluInt8);
     142           1 : }
     143             : 
     144           1 : void FValueTest::test_Int16()
     145             : {
     146           1 :     sal_Int16 src_salInt16 = -10001;
     147           1 :     ORowSetValue v(src_salInt16);
     148           1 :     sal_Int16 trg_salInt16 = v.getInt16();
     149             : 
     150           1 :     std::cerr << "src_salInt16: " << src_salInt16 << std::endl;
     151           1 :     std::cerr << "trg_salInt16: " << trg_salInt16 << std::endl;
     152             : 
     153           1 :     CPPUNIT_ASSERT_MESSAGE("sal_Int16 conversion to ORowSetValue didn't work", src_salInt16 == trg_salInt16);
     154             : 
     155           2 :     Any any_Int16 = v.makeAny();
     156           2 :     ORowSetValue t;
     157           1 :     t.fill(any_Int16);
     158           1 :     trg_salInt16 = t.getInt16();
     159             : 
     160           2 :     CPPUNIT_ASSERT_MESSAGE("sal_Int16 conversion from Any didn't work", src_salInt16 == trg_salInt16);
     161           1 : }
     162             : 
     163           1 : void FValueTest::test_uInt16()
     164             : {
     165           1 :     sal_uInt16 src_saluInt16 = 10001;
     166           1 :     ORowSetValue v(src_saluInt16);
     167           1 :     sal_uInt16 trg_saluInt16 = v.getUInt16();
     168             : 
     169           1 :     std::cerr << "src_saluInt16: " << src_saluInt16 << std::endl;
     170           1 :     std::cerr << "trg_saluInt16: " << trg_saluInt16 << std::endl;
     171             : 
     172           1 :     CPPUNIT_ASSERT_MESSAGE("sal_uInt16 conversion to ORowSetValue didn't work", src_saluInt16 == trg_saluInt16);
     173             : 
     174           2 :     Any any_uInt16 = v.makeAny();
     175           2 :     ORowSetValue t;
     176           1 :     t.fill(any_uInt16);
     177           1 :     trg_saluInt16 = t.getUInt16();
     178             : 
     179           2 :     CPPUNIT_ASSERT_MESSAGE("sal_uInt16 conversion from Any didn't work", src_saluInt16 == trg_saluInt16);
     180           1 : }
     181             : 
     182           1 : void FValueTest::test_Int32()
     183             : {
     184           1 :     sal_Int32 src_salInt32 = -10000001;
     185           1 :     ORowSetValue v(src_salInt32);
     186           1 :     sal_Int32 trg_salInt32 = v.getInt32();
     187             : 
     188           1 :     std::cerr << "src_salInt32: " << src_salInt32 << std::endl;
     189           1 :     std::cerr << "trg_salInt32: " << trg_salInt32 << std::endl;
     190             : 
     191           1 :     CPPUNIT_ASSERT_MESSAGE("sal_Int32 conversion to ORowSetValue didn't work", src_salInt32 == trg_salInt32);
     192             : 
     193           2 :     Any any_Int32 = v.makeAny();
     194           2 :     ORowSetValue t;
     195           1 :     t.fill(any_Int32);
     196           1 :     trg_salInt32 = t.getInt32();
     197             : 
     198           2 :     CPPUNIT_ASSERT_MESSAGE("sal_Int32 conversion from Any didn't work", src_salInt32 == trg_salInt32);
     199           1 : }
     200             : 
     201           1 : void FValueTest::test_uInt32()
     202             : {
     203           1 :     sal_uInt32 src_saluInt32 = 100000001;
     204           1 :     ORowSetValue v(src_saluInt32);
     205           1 :     sal_uInt32 trg_saluInt32 = v.getUInt32();
     206             : 
     207           1 :     std::cerr << "src_saluInt32: " << src_saluInt32 << std::endl;
     208           1 :     std::cerr << "trg_saluInt32: " << trg_saluInt32 << std::endl;
     209             : 
     210           1 :     CPPUNIT_ASSERT_MESSAGE("sal_uInt32 conversion to ORowSetValue didn't work", src_saluInt32 == trg_saluInt32);
     211             : 
     212           2 :     Any any_uInt32 = v.makeAny();
     213           2 :     ORowSetValue t;
     214           1 :     t.fill(any_uInt32);
     215           1 :     trg_saluInt32 = t.getUInt32();
     216             : 
     217           2 :     CPPUNIT_ASSERT_MESSAGE("sal_uInt32 conversion from Any didn't work", src_saluInt32 == trg_saluInt32);
     218           1 : }
     219             : 
     220           1 : void FValueTest::test_Int64()
     221             : {
     222           1 :     sal_Int64 src_salInt64 = -1000000000000000001LL;
     223           1 :     ORowSetValue v(src_salInt64);
     224           1 :     sal_Int64 trg_salInt64 = v.getLong();
     225             : 
     226           1 :     std::cerr << "src_salInt64: " << src_salInt64 << std::endl;
     227           1 :     std::cerr << "trg_salInt64: " << trg_salInt64 << std::endl;
     228             : 
     229           1 :     CPPUNIT_ASSERT_MESSAGE("sal_Int64 conversion to ORowSetValue didn't work", src_salInt64 == trg_salInt64);
     230             : 
     231           2 :     Any any_Int64 = v.makeAny();
     232           2 :     ORowSetValue t;
     233           1 :     t.fill(any_Int64);
     234           1 :     trg_salInt64 = t.getLong();
     235             : 
     236           2 :     CPPUNIT_ASSERT_MESSAGE("sal_Int64 conversion from Any didn't work", src_salInt64 == trg_salInt64);
     237           1 : }
     238             : 
     239           1 : void FValueTest::test_uInt64()
     240             : {
     241           1 :     sal_uInt64 src_saluInt64 = 10000000000000000001ULL;
     242           1 :     ORowSetValue v(src_saluInt64);
     243           1 :     sal_uInt64 trg_saluInt64 = v.getULong();
     244             : 
     245           1 :     std::cerr << "src_saluInt64: " << src_saluInt64 << std::endl;
     246           1 :     std::cerr << "trg_saluInt64: " << trg_saluInt64 << std::endl;
     247             : 
     248           1 :     CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion to ORowSetValue didn't work", src_saluInt64 == trg_saluInt64);
     249             : 
     250           2 :     Any any_uInt64 = v.makeAny();
     251           2 :     ORowSetValue t;
     252           1 :     t.fill(any_uInt64);
     253           1 :     trg_saluInt64 = t.getULong();
     254             : 
     255           2 :     CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion from Any didn't work", src_saluInt64 == trg_saluInt64);
     256           1 : }
     257             : 
     258           1 : void FValueTest::test_float()
     259             : {
     260           1 :     float src_float = 1.234f;
     261           1 :     ORowSetValue v(src_float);
     262           1 :     float trg_float = v.getFloat();
     263             : 
     264           1 :     std::cerr << "src_float: " << src_float << std::endl;
     265           1 :     std::cerr << "trg_float: " << trg_float << std::endl;
     266             : 
     267           1 :     CPPUNIT_ASSERT_MESSAGE("float conversion to ORowSetValue didn't work", src_float == trg_float);
     268             : 
     269           2 :     Any any_float = v.makeAny();
     270           2 :     ORowSetValue t;
     271           1 :     t.fill(any_float);
     272           1 :     trg_float = t.getFloat();
     273             : 
     274           2 :     CPPUNIT_ASSERT_MESSAGE("float conversion from Any didn't work", src_float == trg_float);
     275           1 : }
     276             : 
     277           1 : void FValueTest::test_double()
     278             : {
     279           1 :     double src_double = 1.23456789;
     280           1 :     ORowSetValue v(src_double);
     281           1 :     double trg_double = v.getDouble();
     282             : 
     283           1 :     std::cerr << "src_double: " << src_double << std::endl;
     284           1 :     std::cerr << "trg_double: " << trg_double << std::endl;
     285             : 
     286           1 :     CPPUNIT_ASSERT_MESSAGE("double conversion to ORowSetValue didn't work", src_double == trg_double);
     287             : 
     288           2 :     Any any_double = v.makeAny();
     289           2 :     ORowSetValue t;
     290           1 :     t.fill(any_double);
     291           1 :     trg_double = t.getDouble();
     292             : 
     293           2 :     CPPUNIT_ASSERT_MESSAGE("double conversion from Any didn't work", src_double == trg_double);
     294           1 : }
     295             : 
     296           1 : void FValueTest::test_bool_getString()
     297             : {
     298           1 :     bool src_bool_1 = true;
     299           1 :     ORowSetValue v_1(src_bool_1);
     300           2 :     OUString trg_bool_1 = v_1.getString();
     301             : 
     302           1 :     std::cerr << "src_bool_1: " << src_bool_1 << std::endl;
     303           1 :     std::cerr << "trg_bool_1: " << trg_bool_1 << std::endl;
     304             : 
     305           1 :     CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool to string conversion didn't work", trg_bool_1 == "true");
     306             : 
     307           1 :     bool src_bool_0 = false;
     308           2 :     ORowSetValue v_0(src_bool_0);
     309           2 :     OUString trg_bool_0 = v_0.getString();
     310             : 
     311           1 :     std::cerr << "src_bool_0: " << src_bool_0 << std::endl;
     312           1 :     std::cerr << "trg_bool_0: " << trg_bool_0 << std::endl;
     313             : 
     314           2 :     CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool to string conversion didn't work", trg_bool_0 == "false");
     315           1 : }
     316             : 
     317           1 : void FValueTest::test_bit_getString()
     318             : {
     319           1 :     bool src_bool_1 = true;
     320           1 :     ORowSetValue v_1(src_bool_1);
     321           1 :     v_1.setTypeKind(DataType::BIT);
     322           2 :     OUString trg_bool_1 = v_1.getString();
     323             : 
     324           1 :     std::cerr << "src_bit_1: " << src_bool_1 << std::endl;
     325           1 :     std::cerr << "trg_bit_1: " << trg_bool_1 << std::endl;
     326             : 
     327           1 :     CPPUNIT_ASSERT_MESSAGE("ORowSetValue bit to string conversion didn't work", trg_bool_1 == "1");
     328             : 
     329           1 :     bool src_bool_0 = false;
     330           2 :     ORowSetValue v_0(src_bool_0);
     331           1 :     v_0.setTypeKind(DataType::BIT);
     332           2 :     OUString trg_bool_0 = v_0.getString();
     333             : 
     334           1 :     std::cerr << "src_bit_0: " << src_bool_0 << std::endl;
     335           1 :     std::cerr << "trg_bit_0: " << trg_bool_0 << std::endl;
     336             : 
     337           2 :     CPPUNIT_ASSERT_MESSAGE("ORowSetValue bit to string conversion didn't work", trg_bool_0 == "0");
     338           1 : }
     339             : 
     340           1 : void FValueTest::test_bool_creation()
     341             : {
     342           1 :     OUString s1("1");
     343           2 :     OUString s0("0");
     344           2 :     OUString sTrue("true");
     345           2 :     OUString sTrUe("tRuE");
     346           2 :     OUString sFalse("false");
     347           2 :     ORowSetValue vTrue(true);
     348           2 :     ORowSetValue vFalse(false);
     349             : 
     350             :     {
     351           1 :         ORowSetValue v(s1);
     352           1 :         v.setTypeKind(DataType::BOOLEAN);
     353           1 :         CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vTrue);
     354             :     }
     355             : 
     356             :     {
     357           1 :         ORowSetValue v(s0);
     358           1 :         v.setTypeKind(DataType::BOOLEAN);
     359           1 :         CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vFalse);
     360             :     }
     361             : 
     362             :     {
     363           1 :         ORowSetValue v(sTrue);
     364           1 :         v.setTypeKind(DataType::BOOLEAN);
     365           1 :         CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vTrue);
     366             :     }
     367             : 
     368             :     {
     369           1 :         ORowSetValue v(sTrUe);
     370           1 :         v.setTypeKind(DataType::BOOLEAN);
     371           1 :         CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vTrue);
     372             :     }
     373             : 
     374             :     {
     375           1 :         ORowSetValue v(sFalse);
     376           1 :         v.setTypeKind(DataType::BOOLEAN);
     377           1 :         CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vFalse);
     378             :     }
     379             : 
     380             :     {
     381           1 :         ORowSetValue v(s0);
     382           1 :         v.setTypeKind(DataType::BOOLEAN);
     383           1 :         CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vFalse);
     384           1 :     }
     385             : 
     386           1 : }
     387             : 
     388           1 : CPPUNIT_TEST_SUITE_REGISTRATION(FValueTest);
     389             : 
     390             : }}
     391             : 
     392           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     393             : 
     394             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10