From 7bfaafecba3c507731f5d9832629ff0e75d3e53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Tue, 4 Mar 2014 22:35:23 +0100 Subject: [PATCH] Moved include files out of the src/ dir, to an include/ dir + started a void test file --- CMakeLists.txt | 126 +++++++++++++----- Doxyfile | 2 +- build.bat | 1 + examples/example1/main.cpp | 2 +- {src => include/SQLiteCpp}/Assertion.h | 0 {src => include/SQLiteCpp}/Column.h | 4 +- {src => include/SQLiteCpp}/Database.h | 2 +- {src => include/SQLiteCpp}/Exception.h | 0 .../SQLiteCpp/SQLiteCpp.h | 18 +-- {src => include/SQLiteCpp}/Statement.h | 2 +- {src => include/SQLiteCpp}/Transaction.h | 2 +- sqlite3/CMakeLists.txt | 4 +- sqlite3/sqlite3.c | 2 +- src/Column.cpp | 2 +- src/Database.cpp | 8 +- src/Statement.cpp | 10 +- src/Transaction.cpp | 6 +- tests/Database_test.cpp | 34 +++++ 18 files changed, 157 insertions(+), 68 deletions(-) rename {src => include/SQLiteCpp}/Assertion.h (100%) rename {src => include/SQLiteCpp}/Column.h (99%) rename {src => include/SQLiteCpp}/Database.h (99%) rename {src => include/SQLiteCpp}/Exception.h (100%) rename src/SQLiteC++.h => include/SQLiteCpp/SQLiteCpp.h (77%) rename {src => include/SQLiteCpp}/Statement.h (99%) rename {src => include/SQLiteCpp}/Transaction.h (98%) create mode 100644 tests/Database_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 71cd7f3..6847b33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,13 +13,13 @@ project(SQLiteCpp) option(SQLITE_ENABLE_COLUMN_METADATA "Enable Column::getName(). Require support from sqlite3 library." ON) if (SQLITE_ENABLE_COLUMN_METADATA) add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA) -endif () +endif (SQLITE_ENABLE_COLUMN_METADATA) option(SQLITE_ENABLE_ASSERT_HANDLER "Enable the user defintion of a assertion_failed() handler." ON) if (SQLITE_ENABLE_ASSERT_HANDLER) # Enable the user defintion of a assertion_failed() handler. add_definitions(-DSQLITECPP_ENABLE_ASSERT_HANDLER) -endif () +endif (SQLITE_ENABLE_ASSERT_HANDLER) # Define useful variables to handle OS differences: if (WIN32) @@ -33,6 +33,11 @@ if (MSVC) set(CPPCHECK_ARG_TEMPLATE "--template=vs") # disable Visual Studio warnings for fopen() used in the example add_definitions(-D_CRT_SECURE_NO_WARNINGS) + # Specific flags for multithread static linking + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") else (MSVC) set(CPPLINT_ARG_OUTPUT "--output=eclipse") set(CPPCHECK_ARG_TEMPLATE "--template=gcc") @@ -56,25 +61,55 @@ set(CPPLINT_ARG_LINELENGTH "--linelength=120") # list of sources files of the library set(SQLITECPP_SRC - src/SQLiteC++.h - src/Assertion.h - src/Column.cpp - src/Column.h - src/Database.cpp - src/Database.h - src/Exception.h - src/Statement.cpp - src/Statement.h - src/Transaction.cpp - src/Transaction.h + ${PROJECT_SOURCE_DIR}/src/Column.cpp + ${PROJECT_SOURCE_DIR}/src/Database.cpp + ${PROJECT_SOURCE_DIR}/src/Statement.cpp + ${PROJECT_SOURCE_DIR}/src/Transaction.cpp ) -# add sources of the wrapper as a "SQLiteCpp" static library -add_library (SQLiteCpp ${SQLITECPP_SRC}) source_group(src FILES ${SQLITECPP_SRC}) -if(UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")) +# list of header files of the library +set(SQLITECPP_INC + ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/SQLiteCpp.h + ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Assertion.h + ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Column.h + ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Database.h + ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Exception.h + ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Statement.h + ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Transaction.h +) +source_group(inc FILES ${SQLITECPP_INC}) + +# list of test files of the library +set(SQLITECPP_TESTS + tests/Database_test.cpp +) +source_group(tests FILES ${SQLITECPP_TESTS}) + +# list of example files of the library +set(SQLITECPP_EXAMPLES + examples/example1/main.cpp +) +source_group(example1 FILES ${SQLITECPP_EXAMPLES}) + +# list of doc files of the library +set(SQLITECPP_DOC + README.md + WRAPPERS.md + LICENSE.txt + TODO.txt +) +source_group(doc FILES ${SQLITECPP_DOC}) + +# All includes are relative to the "include" directory +include_directories("${PROJECT_SOURCE_DIR}/include") + +# add sources of the wrapper as a "SQLiteCpp" static library +add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC}) + +if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")) set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fPIC") -endif(UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")) +endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")) # SQLite3 library (Windows only) @@ -85,6 +120,7 @@ if (WIN32) include_directories("${PROJECT_SOURCE_DIR}/sqlite3") endif (WIN32) + # Optional additional targets: option(SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." OFF) @@ -92,11 +128,11 @@ if (SQLITECPP_RUN_CPPLINT) # add a cpplint target to the "all" target add_custom_target(SQLiteCpp_cpplint ALL - COMMAND python cpplint.py ${CPPLINT_ARG_OUTPUT} ${CPPLINT_ARG_VERBOSE} ${CPPLINT_ARG_LINELENGTH} ${PROJECT_SOURCE_DIR}/${SQLITECPP_SRC} + COMMAND python ${PROJECT_SOURCE_DIR}/cpplint.py ${CPPLINT_ARG_OUTPUT} ${CPPLINT_ARG_VERBOSE} ${CPPLINT_ARG_LINELENGTH} ${SQLITECPP_SRC} ${SQLITECPP_INC} ) -else() +else (SQLITECPP_RUN_CPPLINT) message(STATUS "SQLITECPP_RUN_CPPLINT OFF") -endif() +endif (SQLITECPP_RUN_CPPLINT) option(SQLITECPP_RUN_CPPCHECK "Run cppcheck C++ static analysis tool." ON) if (SQLITECPP_RUN_CPPCHECK) @@ -105,9 +141,9 @@ if (SQLITECPP_RUN_CPPCHECK) ALL COMMAND cppcheck -j 4 cppcheck --enable=style --quiet ${CPPCHECK_ARG_TEMPLATE} ${PROJECT_SOURCE_DIR}/src ) -else() +else (SQLITECPP_RUN_CPPCHECK) message(STATUS "SQLITECPP_RUN_CPPCHECK OFF") -endif() +endif (SQLITECPP_RUN_CPPCHECK) option(SQLITECPP_RUN_DOXYGEN "Run Doxygen C++ documentation tool." ON) if (SQLITECPP_RUN_DOXYGEN) @@ -119,24 +155,42 @@ if (SQLITECPP_RUN_DOXYGEN) COMMAND doxygen Doxyfile > ${DEV_NULL} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) - else() + else (DOXYGEN_FOUND) message(STATUS "Doxygen not found") - endif() -else() + endif (DOXYGEN_FOUND) +else (SQLITECPP_RUN_DOXYGEN) message(STATUS "SQLITECPP_RUN_DOXYGEN OFF") -endif() +endif (SQLITECPP_RUN_DOXYGEN) -option(SQLITECPP_RUN_TESTS "Run test tools." ON) -if (SQLITECPP_RUN_TESTS) - # add the example1 executable, linked with the wrapper library - add_executable(example1 examples/example1/main.cpp) - target_link_libraries(example1 SQLiteCpp sqlite3) +option(SQLITECPP_BUILD_EXAMPLES "Build examples." ON) +if (SQLITECPP_BUILD_EXAMPLES) + # add the basic example executable + add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES}) + target_link_libraries(SQLiteCpp_example1 SQLiteCpp sqlite3) +else(SQLITECPP_BUILD_EXAMPLES) + message(STATUS "SQLITECPP_BUILD_EXAMPLES OFF") +endif(SQLITECPP_BUILD_EXAMPLES) + +option(SQLITECPP_BUILD_TESTS "Build and run tests." ON) +if (SQLITECPP_BUILD_TESTS) + # add the subdirectory containing the CMakeLists.txt for the gtest library + add_subdirectory(googletest) + include_directories("${PROJECT_SOURCE_DIR}/googletest/include") + + # add the unit test executable + add_executable(SQLiteCpp_tests ${SQLITECPP_TESTS}) + target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3) # add a "test" target: enable_testing() - # does the example1 runs successfully? - add_test(Example1Run example1) -else() - message(STATUS "SQLITECPP_RUN_TESTS OFF") -endif() + # does the tests pass? + add_test(UnitTests SQLiteCpp_tests) + + if (SQLITECPP_BUILD_EXAMPLES) + # does the example1 runs successfully? + add_test(Example1Run SQLiteCpp_example1) + endif(SQLITECPP_BUILD_EXAMPLES) +else (SQLITECPP_BUILD_TESTS) + message(STATUS "SQLITECPP_BUILD_TESTS OFF") +endif (SQLITECPP_BUILD_TESTS) diff --git a/Doxyfile b/Doxyfile index d13a4f0..14efa3b 100644 --- a/Doxyfile +++ b/Doxyfile @@ -677,7 +677,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = src +INPUT = src include # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is diff --git a/build.bat b/build.bat index 85b6a02..b11395f 100644 --- a/build.bat +++ b/build.bat @@ -15,3 +15,4 @@ mkdir examples\example1 copy ..\examples\example1\example.db3 examples\example1 copy ..\examples\example1\logo.png examples\example1 ctest . +cd .. \ No newline at end of file diff --git a/examples/example1/main.cpp b/examples/example1/main.cpp index 57510d3..673c3f9 100644 --- a/examples/example1/main.cpp +++ b/examples/example1/main.cpp @@ -16,7 +16,7 @@ #include -#include "../../src/SQLiteC++.h" +#include #ifdef SQLITECPP_ENABLE_ASSERT_HANDLER namespace SQLite diff --git a/src/Assertion.h b/include/SQLiteCpp/Assertion.h similarity index 100% rename from src/Assertion.h rename to include/SQLiteCpp/Assertion.h diff --git a/src/Column.h b/include/SQLiteCpp/Column.h similarity index 99% rename from src/Column.h rename to include/SQLiteCpp/Column.h index 7207c8f..e65e285 100644 --- a/src/Column.h +++ b/include/SQLiteCpp/Column.h @@ -12,8 +12,8 @@ #include -#include "Statement.h" -#include "Exception.h" +#include +#include namespace SQLite diff --git a/src/Database.h b/include/SQLiteCpp/Database.h similarity index 99% rename from src/Database.h rename to include/SQLiteCpp/Database.h index c866e1b..48d8fd1 100644 --- a/src/Database.h +++ b/include/SQLiteCpp/Database.h @@ -12,7 +12,7 @@ #include -#include "Column.h" +#include namespace SQLite diff --git a/src/Exception.h b/include/SQLiteCpp/Exception.h similarity index 100% rename from src/Exception.h rename to include/SQLiteCpp/Exception.h diff --git a/src/SQLiteC++.h b/include/SQLiteCpp/SQLiteCpp.h similarity index 77% rename from src/SQLiteC++.h rename to include/SQLiteCpp/SQLiteCpp.h index 18440bf..eafa323 100644 --- a/src/SQLiteC++.h +++ b/include/SQLiteCpp/SQLiteCpp.h @@ -1,5 +1,5 @@ /** - * @file SQLiteC++.h + * @file SQLiteCpp.h * @ingroup SQLiteCpp * @brief SQLiteC++ is a smart and simple C++ SQLite3 wrapper. This file is only "easy include" for other files. * @@ -18,12 +18,12 @@ // Include useful headers of SQLiteC++ -#include "Assertion.h" -#include "Exception.h" -#include "Database.h" -#include "Statement.h" -#include "Column.h" -#include "Transaction.h" +#include +#include +#include +#include +#include +#include /** @@ -38,5 +38,5 @@ * with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same * numbers used in [SQLITECPP_VERSION]. */ -#define SQLITECPP_VERSION "0.8.0" -#define SQLITECPP_VERSION_NUMBER 0008000 +#define SQLITECPP_VERSION "0.9.9" +#define SQLITECPP_VERSION_NUMBER 0009009 diff --git a/src/Statement.h b/include/SQLiteCpp/Statement.h similarity index 99% rename from src/Statement.h rename to include/SQLiteCpp/Statement.h index 6455051..2eeb2e6 100644 --- a/src/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -13,7 +13,7 @@ #include #include -#include "Exception.h" +#include namespace SQLite diff --git a/src/Transaction.h b/include/SQLiteCpp/Transaction.h similarity index 98% rename from src/Transaction.h rename to include/SQLiteCpp/Transaction.h index 96b1426..69649bc 100644 --- a/src/Transaction.h +++ b/include/SQLiteCpp/Transaction.h @@ -10,7 +10,7 @@ */ #pragma once -#include "Exception.h" +#include namespace SQLite diff --git a/sqlite3/CMakeLists.txt b/sqlite3/CMakeLists.txt index 1b2f85f..d163f50 100644 --- a/sqlite3/CMakeLists.txt +++ b/sqlite3/CMakeLists.txt @@ -1,12 +1,12 @@ # CMake file for compiling the sqlite3 static library under Windows (for ease of use) # -# Copyright (c) 2013 Sebastien Rombauts (sebastien.rombauts@gmail.com) +# Copyright (c) 2013-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) # add sources of the "sqlite3" static library -add_library (sqlite3 +add_library(sqlite3 sqlite3.c sqlite3.h ) diff --git a/sqlite3/sqlite3.c b/sqlite3/sqlite3.c index d14314a..28205f6 100644 --- a/sqlite3/sqlite3.c +++ b/sqlite3/sqlite3.c @@ -18,7 +18,7 @@ ** separate file. This file contains only code for the core SQLite library. */ -#define SQLITE_ENABLE_COLUMN_METADATA +// SQLITE_ENABLE_COLUMN_METADATA is defined in the project #define SQLITE_CORE 1 #define SQLITE_AMALGAMATION 1 #ifndef SQLITE_PRIVATE diff --git a/src/Column.cpp b/src/Column.cpp index 2ca474e..eb97a2e 100644 --- a/src/Column.cpp +++ b/src/Column.cpp @@ -8,7 +8,7 @@ * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * or copy at http://opensource.org/licenses/MIT) */ -#include "Column.h" +#include #include diff --git a/src/Database.cpp b/src/Database.cpp index 1167bf9..b847f15 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -8,11 +8,11 @@ * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * or copy at http://opensource.org/licenses/MIT) */ -#include "Database.h" +#include -#include "Statement.h" -#include "Assertion.h" -#include "Exception.h" +#include +#include +#include #ifndef SQLITE_DETERMINISTIC #define SQLITE_DETERMINISTIC 0x800 diff --git a/src/Statement.cpp b/src/Statement.cpp index 67134eb..0bcf409 100644 --- a/src/Statement.cpp +++ b/src/Statement.cpp @@ -8,12 +8,12 @@ * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * or copy at http://opensource.org/licenses/MIT) */ -#include "Statement.h" +#include -#include "Database.h" -#include "Column.h" -#include "Assertion.h" -#include "Exception.h" +#include +#include +#include +#include namespace SQLite diff --git a/src/Transaction.cpp b/src/Transaction.cpp index df50829..0f37cf3 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -8,10 +8,10 @@ * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * or copy at http://opensource.org/licenses/MIT) */ -#include "Transaction.h" +#include -#include "Database.h" -#include "Assertion.h" +#include +#include namespace SQLite diff --git a/tests/Database_test.cpp b/tests/Database_test.cpp new file mode 100644 index 0000000..0ce351a --- /dev/null +++ b/tests/Database_test.cpp @@ -0,0 +1,34 @@ +/** + * @file Database_test.cpp + * @ingroup tests + * @brief Test of a SQLiteCpp Database. + * + * 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 + +#ifdef SQLITECPP_ENABLE_ASSERT_HANDLER +namespace SQLite +{ +/// definition of the assertion handler enabled when SQLITECPP_ENABLE_ASSERT_HANDLER is defined in the project (CMakeList.txt) +void assertion_failed(const char* apFile, const long apLine, const char* apFunc, const char* apExpr, const char* apMsg) +{ + // TODO test +} +} +#endif + + +// Constructor +TEST(Database, ctor) { + SQLite::Database database("test.db3", SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); +// TODO test +// EXPECT_FALSE(database.hasEntity(entity1)); +// EXPECT_EQ((size_t)0, database.unregisterEntity(entity1)); +}