Skip to content
Snippets Groups Projects
Commit 9cfd7222 authored by Steven Murray's avatar Steven Murray
Browse files

Added ConnTest

parent d07c3416
No related branches found
No related tags found
No related merge requests found
......@@ -84,6 +84,7 @@ install (TARGETS ctardbms DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
set(RDBMS_UNIT_TESTS_LIB_SRC_FILES
ConnPoolTest.cpp
ConnTest.cpp
LoginTest.cpp
ParamNameToIdxTest.cpp
SqliteStmtTest.cpp)
......
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/Exception.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
#include "rdbms/ConnPool.hpp"
#include <gtest/gtest.h>
#include <sstream>
namespace unitTests {
class cta_rdbms_ConnTest : public ::testing::Test {
protected:
virtual void SetUp() {
}
virtual void TearDown() {
}
};
TEST_F(cta_rdbms_ConnTest, createSameTableInTwoSeparateInMemoryDatabases_executeNonQuery) {
using namespace cta::rdbms;
const std::string sql = "CREATE TABLE POOLED_STMT_TEST(ID INTEGER)";
// First in-memory database
{
const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared");
auto connFactory = ConnFactoryFactory::create(login);
auto conn = connFactory->create();
ASSERT_TRUE(conn->getTableNames().empty());
conn->executeNonQuery(sql, Stmt::AutocommitMode::ON);
ASSERT_EQ(1, conn->getTableNames().size());
}
// Second in-memory database
{
const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared");
auto connFactory = ConnFactoryFactory::create(login);
auto conn = connFactory->create();
ASSERT_TRUE(conn->getTableNames().empty());
conn->executeNonQuery(sql, Stmt::AutocommitMode::ON);
ASSERT_EQ(1, conn->getTableNames().size());
}
}
TEST_F(cta_rdbms_ConnTest, createSameTableInTwoSeparateInMemoryDatabases_executeNonQueries) {
using namespace cta::rdbms;
const std::string sql = "CREATE TABLE POOLED_STMT_TEST(ID INTEGER);";
// First in-memory database
{
const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared");
auto connFactory = ConnFactoryFactory::create(login);
auto conn = connFactory->create();
ASSERT_TRUE(conn->getTableNames().empty());
conn->executeNonQueries(sql);
ASSERT_EQ(1, conn->getTableNames().size());
}
// Second in-memory database
{
const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared");
auto connFactory = ConnFactoryFactory::create(login);
auto conn = connFactory->create();
ASSERT_TRUE(conn->getTableNames().empty());
conn->executeNonQueries(sql);
ASSERT_EQ(1, conn->getTableNames().size());
}
}
} // namespace unitTests
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment