From acc894c1d21d1ce45cdbbf3d039261d8b91a51af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Thu, 20 Mar 2014 22:13:15 +0100 Subject: [PATCH] Started a unit test for Statement --- CMakeLists.txt | 1 + tests/Statement_test.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/Statement_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 583166e..958acb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,7 @@ source_group(inc FILES ${SQLITECPP_INC}) # list of test files of the library set(SQLITECPP_TESTS tests/Database_test.cpp + tests/Statement_test.cpp ) source_group(tests FILES ${SQLITECPP_TESTS}) diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp new file mode 100644 index 0000000..be5d338 --- /dev/null +++ b/tests/Statement_test.cpp @@ -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 +#include + +#include + +#include + + +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"); +}