Date: Friday, January 20, 2006 @ 23:44:50
Author: marc
Path: /cvsroot/carob/carob/test
Added: 40-Parameter-PreparedStatement/TestIEEE754.cpp (1.1)
40-Parameter-PreparedStatement/TestIEEE754.hpp (1.1)
Modified: CarobTestLauncher.cpp (1.16 -> 1.17)
First draft of TestIEEE754
------------------------------------------------+
40-Parameter-PreparedStatement/TestIEEE754.cpp | 160 +++++++++++++++++++++++
40-Parameter-PreparedStatement/TestIEEE754.hpp | 50 +++++++
CarobTestLauncher.cpp | 6
3 files changed, 213 insertions(+), 3 deletions(-)
Index: carob/test/40-Parameter-PreparedStatement/TestIEEE754.cpp
diff -u /dev/null carob/test/40-Parameter-PreparedStatement/TestIEEE754.cpp:1.1
--- /dev/null Fri Jan 20 23:44:50 2006
+++ carob/test/40-Parameter-PreparedStatement/TestIEEE754.cpp Fri Jan 20
23:44:50 2006
@@ -0,0 +1,160 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005 Emic Networks
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Marc Herbert
+ * Contributor(s):
+ */
+
+#include "TestIEEE754.hpp"
+
+#include "ParameterStatement.hpp"
+
+#include <cmath>
+#include <limits>
+
+// substitute here with the float32_t and float64_t types of your
+// favorite DBMS
+#define TABLE_TYPE L"(i int, f real, d double precision)"
+
+#define TABLE_NAME L"realdouble"
+
+#define INSERT_STMT L"insert into " TABLE_NAME L" values (?, ?, ?)"
+#define RETRIEVE_STMT L"select * from " TABLE_NAME
+
+#ifndef __STDC_IEC_559__
+#error only IEEE 754 platforms are supported
+#endif
+
+
+namespace {
+
+ typedef std::numeric_limits<float> Floats;
+ typedef std::numeric_limits<double> Doubles;
+ typedef struct _fd { float f; double d; } fd_t;
+
+ bool
+ is_nan(float f)
+ { return (f != f); }
+
+ int
+ check_inf(float f)
+ {
+ if (Floats::max() < f)
+ return 1;
+ if (f < Floats::min())
+ return -1;
+
+ return 0;
+ }
+}
+
+using namespace CarobNS;
+
+void
+write_read(Connection * conn, const fd_t data[])
+{
+ // WRITE
+ ParameterStatement *
+ insert(conn->
+ createParameterStatement(INSERT_STMT));
+
+ int row = 0;
+ while (data[row].f || data[row].d) {
+ insert->setInt(1, row);
+ insert->setFloat(2, data[row].f);
+ insert->setDouble(3, data[row].d);
+ int uc =
+ insert->executeUpdate();
+ CPPUNIT_ASSERT(1 == uc);
+ row++;
+ }
+
+ // READ
+ Statement *
+ retrieve(conn->
+ createStatement());
+
+ DriverResultSet* drsPtr =
+ retrieve->executeQuery(RETRIEVE_STMT);
+
+ row = 0;
+ while (data[row].f || data[row].d) {
+ CPPUNIT_ASSERT(drsPtr->next());
+ CPPUNIT_ASSERT(drsPtr->getAsInt(1) == row);
+ CPPUNIT_ASSERT(drsPtr->getFloat(2) == data[row].f);
+ CPPUNIT_ASSERT(drsPtr->getDouble(3) == data[row].d);
+ }
+}
+
+
+
+void
+TestIEEE754::testBasic()
+{
+ createOrReplaceTable(connectionPtr, TABLE_NAME, TABLE_TYPE);
+
+ fd_t basicdata[] =
+ { { 0.0, 1 },
+ { 1, 0.0 },
+ { -1, -1 },
+ { -5e30, 1e-200 },
+ { Floats::round_error(), Doubles::round_error() },
+ { Floats::epsilon(), -Doubles::epsilon() },
+ { -Floats::min(), Doubles::min() },
+ { Floats::max(), -Doubles::max() },
+ { 0, 0 } // END OF DATA
+ };
+
+ write_read(connectionPtr, basicdata);
+
+}
+
+void
+TestIEEE754::testInfNaN()
+{
+
+ createOrReplaceTable(connectionPtr, TABLE_NAME, TABLE_TYPE);
+
+ // TODO
+ // { Floats::denorm_min(), Doubles::denorm_min() },
+
+
+
+}
+
+CppUnit::Test*
+TestIEEE754::suite()
+{
+ CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( "TestIEEE754" );
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestIEEE754>(
+ "testBasic",
+ &TestIEEE754::testBasic));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestIEEE754>(
+ "testInfNaN",
+ &TestIEEE754::testInfNaN));
+
+ return suiteOfTests;
+}
+
+
+/*
+ * Local Variables:
+ * c-file-style: "bsd"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Index: carob/test/40-Parameter-PreparedStatement/TestIEEE754.hpp
diff -u /dev/null carob/test/40-Parameter-PreparedStatement/TestIEEE754.hpp:1.1
--- /dev/null Fri Jan 20 23:44:50 2006
+++ carob/test/40-Parameter-PreparedStatement/TestIEEE754.hpp Fri Jan 20
23:44:50 2006
@@ -0,0 +1,50 @@
+
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005 Emic Networks
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Marc Herbert
+ * Contributor(s):
+ */
+
+#include "../ConnectionSetup.hpp"
+
+
+/**
+ * Test for IEEE754 double and floats
+ */
+class TestIEEE754 : public ConnectionSetup
+{
+public:
+ /** Suite of tests to be run */
+ static CppUnit::Test* suite();
+
+ void testBasic();
+
+ void testInfNaN();
+
+
+ // void testInfinityNaN();
+
+};
+
+/*
+ * Local Variables:
+ * c-file-style: "bsd"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Index: carob/test/CarobTestLauncher.cpp
diff -u carob/test/CarobTestLauncher.cpp:1.16
carob/test/CarobTestLauncher.cpp:1.17
--- carob/test/CarobTestLauncher.cpp:1.16 Wed Jan 11 20:16:19 2006
+++ carob/test/CarobTestLauncher.cpp Fri Jan 20 23:44:50 2006
@@ -40,6 +40,7 @@
#include "30-ResultSet/TestSimpleUnicode.hpp"
#include "40-Parameter-PreparedStatement/TestParameterStatement.hpp"
#include "40-Parameter-PreparedStatement/TestPreparedStatement.hpp"
+#include "40-Parameter-PreparedStatement/TestIEEE754.hpp"
using namespace CarobNS;
@@ -48,8 +49,6 @@
setLogLevel(LOG_LEVEL_INFO);
//setLogLevel(LOG_LEVEL_NONE);
std::locale::global(std::locale(""));
- // workaround for TestSimpleUnicode
- // std::locale::global(std::locale("en_US.utf8"));
std::set_unexpected(UnexpectedException::convertUnexpected);
CppUnit::TextUi::TestRunner runner;
@@ -65,7 +64,8 @@
runner.addTest(TestStringCodecs::suite());
runner.addTest(TestSimpleUnicode::suite());
runner.addTest(TestParameterStatement::suite());
- runner.addTest(TestPreparedStatement::suite());
+ runner.addTest(TestIEEE754::suite());
+
// add our own protector
CarobProtector* cprot = new CarobProtector();
runner.eventManager().pushProtector(cprot);
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits