mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-05 02:06:02 -04:00
Started a unit test for Statement
This commit is contained in:
parent
d69045f3fc
commit
acc894c1d2
@ -83,6 +83,7 @@ source_group(inc FILES ${SQLITECPP_INC})
|
|||||||
# list of test files of the library
|
# list of test files of the library
|
||||||
set(SQLITECPP_TESTS
|
set(SQLITECPP_TESTS
|
||||||
tests/Database_test.cpp
|
tests/Database_test.cpp
|
||||||
|
tests/Statement_test.cpp
|
||||||
)
|
)
|
||||||
source_group(tests FILES ${SQLITECPP_TESTS})
|
source_group(tests FILES ${SQLITECPP_TESTS})
|
||||||
|
|
||||||
|
39
tests/Statement_test.cpp
Normal file
39
tests/Statement_test.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* @file Statement_test.cpp
|
||||||
|
* @ingroup tests
|
||||||
|
* @brief Test of a SQLiteCpp Statement.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Sebastien Rombauts (sebastien.rombauts@gmail.com)
|
||||||
|
*
|
||||||
|
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
|
||||||
|
* or copy at http://opensource.org/licenses/MIT)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SQLiteCpp/Database.h>
|
||||||
|
#include <SQLiteCpp/Statement.h>
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
|
TEST(Statement, exec) {
|
||||||
|
remove("test.db3");
|
||||||
|
{
|
||||||
|
// Create a new database
|
||||||
|
SQLite::Database db("test.db3", SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
|
||||||
|
|
||||||
|
// Compile a SQL query, but without any table in the database
|
||||||
|
EXPECT_THROW(SQLite::Statement query(db, "SELECT * FROM test"), SQLite::Exception);
|
||||||
|
|
||||||
|
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
|
||||||
|
|
||||||
|
// Compile a SQL query with no parameter
|
||||||
|
SQLite::Statement query(db, "SELECT * FROM test");
|
||||||
|
EXPECT_STREQ("SELECT * FROM test", query.getQuery().c_str());
|
||||||
|
EXPECT_EQ(2, query.getColumnCount ());
|
||||||
|
|
||||||
|
|
||||||
|
} // Close DB test.db3
|
||||||
|
remove("test.db3");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user