added bigIntTest, related to issue #909
see http://bugs.campware.org/view.php?id=909
This commit is contained in:
parent
cddaf2f5b9
commit
af576dcdb1
2 changed files with 100 additions and 3 deletions
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.2 $
|
||||
Version : $Revision: 1.3 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/SimpleConnectionManagerTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -43,6 +43,7 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
#include <odbc++/resultset.h>
|
||||
#include <odbc++/preparedstatement.h>
|
||||
|
||||
#include "SimpleConnectionManager.h"
|
||||
#include "SimpleConnectionManagerTest.h"
|
||||
|
@ -113,6 +114,11 @@ SimpleConnectionManagerTest :: firstTest(void)
|
|||
CPPUNIT_ASSERT(rs->next());
|
||||
CPPUNIT_ASSERT(rs->getInt(1) == 1);
|
||||
|
||||
rs.reset();
|
||||
stmt->close();
|
||||
stmt.reset();
|
||||
scm->returnConnection(connection);
|
||||
|
||||
} catch (std::invalid_argument &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
} catch (std::runtime_error &e) {
|
||||
|
@ -122,3 +128,85 @@ SimpleConnectionManagerTest :: firstTest(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to handle large integers.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SimpleConnectionManagerTest :: bigIntTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
long long testValue = 0x7fffffffffffffffLL;
|
||||
std::string createStmt = "CREATE TABLE testTable\n"
|
||||
"(\n"
|
||||
" id BIGINT NOT NULL\n"
|
||||
");";
|
||||
bool b;
|
||||
|
||||
try {
|
||||
xmlpp::DomParser parser;
|
||||
const xmlpp::Document * document = getConfigDocument(parser,
|
||||
configFileName);
|
||||
const xmlpp::Element * root = document->get_root_node();
|
||||
Ptr<SimpleConnectionManager>::Ref scm(new SimpleConnectionManager());
|
||||
|
||||
scm->configure(*root);
|
||||
|
||||
Ptr<Connection>::Ref connection = scm->getConnection();
|
||||
CPPUNIT_ASSERT(connection);
|
||||
|
||||
// simply see if selecting the highest 63 bit number works...
|
||||
Ptr<PreparedStatement>::Ref pstmt(connection->prepareStatement(
|
||||
"SELECT ?"));
|
||||
pstmt->setLong(1, testValue);
|
||||
Ptr<ResultSet>::Ref rs(pstmt->executeQuery());
|
||||
CPPUNIT_ASSERT(rs->next());
|
||||
CPPUNIT_ASSERT(rs->getLong(1) == testValue);
|
||||
rs.reset();
|
||||
pstmt->close();
|
||||
pstmt.reset();
|
||||
|
||||
// so far, so good. now create a table with a BIGINT column
|
||||
// and try the same
|
||||
Ptr<Statement>::Ref stmt(connection->createStatement());
|
||||
stmt->execute(createStmt);
|
||||
stmt->close();
|
||||
stmt.reset();
|
||||
|
||||
pstmt.reset(connection->prepareStatement("INSERT INTO testTable "
|
||||
" VALUES(?)"));
|
||||
pstmt->setLong(1, testValue);
|
||||
CPPUNIT_ASSERT(pstmt->executeUpdate() == 1);
|
||||
pstmt->close();
|
||||
pstmt.reset();
|
||||
|
||||
stmt.reset(connection->createStatement());
|
||||
rs.reset(stmt->executeQuery("SELECT * FROM testTable"));
|
||||
CPPUNIT_ASSERT(rs->next());
|
||||
//std::cerr << std::endl;
|
||||
//std::cerr << "rs->getLong: " << rs->getLong(1) << std::endl;
|
||||
//std::cerr << "testValue: " << testValue << std::endl;
|
||||
b = rs->getLong(1) == testValue;
|
||||
CPPUNIT_ASSERT(b);
|
||||
rs.reset();
|
||||
stmt->close();
|
||||
stmt.reset();
|
||||
|
||||
stmt.reset(connection->createStatement());
|
||||
stmt->executeUpdate("DROP TABLE testTable");
|
||||
stmt->close();
|
||||
stmt.reset();
|
||||
|
||||
scm->returnConnection(connection);
|
||||
|
||||
} catch (std::invalid_argument &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
} catch (std::runtime_error &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
} catch (xmlpp::exception &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
} catch (SQLException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.2 $
|
||||
Version : $Revision: 1.3 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/SimpleConnectionManagerTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -63,13 +63,14 @@ using namespace LiveSupport::Core;
|
|||
* Unit test for the SimpleConnectionManager class.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.2 $
|
||||
* @version $Revision: 1.3 $
|
||||
* @see SimpleConnectionManager
|
||||
*/
|
||||
class SimpleConnectionManagerTest : public BaseTestMethod
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(SimpleConnectionManagerTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST(bigIntTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
protected:
|
||||
|
@ -82,6 +83,14 @@ class SimpleConnectionManagerTest : public BaseTestMethod
|
|||
void
|
||||
firstTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* A test to handle large integers.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
bigIntTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue