Date: Tuesday, March 7, 2006 @ 12:29:39
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/BigDecimal.hpp (1.14 -> 1.15) src/BigDecimal.cpp (1.17
-> 1.18) src/DriverResultSet.cpp (1.45 -> 1.46)
test/30-ResultSet/TestBigDecimal.cpp (1.1 -> 1.2)
Enabled/introduced bigdecimal to int, long and int64_t conversion
Added toIntArray that convert a given gmp integer to an array of int
Moved toBigInteger() as protected
Fixed decimal point retrieval to get it from locale
Added/enhanced test on bigdecimal conversions
--------------------------------------+
include/BigDecimal.hpp | 39 +++++--
src/BigDecimal.cpp | 175 ++++++++++++++++++++++-----------
src/DriverResultSet.cpp | 10 -
test/30-ResultSet/TestBigDecimal.cpp | 152 ++++++++++++++++------------
4 files changed, 238 insertions(+), 138 deletions(-)
Index: carob/include/BigDecimal.hpp
diff -u carob/include/BigDecimal.hpp:1.14 carob/include/BigDecimal.hpp:1.15
--- carob/include/BigDecimal.hpp:1.14 Fri Mar 3 18:18:15 2006
+++ carob/include/BigDecimal.hpp Tue Mar 7 12:29:39 2006
@@ -66,10 +66,6 @@
BigDecimal::BigDecimal(const DriverSocket& input)
throw (SocketIOException, UnexpectedException);
/**
- * Converts this BigDecimal to a GMP integer
- */
- mpz_class toBigInteger() const;
- /**
* Convertion to string.
* A leading minus sign is used to indicate sign, and the number of digits to
* the right of the decimal point is used to indicate scale.
@@ -78,19 +74,40 @@
/**
* Convertion to int.
* Any fractional part of this BigDecimal will be discarded, and if the
- * resulting "BigInteger" is too big to fit in an int, only the low-order 32
- * bits are returned
+ * resulting "BigInteger" is too big to fit in an int, throws an exception
+ * @throw ConversionException if the value is to big to be converted
*/
- operator int() const;
+ operator int() const throw (ConversionException);
/**
* Convertion to long.
* Any fractional part of this BigDecimal will be discarded, and if the
- * resulting "BigInteger" is too big to fit in a long, only the low-order
- * 64 bits are returned
+ * resulting "BigInteger" is too big to fit in a long, throws an exception
+ * @throw ConversionException if the value is to big to be converted
+ */
+ operator long() const throw (ConversionException);
+ /**
+ * Convertion to int64_t
+ * Any fractional part of this BigDecimal will be discarded, and if the
+ * resulting "BigInteger" is too big to fit in a int64_t, throws an exception
+ * @throw ConversionException if the value is to big to be converted
*/
- operator long() const;
+ operator int64_t() const throw (ConversionException);
+protected:
+ /**
+ * Converts this BigDecimal's absolute value to a GMP integer by scaling
+ * its unscaled_value (thus discarding fractional part)
+ */
+ mpz_class toBigInteger() const;
+ /**
+ * Converts the given gmp integer to an array of integers.
+ * The integer array will be allocated by this function, and must be deleted
+ * by the caller
+ * @param scaled_val gmp integer to convert (usually the return value of
+ * toBigInteger)
+ * @param intArrayLength size of the returned array
+ */
+ int* toIntArray(mpz_class scaled_val, int* intArrayLength) const;
private:
-
/** Length of the unscaled value java_byte-array */
size_t byteArrayLength;
/**
Index: carob/src/BigDecimal.cpp
diff -u carob/src/BigDecimal.cpp:1.17 carob/src/BigDecimal.cpp:1.18
--- carob/src/BigDecimal.cpp:1.17 Fri Mar 3 18:18:15 2006
+++ carob/src/BigDecimal.cpp Tue Mar 7 12:29:39 2006
@@ -21,9 +21,13 @@
#include "BigDecimal.hpp"
#include "DriverSocket.hpp"
+
+#include "StringCodecs.hpp"
+#include "CarobException.hpp"
#include "Common.hpp"
-#include <iostream> // REMOVE ME !
+#include <locale>
+
#include <sstream> //for wostringstream
using std::wstring;
@@ -107,44 +111,18 @@
sizeof(java_byte), 1 /*MSB 1st*/, 0, byteArray);
unscaled_value = static_cast<mpz_class>(imported);
mpz_clear(imported);
-#if 0
- mpz_t unscaledVal;
- mpz_init(unscaledVal);
- // convert byte array into and unscaled int
- mpz_import(unscaledVal, byteArrayLength, 1 /*MSB 1st*/,
- sizeof(java_byte), 1 /*MSB 1st*/, 0, byteArray);
- // apply scale
- mpz_t scaler; // will be 10^scale
- mpz_init(scaler);
- mpq_t rat_scaler;
- mpq_init(rat_scaler);
- mpz_ui_pow_ui(scaler, 10, scale);
- mpf_init2(gmp_value, mpz_sizeinbase(unscaledVal, 2/*binary*/) + 2); // + 1
for '.'
- mpq_t rat_uv;
- mpq_init(rat_uv);
- mpq_set_z(rat_uv, unscaledVal);
- mpq_set_z(rat_scaler, scaler);
- mpq_div(rat_uv, rat_uv, rat_scaler);
- mpf_set_q(gmp_value, rat_uv);
- // free tmp data
- mpq_clear(rat_uv);
- mpq_clear(rat_scaler);
- mpz_clear(scaler);
- mpz_clear(unscaledVal);
- if (signum < 0)
- {
- mpf_neg(gmp_value, gmp_value);
- }
-#endif
}
+
+ // FIXME TODO: if ODBC/odbsequoia doesn't need the byte array, we should
+ // delete and throw away the byte array now.
}
-/**
- * Converts this BigDecimal to a GMP integer
- */
+
mpz_class BigDecimal::toBigInteger() const
{
if (scale == 0)
return unscaled_value;
+
+ //we have to apply scale
mpz_t scaler; // will be 10^scale
mpz_init(scaler);
mpz_ui_pow_ui(scaler, 10, scale);
@@ -154,6 +132,22 @@
return ret;
}
+int* BigDecimal::toIntArray(mpz_class scaled_int, int* mag_length) const
+{
+ size_t sizeInInts = mpz_size(scaled_int.get_mpz_t()) * sizeof(mp_limb_t)
+ / sizeof(int);
+ int* mag = new int[sizeInInts];
+ size_t exported = 0;
+ mpz_export(static_cast<void*>(mag), &exported,
+ 1,/*big-endian*/
+ sizeof(int), /*words of integers*/
+ 0, /*native word endianess*/
+ 0, /*full words*/
+ scaled_int.get_mpz_t());
+ *mag_length = static_cast<int>(exported);
+ return mag;
+}
+
BigDecimal::operator wstring() const
{
wstring sRet(L"0");
@@ -166,41 +160,106 @@
//Add the '.' TODO: get this separator from locale
if (sRet.length()-scale > 0 && scale != 0)
{
- sRet.insert(sRet.length()-scale, L".");
+ //FIXME: get the current local instead of default
+ wchar_t decimal_point = std::use_facet<std::numpunct<wchar_t>
>(std::locale("")).decimal_point();
+ sRet.insert(sRet.length()-scale, 1, decimal_point);
}
if (signum < 0)
sRet.insert(0, L"-");
+
}
return sRet;
}
-BigDecimal::operator int() const
+BigDecimal::operator int() const throw (ConversionException)
{
- //TODO
-#if 1
- return 0;
-#else
if (signum == 0)
return 0;
- mpz_class bi(toBigInteger());
-//BYTES_PER_MP_LIMB
-// int bytesPerInt = sizeof(int)/8;
-//mpz_export (void *rop, size_t *countp, int order, int size, int endian,
size_t nails, mpz_t op)
-// mpz_import(imported, byteArrayLength, 1 /*MSB 1st*/,
- int ret = bi.get_si();
- return (signum > 0 ? ret : -ret);
-#endif
-}
-
-BigDecimal::operator long() const
-{
- //TODO
-#if 1
- return 0;
-#else
+ mpz_class scaled_int = toBigInteger();
+ // Check we can convert to int
+ if (signum>0)
+ {
+ if (!mpz_fits_sint_p(scaled_int.get_mpz_t()))
+ throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ + L" is to big to be converted into an int"));
+ }
+ else
+ {
+ // We have to negate the value for the test
+ mpz_class tmp;
+ mpz_neg(tmp.get_mpz_t(), scaled_int.get_mpz_t());
+ if (!mpz_fits_sint_p(tmp.get_mpz_t()))
+ throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ + L" is to big to be converted into an int"));
+ }
+ int mag_length = -1;
+ int* mag = toIntArray(scaled_int, &mag_length);
+ if (mag_length <= 0)
+ {
+ throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ + L" could not be converted to int"));
+ }
+ int res = mag[mag_length-1];
+ delete[] mag;
+ if (signum < 0)
+ res = -res;
+ return res;
+}
+
+BigDecimal::operator long() const throw (ConversionException)
+{
+ if (signum == 0)
+ return 0;
+ mpz_class scaled_int = toBigInteger();
+ // Check we can convert to int
+ if (signum>0)
+ {
+ if (!mpz_fits_slong_p(scaled_int.get_mpz_t()))
+ throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ + L" is to big to be converted into a long"));
+ }
+ else
+ {
+ // We have to negate the value for the test
+ mpz_class tmp;
+ mpz_neg(tmp.get_mpz_t(), scaled_int.get_mpz_t());
+ if (!mpz_fits_slong_p(tmp.get_mpz_t()))
+ throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ + L" is to big to be converted into a long"));
+ }
+ return (signum > 0 ? scaled_int.get_si() : -scaled_int.get_si());
+}
+
+BigDecimal::operator int64_t() const throw (ConversionException)
+{
if (signum == 0)
return 0;
- mpz_class bi(toBigInteger());
- return (signum > 0 ? bi.get_si() : -bi.get_si());
-#endif
+ mpz_class scaled_int = toBigInteger();
+
+ // check size
+ size_t nbBitsNeeded = mpz_sizeinbase(scaled_int.get_mpz_t(), 2);
+ if (signum > 0)
+ nbBitsNeeded++;
+ if (nbBitsNeeded > sizeof(int64_t)*8)
+ throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ + L" is too big to be converted into an int64_t"));
+
+ int mag_length = -1;
+ int* mag = toIntArray(scaled_int, &mag_length);
+ if (mag_length <= 0) //should not happen, but safer
+ {
+ throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ + L" could not be converted to int"));
+ }
+
+ int64_t result = 0;
+ for (int i = 0; i < mag_length; i++)
+ {
+ result = (result<<(8*sizeof(int))) + (mag[i]&0xffffffffLL);
+ }
+ delete[] mag;
+ if (signum < 0)
+ result = -result;
+ return result;
}
+
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.45 carob/src/DriverResultSet.cpp:1.46
--- carob/src/DriverResultSet.cpp:1.45 Tue Mar 7 12:17:44 2006
+++ carob/src/DriverResultSet.cpp Tue Mar 7 12:29:39 2006
@@ -358,9 +358,8 @@
}
break;
case TT_BIGDECIMAL:
-// BigDecimal* bd =
(static_cast<BigDecimal*>((data[currentRow][columnIndex - 1].as_other)));
-// ret = static_cast<int>(*bd);
- throw NotImplementedException(L"BigDecimal to int conversion not
implemented yet.");
+ BigDecimal* bd = (static_cast<BigDecimal*>((data[currentRow][columnIndex
- 1].as_other)));
+ ret = static_cast<int>(*bd);
break;
case TT_BOOLEAN:
if (((data[currentRow])[columnIndex - 1]).as_bool)
@@ -461,9 +460,8 @@
}
break;
case TT_BIGDECIMAL:
- // BigDecimal* bd =
(static_cast<BigDecimal*>((data[currentRow][columnIndex - 1].as_other)));
- // ret = static_cast<long>(*bd);
- throw NotImplementedException(L"BigDecimal to int64 conversion not
implemented yet.");
+ BigDecimal* bd = (static_cast<BigDecimal*>((data[currentRow][columnIndex
- 1].as_other)));
+ ret = static_cast<int64_t>(*bd);
break;
case TT_BOOLEAN:
if (((data[currentRow])[columnIndex - 1]).as_bool)
Index: carob/test/30-ResultSet/TestBigDecimal.cpp
diff -u carob/test/30-ResultSet/TestBigDecimal.cpp:1.1
carob/test/30-ResultSet/TestBigDecimal.cpp:1.2
--- carob/test/30-ResultSet/TestBigDecimal.cpp:1.1 Fri Mar 3 18:21:26 2006
+++ carob/test/30-ResultSet/TestBigDecimal.cpp Tue Mar 7 12:29:39 2006
@@ -24,16 +24,16 @@
#include "Statement.hpp"
#include "DriverResultSet.hpp"
+#include "StringCodecs.hpp"
#include "CarobException.hpp"
#include "Common.hpp"
-#include <values.h>
+#include <locale>
+#include <limits>
#include <string>
#include <iostream>
-using std::wstring;
-using std::endl;
-
+using namespace std;
using namespace CarobNS;
void TestBigDecimal::setUp()
@@ -48,21 +48,25 @@
statementPtr->executeUpdate(
L"UPDATE product SET cost = 0 WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
+ L"UPDATE product SET cost = -1 WHERE id=" + toWString(id++));
+ statementPtr->executeUpdate(
L"UPDATE product SET cost = 1 WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = -1 WHERE id=" + toWString(id++));
+ L"UPDATE product SET cost = -12.34 WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = " + toWString(MININT) + L" WHERE id=" +
toWString(id++));
+ L"UPDATE product SET cost = 12.34 WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = " + toWString(MAXINT) + L" WHERE id=" +
toWString(id++));
+ L"UPDATE product SET cost = " + toWString(numeric_limits<int>::min()) +
L" WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = " + toWString(MINLONG) + L" WHERE id=" +
toWString(id++));
+ L"UPDATE product SET cost = " + toWString(numeric_limits<int>::max()) +
L" WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = " + toWString(MAXLONG) + L" WHERE id= " +
toWString(id++));
+ L"UPDATE product SET cost = " + toWString(numeric_limits<long
long>::min()) + L" WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = 12345678901234567890.12345678901234567890
WHERE id=" + toWString(id++));
+ L"UPDATE product SET cost = " + toWString(numeric_limits<long
long>::max()) + L" WHERE id= " + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = -12345678901234567890.12345678901234567890
WHERE id=" + toWString(id++));
+ L"UPDATE product SET cost =
-123456789012345678901234567890.123456789012345678901234567890 WHERE id=" +
toWString(id++));
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost =
123456789012345678901234567890.123456789012345678901234567890 WHERE id=" +
toWString(id++));
}
void TestBigDecimal::testGetAsString()
@@ -75,31 +79,36 @@
logInfo(fctName, L"0 - getAsString=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"0");
drsPtr->next();
+ logInfo(fctName, L"-1 - getAsString=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"-1");
+ drsPtr->next();
logInfo(fctName, L"1 - getAsString=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"1");
drsPtr->next();
- logInfo(fctName, L"-1 - getAsString=" + drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"-1");
+ logInfo(fctName, toWString(-12.34) + L" - getAsString=" +
drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(-12.34));
+ drsPtr->next();
+ logInfo(fctName, toWString(12.34) + L" - getAsString=" +
drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(12.34));
drsPtr->next();
- logInfo(fctName, toWString(MININT) + L" - getAsString=" +
drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(MININT));
+ logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsString="
+ drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) ==
toWString(numeric_limits<int>::min()));
drsPtr->next();
- logInfo(fctName, toWString(MAXINT) + L" - getAsString=" +
drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(MAXINT));
+ logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsString="
+ drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) ==
toWString(numeric_limits<int>::max()));
drsPtr->next();
- logInfo(fctName, toWString(MINLONG) + L" - getAsString=" +
drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(MINLONG));
+ logInfo(fctName, toWString(numeric_limits<long long>::min()) + L" -
getAsString=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(numeric_limits<long
long>::min()));
drsPtr->next();
- logInfo(fctName, toWString(MAXLONG) + L" - getAsString=" +
drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(MAXLONG));
+ logInfo(fctName, toWString(numeric_limits<long long>::max()) + L" -
getAsString=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(numeric_limits<long
long>::max()));
drsPtr->next();
- logInfo(fctName, L"12345678901234567890.12345678901234567890 - getAsString="
+ drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsString(3) ==
L"12345678901234567890.12345678901234567890");
+ logInfo(fctName, wstring(L"-123456789012345678901234567890") +
use_facet<numpunct<wchar_t> >(std::locale("")).decimal_point() +
L"123456789012345678901234567890 - getAsString=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"-123456789012345678901234567890"
+ fromString(localeconv()->decimal_point) + L"123456789012345678901234567890");
drsPtr->next();
- logInfo(fctName, L"-12345678901234567890.12345678901234567890 -
getAsString=" + drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsString(3) ==
L"-12345678901234567890.12345678901234567890");
+ logInfo(fctName, wstring(L"123456789012345678901234567890") +
use_facet<numpunct<wchar_t> >(std::locale("")).decimal_point() +
L"123456789012345678901234567890 - getAsString=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"123456789012345678901234567890" +
fromString(localeconv()->decimal_point) + L"123456789012345678901234567890");
- connectionPtr->deleteStatement(statementPtr);
}
void TestBigDecimal::testGetAsInt()
@@ -112,29 +121,35 @@
logInfo(fctName, L"0 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 0);
drsPtr->next();
- logInfo(fctName, L"1 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 1);
- drsPtr->next();
logInfo(fctName, L"-1 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
CPPUNIT_ASSERT(drsPtr->getAsInt(3) == -1);
drsPtr->next();
- logInfo(fctName, toWString(MININT) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt(3) == MININT);
- drsPtr->next();
- logInfo(fctName, toWString(MAXINT) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt(3) == MAXINT);
- drsPtr->next();
- logInfo(fctName, toWString(MINLONG) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
-//TODO CPPUNIT_ASSERT(drsPtr->getAsInt(3) == MINLONG);
+ logInfo(fctName, L"1 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 1);
drsPtr->next();
- logInfo(fctName, toWString(MAXLONG) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
-//TODO CPPUNIT_ASSERT(drsPtr->getAsInt(3) == MAXLONG);
+ logInfo(fctName, L"-12.34 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == -12);
drsPtr->next();
- logInfo(fctName, L"12345678901234567890.12345678901234567890 - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
-//TODO CPPUNIT_ASSERT(drsPtr->getAsInt(3) == -6101065172474983726);
+ logInfo(fctName, L"12.34 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 12);
drsPtr->next();
- logInfo(fctName, L"-12345678901234567890.12345678901234567890 - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
-//TODO CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 6101065172474983726);
+ logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsInt=" +
drsPtr->getAsString(3));//toWString(drsPtr->getAsInt(3)));
+ toWString(drsPtr->getAsInt(3));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == numeric_limits<int>::min());
+ drsPtr->next();
+ logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == numeric_limits<int>::max());
+ drsPtr->next();
+ try
+ {
+ logInfo(fctName, L"Trying getAsInt on a too big number
="+drsPtr->getAsString(3));
+ drsPtr->getAsInt(3);
+ CPPUNIT_ASSERT(false);
+ }
+ catch (ConversionException ce)
+ {
+ logInfo(fctName, L"ConversionException catched (this is ok)" +
ce.description());
+ }
connectionPtr->deleteStatement(statementPtr);
}
@@ -149,29 +164,40 @@
logInfo(fctName, L"0 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 0);
drsPtr->next();
- logInfo(fctName, L"1 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 1);
- drsPtr->next();
logInfo(fctName, L"-1 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == -1);
drsPtr->next();
- logInfo(fctName, toWString(MININT) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == MININT);
- drsPtr->next();
- logInfo(fctName, toWString(MAXINT) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == MAXINT);
+ logInfo(fctName, L"1 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 1);
drsPtr->next();
- logInfo(fctName, toWString(MINLONG) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == MINLONG);
+ logInfo(fctName, L"-12.34 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == -12);
drsPtr->next();
- logInfo(fctName, toWString(MAXLONG) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == MAXLONG);
+ logInfo(fctName, L"12.34 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 12);
drsPtr->next();
- logInfo(fctName, L"12345678901234567890.12345678901234567890 - getAsInt64="
+ toWString(drsPtr->getAsInt64(3)));
-// CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == -6101065172474983726);
+ logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<int>::min());
drsPtr->next();
- logInfo(fctName, L"-12345678901234567890.12345678901234567890 - getAsInt64="
+ toWString(drsPtr->getAsInt64(3)));
-// CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 6101065172474983726);
+ logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<int>::max());
+ drsPtr->next();
+ logInfo(fctName, toWString(numeric_limits<long long>::min()) + L" -
getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<long long>::min());
+ drsPtr->next();
+ logInfo(fctName, toWString(numeric_limits<long long>::max()) + L" -
getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<long long>::max());
+ drsPtr->next();
+ try
+ {
+ logInfo(fctName, L"Trying getAsInt64 on a too big number
="+drsPtr->getAsString(3));
+ drsPtr->getAsInt64(3);
+ CPPUNIT_ASSERT(false);
+ }
+ catch (ConversionException ce)
+ {
+ logInfo(fctName, L"ConversionException catched (this is ok)" +
ce.description());
+ }
connectionPtr->deleteStatement(statementPtr);
}
@@ -182,13 +208,13 @@
suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
"TestBigDecimal::testGetAsString",
&TestBigDecimal::testGetAsString));
-/* suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
- "TestBigDecimal::testgetAsInt",
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
+ "TestBigDecimal::testGetAsInt",
&TestBigDecimal::testGetAsInt));
suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
- "TestBigDecimal::testgetAsInt64",
+ "TestBigDecimal::testGetAsInt64",
&TestBigDecimal::testGetAsInt64));
-*/
+
return suiteOfTests;
}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits