IGNITE-2223: Tests for Decimal buffers added.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f4ccbe65 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f4ccbe65 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f4ccbe65 Branch: refs/heads/ignite-1786 Commit: f4ccbe65a28756b47e2c182d08d2030880e6ca45 Parents: d454724 Author: isapego <[email protected]> Authored: Tue Jan 12 16:17:57 2016 +0300 Committer: isapego <[email protected]> Committed: Tue Jan 12 16:17:57 2016 +0300 ---------------------------------------------------------------------- .../cpp/odbc/odbc-driver/src/decimal.cpp | 2 +- .../src/application_data_buffer_test.cpp | 85 ++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/f4ccbe65/modules/platforms/cpp/odbc/odbc-driver/src/decimal.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/odbc-driver/src/decimal.cpp b/modules/platforms/cpp/odbc/odbc-driver/src/decimal.cpp index 128fb97..f88534b 100644 --- a/modules/platforms/cpp/odbc/odbc-driver/src/decimal.cpp +++ b/modules/platforms/cpp/odbc/odbc-driver/src/decimal.cpp @@ -61,7 +61,7 @@ namespace ignite Decimal::operator double() const { - double res = 1; + double res = 0; int32_t localScale = GetScale(); http://git-wip-us.apache.org/repos/asf/ignite/blob/f4ccbe65/modules/platforms/cpp/odbc/odbc-test/src/application_data_buffer_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/odbc-test/src/application_data_buffer_test.cpp b/modules/platforms/cpp/odbc/odbc-test/src/application_data_buffer_test.cpp index db1195b..8194dad 100644 --- a/modules/platforms/cpp/odbc/odbc-test/src/application_data_buffer_test.cpp +++ b/modules/platforms/cpp/odbc/odbc-test/src/application_data_buffer_test.cpp @@ -22,10 +22,12 @@ #include <boost/test/unit_test.hpp> #include <ignite/guid.h> +#include <ignite/odbc/decimal.h> #include <ignite/odbc/app/application_data_buffer.h> #define FLOAT_PRECISION 0.0000001f +using namespace ignite; using namespace ignite::odbc::app; using namespace ignite::odbc::type_traits; @@ -244,6 +246,89 @@ BOOST_AUTO_TEST_CASE(TestPutFloatToShort) BOOST_REQUIRE(numBuf == -42); } +BOOST_AUTO_TEST_CASE(TestPutDecimalToDouble) +{ + double numBuf; + int64_t reslen; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_DOUBLE, &numBuf, sizeof(numBuf), &reslen, 0); + + Decimal decimal; + + BOOST_REQUIRE_CLOSE_FRACTION(static_cast<double>(decimal), 0.0, FLOAT_PRECISION); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, 0.0, FLOAT_PRECISION); + + int8_t mag1[] = { 1, 0 }; + + decimal = Decimal(0, mag1, sizeof(mag1)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, 256.0, FLOAT_PRECISION); + + int8_t mag2[] = { 2, 23 }; + + decimal = Decimal(1 | 0x80000000, mag2, sizeof(mag2)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, -53.5, FLOAT_PRECISION); +} + +BOOST_AUTO_TEST_CASE(TestPutDecimalToLong) +{ + long numBuf; + int64_t reslen; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_SIGNED_LONG, &numBuf, sizeof(numBuf), &reslen, 0); + + Decimal decimal; + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(numBuf == 0); + + int8_t mag1[] = { 1, 0 }; + + decimal = Decimal(0, mag1, sizeof(mag1)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(numBuf == 256); + + int8_t mag2[] = { 2, 23 }; + + decimal = Decimal(1 | 0x80000000, mag2, sizeof(mag2)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(numBuf == -53); +} + +BOOST_AUTO_TEST_CASE(TestPutDecimalToString) +{ + char strBuf[64]; + int64_t reslen; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, &strBuf, sizeof(strBuf), &reslen, 0); + + Decimal decimal; + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(std::string(strBuf, reslen) == "0"); + + int8_t mag1[] = { 1, 0 }; + + decimal = Decimal(0, mag1, sizeof(mag1)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(std::string(strBuf, reslen) == "256"); + + int8_t mag2[] = { 2, 23 }; + + decimal = Decimal(1 | 0x80000000, mag2, sizeof(mag2)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(std::string(strBuf, reslen) == "-53.5"); +} + BOOST_AUTO_TEST_CASE(TestGetStringFromLong) { long numBuf = 42;
