diff --git a/.travis.yml b/.travis.yml index b4ddb8627..4705be33f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,453 +1,152 @@ language: cpp sudo: false +dist: trusty -# Use Linux unless specified otherwise os: linux -dist: trusty matrix: include: - ########################################################################## - # Clang on Linux - ########################################################################## - - # clang-3.6 32 - - env: CLANG_VERSION=3.6 BUILD_TYPE=Debug ARCH=32 - addons: &clang36-32 - apt: - packages: - - clang-3.6 - - linux-libc-dev:i386 - - g++-5-multilib - - gcc-5-multilib - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.6 - # - env: CLANG_VERSION=3.6 BUILD_TYPE=Release ARCH=32 - # addons: *clang36-32 - - # clang-3.6 64 - - env: CLANG_VERSION=3.6 BUILD_TYPE=Debug ARCH=64 - addons: &clang36-64 - apt: - packages: - - clang-3.6 - - g++-5 - - gcc-5 - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.6 - # - env: CLANG_VERSION=3.6 BUILD_TYPE=Release ARCH=32 - # addons: *clang36-64 - - # clang-3.7 32 - - env: CLANG_VERSION=3.7 BUILD_TYPE=Debug ARCH=32 - addons: &clang37-32 - apt: - packages: - - clang-3.7 - - linux-libc-dev:i386 - - g++-5-multilib - - gcc-5-multilib - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.7 - - # - env: CLANG_VERSION=3.7 BUILD_TYPE=Release ARCH=32 - # addons: *clang37-32 - - # clang-3.7 64 - - env: CLANG_VERSION=3.7 BUILD_TYPE=Debug ARCH=64 - os: linux - addons: &clang37-64 - apt: - packages: - - clang-3.7 - - g++-5 - - gcc-5 - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.7 - - # - env: CLANG_VERSION=3.7 BUILD_TYPE=Release ARCH=64 - # addons: *clang37-64 - - # clang-3.8 32 - - env: CLANG_VERSION=3.8 BUILD_TYPE=Debug ARCH=32 - addons: &clang38-32 - apt: - packages: - - clang-3.8 - - linux-libc-dev:i386 - - g++-5-multilib - - gcc-5-multilib - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.8 - - # - env: CLANG_VERSION=3.8 BUILD_TYPE=Release ARCH=32 - # addons: *clang38-32 - - # clang-3.8 64 - - env: CLANG_VERSION=3.8 BUILD_TYPE=Debug ARCH=64 - addons: &clang38-64 - apt: - packages: - - clang-3.8 - - g++-5 - - gcc-5 - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.8 - - # - env: CLANG_VERSION=3.8 BUILD_TYPE=Release ARCH=64 - # addons: *clang38-64 - - # clang-3.9 32 - - env: CLANG_VERSION=3.9 BUILD_TYPE=Debug ARCH=32 - addons: &clang39-32 - apt: - packages: - - clang-3.9 - - linux-libc-dev:i386 - - g++-5-multilib - - gcc-5-multilib - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.9 - - # - env: CLANG_VERSION=3.9 BUILD_TYPE=Release ARCH=32 - # addons: *clang39-32 - - # clang-3.9 64 - - env: CLANG_VERSION=3.9 BUILD_TYPE=Debug ARCH=64 - addons: &clang39-64 - apt: - packages: - - clang-3.9 - - g++-5 - - gcc-5 - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.9 - - # - env: CLANG_VERSION=3.9 BUILD_TYPE=Release ARCH=64 - # addons: *clang39-64 - - # clang-4.0 32 - - env: CLANG_VERSION=4.0 BUILD_TYPE=Debug ARCH=32 - addons: &clang40-32 - apt: - packages: - - clang-4.0 - - linux-libc-dev:i386 - - g++-5-multilib - - gcc-5-multilib - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-trusty-4.0 - - # - env: CLANG_VERSION=4.0 BUILD_TYPE=Release ARCH=32 - # addons: *clang40-32 - - # clang-4.0 64 - - env: CLANG_VERSION=4.0 BUILD_TYPE=Debug ARCH=64 - addons: &clang40-64 - apt: - packages: - - clang-4.0 - - g++-5 - - gcc-5 - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-trusty-4.0 - - # - env: CLANG_VERSION=4.0 BUILD_TYPE=Release ARCH=64 - # addons: *clang40-64 - - # clang-5.0 32 - - env: CLANG_VERSION=5.0 BUILD_TYPE=Debug ARCH=32 - addons: &clang50-32 - apt: - packages: - - clang-5.0 - - linux-libc-dev:i386 - - g++-5-multilib - - gcc-5-multilib - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-trusty-5.0 - - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main' - key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - - # - env: CLANG_VERSION=5.0 BUILD_TYPE=Release ARCH=32 - # addons: *clang50-32 - - # clang-5.0 64 - - env: CLANG_VERSION=5.0 BUILD_TYPE=Debug ARCH=64 - addons: &clang50-64 - apt: - packages: - - clang-5.0 - - g++-5 - - gcc-5 - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-trusty-5.0 - - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main' - key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - - # - env: CLANG_VERSION=5.0 BUILD_TYPE=Release ARCH=64 - # addons: *clang50-64 - - # clang-6.0 32 - - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug ARCH=32 - addons: &clang60-32 - apt: - packages: - - clang-6.0 - - linux-libc-dev:i386 - - g++-5-multilib - - gcc-5-multilib - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-trusty-6.0 - - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main' - key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - - - env: CLANG_VERSION=6.0 BUILD_TYPE=Release ARCH=32 - addons: *clang60-32 - - # clang-6.0 64 - - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug ARCH=64 - addons: &clang60-64 - apt: - packages: - - clang-6.0 - - g++-5 - - gcc-5 - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-trusty-6.0 - - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main' - key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - - - env: CLANG_VERSION=6.0 BUILD_TYPE=Release ARCH=64 - addons: *clang60-64 - - ########################################################################## - # GCC on Linux - ########################################################################## - # gcc-4.9 32 - - env: GCC_VERSION=4.9 BUILD_TYPE=Debug ARCH=32 - addons: &gcc49-32 - apt: - packages: - - linux-libc-dev:i386 - - g++-4.9-multilib - - gcc-4.9-multilib - sources: - - ubuntu-toolchain-r-test - # - env: GCC_VERSION=4.9 BUILD_TYPE=Release ARCH=32 - # addons: *gcc49-32 - - # gcc-4.9 64 - - env: GCC_VERSION=4.9 BUILD_TYPE=Debug ARCH=64 - addons: &gcc49-64 - apt: - packages: - - g++-4.9 - - gcc-4.9 - sources: - - ubuntu-toolchain-r-test - # - env: GCC_VERSION=4.9 BUILD_TYPE=Release ARCH=64 - # addons: *gcc49-64 - - # gcc-5 32 - - env: GCC_VERSION=5 BUILD_TYPE=Debug ARCH=32 - addons: &gcc5-32 - apt: - packages: - - linux-libc-dev:i386 - - g++-5-multilib - - gcc-5-multilib - sources: - - ubuntu-toolchain-r-test - # - env: GCC_VERSION=5 BUILD_TYPE=Release ARCH=32 - # addons: *gcc5-32 - - # gcc-5 64 - - env: GCC_VERSION=5 BUILD_TYPE=Debug ARCH=64 - addons: &gcc5-64 - apt: - packages: - - g++-5 - - gcc-5 - sources: - - ubuntu-toolchain-r-test - # - env: GCC_VERSION=5 BUILD_TYPE=Release ARCH=64 - # addons: *gcc5-64 - - # gcc-6 32 - - env: GCC_VERSION=6 BUILD_TYPE=Debug ARCH=32 - addons: &gcc6-32 - apt: - packages: - - rpm - - linux-libc-dev:i386 - - g++-6-multilib - - gcc-6-multilib - - doxygen - sources: - - ubuntu-toolchain-r-test - # - env: GCC_VERSION=6 BUILD_TYPE=Release ARCH=32 - # addons: *gcc6-32 - - # gcc-6 64 - - env: GCC_VERSION=6 BUILD_TYPE=Debug ARCH=64 - addons: &gcc6-64 - apt: - packages: - - rpm - - g++-6 - - gcc-6 - - doxygen - sources: - - ubuntu-toolchain-r-test - # - env: GCC_VERSION=6 BUILD_TYPE=Release ARCH=64 - # addons: *gcc6-64 - - # gcc-7 32 - - env: GCC_VERSION=7 BUILD_TYPE=Debug ARCH=32 - addons: &gcc7-32 - apt: - packages: - - rpm - - linux-libc-dev:i386 - - g++-7-multilib - - gcc-7-multilib - - doxygen - sources: - - ubuntu-toolchain-r-test - - env: GCC_VERSION=7 BUILD_TYPE=Release ARCH=32 - addons: *gcc7-32 - - # gcc-7 64 - - env: GCC_VERSION=7 BUILD_TYPE=Debug ARCH=64 - addons: &gcc7-64 - apt: - packages: - - rpm - - g++-7 - - gcc-7 - - doxygen - sources: - - ubuntu-toolchain-r-test - - env: GCC_VERSION=7 BUILD_TYPE=Release ARCH=64 - addons: *gcc7-64 - + - env: CLANG_VERSION=3.6 BUILD_TYPE=Release ARCH=32 + addons: { apt: {packages: [clang-3.6,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test]}} + - env: CLANG_VERSION=3.6 BUILD_TYPE=Release ARCH=64 + addons: { apt: {packages: [clang-3.6,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test]}} + - env: CLANG_VERSION=3.7 BUILD_TYPE=Release ARCH=32 + addons: { apt: {packages: [clang-3.7,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-precise-3.7]}} + - env: CLANG_VERSION=3.7 BUILD_TYPE=Release ARCH=64 + addons: { apt: {packages: [clang-3.7,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-precise-3.7]}} + - env: CLANG_VERSION=3.8 BUILD_TYPE=Release ARCH=32 + addons: { apt: {packages: [clang-3.8,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test]}} + - env: CLANG_VERSION=3.8 BUILD_TYPE=Release ARCH=64 + addons: { apt: {packages: [clang-3.8,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test]}} + - env: CLANG_VERSION=3.9 BUILD_TYPE=Release ARCH=32 + addons: { apt: {packages: [clang-3.9,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-trusty-3.9]}} + - env: CLANG_VERSION=3.9 BUILD_TYPE=Release ARCH=64 + addons: { apt: {packages: [clang-3.9,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-trusty-3.9]}} + - env: CLANG_VERSION=4.0 BUILD_TYPE=Release ARCH=32 + addons: { apt: {packages: [clang-4.0,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-trusty-4.0]}} + - env: CLANG_VERSION=4.0 BUILD_TYPE=Release ARCH=64 + addons: { apt: {packages: [clang-4.0,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-trusty-4.0]}} + - env: CLANG_VERSION=5.0 BUILD_TYPE=Release ARCH=32 + addons: { apt: {packages: [clang-5.0,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-trusty-5.0]}} + - env: CLANG_VERSION=5.0 BUILD_TYPE=Release ARCH=64 + addons: { apt: {packages: [clang-5.0,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-trusty-5.0]}} + - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug ARCH=32 + addons: &clang6_32 { apt: {packages: [clang-6.0,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-trusty-6.0]}} + - env: CLANG_VERSION=6.0 BUILD_TYPE=Release ARCH=32 + addons: *clang6_32 + - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug ARCH=64 + addons: &clang6_64 { apt: {packages: [clang-6.0,libstdc++-6-dev] , sources: [ubuntu-toolchain-r-test,llvm-toolchain-trusty-6.0]}} + - env: CLANG_VERSION=6.0 BUILD_TYPE=Release ARCH=64 + addons: *clang6_64 + - env: GCC_VERSION=4.9 BUILD_TYPE=Debug ARCH=32 + addons: { apt: {packages: [g++-4.9-multilib,"linux-libc-dev:i386"] , sources: [ubuntu-toolchain-r-test]}} + - env: GCC_VERSION=4.9 BUILD_TYPE=Debug ARCH=64 + addons: { apt: {packages: [g++-4.9] , sources: [ubuntu-toolchain-r-test]}} + - env: GCC_VERSION=5 BUILD_TYPE=Debug ARCH=32 + addons: { apt: {packages: [g++-5-multilib,"linux-libc-dev:i386"] , sources: [ubuntu-toolchain-r-test]}} + - env: GCC_VERSION=5 BUILD_TYPE=Debug ARCH=64 + addons: { apt: {packages: [g++-5] , sources: [ubuntu-toolchain-r-test]}} + - env: GCC_VERSION=6 BUILD_TYPE=Debug ARCH=32 + addons: { apt: {packages: [g++-6-multilib,"linux-libc-dev:i386"] , sources: [ubuntu-toolchain-r-test]}} + - env: GCC_VERSION=6 BUILD_TYPE=Debug ARCH=64 + addons: { apt: {packages: [g++-6] , sources: [ubuntu-toolchain-r-test]}} + - env: GCC_VERSION=7 BUILD_TYPE=Debug ARCH=32 + addons: &gcc7_32 { apt: {packages: [g++-7-multilib,rpm,doxygen,"linux-libc-dev:i386"] , sources: [ubuntu-toolchain-r-test]}} + - env: GCC_VERSION=7 BUILD_TYPE=Release ARCH=64 + addons: *gcc7_32 + - env: GCC_VERSION=7 BUILD_TYPE=Debug ARCH=64 + addons: &gcc7_64 { apt: {packages: [g++-7,rpm,doxygen] , sources: [ubuntu-toolchain-r-test]}} + - env: GCC_VERSION=7 BUILD_TYPE=Debug ARCH=64 + addons: *gcc7_64 branches: only: - - develop - - master - - /^v\d+\.\d+\.\d+$/ - + - develop + - master + - "/^v\\d+\\.\\d+\\.\\d+$/" before_install: - - | - if [ -n "$GCC_VERSION" ]; then - export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}" GCOV="gcov-${GCC_VERSION}"; - fi - - | - if [ -n "$CLANG_VERSION" ]; then - export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; - fi - +- | + if [ -n "$GCC_VERSION" ]; then + export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}" GCOV="gcov-${GCC_VERSION}"; + fi +- | + if [ -n "$CLANG_VERSION" ]; then + export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; + fi install: - # install latest LCOV (1.9 was failing) - - | - if [[ $TRAVIS_OS_NAME != "osx" ]]; then - cd ${TRAVIS_BUILD_DIR} - wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz - tar xf lcov_1.11.orig.tar.gz - sudo make -C lcov-1.11/ install - gem install coveralls-lcov - lcov --version - fi - # Travis machines have 2 cores - - JOBS=2 - - ############################################################################ - # Install a recent CMake (unless already installed on OS X) - ############################################################################ - - CMAKE_VERSION=3.7.2 - - | - if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then - CMAKE_URL="https://cmake.org/files/v${CMAKE_VERSION%.[0-9]}/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz" - mkdir cmake && travis_retry wget --no-check-certificate -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake - export PATH=${DEPS_DIR}/cmake/bin:${PATH} - else - brew install cmake || brew upgrade cmake - fi - - cmake --version - +- | + if [[ $TRAVIS_OS_NAME != "osx" ]]; then + cd ${TRAVIS_BUILD_DIR} + wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz + tar xf lcov_1.11.orig.tar.gz + sudo make -C lcov-1.11/ install + gem install coveralls-lcov + lcov --version + fi +- JOBS=2 +- CMAKE_VERSION=3.7.2 +- | + if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then + CMAKE_URL="https://cmake.org/files/v${CMAKE_VERSION%.[0-9]}/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz" + mkdir cmake && travis_retry wget --no-check-certificate -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake + export PATH=${DEPS_DIR}/cmake/bin:${PATH} + else + brew install cmake || brew upgrade cmake + fi +- cmake --version before_script: - #- if [[ $TRAVIS_OS_NAME == "osx" ]]; then brew update > /dev/null && brew install mariadb && mysql.server start; fi - - | - if [[ $TRAVIS_OS_NAME != "osx" ]]; then - mysql -e 'create database matador_test;'; - fi - - mkdir build - - cd build - - | - if [ "$GCOV" == "gcov-5" ] && [ "$BUILD_TYPE" == "Debug" ] && [ "$ARCH" == "64" ]; then - cmake -DCMAKE_CXX_COMPILER=${COMPILER} -DARCH=${ARCH} -DGCOV_BINARY=${GCOV} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCOVERAGE=true -DMATADOR_ODBC_TEST=false -DMYSQL_CONNECTION_STRING:STRING="mysql://root@127.0.0.1/matador_test" ..; - lcov --directory include --directory src --directory test --zerocounters - else - cmake -DCMAKE_CXX_COMPILER=${COMPILER} -DARCH=${ARCH} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DMATADOR_ODBC_TEST=false -DMYSQL_CONNECTION_STRING:STRING="mysql://root@127.0.0.1/matador_test" ..; - fi - +- | + if [[ $TRAVIS_OS_NAME != "osx" ]]; then + mysql -e 'create database matador_test;'; + fi +- mkdir build +- cd build +- | + if [ "$GCOV" == "gcov-5" ] && [ "$BUILD_TYPE" == "Debug" ] && [ "$ARCH" == "64" ]; then + cmake -DCMAKE_CXX_COMPILER=${COMPILER} -DARCH=${ARCH} -DGCOV_BINARY=${GCOV} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCOVERAGE=true -DMATADOR_ODBC_TEST=false -DMYSQL_CONNECTION_STRING:STRING="mysql://root@127.0.0.1/matador_test" ..; + lcov --directory include --directory src --directory test --zerocounters + else + cmake -DCMAKE_CXX_COMPILER=${COMPILER} -DARCH=${ARCH} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DMATADOR_ODBC_TEST=false -DMYSQL_CONNECTION_STRING:STRING="mysql://root@127.0.0.1/matador_test" ..; + fi script: - - make - - make test ARGS=-V - +- make +- make test ARGS=-V after_success: - - | - if [ "$GCOV" == "gcov-5" ] && [ "$BUILD_TYPE" == "Debug" ] && [ "$ARCH" == "64" ]; then - cd ${TRAVIS_BUILD_DIR} - type $GCOV - lcov --no-external --base-directory ${TRAVIS_BUILD_DIR} --directory build/src --directory build/test --capture --gcov-tool `which $GCOV` --output-file coverage.info - lcov --remove coverage.info 'build/test/*' 'build/src/*' --gcov-tool `which $GCOV` --output-file coverage.info - lcov --list coverage.info - coveralls-lcov --repo-token=${COVERALLS_TOKEN} coverage.info - fi - +- | + if [ "$GCOV" == "gcov-5" ] && [ "$BUILD_TYPE" == "Debug" ] && [ "$ARCH" == "64" ]; then + cd ${TRAVIS_BUILD_DIR} + type $GCOV + lcov --no-external --base-directory ${TRAVIS_BUILD_DIR} --directory build/src --directory build/test --capture --gcov-tool `which $GCOV` --output-file coverage.info + lcov --remove coverage.info 'build/test/*' 'build/src/*' --gcov-tool `which $GCOV` --output-file coverage.info + lcov --list coverage.info + coveralls-lcov --repo-token=${COVERALLS_TOKEN} coverage.info + fi before_deploy: - - cd ${TRAVIS_BUILD_DIR} - - cmake --build build --target web - - cmake --build build --target package - - export RELEASE_TGZ_FILE=$(ls Package/*.tar.gz) - - export RELEASE_DEB_FILE=$(ls Package/*.deb) - - export RELEASE_RPM_FILE=$(ls Package/*.rpm) - - export RELEASE_PKG_FILE=$(ls Package/*.pkg.tar.xz) - - echo "deploying $RELEASE_TGZ_FILE, $RELEASE_DEB_FILE $RELEASE_PKG_FILE and $RELEASE_RPM_FILE to GitHub releases" +- cd ${TRAVIS_BUILD_DIR} +- cmake --build build --target web +- cmake --build build --target package +- export RELEASE_TGZ_FILE=$(ls Package/*.tar.gz) +- export RELEASE_DEB_FILE=$(ls Package/*.deb) +- export RELEASE_RPM_FILE=$(ls Package/*.rpm) +- echo "deploying $RELEASE_TGZ_FILE, $RELEASE_DEB_FILE and $RELEASE_RPM_FILE to GitHub + releases" +notifications: + email: + recipients: + - sascha.kuehl@gmx.net + on_success: change + on_failure: always deploy: provider: releases - api_key: ${GITHUB_TOKEN} + api_key: + secure: rXDCwgPmhkO4Z14VOrHh89s2aN3Mhi7cuVL5nf6zivwe8YESHQGtxbNOotq/UK2Y2sPkK8Eb+F1OLuxxvnZTOPJTzXP/QYOa+GoRm/YifzkOa3Yz3zE6MD0W3bfyzhSmaUeko+2jOECccrPYtyCjmWQY/Ey/0JvGdunOoqq1sso= file: - - "${RELEASE_TGZ_FILE}" - - "${RELEASE_DEB_FILE}" - - "${RELEASE_RPM_FILE}" - - "${RELEASE_PKG_FILE}" + - "${RELEASE_TGZ_FILE}" + - "${RELEASE_DEB_FILE}" + - "${RELEASE_RPM_FILE}" skip_cleanup: true on: tags: true condition: "$GCC_VERSION = 7 && $BUILD_TYPE = Release" all_branches: true - -notifications: - email: - recipients: - - sascha.kuehl@gmx.net - on_success: change # [always|never|change] # default: change - on_failure: always # [always|never|change] # default: always + repo: zussel/matador diff --git a/CMakeLists.txt b/CMakeLists.txt index 5447adec7..e3ede1303 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,9 +47,7 @@ ELSEIF(MSVC) ENDIF() -MESSAGE(STATUS "Architecture: ${CMAKE_SYSTEM_PROCESSOR}") -MESSAGE(STATUS "Architecture System: ${CMAKE_SYSTEM_NAME}") - +MESSAGE(STATUS "Architecture: ${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_SYSTEM_NAME}") SET(SYSTEM_NAME_LOWER) STRING(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME_LOWER) @@ -112,6 +110,7 @@ SET(BACKENDS SQLite3 MySQL ODBC + PostgreSQL ) FOREACH(backend ${BACKENDS}) @@ -137,7 +136,7 @@ FOREACH(backend ${BACKENDS}) ENDFOREACH(backend) IF (SQLITE3_FOUND) - MESSAGE(STATUS "Adding SQLite3 include directory") + MESSAGE(STATUS "Adding SQLite3 include directory: ${SQLITE3_INCLUDE_DIR}") INCLUDE_DIRECTORIES(${SQLITE3_INCLUDE_DIR}) ELSE () MESSAGE(STATUS "Not adding SQLite3 include directory") diff --git a/appveyor.yml b/appveyor.yml index 5779385d9..6a7f64a25 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -61,7 +61,7 @@ before_build: cd "$env:APPVEYOR_BUILD_FOLDER" mkdir build cd build - cmake -G "$env:generator" -DMATADOR_ODBC=true -DMSSQL_CONNECTION_STRING:STRING="mssql://sa:Password12!@(local)\\SQL2014/matador_test" -DMATADOR_SQLITE3=true -DMATADOR_MYSQL=true -DMYSQL_CONNECTION_STRING:STRING="mysql://root:Password12!@localhost/matador_test" .. + cmake -G "$env:generator" -DMATADOR_ODBC=true -DMATADOR_POSTGRESQL=false -DMSSQL_CONNECTION_STRING:STRING="mssql://sa:Password12!@(local)\\SQL2014/matador_test" -DMATADOR_SQLITE3=true -DMATADOR_MYSQL=true -DMYSQL_CONNECTION_STRING:STRING="mysql://root:Password12!@localhost/matador_test" .. # cmake -G "$env:generator" -DMATADOR_ODBC=true -DMSSQL_CONNECTION_STRING:STRING="mssql://sa:Password12!@(local)\\SQL2014/matador_test" -DMATADOR_SQLITE3=true -DMATADOR_MYSQL=false .. build_script: @@ -80,13 +80,13 @@ after_build: artifacts: - path: Package/matador*.exe name: installer - - path: Package/calc*.zip + - path: Package/matador*.zip name: zipper deploy: provider: GitHub auth_token: - secure: "kz/25t/c0oeOJ3Ux3r+Sy5F4G7YgPmjSrTpgZ73IQDY4N9mYNqH4kAv4+0I0oeh6" + secure: ubPcMpzrx0ulil7eJMpQbO94ufnvHXeeHoXpxr8RAMQXRMShsvlPj4ZE94cZ4T7j artifact: installer,zipper draft: false prerelease: false diff --git a/cmake/FindODBC.cmake b/cmake/FindODBC.cmake deleted file mode 100644 index 1309c1de2..000000000 --- a/cmake/FindODBC.cmake +++ /dev/null @@ -1,64 +0,0 @@ -# -# Find the ODBC driver manager includes and library. -# -# ODBC is an open standard for connecting to different databases in a -# semi-vendor-independent fashion. First you install the ODBC driver -# manager. Then you need a driver for each separate sql you want -# to connect to (unless a generic one works). VTK includes neither -# the driver manager nor the vendor-specific drivers: you have to find -# those yourself. -# -# This module defines -# ODBC_INCLUDE_DIRECTORIES, where to find sql.h -# ODBC_LIBRARIES, the libraries to link against to use ODBC -# ODBC_FOUND. If false, you cannot build anything that requires MySQL. - -# also defined, but not for general use is -# ODBC_LIBRARY, where to find the ODBC driver manager library. - -set(ODBC_FOUND FALSE) - -find_path(ODBC_INCLUDE_DIR sql.h - /usr/include - /usr/include/odbc - /usr/local/include - /usr/local/include/odbc - /usr/local/odbc/include - "C:/Program Files (x86)/Windows Kits/8.1/include/um" - "C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Include" - "C:/Program Files/ODBC/include" - "C:/Program Files/Microsoft SDKs/Windows/v7.0/include" - "C:/Program Files/Microsoft SDKs/Windows/v6.0a/include" - "C:/ODBC/include" - DOC "Specify the directory containing sql.h." -) - -if(MSVC) - # msvc knows where to find sdk libs - set(ODBC_LIBRARY odbc32) -else() - find_library(ODBC_LIBRARY - NAMES iodbc odbc odbcinst odbc32 - PATHS - /usr/lib - /usr/lib/odbc - /usr/local/lib - /usr/local/lib/odbc - /usr/local/odbc/lib - "C:/Program Files (x86)/Windows Kits/8.1/Lib/winv6.3/um/x86/" - "C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib" - "C:/Program Files/ODBC/lib" - "C:/ODBC/lib/debug" - DOC "Specify the ODBC driver manager library here." - ) -endif() - -if(ODBC_LIBRARY) - if(ODBC_INCLUDE_DIR) - set( ODBC_FOUND 1 ) - endif() -endif() - -set(ODBC_LIBRARIES ${ODBC_LIBRARY}) - -mark_as_advanced(ODBC_FOUND ODBC_LIBRARY ODBC_EXTRA_LIBRARIES ODBC_INCLUDE_DIR) diff --git a/cmake/FindSQLite3.cmake b/cmake/FindSQLite3.cmake index 0b0093b3a..06c05ccce 100644 --- a/cmake/FindSQLite3.cmake +++ b/cmake/FindSQLite3.cmake @@ -6,46 +6,46 @@ set(PROGRAMFILES $ENV{ProgramFiles}) if (DEFINED ENV{ProgramW6432}) - set(PROGRAMFILES $ENV{ProgramW6432}) + set(PROGRAMFILES $ENV{ProgramW6432}) endif() IF (WIN32) - FIND_PATH( SQLITE3_INCLUDE_DIR sqlite3.h - $ENV{PROGRAMFILES}/SQLite/include/ - ${PROGRAMFILES}/SQLite/include/ - DOC "The directory where sqlite3.h resides" - ) + FIND_PATH( SQLITE3_INCLUDE_DIR sqlite3.h + $ENV{PROGRAMFILES}/SQLite/include/ + ${PROGRAMFILES}/SQLite/include/ + DOC "The directory where sqlite3.h resides" + ) - FIND_LIBRARY( SQLITE3_LIBRARY - NAMES sqlite3 - PATHS - $ENV{PROGRAMFILES}/SQLite/lib/ - ${PROGRAMFILES}/SQLite/lib/ - DOC "The SQLite3 library" - ) + FIND_LIBRARY( SQLITE3_LIBRARY + NAMES sqlite3 + PATHS + $ENV{PROGRAMFILES}/SQLite/lib/ + ${PROGRAMFILES}/SQLite/lib/ + DOC "The SQLite3 library" + ) ELSE (WIN32) - FIND_PATH( SQLITE3_INCLUDE_DIR sqlite3.h - /usr/include - /usr/local/include - /sw/include - /opt/local/include - DOC "The directory where sqlite3.h resides") - FIND_LIBRARY( SQLITE3_LIBRARY - NAMES sqlite3 - PATHS - /usr/lib64 - /usr/lib - /usr/local/lib64 - /usr/local/lib - /sw/lib - /opt/local/lib - DOC "The SQLite3 library") + FIND_PATH( SQLITE3_INCLUDE_DIR sqlite3.h + /usr/include + /usr/local/include + /sw/include + /opt/local/include + DOC "The directory where sqlite3.h resides") + FIND_LIBRARY( SQLITE3_LIBRARY + NAMES sqlite3 + PATHS + /usr/lib64 + /usr/lib + /usr/local/lib64 + /usr/local/lib + /sw/lib + /opt/local/lib + DOC "The SQLite3 library") ENDIF (WIN32) IF (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY) - SET( SQLITE3_FOUND TRUE CACHE STRING "Set to TRUE if SQLite3 is found, FALSE otherwise") + SET( SQLITE3_FOUND TRUE CACHE STRING "Set to TRUE if SQLite3 is found, FALSE otherwise") ELSE (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY) - SET( SQLITE3_FOUND FALSE CACHE STRING "Set to TRUE if SQLite3 is found, FALSE otherwise") + SET( SQLITE3_FOUND FALSE CACHE STRING "Set to TRUE if SQLite3 is found, FALSE otherwise") ENDIF (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY) -MARK_AS_ADVANCED( SQLITE3_FOUND ) +MARK_AS_ADVANCED( SQLITE3_FOUND ) \ No newline at end of file diff --git a/include/matador/db/mssql/mssql_statement.hpp b/include/matador/db/mssql/mssql_statement.hpp index bc1386300..c0aa9b266 100644 --- a/include/matador/db/mssql/mssql_statement.hpp +++ b/include/matador/db/mssql/mssql_statement.hpp @@ -140,8 +140,8 @@ class mssql_statement : public detail::statement_impl bool bind_null_ = false; - SQLHANDLE stmt_; - SQLHANDLE db_; + SQLHANDLE stmt_ = nullptr; + SQLHANDLE db_ = nullptr; }; } diff --git a/include/matador/db/mysql/mysql_connection.hpp b/include/matador/db/mysql/mysql_connection.hpp index 40cf6de36..08be3c350 100644 --- a/include/matador/db/mysql/mysql_connection.hpp +++ b/include/matador/db/mysql/mysql_connection.hpp @@ -46,6 +46,7 @@ namespace matador { namespace mysql { class mysql_statement; +class mysql_result; /** * @class mysql_database @@ -81,7 +82,7 @@ class OOS_MYSQL_API mysql_connection : public connection_impl void close() override; detail::result_impl* execute(const matador::sql &stmt) override; - detail::result_impl* execute(const std::string &stmt) override; + detail::result_impl* execute(const std::string &sql) override; detail::statement_impl* prepare(const matador::sql &stmt) override; void begin() override; @@ -97,7 +98,10 @@ class OOS_MYSQL_API mysql_connection : public connection_impl basic_dialect* dialect() override; private: - MYSQL mysql_; + mysql_result* execute_internal(const std::string &stmt); + +private: + MYSQL mysql_ = MYSQL(); std::string db_; bool is_open_; mysql_dialect dialect_; diff --git a/include/matador/db/mysql/mysql_result.hpp b/include/matador/db/mysql/mysql_result.hpp index 9c0fcd962..624c0b751 100644 --- a/include/matador/db/mysql/mysql_result.hpp +++ b/include/matador/db/mysql/mysql_result.hpp @@ -83,19 +83,11 @@ class mysql_result : public detail::result_impl bool finalize_fetch() override; private: -// struct result_deleter -// { -// void operator()(MYSQL_RES *res) const { -// if (res) { -// mysql_free_result(res); -// } -// } -// }; - size_type affected_rows_; - size_type rows_; - size_type fields_; + size_type affected_rows_ = 0; + size_type rows_ = 0; + size_type fields_ = 0; MYSQL_ROW row_; - MYSQL_RES *res_; + MYSQL_RES *res_ = nullptr; }; } diff --git a/include/matador/db/mysql/mysql_statement.hpp b/include/matador/db/mysql/mysql_statement.hpp index a13d38ec6..11b26851a 100644 --- a/include/matador/db/mysql/mysql_statement.hpp +++ b/include/matador/db/mysql/mysql_statement.hpp @@ -20,7 +20,6 @@ #include "matador/sql/statement_impl.hpp" -#include "matador/utils/identifier.hpp" #include "matador/utils/varchar.hpp" #include "matador/db/mysql/mysql_result_info.hpp" @@ -41,6 +40,7 @@ namespace matador { class varchar_base; class time; class date; +class basic_identifier; namespace mysql { diff --git a/include/matador/db/postgresql/postgresql_connection.hpp b/include/matador/db/postgresql/postgresql_connection.hpp new file mode 100644 index 000000000..26f9db607 --- /dev/null +++ b/include/matador/db/postgresql/postgresql_connection.hpp @@ -0,0 +1,105 @@ +// +// Created by sascha on 24.05.19. +// + +#ifndef MATADOR_POSTGRESQL_CONNECTION_HPP +#define MATADOR_POSTGRESQL_CONNECTION_HPP + +#ifdef _MSC_VER +#ifdef matador_postgresql_EXPORTS + #define MATADOR_POSTGRESQL_API __declspec(dllexport) + #else + #define MATADOR_POSTGRESQL_API __declspec(dllimport) + #endif + #pragma warning(disable: 4355) +#else +#define MATADOR_POSTGRESQL_API +#endif + +#include "matador/sql/connection_impl.hpp" +#include "matador/sql/types.hpp" + +#include "matador/db/postgresql/postgresql_dialect.hpp" + +#include + +namespace matador { + +namespace postgresql { + +class postgresql_statement; +class postgresql_result; + +/** + * @class mysql_database + * @brief The mysql sql backend + * + * This class is the sqlite sql backend + * class. It provides the mysql version 4 and higher + */ +class MATADOR_POSTGRESQL_API postgresql_connection : public connection_impl +{ +public: + postgresql_connection(); + ~postgresql_connection() override; + + /** + * Returns true if the sql is open + * + * @return True on open sql connection. + */ + bool is_open() const override; + + virtual unsigned long last_inserted_id(); + + /** + * Return the raw pointer to the sqlite3 + * database struct. + * + * @return The raw sqlite3 pointer. + */ +// MYSQL* handle(); + + void open(const std::string &db) override; + void close() override; + + detail::result_impl* execute(const matador::sql &stmt) override; + detail::result_impl* execute(const std::string &stmt) override; + detail::statement_impl* prepare(const matador::sql &stmt) override; + + void begin() override; + void commit() override; + void rollback() override; + + std::string type() const override; + std::string version() const override; + + bool exists(const std::string &table_name) override; + std::vector describe(const std::string &table) override; + + basic_dialect* dialect() override; + + PGconn* handle() const; + +private: + postgresql_result* execute_internal(const std::string &stmt); + +private: + std::string db_; + bool is_open_; + postgresql_dialect dialect_; + PGconn *conn_ = nullptr; +}; + +} + +} + +extern "C" +{ +MATADOR_POSTGRESQL_API matador::connection_impl* create_database(); + +MATADOR_POSTGRESQL_API void destroy_database(matador::connection_impl *db); +} + +#endif //MATADOR_POSTGRESQL_CONNECTION_HPP diff --git a/include/matador/db/postgresql/postgresql_dialect.hpp b/include/matador/db/postgresql/postgresql_dialect.hpp new file mode 100644 index 000000000..3ebd8ab1e --- /dev/null +++ b/include/matador/db/postgresql/postgresql_dialect.hpp @@ -0,0 +1,30 @@ +// +// Created by sascha on 24.05.19. +// + +#ifndef MATADOR_POSTGRESQL_DIALECT_HPP +#define MATADOR_POSTGRESQL_DIALECT_HPP + +#include + +namespace matador { +namespace postgresql { + +class postgresql_dialect : public basic_dialect +{ +public: + postgresql_dialect(); + + const char *type_string(matador::data_type type) const override; + + data_type string_type(const char *type) const; + + dialect_traits::identifier identifier_escape_type() const override; + + std::string next_placeholder() const override; +}; + +} +} + +#endif //MATADOR_POSTGRESQL_DIALECT_HPP diff --git a/include/matador/db/postgresql/postgresql_dialect_compiler.hpp b/include/matador/db/postgresql/postgresql_dialect_compiler.hpp new file mode 100644 index 000000000..8583d70c5 --- /dev/null +++ b/include/matador/db/postgresql/postgresql_dialect_compiler.hpp @@ -0,0 +1,42 @@ +// +// Created by sascha on 21.06.19. +// + +#ifndef MATADOR_POSTGRESQL_DIALECT_COMPILER_HPP +#define MATADOR_POSTGRESQL_DIALECT_COMPILER_HPP + +#include "matador/sql/basic_dialect_compiler.hpp" +#include "matador/sql/dialect_token.hpp" + +namespace matador { +namespace postgresql { + +class postgresql_dialect_compiler : public detail::basic_dialect_compiler +{ +public: + void visit(const matador::detail::select &select1) override; + void visit(const matador::detail::update &update1) override; + void visit(const matador::detail::remove &remove1) override; + void visit(const matador::detail::tablename &tab) override; + void visit(const matador::detail::from &from1) override; + + void visit(const matador::detail::where &where1) override; + void visit(const matador::detail::basic_column_condition &) override; + void visit(const matador::detail::top &limit) override; + +protected: + void on_compile_start() override; + +private: + bool is_update = false; + bool is_delete = false; + bool has_condition_column_name_ = false; + + std::string tablename_; + std::string condition_column_name_; + token_list_t::iterator where_; +}; + +} +} +#endif //MATADOR_POSTGRESQL_DIALECT_COMPILER_HPP diff --git a/include/matador/db/postgresql/postgresql_exception.hpp b/include/matador/db/postgresql/postgresql_exception.hpp new file mode 100644 index 000000000..c1b1ec438 --- /dev/null +++ b/include/matador/db/postgresql/postgresql_exception.hpp @@ -0,0 +1,52 @@ +// +// Created by sascha on 24.05.19. +// + +#ifndef MATADOR_POSTGRESQL_EXCEPTION_HPP +#define MATADOR_POSTGRESQL_EXCEPTION_HPP + +#include +#include + +#include "matador/sql/sql_exception.hpp" + +namespace matador { + +namespace postgresql { + +#define THROW_POSTGRESQL_ERROR(db, source, msg) \ + do { \ + std::stringstream what; \ + what << msg; \ + throw postgresql_exception(db, source, what.str()); \ + } while (false) + +void throw_error(const std::string &source, const std::string &sql = ""); + +void throw_error(int ec, PGconn *db, const std::string &source, const std::string &sql = ""); + +//void throw_stmt_error(int ec, MYSQL_STMT *stmt, const std::string &source, const std::string &sql = ""); + +class postgresql_exception : public sql_exception +{ +public: + postgresql_exception(const std::string &source, const std::string &what); + postgresql_exception(PGconn *db, const std::string &source, const std::string &what); + + ~postgresql_exception() noexcept override = default; +}; + +class postgresql_stmt_exception : public sql_exception +{ +public: + explicit postgresql_stmt_exception(const std::string &what); +// postgresql_stmt_exception(MYSQL_STMT *stmt, const std::string &source, const std::string &what); + + ~postgresql_stmt_exception() noexcept override = default; +}; + +} + +} + +#endif //MATADOR_POSTGRESQL_EXCEPTION_HPP diff --git a/include/matador/db/postgresql/postgresql_getvalue.hpp b/include/matador/db/postgresql/postgresql_getvalue.hpp new file mode 100644 index 000000000..8830aee88 --- /dev/null +++ b/include/matador/db/postgresql/postgresql_getvalue.hpp @@ -0,0 +1,108 @@ +// +// Created by sascha on 06.06.19. +// + +#ifndef MATADOR_POSTGRESQL_GETVALUE_HPP +#define MATADOR_POSTGRESQL_GETVALUE_HPP + +#include "matador/utils/date.hpp" +#include "matador/utils/time.hpp" +#include "matador/utils/string.hpp" + +#include +#include + +namespace matador { +namespace detail { + +//template < typename T > +//void get_value(PGresult *res, size_t row, size_t col, T &val); + +template < typename T, typename std::enable_if_t::value && std::is_signed::value && !std::is_same::value>* = nullptr> +void get_value(PGresult *res, size_t row, size_t col, T &val) +{ + auto value = PQgetvalue(res, row, col); + + if (strlen(value) == 0) { + return; + } + char *end; + val = (T)strtol(value, &end, 10); +} + +template < typename T, typename std::enable_if_t::value && std::is_unsigned::value && !std::is_same::value>* = nullptr> +void get_value(PGresult *res, size_t row, size_t col, T &val) +{ + auto value = PQgetvalue(res, row, col); + + if (strlen(value) == 0) { + return; + } + char *end; + val = (T)strtoul(value, &end, 10); +} + +template < typename T, typename std::enable_if_t::value>* = nullptr> +void get_value(PGresult *res, size_t row, size_t col, T &val) +{ + auto value = PQgetvalue(res, row, col); + + if (strlen(value) == 0) { + return; + } + char *end; + val = (T)strtoul(value, &end, 10) > 0; +} + +template < typename T, typename std::enable_if_t::value>* = nullptr> +void get_value(PGresult *res, size_t row, size_t col, T &val) +{ + auto value = PQgetvalue(res, row, col); + + if (strlen(value) > 1) { + val = value[0]; + } +} + +template < typename T, typename std::enable_if_t::value>* = nullptr> +void get_value(PGresult *res, size_t row, size_t col, T &val) +{ + auto value = PQgetvalue(res, row, col); + + if (strlen(value) == 0) { + return; + } + char *end; + val = (T)strtof(value, &end); +} + +template < typename T, typename std::enable_if_t::value>* = nullptr> +void get_value(PGresult *res, size_t row, size_t col, T &val) +{ + val.assign(PQgetvalue(res, row, col)); +} + +template < typename T, typename std::enable_if_t::value>* = nullptr> +void get_value(PGresult *res, size_t row, size_t col, T &val) +{ + val = PQgetvalue(res, row, col); +} + +template < typename T, typename std::enable_if_t::value>* = nullptr> +void get_value(PGresult *res, size_t row, size_t col, T &val) +{ + val = matador::time::parse(PQgetvalue(res, row, col), "%Y-%m-%d %T.%f"); +} + +template < typename T, typename std::enable_if_t::value>* = nullptr> +void get_value(PGresult *res, size_t row, size_t col, T &val) +{ + val.set(PQgetvalue(res, row, col), date_format::ISO8601); +} + +void get_value(PGresult *res, size_t row, size_t col, char *val, size_t s); + +} +} + +#endif //MATADOR_POSTGRESQL_GETVALUE_HPP diff --git a/include/matador/db/postgresql/postgresql_prepared_result.hpp b/include/matador/db/postgresql/postgresql_prepared_result.hpp new file mode 100644 index 000000000..abe0e3aa9 --- /dev/null +++ b/include/matador/db/postgresql/postgresql_prepared_result.hpp @@ -0,0 +1,78 @@ +// +// Created by sascha on 11.06.19. +// + +#ifndef MATADOR_POSTGRESQL_PREPARED_RESULT_HPP +#define MATADOR_POSTGRESQL_PREPARED_RESULT_HPP + +#include "matador/sql/result_impl.hpp" + +#include + +namespace matador { +namespace postgresql { + +class postgresql_statement; + +class postgresql_prepared_result : public detail::result_impl +{ +public: + postgresql_prepared_result(const postgresql_prepared_result &) = delete; + postgresql_prepared_result &operator=(const postgresql_prepared_result &) = delete; + +public: + typedef detail::result_impl::size_type size_type; + +public: + postgresql_prepared_result(postgresql_statement *owner, PGresult *s); + ~postgresql_prepared_result() override; + + const char* column(size_type c) const override; + bool fetch() override; + + size_type affected_rows() const override; + size_type result_rows() const override; + size_type fields() const override; + + int transform_index(int index) const override; + + void serialize(const char *id, char &x) override; + void serialize(const char *id, short &x) override; + void serialize(const char *id, int &x) override; + void serialize(const char *id, long &x) override; + void serialize(const char *id, unsigned char &x) override; + void serialize(const char *id, unsigned short &x) override; + void serialize(const char *id, unsigned int &x) override; + void serialize(const char *id, unsigned long &x) override; + void serialize(const char *id, bool &x) override; + void serialize(const char *id, float &x) override; + void serialize(const char *id, double &x) override; + void serialize(const char *id, char *x, size_t s) override; + void serialize(const char *id, matador::date &x) override; + void serialize(const char *id, matador::time &x) override; + void serialize(const char *id, std::string &x) override; + void serialize(const char *id, varchar_base &x) override; + void serialize(const char *id, basic_identifier &x) override; + void serialize(const char *id, identifiable_holder &x, cascade_type) override; + +protected: + bool needs_bind() override; + bool finalize_bind() override; + + bool prepare_fetch() override; + bool finalize_fetch() override; + +private: + PGresult *res_ = nullptr; + size_type row_ = 0; + size_type column_ = 0; + + size_type affected_rows_ = 0; + size_type rows_ = 0; + size_type fields_ = 0; +}; + +} +} + +#endif //MATADOR_POSTGRESQL_PREPARED_RESULT_HPP diff --git a/include/matador/db/postgresql/postgresql_result.hpp b/include/matador/db/postgresql/postgresql_result.hpp new file mode 100644 index 000000000..403f2edfa --- /dev/null +++ b/include/matador/db/postgresql/postgresql_result.hpp @@ -0,0 +1,91 @@ +// +// Created by sascha on 29.05.19. +// + +#ifndef MATADOR_POSTGRESQL_RESULT_HPP +#define MATADOR_POSTGRESQL_RESULT_HPP + +#ifdef _MSC_VER +#ifdef matador_postgresql_EXPORTS + #define MATADOR_POSTGRESQL_API __declspec(dllexport) + #else + #define MATADOR_POSTGRESQL_API __declspec(dllimport) + #endif + #pragma warning(disable: 4355) +#else +#define MATADOR_POSTGRESQL_API +#endif + +#include + +#include "matador/sql/result_impl.hpp" + +namespace matador { + +class row; +class serializer; + +namespace postgresql { + +class MATADOR_POSTGRESQL_API postgresql_result : public detail::result_impl +{ +public: + postgresql_result(const postgresql_result&) = delete; + postgresql_result& operator=(const postgresql_result&) = delete; + +public: + typedef detail::result_impl::size_type size_type; + +public: + explicit postgresql_result(PGresult *res); + ~postgresql_result() override; + + const char* column(size_type c) const override; + bool fetch() override; + + size_type affected_rows() const override; + size_type result_rows() const override; + size_type fields() const override; + + int transform_index(int index) const override; + + PGresult* result_handle(); + +protected: + void serialize(const char *id, char &x) override; + void serialize(const char *id, short &x) override; + void serialize(const char *id, int &x) override; + void serialize(const char *id, long &x) override; + void serialize(const char *id, unsigned char &x) override; + void serialize(const char *id, unsigned short &x) override; + void serialize(const char *id, unsigned int &x) override; + void serialize(const char *id, unsigned long &x) override; + void serialize(const char *id, bool &x) override; + void serialize(const char *id, float &x) override; + void serialize(const char *id, double &x) override; + void serialize(const char *id, char *x, size_t s) override; + void serialize(const char *id, varchar_base &x) override; + void serialize(const char *id, std::string &x) override; + void serialize(const char *id, matador::date &x) override; + void serialize(const char *id, matador::time &x) override; + void serialize(const char *id, matador::basic_identifier &x) override; + void serialize(const char *id, matador::identifiable_holder &x, cascade_type) override; + +protected: + bool prepare_fetch() override; + bool finalize_fetch() override; + +private: + size_type affected_rows_; + size_type rows_; + size_type fields_; + + size_type column_ = 0; + size_type pos_ = 0; + + PGresult *res_ = nullptr; +}; + +} +} +#endif //MATADOR_POSTGRESQL_RESULT_HPP diff --git a/include/matador/db/postgresql/postgresql_statement.hpp b/include/matador/db/postgresql/postgresql_statement.hpp new file mode 100644 index 000000000..1910d4d46 --- /dev/null +++ b/include/matador/db/postgresql/postgresql_statement.hpp @@ -0,0 +1,77 @@ +// +// Created by sascha on 03.06.19. +// + +#ifndef MATADOR_POSTGRESQL_STATEMENT_HPP +#define MATADOR_POSTGRESQL_STATEMENT_HPP + +#include "matador/sql/statement_impl.hpp" + +#include + +namespace matador { + +class varchar_base; + +class basic_identifier; + +namespace postgresql { + +class postgresql_connection; + +class postgresql_statement : public matador::detail::statement_impl +{ +public: + postgresql_statement(postgresql_connection &db, const matador::sql &stmt); + postgresql_statement(const postgresql_statement &x); + postgresql_statement& operator=(const postgresql_statement &x); + ~postgresql_statement() override; + + void clear() override; + + detail::result_impl *execute() override; + + void reset() override; + +protected: + void serialize(const char *id, char &x) override; + void serialize(const char *id, short &x) override; + void serialize(const char *id, int &x) override; + void serialize(const char *id, long &x) override; + void serialize(const char *id, unsigned char &x) override; + void serialize(const char *id, unsigned short &x) override; + void serialize(const char *id, unsigned int &x) override; + void serialize(const char *id, unsigned long &x) override; + void serialize(const char *id, float &x) override; + void serialize(const char *id, double &x) override; + void serialize(const char *id, bool &x) override; + void serialize(const char *id, char *x, size_t s) override; + void serialize(const char *id, varchar_base &x) override; + void serialize(const char *id, std::string &x) override; + void serialize(const char *id, matador::date &x) override; + void serialize(const char *id, matador::time &x) override; + void serialize(const char *id, basic_identifier &x) override; + void serialize(const char *id, identifiable_holder &x, cascade_type) override; + +private: + std::string generate_statement_name(const matador::sql &stmt); + +private: + postgresql_connection &db_; + size_t result_size; + size_t host_size; + + std::vector host_strings_; + std::vector host_params_; + + std::string name_; + + static std::unordered_map statement_name_map_; + + PGresult *res_ = nullptr; +}; + +} +} + +#endif //MATADOR_POSTGRESQL_STATEMENT_HPP diff --git a/include/matador/db/sqlite/sqlite_connection.hpp b/include/matador/db/sqlite/sqlite_connection.hpp index 9243f2321..bdcc027f7 100644 --- a/include/matador/db/sqlite/sqlite_connection.hpp +++ b/include/matador/db/sqlite/sqlite_connection.hpp @@ -44,6 +44,7 @@ class prototype_node; namespace sqlite { class sqlite_statement; +class sqlite_result; /** * @class sqlite_database @@ -56,35 +57,35 @@ class OOS_SQLITE_API sqlite_connection : public connection_impl { public: sqlite_connection(); - virtual ~sqlite_connection(); + ~sqlite_connection() override; /** * Returns true if the sql is open * * @return True on open sql connection. */ - virtual bool is_open() const override; + bool is_open() const override; - virtual unsigned long last_inserted_id(); + unsigned long last_inserted_id(); - virtual void open(const std::string &db) override; - virtual void close() override; + void open(const std::string &db) override; + void close() override; - virtual detail::result_impl* execute(const matador::sql &stmt) override; - virtual detail::result_impl* execute(const std::string &stmt) override; - virtual detail::statement_impl* prepare(const matador::sql &stmt) override; + detail::result_impl* execute(const matador::sql &stmt) override; + detail::result_impl* execute(const std::string &stmt) override; + detail::statement_impl* prepare(const matador::sql &stmt) override; - virtual void begin() override; - virtual void commit() override; - virtual void rollback() override; + void begin() override; + void commit() override; + void rollback() override; - virtual std::string type() const override; - virtual std::string version() const override; + std::string type() const override; + std::string version() const override; - virtual bool exists(const std::string &tablename) override; - virtual std::vector describe(const std::string &table) override; + bool exists(const std::string &table_name) override; + std::vector describe(const std::string &table) override; - virtual basic_dialect* dialect() override; + basic_dialect* dialect() override; /** * Return the raw pointer to the sqlite3 @@ -95,6 +96,8 @@ class OOS_SQLITE_API sqlite_connection : public connection_impl sqlite3* handle(); private: + sqlite_result* execute_internal(const std::string &stmt); + static int parse_result(void* param, int column_count, char** values, char** columns); private: diff --git a/include/matador/db/sqlite/sqlite_dialect_compiler.hpp b/include/matador/db/sqlite/sqlite_dialect_compiler.hpp index 36b63a5fb..22834cacf 100644 --- a/include/matador/db/sqlite/sqlite_dialect_compiler.hpp +++ b/include/matador/db/sqlite/sqlite_dialect_compiler.hpp @@ -18,17 +18,17 @@ class sqlite_dialect; class sqlite_dialect_compiler : public detail::basic_dialect_compiler { public: - virtual void visit(const matador::detail::select &select1) override; - virtual void visit(const matador::detail::update &update1) override; - virtual void visit(const matador::detail::remove &remove1) override; - virtual void visit(const matador::detail::tablename &tab) override; - virtual void visit(const matador::detail::from &from1) override; + void visit(const matador::detail::select &select1) override; + void visit(const matador::detail::update &update1) override; + void visit(const matador::detail::remove &remove1) override; + void visit(const matador::detail::tablename &tab) override; + void visit(const matador::detail::from &from1) override; - virtual void visit(const matador::detail::where &where1) override; - virtual void visit(const matador::detail::top &top1) override; + void visit(const matador::detail::where &where1) override; + void visit(const matador::detail::top &top1) override; protected: - virtual void on_compile_start() override; + void on_compile_start() override; private: bool is_update = false; diff --git a/include/matador/db/sqlite/sqlite_prepared_result.hpp b/include/matador/db/sqlite/sqlite_prepared_result.hpp index d8659baad..db97e07d4 100644 --- a/include/matador/db/sqlite/sqlite_prepared_result.hpp +++ b/include/matador/db/sqlite/sqlite_prepared_result.hpp @@ -13,7 +13,7 @@ namespace sqlite { class sqlite_prepared_result : public matador::detail::result_impl { -private: +public: sqlite_prepared_result(const sqlite_prepared_result &) = delete; sqlite_prepared_result &operator=(const sqlite_prepared_result &) = delete; @@ -22,40 +22,40 @@ class sqlite_prepared_result : public matador::detail::result_impl public: sqlite_prepared_result(sqlite3_stmt *stmt, int rs); - virtual ~sqlite_prepared_result(); + ~sqlite_prepared_result() override = default; - virtual const char *column(size_type c) const override; - virtual bool fetch() override; + const char *column(size_type c) const override; + bool fetch() override; size_type affected_rows() const override; size_type result_rows() const override; size_type fields() const override; - virtual int transform_index(int index) const override; + int transform_index(int index) const override; protected: - virtual bool prepare_fetch() override; + bool prepare_fetch() override; - virtual bool finalize_fetch() override; + bool finalize_fetch() override; protected: - virtual void serialize(const char *id, char &x) override; - virtual void serialize(const char *id, short &x) override; - virtual void serialize(const char *id, int &x) override; - virtual void serialize(const char *id, long &x) override; - virtual void serialize(const char *id, unsigned char &x) override; - virtual void serialize(const char *id, unsigned short &x) override; - virtual void serialize(const char *id, unsigned int &x) override; - virtual void serialize(const char *id, unsigned long &x) override; - virtual void serialize(const char *id, float &x) override; - virtual void serialize(const char *id, double &x) override; - virtual void serialize(const char *id, bool &x) override; - virtual void serialize(const char *id, char *x, size_t s) override; - virtual void serialize(const char *id, varchar_base &x) override; - virtual void serialize(const char *id, std::string &x) override; - virtual void serialize(const char *id, matador::date &x) override; - virtual void serialize(const char *id, matador::time &x) override; - virtual void serialize(const char *id, basic_identifier &x) override; - virtual void serialize(const char *id, identifiable_holder&x, cascade_type) override; + void serialize(const char *id, char &x) override; + void serialize(const char *id, short &x) override; + void serialize(const char *id, int &x) override; + void serialize(const char *id, long &x) override; + void serialize(const char *id, unsigned char &x) override; + void serialize(const char *id, unsigned short &x) override; + void serialize(const char *id, unsigned int &x) override; + void serialize(const char *id, unsigned long &x) override; + void serialize(const char *id, float &x) override; + void serialize(const char *id, double &x) override; + void serialize(const char *id, bool &x) override; + void serialize(const char *id, char *x, size_t s) override; + void serialize(const char *id, varchar_base &x) override; + void serialize(const char *id, std::string &x) override; + void serialize(const char *id, matador::date &x) override; + void serialize(const char *id, matador::time &x) override; + void serialize(const char *id, basic_identifier &x) override; + void serialize(const char *id, identifiable_holder&x, cascade_type) override; private: int ret_; diff --git a/include/matador/db/sqlite/sqlite_result.hpp b/include/matador/db/sqlite/sqlite_result.hpp index ea413e858..0bda60f83 100644 --- a/include/matador/db/sqlite/sqlite_result.hpp +++ b/include/matador/db/sqlite/sqlite_result.hpp @@ -31,7 +31,7 @@ namespace sqlite { class sqlite_result : public detail::result_impl { -private: +public: sqlite_result(const sqlite_result&) = delete; sqlite_result& operator=(const sqlite_result&) = delete; @@ -39,43 +39,43 @@ class sqlite_result : public detail::result_impl typedef detail::result_impl::size_type size_type; public: - sqlite_result(); - virtual ~sqlite_result(); + sqlite_result() = default; + ~sqlite_result() override; - virtual const char* column(size_type c) const override; - virtual bool fetch() override; - virtual size_type affected_rows() const override; - virtual size_type result_rows() const override; - virtual size_type fields() const override; + const char* column(size_type c) const override; + bool fetch() override; + size_type affected_rows() const override; + size_type result_rows() const override; + size_type fields() const override; - virtual int transform_index(int index) const override; + int transform_index(int index) const override; void push_back(char **row_values, int column_count); protected: - virtual bool prepare_fetch() override; + bool prepare_fetch() override; - virtual bool finalize_fetch() override; + bool finalize_fetch() override; protected: - virtual void serialize(const char*, char&) override; - virtual void serialize(const char*, short&) override; - virtual void serialize(const char*, int&) override; - virtual void serialize(const char*, long&) override; - virtual void serialize(const char*, unsigned char&) override; - virtual void serialize(const char*, unsigned short&) override; - virtual void serialize(const char*, unsigned int&) override; - virtual void serialize(const char*, unsigned long&) override; - virtual void serialize(const char*, bool&) override; - virtual void serialize(const char*, float&) override; - virtual void serialize(const char*, double&) override; - virtual void serialize(const char*, char *, size_t) override; - virtual void serialize(const char*, std::string&) override; - virtual void serialize(const char*, matador::varchar_base&) override; - virtual void serialize(const char*, matador::time&) override; - virtual void serialize(const char*, matador::date&) override; - virtual void serialize(const char*, matador::basic_identifier &x) override; - virtual void serialize(const char*, matador::identifiable_holder &x, cascade_type) override; + void serialize(const char*, char&) override; + void serialize(const char*, short&) override; + void serialize(const char*, int&) override; + void serialize(const char*, long&) override; + void serialize(const char*, unsigned char&) override; + void serialize(const char*, unsigned short&) override; + void serialize(const char*, unsigned int&) override; + void serialize(const char*, unsigned long&) override; + void serialize(const char*, bool&) override; + void serialize(const char*, float&) override; + void serialize(const char*, double&) override; + void serialize(const char*, char *, size_t) override; + void serialize(const char*, std::string&) override; + void serialize(const char*, matador::varchar_base&) override; + void serialize(const char*, matador::time&) override; + void serialize(const char*, matador::date&) override; + void serialize(const char*, matador::basic_identifier &x) override; + void serialize(const char*, matador::identifiable_holder &x, cascade_type) override; private: friend class sqlite_connection; @@ -90,7 +90,7 @@ class sqlite_result : public detail::result_impl t_result::size_type pos_ = 0; t_result::size_type column_ = 0; - size_type fields_; + size_type fields_ = 0; }; } diff --git a/include/matador/db/sqlite/sqlite_statement.hpp b/include/matador/db/sqlite/sqlite_statement.hpp index 22f780c82..c7d5ac707 100644 --- a/include/matador/db/sqlite/sqlite_statement.hpp +++ b/include/matador/db/sqlite/sqlite_statement.hpp @@ -38,32 +38,32 @@ class sqlite_connection; class sqlite_statement : public matador::detail::statement_impl { public: - sqlite_statement(sqlite_connection &db, const std::string stmt); - virtual ~sqlite_statement(); + sqlite_statement(sqlite_connection &db, const std::string &stmt); + ~sqlite_statement() override; - virtual void clear(); - virtual detail::result_impl* execute(); - virtual void reset(); + void clear() override; + detail::result_impl* execute() override; + void reset() override; protected: - virtual void serialize(const char *id, char &x); - virtual void serialize(const char *id, short &x); - virtual void serialize(const char *id, int &x); - virtual void serialize(const char *id, long &x); - virtual void serialize(const char *id, unsigned char &x); - virtual void serialize(const char *id, unsigned short &x); - virtual void serialize(const char *id, unsigned int &x); - virtual void serialize(const char *id, unsigned long &x); - virtual void serialize(const char *id, float &x); - virtual void serialize(const char *id, double &x); - virtual void serialize(const char *id, bool &x); - virtual void serialize(const char *id, char *x, size_t s); - virtual void serialize(const char *id, varchar_base &x); - virtual void serialize(const char *id, std::string &x); - virtual void serialize(const char *id, matador::date &x); - virtual void serialize(const char *id, matador::time &x); - virtual void serialize(const char *id, basic_identifier &x); - virtual void serialize(const char *id, identifiable_holder&x, cascade_type); + void serialize(const char *id, char &x) override; + void serialize(const char *id, short &x) override; + void serialize(const char *id, int &x) override; + void serialize(const char *id, long &x) override; + void serialize(const char *id, unsigned char &x) override; + void serialize(const char *id, unsigned short &x) override; + void serialize(const char *id, unsigned int &x) override; + void serialize(const char *id, unsigned long &x) override; + void serialize(const char *id, float &x) override; + void serialize(const char *id, double &x) override; + void serialize(const char *id, bool &x) override; + void serialize(const char *id, char *x, size_t s) override; + void serialize(const char *id, varchar_base &x) override; + void serialize(const char *id, std::string &x) override; + void serialize(const char *id, matador::date &x) override; + void serialize(const char *id, matador::time &x) override; + void serialize(const char *id, basic_identifier &x) override; + void serialize(const char *id, identifiable_holder&x, cascade_type) override; private: sqlite_connection &db_; diff --git a/include/matador/object/has_many_list.hpp b/include/matador/object/has_many_list.hpp index 52c69e1d7..502fe4196 100644 --- a/include/matador/object/has_many_list.hpp +++ b/include/matador/object/has_many_list.hpp @@ -74,7 +74,7 @@ class has_many_iterator : public has_many_iterator_traits : public has_many_iterator_traits : public has_many_iterator_traits - bool is_deletable(object_proxy *proxy, T *o); + bool is_deletable(object_proxy *proxy, const T *o); void remove(bool notify); @@ -125,7 +125,7 @@ class MATADOR_OBJECT_API object_deleter { void serialize(T &x) { matador::access::serialize(*this, x); } template - void serialize(const char *, T &); + void serialize(const char *, const T &); void serialize(const char *, char *, size_t); template diff --git a/include/matador/object/object_deleter.tpp b/include/matador/object/object_deleter.tpp index 2309378d5..c041c4676 100644 --- a/include/matador/object/object_deleter.tpp +++ b/include/matador/object/object_deleter.tpp @@ -10,7 +10,7 @@ void object_deleter::t_object_count::remove_object(object_proxy *proxy, bool not } template -bool object_deleter::is_deletable(object_proxy *proxy, T *o) { +bool object_deleter::is_deletable(object_proxy *proxy, const T *o) { objects_to_remove_.clear(); objects_to_remove_.insert(std::make_pair(proxy->id(), t_object_count(proxy, (T*)proxy->obj()))); @@ -26,7 +26,7 @@ bool object_deleter::is_deletable(object_proxy *proxy, T *o) { } template -void object_deleter::serialize(const char *, T &) +void object_deleter::serialize(const char *, const T &) { if (!proxy_stack_.top()->node()->is_relation_node()) { return; diff --git a/include/matador/object/object_exception.hpp b/include/matador/object/object_exception.hpp index 05fe20d8b..8c42e3f8c 100644 --- a/include/matador/object/object_exception.hpp +++ b/include/matador/object/object_exception.hpp @@ -59,7 +59,7 @@ class object_exception : public std::runtime_error std::stringstream msg; \ msg << message; \ throw object_exception(msg.str().c_str()); \ - } while(false); + } while(false) } diff --git a/include/matador/object/object_ptr.hpp b/include/matador/object/object_ptr.hpp index aa13f36d8..30f3a954d 100644 --- a/include/matador/object/object_ptr.hpp +++ b/include/matador/object/object_ptr.hpp @@ -67,7 +67,7 @@ class object_pointer : public object_holder * * @param x object_pointer to move */ - explicit object_pointer(self &&x) noexcept + object_pointer(self &&x) noexcept : object_holder(std::move(x)) {} @@ -114,7 +114,7 @@ class object_pointer : public object_holder * * @param x The x serializable to assign from. */ - self& operator=(T *x) + object_pointer& operator=(T *x) { reset(new object_proxy(x), cascade_); return *this; @@ -125,7 +125,7 @@ class object_pointer : public object_holder * @param x The has_one object to created the object_pointer from * @return A reference to the created object_pointer */ - self& operator=(const self &x) + object_pointer& operator=(const self &x) { reset(x.proxy_, x.cascade_); return *this; @@ -136,7 +136,7 @@ class object_pointer : public object_holder * * @param x object_pointer to be moved */ - self& operator=(self &&x) noexcept + object_pointer& operator=(self &&x) noexcept { return static_cast(object_holder::operator=(std::move(x))); } @@ -147,7 +147,7 @@ class object_pointer : public object_holder * @return A reference to the created object_pointer */ template < object_holder_type OOPT > - self& operator=(object_pointer &x) + object_pointer& operator=(object_pointer &x) { reset(x.proxy_, x.cascade_); return *this; @@ -158,7 +158,7 @@ class object_pointer : public object_holder * * @return Cleared reference to object_pointer */ - self& operator=(std::nullptr_t) + object_pointer& operator=(std::nullptr_t) { clear(); return *this; @@ -182,7 +182,7 @@ class object_pointer : public object_holder * * @return The pointer to the serializable of type T. */ - T* operator->() const { + const T* operator->() const { return get(); } @@ -190,9 +190,10 @@ class object_pointer : public object_holder return get(); } - T* get() const { + const T* get() const { return static_cast(lookup_object()); } + T* get() { if (proxy_ && proxy_->obj()) { if (proxy_->ostore_ && proxy_->has_transaction()) { @@ -215,7 +216,7 @@ class object_pointer : public object_holder * * @return The reference to the serializable of type T. */ - T& operator*() const { + const T& operator*() const { return *get(); } diff --git a/include/matador/object/object_store.hpp b/include/matador/object/object_store.hpp index 658b51cc8..0d965e289 100644 --- a/include/matador/object/object_store.hpp +++ b/include/matador/object/object_store.hpp @@ -124,7 +124,7 @@ class MATADOR_OBJECT_API object_store */ enum abstract_type { abstract, /**< Indicates an abstract object type */ - not_abstract /**< Indicates an concreate object type */ + not_abstract /**< Indicates a concrete object type */ }; /// @cond MATADOR_DEV @@ -453,17 +453,17 @@ class MATADOR_OBJECT_API object_store void clear(bool full = false); /** - * Clears a prototype node and its cildren nodes. - * All objects will be deleted. - * - * @param type The name of the type to remove. - * @throws matador::object_exception on error - */ + * Clears a prototype node and its cildren nodes. + * All objects will be deleted. + * + * @param type The name of the type to remove. + * @throws matador::object_exception on error + */ void clear(const char *type); /** * Clears a prototype node by an iterator and its - * cildren nodes. All object_proxy objects will be + * children nodes. All object_proxy objects will be * deleted. * * @param node The prototype_iterator to remove. @@ -493,10 +493,10 @@ class MATADOR_OBJECT_API object_store * @param node The prototype_node * @return The depth of the node */ - size_t depth(const prototype_node *node) const; +// size_t depth(const prototype_node *node) const; /// @cond MATADOR_DEV - void dump(std::ostream &out) const; +// void dump(std::ostream &out) const; /// @endcond /** @@ -504,7 +504,7 @@ class MATADOR_OBJECT_API object_store * * @param out The stream to the objects dump on. */ - void dump_objects(std::ostream &out) const; +// void dump_objects(std::ostream &out) const; /** * Creates an serializable of the given type name. @@ -738,12 +738,12 @@ class MATADOR_OBJECT_API object_store * @param o The object set into the new object proxy. * @return An serializable proxy serializable or null. */ - template - object_proxy *create_proxy(T *o) - { - std::unique_ptr proxy(new object_proxy(o, seq_.next(), this)); - return object_map_.insert(std::make_pair(seq_.current(), proxy.release())).first->second; - } +// template +// object_proxy *create_proxy(T *o) +// { +// std::unique_ptr proxy(new object_proxy(o, seq_.next(), this)); +// return object_map_.insert(std::make_pair(seq_.current(), proxy.release())).first->second; +// } /** * @brief Creates and inserts an serializable proxy serializable. @@ -762,14 +762,12 @@ class MATADOR_OBJECT_API object_store * @param oid Unique id of the object_proxy. * @return An object_proxy object or null. */ - template - object_proxy *create_proxy(T *o, unsigned long oid) - { - std::unique_ptr proxy(new object_proxy(o, oid, this)); - return object_map_.insert(std::make_pair(oid, proxy.release())).first->second; - } - -// object_proxy *create_proxy(unsigned long id); +// template +// object_proxy *create_proxy(T *o, unsigned long oid) +// { +// std::unique_ptr proxy(new object_proxy(o, oid, this)); +// return object_map_.insert(std::make_pair(oid, proxy.release())).first->second; +// } /** * @brief Delete proxy from map @@ -780,7 +778,7 @@ class MATADOR_OBJECT_API object_store * @param id Id of proxy to delete * @return Returns true if deletion was successfully */ - bool delete_proxy(unsigned long id); +// bool delete_proxy(unsigned long id); /** * @brief Finds serializable proxy with id @@ -813,7 +811,7 @@ class MATADOR_OBJECT_API object_store * @return The registered object_proxy * @throws object_exception */ - object_proxy *register_proxy(object_proxy *oproxy); +// object_proxy *register_proxy(object_proxy *oproxy); /** * @brief Exchange the sequencer strategy. @@ -827,7 +825,7 @@ class MATADOR_OBJECT_API object_store * @param seq The new sequencer strategy serializable. * @return The old sequencer startegy implementation. */ - sequencer_impl_ptr exchange_sequencer(const sequencer_impl_ptr &seq); +// sequencer_impl_ptr exchange_sequencer(const sequencer_impl_ptr &seq); /** * Return the current transaction in stack @@ -892,15 +890,6 @@ class MATADOR_OBJECT_API object_store private: -// template < class T, template < class V = T > class ... O, typename = typename std::enable_if< std::is_same>::value >::type > -// prototype_iterator attach(const char *id, abstract_has_many *container) -// { -// temp_container_ = container; -// prototype_iterator i = attach(id); -// temp_container_ = nullptr; -// return i; -// } - /** * Clears a prototype_node and its * cildren nodes. All object_proxy objects will be @@ -984,13 +973,7 @@ class MATADOR_OBJECT_API object_store detail::object_deleter object_deleter_; detail::object_inserter object_inserter_; - // only used when a has_many object is inserted - abstract_has_many *temp_container_ = nullptr; - std::stack transactions_; - - // relation notification related - bool relation_notification_ = true; }; template < class T > @@ -999,7 +982,7 @@ void object_store::validate(prototype_node *node) std::unique_ptr nptr(node); // try to find node in prepared map const char *name = typeid(T).name(); - t_prototype_map::iterator i = prototype_map_.find(node->type_); + auto i = prototype_map_.find(node->type_); if (i != prototype_map_.end()) { throw_object_exception("prototype already inserted: " << node->type_.c_str()); } @@ -1013,7 +996,7 @@ void object_store::validate(prototype_node *node) * a new type * to be sure check in typeid map */ - t_typeid_prototype_map::iterator j = typeid_prototype_map_.find(name); + auto j = typeid_prototype_map_.find(name); if (j != typeid_prototype_map_.end() && j->second.find(node->type_) != j->second.end()) { /* unexpected found the * typeid check for type @@ -1028,7 +1011,7 @@ template class O > prototype_iterator object_store::attach(const char *type, object_store::abstract_type abstract, const char *parent, std::initializer_list*> observer) { - prototype_node *node = new prototype_node(this, type, new T, abstract == object_store::abstract_type::abstract); + auto *node = new prototype_node(this, type, new T, abstract == object_store::abstract_type::abstract); return attach(node, parent, observer); } @@ -1117,7 +1100,6 @@ void modified_marker::marker_func(object_store &store, object_proxy &proxy) #include "matador/object/node_analyzer.tpp" #include "matador/object/relation_field_endpoint.tpp" -//#include "matador/object/relation_field_serializer.tpp" #include "matador/object/relation_endpoint_value_inserter.tpp" #include "matador/object/relation_endpoint_value_remover.tpp" #include "matador/object/object_inserter.tpp" diff --git a/include/matador/object/object_store_observer.hpp b/include/matador/object/object_store_observer.hpp index 355cc3617..fcb4f84b7 100644 --- a/include/matador/object/object_store_observer.hpp +++ b/include/matador/object/object_store_observer.hpp @@ -37,12 +37,12 @@ class basic_object_store_observer * * @param tindex type index of the observer */ - basic_object_store_observer(const std::type_index &tindex) + explicit basic_object_store_observer(const std::type_index &tindex) : type_index_(tindex) {} public: - virtual ~basic_object_store_observer() {} + virtual ~basic_object_store_observer() = default; /** * Return the type index of the observer. diff --git a/include/matador/object/prototype_iterator.hpp b/include/matador/object/prototype_iterator.hpp index 1bb7988e6..a404b10f3 100644 --- a/include/matador/object/prototype_iterator.hpp +++ b/include/matador/object/prototype_iterator.hpp @@ -35,7 +35,7 @@ typedef base_iterator::reference reference ; /**< Shortcut for the reference ty /** * Creates an empty iterator */ -prototype_iterator(); +prototype_iterator() = default; /** * @brief Creates a iterator for a concrete type. @@ -45,7 +45,7 @@ prototype_iterator(); * * @param node The prototype_node of the object_proxy */ -prototype_iterator(pointer node); +explicit prototype_iterator(pointer node); /** * Copy from a given const_object_view_iterator. @@ -62,7 +62,7 @@ prototype_iterator(const prototype_iterator &x); */ prototype_iterator& operator=(const prototype_iterator &x); -~prototype_iterator(); +~prototype_iterator() = default; /** * @brief Compares this with another iterators. @@ -170,7 +170,7 @@ const_prototype_iterator(); * * @param node The prototype_node of the object_proxy */ -const_prototype_iterator(pointer node); +explicit const_prototype_iterator(pointer node); /** * Copy from a given const_object_view_iterator. @@ -202,7 +202,7 @@ const_prototype_iterator& operator=(const prototype_iterator &x); */ const_prototype_iterator& operator=(const const_prototype_iterator &x); -~const_prototype_iterator(); +~const_prototype_iterator() = default; /** * @brief Compares this with another iterators. diff --git a/include/matador/object/prototype_node.hpp b/include/matador/object/prototype_node.hpp index 4626eef09..c1bfc9582 100644 --- a/include/matador/object/prototype_node.hpp +++ b/include/matador/object/prototype_node.hpp @@ -135,7 +135,7 @@ class MATADOR_OBJECT_API prototype_node T *item, bool abstract, const char *owner_type, const char *relation_id); - prototype_node(); + prototype_node() = default; /** * @brief Creates a new prototype_node. @@ -163,7 +163,7 @@ class MATADOR_OBJECT_API prototype_node } - ~prototype_node(); + ~prototype_node() = default; /** * @brief Initializes a prototype_node. @@ -306,10 +306,10 @@ class MATADOR_OBJECT_API prototype_node /** * Returns true if node is child of given parent node. * - * @param parent The parent node. + * @param prnt The parent node. * @return True if node is child of given parent node. */ - bool is_child_of(const prototype_node *parent) const; + bool is_child_of(const prototype_node *prnt) const; /** * Returns true if node has children. @@ -381,15 +381,6 @@ class MATADOR_OBJECT_API prototype_node template < class T > T* prototype() const; - /** - * Prints the node in graphviz layout to the stream. - * - * @param os The ostream to write to. - * @param pn The prototype_node to be written. - * @return The modified ostream. - */ - friend MATADOR_OBJECT_API std::ostream& operator <<(std::ostream &os, const prototype_node &pn); - /** * Find the underlying proxy of the given primary key. * If no proxy is found nullptr is returned @@ -529,7 +520,7 @@ class MATADOR_OBJECT_API prototype_node template T *prototype_node::create() const { - return static_cast(info_.get()->create()); + return static_cast(info_->create()); } template diff --git a/include/matador/orm/persistence.hpp b/include/matador/orm/persistence.hpp index 3815e410d..5bf0cc452 100644 --- a/include/matador/orm/persistence.hpp +++ b/include/matador/orm/persistence.hpp @@ -110,7 +110,7 @@ class OOS_ORM_API persistence template bool exists() { - t_table_map::iterator i = tables_.find(store_.type()); + auto i = tables_.find(store_.type()); if (i == tables_.end()) { return false; diff --git a/include/matador/sql/basic_dialect.hpp b/include/matador/sql/basic_dialect.hpp index 6daa8a082..38857f140 100644 --- a/include/matador/sql/basic_dialect.hpp +++ b/include/matador/sql/basic_dialect.hpp @@ -202,6 +202,14 @@ class OOS_SQL_API basic_dialect */ virtual dialect_traits::identifier identifier_escape_type() const = 0; + /** + * Generates a next placeholder string. default is + * questionmark '?' + * + * @return Placeholder string + */ + virtual std::string next_placeholder() const; + /** * Return the identifier opening quote * diff --git a/include/matador/sql/basic_dialect_compiler.hpp b/include/matador/sql/basic_dialect_compiler.hpp index b2cde0f3a..6eabf5c0d 100644 --- a/include/matador/sql/basic_dialect_compiler.hpp +++ b/include/matador/sql/basic_dialect_compiler.hpp @@ -39,39 +39,39 @@ class OOS_SQL_API basic_dialect_compiler : public token_visitor public: void compile(basic_dialect &dialect); - virtual void visit(const matador::detail::create &) override; - virtual void visit(const matador::detail::drop &) override; - virtual void visit(const matador::detail::select &) override; - virtual void visit(const matador::detail::distinct &) override; - virtual void visit(const matador::detail::update &) override; - virtual void visit(const matador::detail::tablename &) override; - virtual void visit(const matador::detail::set &) override; - virtual void visit(const matador::columns &) override; - virtual void visit(const matador::column &) override; - virtual void visit(const matador::detail::typed_column &) override; - virtual void visit(const matador::detail::typed_identifier_column &) override; - virtual void visit(const matador::detail::typed_varchar_column &) override; - virtual void visit(const matador::detail::identifier_varchar_column &) override; - virtual void visit(const matador::detail::basic_value_column &) override; - virtual void visit(const matador::detail::from &) override; - virtual void visit(const matador::detail::where &) override; - virtual void visit(const matador::detail::basic_condition &) override; - virtual void visit(const matador::detail::basic_column_condition &) override; - virtual void visit(const matador::detail::basic_in_condition &) override; - virtual void visit(const matador::detail::order_by &) override; - virtual void visit(const matador::detail::asc &) override; - virtual void visit(const matador::detail::desc &) override; - virtual void visit(const matador::detail::group_by &) override; - virtual void visit(const matador::detail::insert &) override; - virtual void visit(const matador::detail::values &) override; - virtual void visit(const matador::detail::basic_value &) override; - virtual void visit(const matador::detail::remove &) override; - virtual void visit(const matador::detail::top &) override; - virtual void visit(const matador::detail::as &) override; - virtual void visit(const matador::detail::begin &) override; - virtual void visit(const matador::detail::commit &) override; - virtual void visit(const matador::detail::rollback &) override; - virtual void visit(matador::detail::query &) override; + void visit(const matador::detail::create &) override; + void visit(const matador::detail::drop &) override; + void visit(const matador::detail::select &) override; + void visit(const matador::detail::distinct &) override; + void visit(const matador::detail::update &) override; + void visit(const matador::detail::tablename &) override; + void visit(const matador::detail::set &) override; + void visit(const matador::columns &) override; + void visit(const matador::column &) override; + void visit(const matador::detail::typed_column &) override; + void visit(const matador::detail::typed_identifier_column &) override; + void visit(const matador::detail::typed_varchar_column &) override; + void visit(const matador::detail::identifier_varchar_column &) override; + void visit(const matador::detail::basic_value_column &) override; + void visit(const matador::detail::from &) override; + void visit(const matador::detail::where &) override; + void visit(const matador::detail::basic_condition &) override; + void visit(const matador::detail::basic_column_condition &) override; + void visit(const matador::detail::basic_in_condition &) override; + void visit(const matador::detail::order_by &) override; + void visit(const matador::detail::asc &) override; + void visit(const matador::detail::desc &) override; + void visit(const matador::detail::group_by &) override; + void visit(const matador::detail::insert &) override; + void visit(const matador::detail::values &) override; + void visit(const matador::detail::basic_value &) override; + void visit(const matador::detail::remove &) override; + void visit(const matador::detail::top &) override; + void visit(const matador::detail::as &) override; + void visit(const matador::detail::begin &) override; + void visit(const matador::detail::commit &) override; + void visit(const matador::detail::rollback &) override; + void visit(matador::detail::query &) override; protected: virtual void on_compile_start(); diff --git a/include/matador/sql/basic_dialect_linker.hpp b/include/matador/sql/basic_dialect_linker.hpp index 69b919427..923c1136c 100644 --- a/include/matador/sql/basic_dialect_linker.hpp +++ b/include/matador/sql/basic_dialect_linker.hpp @@ -43,39 +43,39 @@ class OOS_SQL_API basic_dialect_linker : public token_visitor std::string token_string(detail::token::t_token tok) const; - virtual void visit(const matador::detail::create &) override; - virtual void visit(const matador::detail::drop &) override; - virtual void visit(const matador::detail::select &) override; - virtual void visit(const matador::detail::distinct &) override; - virtual void visit(const matador::detail::update &) override; - virtual void visit(const matador::detail::tablename &table) override; - virtual void visit(const matador::detail::set &) override; - virtual void visit(const matador::detail::as &) override; - virtual void visit(const matador::detail::top &) override; - virtual void visit(const matador::detail::remove &) override; - virtual void visit(const matador::detail::values &values) override; - virtual void visit(const matador::detail::basic_value &) override; - virtual void visit(const matador::detail::order_by &) override; - virtual void visit(const matador::detail::asc &) override; - virtual void visit(const matador::detail::desc &) override; - virtual void visit(const matador::detail::group_by &) override; - virtual void visit(const matador::detail::insert &) override; - virtual void visit(const matador::detail::from &) override; - virtual void visit(const matador::detail::where &) override; - virtual void visit(const matador::detail::basic_condition &) override; - virtual void visit(const matador::detail::basic_column_condition &) override; - virtual void visit(const matador::detail::basic_in_condition &) override; - virtual void visit(const matador::columns &) override; - virtual void visit(const matador::column &) override; - virtual void visit(const matador::detail::typed_column &) override; - virtual void visit(const matador::detail::typed_identifier_column &) override; - virtual void visit(const matador::detail::typed_varchar_column &) override; - virtual void visit(const matador::detail::identifier_varchar_column &) override; - virtual void visit(const matador::detail::basic_value_column &) override; - virtual void visit(const matador::detail::begin &) override; - virtual void visit(const matador::detail::commit &) override; - virtual void visit(const matador::detail::rollback &) override; - virtual void visit(matador::detail::query &) override; + void visit(const matador::detail::create &) override; + void visit(const matador::detail::drop &) override; + void visit(const matador::detail::select &) override; + void visit(const matador::detail::distinct &) override; + void visit(const matador::detail::update &) override; + void visit(const matador::detail::tablename &table) override; + void visit(const matador::detail::set &) override; + void visit(const matador::detail::as &) override; + void visit(const matador::detail::top &) override; + void visit(const matador::detail::remove &) override; + void visit(const matador::detail::values &values) override; + void visit(const matador::detail::basic_value &) override; + void visit(const matador::detail::order_by &) override; + void visit(const matador::detail::asc &) override; + void visit(const matador::detail::desc &) override; + void visit(const matador::detail::group_by &) override; + void visit(const matador::detail::insert &) override; + void visit(const matador::detail::from &) override; + void visit(const matador::detail::where &) override; + void visit(const matador::detail::basic_condition &) override; + void visit(const matador::detail::basic_column_condition &) override; + void visit(const matador::detail::basic_in_condition &) override; + void visit(const matador::columns &) override; + void visit(const matador::column &) override; + void visit(const matador::detail::typed_column &) override; + void visit(const matador::detail::typed_identifier_column &) override; + void visit(const matador::detail::typed_varchar_column &) override; + void visit(const matador::detail::identifier_varchar_column &) override; + void visit(const matador::detail::basic_value_column &) override; + void visit(const matador::detail::begin &) override; + void visit(const matador::detail::commit &) override; + void visit(const matador::detail::rollback &) override; + void visit(matador::detail::query &) override; protected: basic_dialect& dialect() const; diff --git a/include/matador/sql/basic_query.hpp b/include/matador/sql/basic_query.hpp index e5da88ecb..306e106bf 100644 --- a/include/matador/sql/basic_query.hpp +++ b/include/matador/sql/basic_query.hpp @@ -51,7 +51,7 @@ class OOS_SQL_API basic_query * * @param table_name The name of the table */ - basic_query(const std::string &table_name); + explicit basic_query(std::string table_name); /** * Creates a basic query for the given diff --git a/include/matador/sql/column.hpp b/include/matador/sql/column.hpp index 3bf13ade1..ee910996b 100644 --- a/include/matador/sql/column.hpp +++ b/include/matador/sql/column.hpp @@ -38,7 +38,7 @@ struct OOS_SQL_API column : public detail::token * * @param col The name of the column */ - column(const std::string &col); + explicit column(const std::string &col); /** * @brief Creates a new column with given name @@ -53,7 +53,7 @@ struct OOS_SQL_API column : public detail::token * * @param visitor The visitor obejct to be accepted */ - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; std::string name; /**< Name of the column */ bool skip_quotes = false; /**< If true skip quoting */ @@ -163,7 +163,7 @@ struct OOS_SQL_API columns : public detail::token * * @param visitor The visitor obejct to be accepted */ - virtual void accept(token_visitor &visitor); + void accept(token_visitor &visitor) override; std::vector> columns_; /**< The list of column shared pointer */ t_brackets with_brackets_ = WITH_BRACKETS; /**< The bracket type */ @@ -173,6 +173,8 @@ struct OOS_SQL_API columns : public detail::token static column count_all_; /**< An count all column object */ }; +OOS_SQL_API column operator "" _col(const char *name, size_t len); + namespace detail { struct typed_column; struct typed_identifier_column; @@ -236,7 +238,7 @@ struct OOS_SQL_API typed_column : public matador::column typed_column(const std::string &col, data_type t); typed_column(const std::string &col, data_type t, std::size_t idx, bool host); - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; data_type type; std::size_t index = 0; @@ -248,7 +250,7 @@ struct OOS_SQL_API typed_identifier_column : public typed_column typed_identifier_column(const std::string &n, data_type t) : typed_column(n, t) { } typed_identifier_column(const std::string &n, data_type t, size_t idx, bool host) : typed_column(n, t, idx, host) { } - virtual void accept(token_visitor &visitor) override + void accept(token_visitor &visitor) override { return visitor.visit(*this); } @@ -265,7 +267,7 @@ struct OOS_SQL_API typed_varchar_column : public typed_column , size(size) { } - virtual void accept(token_visitor &visitor) override + void accept(token_visitor &visitor) override { return visitor.visit(*this); } @@ -279,7 +281,7 @@ struct OOS_SQL_API identifier_varchar_column : public typed_varchar_column : typed_varchar_column(n, size, t, idx, host) { } - virtual void accept(token_visitor &visitor) override + void accept(token_visitor &visitor) override { return visitor.visit(*this); } @@ -297,7 +299,7 @@ struct OOS_SQL_API basic_value_column : public column , value_(val) { } - virtual void accept(token_visitor &visitor) override + void accept(token_visitor &visitor) override { visitor.visit(*this); } diff --git a/include/matador/sql/column_serializer.hpp b/include/matador/sql/column_serializer.hpp index 7a76d75fd..78c65a53f 100644 --- a/include/matador/sql/column_serializer.hpp +++ b/include/matador/sql/column_serializer.hpp @@ -38,33 +38,33 @@ class OOS_SQL_API column_serializer : public serializer { public: explicit column_serializer(columns::t_brackets brackets); - virtual ~column_serializer() { } + ~column_serializer() override = default; template columns *execute(T &x) { - cols_.reset(new columns(brackets_)); + cols_ = std::make_unique(brackets_); matador::access::serialize(static_cast(*this), x); return cols_.release(); } - void serialize(const char *id, char &x); - void serialize(const char *id, short &x); - void serialize(const char *id, int &x); - void serialize(const char *id, long &x); - void serialize(const char *id, unsigned char &x); - void serialize(const char *id, unsigned short &x); - void serialize(const char *id, unsigned int &x); - void serialize(const char *id, unsigned long &x); - void serialize(const char *id, float &x); - void serialize(const char *id, double &x); - void serialize(const char *id, bool &x); - void serialize(const char *id, char *x, size_t s); - void serialize(const char *id, varchar_base &x); - void serialize(const char *id, std::string &x); - void serialize(const char *id, date &x); - void serialize(const char *id, time &x); - void serialize(const char *id, identifiable_holder &x, cascade_type); - void serialize(const char *id, basic_identifier &x); + void serialize(const char *id, char &x) override; + void serialize(const char *id, short &x) override; + void serialize(const char *id, int &x) override; + void serialize(const char *id, long &x) override; + void serialize(const char *id, unsigned char &x) override; + void serialize(const char *id, unsigned short &x) override; + void serialize(const char *id, unsigned int &x) override; + void serialize(const char *id, unsigned long &x) override; + void serialize(const char *id, float &x) override; + void serialize(const char *id, double &x) override; + void serialize(const char *id, bool &x) override; + void serialize(const char *id, char *x, size_t s) override; + void serialize(const char *id, varchar_base &x) override; + void serialize(const char *id, std::string &x) override; + void serialize(const char *id, date &x) override; + void serialize(const char *id, time &x) override; + void serialize(const char *id, identifiable_holder &x, cascade_type) override; + void serialize(const char *id, basic_identifier &x) override; private: columns::t_brackets brackets_; diff --git a/include/matador/sql/condition.hpp b/include/matador/sql/condition.hpp index 9c522cf35..53bf12a98 100644 --- a/include/matador/sql/condition.hpp +++ b/include/matador/sql/condition.hpp @@ -65,15 +65,16 @@ class OOS_SQL_API basic_condition : public token GREATER_EQUAL, OR, AND, - NOT + NOT, + IN_LIST }; enum { - num_operands = 9 + num_operands = 10 }; - virtual void accept(token_visitor &visitor) override + void accept(token_visitor &visitor) override { visitor.visit(*this); } @@ -89,11 +90,11 @@ class OOS_SQL_API basic_column_condition : public basic_condition column field_; std::string operand; - basic_column_condition(const column &fld, detail::basic_condition::t_operand op) - : field_(fld), operand(detail::basic_condition::operands[op]) + basic_column_condition(column fld, detail::basic_condition::t_operand op) + : field_(std::move(fld)), operand(detail::basic_condition::operands[op]) { } - virtual void accept(token_visitor &visitor) override + void accept(token_visitor &visitor) override { visitor.visit(*this); } @@ -104,11 +105,11 @@ class OOS_SQL_API basic_in_condition : public basic_condition public: column field_; - basic_in_condition(const column &fld) - : field_(fld) + explicit basic_in_condition(column fld) + : field_(std::move(fld)) { } - virtual void accept(token_visitor &visitor) override + void accept(token_visitor &visitor) override { visitor.visit(*this); } @@ -152,13 +153,14 @@ class condition> : public detail::basic_in_cond * @param dialect The dialect used to evaluate * @return A condition IN part of the query */ - virtual std::string evaluate(basic_dialect &dialect) const override + std::string evaluate(basic_dialect &dialect) const override { + dialect.inc_bind_count(size()); std::stringstream str; str << dialect.prepare_identifier(field_.name) << " IN ("; if (args_.size() > 1) { @@ -283,7 +287,7 @@ class condition> : public detail::basic_in_cond str << *first++ << ","; } else { ++first; - str << "?,"; + str << dialect.next_placeholder() << ","; } } } @@ -291,7 +295,7 @@ class condition> : public detail::basic_in_cond if (dialect.compile_type() == basic_dialect::DIRECT) { str << args_.back(); } else { - str << "?"; + str << dialect.next_placeholder(); } } str << ")"; @@ -302,7 +306,7 @@ class condition> : public detail::basic_in_cond * @brief Returns the number of arguments in the list * @return The number of arguments in the list */ - virtual size_t size() const override + size_t size() const override { return args_.size(); } @@ -322,7 +326,7 @@ class condition> : public detail::basic_in_cond * @endcode */ template <> -class condition : public detail::basic_condition +class condition : public detail::basic_column_condition { public: /** @@ -335,8 +339,9 @@ class condition : public detail::basic_condition * @param col Column for the IN condition * @param q The query to be evaluated to the IN arguments */ - condition(const column &col, const detail::basic_query &q) - : field_(col), query_(q) + condition(column col, detail::basic_condition::t_operand op, detail::basic_query q) + : basic_column_condition(std::move(col), op) + , query_(std::move(q)) {} /** @@ -348,16 +353,15 @@ class condition : public detail::basic_condition * @param dialect The dialect used to evaluate * @return A condition IN part of the query */ - std::string evaluate(basic_dialect &dialect) const + std::string evaluate(basic_dialect &dialect) const override { - std::string result(dialect.prepare_identifier(field_.name) + " IN ("); + std::string result(dialect.prepare_identifier(field_.name) + " " + operand + " ("); result += dialect.build(query_.stmt(), dialect.compile_type()); result += (")"); return result; } private: - column field_; detail::basic_query query_; }; @@ -379,8 +383,8 @@ class condition> : public detail::basic_condition * @param col The column for the range check * @param range The boundary values defining the range */ - condition(const column &col, const std::pair &range) - : field_(col), range_(range) { } + condition(column col, const std::pair &range) + : field_(std::move(col)), range_(range) { } /** * @brief Evaluates the condition @@ -391,13 +395,14 @@ class condition> : public detail::basic_condition * @param dialect The dialect used to evaluate * @return A condition BETWEEN part of the query */ - std::string evaluate(basic_dialect &dialect) const + std::string evaluate(basic_dialect &dialect) const override { + dialect.inc_bind_count(2); std::stringstream str; if (dialect.compile_type() == basic_dialect::DIRECT) { str << dialect.prepare_identifier(field_.name) << " BETWEEN " << range_.first << " AND " << range_.second; } else { - str << dialect.prepare_identifier(field_.name) << " BETWEEN ? AND ?"; + str << dialect.prepare_identifier(field_.name) << " BETWEEN " << dialect.next_placeholder() << " AND " << dialect.next_placeholder(); } return str.str(); } @@ -438,7 +443,7 @@ class condition, condition> : public detail::basic_con * @param dialect The dialect used to evaluate * @return The exaluated string based on the compile type */ - std::string evaluate(basic_dialect &dialect) const + std::string evaluate(basic_dialect &dialect) const override { std::stringstream str; if (operand == detail::basic_condition::AND) { @@ -449,6 +454,12 @@ class condition, condition> : public detail::basic_con return str.str(); } + void accept(token_visitor &visitor) override + { + left.accept(visitor); + right.accept(visitor); + } + private: condition left; condition right; @@ -480,7 +491,7 @@ class condition, void> : public detail::basic_condition * @param dialect The dialect used to evaluate * @return The exaluated string based on the compile type */ - std::string evaluate(basic_dialect &dialect) const + std::string evaluate(basic_dialect &dialect) const override { std::stringstream str; str << operand << " (" << cond.evaluate(dialect) << ")"; @@ -566,6 +577,8 @@ condition operator==(const column &col, T val) return condition(col, detail::basic_condition::EQUAL, val); } +condition equals(const column &col, detail::basic_query &q); + /** * @brief Condition unequality operator for a column and a value * @@ -652,7 +665,7 @@ condition operator>=(const column &col, T val) } /** - * @brief AND operation condition consisting of a left and rigth hand condition + * @brief AND operation condition consisting of a left and right hand condition * * @tparam L1 Left hand type of left hand condition * @tparam R1 Right hand type of left hand condition @@ -669,7 +682,7 @@ condition, condition> operator&&(const conditiondialect()->direct(stmt); return result(impl_->execute(stmt), prototype); } @@ -209,6 +210,7 @@ class OOS_SQL_API connection template < class T > result execute(const sql &stmt, typename std::enable_if< !std::is_same::value >::type* = 0) { +// std::cout << "\n" << impl_->dialect()->direct(stmt); return result(impl_->execute(stmt)); } diff --git a/include/matador/sql/connection_factory.hpp b/include/matador/sql/connection_factory.hpp index ef09a480a..068f311ee 100644 --- a/include/matador/sql/connection_factory.hpp +++ b/include/matador/sql/connection_factory.hpp @@ -52,7 +52,7 @@ class OOS_SQL_API connection_factory : public matador::singleton describe(const std::string &table) = 0; virtual basic_dialect* dialect() = 0; diff --git a/include/matador/sql/dialect_token.hpp b/include/matador/sql/dialect_token.hpp index 7349ba763..eafa9b042 100644 --- a/include/matador/sql/dialect_token.hpp +++ b/include/matador/sql/dialect_token.hpp @@ -32,92 +32,84 @@ struct OOS_SQL_API select : public token { select() : token(SELECT) {} - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API begin : public token { begin() : token(BEGIN) {} - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API commit : public token { commit() : token(COMMIT) {} - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API rollback : public token { rollback() : token(ROLLBACK) {} - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; -struct OOS_SQL_API drop : public token +struct OOS_SQL_API drop : public table_name_token { - drop(const std::string &t) : token(DROP), table(t) {} + explicit drop(const std::string &t) : table_name_token(DROP, t) {} - virtual void accept(token_visitor &visitor) override; - - std::string table; + void accept(token_visitor &visitor) override; }; -struct OOS_SQL_API create : public token +struct OOS_SQL_API create : public table_name_token { - create(const std::string &t); - - virtual void accept(token_visitor &visitor) override; + explicit create(const std::string &t); - std::string table; + void accept(token_visitor &visitor) override; }; -struct OOS_SQL_API insert : public token +struct OOS_SQL_API insert : public table_name_token { - insert(const std::string &t); - - virtual void accept(token_visitor &visitor) override; + explicit insert(std::string t); - std::string table; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API update : public token { update(); - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; -struct OOS_SQL_API tablename : public token +struct OOS_SQL_API tablename : public table_name_token { - tablename(const std::string &t); + explicit tablename(std::string t); - virtual void accept(token_visitor &visitor) override; - - std::string tab; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API remove : public token { remove(); - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API distinct : public token { distinct() : token(DISTINCT) {} - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API set : public token { set() : token(SET) {} - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API values : public token @@ -126,7 +118,7 @@ struct OOS_SQL_API values : public token void push_back(const std::shared_ptr &val) { values_.push_back(val); } - virtual void accept(token_visitor &visitor) override + void accept(token_visitor &visitor) override { return visitor.visit(*this); } @@ -138,57 +130,55 @@ struct OOS_SQL_API asc : public token { asc() : token(ASC) {} - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API desc : public token { desc() : token(DESC) {} - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; }; -struct OOS_SQL_API from : public token +struct OOS_SQL_API from : public table_name_token { - from(const std::string &t); - - virtual void accept(token_visitor &visitor) override; + explicit from(const std::string &t); - std::string table; + void accept(token_visitor &visitor) override; }; struct OOS_SQL_API top : public token { - top(size_t lmt); + explicit top(size_t lmt); - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; size_t limit_; }; struct OOS_SQL_API as : public token { - as(const std::string &a); + explicit as(std::string a); - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; std::string alias; }; struct OOS_SQL_API order_by : public token { - order_by(const std::string &col); + explicit order_by(std::string col); - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; std::string column; }; struct OOS_SQL_API group_by : public token { - group_by(const std::string &col); + explicit group_by(std::string col); - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; std::string column; }; @@ -201,12 +191,12 @@ struct OOS_SQL_API where : public token , cond(new COND(c)) { } - where(const std::shared_ptr &c) + explicit where(std::shared_ptr c) : token(token::WHERE) - , cond(c) + , cond(std::move(c)) { } - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; std::shared_ptr cond; }; diff --git a/include/matador/sql/field.hpp b/include/matador/sql/field.hpp index 392f9938a..138b14625 100644 --- a/include/matador/sql/field.hpp +++ b/include/matador/sql/field.hpp @@ -40,13 +40,17 @@ class OOS_SQL_API field * @brief Creates a named field * @param name Name of the column field */ - field(const char *name); + explicit field(const char *name); /** * @brief Creates a named field * @param name Name of the column field */ - field(const std::string &name); + explicit field(const std::string &name); + + /** + * @brief Destroy a field + */ ~field(); /** diff --git a/include/matador/sql/memory_connection.hpp b/include/matador/sql/memory_connection.hpp index 2465b4504..13dda57bd 100644 --- a/include/matador/sql/memory_connection.hpp +++ b/include/matador/sql/memory_connection.hpp @@ -16,30 +16,30 @@ namespace memory { class memory_connection : public matador::connection_impl { public: - virtual void open(const std::string &) override {} - virtual bool is_open() const override { return true; } - virtual void close() override {} + void open(const std::string &) override {} + bool is_open() const override { return true; } + void close() override {} - virtual matador::detail::result_impl *execute(const matador::sql &) override { return nullptr; } - virtual matador::detail::result_impl *execute(const std::string &) override { return nullptr; } - virtual detail::statement_impl *prepare(const matador::sql &) override { return nullptr; }; + matador::detail::result_impl *execute(const matador::sql &) override { return nullptr; } + matador::detail::result_impl *execute(const std::string &) override { return nullptr; } + detail::statement_impl *prepare(const matador::sql &) override { return nullptr; }; - virtual void begin() override {} + void begin() override {} - virtual void commit() override {} + void commit() override {} - virtual void rollback() override {} + void rollback() override {} - virtual std::string type() const override { return "memory"; }; - virtual std::string version() const override { return "0.5.0"; }; + std::string type() const override { return "memory"; }; + std::string version() const override { return "0.5.1"; }; virtual const char *type_string(data_type) const { return nullptr; } - virtual bool exists(const std::string &) override { return true; } + bool exists(const std::string &) override { return true; } - virtual std::vector describe(const std::string &) override { return std::vector(); } + std::vector describe(const std::string &) override { return std::vector(); } - virtual basic_dialect* dialect() override { return nullptr; } + basic_dialect* dialect() override { return nullptr; } }; /// @endcond diff --git a/include/matador/sql/query.hpp b/include/matador/sql/query.hpp index 7ba302581..6f5764294 100644 --- a/include/matador/sql/query.hpp +++ b/include/matador/sql/query.hpp @@ -51,8 +51,6 @@ namespace matador { -//class condition; - /** * @class query * @brief Creates a SQL query. @@ -101,10 +99,10 @@ class query : public detail::basic_query /** * @brief Create a new query for the given table. * - * @param tablename The default tablename used for the query. + * @param table_name The default table name used for the query. */ - query(const std::string &tablename) - : basic_query(tablename) + explicit query(const std::string &table_name) + : basic_query(table_name) {} /** @@ -112,7 +110,7 @@ class query : public detail::basic_query * * @param conn The default connection to be used */ - query(const connection &conn) + explicit query(const connection &conn) : query(conn, "") { determine_tablename(); @@ -128,17 +126,17 @@ class query : public detail::basic_query : detail::basic_query(conn, tablename) {} - ~query() {} + ~query() = default; /** - * Bind a tablename to a specific + * Bind a table name to a specific * object type * - * @param tablename The tablename to bind + * @param table_name The tablename to bind */ - static void bind_table(const std::string &tablename) + static void bind_table(const std::string &table_name) { - tablename_map_.insert(std::make_pair(std::type_index(typeid(T)), tablename)); + tablename_map_.insert(std::make_pair(std::type_index(typeid(T)), table_name)); } /** @@ -171,6 +169,7 @@ class query : public detail::basic_query reset(t_query_command::CREATE); sql_.append(new detail::create(table_name_)); + sql_.table_name(table_name_); detail::typed_column_serializer serializer; @@ -215,6 +214,7 @@ class query : public detail::basic_query sql_.append(cols.release()); sql_.append(new detail::from(table_name_)); + sql_.table_name(table_name_); state = QUERY_FROM; return *this; @@ -241,6 +241,7 @@ class query : public detail::basic_query sql_.append(cols.release()); sql_.append(new detail::from(table_name_)); + sql_.table_name(table_name_); state = QUERY_FROM; return *this; @@ -268,6 +269,7 @@ class query : public detail::basic_query reset(t_query_command::INSERT); sql_.append(new detail::insert(table_name_)); + sql_.table_name(table_name_); detail::column_serializer serializer(columns::WITH_BRACKETS); @@ -314,6 +316,7 @@ class query : public detail::basic_query sql_.append(new detail::update); sql_.append(new detail::tablename(table_name_)); + sql_.table_name(table_name_); sql_.append(new detail::set); sql_.append(update_columns_); @@ -342,6 +345,7 @@ class query : public detail::basic_query sql_.append(new detail::update); sql_.append(new detail::tablename(table_name_)); + sql_.table_name(table_name_); sql_.append(new detail::set); for (auto colvalue : colvalues) { @@ -366,6 +370,7 @@ class query : public detail::basic_query query& from(const std::string &table) { sql_.append(new detail::from(table)); + sql_.table_name(table_name_); return *this; } @@ -381,6 +386,7 @@ class query : public detail::basic_query sql_.append(new detail::remove()); sql_.append(new detail::from(table_name_)); + sql_.table_name(table_name_); state = QUERY_DELETE; @@ -605,10 +611,10 @@ class query : public detail::basic_query * @brief Create a new query for the * given table. * - * @param tablename The default tablename used for the query. + * @param table_name The default table name used for the query. */ - query(const std::string &tablename) - : basic_query(tablename) + explicit query(const std::string &table_name) + : basic_query(table_name) {} /** @@ -616,7 +622,7 @@ class query : public detail::basic_query * * @param conn The default connection to be used */ - query(const connection &conn) + explicit query(const connection &conn) : query(conn, "") {} @@ -624,13 +630,13 @@ class query : public detail::basic_query * @brief Create a query with a default connection and default tablename * * @param conn The default connection to be used - * @param tablename The default tablename used for the query. + * @param table_name The default table name used for the query. */ - query(const connection &conn, const std::string &tablename) - : detail::basic_query(conn, tablename) + query(const connection &conn, const std::string &table_name) + : detail::basic_query(conn, table_name) {} - ~query() {} + ~query() = default; /** * @brief Start a create query for default table @@ -645,15 +651,16 @@ class query : public detail::basic_query /** * @brief Create a table with given name * - * @param tablename The tablename to be used for the statement + * @param table_name The table name to be used for the statement * @param collist The columns to be created * @return A reference to the query. */ - query& create(const std::string &tablename, const std::initializer_list> &collist) + query& create(const std::string &table_name, const std::initializer_list> &collist) { reset(t_query_command::CREATE); - sql_.append(new detail::create(tablename)); + sql_.append(new detail::create(table_name)); + sql_.table_name(table_name_); std::unique_ptr cols(new matador::columns(matador::columns::WITH_BRACKETS)); for (auto &&col : collist) { @@ -676,14 +683,15 @@ class query : public detail::basic_query } /** - * @brief Start a drop query for the given tablename - * @param tablename The table to be dropped + * @brief Start a drop query for the given table name + * @param table_name The table to be dropped * @return A reference to the query. */ - query& drop(const std::string &tablename) + query& drop(const std::string &table_name) { reset(t_query_command::DROP); - sql_.append(new detail::drop(tablename)); + sql_.append(new detail::drop(table_name)); + sql_.table_name(table_name_); state = QUERY_DROP; return *this; @@ -699,6 +707,7 @@ class query : public detail::basic_query reset(t_query_command::INSERT); sql_.append(new detail::insert(table_name_)); + sql_.table_name(table_name_); std::unique_ptr cols(new matador::columns); @@ -748,6 +757,7 @@ class query : public detail::basic_query sql_.append(new detail::update); sql_.append(new detail::tablename(table_name_)); + sql_.table_name(table_name_); sql_.append(new detail::set); for (auto colvalue : colvalues) { @@ -825,6 +835,7 @@ class query : public detail::basic_query throw_invalid(QUERY_FROM, state); sql_.append(new detail::from(table)); + sql_.table_name(table_name_); table_name_ = table; diff --git a/include/matador/sql/result.hpp b/include/matador/sql/result.hpp index 4cea1365d..be991a351 100644 --- a/include/matador/sql/result.hpp +++ b/include/matador/sql/result.hpp @@ -52,7 +52,7 @@ class base_result_iterator : public std::iterator , result_(x.result_) {} - base_result_iterator& operator=(base_result_iterator&& x) + base_result_iterator& operator=(base_result_iterator&& x) noexcept { result_ = x.result_; obj_.reset(x.obj_.release()); @@ -284,7 +284,7 @@ class result /** * Empty result */ - result() = default; + result() : prototype_(row()) {} /** * Creates a result initialized @@ -312,6 +312,7 @@ class result * @param x The result ro move */ result(result &&x) noexcept + : prototype_(x.prototype_) { std::swap(p, x.p); } diff --git a/include/matador/sql/row.hpp b/include/matador/sql/row.hpp index 3fc99a37a..92ded775d 100644 --- a/include/matador/sql/row.hpp +++ b/include/matador/sql/row.hpp @@ -45,8 +45,8 @@ namespace matador { class OOS_SQL_API row { public: - row(); - ~row(); + row() = default; + ~row() = default; /** * Add a column to the row. If column diff --git a/include/matador/sql/sql.hpp b/include/matador/sql/sql.hpp index 8850b7cce..440eed103 100644 --- a/include/matador/sql/sql.hpp +++ b/include/matador/sql/sql.hpp @@ -61,20 +61,22 @@ class OOS_SQL_API sql sql(); ~sql(); - void append(const std::shared_ptr tokptr); + void append(const std::shared_ptr &tokptr); void append(detail::token *tok); void append(const sql &stmt); void reset(t_query_command command_type); - static unsigned int type_size(data_type type); - template < class T > static unsigned int type() { return data_type_traits::type(); } + std::string command() const; + std::string table_name() const; + void table_name(const std::string &tname); + private: friend class basic_dialect; friend struct detail::build_info; @@ -85,15 +87,17 @@ class OOS_SQL_API sql t_query_command command_type_; token_list_t token_list_; + + std::string table_name_; }; namespace detail { struct query : public token { - query(const sql &s); + explicit query(const sql &s); - virtual void accept(token_visitor &visitor) override; + void accept(token_visitor &visitor) override; sql sql_; }; diff --git a/include/matador/sql/sql_exception.hpp b/include/matador/sql/sql_exception.hpp index beda1e371..e994da176 100644 --- a/include/matador/sql/sql_exception.hpp +++ b/include/matador/sql/sql_exception.hpp @@ -31,14 +31,20 @@ class sql_exception : public std::exception {} - virtual ~sql_exception() {} + sql_exception(std::string source, std::string what) + : source_(std::move(source)) + , what_(std::move(what)) + {} + + + ~sql_exception() override = default; /** * Returns the message of the exception * * @return The message of this exception. */ - virtual const char* what() const noexcept + const char* what() const noexcept override { return what_.c_str(); } diff --git a/include/matador/sql/statement.hpp b/include/matador/sql/statement.hpp index 010f5da25..875d81631 100644 --- a/include/matador/sql/statement.hpp +++ b/include/matador/sql/statement.hpp @@ -106,6 +106,7 @@ class statement */ result execute() { +// std::cout << "\n" << p->str(); return result(p->execute()); } @@ -175,7 +176,7 @@ class statement /** * Creates an empty statement */ - statement() = default; + statement() : prototype_(row()) {} /** * Creates a statement initialized from the @@ -198,6 +199,7 @@ class statement * @param x The statement to move from */ statement(statement &&x) noexcept + : prototype_(x.prototype_) { std::swap(p, x.p); } @@ -234,6 +236,7 @@ class statement */ result execute() { +// std::cout << "\n" << p->str(); return result(p->execute(), prototype_); } diff --git a/include/matador/sql/statement_impl.hpp b/include/matador/sql/statement_impl.hpp index 86d3394da..d6dd1a613 100644 --- a/include/matador/sql/statement_impl.hpp +++ b/include/matador/sql/statement_impl.hpp @@ -33,6 +33,13 @@ namespace detail { class OOS_SQL_API statement_impl : public serializer { public: + statement_impl& operator=(statement_impl &&) = delete; + statement_impl(statement_impl &&) = delete; + +public: + statement_impl() = default; + statement_impl(const statement_impl &) = default; + statement_impl& operator=(const statement_impl &) = default; ~statement_impl() override = default; virtual void clear() = 0; @@ -64,7 +71,7 @@ class OOS_SQL_API statement_impl : public serializer void str(const std::string &s); protected: - size_t host_index; + size_t host_index = 0; private: std::string sql_; diff --git a/include/matador/sql/token.hpp b/include/matador/sql/token.hpp index 56a54912b..bcd17f48a 100644 --- a/include/matador/sql/token.hpp +++ b/include/matador/sql/token.hpp @@ -95,6 +95,13 @@ struct OOS_SQL_API token t_token type; }; +struct OOS_SQL_API table_name_token : public token +{ + table_name_token(t_token tok, std::string tablename); + + std::string table_name; +}; + } /// @endcond diff --git a/include/matador/sql/token_visitor.hpp b/include/matador/sql/token_visitor.hpp index edca54f44..5d0d0747d 100644 --- a/include/matador/sql/token_visitor.hpp +++ b/include/matador/sql/token_visitor.hpp @@ -65,7 +65,7 @@ struct query; class OOS_SQL_API token_visitor { public: - virtual ~token_visitor() {} + virtual ~token_visitor() = default; virtual void visit(const matador::detail::create &) = 0; virtual void visit(const matador::detail::drop &) = 0; diff --git a/include/matador/sql/types.hpp b/include/matador/sql/types.hpp index 2c51e8ade..15b39661c 100644 --- a/include/matador/sql/types.hpp +++ b/include/matador/sql/types.hpp @@ -73,7 +73,7 @@ enum struct data_type { * @param type The data ytpe to be written * @return The modified output stream */ -OOS_SQL_API std::ostream& operator<<(std::ostream &out, const matador::data_type type); +//OOS_SQL_API std::ostream& operator<<(std::ostream &out, const matador::data_type &type); /** * @tparam T The type of the traits diff --git a/include/matador/sql/value.hpp b/include/matador/sql/value.hpp index b2cae4b18..f43e91ebc 100644 --- a/include/matador/sql/value.hpp +++ b/include/matador/sql/value.hpp @@ -55,10 +55,10 @@ namespace detail { struct OOS_SQL_API basic_value : public token { - basic_value(token::t_token tok) : token(tok) { } + explicit basic_value(token::t_token tok) : token(tok) { } template < class T > T get() { - matador::value *v = dynamic_cast* >(this); + auto *v = dynamic_cast* >(this); if (v) { return v->val; } else { @@ -98,7 +98,7 @@ struct value::value && !std::is_same::value>::type> : public detail::basic_value { - value(const T &val) + explicit value(const T &val) : basic_value(detail::token::VALUE) , val(val) { } @@ -134,26 +134,26 @@ struct value struct value::value>::type> : public detail::basic_value { - value(const T &val) + explicit value(const T &val) : basic_value(detail::token::VALUE) , val(val) { } - virtual void serialize(const char *id, serializer &srlzr) + void serialize(const char *id, serializer &srlzr) override { srlzr.serialize(id, val); } - std::string str() const + std::string str() const override { return "'" + val.str() + "'"; } - std::string safe_string(const basic_dialect &dialect) const + std::string safe_string(const basic_dialect &dialect) const override { return "'" + dialect.prepare_literal(val.str()) + "'"; } - const char* type_id() const + const char* type_id() const override { return typeid(T).name(); } @@ -163,26 +163,26 @@ struct value struct value : public detail::basic_value { - value(const std::string &val) + explicit value(std::string val) : basic_value(detail::token::VALUE) - , val(val) { } + , val(std::move(val)) { } - virtual void serialize(const char *id, serializer &srlzr) + void serialize(const char *id, serializer &srlzr) override { srlzr.serialize(id, val); } - std::string str() const + std::string str() const override { return "'" + val + "'"; } - std::string safe_string(const basic_dialect &dialect) const + std::string safe_string(const basic_dialect &dialect) const override { return "'" + dialect.prepare_literal(val) + "'"; } - const char* type_id() const + const char* type_id() const override { return typeid(std::string).name(); } @@ -192,30 +192,30 @@ struct value : public detail::basic_value template<> struct value : public detail::basic_value { - value(char val) + explicit value(char val) : basic_value(detail::token::VALUE) , val(val) { } - virtual void serialize(const char *id, serializer &srlzr) + void serialize(const char *id, serializer &srlzr) override { srlzr.serialize(id, val); } - std::string str() const + std::string str() const override { std::stringstream str; str << "'" << val << "'"; return str.str(); } - std::string safe_string(const basic_dialect &) const + std::string safe_string(const basic_dialect &) const override { std::stringstream str; str << "'" << val << "'"; return str.str(); } - const char* type_id() const + const char* type_id() const override { return typeid(char).name(); } @@ -231,26 +231,26 @@ struct value : public detail::basic_value { } - virtual void serialize(const char *id, serializer &srlzr) + void serialize(const char *id, serializer &srlzr) override { srlzr.serialize(id, val); } - std::string str() const + std::string str() const override { std::stringstream str; str << "'" << val << "'"; return str.str(); } - std::string safe_string(const basic_dialect &dialect) const + std::string safe_string(const basic_dialect &dialect) const override { std::stringstream str; str << "'" << dialect.prepare_literal(val) << "'"; return str.str(); } - const char* type_id() const + const char* type_id() const override { return typeid(char*).name(); } @@ -267,26 +267,26 @@ struct value : public detail::basic_value { } - virtual void serialize(const char *id, serializer &srlzr) + void serialize(const char *id, serializer &srlzr) override { srlzr.serialize(id, val); } - std::string str() const + std::string str() const override { std::stringstream str; str << "'" << val << "'"; return str.str(); } - std::string safe_string(const basic_dialect &dialect) const + std::string safe_string(const basic_dialect &dialect) const override { std::stringstream str; str << "'" << dialect.prepare_literal(val) << "'"; return str.str(); } - const char* type_id() const + const char* type_id() const override { return typeid(const char*).name(); } @@ -296,30 +296,30 @@ struct value : public detail::basic_value template<> struct value : public detail::basic_value { - value(const matador::date &val) + explicit value(matador::date val) : basic_value(detail::token::VALUE) - , val(val) { } + , val(std::move(val)) { } - virtual void serialize(const char *id, serializer &srlzr) + void serialize(const char *id, serializer &srlzr) override { srlzr.serialize(id, val); } - std::string str() const + std::string str() const override { std::stringstream str; str << "'" << matador::to_string(val) << "'"; return str.str(); } - std::string safe_string(const basic_dialect &dialect) const + std::string safe_string(const basic_dialect &dialect) const override { std::stringstream str; str << "'" << dialect.prepare_literal(matador::to_string(val)) << "'"; return str.str(); } - const char* type_id() const + const char* type_id() const override { return typeid(matador::date).name(); } @@ -329,31 +329,31 @@ struct value : public detail::basic_value template<> struct value : public detail::basic_value { - value(const matador::time &val) + explicit value(matador::time val) : basic_value(detail::token::VALUE) - , val(val) + , val(std::move(val)) { } - virtual void serialize(const char *id, serializer &srlzr) + void serialize(const char *id, serializer &srlzr) override { srlzr.serialize(id, val); } - std::string str() const + std::string str() const override { std::stringstream str; str << "'" << matador::to_string(val, "%FT%T.%f") << "'"; return str.str(); } - std::string safe_string(const basic_dialect &dialect) const + std::string safe_string(const basic_dialect &dialect) const override { std::stringstream str; str << "'" << dialect.prepare_literal(matador::to_string(val, "%FT%T.%f")) << "'"; return str.str(); } - const char* type_id() const + const char* type_id() const override { return typeid(matador::time).name(); } diff --git a/include/matador/sql/value_column_serializer.hpp b/include/matador/sql/value_column_serializer.hpp index f327265b3..ec576dc7a 100644 --- a/include/matador/sql/value_column_serializer.hpp +++ b/include/matador/sql/value_column_serializer.hpp @@ -37,30 +37,30 @@ class OOS_SQL_API value_column_serializer : public serializer { value_column_serializer(); template - void append_to(const std::shared_ptr cols, T &x) + void append_to(const std::shared_ptr &cols, T &x) { cols_ = cols; matador::access::serialize(static_cast(*this), x); } - void serialize(const char *id, char &x); - void serialize(const char *id, short &x); - void serialize(const char *id, int &x); - void serialize(const char *id, long &x); - void serialize(const char *id, unsigned char &x); - void serialize(const char *id, unsigned short &x); - void serialize(const char *id, unsigned int &x); - void serialize(const char *id, unsigned long &x); - void serialize(const char *id, float &x); - void serialize(const char *id, double &x); - void serialize(const char *id, bool &x); - void serialize(const char *id, char *x, size_t s); - void serialize(const char *id, varchar_base &x); - void serialize(const char *id, std::string &x); - void serialize(const char *id, date &x); - void serialize(const char *id, time &x); - void serialize(const char *id, identifiable_holder &x, cascade_type); - void serialize(const char *id, basic_identifier &x); + void serialize(const char *id, char &x) override; + void serialize(const char *id, short &x) override; + void serialize(const char *id, int &x) override; + void serialize(const char *id, long &x) override; + void serialize(const char *id, unsigned char &x) override; + void serialize(const char *id, unsigned short &x) override; + void serialize(const char *id, unsigned int &x) override; + void serialize(const char *id, unsigned long &x) override; + void serialize(const char *id, float &x) override; + void serialize(const char *id, double &x) override; + void serialize(const char *id, bool &x) override; + void serialize(const char *id, char *x, size_t s) override; + void serialize(const char *id, varchar_base &x) override; + void serialize(const char *id, std::string &x) override; + void serialize(const char *id, date &x) override; + void serialize(const char *id, time &x) override; + void serialize(const char *id, identifiable_holder &x, cascade_type) override; + void serialize(const char *id, basic_identifier &x) override; private: std::shared_ptr cols_; diff --git a/include/matador/sql/value_serializer.hpp b/include/matador/sql/value_serializer.hpp index 30b5846e9..e8d168965 100644 --- a/include/matador/sql/value_serializer.hpp +++ b/include/matador/sql/value_serializer.hpp @@ -34,33 +34,33 @@ class OOS_SQL_API value_serializer : public serializer { public: value_serializer(); - virtual ~value_serializer() { } + ~value_serializer() override = default; template values *execute(T &x) { - values_.reset(new values); + values_ = std::make_unique(); matador::access::serialize(static_cast(*this), x); return values_.release(); } - void serialize(const char *id, char &x); - void serialize(const char *id, short &x); - void serialize(const char *id, int &x); - void serialize(const char *id, long &x); - void serialize(const char *id, unsigned char &x); - void serialize(const char *id, unsigned short &x); - void serialize(const char *id, unsigned int &x); - void serialize(const char *id, unsigned long &x); - void serialize(const char *id, float &x); - void serialize(const char *id, double &x); - void serialize(const char *id, bool &x); - void serialize(const char *id, char *x, size_t s); - void serialize(const char *id, varchar_base &x); - void serialize(const char *id, std::string &x); - void serialize(const char *id, date &x); - void serialize(const char *id, time &x); - void serialize(const char *id, identifiable_holder &x, cascade_type); - void serialize(const char *id, basic_identifier &x); + void serialize(const char *id, char &x) override; + void serialize(const char *id, short &x) override; + void serialize(const char *id, int &x) override; + void serialize(const char *id, long &x) override; + void serialize(const char *id, unsigned char &x) override; + void serialize(const char *id, unsigned short &x) override; + void serialize(const char *id, unsigned int &x) override; + void serialize(const char *id, unsigned long &x) override; + void serialize(const char *id, float &x) override; + void serialize(const char *id, double &x) override; + void serialize(const char *id, bool &x) override; + void serialize(const char *id, char *x, size_t s) override; + void serialize(const char *id, varchar_base &x) override; + void serialize(const char *id, std::string &x) override; + void serialize(const char *id, date &x) override; + void serialize(const char *id, time &x) override; + void serialize(const char *id, identifiable_holder &x, cascade_type) override; + void serialize(const char *id, basic_identifier &x) override; private: std::unique_ptr values_; diff --git a/include/matador/unit/test_suite.hpp b/include/matador/unit/test_suite.hpp index 8f57f6570..8979a8170 100644 --- a/include/matador/unit/test_suite.hpp +++ b/include/matador/unit/test_suite.hpp @@ -168,14 +168,14 @@ class OOS_UNIT_API test_suite struct unit_lister : public std::unary_function { - unit_lister(std::ostream &o, bool b = false); + explicit unit_lister(std::ostream &o, bool b = false); void operator()(const test_suite::value_type &x) const; std::ostream &out; bool brief; }; public: - test_suite(); + test_suite() = default; virtual ~test_suite(); /** diff --git a/include/matador/unit/unit_exception.hpp b/include/matador/unit/unit_exception.hpp index 78d49c185..51aab2aa1 100644 --- a/include/matador/unit/unit_exception.hpp +++ b/include/matador/unit/unit_exception.hpp @@ -44,18 +44,18 @@ class unit_exception : public std::exception * * @param msg Message of the exception. */ - explicit unit_exception(std::string msg) throw() + explicit unit_exception(std::string msg) noexcept : what_(std::move(msg)) {} - virtual ~unit_exception() throw() {} + ~unit_exception() noexcept override = default; /** * Returns the message of this exception. * * @return The message of the exception. */ - virtual const char* what() const throw() + const char* what() const noexcept override { return what_.c_str(); } diff --git a/include/matador/unit/unit_test.hpp b/include/matador/unit/unit_test.hpp index 778368e35..48f12278d 100644 --- a/include/matador/unit/unit_test.hpp +++ b/include/matador/unit/unit_test.hpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -61,7 +60,7 @@ * exception is caught by the test_suite the * message is displayed */ -#define UNIT_ASSERT_EQUAL(a, b, msg) assert_equal(a, b, msg, __LINE__, __FILE__) +#define UNIT_ASSERT_EQUAL(a, b) assert_equal(a, b, __LINE__, __FILE__) /** * @brief Checks if a is not msgstrequal b. @@ -71,7 +70,7 @@ * exception is caught by the test_suite the * message is displayed */ -#define UNIT_ASSERT_NOT_EQUAL(a, b, msg) assert_not_equal(a, b, msg, __LINE__, __FILE__) +#define UNIT_ASSERT_NOT_EQUAL(a, b) assert_not_equal(a, b, __LINE__, __FILE__) /** * @brief Checks if a is greater b. @@ -81,7 +80,7 @@ * exception is caught by the test_suite the * message is displayed */ -#define UNIT_ASSERT_GREATER(a, b, msg) assert_greater(a, b, msg, __LINE__, __FILE__) +#define UNIT_ASSERT_GREATER(a, b) assert_greater(a, b, __LINE__, __FILE__) /** * @brief Checks if a is greater b. @@ -91,7 +90,7 @@ * exception is caught by the test_suite the * message is displayed */ -#define UNIT_ASSERT_LESS(a, b, msg) assert_less(a, b, msg, __LINE__, __FILE__) +#define UNIT_ASSERT_LESS(a, b) assert_less(a, b, __LINE__, __FILE__) /** * @brief Checks if a evaluates to false. @@ -101,7 +100,7 @@ * The exception is caught by the test_suite the * message is displayed */ -#define UNIT_ASSERT_FALSE(a, msg) assert_false(a, msg, __LINE__, __FILE__) +#define UNIT_ASSERT_FALSE(a) assert_false(a, __LINE__, __FILE__) /** * @brief Checks if a evaluates to true. @@ -111,7 +110,7 @@ * The exception is caught by the test_suite the * message is displayed */ -#define UNIT_ASSERT_TRUE(a, msg) assert_true(a, msg, __LINE__, __FILE__) +#define UNIT_ASSERT_TRUE(a) assert_true(a, __LINE__, __FILE__) /** * @brief Checks if o is NULL. @@ -121,7 +120,7 @@ * exception is caught by the test_suite the * message is displayed */ -#define UNIT_ASSERT_NULL(o, msg) assert_null(o, msg, __LINE__, __FILE__) +#define UNIT_ASSERT_NULL(o) assert_null(o, __LINE__, __FILE__) /** * @brief Checks if o is not NULL. @@ -131,7 +130,7 @@ * exception is caught by the test_suite the * message is displayed */ -#define UNIT_ASSERT_NOT_NULL(o, msg) assert_not_null(o, msg, __LINE__, __FILE__) +#define UNIT_ASSERT_NOT_NULL(o) assert_not_null(o, __LINE__, __FILE__) /** * @brief Checks if a is equal b. @@ -141,19 +140,19 @@ * exception is caught by the test_suite the * message is displayed */ -#define UNIT_ASSERT_EXCEPTION(expression, exception_type, exception_msg, msg) \ +#define UNIT_ASSERT_EXCEPTION(expression, exception_type, exception_msg) \ do { \ bool exception_caught(false); \ try { \ expression; \ } catch(exception_type &ex) { \ - assert_equal(ex.what(), exception_msg, msg, __LINE__, __FILE__); \ + assert_equal(ex.what(), exception_msg, __LINE__, __FILE__); \ exception_caught = true; \ } \ if (!exception_caught) { \ - error(msg, __LINE__, __FILE__); \ + error("expected exception not caught", __LINE__, __FILE__); \ } \ - } while(false); + } while(false) /** @@ -162,7 +161,7 @@ * If a is not equal b the test prints * the given message to stdout. */ -#define UNIT_EXPECT_EQUAL(a, b, msg) expect_equal(a, b, msg, __LINE__, __FILE__) +#define UNIT_EXPECT_EQUAL(a, b) expect_equal(a, b, __LINE__, __FILE__) /** * @brief Checks if a is greater b. @@ -170,7 +169,7 @@ * If a is not greater b the test prints * the given message to stdout. */ -#define UNIT_EXPECT_GREATER(a, b, msg) expect_greater(a, b, msg, __LINE__, __FILE__) +#define UNIT_EXPECT_GREATER(a, b) expect_greater(a, b, __LINE__, __FILE__) /** * @brief Checks if a evaluates to false. @@ -178,7 +177,7 @@ * If a doesn't evaluates to false the test method * prints the given message to stdout. */ -#define UNIT_EXPECT_FALSE(a, msg) expect_false(a, msg, __LINE__, __FILE__) +#define UNIT_EXPECT_FALSE(a) expect_false(a, __LINE__, __FILE__) /** * @brief Checks if a evaluates to true. @@ -186,7 +185,7 @@ * If a doesn't evaluates to true the test method * prints the given message to stdout. */ -#define UNIT_EXPECT_TRUE(a, msg) expect_true(a, msg, __LINE__, __FILE__) +#define UNIT_EXPECT_TRUE(a) expect_true(a, __LINE__, __FILE__) /** * @brief Throws an error. @@ -254,7 +253,7 @@ class OOS_UNIT_API unit_test * @param name The name of a test_unit serializable. * @param caption The caption of a test_unit serializable. */ - unit_test(const std::string &name, const std::string &caption); + unit_test(std::string name, std::string caption); virtual ~unit_test(); /** @@ -348,12 +347,12 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class X > - void assert_equal(const X &a, const X &b, const std::string &msg, int line, const char *file) + void assert_equal(const X &a, const X &b, int line, const char *file) { ++current_test_func_info->assertion_count; if (a != b) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; throw unit_exception(msgstr.str()); } } @@ -375,97 +374,59 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class X, class Y > - void assert_equal(const X &a, const Y &b, const std::string &msg, int line, const char *file) + void assert_equal(const X &a, const Y &b, int line, const char *file) { ++current_test_func_info->assertion_count; if (a != b) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; throw unit_exception(msgstr.str()); } } #ifndef MATADOR_DOXYGEN_DOC - void assert_equal(char *&a, const char* &b, const std::string &msg, int line, const char *file) - { - ++current_test_func_info->assertion_count; - if (strcmp(a, b) != 0) { - std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; - throw unit_exception(msgstr.str()); - } - } + void assert_equal(char *&a, const char* &b, int line, const char *file); + void assert_equal(const std::string &a, const char *b, int line, const char *file); + void assert_equal(const char *a, const std::string &b, int line, const char *file); + void assert_equal(const char *a, const char *b, int line, const char *file); - void assert_equal(const std::string &a, const char *b, const std::string &msg, int line, const char *file) - { - ++current_test_func_info->assertion_count; - if (strcmp(a.c_str(), b) != 0) { - std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; - throw unit_exception(msgstr.str()); - } - } - void assert_equal(const char *a, const std::string &b, const std::string &msg, int line, const char *file) - { - ++current_test_func_info->assertion_count; - if (strcmp(a, b.c_str()) != 0) { - std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; - throw unit_exception(msgstr.str()); - } - } - void assert_equal(const char *a, const char *b, const std::string &msg, int line, const char *file) - { - ++current_test_func_info->assertion_count; - if (strcmp(a, b) != 0) { - std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; - throw unit_exception(msgstr.str()); - } - } template < int N1, int N2 > void - assert_equal(const char (&a)[N1], const char (&b)[N2], const std::string &msg, int line, const char *file) + assert_equal(const char (&a)[N1], const char (&b)[N2], int line, const char *file) { ++current_test_func_info->assertion_count; if (strcmp(a, b) != 0) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; throw unit_exception(msgstr.str()); } } + template < int N1, int N2 > void - assert_equal(char (&a)[N1], const char (&b)[N2], const std::string &msg, int line, const char *file) + assert_equal(char (&a)[N1], const char (&b)[N2], int line, const char *file) { ++current_test_func_info->assertion_count; if (strcmp(a, b) != 0) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; throw unit_exception(msgstr.str()); } } + template < class X > - void assert_equal(const X &a, const bool &b, const std::string &msg, int line, const char *file) + void assert_equal(const X &a, const bool &b, int line, const char *file) { ++current_test_func_info->assertion_count; bool cmp = a > 0; if (cmp != b) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; throw unit_exception(msgstr.str()); } } - void assert_equal(const bool &a, const bool &b, const std::string &msg, int line, const char *file) - { - ++current_test_func_info->assertion_count; - if (a != b) { - std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; - throw unit_exception(msgstr.str()); - } - } + void assert_equal(const bool &a, const bool &b, int line, const char *file); #endif /* MATADOR_DOXYGEN_DOC */ /** @@ -484,12 +445,12 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class T > - void assert_not_equal(const T &a, const T &b, const std::string &msg, int line, const char *file) + void assert_not_equal(const T &a, const T &b, int line, const char *file) { ++current_test_func_info->assertion_count; if (a == b) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is equal " << b; throw unit_exception(msgstr.str()); } } @@ -511,12 +472,12 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class T, class V > - void assert_not_equal(const T &a, const V &b, const std::string &msg, int line, const char *file) + void assert_not_equal(const T &a, const V &b, int line, const char *file) { ++current_test_func_info->assertion_count; if (a == b) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is equal " << b; throw unit_exception(msgstr.str()); } } @@ -537,24 +498,24 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class T > - void assert_greater(const T &a, const T &b, const std::string &msg, int line, const char *file) + void assert_greater(const T &a, const T &b, int line, const char *file) { ++current_test_func_info->assertion_count; if (a <= b) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not greater " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not greater " << b; throw unit_exception(msgstr.str()); } } #ifndef MATADOR_DOXYGEN_DOC template < class X, class Y > - void assert_greater(const X &a, const Y &b, const std::string &msg, int line, const char *file) + void assert_greater(const X &a, const Y &b, int line, const char *file) { ++current_test_func_info->assertion_count; if (a <= b) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not greater " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not greater " << b; throw unit_exception(msgstr.str()); } } @@ -576,12 +537,12 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class T > - void assert_less(const T &a, const T &b, const std::string &msg, int line, const char *file) + void assert_less(const T &a, const T &b, int line, const char *file) { ++current_test_func_info->assertion_count; if (a >= b) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is greater equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is greater equal " << b; throw unit_exception(msgstr.str()); } } @@ -601,12 +562,12 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class T > - void assert_null(const T *a, const std::string &msg, int line, const char *file) + void assert_null(const T *a, int line, const char *file) { ++current_test_func_info->assertion_count; if (a != nullptr) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not null: " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not null"; throw unit_exception(msgstr.str()); } } @@ -626,12 +587,12 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class T > - void assert_not_null(const T *a, const std::string &msg, int line, const char *file) + void assert_not_null(const T *a, int line, const char *file) { ++current_test_func_info->assertion_count; if (a == 0) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is null: " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is null"; throw unit_exception(msgstr.str()); } } @@ -650,7 +611,7 @@ class OOS_UNIT_API unit_test * @param line The line number of this check in the source code. * @param file The file where this check can be found. */ - void assert_true(bool a, const std::string &msg, int line, const char *file); + void assert_true(bool a, int line, const char *file); /** * @brief Checks if a evaluates to false. @@ -666,7 +627,7 @@ class OOS_UNIT_API unit_test * @param line The line number of this check in the source code. * @param file The file where this check can be found. */ - void assert_false(bool a, const std::string &msg, int line, const char *file); + void assert_false(bool a, int line, const char *file); /** * @brief Checks if a evaluates to true. @@ -680,7 +641,7 @@ class OOS_UNIT_API unit_test * @param line The line number of this check in the source code. * @param file The file where this check can be found. */ - void expect_true(bool a, const std::string &msg, int line, const char *file); + void expect_true(bool a, int line, const char *file); /** * @brief Checks if a evaluates to false. @@ -696,7 +657,7 @@ class OOS_UNIT_API unit_test * @param line The line number of this check in the source code. * @param file The file where this check can be found. */ - void expect_false(bool a, const std::string &msg, int line, const char *file); + void expect_false(bool a, int line, const char *file); /** * @brief Checks if a is equal b. @@ -712,12 +673,12 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class X > - void expect_equal(const X &a, const X &b, const std::string &msg, int line, const char *file) + void expect_equal(const X &a, const X &b, int line, const char *file) { ++current_test_func_info->error_count; if (a != b) { ++current_test_func_info->errors; - std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; + std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; } } @@ -736,57 +697,37 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class X, class Y > - void expect_equal(const X &a, const Y &b, const std::string &msg, int line, const char *file) + void expect_equal(const X &a, const Y &b, int line, const char *file) { ++current_test_func_info->error_count; if (a != b) { ++current_test_func_info->errors; - std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; + std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; } } #ifndef MATADOR_DOXYGEN_DOC - void expect_equal(const char *a, const std::string &b, const std::string &msg, int line, const char *file) - { - ++current_test_func_info->error_count; - if (strcmp(a, b.c_str()) != 0) { - ++current_test_func_info->errors; - std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; - } - } - void expect_equal(const std::string &a, const char *b, const std::string &msg, int line, const char *file) - { - ++current_test_func_info->error_count; - if (strcmp(a.c_str(), b) != 0) { - ++current_test_func_info->errors; - std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; - } - } - void expect_equal(const char *a, const char *b, const std::string &msg, int line, const char *file) - { - ++current_test_func_info->error_count; - if (strcmp(a, b) != 0) { - ++current_test_func_info->errors; - std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; - } - } + void expect_equal(const double &a, const double &b, int line, const char *file); + void expect_equal(const char *a, const std::string &b, int line, const char *file); + void expect_equal(const std::string &a, const char *b, int line, const char *file); + void expect_equal(const char *a, const char *b, int line, const char *file); template < int N1, int N2 > void - expect_equal(const char (&a)[N1], const char (&b)[N2], const std::string &msg, int line, const char *file) + expect_equal(const char (&a)[N1], const char (&b)[N2], int line, const char *file) { ++current_test_func_info->error_count; if (strcmp(a, b) != 0) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; } } template < int N1, int N2 > void - expect_equal(char (&a)[N1], const char (&b)[N2], const std::string &msg, int line, const char *file) + expect_equal(char (&a)[N1], const char (&b)[N2], int line, const char *file) { ++current_test_func_info->error_count; if (strcmp(a, b) != 0) { std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b << ": " << msg; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; } } #endif @@ -804,12 +745,12 @@ class OOS_UNIT_API unit_test * @param file The file where this check can be found. */ template < class T > - void expect_greater(const T &a, const T &b, const std::string &msg, int line, const char *file) + void expect_greater(const T &a, const T &b, int line, const char *file) { ++current_test_func_info->error_count; if (a <= b) { ++current_test_func_info->errors; - std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not greater " << b << ": " << msg; + std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not greater " << b; } } @@ -890,7 +831,7 @@ class OOS_UNIT_API unit_test t_test_func_info_vector test_func_infos_; // runtime data - test_func_info *current_test_func_info; + test_func_info *current_test_func_info = nullptr; }; } diff --git a/include/matador/utils/access.hpp b/include/matador/utils/access.hpp index a8aafa940..fbc64fbd2 100644 --- a/include/matador/utils/access.hpp +++ b/include/matador/utils/access.hpp @@ -23,7 +23,9 @@ class access * @param t Object to be serialized */ template - friend inline void serialize(S &s, T &t); + friend inline void serialize(S &, T &) {} + template + friend inline void serialize(S &, const T &) {} /** * @brief Serializes the given object with the given serializer @@ -38,6 +40,12 @@ class access { t.serialize(s); } + + template + static void serialize(S &s, const T &t) + { + const_cast(t).serialize(s); + } }; } diff --git a/src/db/CMakeLists.txt b/src/db/CMakeLists.txt index 989a3728c..6d45a236c 100644 --- a/src/db/CMakeLists.txt +++ b/src/db/CMakeLists.txt @@ -15,3 +15,9 @@ IF (ODBC_FOUND) ELSE(ODBC_FOUND) MESSAGE(STATUS "Skip building ODBC backend") ENDIF(ODBC_FOUND) + +IF (PostgreSQL_FOUND) + ADD_SUBDIRECTORY(postgresql) +ELSE(PostgreSQL_FOUND) + MESSAGE(STATUS "Skip building PostgreSQL backend") +ENDIF(PostgreSQL_FOUND) diff --git a/src/db/mssql/CMakeLists.txt b/src/db/mssql/CMakeLists.txt index 2225a644b..1d74a5626 100644 --- a/src/db/mssql/CMakeLists.txt +++ b/src/db/mssql/CMakeLists.txt @@ -26,8 +26,8 @@ TARGET_LINK_LIBRARIES(matador-mssql matador-utils matador-sql ${ODBC_LIBRARY}) # Set the build version (VERSION) and the API version (SOVERSION) SET_TARGET_PROPERTIES(matador-mssql PROPERTIES - VERSION 0.5.0 - SOVERSION 0) + VERSION ${APP_VERSION} + SOVERSION ${APP_MAJOR_VERSION}) SOURCE_GROUP("include\\matador\\db\\mssql" FILES ${HEADER}) SOURCE_GROUP("src\\matador\\db\\mssql" FILES ${SOURCES}) diff --git a/src/db/mssql/mssql_connection.cpp b/src/db/mssql/mssql_connection.cpp index 3b4d48d80..62c88082e 100644 --- a/src/db/mssql/mssql_connection.cpp +++ b/src/db/mssql/mssql_connection.cpp @@ -48,7 +48,6 @@ void mssql_connection::open(const std::string &connection) { // dns syntax: // user[:passwd]@host[:port]/instance/db [(Drivername)] - //static const std::regex DNS_RGX("(.+?)(?::(.+?))?@([^:]+?)(?::([1-9][0-9]*?))?(?:/(.+?))?/(.+?)(?:\\s+\\((.+)\\))?"); static const std::regex DNS_RGX(R"((.+?)(?::(.+?))?@([^:]+?)(?::([1-9][0-9]*?))?(?:/(.+?))?/(.+?)(?:\s+\((.+)\))?)"); std::smatch what; diff --git a/src/db/mysql/CMakeLists.txt b/src/db/mysql/CMakeLists.txt index be8d98e95..dc7634945 100644 --- a/src/db/mysql/CMakeLists.txt +++ b/src/db/mysql/CMakeLists.txt @@ -30,8 +30,8 @@ TARGET_LINK_LIBRARIES(matador-mysql matador-utils matador-sql ${MYSQL_LIBRARY}) # Set the build version (VERSION) and the API version (SOVERSION) SET_TARGET_PROPERTIES(matador-mysql PROPERTIES - VERSION 0.5.0 - SOVERSION 0) + VERSION ${APP_VERSION} + SOVERSION ${APP_MAJOR_VERSION}) SOURCE_GROUP("include\\matador\\db\\mysql" FILES ${HEADER}) SOURCE_GROUP("src\\matador\\db\\mysql" FILES ${SOURCES}) diff --git a/src/db/mysql/mysql_connection.cpp b/src/db/mysql/mysql_connection.cpp index 13b6e66d3..82da6281a 100644 --- a/src/db/mysql/mysql_connection.cpp +++ b/src/db/mysql/mysql_connection.cpp @@ -105,12 +105,9 @@ detail::result_impl* mysql_connection::execute(const matador::sql &sql) return execute(stmt); } -detail::result_impl* mysql_connection::execute(const std::string &stmt) +detail::result_impl* mysql_connection::execute(const std::string &sql) { - if (mysql_query(&mysql_, stmt.c_str())) { - throw mysql_exception(&mysql_, "mysql_query", stmt); - } - return new mysql_result(&mysql_); + return execute_internal(sql); } detail::statement_impl* mysql_connection::prepare(const matador::sql &stmt) @@ -121,19 +118,19 @@ detail::statement_impl* mysql_connection::prepare(const matador::sql &stmt) void mysql_connection::begin() { // TODO: check result - std::unique_ptr res(static_cast(execute("START TRANSACTION;"))); + std::unique_ptr res(execute_internal("START TRANSACTION;")); } void mysql_connection::commit() { // TODO: check result - std::unique_ptr res(static_cast(execute("COMMIT;"))); + std::unique_ptr res(execute_internal("COMMIT;")); } void mysql_connection::rollback() { // TODO: check result - std::unique_ptr res(static_cast(execute("ROLLBACK;"))); + std::unique_ptr res(execute_internal("ROLLBACK;")); } std::string mysql_connection::type() const @@ -150,20 +147,14 @@ bool mysql_connection::exists(const std::string &tablename) { std::string stmt("SHOW TABLES LIKE '" + tablename + "'"); // std::string stmt("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '" + db_ + "' AND table_name = '" + tablename + "' LIMIT 1"); - std::unique_ptr res(static_cast(execute(stmt))); - if (!res->fetch()) { - return false; - } else { - return true; -// char *end; -// return strtoul(res->column(0), &end, 10) == 1; - } + std::unique_ptr res(execute_internal(stmt)); + return res->fetch(); } std::vector mysql_connection::describe(const std::string &table) { std::string stmt("SHOW COLUMNS FROM " + table); - std::unique_ptr res(static_cast(execute(stmt))); + std::unique_ptr res(execute_internal(stmt)); std::vector fields; @@ -181,6 +172,14 @@ std::vector mysql_connection::describe(const std::string &table) return fields; } +mysql_result *mysql_connection::execute_internal(const std::string &sql) +{ + if (mysql_query(&mysql_, sql.c_str())) { + throw mysql_exception(&mysql_, "mysql_query", sql); + } + return new mysql_result(&mysql_); +} + basic_dialect* mysql_connection::dialect() { return &dialect_; diff --git a/src/db/mysql/mysql_result.cpp b/src/db/mysql/mysql_result.cpp index 9520eae01..95d710cc4 100644 --- a/src/db/mysql/mysql_result.cpp +++ b/src/db/mysql/mysql_result.cpp @@ -34,9 +34,6 @@ namespace mysql { mysql_result::mysql_result(MYSQL *c) : affected_rows_((size_type)mysql_affected_rows(c)) - , rows_(0) - , fields_(0) - , res_(nullptr) { res_ = mysql_store_result(c); if (res_ == nullptr && mysql_errno(c) > 0) { @@ -46,6 +43,7 @@ mysql_result::mysql_result(MYSQL *c) fields_ = mysql_num_fields(res_); } } + mysql_result::~mysql_result() { if (res_) { diff --git a/src/db/mysql/mysql_statement.cpp b/src/db/mysql/mysql_statement.cpp index 9ba5645c7..bb9aae939 100644 --- a/src/db/mysql/mysql_statement.cpp +++ b/src/db/mysql/mysql_statement.cpp @@ -25,6 +25,7 @@ #include "matador/utils/date.hpp" #include "matador/utils/time.hpp" #include "matador/utils/identifiable_holder.hpp" +#include "matador/utils/identifier.hpp" #include "matador/sql/sql.hpp" @@ -56,9 +57,7 @@ mysql_statement::mysql_statement(mysql_connection &db, const matador::sql &stmt) int res = mysql_stmt_prepare(stmt_, str().c_str(), str().size()); // std::cout << this << " $$ mysql_statement::mysql_statement:\t\t\t\tcreating STMT " << stmt_ << "\n"; - if (res > 0) { - throw_stmt_error(res, stmt_, "mysql", str()); - } + throw_stmt_error(res, stmt_, "mysql", str()); } mysql_statement::~mysql_statement() @@ -109,20 +108,14 @@ detail::result_impl* mysql_statement::execute() } if (host_size > 0) { int res = mysql_stmt_bind_param(stmt_, &host_array.front()); - if (res > 0) { - throw_stmt_error(res, stmt_, "mysql", str()); - } + throw_stmt_error(res, stmt_, "mysql", str()); } int res = mysql_stmt_execute(stmt_); // std::cout << this << " $$ valgrind: invalid write took place\n"; - if (res > 0) { - throw_stmt_error(res, stmt_, "mysql", str()); - } + throw_stmt_error(res, stmt_, "mysql", str()); res = mysql_stmt_store_result(stmt_); - if (res > 0) { - throw_stmt_error(res, stmt_, "mysql", str()); - } + throw_stmt_error(res, stmt_, "mysql", str()); current_result = new mysql_prepared_result(this, stmt_, bind_, info_); // std::cout << this << " $$ mysql_statement::execute:\t\t\t\t\t\tcreate result STMT " << stmt_ << "\n"; return current_result; diff --git a/src/db/postgresql/CMakeLists.txt b/src/db/postgresql/CMakeLists.txt new file mode 100644 index 000000000..0542c4907 --- /dev/null +++ b/src/db/postgresql/CMakeLists.txt @@ -0,0 +1,54 @@ +SET(SOURCES + postgresql_connection.cpp + postgresql_dialect.cpp + postgresql_exception.cpp + postgresql_result.cpp + postgresql_statement.cpp + postgresql_getvalue.cpp + postgresql_prepared_result.cpp postgresql_dialect_compiler.cpp) + +SET(HEADER + ../../../include/matador/db/postgresql/postgresql_connection.hpp + ../../../include/matador/db/postgresql/postgresql_dialect.hpp + ../../../include/matador/db/postgresql/postgresql_exception.hpp + ../../../include/matador/db/postgresql/postgresql_result.hpp + ../../../include/matador/db/postgresql/postgresql_statement.hpp + ../../../include/matador/db/postgresql/postgresql_getvalue.hpp + ../../../include/matador/db/postgresql/postgresql_prepared_result.hpp + ../../../include/matador/db/postgresql/postgresql_dialect_compiler.hpp) + +SET(HEADER_INSTALL + ../../../include/matador/db/postgresql/postgresql_constants.hpp +) + +ADD_LIBRARY(matador-postgresql SHARED ${SOURCES} ${HEADER}) + +TARGET_LINK_LIBRARIES(matador-postgresql matador-utils matador-sql ${PostgreSQL_LIBRARIES}) + +# Set the build version (VERSION) and the API version (SOVERSION) +SET_TARGET_PROPERTIES(matador-postgresql + PROPERTIES + VERSION ${APP_VERSION} + SOVERSION ${APP_MAJOR_VERSION}) + +SOURCE_GROUP("include\\matador\\db\\postgresql" FILES ${HEADER}) +SOURCE_GROUP("src\\matador\\db\\postgresql" FILES ${SOURCES}) + +INSTALL( + TARGETS matador-postgresql + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + COMPONENT libraries +) + +INSTALL( + TARGETS matador-postgresql + DESTINATION lib + COMPONENT libraries +) + +INSTALL( + FILES ${HEADER_INSTALL} + DESTINATION include/matador/db/postgresql + COMPONENT headers +) diff --git a/src/db/postgresql/limit.txt b/src/db/postgresql/limit.txt new file mode 100644 index 000000000..687f63b68 --- /dev/null +++ b/src/db/postgresql/limit.txt @@ -0,0 +1,26 @@ +SELECT "owner_id", "item_id" FROM "relation" WHERE ("owner_id" = 1 AND "item_id" = 1) LIMIT 1 +SELECT "owner_id", "item_id" FROM "relation" WHERE ("owner_id" = 1 AND "ident_id" = 1) LIMIT 1 + +UPDATE "relations" SET "owner_id"=1 WHERE ("owner_id" = 1 AND "ident_id" = 1) LIMIT 1 + +1. copy where clause +2. get first condition from where clause +3. replace value with select of field of first condition and copied where clause limit 1 + +UPDATE "relations" SET "owner_id"=1 WHERE "owner_id" = ( + SELECT "owner_id" + FROM "relations" + WHERE ("owner_id" = 1 AND "ident_id" = 1) + LIMIT 1 +) + +UPDATE server_info SET status = 'active' +WHERE status = 'standby' [[LIMIT 1???]] + +UPDATE server_info SET status = 'active' +WHERE server_ip = ( + SELECT server_ip + FROM server_info + WHERE status = 'standby' + LIMIT 1 + ) \ No newline at end of file diff --git a/src/db/postgresql/postgresql_connection.cpp b/src/db/postgresql/postgresql_connection.cpp new file mode 100644 index 000000000..25c03fcea --- /dev/null +++ b/src/db/postgresql/postgresql_connection.cpp @@ -0,0 +1,197 @@ +// +// Created by sascha on 24.05.19. +// + +#include +#include + +#include "matador/db/postgresql/postgresql_connection.hpp" +#include "matador/db/postgresql/postgresql_statement.hpp" +#include "matador/db/postgresql/postgresql_exception.hpp" +#include "matador/db/postgresql/postgresql_result.hpp" + +namespace matador { +namespace postgresql { + +postgresql_connection::postgresql_connection() + :is_open_(false) +{ + +} + +postgresql_connection::~postgresql_connection() +{ + close(); +} + +bool postgresql_connection::is_open() const +{ + return is_open_; +} + +unsigned long postgresql_connection::last_inserted_id() +{ + return 0; +} + +void postgresql_connection::open(const std::string &dns) +{ + if (is_open_) { + return; + } + static const std::regex DNS_RGX("(.+?)(?::(.+?))?@([^:]+?)(?::([1-9][0-9]*?))?/(.+)"); + std::smatch what; + + if (!std::regex_match(dns, what, DNS_RGX)) { + throw_error("mysql:open", "invalid dns: " + dns); + } + + const std::string user = what[1].str(); + const std::string passwd = what[2].str(); + const std::string host = what[3].str(); + + std::string port = "5432"; + if (what[4].matched) { + port = what[4].str(); + } + + db_ = what[5].str(); + + + std::string connection("user=" + user + " password=" + passwd + " host=" + host + " dbname=" + db_ + " port=" + port); + + conn_ = PQconnectdb(connection.c_str()); + if (PQstatus(conn_) == CONNECTION_BAD) { + PQfinish(conn_); + throw postgresql_exception(conn_, "mysql_query", dns); + } + + is_open_ = true; +} + +void postgresql_connection::close() +{ + if (is_open_) { + PQfinish(conn_); + is_open_ = false; + } +} + +detail::result_impl *postgresql_connection::execute(const matador::sql &sql) +{ + std::string stmt = dialect_.direct(sql); + return execute_internal(stmt); +} + +detail::result_impl *postgresql_connection::execute(const std::string &stmt) +{ + return execute_internal(stmt); +} + +detail::statement_impl *postgresql_connection::prepare(const matador::sql &stmt) +{ + return new postgresql_statement(*this, stmt); +} + +void postgresql_connection::begin() +{ + // TODO: check result + std::unique_ptr res(execute_internal("START TRANSACTION;")); +} + +void postgresql_connection::commit() +{ + // TODO: check result + std::unique_ptr res(execute_internal("COMMIT;")); +} + +void postgresql_connection::rollback() +{ + // TODO: check result + std::unique_ptr res(execute_internal("ROLLBACK;")); +} + +std::string postgresql_connection::type() const +{ + return "postgresql"; +} + +std::string postgresql_connection::version() const +{ + return ""; +} + +bool postgresql_connection::exists(const std::string &tablename) +{ + std::string stmt("SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '" + tablename + "'"); + + std::unique_ptr res(execute_internal(stmt)); + return res->result_rows() == 1; +} + +std::vector postgresql_connection::describe(const std::string &table) +{ + std::string stmt( + "SELECT ordinal_position, column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_schema='public' AND table_name='" + table + "'"); + + std::unique_ptr res(execute_internal(stmt)); + + std::vector fields; + + if (res->result_rows() == 0) { + return fields; + } + + do { + field f; + + char *end = nullptr; + f.index(strtoul(res->column(0), &end, 10) - 1); + f.name(res->column(1)); + f.type(dialect_.string_type(res->column(2))); + end = nullptr; + f.not_null(strtoul(res->column(3), &end, 10) == 0); + f.default_value(res->column(4)); + fields.push_back(f); + } while(res->fetch()); + + return fields; +} + +PGconn *postgresql_connection::handle() const +{ + return conn_; +} + +basic_dialect *postgresql_connection::dialect() +{ + return &dialect_; +} + +postgresql_result* postgresql_connection::execute_internal(const std::string &stmt) +{ +// std::cout << "\n" << stmt; + PGresult *res = PQexec(conn_, stmt.c_str()); + + auto status = PQresultStatus(res); + if (status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK) { + THROW_POSTGRESQL_ERROR(conn_, "execute", "error on sql statement"); + } + return new postgresql_result(res); +} + +} +} + +extern "C" +{ +MATADOR_POSTGRESQL_API matador::connection_impl* create_database() +{ + return new matador::postgresql::postgresql_connection(); +} + +MATADOR_POSTGRESQL_API void destroy_database(matador::connection_impl *db) +{ + delete db; +} +} diff --git a/src/db/postgresql/postgresql_dialect.cpp b/src/db/postgresql/postgresql_dialect.cpp new file mode 100644 index 000000000..ca0feb58e --- /dev/null +++ b/src/db/postgresql/postgresql_dialect.cpp @@ -0,0 +1,108 @@ +// +// Created by sascha on 24.05.19. +// + +#include + +#include "matador/db/postgresql/postgresql_dialect_compiler.hpp" +#include "matador/db/postgresql/postgresql_dialect.hpp" + +#include "matador/sql/dialect_token.hpp" +#include "matador/sql/basic_dialect_compiler.hpp" +#include "matador/sql/basic_dialect_linker.hpp" + +namespace matador { +namespace postgresql { + +postgresql_dialect::postgresql_dialect() +: basic_dialect(new postgresql_dialect_compiler, new detail::basic_dialect_linker) +{ + +} + +const char *postgresql_dialect::type_string(matador::data_type type) const +{ + switch (type) { + case data_type::type_char: + return "CHAR(1)"; + case data_type::type_short: + return "SMALLINT"; + case data_type::type_int: + return "INTEGER"; + case data_type::type_long: + //return "INTEGER"; + return "BIGINT"; + case data_type::type_unsigned_char: + return "CHAR(1)"; + case data_type::type_unsigned_short: + return "INTEGER"; + case data_type::type_unsigned_int: + return "BIGINT"; + case data_type::type_unsigned_long: + //return "INTEGER"; + return "BIGINT"; + case data_type::type_bool: + return "INTEGER"; + case data_type::type_float: + return "FLOAT4"; + case data_type::type_double: + return "FLOAT8"; + case data_type::type_date: + return "DATE"; + case data_type::type_time: + return "TIMESTAMP"; + case data_type::type_char_pointer: + return "VARCHAR"; + case data_type::type_varchar: + return "VARCHAR"; + case data_type::type_text: + return "TEXT"; + default: + { + std::stringstream msg; + msg << "postgresql sql: unknown type xxx [" << (int)type << "]"; + throw std::logic_error(msg.str()); + //throw std::logic_error("mysql sql: unknown type"); + } + } +} + +matador::data_type postgresql_dialect::string_type(const char *type) const +{ + if (strncmp(type, "int", 3) == 0) { + return data_type::type_int; + } else if (strncmp(type, "bigint", 6) == 0) { + return data_type::type_long; + } else if (strcmp(type, "date") == 0) { + return data_type::type_date; + } else if (strncmp(type, "timestamp", 8) == 0) { + return data_type::type_time; + } else if (strcmp(type, "real") == 0 || strcmp(type, "float4") == 0) { + return data_type::type_float; + } else if (strcmp(type, "double precision") == 0 || strcmp(type, "float8") == 0) { + return data_type::type_double; + } else if (strncmp(type, "varchar", 7) == 0) { + return data_type::type_varchar; + } else if (strncmp(type, "character varying", 7) == 0) { + return data_type::type_varchar; + } else if (strncmp(type, "text", 0) == 0) { + return data_type::type_text; + } else { + return data_type::type_unknown; + } +} + +matador::dialect_traits::identifier postgresql_dialect::identifier_escape_type() const +{ + return dialect_traits::ESCAPE_BOTH_SAME; +} + +std::string postgresql_dialect::next_placeholder() const +{ + std::stringstream ss; + ss << "$" << bind_count(); + return ss.str(); +} + +} +} diff --git a/src/db/postgresql/postgresql_dialect_compiler.cpp b/src/db/postgresql/postgresql_dialect_compiler.cpp new file mode 100644 index 000000000..4a47d0d53 --- /dev/null +++ b/src/db/postgresql/postgresql_dialect_compiler.cpp @@ -0,0 +1,84 @@ +// +// Created by sascha on 24.06.19. +// +#include "matador/sql/query.hpp" + +#include "matador/db/postgresql/postgresql_dialect_compiler.hpp" + +namespace matador { +namespace postgresql { + +void postgresql_dialect_compiler::visit(const matador::detail::select &) +{ + is_update = false; + is_delete = false; + has_condition_column_name_ = false; +} + +void postgresql_dialect_compiler::visit(const matador::detail::update &) +{ + is_update = true; + is_delete = false; + has_condition_column_name_ = false; +} + +void postgresql_dialect_compiler::visit(const matador::detail::remove &) +{ + is_update = false; + is_delete = true; + has_condition_column_name_ = false; +} + +void postgresql_dialect_compiler::visit(const matador::detail::tablename &tab) +{ + tablename_ = tab.table_name; +} + +void postgresql_dialect_compiler::visit(const matador::detail::from &tab) +{ + tablename_ = tab.table_name; +} + +void postgresql_dialect_compiler::visit(const matador::detail::where &whr) +{ + if (is_update || is_delete) { + where_ = top().current; + whr.cond->accept(*this); + } +} + +void postgresql_dialect_compiler::visit(const matador::detail::basic_column_condition &cond) +{ + if (!has_condition_column_name_) { + condition_column_name_ = cond.field_.name; + has_condition_column_name_ = true; + } +} + +void postgresql_dialect_compiler::visit(const matador::detail::top &limit) +{ + if (!is_update && !is_delete) { + return; + } + + if (!has_condition_column_name_) { + return; + } + + column rowid(condition_column_name_); + auto where_token = std::static_pointer_cast(*where_); + auto sub_select = matador::select({rowid}).from(tablename_).where(where_token->cond).limit(limit.limit_); + auto cond = make_condition(equals(rowid, sub_select)); + + where_token->cond.swap(cond); + + top().tokens_.erase(top().current); +} + +void postgresql_dialect_compiler::on_compile_start() +{ + basic_dialect_compiler::on_compile_start(); +} + +} +} \ No newline at end of file diff --git a/src/db/postgresql/postgresql_exception.cpp b/src/db/postgresql/postgresql_exception.cpp new file mode 100644 index 000000000..35a1d54c5 --- /dev/null +++ b/src/db/postgresql/postgresql_exception.cpp @@ -0,0 +1,65 @@ +// +// Created by sascha on 24.05.19. +// + +#include +#include "matador/db/postgresql/postgresql_exception.hpp" + +namespace matador { + +namespace postgresql { + +std::string error_message(PGconn *db, const std::string &source, const std::string &sql) +{ + std::stringstream msg; + msg << source << ": " << PQerrorMessage(db) << " (" << sql << ")"; + return msg.str(); +} + +//std::string error_message(MYSQL_STMT *stmt, const std::string &source, const std::string &sql) +//{ +// std::stringstream msg; +// msg << source << ": " << mysql_stmt_error(stmt) << " (" << sql << ")"; +// return msg.str(); +//} + +void throw_error(const std::string &source, const std::string &msg) +{ + throw postgresql_exception(source, msg); +} + +void throw_error(int ec, PGconn *db, const std::string &source, const std::string &sql) +{ + if (ec == 0) { + return; + } + throw postgresql_exception(db, source, sql); +} + +//void throw_stmt_error(int ec, MYSQL_STMT *stmt, const std::string &source, const std::string &sql) +//{ +// if (ec == 0) { +// return; +// } +// throw mysql_stmt_exception(stmt, source, sql); +//} + +postgresql_exception::postgresql_exception(const std::string &source, const std::string &what) + : sql_exception("postgresql", (source + ": " + what).c_str()) +{} + + +postgresql_exception::postgresql_exception(PGconn *db, const std::string &source, const std::string &what) + : sql_exception("postgresql", error_message(db, source, what).c_str()) +{} + +postgresql_stmt_exception::postgresql_stmt_exception(const std::string &what) + : sql_exception("postgresql", what.c_str()) +{} + +//postgresql_stmt_exception::postgresql_stmt_exception(MYSQL_STMT *stmt, const std::string &source, const std::string &what) +//: sql_exception("mysql", error_message(stmt, source, what).c_str()) +//{} + +} +} \ No newline at end of file diff --git a/src/db/postgresql/postgresql_getvalue.cpp b/src/db/postgresql/postgresql_getvalue.cpp new file mode 100644 index 000000000..1d9b04846 --- /dev/null +++ b/src/db/postgresql/postgresql_getvalue.cpp @@ -0,0 +1,26 @@ +// +// Created by sascha on 06.06.19. +// + +#include "matador/utils/varchar.hpp" + +#include "matador/db/postgresql/postgresql_getvalue.hpp" + +namespace matador { +namespace detail { + +void get_value(PGresult *res, size_t row, size_t col, char *val, size_t s) +{ + auto value = PQgetvalue(res, row, col); + + size_t len = strlen(value); + if (len > (size_t)s) { + strncpy(val, value, s); + val[s-1] = '\n'; + } else { + strcpy(val, value); + } +} + +} +} \ No newline at end of file diff --git a/src/db/postgresql/postgresql_prepared_result.cpp b/src/db/postgresql/postgresql_prepared_result.cpp new file mode 100644 index 000000000..00e30da9c --- /dev/null +++ b/src/db/postgresql/postgresql_prepared_result.cpp @@ -0,0 +1,168 @@ +// +// Created by sascha on 11.06.19. +// +#include "matador/db/postgresql/postgresql_prepared_result.hpp" +#include "matador/db/postgresql/postgresql_getvalue.hpp" + +#include "matador/utils/basic_identifier.hpp" + +namespace matador { +namespace postgresql { + +postgresql_prepared_result::postgresql_prepared_result(postgresql_statement *, PGresult *res) + : res_(res) + , affected_rows_(0) + , rows_(PQntuples(res)) + , fields_(PQnfields(res)) +{ + +} + +postgresql_prepared_result::~postgresql_prepared_result() +{ + PQclear(res_); +} + +const char *postgresql_prepared_result::column(postgresql_prepared_result::size_type c) const +{ + return PQgetvalue(res_,row_, c); +} + +bool postgresql_prepared_result::fetch() +{ + return row_++ < rows_; +} + +postgresql_prepared_result::size_type postgresql_prepared_result::affected_rows() const +{ + return affected_rows_; +} + +postgresql_prepared_result::size_type postgresql_prepared_result::result_rows() const +{ + return rows_; +} + +postgresql_prepared_result::size_type postgresql_prepared_result::fields() const +{ + return fields_; +} + +int postgresql_prepared_result::transform_index(int index) const +{ + return index; +} + +void postgresql_prepared_result::serialize(const char *, char &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, short &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, int &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, long &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, unsigned char &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, unsigned short &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, unsigned int &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, unsigned long &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, bool &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, float &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, double &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, char *x, size_t s) +{ + detail::get_value(res_, row_, column_++, x, s); +} + +void postgresql_prepared_result::serialize(const char *, matador::date &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, matador::time &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, std::string &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *, varchar_base &x) +{ + detail::get_value(res_, row_, column_++, x); +} + +void postgresql_prepared_result::serialize(const char *id, basic_identifier &x) +{ + x.serialize(id, *this); +} + +void postgresql_prepared_result::serialize(const char *id, identifiable_holder &x, cascade_type) +{ + read_foreign_object(id, x); +} + +bool postgresql_prepared_result::needs_bind() +{ + return result_impl::needs_bind(); +} + +bool postgresql_prepared_result::finalize_bind() +{ + return result_impl::finalize_bind(); +} + +bool postgresql_prepared_result::prepare_fetch() +{ + column_ = 0; + return row_ + 1 <= rows_; +} + +bool postgresql_prepared_result::finalize_fetch() +{ + ++row_; + return true; +} +} +} \ No newline at end of file diff --git a/src/db/postgresql/postgresql_result.cpp b/src/db/postgresql/postgresql_result.cpp new file mode 100644 index 000000000..9343affa1 --- /dev/null +++ b/src/db/postgresql/postgresql_result.cpp @@ -0,0 +1,171 @@ +// +// Created by sascha on 29.05.19. +// + +#include + +#include "matador/utils/string.hpp" +#include "matador/utils/date.hpp" +#include "matador/utils/time.hpp" +#include "matador/utils/basic_identifier.hpp" + +#include "matador/db/postgresql/postgresql_result.hpp" +#include "matador/db/postgresql/postgresql_getvalue.hpp" + +namespace matador { +namespace postgresql { + +postgresql_result::postgresql_result(PGresult *res) + : affected_rows_(0) + , rows_(PQntuples(res)) + , fields_(PQnfields(res)) + , res_(res) +{ +} + +postgresql_result::~postgresql_result() +{ + if (res_) { + PQclear(res_); + } +} + +const char *postgresql_result::column(postgresql_result::size_type c) const +{ + return PQgetvalue(res_, pos_, c); +} + +bool postgresql_result::fetch() +{ + return pos_++ < rows_; +} + +postgresql_result::size_type postgresql_result::affected_rows() const +{ + return affected_rows_; +} + +postgresql_result::size_type postgresql_result::result_rows() const +{ + return rows_; +} + +postgresql_result::size_type postgresql_result::fields() const +{ + return fields_; +} + +int postgresql_result::transform_index(int index) const +{ + return index; +} + +void postgresql_result::serialize(const char *, char &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, short &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, int &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, long &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, unsigned char &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, unsigned short &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, unsigned int &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, unsigned long &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, bool &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, float &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, double &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, char *x, size_t s) +{ + detail::get_value(res_, pos_, column_++, x, s); +} + +void postgresql_result::serialize(const char *, varchar_base &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, std::string &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, matador::date &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *, matador::time &x) +{ + detail::get_value(res_, pos_, column_++, x); +} + +void postgresql_result::serialize(const char *id, matador::basic_identifier &x) +{ + x.serialize(id, *this); +} + +void postgresql_result::serialize(const char *id, matador::identifiable_holder &x, cascade_type) +{ + read_foreign_object(id, x); +} + +bool postgresql_result::prepare_fetch() +{ + column_ = 0; + return pos_ + 1 <= rows_; +} + +bool postgresql_result::finalize_fetch() +{ + ++pos_; + return true; +} + +PGresult *postgresql_result::result_handle() +{ + return res_; +} + +} +} \ No newline at end of file diff --git a/src/db/postgresql/postgresql_statement.cpp b/src/db/postgresql/postgresql_statement.cpp new file mode 100644 index 000000000..b97b29927 --- /dev/null +++ b/src/db/postgresql/postgresql_statement.cpp @@ -0,0 +1,251 @@ +// +// Created by sascha on 03.06.19. +// + +#include "matador/db/postgresql/postgresql_exception.hpp" +#include "matador/db/postgresql/postgresql_statement.hpp" +#include "matador/db/postgresql/postgresql_prepared_result.hpp" +#include "matador/db/postgresql/postgresql_connection.hpp" + +#include "matador/utils/identifiable_holder.hpp" +#include "matador/utils/identifier.hpp" + +#include "matador/sql/sql.hpp" + +namespace matador { + +namespace postgresql { + +std::unordered_map postgresql_statement::statement_name_map_ = {}; + +postgresql_statement::postgresql_statement(postgresql_connection &db, const matador::sql &stmt) + : db_(db) +{ + // generate sql + str(db.dialect()->prepare(stmt)); + // parse sql to create result and host arrays + result_size = db.dialect()->column_count(); + host_size = db.dialect()->bind_count(); + + host_strings_.resize(host_size); + host_params_.resize(host_size); + + name_ = generate_statement_name(stmt); + + res_ = PQprepare(db.handle(), name_.c_str(), str().c_str(), host_size, nullptr); + if (res_ == nullptr) { + THROW_POSTGRESQL_ERROR(db_.handle(), "execute", "error on sql statement"); + } else if (PQresultStatus(res_) != PGRES_COMMAND_OK) { + THROW_POSTGRESQL_ERROR(db_.handle(), "execute", "error on sql statement"); + } +} + +postgresql_statement::postgresql_statement(const postgresql_statement &x) + : statement_impl(x) + , db_(x.db_) + , result_size(x.result_size) + , host_size(x.host_size) + , host_strings_(x.host_strings_) + , host_params_(x.host_params_) + , name_(x.name_) +{ + if (res_ != nullptr) { + PQclear(res_); + } + res_ = x.res_; +} + +postgresql_statement &postgresql_statement::operator=(const postgresql_statement &x) +{ + db_ = x.db_; + result_size = x.result_size; + host_index = x.host_index; + host_size = x.host_size; + host_strings_ = x.host_strings_; + host_params_ = x.host_params_; + name_ = x.name_; + + if (res_ != nullptr) { + PQclear(res_); + } + res_ = x.res_; + return *this; +} + +postgresql_statement::~postgresql_statement() +{ + clear(); +} + +void postgresql_statement::clear() +{ + if (res_ != nullptr) { + PQclear(res_); + res_ = nullptr; + } + + host_params_.clear(); + host_strings_.clear(); +} + +detail::result_impl *postgresql_statement::execute() +{ + PGresult *res = PQexecPrepared(db_.handle(), name_.c_str(), host_size, host_params_.data(), nullptr, nullptr, 0); + auto status = PQresultStatus(res); + if (status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK) { + THROW_POSTGRESQL_ERROR(db_.handle(), "execute", "error on sql statement"); + } + return new postgresql_prepared_result(this, res); +} + +void postgresql_statement::reset() +{ +} + +template < class T > +void bind_value(std::vector &strings, std::vector ¶ms, size_t &index, T &x) +{ + strings[index] = std::to_string(x); + params[index] = strings[index].c_str(); + ++index; +} + +template <> +void bind_value(std::vector &strings, std::vector ¶ms, size_t &index, char &x) +{ + strings[index] = x; + params[index] = strings[index].data(); + ++index; +} + +template <> +void bind_value(std::vector &strings, std::vector ¶ms, size_t &index, matador::date &x) +{ + strings[index] = matador::to_string(x, date_format::ISO8601); + params[index] = strings[index].c_str(); + ++index; +} + +template <> +void bind_value(std::vector &strings, std::vector ¶ms, size_t &index, matador::time &x) +{ + strings[index] = matador::to_string(x, "%Y-%m-%d %T.%f"); + params[index] = strings[index].c_str(); + ++index; +} + +void postgresql_statement::serialize(const char *, char &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, short &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, int &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, long &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, unsigned char &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, unsigned short &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, unsigned int &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, unsigned long &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, float &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, double &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, bool &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, char *x, size_t) +{ + host_params_[host_index++] = x; +} + +void postgresql_statement::serialize(const char *, varchar_base &x) +{ + host_strings_[host_index] = x.str(); + host_params_[host_index] = host_strings_[host_index].c_str(); + ++host_index; +} + +void postgresql_statement::serialize(const char *, std::string &x) +{ + host_strings_[host_index] = x; + host_params_[host_index] = host_strings_[host_index].c_str(); + ++host_index; +} + +void postgresql_statement::serialize(const char *, matador::date &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *, matador::time &x) +{ + bind_value(host_strings_, host_params_, host_index, x); +} + +void postgresql_statement::serialize(const char *id, basic_identifier &x) +{ + x.serialize(id, *this); +} + +void postgresql_statement::serialize(const char *id, identifiable_holder &x, cascade_type) +{ + if (x.has_primary_key()) { + x.primary_key()->serialize(id, *this); + } else { + host_params_[host_index++] = nullptr; + } +} + +std::string postgresql_statement::generate_statement_name(const matador::sql &stmt) +{ + std::stringstream name; + name << stmt.table_name() << "_" << stmt.command(); + auto result = postgresql_statement::statement_name_map_.find(name.str()); + + if (result == postgresql_statement::statement_name_map_.end()) { + result = postgresql_statement::statement_name_map_.insert(std::make_pair(name.str(), 0)).first; + } + + name << "_" << ++result->second; + + return name.str(); +} + +} +} \ No newline at end of file diff --git a/src/db/sqlite/CMakeLists.txt b/src/db/sqlite/CMakeLists.txt index 00aeeaaaf..7911ba7c2 100644 --- a/src/db/sqlite/CMakeLists.txt +++ b/src/db/sqlite/CMakeLists.txt @@ -26,8 +26,8 @@ TARGET_LINK_LIBRARIES(matador-sqlite matador-utils matador-sql ${SQLITE3_LIBRARY # Set the build version (VERSION) and the API version (SOVERSION) SET_TARGET_PROPERTIES(matador-sqlite PROPERTIES - VERSION 0.5.0 - SOVERSION 0) + VERSION ${APP_VERSION} + SOVERSION ${APP_MAJOR_VERSION}) SOURCE_GROUP("include\\matador\\db\\sqlite" FILES ${HEADER}) SOURCE_GROUP("src\\matador\\db\\sqlite" FILES ${SOURCES}) diff --git a/src/db/sqlite/sqlite_connection.cpp b/src/db/sqlite/sqlite_connection.cpp index 328172506..baeca7f62 100644 --- a/src/db/sqlite/sqlite_connection.cpp +++ b/src/db/sqlite/sqlite_connection.cpp @@ -42,7 +42,7 @@ void throw_error(int ec, sqlite3 *db, const std::string &source) } sqlite_connection::sqlite_connection() - : sqlite_db_(0) + : sqlite_db_(nullptr) { } @@ -62,7 +62,7 @@ void sqlite_connection::open(const std::string &db) bool sqlite_connection::is_open() const { - return sqlite_db_ != 0; + return sqlite_db_ != nullptr; } void sqlite_connection::close() @@ -71,7 +71,7 @@ void sqlite_connection::close() throw_error(ret, sqlite_db_, "sqlite_close"); - sqlite_db_ = 0; + sqlite_db_ = nullptr; } sqlite3* sqlite_connection::handle() @@ -81,17 +81,17 @@ sqlite3* sqlite_connection::handle() void sqlite_connection::begin() { - std::unique_ptr res(static_cast(execute("BEGIN TRANSACTION;"))); + std::unique_ptr res(execute_internal("BEGIN TRANSACTION;")); } void sqlite_connection::commit() { - std::unique_ptr res(static_cast(execute("COMMIT TRANSACTION;"))); + std::unique_ptr res(execute_internal("COMMIT TRANSACTION;")); } void sqlite_connection::rollback() { - std::unique_ptr res(static_cast(execute("ROLLBACK TRANSACTION;"))); + std::unique_ptr res(execute_internal("ROLLBACK TRANSACTION;")); } std::string sqlite_connection::type() const @@ -107,20 +107,12 @@ std::string sqlite_connection::version() const matador::detail::result_impl* sqlite_connection::execute(const matador::sql &sql) { std::string stmt = dialect_.direct(sql); - return execute(stmt); + return execute_internal(stmt); } matador::detail::result_impl* sqlite_connection::execute(const std::string &stmt) { - std::unique_ptr res(new sqlite_result); - char *errmsg = 0; - int ret = sqlite3_exec(sqlite_db_, stmt.c_str(), parse_result, res.get(), &errmsg); - if (ret != SQLITE_OK) { - std::string error(errmsg); - sqlite3_free(errmsg); - throw sqlite_exception(error); - } - return res.release(); + return execute_internal(stmt); } matador::detail::statement_impl *sqlite_connection::prepare(const matador::sql &sql) @@ -129,10 +121,10 @@ matador::detail::statement_impl *sqlite_connection::prepare(const matador::sql & return new sqlite_statement(*this, stmt); } -bool sqlite_connection::exists(const std::string &tablename) +bool sqlite_connection::exists(const std::string &table_name) { - std::string stmt("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND tbl_name='" + tablename + "' LIMIT 1"); - std::unique_ptr res(static_cast(execute(stmt))); + std::string stmt("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND tbl_name='" + table_name + "' LIMIT 1"); + std::unique_ptr res((execute_internal(stmt))); if (res->result_rows() != 1) { return false; @@ -145,7 +137,7 @@ bool sqlite_connection::exists(const std::string &tablename) std::vector sqlite_connection::describe(const std::string &table) { std::string stmt("PRAGMA table_info(" + table + ")"); - std::unique_ptr res(static_cast(execute(stmt))); + std::unique_ptr res((execute_internal(stmt))); std::vector fields; @@ -173,7 +165,7 @@ basic_dialect *sqlite_connection::dialect() int sqlite_connection::parse_result(void* param, int column_count, char** values, char** /*columns*/) { - sqlite_result *result = static_cast(param); + auto *result = static_cast(param); /******************** * @@ -194,6 +186,18 @@ unsigned long sqlite_connection::last_inserted_id() return static_cast(sqlite3_last_insert_rowid(sqlite_db_)); } +sqlite_result *sqlite_connection::execute_internal(const std::string &stmt) +{ + std::unique_ptr res(new sqlite_result); + char *errmsg = nullptr; + int ret = sqlite3_exec(sqlite_db_, stmt.c_str(), parse_result, res.get(), &errmsg); + if (ret != SQLITE_OK) { + std::string error(errmsg); + sqlite3_free(errmsg); + throw sqlite_exception(error); + } + return res.release(); +} } } diff --git a/src/db/sqlite/sqlite_dialect_compiler.cpp b/src/db/sqlite/sqlite_dialect_compiler.cpp index 1dab05537..d15d29ef8 100644 --- a/src/db/sqlite/sqlite_dialect_compiler.cpp +++ b/src/db/sqlite/sqlite_dialect_compiler.cpp @@ -31,12 +31,12 @@ void sqlite_dialect_compiler::visit(const matador::detail::remove &) void sqlite_dialect_compiler::visit(const matador::detail::tablename &tab) { - tablename_ = tab.tab; + tablename_ = tab.table_name; } void sqlite_dialect_compiler::visit(const matador::detail::from &from1) { - tablename_ = from1.table; + tablename_ = from1.table_name; } void sqlite_dialect_compiler::visit(const matador::detail::where &) @@ -57,8 +57,8 @@ void sqlite_dialect_compiler::visit(const matador::detail::top &limit) column rowid("rowid"); auto where_token = std::static_pointer_cast(*where_); - auto subselect = matador::select({rowid}).from(tablename_).where(where_token->cond).limit(limit.limit_); - auto cond = make_condition(matador::in(rowid, subselect)); + auto sub_select = matador::select({rowid}).from(tablename_).where(where_token->cond).limit(limit.limit_); + auto cond = make_condition(matador::in(rowid, sub_select)); where_token->cond.swap(cond); diff --git a/src/db/sqlite/sqlite_prepared_result.cpp b/src/db/sqlite/sqlite_prepared_result.cpp index 9b2a139b7..897ef95f9 100644 --- a/src/db/sqlite/sqlite_prepared_result.cpp +++ b/src/db/sqlite/sqlite_prepared_result.cpp @@ -23,13 +23,9 @@ sqlite_prepared_result::sqlite_prepared_result(sqlite3_stmt *stmt, int ret) { } -sqlite_prepared_result::~sqlite_prepared_result() +const char* sqlite_prepared_result::column(size_type c) const { -} - -const char* sqlite_prepared_result::column(size_type ) const -{ - return 0; + return (const char*)sqlite3_column_text(stmt_, c); } bool sqlite_prepared_result::fetch() @@ -122,14 +118,14 @@ void sqlite_prepared_result::serialize(const char *, double &x) void sqlite_prepared_result::serialize(const char *, std::string &x) { - size_t s = (size_t)sqlite3_column_bytes(stmt_, result_index_); - const char *text = (const char*)sqlite3_column_text(stmt_, result_index_++); + auto s = (size_t)sqlite3_column_bytes(stmt_, result_index_); + auto *text = (const char*)sqlite3_column_text(stmt_, result_index_++); x.assign(text, s); } void sqlite_prepared_result::serialize(const char *, varchar_base &x) { - size_t s = (size_t)sqlite3_column_bytes(stmt_, result_index_); + auto s = (size_t)sqlite3_column_bytes(stmt_, result_index_); const char *text = (const char*)sqlite3_column_text(stmt_, result_index_++); if (s == 0) { } else { @@ -139,7 +135,7 @@ void sqlite_prepared_result::serialize(const char *, varchar_base &x) void sqlite_prepared_result::serialize(const char *, char *x, size_t s) { - size_t size = (size_t)sqlite3_column_bytes(stmt_, result_index_); + auto size = (size_t)sqlite3_column_bytes(stmt_, result_index_); if (size < s) { #ifdef _MSC_VER strncpy_s(x, size, (const char*)sqlite3_column_text(stmt_, result_index_++), s); diff --git a/src/db/sqlite/sqlite_result.cpp b/src/db/sqlite/sqlite_result.cpp index 6a158250c..b95184294 100644 --- a/src/db/sqlite/sqlite_result.cpp +++ b/src/db/sqlite/sqlite_result.cpp @@ -30,12 +30,10 @@ namespace matador { namespace sqlite { -sqlite_result::sqlite_result() {} - sqlite_result::~sqlite_result() { std::for_each(result_.begin(), result_.end(), [](t_result::value_type& row) { - std::for_each(row.begin(), row.end(), [](char *val) { + std::for_each(row.begin(), row.end(), [](const char *val) { delete [] val; }); }); @@ -246,22 +244,17 @@ void sqlite_result::serialize(const char *, std::string &x) { t_row::value_type val = result_[pos_][column_++]; x = val; -// x.assign(val); } void sqlite_result::serialize(const char *, matador::date &x) { t_row::value_type val = result_[pos_][column_++]; -// std::string val; -// serialize(id, val); x.set(val, date_format::ISO8601); } void sqlite_result::serialize(const char *, matador::time &x) { t_row::value_type val = result_[pos_][column_++]; -// std::string val; -// serialize(id, val); x = matador::time::parse(val, "%Y-%m-%dT%T.%f"); } diff --git a/src/db/sqlite/sqlite_statement.cpp b/src/db/sqlite/sqlite_statement.cpp index 06ce49d35..57ce272db 100644 --- a/src/db/sqlite/sqlite_statement.cpp +++ b/src/db/sqlite/sqlite_statement.cpp @@ -49,13 +49,13 @@ void throw_error(int ec, sqlite3 *db, const std::string &source, const std::stri throw sqlite_exception(msg.str()); } -sqlite_statement::sqlite_statement(sqlite_connection &db, const std::string stmt) +sqlite_statement::sqlite_statement(sqlite_connection &db, const std::string &stmt) : db_(db) - , stmt_(0) + , stmt_(nullptr) { str(stmt); // prepare sqlite statement - int ret = sqlite3_prepare_v2(db_.handle(), str().c_str(), str().size(), &stmt_, 0); + int ret = sqlite3_prepare_v2(db_.handle(), str().c_str(), str().size(), &stmt_, nullptr); throw_error(ret, db_.handle(), "sqlite3_prepare_v2", str()); } @@ -87,8 +87,7 @@ void sqlite_statement::clear() } int ret = sqlite3_finalize(stmt_); throw_error(ret, db_.handle(), "sqlite3_finalize"); - stmt_ = 0; - return; + stmt_ = nullptr; } void sqlite_statement::serialize(const char*, bool &x) @@ -159,19 +158,19 @@ void sqlite_statement::serialize(const char*, double &x) void sqlite_statement::serialize(const char*, char *x, size_t len) { - int ret = sqlite3_bind_text(stmt_, (int)++host_index, x, (int)len, 0); + int ret = sqlite3_bind_text(stmt_, (int)++host_index, x, (int)len, nullptr); throw_error(ret, db_.handle(), "sqlite3_bind_text"); } void sqlite_statement::serialize(const char*, std::string &x) { - int ret = sqlite3_bind_text(stmt_, (int)++host_index, x.c_str(), (int)x.size(), 0); + int ret = sqlite3_bind_text(stmt_, (int)++host_index, x.c_str(), (int)x.size(), nullptr); throw_error(ret, db_.handle(), "sqlite3_bind_text"); } void sqlite_statement::serialize(const char*, varchar_base &x) { - int ret = sqlite3_bind_text(stmt_, (int)++host_index, x.c_str(), (int)x.size(), 0); + int ret = sqlite3_bind_text(stmt_, (int)++host_index, x.c_str(), (int)x.size(), nullptr); throw_error(ret, db_.handle(), "sqlite3_bind_text"); } diff --git a/src/object/CMakeLists.txt b/src/object/CMakeLists.txt index 1f4947fa4..f5d41f2b4 100644 --- a/src/object/CMakeLists.txt +++ b/src/object/CMakeLists.txt @@ -85,8 +85,8 @@ TARGET_LINK_LIBRARIES(matador-object matador-utils) # Set the build version (VERSION) and the API version (SOVERSION) SET_TARGET_PROPERTIES(matador-object PROPERTIES - VERSION 0.5.0 - SOVERSION 0) + VERSION ${APP_VERSION} + SOVERSION ${APP_MAJOR_VERSION}) SOURCE_GROUP("include\\matador\\object" FILES ${HEADER}) SOURCE_GROUP("src\\matador\\object" FILES ${SOURCES}) diff --git a/src/object/object_store.cpp b/src/object/object_store.cpp index 723b9e8a1..dfb0921a8 100644 --- a/src/object/object_store.cpp +++ b/src/object/object_store.cpp @@ -62,7 +62,7 @@ object_store::iterator object_store::detach(const prototype_iterator &i) i->on_detach(); - return remove_prototype_node(i.get(), i->depth == 0); + return iterator(remove_prototype_node(i.get(), i->depth == 0)); } object_store::iterator object_store::find(const char *type) @@ -153,58 +153,6 @@ bool object_store::empty() const return is_empty; } -size_t object_store::depth(const prototype_node *node) const -{ - size_t d = 0; - while (node->parent) { - node = node->parent; - ++d; - } - return d; -} - -void object_store::dump(std::ostream &out) const -{ - const_prototype_iterator node = begin(); - out << "digraph G {\n"; - out << "\tgraph [fontsize=10]\n"; - out << "\tnode [color=\"#0c0c0c\", fillcolor=\"#dd5555\", shape=record, style=\"rounded,filled\", fontname=\"Verdana-Bold\"]\n"; - out << "\tedge [color=\"#0c0c0c\"]\n"; - do { - size_t d = depth(node.get()); - for (size_t i = 0; i < d; ++i) out << " "; - out << *node; - out.flush(); - } while (++node != end()); - out << "}" << std::endl; - - out << "prototype map item keys\n"; - std::for_each(prototype_map_.begin(), prototype_map_.end(), [&](const t_prototype_map::value_type &item) { - out << "key: " << item.first << "\n"; - }); - out << "typeid map item keys\n"; - std::for_each(typeid_prototype_map_.begin(), typeid_prototype_map_.end(), [&](const t_typeid_prototype_map::value_type &item) { - out << "key: " << item.first << "\n"; - }); -} - -void object_store::dump_objects(std::ostream &out) const -{ - const_prototype_iterator root = begin(); - out << "dumping all objects\n"; - - object_proxy *op = root->op_first; - while (op) { - out << "[" << op << "] ("; - if (op->obj()) { - out << op->obj() << " prev [" << op->prev()->obj() << "] next [" << op->next()->obj() << "])\n"; - } else { - out << "serializable 0)\n"; - } - op = op->next_; - } -} - object_proxy* object_store::find_proxy(unsigned long id) const { auto i = object_map_.find(id); @@ -215,19 +163,6 @@ object_proxy* object_store::find_proxy(unsigned long id) const } } -bool object_store::delete_proxy(unsigned long id) -{ - auto i = object_map_.find(id); - if (i == object_map_.end()) { - return false; - } else if (i->second->linked()) { - return false; - } else { - object_map_.erase(i); - return true; - } -} - object_proxy* object_store::insert_proxy(object_proxy *proxy) { if (proxy == nullptr) { @@ -268,26 +203,6 @@ void object_store::remove_proxy(object_proxy *proxy) delete proxy; } -object_proxy* object_store::register_proxy(object_proxy *oproxy) -{ - if (oproxy->id() != 0) { - throw_object_exception("object proxy already registerd"); - } - - if (oproxy->node() == nullptr) { - throw_object_exception("object proxy hasn't git a prototype node"); - } - - oproxy->id(seq_.next()); - - return object_map_.insert(std::make_pair(oproxy->id(), oproxy)).first->second; -} - -sequencer_impl_ptr object_store::exchange_sequencer(const sequencer_impl_ptr &seq) -{ - return seq_.exchange_sequencer(seq); -} - prototype_node* object_store::find_prototype_node(const char *type) const { // check for null if (type == nullptr) { diff --git a/src/object/prototype_iterator.cpp b/src/object/prototype_iterator.cpp index 4ad22f7d2..cd645d6a3 100644 --- a/src/object/prototype_iterator.cpp +++ b/src/object/prototype_iterator.cpp @@ -5,9 +5,6 @@ namespace matador { -prototype_iterator::prototype_iterator() -{} - prototype_iterator::prototype_iterator(prototype_iterator::pointer node) : node_(node) {} @@ -22,9 +19,6 @@ prototype_iterator& prototype_iterator::operator=(const prototype_iterator &x) return *this; } -prototype_iterator::~prototype_iterator() -{} - bool prototype_iterator::operator==(const prototype_iterator &i) const { return (node_ == i.node_); @@ -128,9 +122,6 @@ const_prototype_iterator& const_prototype_iterator::operator=(const prototype_it return *this; } -const_prototype_iterator::~const_prototype_iterator() -{} - bool const_prototype_iterator::operator==(const const_prototype_iterator &i) const { return (node_ == i.node_); diff --git a/src/object/prototype_node.cpp b/src/object/prototype_node.cpp index 7b0b8ab6c..edbaa1260 100644 --- a/src/object/prototype_node.cpp +++ b/src/object/prototype_node.cpp @@ -1,3 +1,5 @@ +#include + /* * This file is part of OpenObjectStore OOS. * @@ -25,18 +27,11 @@ using namespace std; namespace matador { -prototype_node::prototype_node() -{} - -prototype_node::~prototype_node() -{ -} - void prototype_node::initialize(object_store *tree, const char *type, bool abstract) { tree_ = tree; - first.reset(new prototype_node); - last.reset(new prototype_node); + first = std::make_unique(); + last = std::make_unique(); type_.assign(type); abstract_ = abstract; first->next = last.get(); @@ -77,9 +72,7 @@ void prototype_node::append(prototype_node *sibling) if (!parent) { sibling->op_first = new object_proxy(); -// sibling->op_first = new object_proxy(nullptr); sibling->op_last = sibling->op_marker = new object_proxy(); -// sibling->op_last = sibling->op_marker = new object_proxy(nullptr); sibling->op_first->next_ = sibling->op_last; sibling->op_last->prev_ = sibling->op_first; } else { @@ -220,8 +213,8 @@ void prototype_node::unlink() // unlink node prev->next = next; next->prev = prev; - next = 0; - prev = 0; + next = nullptr; + prev = nullptr; } prototype_node* prototype_node::next_node() const @@ -264,7 +257,7 @@ prototype_node* prototype_node::previous_node() const { // if node has a previous sibling, we set it // as our next iterator. then we check if there - // are last childs. if so, we set the last last + // are last children. if so, we set the last last // child as our iterator if (prev && prev->prev) { const prototype_node *node = prev; @@ -283,7 +276,7 @@ prototype_node* prototype_node::previous_node(const prototype_node *root) const { // if node has a previous sibling, we set it // as our next iterator. then we check if there - // are last childs. if so, we set the last last + // are last children. if so, we set the last last // child as our iterator if (prev && prev->prev) { const prototype_node *node = prev; @@ -303,13 +296,13 @@ object_store *prototype_node::tree() const return tree_; } -bool prototype_node::is_child_of(const prototype_node *parent) const +bool prototype_node::is_child_of(const prototype_node *prnt) const { const prototype_node *node = this; - while (parent->depth < node->depth) { + while (prnt->depth < node->depth) { node = node->parent; } - return node == parent; + return node == prnt; } @@ -455,30 +448,4 @@ const prototype_node::relation_node_info &prototype_node::node_info() const return relation_node_info_; } -std::ostream& operator <<(std::ostream &os, const prototype_node &pn) -{ - if (pn.parent) { - os << "\t" << pn.parent->type_ << " -> " << pn.type_ << "\n"; - } - os << "\t" << pn.type_ << " [label=\"{" << pn.type_ << " (" << &pn << ")"; - os << "|{op_first|" << pn.op_first << "}"; - os << "|{op_marker|" << pn.op_marker << "}"; - os << "|{op_last|" << pn.op_last << "}"; - os << "|{parent|" << pn.parent << "}"; - os << "|{prev|" << pn.prev << "}"; - os << "|{next|" << pn.next << "}"; - os << "|{first|" << pn.first.get() << "}"; - os << "|{last|" << pn.last.get() << "}"; - // determine size - int i = 0; - const object_proxy *iop = pn.op_first; - while (iop && iop->next() != pn.op_marker) { - ++i; - iop = iop->next(); - } - os << "|{size|" << i << "}"; - os << "}\"]\n"; - return os; -} - } diff --git a/src/orm/CMakeLists.txt b/src/orm/CMakeLists.txt index 3113da697..ccc1ef365 100644 --- a/src/orm/CMakeLists.txt +++ b/src/orm/CMakeLists.txt @@ -26,8 +26,8 @@ TARGET_LINK_LIBRARIES(matador-orm matador-utils matador-sql matador-object) # Set the build version (VERSION) and the API version (SOVERSION) SET_TARGET_PROPERTIES(matador-orm PROPERTIES - VERSION 0.5.0 - SOVERSION 0) + VERSION ${APP_VERSION} + SOVERSION ${APP_MAJOR_VERSION}) SOURCE_GROUP("include\\matador\\orm" FILES ${HEADER}) SOURCE_GROUP("src\\matador\\orm" FILES ${SOURCES}) diff --git a/src/sql/CMakeLists.txt b/src/sql/CMakeLists.txt index 8118a56aa..d21465e7d 100644 --- a/src/sql/CMakeLists.txt +++ b/src/sql/CMakeLists.txt @@ -23,7 +23,7 @@ SET(SOURCES type.cpp query_value_column_processor.cpp query_value_creator.cpp -) + ) SET(HEADER ${CMAKE_SOURCE_DIR}/include/matador/sql/condition.hpp @@ -66,8 +66,8 @@ TARGET_LINK_LIBRARIES(matador-sql matador-utils) # Set the build version (VERSION) and the API version (SOVERSION) SET_TARGET_PROPERTIES(matador-sql PROPERTIES - VERSION 0.5.0 - SOVERSION 0) + VERSION ${APP_VERSION} + SOVERSION ${APP_MAJOR_VERSION}) SOURCE_GROUP("include\\matador\\sql" FILES ${HEADER}) SOURCE_GROUP("src\\matador\\sql" FILES ${SOURCES}) diff --git a/src/sql/basic_dialect.cpp b/src/sql/basic_dialect.cpp index 87c7c0e6a..ed26fb6b3 100644 --- a/src/sql/basic_dialect.cpp +++ b/src/sql/basic_dialect.cpp @@ -48,7 +48,9 @@ std::string basic_dialect::prepare(const sql &s) std::string basic_dialect::build(const sql &s, t_compile_type compile_type) { compile_type_ = compile_type; - + bind_count_ = 0; + column_count_ = 0; + push(s); compile(); link(); @@ -172,6 +174,11 @@ void basic_dialect::escape_quotes_in_literals(std::string &str) const replace_all(str, single_quote, double_quote); } +std::string basic_dialect::next_placeholder() const +{ + return "?"; +} + char basic_dialect::identifier_opening_quote() const { return token_at(detail::token::START_QUOTE)[0]; diff --git a/src/sql/basic_dialect_linker.cpp b/src/sql/basic_dialect_linker.cpp index b8b5f113c..6012d7841 100644 --- a/src/sql/basic_dialect_linker.cpp +++ b/src/sql/basic_dialect_linker.cpp @@ -14,7 +14,7 @@ namespace detail { void basic_dialect_linker::link() { // build the query - for(auto tokptr : top().tokens_) { + for(auto const &tokptr : top().tokens_) { tokptr->accept(*this); } } @@ -42,12 +42,12 @@ void basic_dialect_linker::visit(matador::detail::query &q) void basic_dialect_linker::visit(const matador::detail::create &create) { - dialect().append_to_result(token_string(create.type) + " " + dialect_->prepare_identifier(create.table) + " "); + dialect().append_to_result(token_string(create.type) + " " + dialect_->prepare_identifier(create.table_name) + " "); } void basic_dialect_linker::visit(const matador::detail::drop &drop) { - dialect().append_to_result(token_string(drop.type) + " " + dialect_->prepare_identifier(drop.table) + " "); + dialect().append_to_result(token_string(drop.type) + " " + dialect_->prepare_identifier(drop.table_name) + " "); } void basic_dialect_linker::visit(const matador::detail::select &select) @@ -67,7 +67,7 @@ void basic_dialect_linker::visit(const matador::detail::update &update) void basic_dialect_linker::visit(const matador::detail::tablename &table) { - dialect().append_to_result(dialect_->prepare_identifier(table.tab) + " "); + dialect().append_to_result(dialect_->prepare_identifier(table.table_name) + " "); } void basic_dialect_linker::visit(const matador::detail::set &set) @@ -116,7 +116,7 @@ void basic_dialect_linker::visit(const matador::detail::basic_value &val) dialect().append_to_result(val.safe_string(dialect())); } else { dialect().inc_bind_count(); - dialect().append_to_result("?"); + dialect().append_to_result(dialect().next_placeholder()); } } @@ -142,40 +142,38 @@ void basic_dialect_linker::visit(const matador::detail::group_by &by) void basic_dialect_linker::visit(const matador::detail::insert &insert) { - dialect().append_to_result(token_string(insert.type) + " " + dialect_->prepare_identifier(insert.table) + " "); + dialect().append_to_result(token_string(insert.type) + " " + dialect_->prepare_identifier(insert.table_name) + " "); } void basic_dialect_linker::visit(const matador::detail::from &from) { - if (from.table.empty()) { + if (from.table_name.empty()) { dialect().append_to_result(token_string(from.type) + " "); } else { - dialect().append_to_result(token_string(from.type) + " " + dialect_->prepare_identifier(from.table) + " "); + dialect().append_to_result(token_string(from.type) + " " + dialect_->prepare_identifier(from.table_name) + " "); } } void basic_dialect_linker::visit(const matador::detail::where &where) { dialect().append_to_result(token_string(where.type) + " "); - where.cond->accept(*this); + dialect().append_to_result(where.cond->evaluate(dialect())); +// where.cond->accept(*this); dialect().append_to_result(" "); } void basic_dialect_linker::visit(const matador::detail::basic_condition &cond) { dialect().append_to_result(cond.evaluate(dialect())); -// cond.evaluate(dialect().compile_type()); } void basic_dialect_linker::visit(const matador::detail::basic_column_condition &cond) { - dialect().inc_bind_count(); dialect().append_to_result(cond.evaluate(dialect())); } void basic_dialect_linker::visit(const matador::detail::basic_in_condition &cond) { - dialect().inc_bind_count(cond.size()); dialect().append_to_result(cond.evaluate(dialect())); } diff --git a/src/sql/basic_query.cpp b/src/sql/basic_query.cpp index 4d93594be..309b745de 100644 --- a/src/sql/basic_query.cpp +++ b/src/sql/basic_query.cpp @@ -10,9 +10,9 @@ namespace matador { namespace detail { -basic_query::basic_query(const std::string &table_name) +basic_query::basic_query(std::string table_name) : state(QUERY_BEGIN) - , table_name_(table_name) + , table_name_(std::move(table_name)) , update_columns_(new columns(columns::WITHOUT_BRACKETS)) , query_value_column_processor_(update_columns_, rowvalues_) {} @@ -28,6 +28,7 @@ basic_query::basic_query(const connection &conn, const std::string &table_name) void basic_query::reset_query(t_query_command query_command) { sql_.reset(query_command); + sql_.table_name(""); state = QUERY_BEGIN; update_columns_->columns_.clear(); } diff --git a/src/sql/column.cpp b/src/sql/column.cpp index 76c4c8b3f..3e46f3ed5 100644 --- a/src/sql/column.cpp +++ b/src/sql/column.cpp @@ -122,4 +122,9 @@ column columns::count_all() columns columns::all_ = columns({column("*", true)}, WITHOUT_BRACKETS); column columns::count_all_ = column("COUNT(*)", true); +column operator "" _col(const char *name, size_t len) +{ + return column(std::string(name, len)); +} + } diff --git a/src/sql/condition.cpp b/src/sql/condition.cpp index deb46e349..b43cde6d4 100644 --- a/src/sql/condition.cpp +++ b/src/sql/condition.cpp @@ -5,13 +5,18 @@ namespace matador { namespace detail { std::array - basic_condition::operands = { {"=", "<>", "<", "<=", ">", ">=", "OR", "AND", "NOT"} }; + basic_condition::operands = { {"=", "<>", "<", "<=", ">", ">=", "OR", "AND", "NOT", "IN"} }; } -condition in(const matador::column &f, detail::basic_query &q) +condition equals(const column &col, detail::basic_query &q) { - return condition(f, q); + return condition(col, detail::basic_condition::EQUAL, q); +} + +condition in(const column &f, detail::basic_query &q) +{ + return condition(f, detail::basic_condition::IN_LIST, q); } } diff --git a/src/sql/connection.cpp b/src/sql/connection.cpp index cc25380b3..734c03843 100644 --- a/src/sql/connection.cpp +++ b/src/sql/connection.cpp @@ -111,9 +111,9 @@ std::string connection::version() const return ""; } -bool connection::exists(const std::string &tablename) const +bool connection::exists(const std::string &table_name) const { - return impl_->exists(tablename); + return impl_->exists(table_name); } std::vector connection::describe(const std::string &table) const @@ -142,7 +142,7 @@ void connection::prepare_prototype_row(row &prototype, const std::string &tablen for (auto &&f : fields) { if (!prototype.has_column(f.name())) { continue; - }; + } // generate value by type // f.type(); // std::shared_ptr value(new null_value); diff --git a/src/sql/dialect_token.cpp b/src/sql/dialect_token.cpp index 03dde7fc8..4e0cb580e 100644 --- a/src/sql/dialect_token.cpp +++ b/src/sql/dialect_token.cpp @@ -35,7 +35,7 @@ void drop::accept(token_visitor &visitor) } create::create(const std::string &t) - : token(CREATE_TABLE), table(t) + : table_name_token(CREATE_TABLE, t) {} void create::accept(token_visitor &visitor) @@ -43,8 +43,8 @@ void create::accept(token_visitor &visitor) visitor.visit(*this); } -insert::insert(const std::string &t) - : token(INSERT), table(t) +insert::insert(std::string t) + : table_name_token(INSERT, std::move(t)) {} void insert::accept(token_visitor &visitor) @@ -61,9 +61,8 @@ void update::accept(token_visitor &visitor) visitor.visit(*this); } -tablename::tablename(const std::string &t) - : token(TABLE) - , tab(t) +tablename::tablename(std::string t) + : table_name_token(TABLE, std::move(t)) {} void tablename::accept(token_visitor &visitor) @@ -101,7 +100,7 @@ void desc::accept(token_visitor &visitor) } from::from(const std::string &t) - : token(FROM), table(t) + : table_name_token(FROM, t) {} void from::accept(token_visitor &visitor) @@ -118,8 +117,8 @@ void top::accept(token_visitor &visitor) visitor.visit(*this); } -as::as(const std::string &a) - : token(AS), alias(a) +as::as(std::string a) + : token(AS), alias(std::move(a)) { } void as::accept(token_visitor &visitor) @@ -127,8 +126,8 @@ void as::accept(token_visitor &visitor) visitor.visit(*this); } -order_by::order_by(const std::string &col) - : token(ORDER_BY), column(col) +order_by::order_by(std::string col) + : token(ORDER_BY), column(std::move(col)) {} void order_by::accept(token_visitor &visitor) @@ -136,8 +135,8 @@ void order_by::accept(token_visitor &visitor) visitor.visit(*this); } -group_by::group_by(const std::string &col) - : token(GROUP_BY), column(col) +group_by::group_by(std::string col) + : token(GROUP_BY), column(std::move(col)) {} void group_by::accept(token_visitor &visitor) diff --git a/src/sql/row.cpp b/src/sql/row.cpp index ab2b904db..50c1eba3b 100644 --- a/src/sql/row.cpp +++ b/src/sql/row.cpp @@ -19,12 +19,6 @@ namespace matador { -row::row() -{} - -row::~row() -{} - bool row::add_column(const std::string &column) { return add_column(column, std::make_shared()); diff --git a/src/sql/sql.cpp b/src/sql/sql.cpp index 843e906d9..1f8e87322 100644 --- a/src/sql/sql.cpp +++ b/src/sql/sql.cpp @@ -31,7 +31,7 @@ sql::~sql() reset(t_query_command::UNKNOWN); } -void sql::append(const std::shared_ptr tokptr) +void sql::append(const std::shared_ptr &tokptr) { token_list_.push_back(tokptr); } @@ -53,40 +53,37 @@ void sql::reset(t_query_command command_type) token_list_.clear(); } -unsigned int sql::type_size(data_type type) +std::string sql::command() const { - switch(type) { - case data_type::type_char: - return sizeof(char); - case data_type::type_short: - return sizeof(short); - case data_type::type_int: - return sizeof(int); - case data_type::type_long: - return sizeof(long); - case data_type::type_unsigned_char: - return sizeof(unsigned char); - case data_type::type_unsigned_short: - return sizeof(unsigned short); - case data_type::type_unsigned_int: - return sizeof(unsigned int); - case data_type::type_unsigned_long: - return sizeof(unsigned long); - case data_type::type_bool: - return sizeof(bool); - case data_type::type_float: - return sizeof(float); - case data_type::type_double: - return sizeof(double); - case data_type::type_char_pointer: - case data_type::type_varchar: - case data_type::type_text: - return 64; + switch (command_type_) { + case t_query_command::CREATE: + return "create"; + case t_query_command::DROP: + return "drop"; + case t_query_command::INSERT: + return "insert"; + case t_query_command::UPDATE: + return "update"; + case t_query_command::REMOVE: + return "delete"; + case t_query_command::SELECT: + return "select"; + case t_query_command::UNKNOWN: default: - throw std::logic_error("unknown type"); + return "unknown"; } } +std::string sql::table_name() const +{ + return table_name_; +} + +void sql::table_name(const std::string &tname) +{ + table_name_ = tname; +} + namespace detail { query::query(const sql &s) : token(NONE), sql_(s) @@ -95,8 +92,6 @@ query::query(const sql &s) void query::accept(token_visitor &visitor) { visitor.visit(*this); -// std::string result("("); -// return result.append(sql_.compile(d)).append(")"); } } diff --git a/src/sql/token.cpp b/src/sql/token.cpp index a4dd0a729..bce6c0e6f 100644 --- a/src/sql/token.cpp +++ b/src/sql/token.cpp @@ -11,5 +11,10 @@ token::token(t_token tok) : type(tok) {} +table_name_token::table_name_token(token::t_token tok, std::string tablename) + : token(tok) + , table_name(tablename) +{} + } } \ No newline at end of file diff --git a/src/unit/CMakeLists.txt b/src/unit/CMakeLists.txt index acd06564a..c1abad695 100644 --- a/src/unit/CMakeLists.txt +++ b/src/unit/CMakeLists.txt @@ -14,8 +14,8 @@ ADD_LIBRARY(matador-unit SHARED ${SOURCES} ${HEADER}) # Set the build version (VERSION) and the API version (SOVERSION) SET_TARGET_PROPERTIES(matador-unit PROPERTIES - VERSION 0.5.0 - SOVERSION 0) + VERSION ${APP_VERSION} + SOVERSION ${APP_MAJOR_VERSION}) SOURCE_GROUP("include\\matador\\unit" FILES ${HEADER}) SOURCE_GROUP("src\\matador\\unit" FILES ${SOURCES}) diff --git a/src/unit/test_suite.cpp b/src/unit/test_suite.cpp index 9d69640a4..87715ac70 100644 --- a/src/unit/test_suite.cpp +++ b/src/unit/test_suite.cpp @@ -4,12 +4,10 @@ #include #include #include +#include namespace matador { -test_suite::test_suite() -{} - void test_suite::register_unit(unit_test *utest) { unit_test_map_.insert(std::make_pair(utest->name(), unit_test_ptr(utest))); @@ -135,7 +133,7 @@ bool test_suite::run() summary_.reset(); if (!args_.unit_args.empty()) { bool result = true; - for (auto item : args_.unit_args) { + for (auto const &item : args_.unit_args) { bool succeeded = run(item); if (result && !succeeded) { result = succeeded; @@ -189,7 +187,7 @@ bool test_suite::run(const test_unit_args &unit_args) if (unit_args.tests.empty()) { result = run(unit_args.unit); } else { - for (auto test : unit_args.tests) { + for (auto const &test : unit_args.tests) { bool succeeded = run(unit_args.unit, test); if (result && !succeeded) { result = succeeded; diff --git a/src/unit/unit_test.cpp b/src/unit/unit_test.cpp index be7ee566a..9bfb5835a 100644 --- a/src/unit/unit_test.cpp +++ b/src/unit/unit_test.cpp @@ -21,15 +21,16 @@ #include #include #include +#include +#include using namespace std::chrono; namespace matador { -unit_test::unit_test(const std::string &name, const std::string &caption) - : name_(name) - , caption_(caption) - , current_test_func_info(nullptr) +unit_test::unit_test(std::string name, std::string caption) + : name_(std::move(name)) + , caption_(std::move(caption)) {} unit_test::~unit_test() @@ -62,7 +63,7 @@ bool unit_test::execute(bool quiet) bool unit_test::execute(const std::string &test, bool quiet) { - t_test_func_info_vector::iterator i = std::find_if(test_func_infos_.begin(), test_func_infos_.end(), [test](const t_test_func_info_vector::value_type &x) { + auto i = std::find_if(test_func_infos_.begin(), test_func_infos_.end(), [test](const t_test_func_info_vector::value_type &x) { return x.name == test; }); @@ -89,41 +90,41 @@ void unit_test::add_test(const std::string &name, const test_func &test, const s test_func_infos_.push_back(test_func_info(test, name, caption)); } -void unit_test::assert_true(bool a, const std::string &msg, int line, const char *file) +void unit_test::assert_true(bool a, int line, const char *file) { ++current_test_func_info->assertion_count; if (!a) { - std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is false: " << msg; - throw unit_exception(msgstr.str()); + std::stringstream msgstr; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is false"; + throw unit_exception(msgstr.str()); } } -void unit_test::assert_false(bool a, const std::string &msg, int line, const char *file) +void unit_test::assert_false(bool a, int line, const char *file) { ++current_test_func_info->assertion_count; if (a) { - std::stringstream msgstr; - msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is true: " << msg; - throw unit_exception(msgstr.str()); + std::stringstream msgstr; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is true"; + throw unit_exception(msgstr.str()); } } -void unit_test::expect_true(bool a, const std::string &msg, int line, const char *file) +void unit_test::expect_true(bool a, int line, const char *file) { ++current_test_func_info->error_count; if (!a) { ++current_test_func_info->errors; - std::cout << "ERROR at " << file << ":" << line << ": value " << a << " is false: " << msg; + std::cout << "ERROR at " << file << ":" << line << ": value " << a << " is false"; } } -void unit_test::expect_false(bool a, const std::string &msg, int line, const char *file) +void unit_test::expect_false(bool a, int line, const char *file) { ++current_test_func_info->error_count; if (a) { ++current_test_func_info->errors; - std::cout << "ERROR at " << file << ":" << line << ": value " << a << " is false: " << msg; + std::cout << "ERROR at " << file << ":" << line << ": value " << a << " is false"; } } @@ -178,4 +179,81 @@ void unit_test::execute(test_func_info &test_info, bool quiet) } } +void unit_test::assert_equal(char *&a, const char *&b, int line, const char *file) { + ++current_test_func_info->assertion_count; + if (strcmp(a, b) != 0) { + std::stringstream msgstr; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; + throw unit_exception(msgstr.str()); + } +} + +void unit_test::assert_equal(const std::string &a, const char *b, int line, const char *file) { + ++current_test_func_info->assertion_count; + if (strcmp(a.c_str(), b) != 0) { + std::stringstream msgstr; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; + throw unit_exception(msgstr.str()); + } +} + +void unit_test::assert_equal(const char *a, const std::string &b, int line, const char *file) { + ++current_test_func_info->assertion_count; + if (strcmp(a, b.c_str()) != 0) { + std::stringstream msgstr; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; + throw unit_exception(msgstr.str()); + } +} + +void unit_test::assert_equal(const char *a, const char *b, int line, const char *file) { + ++current_test_func_info->assertion_count; + if (strcmp(a, b) != 0) { + std::stringstream msgstr; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; + throw unit_exception(msgstr.str()); + } +} + +void unit_test::assert_equal(const bool &a, const bool &b, int line, const char *file) { + ++current_test_func_info->assertion_count; + if (a != b) { + std::stringstream msgstr; + msgstr << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; + throw unit_exception(msgstr.str()); + } +} + +void unit_test::expect_equal(const double &a, const double &b, int line, const char *file) { + ++current_test_func_info->error_count; + if (std::abs(a - b) > 0.000001) { + ++current_test_func_info->errors; + std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; + } +} + +void unit_test::expect_equal(const char *a, const std::string &b, int line, const char *file) { + ++current_test_func_info->error_count; + if (strcmp(a, b.c_str()) != 0) { + ++current_test_func_info->errors; + std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; + } +} + +void unit_test::expect_equal(const std::string &a, const char *b, int line, const char *file) { + ++current_test_func_info->error_count; + if (strcmp(a.c_str(), b) != 0) { + ++current_test_func_info->errors; + std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; + } +} + +void unit_test::expect_equal(const char *a, const char *b, int line, const char *file) { + ++current_test_func_info->error_count; + if (strcmp(a, b) != 0) { + ++current_test_func_info->errors; + std::cout << "FAILURE at " << file << ":" << line << ": value " << a << " is not equal " << b; + } +} + } diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 58a37c6ef..20f0a2ba2 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -52,8 +52,8 @@ TARGET_LINK_LIBRARIES(matador-utils ${CMAKE_DL_LIBS}) # Set the build version (VERSION) and the API version (SOVERSION) SET_TARGET_PROPERTIES(matador-utils PROPERTIES - VERSION 0.5.0 - SOVERSION 0) + VERSION ${APP_VERSION} + SOVERSION ${APP_MAJOR_VERSION}) SOURCE_GROUP("include\\matador\\utils" FILES ${HEADER}) SOURCE_GROUP("src\\matador\\utils" FILES ${SOURCES}) diff --git a/src/utils/time.cpp b/src/utils/time.cpp index 3423e82d4..04e24de53 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -46,7 +46,7 @@ namespace detail { return 0; #else - return ::gettimeofday(tp, 0); + return ::gettimeofday(tp, nullptr); #endif } } @@ -174,7 +174,7 @@ time time::parse(const std::string &tstr, const char *format) char *next; usec = std::strtoul(endptr, &next, 10); // calculate precision - unsigned digits = (unsigned int) (next - endptr); + auto digits = (unsigned int) (next - endptr); usec *= (unsigned long)pow(10.0, 6 - digits); if ((size_t)(next - format) != strlen(format)) { // still time string to parse diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 52bd6d749..7de6a9e73 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,7 +61,8 @@ SET (TEST_SQL_SOURCES sql/SQLiteDialectTestUnit.hpp sql/ValueUnitTest.cpp sql/ValueUnitTest.hpp -) + sql/PostgreSQLDialectTestUnit.cpp + sql/PostgreSQLDialectTestUnit.hpp) SET (TEST_ORM_SOURCES orm/TransactionTestUnit.cpp @@ -96,27 +97,38 @@ ELSE() # SET(MSSQL_CONNECTION_STRING "mssql://sascha:sascha@192.168.178.31\\\\SQLEXPRESS/test_matador (FreeTDS)" CACHE STRING "mssql connection string") ENDIF() SET(SQLITE_CONNECTION_STRING "sqlite://test.sqlite" CACHE STRING "sqlite connection string") +SET(POSTGRESQL_CONNECTION_STRING "postgresql://test:test123@127.0.0.1/matador_test" CACHE STRING "postgresql connection string") + MESSAGE(STATUS "mysql connection string: ${MYSQL_CONNECTION_STRING}") MESSAGE(STATUS "mssql connection string: ${MSSQL_CONNECTION_STRING}") MESSAGE(STATUS "sqlite connection string: ${SQLITE_CONNECTION_STRING}") +MESSAGE(STATUS "postgresql connection string: ${POSTGRESQL_CONNECTION_STRING}") CONFIGURE_FILE(connections.hpp.in ${PROJECT_BINARY_DIR}/connections.hpp @ONLY IMMEDIATE) SET(DB_LIBRARIES) IF(ODBC_FOUND) + MESSAGE(STATUS "Appendig ODBC libs: ${ODBC_LIBRARY}") LIST(APPEND DB_LIBRARIES ${ODBC_LIBRARY}) ENDIF() IF(MYSQL_FOUND) + MESSAGE(STATUS "Appendig MySQL libs: ${MYSQL_LIBRARY}") LIST(APPEND DB_LIBRARIES ${MYSQL_LIBRARY}) ENDIF() IF(SQLITE3_FOUND) + MESSAGE(STATUS "Appendig SQLite3 libs: ${SQLITE3_LIBRARY}") LIST(APPEND DB_LIBRARIES ${SQLITE3_LIBRARY}) ENDIF() +IF(PostgreSQL_FOUND) + MESSAGE(STATUS "Appendig PostgreSQL libs: ${PostgreSQL_LIBRARIES}") + LIST(APPEND DB_LIBRARIES ${PostgreSQL_LIBRARIES}) +ENDIF() + TARGET_LINK_LIBRARIES(test_matador matador-unit matador-utils diff --git a/test/connections.hpp.in b/test/connections.hpp.in index 58294922f..53c175637 100644 --- a/test/connections.hpp.in +++ b/test/connections.hpp.in @@ -5,6 +5,7 @@ namespace connection { const char* const mysql = "@MYSQL_CONNECTION_STRING@"; const char* const sqlite = "@SQLITE_CONNECTION_STRING@"; const char* const mssql = "@MSSQL_CONNECTION_STRING@"; + const char* const postgresql = "@POSTGRESQL_CONNECTION_STRING@"; } #endif /* CONNECTIONS_HPP */ diff --git a/test/object/HasManyListUnitTest.cpp b/test/object/HasManyListUnitTest.cpp index 252c64c99..ec9107d05 100644 --- a/test/object/HasManyListUnitTest.cpp +++ b/test/object/HasManyListUnitTest.cpp @@ -33,25 +33,25 @@ void HasManyListUnitTest::test_join_table() store.attach("owner"); prototype_iterator i = store.find("owner_item"); - UNIT_ASSERT_TRUE(i != store.end(), "iterator shouldn't be end"); + UNIT_ASSERT_TRUE(i != store.end()); - UNIT_ASSERT_EQUAL("owner_item", i->type(), "type should be 'owner_item'"); + UNIT_ASSERT_EQUAL("owner_item", i->type()); object_ptr o = store.insert(new owner("hans")); - UNIT_ASSERT_EQUAL("hans", o->name, "name should be 'hans'"); + UNIT_ASSERT_EQUAL("hans", o->name); object_ptr i1 = store.insert(new item("i1")); - UNIT_ASSERT_EQUAL("i1", i1->name, "name should be 'i1'"); + UNIT_ASSERT_EQUAL("i1", i1->name); o->items.push_back(i1); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); o->items.push_back(new item("i2")); - UNIT_ASSERT_EQUAL(2U, o->items.size(), "size should be 2 (two)"); + UNIT_ASSERT_EQUAL(2U, o->items.size()); } void HasManyListUnitTest::test_const_iterator() @@ -66,25 +66,25 @@ void HasManyListUnitTest::test_const_iterator() many_ints::element_list_t::iterator i = mi.elements.end(); many_ints::element_list_t::const_iterator last = i; - UNIT_ASSERT_FALSE(first == last, "first and last must not be equal"); - UNIT_ASSERT_TRUE(first == mi.elements.begin(), "first must be equal begin()"); - UNIT_ASSERT_TRUE(last == mi.elements.end(), "last must be equal end()"); + UNIT_ASSERT_FALSE(first == last); + UNIT_ASSERT_TRUE(first == mi.elements.begin()); + UNIT_ASSERT_TRUE(last == mi.elements.end()); ++first; - UNIT_ASSERT_EQUAL(*first, 7, "value of first must be '7'"); + UNIT_ASSERT_EQUAL(*first, 7); first++; - UNIT_ASSERT_EQUAL(*first, 1, "value of first must be '1'"); + UNIT_ASSERT_EQUAL(*first, 1); first--; - UNIT_ASSERT_EQUAL(*first, 7, "value of first must be '7'"); + UNIT_ASSERT_EQUAL(*first, 7); --first; - UNIT_ASSERT_EQUAL(*first, 6, "value of first must be '6'"); + UNIT_ASSERT_EQUAL(*first, 6); } void HasManyListUnitTest::test_erase_scalar() @@ -97,19 +97,19 @@ void HasManyListUnitTest::test_erase_scalar() mptr->elements.push_back(1); - UNIT_ASSERT_EQUAL(1U, mptr->elements.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, mptr->elements.size()); mptr->elements.push_back(7); mptr->elements.push_back(90); - UNIT_ASSERT_EQUAL(3U, mptr->elements.size(), "size should be 3 (three)"); + UNIT_ASSERT_EQUAL(3U, mptr->elements.size()); many_ints::element_list_t::iterator i = mptr->elements.begin(); i = mptr->elements.erase(i); - UNIT_ASSERT_EQUAL(2U, mptr->elements.size(), "size should be 2 (two)"); - UNIT_ASSERT_EQUAL(*i, 7, "name must be '7'"); + UNIT_ASSERT_EQUAL(2U, mptr->elements.size()); + UNIT_ASSERT_EQUAL(*i, 7); mptr->elements.push_back(3); mptr->elements.push_back(4); @@ -122,8 +122,8 @@ void HasManyListUnitTest::test_erase_scalar() i = mptr->elements.erase(i, j); - UNIT_ASSERT_EQUAL(2U, mptr->elements.size(), "size should be 2 (two)"); - UNIT_ASSERT_EQUAL(*i, 3, "name must be '3'"); + UNIT_ASSERT_EQUAL(2U, mptr->elements.size()); + UNIT_ASSERT_EQUAL(*i, 3); } void HasManyListUnitTest::test_erase_object() @@ -136,22 +136,22 @@ void HasManyListUnitTest::test_erase_object() object_ptr o = store.insert(new owner("hans")); object_ptr i1 = store.insert(new item("i1")); - UNIT_ASSERT_EQUAL("i1", i1->name, "name should be 'i1'"); + UNIT_ASSERT_EQUAL("i1", i1->name); o->items.push_back(i1); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); o->items.push_back(new item("i2")); - UNIT_ASSERT_EQUAL(2U, o->items.size(), "size should be 2 (two)"); + UNIT_ASSERT_EQUAL(2U, o->items.size()); owner::item_list_t::iterator i = o->items.begin(); i = o->items.erase(i); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); - UNIT_ASSERT_EQUAL(i->name, "i2", "name must be 'i2"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); + UNIT_ASSERT_EQUAL(i->name, "i2"); o->items.push_back(new item("i3")); o->items.push_back(new item("i4")); @@ -164,8 +164,8 @@ void HasManyListUnitTest::test_erase_object() i = o->items.erase(i, j); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); - UNIT_ASSERT_EQUAL(i->name, "i4", "name must be 'i4'"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); + UNIT_ASSERT_EQUAL(i->name, "i4"); } void HasManyListUnitTest::test_remove_scalar() @@ -178,22 +178,22 @@ void HasManyListUnitTest::test_remove_scalar() mptr->elements.push_back(1); - UNIT_ASSERT_EQUAL(1U, mptr->elements.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, mptr->elements.size()); mptr->elements.push_back(7); mptr->elements.push_back(90); - UNIT_ASSERT_EQUAL(3U, mptr->elements.size(), "size should be 3 (three)"); + UNIT_ASSERT_EQUAL(3U, mptr->elements.size()); mptr->elements.remove(1); - UNIT_ASSERT_EQUAL(2U, mptr->elements.size(), "size should be 2 (two)"); + UNIT_ASSERT_EQUAL(2U, mptr->elements.size()); mptr->elements.remove_if([](const int &val) { return val == 90; }); - UNIT_ASSERT_EQUAL(1U, mptr->elements.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, mptr->elements.size()); } void HasManyListUnitTest::test_remove_object() @@ -207,26 +207,26 @@ void HasManyListUnitTest::test_remove_object() object_ptr i1 = store.insert(new item("i1")); object_ptr i2 = store.insert(new item("i2")); - UNIT_ASSERT_EQUAL("i1", i1->name, "name should be 'i1'"); + UNIT_ASSERT_EQUAL("i1", i1->name); o->items.push_back(i1); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); o->items.push_back(i2); - UNIT_ASSERT_EQUAL(2U, o->items.size(), "size should be 2 (two)"); + UNIT_ASSERT_EQUAL(2U, o->items.size()); o->items.remove(i2); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); o->items.remove_if([&i1](const object_ptr &x) { return i1 == x; }); - UNIT_ASSERT_EQUAL(0U, o->items.size(), "size should be 0 (zero)"); - UNIT_ASSERT_TRUE(o->items.empty(), "list should be empty"); + UNIT_ASSERT_EQUAL(0U, o->items.size()); + UNIT_ASSERT_TRUE(o->items.empty()); } void HasManyListUnitTest::test_integer() @@ -237,24 +237,24 @@ void HasManyListUnitTest::test_integer() object_ptr mi = store.insert(new many_ints); - UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL, "has many list is not empty"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL); for (int i = 0; i < 20; ++i) { mi->elements.push_back(i); } - UNIT_ASSERT_EQUAL(mi->elements.size(), 20UL, "has many list has invalid size"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 20UL); many_ints::element_list_t::iterator i = mi->elements.begin(); - UNIT_ASSERT_EQUAL(*i, 0, "item is invalid"); + UNIT_ASSERT_EQUAL(*i, 0); i++; - UNIT_ASSERT_EQUAL(*i, 1, "item is invalid"); + UNIT_ASSERT_EQUAL(*i, 1); // ival = 4; -// UNIT_ASSERT_EQUAL((int)(*i)->index(), ival, "item is invalid"); +// UNIT_ASSERT_EQUAL((int)(*i)->index(), ival); // // i = itemvector->erase(i); // @@ -262,8 +262,8 @@ void HasManyListUnitTest::test_integer() // //// std::for_each(itemvector->begin(), itemvector->end(), print); // -// UNIT_ASSERT_EQUAL((int)(*i)->index(), ival, "item is invalid"); -// UNIT_ASSERT_EQUAL((int)itemvector->size(), 19, "itemvector size isn't valid"); +// UNIT_ASSERT_EQUAL((int)(*i)->index(), ival); +// UNIT_ASSERT_EQUAL((int)itemvector->size(), 19); } void HasManyListUnitTest::test_string() @@ -274,22 +274,22 @@ void HasManyListUnitTest::test_string() object_ptr mi = store.insert(new many_strings); - UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL, "has many list is not empty"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL); std::vector names = { "george", "jane", "rudi", "hanna" }; for (const auto &name : names) { mi->elements.push_back(name); } - UNIT_ASSERT_EQUAL(mi->elements.size(), 4UL, "has many list has invalid size"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 4UL); many_strings::element_list_t::iterator i = mi->elements.begin(); - UNIT_ASSERT_EQUAL(*i, "george", "value is invalid"); + UNIT_ASSERT_EQUAL(*i, "george"); i++; - UNIT_ASSERT_EQUAL(*i, "jane", "value is invalid"); + UNIT_ASSERT_EQUAL(*i, "jane"); } using many_list_varchars = many_builtins, std::list>; @@ -302,20 +302,20 @@ void HasManyListUnitTest::test_varchar() object_ptr mi = store.insert(new many_list_varchars); - UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL, "has many list is not empty"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL); std::vector names = { "george", "jane", "rudi", "hanna" }; for (const auto &name : names) { mi->elements.push_back(name.c_str()); } - UNIT_ASSERT_EQUAL(mi->elements.size(), 4UL, "has many list has invalid size"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 4UL); auto i = mi->elements.begin(); - UNIT_ASSERT_EQUAL(*i, "george", "value is invalid"); + UNIT_ASSERT_EQUAL(*i, "george"); i++; - UNIT_ASSERT_EQUAL(*i, "jane", "value is invalid"); + UNIT_ASSERT_EQUAL(*i, "jane"); } diff --git a/test/object/HasManyVectorUnitTest.cpp b/test/object/HasManyVectorUnitTest.cpp index 8ebca33cc..7656934f8 100644 --- a/test/object/HasManyVectorUnitTest.cpp +++ b/test/object/HasManyVectorUnitTest.cpp @@ -29,25 +29,25 @@ void HasManyVectorUnitTest::test_join_table() store.attach("owner"); prototype_iterator i = store.find("owner_item"); - UNIT_ASSERT_TRUE(i != store.end(), "iterator shouldn't be end"); + UNIT_ASSERT_TRUE(i != store.end()); - UNIT_ASSERT_EQUAL("owner_item", i->type(), "type should be 'owner_item'"); + UNIT_ASSERT_EQUAL("owner_item", i->type()); object_ptr o = store.insert(new owner("hans")); - UNIT_ASSERT_EQUAL("hans", o->name, "name should be 'hans'"); + UNIT_ASSERT_EQUAL("hans", o->name); object_ptr i1 = store.insert(new item("i1")); - UNIT_ASSERT_EQUAL("i1", i1->name, "name should be 'i1'"); + UNIT_ASSERT_EQUAL("i1", i1->name); o->items.push_back(i1); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); o->items.push_back(new item("i2")); - UNIT_ASSERT_EQUAL(2U, o->items.size(), "size should be 2 (two)"); + UNIT_ASSERT_EQUAL(2U, o->items.size()); } void HasManyVectorUnitTest::test_const_iterator() @@ -62,25 +62,25 @@ void HasManyVectorUnitTest::test_const_iterator() many_vector_ints::element_list_t::iterator i = mi.elements.end(); many_vector_ints::element_list_t::const_iterator last = i; - UNIT_ASSERT_FALSE(first == last, "first and last must not be equal"); - UNIT_ASSERT_TRUE(first == mi.elements.begin(), "first must be equal begin()"); - UNIT_ASSERT_TRUE(last == mi.elements.end(), "last must be equal end()"); + UNIT_ASSERT_FALSE(first == last); + UNIT_ASSERT_TRUE(first == mi.elements.begin()); + UNIT_ASSERT_TRUE(last == mi.elements.end()); ++first; - UNIT_ASSERT_EQUAL(*first, 7, "value of first must be '7'"); + UNIT_ASSERT_EQUAL(*first, 7); first++; - UNIT_ASSERT_EQUAL(*first, 1, "value of first must be '1'"); + UNIT_ASSERT_EQUAL(*first, 1); first--; - UNIT_ASSERT_EQUAL(*first, 7, "value of first must be '7'"); + UNIT_ASSERT_EQUAL(*first, 7); --first; - UNIT_ASSERT_EQUAL(*first, 6, "value of first must be '6'"); + UNIT_ASSERT_EQUAL(*first, 6); } void HasManyVectorUnitTest::test_erase_scalar() @@ -93,19 +93,19 @@ void HasManyVectorUnitTest::test_erase_scalar() mptr->elements.push_back(1); - UNIT_ASSERT_EQUAL(1U, mptr->elements.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, mptr->elements.size()); mptr->elements.push_back(7); mptr->elements.push_back(90); - UNIT_ASSERT_EQUAL(3U, mptr->elements.size(), "size should be 3 (three)"); + UNIT_ASSERT_EQUAL(3U, mptr->elements.size()); many_vector_ints::element_list_t::iterator i = mptr->elements.begin(); i = mptr->elements.erase(i); - UNIT_ASSERT_EQUAL(2U, mptr->elements.size(), "size should be 2 (two)"); - UNIT_ASSERT_EQUAL(*i, 7, "name must be '7'"); + UNIT_ASSERT_EQUAL(2U, mptr->elements.size()); + UNIT_ASSERT_EQUAL(*i, 7); mptr->elements.push_back(3); mptr->elements.push_back(4); @@ -118,8 +118,8 @@ void HasManyVectorUnitTest::test_erase_scalar() i = mptr->elements.erase(i, j); - UNIT_ASSERT_EQUAL(2U, mptr->elements.size(), "size should be 2 (two)"); - UNIT_ASSERT_EQUAL(*i, 3, "name must be '3'"); + UNIT_ASSERT_EQUAL(2U, mptr->elements.size()); + UNIT_ASSERT_EQUAL(*i, 3); } void HasManyVectorUnitTest::test_erase_object() @@ -132,22 +132,22 @@ void HasManyVectorUnitTest::test_erase_object() object_ptr o = store.insert(new owner("hans")); object_ptr i1 = store.insert(new item("i1")); - UNIT_ASSERT_EQUAL("i1", i1->name, "name should be 'i1'"); + UNIT_ASSERT_EQUAL("i1", i1->name); o->items.push_back(i1); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); o->items.push_back(new item("i2")); - UNIT_ASSERT_EQUAL(2U, o->items.size(), "size should be 2 (two)"); + UNIT_ASSERT_EQUAL(2U, o->items.size()); owner::item_vector_t::iterator i = o->items.begin(); i = o->items.erase(i); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); - UNIT_ASSERT_EQUAL(i->name, "i2", "name must be 'i2"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); + UNIT_ASSERT_EQUAL(i->name, "i2"); o->items.push_back(new item("i3")); o->items.push_back(new item("i4")); @@ -156,8 +156,8 @@ void HasManyVectorUnitTest::test_erase_object() i = o->items.erase(i, i+2); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); - UNIT_ASSERT_EQUAL(i->name, "i4", "name must be 'i4'"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); + UNIT_ASSERT_EQUAL(i->name, "i4"); } void HasManyVectorUnitTest::test_remove_scalar() @@ -170,16 +170,16 @@ void HasManyVectorUnitTest::test_remove_scalar() mptr->elements.push_back(1); - UNIT_ASSERT_EQUAL(1U, mptr->elements.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, mptr->elements.size()); mptr->elements.push_back(7); mptr->elements.push_back(90); - UNIT_ASSERT_EQUAL(3U, mptr->elements.size(), "size should be 3 (three)"); + UNIT_ASSERT_EQUAL(3U, mptr->elements.size()); mptr->elements.remove(7); - UNIT_ASSERT_EQUAL(2U, mptr->elements.size(), "size should be 2 (two)"); + UNIT_ASSERT_EQUAL(2U, mptr->elements.size()); } void HasManyVectorUnitTest::test_remove_object() @@ -193,19 +193,19 @@ void HasManyVectorUnitTest::test_remove_object() object_ptr i1 = store.insert(new item("i1")); object_ptr i2 = store.insert(new item("i2")); - UNIT_ASSERT_EQUAL("i1", i1->name, "name should be 'i1'"); + UNIT_ASSERT_EQUAL("i1", i1->name); o->items.push_back(i1); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); o->items.push_back(i2); - UNIT_ASSERT_EQUAL(2U, o->items.size(), "size should be 2 (two)"); + UNIT_ASSERT_EQUAL(2U, o->items.size()); o->items.remove(i1); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); } void HasManyVectorUnitTest::test_remove_if() @@ -222,19 +222,19 @@ void HasManyVectorUnitTest::test_remove_if() object_ptr i4 = store.insert(new item("i4")); object_ptr i5 = store.insert(new item("i5")); - UNIT_ASSERT_EQUAL("i1", i1->name, "name should be 'i1'"); + UNIT_ASSERT_EQUAL("i1", i1->name); o->items.push_back(i1); - UNIT_ASSERT_EQUAL(1U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(1U, o->items.size()); o->items.push_back(i2); - UNIT_ASSERT_EQUAL(2U, o->items.size(), "size should be 2 (two)"); + UNIT_ASSERT_EQUAL(2U, o->items.size()); o->items.push_back(i3); - UNIT_ASSERT_EQUAL(3U, o->items.size(), "size should be 3 (three)"); + UNIT_ASSERT_EQUAL(3U, o->items.size()); o->items.push_back(i4); o->items.push_back(i5); @@ -243,7 +243,7 @@ void HasManyVectorUnitTest::test_remove_if() return i1 == val || i3 == val; }); - UNIT_ASSERT_EQUAL(3U, o->items.size(), "size should be 1 (one)"); + UNIT_ASSERT_EQUAL(3U, o->items.size()); } void HasManyVectorUnitTest::test_integer() @@ -254,21 +254,21 @@ void HasManyVectorUnitTest::test_integer() object_ptr mi = store.insert(new many_vector_ints); - UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL, "pointer vector is not empty"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL); for (int i = 0; i < 20; ++i) { mi->elements.push_back(i); } - UNIT_ASSERT_EQUAL(mi->elements.size(), 20UL, "pointer vector has invalid size"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 20UL); many_vector_ints::element_list_t::iterator i = mi->elements.begin(); - UNIT_ASSERT_EQUAL(*i, 0, "item is invalid"); + UNIT_ASSERT_EQUAL(*i, 0); i++; - UNIT_ASSERT_EQUAL(*i, 1, "item is invalid"); + UNIT_ASSERT_EQUAL(*i, 1); } void HasManyVectorUnitTest::test_string() @@ -279,20 +279,20 @@ void HasManyVectorUnitTest::test_string() object_ptr mi = store.insert(new many_vector_strings); - UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL, "has many list is not empty"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 0UL); std::vector names = { "george", "jane", "rudi", "hanna" }; for (const auto &name : names) { mi->elements.push_back(name); } - UNIT_ASSERT_EQUAL(mi->elements.size(), 4UL, "has many list has invalid size"); + UNIT_ASSERT_EQUAL(mi->elements.size(), 4UL); many_vector_strings::element_list_t::iterator i = mi->elements.begin(); - UNIT_ASSERT_EQUAL(*i, "george", "value is invalid"); + UNIT_ASSERT_EQUAL(*i, "george"); i++; - UNIT_ASSERT_EQUAL(*i, "jane", "value is invalid"); + UNIT_ASSERT_EQUAL(*i, "jane"); } diff --git a/test/object/ObjectPrototypeTestUnit.cpp b/test/object/ObjectPrototypeTestUnit.cpp index b79dea5ea..1a3514dc9 100644 --- a/test/object/ObjectPrototypeTestUnit.cpp +++ b/test/object/ObjectPrototypeTestUnit.cpp @@ -28,7 +28,7 @@ ObjectPrototypeTestUnit::empty_store() { object_store ostore; - UNIT_ASSERT_TRUE(ostore.empty(), "serializable store must be empty"); + UNIT_ASSERT_TRUE(ostore.empty()); } void @@ -39,7 +39,7 @@ ObjectPrototypeTestUnit::test_find() prototype_iterator i = ostore.find(); - UNIT_ASSERT_TRUE(i != ostore.end(), "couldn't find prototype"); + UNIT_ASSERT_TRUE(i != ostore.end()); } void @@ -49,17 +49,17 @@ ObjectPrototypeTestUnit::test_size() prototype_iterator i = ostore.begin(); - UNIT_ASSERT_TRUE(i->size() == 0, "prototype node must be empty"); + UNIT_ASSERT_TRUE(i->size() == 0); ostore.attach("item"); i = ostore.find(); - UNIT_ASSERT_TRUE(i->size() == 0, "prototype node must be empty"); + UNIT_ASSERT_TRUE(i->size() == 0); ostore.insert(new Item); - UNIT_ASSERT_TRUE(i->size() == 1, "prototype node must be one (1)"); + UNIT_ASSERT_TRUE(i->size() == 1); } void @@ -69,15 +69,15 @@ ObjectPrototypeTestUnit::test_is_parent_of() prototype_iterator root = ostore.begin(); - UNIT_ASSERT_TRUE(root->size() == 0, "prototype node must be empty"); + UNIT_ASSERT_TRUE(root->size() == 0); ostore.attach("item"); prototype_iterator i = ostore.find(); - UNIT_ASSERT_FALSE(root->is_child_of(i.get()), "root must not be child of node"); + UNIT_ASSERT_FALSE(root->is_child_of(i.get())); -// UNIT_ASSERT_TRUE(i->is_child_of(root.get()), "node must be child of root"); +// UNIT_ASSERT_TRUE(i->is_child_of(root.get())); } void @@ -91,7 +91,7 @@ ObjectPrototypeTestUnit::test_decrement() --i; - UNIT_ASSERT_TRUE(--i == ostore.begin(), "iterator must be begin"); + UNIT_ASSERT_TRUE(--i == ostore.begin()); } void @@ -103,13 +103,13 @@ ObjectPrototypeTestUnit::one_prototype() auto *o = ostore.create(); - UNIT_ASSERT_NOT_NULL(o, "couldn't create serializable of type "); + UNIT_ASSERT_NOT_NULL(o); delete o; ostore.detach("item"); - UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type", "create with invalid type"); + UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type"); } void @@ -123,19 +123,19 @@ ObjectPrototypeTestUnit::prototype_hierachy() auto *a = ostore.create(); - UNIT_ASSERT_NOT_NULL(a, "couldn't create serializable of type "); + UNIT_ASSERT_NOT_NULL(a); delete a; ostore.detach("ITEM_B"); - UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type", "create with invalid type"); + UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type"); ostore.detach("ITEM"); - UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type", "create with invalid type"); - UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type", "create with invalid type"); - UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type", "create with invalid type"); + UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type"); + UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type"); + UNIT_ASSERT_EXCEPTION(ostore.create(), object_exception, "unknown prototype type"); } void @@ -152,12 +152,12 @@ ObjectPrototypeTestUnit::prototype_traverse() int count(0); while (first != last) { - UNIT_ASSERT_LESS(count, 4, "prototype count isn't valid"); + UNIT_ASSERT_LESS(count, 4); ++first; ++count; } - UNIT_ASSERT_EQUAL(count, 4, "expected prototype size isn't 4"); + UNIT_ASSERT_EQUAL(count, 4); } void diff --git a/test/object/ObjectStoreTestUnit.cpp b/test/object/ObjectStoreTestUnit.cpp index 1229e20e9..eee69b02d 100644 --- a/test/object/ObjectStoreTestUnit.cpp +++ b/test/object/ObjectStoreTestUnit.cpp @@ -32,6 +32,7 @@ ObjectStoreTestUnit::ObjectStoreTestUnit() add_test("delete", std::bind(&ObjectStoreTestUnit::test_delete_object, this), "object deletion test"); add_test("hierarchy", std::bind(&ObjectStoreTestUnit::test_hierarchy, this), "object hierarchy test"); add_test("view", std::bind(&ObjectStoreTestUnit::test_view, this), "object view test"); +// add_test("clear_type", std::bind(&ObjectStoreTestUnit::test_clear_type, this), "object store clear type test"); add_test("clear", std::bind(&ObjectStoreTestUnit::test_clear, this), "object store clear test"); add_test("generic", std::bind(&ObjectStoreTestUnit::test_generic, this), "generic object access test"); add_test("structure", std::bind(&ObjectStoreTestUnit::test_structure, this), "object transient structure test"); @@ -60,7 +61,7 @@ struct test_pair; template < class T > struct test_pair::value >::type > : public basic_test_pair { - explicit test_pair(const T &exp) : expected(exp) {} + explicit test_pair(T exp) : expected(std::move(exp)) {} T expected; T result; }; @@ -98,11 +99,11 @@ void ObjectStoreTestUnit::test_version() { std::string version("0.5.1"); - UNIT_ASSERT_EQUAL(matador::version::str, version, "invalid matador version"); + UNIT_ASSERT_EQUAL(matador::version::str, version); - UNIT_ASSERT_EQUAL(matador::version::major, 0, "invalid major version"); - UNIT_ASSERT_EQUAL(matador::version::minor, 5, "invalid minor version"); - UNIT_ASSERT_EQUAL(matador::version::patch_level, 1, "invalid patch level"); + UNIT_ASSERT_EQUAL(matador::version::major, 0); + UNIT_ASSERT_EQUAL(matador::version::minor, 5); + UNIT_ASSERT_EQUAL(matador::version::patch_level, 1); } @@ -114,15 +115,15 @@ void ObjectStoreTestUnit::test_optr() item_ptr item_null; - UNIT_ASSERT_EXCEPTION(ostore_.insert(item_null), object_exception, "proxy is null", "shouldn't insert null object pointer"); + UNIT_ASSERT_EXCEPTION(ostore_.insert(item_null), object_exception, "proxy is null"); item_ptr item(new Item("Test")); - UNIT_ASSERT_NULL(item.store(), "item must not be internal"); + UNIT_ASSERT_NULL(item.store()); item = ostore_.insert(item); - UNIT_ASSERT_NOT_NULL(item.store(), "item must be internal"); + UNIT_ASSERT_NOT_NULL(item.store()); } void ObjectStoreTestUnit::test_expression() @@ -154,7 +155,7 @@ void ObjectStoreTestUnit::test_expression() int count(0); for_each_if(oview.begin(), oview.end(), x >= 3 && x <= 7 && x != 5, item_counter(count)); - UNIT_ASSERT_EQUAL(count, 4, "invalid number of objects found"); + UNIT_ASSERT_EQUAL(count, 4); variable z(make_var(&ObjectItem::get_int)); @@ -166,40 +167,40 @@ void ObjectStoreTestUnit::test_expression() #ifndef _MSC_VER ObjectItemList::iterator it = std::find_if(itemlist->begin(), itemlist->end(), z == 4); - UNIT_ASSERT_FALSE(it == itemlist->end(), "couldn't find item"); + UNIT_ASSERT_FALSE(it == itemlist->end()); #endif object_view >::iterator j = std::find_if(oview.begin(), oview.end(), 6 > x); - UNIT_ASSERT_EQUAL((*j)->get_int(), 1, "couldn't find item 1"); + UNIT_ASSERT_EQUAL((*j)->get_int(), 1); j = std::find_if(oview.begin(), oview.end(), x > 6); - UNIT_ASSERT_EQUAL((*j)->get_int(), 7, "couldn't find item 7"); + UNIT_ASSERT_EQUAL((*j)->get_int(), 7); j = std::find_if(oview.begin(), oview.end(), x < 6); - UNIT_ASSERT_EQUAL((*j)->get_int(), 1, "couldn't find item 1"); + UNIT_ASSERT_EQUAL((*j)->get_int(), 1); j = std::find_if(oview.begin(), oview.end(), x == 6); - UNIT_ASSERT_EQUAL((*j)->get_int(), 6, "couldn't find item 6"); + UNIT_ASSERT_EQUAL((*j)->get_int(), 6); j = std::find_if(oview.begin(), oview.end(), 6 == x); - UNIT_ASSERT_EQUAL((*j)->get_int(), 6, "couldn't find item 6"); + UNIT_ASSERT_EQUAL((*j)->get_int(), 6); j = std::find_if(oview.begin(), oview.end(), (6 == x) || (x < 4)); - UNIT_ASSERT_EQUAL((*j)->get_int(), 1, "couldn't find item 1"); + UNIT_ASSERT_EQUAL((*j)->get_int(), 1); j = std::find_if(oview.begin(), oview.end(), u == ii); - UNIT_ASSERT_EQUAL((*j)->ptr(), ii, "couldn't find item 10"); + UNIT_ASSERT_EQUAL((*j)->ptr(), ii); j = std::find_if(oview.begin(), oview.end(), y == std::string("ObjectItem")); - UNIT_ASSERT_EQUAL((*j)->get_string(), "ObjectItem", "couldn't find item 'ObjectItem'"); + UNIT_ASSERT_EQUAL((*j)->get_string(), "ObjectItem"); // try to find unknown object j = std::find_if(oview.begin(), oview.end(), y == std::string("Simple")); - UNIT_ASSERT_TRUE(j == oview.end(), "iterator must be end"); + UNIT_ASSERT_TRUE(j == oview.end()); j = std::find_if(oview.begin(), oview.end(), (x > 6) && (y == std::string("ObjectItem"))); - UNIT_ASSERT_EQUAL((*j)->get_int(), 7, "couldn't find item 7"); - UNIT_ASSERT_EQUAL((*j)->get_string(), "ObjectItem", "couldn't find item 'ObjectItem'"); + UNIT_ASSERT_EQUAL((*j)->get_int(), 7); + UNIT_ASSERT_EQUAL((*j)->get_string(), "ObjectItem"); } void ObjectStoreTestUnit::test_serializer() @@ -247,20 +248,20 @@ void ObjectStoreTestUnit::test_serializer() serializer.deserialize(item, &buffer, &ostore_); - UNIT_ASSERT_EQUAL(c, item->get_char(), "restored character is not equal to the original character"); - UNIT_ASSERT_EQUAL(f, item->get_float(), "restored float is not equal to the original float"); - UNIT_ASSERT_EQUAL(d, item->get_double(), "restored double is not equal to the original double"); - UNIT_ASSERT_EQUAL(s, item->get_short(), "restored short is not equal to the original short"); - UNIT_ASSERT_EQUAL(i, item->get_int(), "restored int is not equal to the original int"); - UNIT_ASSERT_EQUAL(l, item->get_long(), "restored long is not equal to the original long"); - UNIT_ASSERT_EQUAL(us, item->get_unsigned_short(), "restored unsigned short is not equal to the original unsigned"); - UNIT_ASSERT_EQUAL(ui, item->get_unsigned_int(), "restored unsigned int is not equal to the original unsigned"); - UNIT_ASSERT_EQUAL(ul, item->get_unsigned_long(), "restored unsigned long is not equal to the original unsigned"); - UNIT_ASSERT_EQUAL(b, item->get_bool(), "restored bool is not equal to the original bool"); - UNIT_ASSERT_EQUAL(title, item->get_string(), "restored string is not equal to the original string"); - UNIT_ASSERT_EQUAL(str, item->get_varchar(), "restored varchar is not equal to the original varchar"); - UNIT_ASSERT_EQUAL(dt, item->get_date(), "restored date is not equal to the original date"); - UNIT_ASSERT_EQUAL(t, item->get_time(), "restored time is not equal to the original time"); + UNIT_ASSERT_EQUAL(c, item->get_char()); + UNIT_ASSERT_EQUAL(f, item->get_float()); + UNIT_ASSERT_EQUAL(d, item->get_double()); + UNIT_ASSERT_EQUAL(s, item->get_short()); + UNIT_ASSERT_EQUAL(i, item->get_int()); + UNIT_ASSERT_EQUAL(l, item->get_long()); + UNIT_ASSERT_EQUAL(us, item->get_unsigned_short()); + UNIT_ASSERT_EQUAL(ui, item->get_unsigned_int()); + UNIT_ASSERT_EQUAL(ul, item->get_unsigned_long()); + UNIT_ASSERT_EQUAL(b, item->get_bool()); + UNIT_ASSERT_EQUAL(title, item->get_string()); + UNIT_ASSERT_EQUAL(str, item->get_varchar()); + UNIT_ASSERT_EQUAL(dt, item->get_date()); + UNIT_ASSERT_EQUAL(t, item->get_time()); delete item; } @@ -274,7 +275,7 @@ void ObjectStoreTestUnit::test_identifier_serializer() typedef identifier t_ul_id; std::unique_ptr id(new t_ul_id(8UL)); - UNIT_ASSERT_EQUAL(id->value(), 8UL, "identifier value must be 8"); + UNIT_ASSERT_EQUAL(id->value(), 8UL); serializer.serialize(*id, buffer); @@ -282,16 +283,16 @@ void ObjectStoreTestUnit::test_identifier_serializer() serializer.deserialize(*id2, buffer); - UNIT_ASSERT_EQUAL(id2->value(), 8UL, "identifier value must be 8"); + UNIT_ASSERT_EQUAL(id2->value(), 8UL); - UNIT_ASSERT_EXCEPTION(serializer.deserialize(*id2, buffer), std::logic_error, "invalid identifier type", "deserialize excpetion must be thrown"); + UNIT_ASSERT_EXCEPTION(serializer.deserialize(*id2, buffer), std::logic_error, "invalid identifier type"); } { typedef identifier t_str_id; std::unique_ptr id(new identifier("hallo")); - UNIT_ASSERT_EQUAL(id->value(), "hallo", "identifier value must be 'hallo'"); + UNIT_ASSERT_EQUAL(id->value(), "hallo"); serializer.serialize(*id, buffer); @@ -299,9 +300,9 @@ void ObjectStoreTestUnit::test_identifier_serializer() serializer.deserialize(*id2, buffer); - UNIT_ASSERT_EQUAL(id2->value(), "hallo", "identifier value must be 'hallo'"); + UNIT_ASSERT_EQUAL(id2->value(), "hallo"); - UNIT_ASSERT_EXCEPTION(serializer.deserialize(*id2, buffer), std::logic_error, "invalid identifier type", "deserialize excpetion must be thrown"); + UNIT_ASSERT_EXCEPTION(serializer.deserialize(*id2, buffer), std::logic_error, "invalid identifier type"); } } @@ -317,26 +318,26 @@ void ObjectStoreTestUnit::test_reference_counter() item_ptr item = ostore_.insert(i); - UNIT_ASSERT_EQUAL(item.reference_count(), 0UL, "reference count must be zero"); + UNIT_ASSERT_EQUAL(item.reference_count(), 0UL); object_item_ptr object_item_1 = ostore_.insert(new ObjectItem()); object_item_ptr object_item_2 = ostore_.insert(new ObjectItem()); object_item_1->ptr(item); - UNIT_ASSERT_EQUAL(item.reference_count(), 1UL, "reference count must be one"); + UNIT_ASSERT_EQUAL(item.reference_count(), 1UL); auto a1 = item; auto a2 = item; - UNIT_ASSERT_EQUAL(item.reference_count(), 1UL, "reference count must be one"); - UNIT_ASSERT_EQUAL(a1.reference_count(), 1UL, "reference count must be one"); - UNIT_ASSERT_EQUAL(a2.reference_count(), 1UL, "reference count must be one"); + UNIT_ASSERT_EQUAL(item.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(a1.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(a2.reference_count(), 1UL); object_item_1->ref(a1); - UNIT_ASSERT_EQUAL(item.reference_count(), 2UL, "reference count must be two"); - UNIT_ASSERT_EQUAL(a1.reference_count(), 2UL, "reference count must be two"); - UNIT_ASSERT_EQUAL(a2.reference_count(), 2UL, "reference count must be two"); + UNIT_ASSERT_EQUAL(item.reference_count(), 2UL); + UNIT_ASSERT_EQUAL(a1.reference_count(), 2UL); + UNIT_ASSERT_EQUAL(a2.reference_count(), 2UL); } @@ -365,29 +366,29 @@ void ObjectStoreTestUnit::test_set() matador::set(i, "val_date", dt); matador::set(i, "val_time", t); - UNIT_ASSERT_EQUAL('f', i.get_char(), "invalid value"); - UNIT_ASSERT_EQUAL(-2, i.get_short(), "invalid value"); - UNIT_ASSERT_EQUAL(-1, i.get_int(), "invalid value"); - UNIT_ASSERT_EQUAL(-7L, i.get_long(), "invalid value"); - UNIT_ASSERT_EQUAL(2, i.get_unsigned_short(), "invalid value"); - UNIT_ASSERT_EQUAL(1U, i.get_unsigned_int(), "invalid value"); - UNIT_ASSERT_EQUAL(7UL, i.get_unsigned_long(), "invalid value"); - UNIT_ASSERT_EQUAL(7UL, i.get_unsigned_long(), "invalid value"); - UNIT_ASSERT_EQUAL(false, i.get_bool(), "invalid value"); - UNIT_ASSERT_EQUAL(0.456f, i.get_float(), "invalid value"); - UNIT_ASSERT_EQUAL(3.1415, i.get_double(), "invalid value"); - UNIT_ASSERT_EQUAL("tiger", i.get_string(), "invalid value"); - UNIT_ASSERT_EQUAL(str, i.get_string(), "invalid value"); - UNIT_ASSERT_EQUAL(varstr, i.get_varchar(), "invalid value"); - UNIT_ASSERT_EQUAL(dt, i.get_date(), "invalid value"); - UNIT_ASSERT_EQUAL(t, i.get_time(), "invalid value"); + UNIT_ASSERT_EQUAL('f', i.get_char()); + UNIT_ASSERT_EQUAL(-2, i.get_short()); + UNIT_ASSERT_EQUAL(-1, i.get_int()); + UNIT_ASSERT_EQUAL(-7L, i.get_long()); + UNIT_ASSERT_EQUAL(2, i.get_unsigned_short()); + UNIT_ASSERT_EQUAL(1U, i.get_unsigned_int()); + UNIT_ASSERT_EQUAL(7UL, i.get_unsigned_long()); + UNIT_ASSERT_EQUAL(7UL, i.get_unsigned_long()); + UNIT_ASSERT_EQUAL(false, i.get_bool()); + UNIT_ASSERT_EQUAL(0.456f, i.get_float()); + UNIT_ASSERT_EQUAL(3.1415, i.get_double()); + UNIT_ASSERT_EQUAL("tiger", i.get_string()); + UNIT_ASSERT_EQUAL(str, i.get_string()); + UNIT_ASSERT_EQUAL(varstr, i.get_varchar()); + UNIT_ASSERT_EQUAL(dt, i.get_date()); + UNIT_ASSERT_EQUAL(t, i.get_time()); matador::set(i, "val_string", "lion"); - UNIT_ASSERT_EQUAL("lion", i.get_string(), "invalid value"); + UNIT_ASSERT_EQUAL("lion", i.get_string()); // auto vc = matador::varchar<16>("elefant"); // matador::set(i, "val_string", vc); -// UNIT_ASSERT_EQUAL("elefant", i.get_string(), "invalid value"); +// UNIT_ASSERT_EQUAL("elefant", i.get_string()); } void ObjectStoreTestUnit::test_get() @@ -427,35 +428,35 @@ void ObjectStoreTestUnit::test_get() item.set_time(timeval.expected); matador::get(item, "val_char", c.result); - UNIT_ASSERT_EQUAL(c.result, c.expected, "invalid value"); + UNIT_ASSERT_EQUAL(c.result, c.expected); matador::get(item, "val_short", s.result); - UNIT_ASSERT_EQUAL(s.result, s.expected, "invalid value"); + UNIT_ASSERT_EQUAL(s.result, s.expected); matador::get(item, "val_int", i.result); - UNIT_ASSERT_EQUAL(i.result, i.expected, "invalid value"); + UNIT_ASSERT_EQUAL(i.result, i.expected); matador::get(item, "val_long", l.result); - UNIT_ASSERT_EQUAL(l.result, l.expected, "invalid value"); + UNIT_ASSERT_EQUAL(l.result, l.expected); matador::get(item, "val_unsigned_short", us.result); - UNIT_ASSERT_EQUAL(us.result, us.expected, "invalid value"); + UNIT_ASSERT_EQUAL(us.result, us.expected); matador::get(item, "val_unsigned_int", ui.result); - UNIT_ASSERT_EQUAL(ui.result, ui.expected, "invalid value"); + UNIT_ASSERT_EQUAL(ui.result, ui.expected); matador::get(item, "val_unsigned_long", ul.result); - UNIT_ASSERT_EQUAL(ul.result, ul.expected, "invalid value"); + UNIT_ASSERT_EQUAL(ul.result, ul.expected); matador::get(item, "val_float", f.result); - UNIT_ASSERT_EQUAL(f.result, f.expected, "invalid value"); + UNIT_ASSERT_EQUAL(f.result, f.expected); matador::get(item, "val_double", d.result); - UNIT_ASSERT_EQUAL(d.result, d.expected, "invalid value"); + UNIT_ASSERT_EQUAL(d.result, d.expected); matador::get(item, "val_bool", b.result); - UNIT_ASSERT_EQUAL(b.result, b.expected, "invalid value"); + UNIT_ASSERT_EQUAL(b.result, b.expected); matador::get(item, "val_string", str.result); - UNIT_ASSERT_EQUAL(str.result, str.expected, "invalid value"); + UNIT_ASSERT_EQUAL(str.result, str.expected); matador::get(item, "val_varchar", varstr.result); - UNIT_ASSERT_EQUAL(varstr.result, varstr.expected, "invalid value"); + UNIT_ASSERT_EQUAL(varstr.result, varstr.expected); matador::get(item, "val_cstr", cstr.result, cstr.size); - UNIT_ASSERT_EQUAL(cstr.result, cstr.expected, "invalid value"); + UNIT_ASSERT_EQUAL(cstr.result, cstr.expected); matador::get(item, "val_date", dateval.result); - UNIT_ASSERT_EQUAL(dateval.result, dateval.expected, "invalid value"); + UNIT_ASSERT_EQUAL(dateval.result, dateval.expected); matador::get(item, "val_time", timeval.result); - UNIT_ASSERT_EQUAL(timeval.result, timeval.expected, "invalid value"); + UNIT_ASSERT_EQUAL(timeval.result, timeval.expected); } void ObjectStoreTestUnit::test_simple_object() @@ -464,15 +465,15 @@ void ObjectStoreTestUnit::test_simple_object() auto *a = ostore_.create(); - UNIT_ASSERT_NOT_NULL(a, "couldn't create object of type "); + UNIT_ASSERT_NOT_NULL(a); typedef object_ptr item_ptr; item_ptr simple = ostore_.insert(a); - UNIT_ASSERT_NOT_NULL(simple.get(), "item object insertion failed"); + UNIT_ASSERT_NOT_NULL(simple.get()); - UNIT_ASSERT_TRUE(ostore_.is_removable(simple), "deletion of item object failed"); + UNIT_ASSERT_TRUE(ostore_.is_removable(simple)); ostore_.remove(simple); } @@ -484,20 +485,20 @@ void ObjectStoreTestUnit::test_object_with_sub_object() auto *s = ostore_.create>(); - UNIT_ASSERT_NOT_NULL(s, "couldn't create object of type "); + UNIT_ASSERT_NOT_NULL(s); typedef object_ptr > obj_item_ptr; obj_item_ptr ows = ostore_.insert(s); - UNIT_ASSERT_NOT_NULL(ows.get(), "object item object insertion failed"); + UNIT_ASSERT_NOT_NULL(ows.get()); // check if sub object exists object_ptr simple = ows->ptr(); - UNIT_ASSERT_NULL(simple.get(), "item must be nullptr"); + UNIT_ASSERT_NULL(simple.get()); - UNIT_ASSERT_TRUE(ostore_.is_removable(ows), "deletion of object item failed"); + UNIT_ASSERT_TRUE(ostore_.is_removable(ows)); ostore_.remove(ows); } @@ -513,7 +514,7 @@ void ObjectStoreTestUnit::test_multiple_simple_objects() for (size_t i = 0; i < elem_size; ++i) { auto *a = ostore_.create(); - UNIT_ASSERT_NOT_NULL(a, "couldn't create object of type "); + UNIT_ASSERT_NOT_NULL(a); item_ptr simple = ostore_.insert(a); } @@ -521,7 +522,7 @@ void ObjectStoreTestUnit::test_multiple_simple_objects() typedef object_view simple_view_t; simple_view_t simple_view(ostore_); - UNIT_ASSERT_EQUAL(elem_size, simple_view.size(), "expected size of view isn't 10"); + UNIT_ASSERT_EQUAL(elem_size, simple_view.size()); } void ObjectStoreTestUnit::test_multiple_object_with_sub_objects() @@ -536,7 +537,7 @@ void ObjectStoreTestUnit::test_multiple_object_with_sub_objects() for (size_t i = 0; i < elem_size; ++i) { auto *s = ostore_.create>(); - UNIT_ASSERT_NOT_NULL(s, "couldn't create object of type "); + UNIT_ASSERT_NOT_NULL(s); ows_ptr ows = ostore_.insert(s); } @@ -544,7 +545,7 @@ void ObjectStoreTestUnit::test_multiple_object_with_sub_objects() typedef object_view > withsub_view_t; withsub_view_t withsub_view(ostore_); - UNIT_ASSERT_EQUAL(elem_size, withsub_view.size(), "expected size of view isn't 10"); + UNIT_ASSERT_EQUAL(elem_size, withsub_view.size()); } void ObjectStoreTestUnit::test_delete_object() @@ -564,23 +565,23 @@ void ObjectStoreTestUnit::test_delete_object() test_item_ptr testitem = ostore_.insert(ti); - UNIT_ASSERT_EQUAL(item.reference_count(), 1UL, "reference count for item should be 1 (one)"); - UNIT_ASSERT_EQUAL(testitem.reference_count(), 0UL, "reference count for test item should be 0 (zero)"); + UNIT_ASSERT_EQUAL(item.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(testitem.reference_count(), 0UL); typedef object_view item_view_t; item_view_t item_view(ostore_); - UNIT_ASSERT_FALSE(ostore_.is_removable(item), "item shouldn't be removable because ref count is one"); + UNIT_ASSERT_FALSE(ostore_.is_removable(item)); // std::cout << "remove item from store (false)\n"; - UNIT_ASSERT_EXCEPTION(ostore_.remove(item), object_exception, "object is not removable", "item shouldn't be removed"); + UNIT_ASSERT_EXCEPTION(ostore_.remove(item), object_exception, "object is not removable"); - UNIT_ASSERT_TRUE(ostore_.is_removable(testitem), "test object item must be removable"); + UNIT_ASSERT_TRUE(ostore_.is_removable(testitem)); // std::cout << "remove testitem from store\n"; ostore_.remove(testitem); - UNIT_ASSERT_TRUE(ostore_.is_removable(item), "item must be removable"); + UNIT_ASSERT_TRUE(ostore_.is_removable(item)); // std::cout << "remove item from store (true)\n"; ostore_.remove(item); @@ -629,14 +630,14 @@ void ObjectStoreTestUnit::test_hierarchy() ************************************/ size_t max = 20; - UNIT_ASSERT_EQUAL(item_view.size(), max, "expected item view size isn't 20"); + UNIT_ASSERT_EQUAL(item_view.size(), max); item_view_t::const_iterator first = item_view.begin(); item_view_t::const_iterator last = item_view.end(); int count = 0; while (first != last) { - UNIT_ASSERT_LESS(count, 20, "item view count isn't valid"); + UNIT_ASSERT_LESS(count, 20); ++first; ++count; } @@ -650,14 +651,14 @@ void ObjectStoreTestUnit::test_hierarchy() ************************************/ max = 5; - UNIT_ASSERT_EQUAL(item_view.size(), max, "expected item view size isn't 5"); + UNIT_ASSERT_EQUAL(item_view.size(), max); first = item_view.begin(); last = item_view.end(); count = 0; while (first != last) { - UNIT_ASSERT_LESS(count, 5, "item view count isn't valid"); + UNIT_ASSERT_LESS(count, 5); ++first; ++count; } @@ -669,14 +670,14 @@ void ObjectStoreTestUnit::test_hierarchy() item_a_view_t item_a_view(ostore_); - UNIT_ASSERT_EQUAL(item_a_view.size(), max, "expected item_a view size isn't 15"); + UNIT_ASSERT_EQUAL(item_a_view.size(), max); item_a_view_t::const_iterator afirst = item_a_view.begin(); item_a_view_t::const_iterator alast = item_a_view.end(); count = 0; while (afirst != alast) { - UNIT_ASSERT_LESS(count, 5, "item_a view count isn't valid"); + UNIT_ASSERT_LESS(count, 5); ++afirst; ++count; } @@ -697,18 +698,55 @@ void ObjectStoreTestUnit::test_view() item_view_t iview(ostore_); - UNIT_ASSERT_EQUAL((int)iview.size(), 10, "invalid item view size"); - UNIT_ASSERT_FALSE(iview.empty(), "item view is not empty"); + UNIT_ASSERT_EQUAL((int)iview.size(), 10); + UNIT_ASSERT_FALSE(iview.empty()); item_ptr item = iview.front(); - UNIT_ASSERT_GREATER(item->id(), 0UL, "invalid item"); + UNIT_ASSERT_GREATER(item->id(), 0UL); item = iview.back(); - UNIT_ASSERT_GREATER(item->id(), 0UL, "invalid item"); + UNIT_ASSERT_GREATER(item->id(), 0UL); } +//void ObjectStoreTestUnit::test_clear_type() +//{ +// ostore_.attach("item"); +// +// for (int i = 0; i < 10; ++i) { +// std::stringstream str; +// str << "Item " << i+1; +// ostore_.insert(new Item(str.str(), i+1)); +// } +// +// typedef object_view item_view_t; +// +// item_view_t iview(ostore_); +// +// UNIT_ASSERT_EQUAL((int)iview.size(), 10); +// UNIT_ASSERT_FALSE(iview.empty()); +// UNIT_ASSERT_FALSE(ostore_.empty()); +// +// ostore_.clear("item"); +// +// UNIT_ASSERT_TRUE(ostore_.empty()); +// UNIT_ASSERT_EQUAL(iview.size(), 0UL); +// UNIT_ASSERT_TRUE(iview.empty()); +// +// prototype_iterator first = ostore_.begin(); +// prototype_iterator last = ostore_.end(); +// +// UNIT_ASSERT_FALSE(first == last); +// +// ostore_.clear(true); +// +// first = ostore_.begin(); +// last = ostore_.end(); +// +// UNIT_ASSERT_TRUE(first == last); +//} + void ObjectStoreTestUnit::test_clear() { ostore_.attach("item"); @@ -723,27 +761,27 @@ void ObjectStoreTestUnit::test_clear() item_view_t iview(ostore_); - UNIT_ASSERT_EQUAL((int)iview.size(), 10, "invalid item view size"); - UNIT_ASSERT_FALSE(iview.empty(), "item view shouldn't be empty"); - UNIT_ASSERT_FALSE(ostore_.empty(), "object store shouldn't be empty"); + UNIT_ASSERT_EQUAL((int)iview.size(), 10); + UNIT_ASSERT_FALSE(iview.empty()); + UNIT_ASSERT_FALSE(ostore_.empty()); ostore_.clear(); - UNIT_ASSERT_TRUE(ostore_.empty(), "object store must be empty"); - UNIT_ASSERT_EQUAL((int)iview.size(), 0, "invalid item view size"); - UNIT_ASSERT_TRUE(iview.empty(), "item view must be empty"); + UNIT_ASSERT_TRUE(ostore_.empty()); + UNIT_ASSERT_EQUAL(iview.size(), 0UL); + UNIT_ASSERT_TRUE(iview.empty()); prototype_iterator first = ostore_.begin(); prototype_iterator last = ostore_.end(); - UNIT_ASSERT_FALSE(first == last, "prototype iterator shouldn't be the same"); + UNIT_ASSERT_FALSE(first == last); ostore_.clear(true); first = ostore_.begin(); last = ostore_.end(); - UNIT_ASSERT_TRUE(first == last, "prototype iterator must be the same"); + UNIT_ASSERT_TRUE(first == last); } void ObjectStoreTestUnit::test_generic() @@ -768,78 +806,78 @@ void ObjectStoreTestUnit::test_generic() matador::set(*item, "val_char", c.expected); matador::get(*item, "val_char", c.result); - UNIT_ASSERT_EQUAL(c.result, c.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(c.result, c.expected); matador::set(*item, "val_short", s.expected); matador::get(*item, "val_short", s.result); - UNIT_ASSERT_EQUAL(s.result, s.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(s.result, s.expected); matador::get(*item, "val_short", s.str_result); - UNIT_ASSERT_EQUAL(s.str_result, "-42", "short string is invalid"); + UNIT_ASSERT_EQUAL(s.str_result, "-42"); matador::set(*item, "val_int", i.expected); matador::get(*item, "val_int", i.result); - UNIT_ASSERT_EQUAL(i.result, i.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(i.result, i.expected); matador::set(*item, "val_long", l.expected); matador::get(*item, "val_long", l.result); - UNIT_ASSERT_EQUAL(l.result, l.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(l.result, l.expected); matador::set(*item, "val_unsigned_short", us.expected); matador::get(*item, "val_unsigned_short", us.result); - UNIT_ASSERT_EQUAL(us.result, us.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(us.result, us.expected); matador::set(*item, "val_unsigned_int", ui.expected); matador::get(*item, "val_unsigned_int", ui.result); - UNIT_ASSERT_EQUAL(ui.result, ui.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(ui.result, ui.expected); matador::set(*item, "val_unsigned_long", ul.expected); matador::get(*item, "val_unsigned_long", ul.result); - UNIT_ASSERT_EQUAL(ul.result, ul.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(ul.result, ul.expected); matador::set(*item, "val_bool", b.expected); matador::get(*item, "val_bool", b.result); - UNIT_ASSERT_EQUAL(b.result, b.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(b.result, b.expected); matador::set(*item, "val_cstr", cstr.expected); matador::get(*item, "val_cstr", cstr.result, cstr.size); - UNIT_ASSERT_EQUAL(cstr.result, cstr.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(cstr.result, cstr.expected); matador::set(*item, "val_string", str.expected); matador::get(*item, "val_string", str.result); - UNIT_ASSERT_EQUAL(str.result, str.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(str.result, str.expected); matador::set(*item, "val_varchar", varstr.expected); matador::get(*item, "val_varchar", varstr.result); - UNIT_ASSERT_EQUAL(varstr.result, varstr.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(varstr.result, varstr.expected); matador::set(*item, "val_float", f.expected); matador::get(*item, "val_float", f.result); - UNIT_ASSERT_EQUAL(f.result, f.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(f.result, f.expected); /* get float value into string * with precision 2 */ matador::get(*item, "val_float", f.str_result, 2); - UNIT_ASSERT_EQUAL(f.str_result, "1.55", "float string is invalid"); + UNIT_ASSERT_EQUAL(f.str_result, "1.55"); matador::set(*item, "val_double", d.expected); matador::get(*item, "val_double", d.result); - UNIT_ASSERT_EQUAL(d.result, d.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(d.result, d.expected); /* get double value into string * with precision 3 */ matador::get(*item, "val_double", d.str_result, 3); - UNIT_ASSERT_EQUAL(d.str_result, "123.558", "double string is invalid"); + UNIT_ASSERT_EQUAL(d.str_result, "123.558"); matador::get(*item, "val_int", str.result); - UNIT_ASSERT_EQUAL(str.result, "-98765", "float string is invalid"); + UNIT_ASSERT_EQUAL(str.result, "-98765"); matador::set(*item, "val_date", dateval.expected); matador::get(*item, "val_date", dateval.result); - UNIT_ASSERT_EQUAL(dateval.result, dateval.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(dateval.result, dateval.expected); matador::set(*item, "val_time", timeval.expected); matador::get(*item, "val_time", timeval.result); - UNIT_ASSERT_EQUAL(timeval.result, timeval.expected, "not expected result value"); + UNIT_ASSERT_EQUAL(timeval.result, timeval.expected); master m1("master 1"); @@ -848,27 +886,27 @@ void ObjectStoreTestUnit::test_generic() matador::set(m1, "child", c1); matador::get(m1, "child", child_result); - UNIT_ASSERT_EQUAL(c1->name, child_result->name, "not expected result value"); + UNIT_ASSERT_EQUAL(c1->name, child_result->name); matador::set(m1, "child", object_ptr()); matador::get(m1, "child", child_result); - UNIT_ASSERT_TRUE(child_result.get() == nullptr, "not expected result value"); + UNIT_ASSERT_TRUE(child_result.get() == nullptr); children_vector cv("children vector"); - UNIT_ASSERT_TRUE(cv.children.empty(), "vector must be empty"); + UNIT_ASSERT_TRUE(cv.children.empty()); matador::append(cv, "children", c1); - UNIT_ASSERT_FALSE(cv.children.empty(), "vector must not be empty"); + UNIT_ASSERT_FALSE(cv.children.empty()); matador::remove(cv, "children", c1); - UNIT_ASSERT_TRUE(cv.children.empty(), "vector must be empty"); + UNIT_ASSERT_TRUE(cv.children.empty()); // Todo: matador::remove, matador::begin, matador::end, matador::size, matador::empty for generic access has_many // see: https://tartanllama.github.io/c++/2017/01/03/deduction-on-the-left/ for begin and end // -// auto i = matador::begin(cv, "children"); -// auto i = matador::end(cv, "children"); +// auto i = matador::begin(cv); +// auto i = matador::end(cv); // -// auto size = matador::size(cv, "children"); -// bool is_empty = matador::empty(cv, "children"); +// auto size = matador::size(cv); +// bool is_empty = matador::empty(cv); } void ObjectStoreTestUnit::test_structure() @@ -887,11 +925,11 @@ void ObjectStoreTestUnit::test_structure() object_item_ptr optr = ostore_.insert(oi); - UNIT_ASSERT_GREATER(optr.id(), 0UL, "object id must be greater zero"); + UNIT_ASSERT_GREATER(optr.id(), 0UL); iptr = optr->ptr(); - UNIT_ASSERT_GREATER(iptr.id(), 0UL, "object id must be greater zero"); + UNIT_ASSERT_GREATER(iptr.id(), 0UL); } class cyclic @@ -923,35 +961,35 @@ void ObjectStoreTestUnit::test_structure_cyclic() cyclic_ptr c2(new cyclic("c2")); cyclic_ptr c3(new cyclic("c3")); - UNIT_ASSERT_EQUAL(c1.reference_count(), 0UL, "reference count must be zero"); - UNIT_ASSERT_EQUAL(c2.reference_count(), 0UL, "reference count must be zero"); + UNIT_ASSERT_EQUAL(c1.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(c2.reference_count(), 0UL); // cycle: c1 -> c2 -> c1 c1->cycler = c2; - UNIT_ASSERT_EQUAL(c1.reference_count(), 0UL, "reference count must be zero"); - UNIT_ASSERT_EQUAL(c2.reference_count(), 0UL, "reference count must be zero"); + UNIT_ASSERT_EQUAL(c1.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(c2.reference_count(), 0UL); c2->cycler = c1; - UNIT_ASSERT_EQUAL(c1.reference_count(), 0UL, "reference count must be zero"); - UNIT_ASSERT_EQUAL(c2.reference_count(), 0UL, "reference count must be zero"); + UNIT_ASSERT_EQUAL(c1.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(c2.reference_count(), 0UL); c1 = ostore.insert(c1); - UNIT_ASSERT_EQUAL(c1.reference_count(), 1UL, "reference count must be 1 (one)"); - UNIT_ASSERT_EQUAL(c2.reference_count(), 1UL, "reference count must be 1 (one)"); + UNIT_ASSERT_EQUAL(c1.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(c2.reference_count(), 1UL); c3->cycler = c1; - UNIT_ASSERT_EQUAL(c1.reference_count(), 1UL, "reference count must be 1 (one)"); - UNIT_ASSERT_EQUAL(c2.reference_count(), 1UL, "reference count must be 1 (one)"); + UNIT_ASSERT_EQUAL(c1.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(c2.reference_count(), 1UL); c3 = ostore.insert(c3); - UNIT_ASSERT_EQUAL(c1.reference_count(), 2UL, "reference count must be 2 (two)"); - UNIT_ASSERT_EQUAL(c2.reference_count(), 1UL, "reference count must be 1 (one)"); - UNIT_ASSERT_EQUAL(c3.reference_count(), 0UL, "reference count must be 0 (zero)"); + UNIT_ASSERT_EQUAL(c1.reference_count(), 2UL); + UNIT_ASSERT_EQUAL(c2.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(c3.reference_count(), 0UL); } void ObjectStoreTestUnit::test_structure_container() @@ -970,8 +1008,8 @@ void ObjectStoreTestUnit::test_structure_container() object_ptr c1 = childrens->children.front(); - UNIT_ASSERT_GREATER(c1.id(), 0UL, "object store must be greater zero"); - UNIT_ASSERT_EQUAL(c1.reference_count(), 1UL, "reference count must be one"); + UNIT_ASSERT_GREATER(c1.id(), 0UL); + UNIT_ASSERT_EQUAL(c1.reference_count(), 1UL); } void ObjectStoreTestUnit::test_transient_optr() @@ -991,14 +1029,14 @@ void ObjectStoreTestUnit::test_insert() { ostore_.attach("item"); - UNIT_ASSERT_EXCEPTION(ostore_.insert((Item *)nullptr), object_exception, "object is null", "null shouldn't be insertable"); + UNIT_ASSERT_EXCEPTION(ostore_.insert((Item *)nullptr), object_exception, "object is null"); std::unique_ptr ic(new ItemC); - UNIT_ASSERT_EXCEPTION(ostore_.insert(ic.get()), object_exception, "couldn't find object type", "unknown object type shouldn't be insertable"); + UNIT_ASSERT_EXCEPTION(ostore_.insert(ic.get()), object_exception, "couldn't find object type"); object_ptr item = ostore_.insert(new Item("test")); - UNIT_ASSERT_NOT_NULL(item.ptr(), "internal pointer should not be zero"); - UNIT_ASSERT_TRUE(item->id() > 0, "id must be greater zero"); + UNIT_ASSERT_NOT_NULL(item.ptr()); + UNIT_ASSERT_TRUE(item->id() > 0); } void ObjectStoreTestUnit::test_remove() @@ -1009,12 +1047,12 @@ void ObjectStoreTestUnit::test_remove() item_ptr item; - UNIT_ASSERT_EXCEPTION(ostore_.remove(item), object_exception, "object proxy is nullptr", "null shouldn't be removable"); + UNIT_ASSERT_EXCEPTION(ostore_.remove(item), object_exception, "object proxy is nullptr"); auto *i = new Item; item = i; - UNIT_ASSERT_EXCEPTION(ostore_.remove(item), object_exception, "prototype node is nullptr", "transient object shouldn't be removable"); + UNIT_ASSERT_EXCEPTION(ostore_.remove(item), object_exception, "prototype node is nullptr"); } void ObjectStoreTestUnit::test_primary_key() @@ -1023,11 +1061,11 @@ void ObjectStoreTestUnit::test_primary_key() item_ptr item; - UNIT_ASSERT_FALSE(item.has_primary_key(), "item must not have a primary key"); + UNIT_ASSERT_FALSE(item.has_primary_key()); item = new Item("Test"); - UNIT_ASSERT_TRUE(item.has_primary_key(), "item must have a primary key"); + UNIT_ASSERT_TRUE(item.has_primary_key()); } void ObjectStoreTestUnit::test_has_many() @@ -1037,8 +1075,8 @@ void ObjectStoreTestUnit::test_has_many() auto prototype = ostore_.find("books"); - UNIT_ASSERT_EQUAL("books", prototype->type(), "invalid type"); - UNIT_ASSERT_FALSE(prototype->has_primary_key(), "must be false"); + UNIT_ASSERT_EQUAL("books", prototype->type()); + UNIT_ASSERT_FALSE(prototype->has_primary_key()); ostore_.insert(new book_list); } @@ -1049,45 +1087,45 @@ void ObjectStoreTestUnit::test_has_many_to_many() ostore_.attach("student"); ostore_.attach("course"); - UNIT_ASSERT_EQUAL(4UL, ostore_.size(), "unexpected size"); + UNIT_ASSERT_EQUAL(4UL, ostore_.size()); auto george = ostore_.insert(new student("george")); auto jane = ostore_.insert(new student("jane")); auto algebra = ostore_.insert(new course("algebra")); auto art = ostore_.insert(new course("art")); - UNIT_ASSERT_TRUE(george->courses.empty(), "georges courses must be empty"); - UNIT_ASSERT_TRUE(jane->courses.empty(), "janes courses must be empty"); - UNIT_ASSERT_TRUE(algebra->students.empty(), "there must be no students in algebra"); - UNIT_ASSERT_TRUE(art->students.empty(), "there must be no students in art"); + UNIT_ASSERT_TRUE(george->courses.empty()); + UNIT_ASSERT_TRUE(jane->courses.empty()); + UNIT_ASSERT_TRUE(algebra->students.empty()); + UNIT_ASSERT_TRUE(art->students.empty()); art->students.push_back(jane); - UNIT_ASSERT_FALSE(art->students.empty(), "there must not be students in art"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "there must be one student in art course"); - UNIT_ASSERT_EQUAL(art->students.front()->name(), jane->name(), "arts student must be jane"); - UNIT_ASSERT_FALSE(jane->courses.empty(), "janes courses must not be empty"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL, "jane must've took one course"); - UNIT_ASSERT_EQUAL(jane->courses.front()->title, art->title, "janes course must be art"); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); + UNIT_ASSERT_EQUAL(art->students.front()->name(), jane->name()); + UNIT_ASSERT_FALSE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->courses.front()->title, art->title); jane->courses.erase(jane->courses.begin()); - UNIT_ASSERT_TRUE(jane->courses.empty(), "janes courses must be empty"); - UNIT_ASSERT_TRUE(art->students.empty(), "there must be no students in art"); + UNIT_ASSERT_TRUE(jane->courses.empty()); + UNIT_ASSERT_TRUE(art->students.empty()); george->courses.push_back(algebra); - UNIT_ASSERT_FALSE(algebra->students.empty(), "there must not be students in algebra"); - UNIT_ASSERT_EQUAL(algebra->students.size(), 1UL, "there must be one student in algebra course"); - UNIT_ASSERT_EQUAL(algebra->students.front()->name(), george->name(), "algebras student must be george"); - UNIT_ASSERT_FALSE(george->courses.empty(), "georges courses must not be empty"); - UNIT_ASSERT_EQUAL(george->courses.size(), 1UL, "george must've took one course"); - UNIT_ASSERT_EQUAL(george->courses.front()->title, algebra->title, "georges course must be algebra"); + UNIT_ASSERT_FALSE(algebra->students.empty()); + UNIT_ASSERT_EQUAL(algebra->students.size(), 1UL); + UNIT_ASSERT_EQUAL(algebra->students.front()->name(), george->name()); + UNIT_ASSERT_FALSE(george->courses.empty()); + UNIT_ASSERT_EQUAL(george->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(george->courses.front()->title, algebra->title); algebra->students.clear(); - UNIT_ASSERT_TRUE(george->courses.empty(), "georges courses must be empty"); - UNIT_ASSERT_TRUE(algebra->students.empty(), "there must be no students in algebra"); + UNIT_ASSERT_TRUE(george->courses.empty()); + UNIT_ASSERT_TRUE(algebra->students.empty()); } void ObjectStoreTestUnit::test_belongs_to_one() @@ -1099,24 +1137,24 @@ void ObjectStoreTestUnit::test_belongs_to_one() auto george = ostore_.insert(new citizen("george")); auto home = ostore_.insert(new address("foreststreet", "foresting")); - UNIT_ASSERT_TRUE(george->address_.empty(), "address must be empty"); - UNIT_ASSERT_TRUE(home->citizen_.empty(), "citizen must be empty"); + UNIT_ASSERT_TRUE(george->address_.empty()); + UNIT_ASSERT_TRUE(home->citizen_.empty()); // george->address_ = home; home->citizen_ = george; - UNIT_ASSERT_FALSE(george->address_.empty(), "address must not be empty"); - UNIT_ASSERT_FALSE(home->citizen_.empty(), "citizen must not be empty"); + UNIT_ASSERT_FALSE(george->address_.empty()); + UNIT_ASSERT_FALSE(home->citizen_.empty()); george->address_.clear(); - UNIT_ASSERT_TRUE(george->address_.empty(), "address must be empty"); - UNIT_ASSERT_TRUE(home->citizen_.empty(), "citizen must be empty"); + UNIT_ASSERT_TRUE(george->address_.empty()); + UNIT_ASSERT_TRUE(home->citizen_.empty()); george->address_ = home; - UNIT_ASSERT_FALSE(george->address_.empty(), "address must not be empty"); - UNIT_ASSERT_FALSE(home->citizen_.empty(), "citizen must not be empty"); + UNIT_ASSERT_FALSE(george->address_.empty()); + UNIT_ASSERT_FALSE(home->citizen_.empty()); } void ObjectStoreTestUnit::test_belongs_to_many() @@ -1132,34 +1170,34 @@ void ObjectStoreTestUnit::test_belongs_to_many() auto jane = ostore_.insert(new employee("jane")); auto dep = ostore_.insert(new department("insurance")); - UNIT_ASSERT_TRUE(dep->employees.empty(), "there must be no employees"); - UNIT_ASSERT_TRUE(george->dep().empty(), "there must not be an department"); - UNIT_ASSERT_TRUE(jane->dep().empty(), "there must not be an department"); + UNIT_ASSERT_TRUE(dep->employees.empty()); + UNIT_ASSERT_TRUE(george->dep().empty()); + UNIT_ASSERT_TRUE(jane->dep().empty()); // department is automatically set dep->employees.push_back(george); - UNIT_ASSERT_EQUAL(dep->employees.size(), 1UL, "there must be one employee"); - UNIT_ASSERT_EQUAL(dep->employees.front()->name(), "george", "expected name must be george"); - UNIT_ASSERT_FALSE(george->dep().empty(), "department must not be empty"); - UNIT_ASSERT_EQUAL(george->dep()->name, dep->name, "names must be equal"); + UNIT_ASSERT_EQUAL(dep->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(dep->employees.front()->name(), "george"); + UNIT_ASSERT_FALSE(george->dep().empty()); + UNIT_ASSERT_EQUAL(george->dep()->name, dep->name); // jane is automatically added to deps employee list jane->dep(dep); - UNIT_ASSERT_EQUAL(dep->employees.size(), 2UL, "there must be two employees"); + UNIT_ASSERT_EQUAL(dep->employees.size(), 2UL); // remove george auto i = dep->employees.begin(); i = dep->employees.erase(i); - UNIT_ASSERT_EQUAL(dep->employees.size(), 1UL, "there must be one employee"); - UNIT_ASSERT_TRUE(george->dep().empty(), "there must not be an department"); - UNIT_ASSERT_EQUAL(dep->employees.front()->name(), "jane", "expected name must be jane"); + UNIT_ASSERT_EQUAL(dep->employees.size(), 1UL); + UNIT_ASSERT_TRUE(george->dep().empty()); + UNIT_ASSERT_EQUAL(dep->employees.front()->name(), "jane"); jane->department_.clear(); - UNIT_ASSERT_TRUE(dep->employees.empty(), "there must be no employees"); + UNIT_ASSERT_TRUE(dep->employees.empty()); } struct basic_logger @@ -1209,7 +1247,7 @@ void ObjectStoreTestUnit::test_observer() "book_list" }); - UNIT_ASSERT_TRUE(basic_logger::nodes == result, "vectors must be equal"); + UNIT_ASSERT_TRUE(basic_logger::nodes == result); basic_logger::nodes.clear(); @@ -1232,7 +1270,7 @@ void ObjectStoreTestUnit::test_observer() "book" }; - UNIT_ASSERT_TRUE(basic_logger::nodes == result, "vectors must be equal"); + UNIT_ASSERT_TRUE(basic_logger::nodes == result); } typedef has_many_to_many_item course_student_item; @@ -1243,17 +1281,17 @@ void ObjectStoreTestUnit::test_attach_has_many() ostore_.attach("student"); ostore_.attach("course"); - UNIT_ASSERT_EQUAL(4UL, ostore_.size(), "unexpected size"); + UNIT_ASSERT_EQUAL(4UL, ostore_.size()); std::unique_ptr item1(ostore_.create()); - UNIT_ASSERT_NOT_NULL(item1.get(), "course student item must not be null"); + UNIT_ASSERT_NOT_NULL(item1.get()); auto node = ostore_.find("student_course"); - UNIT_ASSERT_FALSE(node == ostore_.end(), "node must be valid"); + UNIT_ASSERT_FALSE(node == ostore_.end()); node = ostore_.find(); - UNIT_ASSERT_FALSE(node == ostore_.end(), "node must be valid"); + UNIT_ASSERT_FALSE(node == ostore_.end()); } diff --git a/test/object/ObjectStoreTestUnit.hpp b/test/object/ObjectStoreTestUnit.hpp index 9d4522199..4d42fd597 100644 --- a/test/object/ObjectStoreTestUnit.hpp +++ b/test/object/ObjectStoreTestUnit.hpp @@ -30,6 +30,7 @@ class ObjectStoreTestUnit : public matador::unit_test void test_delete_object(); void test_hierarchy(); void test_view(); +// void test_clear_type(); void test_clear(); void test_generic(); void test_structure(); diff --git a/test/object/ObjectTransactiontestUnit.cpp b/test/object/ObjectTransactiontestUnit.cpp index 6a93aa584..f7f8347b3 100644 --- a/test/object/ObjectTransactiontestUnit.cpp +++ b/test/object/ObjectTransactiontestUnit.cpp @@ -40,7 +40,7 @@ void ObjectTransactiontestUnit::test_insert() auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180)); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_GREATER(hans->id(), 0UL); tr.commit(); } catch (std::exception &) { @@ -51,8 +51,8 @@ void ObjectTransactiontestUnit::test_insert() auto p = pview.front(); - UNIT_ASSERT_GREATER(p->id(), 0UL, "id must be valid"); - UNIT_ASSERT_EQUAL(p->name(), "Hans", "name must be 'Hans'"); + UNIT_ASSERT_GREATER(p->id(), 0UL); + UNIT_ASSERT_EQUAL(p->name(), "Hans"); } void ObjectTransactiontestUnit::test_insert_rollback() @@ -67,7 +67,7 @@ void ObjectTransactiontestUnit::test_insert_rollback() auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180)); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_GREATER(hans->id(), 0UL); tr.rollback(); } catch (std::exception &) { @@ -76,7 +76,7 @@ void ObjectTransactiontestUnit::test_insert_rollback() matador::object_view pview(store); - UNIT_ASSERT_TRUE(pview.empty(), "view must be empty"); + UNIT_ASSERT_TRUE(pview.empty()); } void ObjectTransactiontestUnit::test_update() @@ -92,22 +92,22 @@ void ObjectTransactiontestUnit::test_update() tr.begin(); - UNIT_ASSERT_EQUAL(hans->height(), 180U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 180U); hans->height(183); - UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid"); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 183U); + UNIT_ASSERT_GREATER(hans->id(), 0UL); tr.commit(); } catch (std::exception &) { UNIT_FAIL("shouldn't come here"); } - UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid"); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 183U); + UNIT_ASSERT_GREATER(hans->id(), 0UL); matador::object_view pview(store); - UNIT_ASSERT_FALSE(pview.empty(), "view must not be empty"); + UNIT_ASSERT_FALSE(pview.empty()); } void ObjectTransactiontestUnit::test_update_rollback() @@ -124,22 +124,22 @@ void ObjectTransactiontestUnit::test_update_rollback() tr.begin(); - UNIT_ASSERT_EQUAL(hans->height(), 180U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 180U); hans->height(183); - UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid"); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 183U); + UNIT_ASSERT_GREATER(hans->id(), 0UL); tr.rollback(); } catch (std::exception &) { UNIT_FAIL("shouldn't come here"); } - UNIT_ASSERT_EQUAL(hans->height(), 180U, "height must be valid"); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 180U); + UNIT_ASSERT_GREATER(hans->id(), 0UL); matador::object_view pview(store); - UNIT_ASSERT_FALSE(pview.empty(), "view must not be empty"); + UNIT_ASSERT_FALSE(pview.empty()); } void ObjectTransactiontestUnit::test_delete() @@ -149,7 +149,7 @@ void ObjectTransactiontestUnit::test_delete() auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180)); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_GREATER(hans->id(), 0UL); matador::transaction tr(store); @@ -167,8 +167,8 @@ void ObjectTransactiontestUnit::test_delete() auto p = pview.front(); - UNIT_ASSERT_EQUAL(p.id(), 0UL, "id must be valid"); - UNIT_ASSERT_TRUE(p.ptr() == nullptr, "object must be nullptr"); + UNIT_ASSERT_EQUAL(p.id(), 0UL); + UNIT_ASSERT_TRUE(p.ptr() == nullptr); } void ObjectTransactiontestUnit::test_delete_rollback() @@ -178,7 +178,7 @@ void ObjectTransactiontestUnit::test_delete_rollback() auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180)); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_GREATER(hans->id(), 0UL); matador::transaction tr(store); @@ -195,12 +195,12 @@ void ObjectTransactiontestUnit::test_delete_rollback() matador::object_view pview(store); auto p = pview.front(); - UNIT_ASSERT_EQUAL(pview.size(), 1UL, "size must be one"); + UNIT_ASSERT_EQUAL(pview.size(), 1UL); - UNIT_ASSERT_GREATER(p.id(), 0UL, "id must be valid"); - UNIT_ASSERT_FALSE(p.ptr() == nullptr, "object must be nullptr"); - UNIT_ASSERT_GREATER(p->id(), 0UL, "id must be valid"); - UNIT_ASSERT_EQUAL(p->name(), "Hans", "name must be 'Hans'"); + UNIT_ASSERT_GREATER(p.id(), 0UL); + UNIT_ASSERT_FALSE(p.ptr() == nullptr); + UNIT_ASSERT_GREATER(p->id(), 0UL); + UNIT_ASSERT_EQUAL(p->name(), "Hans"); } void ObjectTransactiontestUnit::test_nested() @@ -215,24 +215,24 @@ void ObjectTransactiontestUnit::test_nested() auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180)); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_GREATER(hans->id(), 0UL); tr1.commit(); tr1.begin(); - UNIT_ASSERT_EQUAL(hans->height(), 180U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 180U); hans->height(183); - UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 183U); matador::transaction tr2(store); try { tr2.begin(); - UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 183U); hans->height(159); - UNIT_ASSERT_EQUAL(hans->height(), 159U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 159U); tr2.commit(); } catch (std::exception &) { @@ -248,8 +248,8 @@ void ObjectTransactiontestUnit::test_nested() auto p = pview.front(); - UNIT_ASSERT_GREATER(p->id(), 0UL, "id must be valid"); - UNIT_ASSERT_EQUAL(p->name(), "Hans", "name must be 'Hans'"); + UNIT_ASSERT_GREATER(p->id(), 0UL); + UNIT_ASSERT_EQUAL(p->name(), "Hans"); } void ObjectTransactiontestUnit::test_nested_rollback() @@ -264,28 +264,28 @@ void ObjectTransactiontestUnit::test_nested_rollback() auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180)); - UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid"); + UNIT_ASSERT_GREATER(hans->id(), 0UL); tr1.commit(); tr1.begin(); - UNIT_ASSERT_EQUAL(hans->height(), 180U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 180U); hans->height(183); - UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 183U); matador::transaction tr2(store); try { tr2.begin(); - UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 183U); hans->height(159); - UNIT_ASSERT_EQUAL(hans->height(), 159U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 159U); tr2.rollback(); - UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid"); + UNIT_ASSERT_EQUAL(hans->height(), 183U); } catch (std::exception &) { tr2.rollback(); @@ -300,8 +300,8 @@ void ObjectTransactiontestUnit::test_nested_rollback() auto p = pview.front(); - UNIT_ASSERT_GREATER(p->id(), 0UL, "id must be valid"); - UNIT_ASSERT_EQUAL(p->name(), "Hans", "name must be 'Hans'"); + UNIT_ASSERT_GREATER(p->id(), 0UL); + UNIT_ASSERT_EQUAL(p->name(), "Hans"); } void ObjectTransactiontestUnit::test_foreign() @@ -323,15 +323,15 @@ void ObjectTransactiontestUnit::test_foreign() m1 = mview.front(); - UNIT_ASSERT_TRUE(m1.ptr() != nullptr, "master must be valid"); - UNIT_ASSERT_TRUE(m1->children.ptr() != nullptr, "child must be valid"); - UNIT_ASSERT_EQUAL(m1->name, "m1", "name must be valid"); + UNIT_ASSERT_TRUE(m1.ptr() != nullptr); + UNIT_ASSERT_TRUE(m1->children.ptr() != nullptr); + UNIT_ASSERT_EQUAL(m1->name, "m1"); - UNIT_ASSERT_TRUE(store.is_removable(m1), "m1 must be removable"); + UNIT_ASSERT_TRUE(store.is_removable(m1)); store.remove(m1); - UNIT_ASSERT_TRUE(mview.empty(), "view must be empty"); + UNIT_ASSERT_TRUE(mview.empty()); tr.commit(); } catch (std::exception &) { @@ -358,21 +358,21 @@ void ObjectTransactiontestUnit::test_foreign_rollback() try { tr.begin(); - UNIT_ASSERT_TRUE(m1.ptr() != nullptr, "master must be valid"); - UNIT_ASSERT_TRUE(m1->children.ptr() != nullptr, "child must be valid"); - UNIT_ASSERT_EQUAL(m1->name, "m1", "name must be valid"); + UNIT_ASSERT_TRUE(m1.ptr() != nullptr); + UNIT_ASSERT_TRUE(m1->children.ptr() != nullptr); + UNIT_ASSERT_EQUAL(m1->name, "m1"); - UNIT_ASSERT_TRUE(store.is_removable(m1), "m1 must be removable"); + UNIT_ASSERT_TRUE(store.is_removable(m1)); store.remove(m1); - UNIT_ASSERT_TRUE(mview.empty(), "view must be empty"); + UNIT_ASSERT_TRUE(mview.empty()); tr.rollback(); } catch (std::exception &) { tr.rollback(); } - UNIT_ASSERT_FALSE(mview.empty(), "view must be empty"); + UNIT_ASSERT_FALSE(mview.empty()); } diff --git a/test/object/PrimaryKeyUnitTest.cpp b/test/object/PrimaryKeyUnitTest.cpp index 4dfcd296d..7be474f65 100644 --- a/test/object/PrimaryKeyUnitTest.cpp +++ b/test/object/PrimaryKeyUnitTest.cpp @@ -24,7 +24,7 @@ void PrimaryKeyUnitTest::test_create() // long result = pkb->id(); // -// UNIT_ASSERT_EQUAL(id57, result, "values are must be equal"); +// UNIT_ASSERT_EQUAL(id57, result); } void PrimaryKeyUnitTest::test_share() @@ -33,18 +33,18 @@ void PrimaryKeyUnitTest::test_share() std::string gollum("gollum@mittelerde.to"); matador::identifier email(id); - UNIT_ASSERT_EQUAL(id, email.value(), "invalid identifier value"); + UNIT_ASSERT_EQUAL(id, email.value()); matador::identifier shared_email; - UNIT_ASSERT_TRUE(shared_email.value().empty(), "identifier must be empty"); + UNIT_ASSERT_TRUE(shared_email.value().empty()); // email.share_with(shared_email); -// UNIT_ASSERT_EQUAL(id, shared_email.value(), "invalid identifier value"); +// UNIT_ASSERT_EQUAL(id, shared_email.value()); email.value(gollum); - UNIT_ASSERT_EQUAL(gollum, email.value(), "invalid identifier value"); -// UNIT_ASSERT_EQUAL(gollum, shared_email.value(), "invalid identifier value"); + UNIT_ASSERT_EQUAL(gollum, email.value()); +// UNIT_ASSERT_EQUAL(gollum, shared_email.value()); } diff --git a/test/object/PrototypeTreeTest.cpp b/test/object/PrototypeTreeTest.cpp index 7a7d0dd32..a088f5647 100644 --- a/test/object/PrototypeTreeTest.cpp +++ b/test/object/PrototypeTreeTest.cpp @@ -29,24 +29,24 @@ PrototypeTreeTestUnit::PrototypeTreeTestUnit() void PrototypeTreeTestUnit::test_empty() { object_store ptree; - UNIT_ASSERT_TRUE(ptree.empty(), "prototype must be empty"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)0, "prototype size must be zero (0)"); + UNIT_ASSERT_TRUE(ptree.empty()); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)0); } void PrototypeTreeTestUnit::test_insert() { object_store ptree; - UNIT_ASSERT_EXCEPTION(ptree.attach("item", matador::object_store::not_abstract, "baba"), object_exception, "unknown prototype type", "inserted with invalid parent"); + UNIT_ASSERT_EXCEPTION(ptree.attach("item", matador::object_store::not_abstract, "baba"), object_exception, "unknown prototype type"); ptree.attach("item"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1, "prototype size must be one (1)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1); - UNIT_ASSERT_EXCEPTION(ptree.attach("item"), object_exception, "prototype already inserted: item", "inserted same prototype twice"); + UNIT_ASSERT_EXCEPTION(ptree.attach("item"), object_exception, "prototype already inserted: item"); ptree.attach("item_a"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)2, "prototype size must be one (2)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)2); } void PrototypeTreeTestUnit::test_find() @@ -54,33 +54,33 @@ void PrototypeTreeTestUnit::test_find() object_store ptree; ptree.attach("item"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1, "prototype size must be one (1)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1); prototype_iterator elem = ptree.find("item"); - UNIT_ASSERT_TRUE(elem != ptree.end(), "couldn't find prototype"); - UNIT_ASSERT_EQUAL(elem->type(), "item", "type must be 'item'"); + UNIT_ASSERT_TRUE(elem != ptree.end()); + UNIT_ASSERT_EQUAL(elem->type(), "item"); elem = ptree.find(); - UNIT_ASSERT_TRUE(elem != ptree.end(), "couldn't find prototype"); - UNIT_ASSERT_EQUAL(elem->type(), "item", "type must be 'item'"); + UNIT_ASSERT_TRUE(elem != ptree.end()); + UNIT_ASSERT_EQUAL(elem->type(), "item"); elem = ptree.find("unknown"); - UNIT_ASSERT_TRUE(elem == ptree.end(), "shouldn't find a prototype"); + UNIT_ASSERT_TRUE(elem == ptree.end()); - ptree.attach>("object_item", matador::object_store::not_abstract, "item"); + ptree.attach>("object_item", matador::object_store::not_abstract); elem = ptree.find("object_item"); - UNIT_ASSERT_TRUE(elem != ptree.end(), "couldn't find prototype"); - UNIT_ASSERT_EQUAL(elem->type(), "object_item", "type must be 'item'"); + UNIT_ASSERT_TRUE(elem != ptree.end()); + UNIT_ASSERT_EQUAL(elem->type(), "object_item"); elem = ptree.find("item"); - UNIT_ASSERT_TRUE(elem != ptree.end(), "couldn't find prototype"); - UNIT_ASSERT_EQUAL(elem->type(), "item", "type must be 'item'"); + UNIT_ASSERT_TRUE(elem != ptree.end()); + UNIT_ASSERT_EQUAL(elem->type(), "item"); -// ptree.insert(new list_object_producer("ptr_list"), "item_ptr_list"); +// ptree.insert(new list_object_producer("ptr_list")); } void PrototypeTreeTestUnit::test_remove() @@ -88,15 +88,15 @@ void PrototypeTreeTestUnit::test_remove() object_store ptree; ptree.attach("item"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1, "prototype size must be one (1)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1); - UNIT_ASSERT_EXCEPTION(ptree.detach(nullptr), object_exception, "invalid type (null)", "expect an serializable exception when trying to remove unknown type"); - UNIT_ASSERT_EXCEPTION(ptree.detach("ITEM"), object_exception, "unknown prototype type", "expect an serializable exception when trying to remove unknown type"); + UNIT_ASSERT_EXCEPTION(ptree.detach(nullptr), object_exception, "invalid type (null)"); + UNIT_ASSERT_EXCEPTION(ptree.detach("ITEM"), object_exception, "unknown prototype type"); ptree.detach("item"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)0, "prototype size must be one (0)"); - UNIT_ASSERT_TRUE(ptree.empty(), "prototype tree must be empty"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)0); + UNIT_ASSERT_TRUE(ptree.empty()); } void PrototypeTreeTestUnit::test_erase() @@ -104,15 +104,15 @@ void PrototypeTreeTestUnit::test_erase() object_store ptree; prototype_iterator iter = ptree.attach("item"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1, "prototype size must be one (1)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1); prototype_iterator iter2; - UNIT_ASSERT_EXCEPTION(ptree.detach(iter2), object_exception, "invalid prototype iterator", "expect an serializable exception when trying to remove unknown type"); + UNIT_ASSERT_EXCEPTION(ptree.detach(iter2), object_exception, "invalid prototype iterator"); ptree.detach(iter); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)0, "prototype size must be one (0)"); - UNIT_ASSERT_TRUE(ptree.empty(), "prototype tree must be empty"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)0); + UNIT_ASSERT_TRUE(ptree.empty()); } void PrototypeTreeTestUnit::test_clear() @@ -123,12 +123,12 @@ void PrototypeTreeTestUnit::test_clear() ptree.attach("item_b", matador::object_store::not_abstract, "item"); ptree.attach("item_c", matador::object_store::not_abstract, "item"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)4, "prototype size must be one (4)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)4); ptree.clear(true); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)0, "prototype size must be one (0)"); - UNIT_ASSERT_TRUE(ptree.empty(), "prototype tree must be empty"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)0); + UNIT_ASSERT_TRUE(ptree.empty()); } void PrototypeTreeTestUnit::test_has_many() @@ -137,11 +137,11 @@ void PrototypeTreeTestUnit::test_has_many() ptree.attach("book"); ptree.attach("book_list"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)3, "prototype size must be one (3)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)3); prototype_iterator i = ptree.find("books"); - UNIT_ASSERT_TRUE(i != ptree.end(), "should've found 'books' node"); + UNIT_ASSERT_TRUE(i != ptree.end()); } void PrototypeTreeTestUnit::test_decrement() @@ -149,13 +149,13 @@ void PrototypeTreeTestUnit::test_decrement() object_store ptree; ptree.attach("item"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1, "prototype size must be one (1)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)1); prototype_iterator i = ptree.end(); --i; - UNIT_ASSERT_TRUE(i == ptree.begin(), "iterator must be begin"); + UNIT_ASSERT_TRUE(i == ptree.begin()); } void PrototypeTreeTestUnit::test_count() { @@ -165,7 +165,7 @@ void PrototypeTreeTestUnit::test_count() { ptree.attach("item_b", matador::object_store::not_abstract, "item"); ptree.attach("item_c", matador::object_store::not_abstract, "item"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)4, "prototype size must be one (5)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)4); } void PrototypeTreeTestUnit::test_child_of() @@ -174,15 +174,15 @@ void PrototypeTreeTestUnit::test_child_of() ptree.attach("item"); ptree.attach("item_a", matador::object_store::not_abstract, "item"); - UNIT_ASSERT_EQUAL(ptree.size(), (size_t)2, "prototype size must be one (1)"); + UNIT_ASSERT_EQUAL(ptree.size(), (size_t)2); prototype_iterator root = ptree.begin(); prototype_iterator item_a = ptree.find(); - UNIT_ASSERT_FALSE(root->is_child_of(item_a.get()), "root must not be child of node"); + UNIT_ASSERT_FALSE(root->is_child_of(item_a.get())); - UNIT_ASSERT_TRUE(item_a->is_child_of(root.get()), "node must be child of root"); + UNIT_ASSERT_TRUE(item_a->is_child_of(root.get())); } void PrototypeTreeTestUnit::test_traverse() @@ -199,18 +199,18 @@ void PrototypeTreeTestUnit::test_traverse() int count(0); while (first != last) { - UNIT_ASSERT_LESS(count, 4, "prototype count isn't valid"); + UNIT_ASSERT_LESS(count, 4); ++first; ++count; } - UNIT_ASSERT_EQUAL(count, 4, "expected prototype size isn't 5"); + UNIT_ASSERT_EQUAL(count, 4); first = ptree.begin(); ++first; first--; - UNIT_ASSERT_TRUE(first == ptree.begin(), "expected prototype iterator to be begin()"); + UNIT_ASSERT_TRUE(first == ptree.begin()); } void PrototypeTreeTestUnit::test_const_traverse() @@ -226,19 +226,19 @@ void PrototypeTreeTestUnit::test_const_traverse() int count(0); while (first != last) { - UNIT_ASSERT_LESS(count, 4, "prototype count isn't valid"); + UNIT_ASSERT_LESS(count, 4); ++first; ++count; } - UNIT_ASSERT_EQUAL(count, 4, "expected prototype size isn't 5"); + UNIT_ASSERT_EQUAL(count, 4); first = ptree.begin(); first++; - UNIT_ASSERT_EQUAL(first->type(), "item_a", "type must be 'item_a'"); - UNIT_ASSERT_EQUAL((*first).type(), "item_a", "type must be 'item_a'"); - UNIT_ASSERT_EQUAL(first.get()->type(), "item_a", "type must be 'item_a'"); + UNIT_ASSERT_EQUAL(first->type(), "item_a"); + UNIT_ASSERT_EQUAL((*first).type(), "item_a"); + UNIT_ASSERT_EQUAL(first.get()->type(), "item_a"); first--; - UNIT_ASSERT_TRUE(first == ptree.begin(), "expected prototype iterator to be begin()"); + UNIT_ASSERT_TRUE(first == ptree.begin()); } diff --git a/test/object/RelationTestUnit.cpp b/test/object/RelationTestUnit.cpp index f8dfef997..0793c8d7e 100644 --- a/test/object/RelationTestUnit.cpp +++ b/test/object/RelationTestUnit.cpp @@ -48,48 +48,48 @@ void RelationTestUnit::test_has_one() store.attach("child"); store.attach("master"); - UNIT_ASSERT_EQUAL(2UL, store.size(), "must be two nodes"); + UNIT_ASSERT_EQUAL(2UL, store.size()); auto node = store.find("master"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "child", "endpoint field name must be 'child'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE, "endpoint type must be HS_ONE"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "child"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE); node = store.find(); - UNIT_ASSERT_TRUE(node->endpoints_empty(), "endpoints must be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 0UL, "endpoints must be zero"); + UNIT_ASSERT_TRUE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 0UL); auto child1 = store.insert(new child("child 1")); - UNIT_ASSERT_TRUE(child1.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(child1.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(child1.id() > 0UL); + UNIT_ASSERT_EQUAL(child1.reference_count(), 0UL); auto m1 = store.insert(new master("m1", child1)); - UNIT_ASSERT_TRUE(m1.id() > 0UL, "id must be greater zero"); + UNIT_ASSERT_TRUE(m1.id() > 0UL); - UNIT_ASSERT_NOT_NULL(m1->children.get(), "id must not be null"); - UNIT_ASSERT_EQUAL(child1.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_NOT_NULL(m1->children.get()); + UNIT_ASSERT_EQUAL(child1.reference_count(), 1UL); m1->children = nullptr; - UNIT_ASSERT_NULL(m1->children.get(), "id must be null"); - UNIT_ASSERT_EQUAL(child1.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_NULL(m1->children.get()); + UNIT_ASSERT_EQUAL(child1.reference_count(), 0UL); store.remove(m1); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find()->size(), 1UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find()->size(), 1UL); store.remove(child1); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); auto m1_ptr = std::make_unique("m1"); auto child1_ptr = std::make_unique("child 1"); @@ -99,14 +99,14 @@ void RelationTestUnit::test_has_one() m1 = store.insert(m1_ptr.release()); child1 = m1->children; - UNIT_ASSERT_TRUE(m1.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_TRUE(child1.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(child1.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_TRUE(m1.id() > 0UL); + UNIT_ASSERT_TRUE(child1.id() > 0UL); + UNIT_ASSERT_EQUAL(child1.reference_count(), 1UL); store.remove(m1); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); } void RelationTestUnit::test_insert_belongs_to_one() @@ -117,27 +117,27 @@ void RelationTestUnit::test_insert_belongs_to_one() store.attach("citizen"); store.attach
("address"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("citizen"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "address", "endpoint field name must be 'address'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE, "endpoint type must be HAS_ONE"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "address"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE); node = store.find
(); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "citizen", "endpoint field name must be 'citizen'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "citizen"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); // create a citizen and set its address // than insert that combination into store @@ -149,43 +149,43 @@ void RelationTestUnit::test_insert_belongs_to_one() auto george = store.insert(george_ptr.release()); - UNIT_ASSERT_TRUE(george.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(george.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_NOT_NULL(george->address_.get(), "id must not be null"); + UNIT_ASSERT_TRUE(george.id() > 0UL); + UNIT_ASSERT_EQUAL(george.reference_count(), 1UL); + UNIT_ASSERT_NOT_NULL(george->address_.get()); auto home = george->address_; - UNIT_ASSERT_TRUE(home.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(home.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_NOT_NULL(home->citizen_.get(), "id must not be null"); + UNIT_ASSERT_TRUE(home.id() > 0UL); + UNIT_ASSERT_EQUAL(home.reference_count(), 1UL); + UNIT_ASSERT_NOT_NULL(home->citizen_.get()); store.remove(george); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find
()->size(), 0UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find
()->size(), 0UL); george_ptr = std::make_unique("george"); home = store.insert(new address("foreststreet", "foresting")); - UNIT_ASSERT_TRUE(home.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(home.reference_count(), 0UL, "ref count must be one"); - UNIT_ASSERT_NULL(home->citizen_.get(), "id must not be null"); + UNIT_ASSERT_TRUE(home.id() > 0UL); + UNIT_ASSERT_EQUAL(home.reference_count(), 0UL); + UNIT_ASSERT_NULL(home->citizen_.get()); george_ptr->address_ = home; george = store.insert(george_ptr.release()); - UNIT_ASSERT_TRUE(george.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(george.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_NOT_NULL(george->address_.get(), "id must not be null"); - UNIT_ASSERT_TRUE(home.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(home.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_NOT_NULL(home->citizen_.get(), "id must not be null"); + UNIT_ASSERT_TRUE(george.id() > 0UL); + UNIT_ASSERT_EQUAL(george.reference_count(), 1UL); + UNIT_ASSERT_NOT_NULL(george->address_.get()); + UNIT_ASSERT_TRUE(home.id() > 0UL); + UNIT_ASSERT_EQUAL(home.reference_count(), 1UL); + UNIT_ASSERT_NOT_NULL(home->citizen_.get()); store.remove(george); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find
()->size(), 0UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find
()->size(), 0UL); } void RelationTestUnit::test_belongs_to_one() @@ -196,50 +196,50 @@ void RelationTestUnit::test_belongs_to_one() store.attach("citizen"); store.attach
("address"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("citizen"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "address", "endpoint field name must be 'address'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE, "endpoint type must be HAS_ONE"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "address"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE); node = store.find
(); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "citizen", "endpoint field name must be 'citizen'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "citizen"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); auto george = store.insert(new citizen("george")); auto home = store.insert(new address("foreststreet", "foresting")); - UNIT_ASSERT_TRUE(george.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_TRUE(home.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_NULL(george->address_.get(), "id must be null"); - UNIT_ASSERT_NULL(home->citizen_.get(), "id must be null"); + UNIT_ASSERT_TRUE(george.id() > 0UL); + UNIT_ASSERT_TRUE(home.id() > 0UL); + UNIT_ASSERT_NULL(george->address_.get()); + UNIT_ASSERT_NULL(home->citizen_.get()); george->address_ = home; - UNIT_ASSERT_NOT_NULL(george->address_.get(), "id must not be null"); - UNIT_ASSERT_NOT_NULL(home->citizen_.get(), "id must not be null"); + UNIT_ASSERT_NOT_NULL(george->address_.get()); + UNIT_ASSERT_NOT_NULL(home->citizen_.get()); george->address_ = nullptr; - UNIT_ASSERT_NULL(george->address_.get(), "id must be null"); - UNIT_ASSERT_NULL(home->citizen_.get(), "id must be null"); + UNIT_ASSERT_NULL(george->address_.get()); + UNIT_ASSERT_NULL(home->citizen_.get()); home->citizen_ = george; - UNIT_ASSERT_NOT_NULL(george->address_.get(), "id must be null"); - UNIT_ASSERT_NOT_NULL(home->citizen_.get(), "id must be null"); + UNIT_ASSERT_NOT_NULL(george->address_.get()); + UNIT_ASSERT_NOT_NULL(home->citizen_.get()); } void RelationTestUnit::test_remove_belongs_to_one() @@ -250,77 +250,77 @@ void RelationTestUnit::test_remove_belongs_to_one() store.attach("citizen"); store.attach
("address"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("citizen"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "address", "endpoint field name must be 'address'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE, "endpoint type must be HAS_ONE"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "address"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE); node = store.find
(); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "citizen", "endpoint field name must be 'citizen'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "citizen"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); auto george = store.insert(new citizen("george")); auto home = store.insert(new address("foreststreet", "foresting")); - UNIT_ASSERT_TRUE(george.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_NULL(george->address_.get(), "id must be null"); - UNIT_ASSERT_TRUE(home.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_NULL(home->citizen_.get(), "id must be null"); + UNIT_ASSERT_TRUE(george.id() > 0UL); + UNIT_ASSERT_NULL(george->address_.get()); + UNIT_ASSERT_TRUE(home.id() > 0UL); + UNIT_ASSERT_NULL(home->citizen_.get()); george->address_ = home; - UNIT_ASSERT_NOT_NULL(george->address_.get(), "id must not be null"); - UNIT_ASSERT_EQUAL(george.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_NOT_NULL(home->citizen_.get(), "id must not be null"); - UNIT_ASSERT_EQUAL(home.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_NOT_NULL(george->address_.get()); + UNIT_ASSERT_EQUAL(george.reference_count(), 1UL); + UNIT_ASSERT_NOT_NULL(home->citizen_.get()); + UNIT_ASSERT_EQUAL(home.reference_count(), 1UL); store.remove(george); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find
()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_FALSE(home.valid(), "home must be null"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find
()->size(), 0UL); + UNIT_ASSERT_FALSE(home.valid()); george = store.insert(new citizen("george")); - UNIT_ASSERT_TRUE(george.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_NULL(george->address_.get(), "id must be null"); + UNIT_ASSERT_TRUE(george.id() > 0UL); + UNIT_ASSERT_NULL(george->address_.get()); home = store.insert(new address("foreststreet", "foresting")); - UNIT_ASSERT_TRUE(home.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_FALSE(home->citizen_.valid(), "id must be null"); + UNIT_ASSERT_TRUE(home.id() > 0UL); + UNIT_ASSERT_FALSE(home->citizen_.valid()); home->citizen_ = george; - UNIT_ASSERT_TRUE(george->address_.valid(), "id must not be null"); - UNIT_ASSERT_EQUAL(george.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_TRUE(home->citizen_.valid(), "id must not be null"); - UNIT_ASSERT_EQUAL(home.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_TRUE(george->address_.valid()); + UNIT_ASSERT_EQUAL(george.reference_count(), 1UL); + UNIT_ASSERT_TRUE(home->citizen_.valid()); + UNIT_ASSERT_EQUAL(home.reference_count(), 1UL); store.remove(home); - UNIT_ASSERT_EQUAL(store.find
()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_TRUE(george.valid(), "george must be valid"); - UNIT_ASSERT_TRUE(george.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_FALSE(george->address_.valid(), "id must be null"); + UNIT_ASSERT_EQUAL(store.find
()->size(), 0UL); + UNIT_ASSERT_TRUE(george.valid()); + UNIT_ASSERT_TRUE(george.id() > 0UL); + UNIT_ASSERT_FALSE(george->address_.valid()); store.remove(george); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_FALSE(george.valid(), "home must be null"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_FALSE(george.valid()); } void RelationTestUnit::test_insert_belongs_to_many() @@ -331,91 +331,91 @@ void RelationTestUnit::test_insert_belongs_to_many() store.attach("department"); store.attach("employee"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("employee"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "department", "endpoint field name must be 'department'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "department"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); node = store.find(); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "employee", "endpoint field name must be 'employee'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "employee"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); auto george_ptr = std::make_unique("george"); george_ptr->dep(new department("insurance")); auto george = store.insert(george_ptr.release()); - UNIT_ASSERT_TRUE(george.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(george.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_NOT_NULL(george->dep().get(), "id must not be null"); + UNIT_ASSERT_TRUE(george.id() > 0UL); + UNIT_ASSERT_EQUAL(george.reference_count(), 1UL); + UNIT_ASSERT_NOT_NULL(george->dep().get()); auto insurance = george->dep(); - UNIT_ASSERT_EQUAL(insurance.id(), 0UL, "id must be zero"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "size must be one"); + UNIT_ASSERT_EQUAL(insurance.id(), 0UL); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); insurance = store.insert(insurance); - UNIT_ASSERT_GREATER(insurance.id(), 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "size must be one"); - UNIT_ASSERT_EQUAL(george.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_GREATER(insurance.id(), 0UL); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(george.reference_count(), 1UL); store.remove(george); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find()->size(), 1UL, "size must be one"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find()->size(), 1UL); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); store.remove(insurance); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); george_ptr = std::make_unique("george"); insurance = store.insert(new department("insurance")); - UNIT_ASSERT_TRUE(insurance.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "size must be zero"); + UNIT_ASSERT_TRUE(insurance.id() > 0UL); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); george_ptr->dep(insurance); george = store.insert(george_ptr.release()); - UNIT_ASSERT_TRUE(george.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(george.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_NOT_NULL(george->dep().get(), "id must not be null"); - UNIT_ASSERT_TRUE(insurance.id() > 0UL, "id must be greater zero"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "size must be one"); + UNIT_ASSERT_TRUE(george.id() > 0UL); + UNIT_ASSERT_EQUAL(george.reference_count(), 1UL); + UNIT_ASSERT_NOT_NULL(george->dep().get()); + UNIT_ASSERT_TRUE(insurance.id() > 0UL); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); store.remove(george); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find()->size(), 1UL, "size must be one"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find()->size(), 1UL); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); store.remove(insurance); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); } void RelationTestUnit::test_belongs_to_many() @@ -426,84 +426,84 @@ void RelationTestUnit::test_belongs_to_many() store.attach("department"); store.attach("employee"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("employee"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "department", "endpoint field name must be 'department'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "department"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); node = store.find(); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "employee", "endpoint field name must be 'employee'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "employee"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); auto jane = store.insert(new employee("jane")); auto insurance = store.insert(new department("insurance")); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); jane->dep(insurance); - UNIT_ASSERT_FALSE(insurance->employees.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->dep(), insurance, "objects must be equal"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->dep(), insurance); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); jane->dep(nullptr); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); insurance->employees.push_back(jane); - UNIT_ASSERT_FALSE(insurance->employees.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->dep(), insurance, "objects must be equal"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->dep(), insurance); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); insurance->employees.clear(); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); jane->dep(insurance); - UNIT_ASSERT_FALSE(insurance->employees.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->dep(), insurance, "objects must be equal"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->dep(), insurance); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); insurance->employees.remove(jane); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); } void RelationTestUnit::test_remove_belongs_to_many() @@ -514,62 +514,62 @@ void RelationTestUnit::test_remove_belongs_to_many() store.attach("department"); store.attach("employee"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("employee"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "department", "endpoint field name must be 'department'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "department"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); node = store.find(); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "employee", "endpoint field name must be 'employee'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "employee"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); auto jane = store.insert(new employee("jane")); auto george = store.insert(new employee("george")); auto insurance = store.insert(new department("insurance")); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "reference of insurance count must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "reference of jane count must be zero"); - UNIT_ASSERT_NULL(george->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(george.reference_count(), 0UL, "reference of george count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); + UNIT_ASSERT_NULL(george->dep().get()); + UNIT_ASSERT_EQUAL(george.reference_count(), 0UL); jane->dep(insurance); - UNIT_ASSERT_FALSE(insurance->employees.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "reference of insurance count must be one"); - UNIT_ASSERT_EQUAL(jane->dep(), insurance, "objects must be equal"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "reference of jane count must be zero"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(jane->dep(), insurance); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); store.remove(jane); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); george->dep(insurance); - UNIT_ASSERT_FALSE(insurance->employees.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(george->dep(), insurance, "objects must be equal"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(george->dep(), insurance); store.remove(insurance); - UNIT_ASSERT_NULL(george->dep().get(), "object must be null"); + UNIT_ASSERT_NULL(george->dep().get()); } void RelationTestUnit::test_belongs_to_many_first_belongs_to() @@ -580,84 +580,84 @@ void RelationTestUnit::test_belongs_to_many_first_belongs_to() store.attach("employee"); store.attach("department"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("employee"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "department", "endpoint field name must be 'department'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "department"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); node = store.find(); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "employee", "endpoint field name must be 'employee'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "employee"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); auto jane = store.insert(new employee("jane")); auto insurance = store.insert(new department("insurance")); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); jane->dep(insurance); - UNIT_ASSERT_FALSE(insurance->employees.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->dep(), insurance, "objects must be equal"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->dep(), insurance); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); jane->dep(nullptr); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); insurance->employees.push_back(jane); - UNIT_ASSERT_FALSE(insurance->employees.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->dep(), insurance, "objects must be equal"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->dep(), insurance); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); insurance->employees.clear(); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); jane->dep(insurance); - UNIT_ASSERT_FALSE(insurance->employees.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->dep(), insurance, "objects must be equal"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->dep(), insurance); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); insurance->employees.remove(jane); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); } void RelationTestUnit::test_insert_has_many_vector() @@ -667,59 +667,59 @@ void RelationTestUnit::test_insert_has_many_vector() store.attach("child"); store.attach("children_vector"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("children_vector"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "children", "endpoint field name must be 'children'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "children"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); node = store.find("children"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 2UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 2UL); endpoint = node->find_endpoint("child_id"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "must find endpoint"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "child_id", "endpoint field name must be 'child_id'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "child_id"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); endpoint = node->find_endpoint("vector_id"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "must find endpoint"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "vector_id", "endpoint field name must be 'vector_id'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE, "endpoint type must be HAS_ONE"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "vector_id"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE); auto tim_ptr = std::make_unique("tim"); auto group_ptr = std::make_unique("group"); - UNIT_ASSERT_TRUE(group_ptr->children.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(group_ptr->children.size(), 0UL, "vector size must be zero"); + UNIT_ASSERT_TRUE(group_ptr->children.empty()); + UNIT_ASSERT_EQUAL(group_ptr->children.size(), 0UL); group_ptr->children.push_back(tim_ptr.release()); - UNIT_ASSERT_FALSE(group_ptr->children.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(group_ptr->children.size(), 1UL, "vector size must be one"); + UNIT_ASSERT_FALSE(group_ptr->children.empty()); + UNIT_ASSERT_EQUAL(group_ptr->children.size(), 1UL); auto group = store.insert(group_ptr.release()); - UNIT_ASSERT_GREATER(group.id(), 0UL, "id must be greater zero"); - UNIT_ASSERT_FALSE(group->children.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(group->children.size(), 1UL, "vector size must be one"); + UNIT_ASSERT_GREATER(group.id(), 0UL); + UNIT_ASSERT_FALSE(group->children.empty()); + UNIT_ASSERT_EQUAL(group->children.size(), 1UL); auto tim = group->children.front(); - UNIT_ASSERT_EQUAL(tim.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_GREATER(tim.id(), 0UL, "object id must be valid"); + UNIT_ASSERT_EQUAL(tim.reference_count(), 1UL); + UNIT_ASSERT_GREATER(tim.id(), 0UL); group->children.clear(); - UNIT_ASSERT_EQUAL(tim.reference_count(), 0UL, "ref count must be one"); - UNIT_ASSERT_GREATER(tim.id(), 0UL, "object id must be valid"); + UNIT_ASSERT_EQUAL(tim.reference_count(), 0UL); + UNIT_ASSERT_GREATER(tim.id(), 0UL); try { store.remove(tim); @@ -727,14 +727,14 @@ void RelationTestUnit::test_insert_has_many_vector() UNIT_FAIL("couldn't remove tim " + std::string(ex.what())); } - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_TRUE(group->children.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(group->children.size(), 0UL, "vector size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_TRUE(group->children.empty()); + UNIT_ASSERT_EQUAL(group->children.size(), 0UL); store.remove(group); - UNIT_ASSERT_EQUAL(store.find()->size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(store.find("children")->size(), 0UL, "size must be zero"); + UNIT_ASSERT_EQUAL(store.find()->size(), 0UL); + UNIT_ASSERT_EQUAL(store.find("children")->size(), 0UL); } void RelationTestUnit::test_has_many_vector() @@ -744,67 +744,67 @@ void RelationTestUnit::test_has_many_vector() store.attach("child"); store.attach("children_vector"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("children_vector"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "children", "endpoint field name must be 'children'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "children"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); node = store.find("children"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 2UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 2UL); endpoint = node->find_endpoint("child_id"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "must find endpoint"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "child_id", "endpoint field name must be 'child_id'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "child_id"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); endpoint = node->find_endpoint("vector_id"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "must find endpoint"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "vector_id", "endpoint field name must be 'vector_id'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE, "endpoint type must be HAS_ONE"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "vector_id"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE); auto tim = store.insert(new child("tim")); auto group = store.insert(new children_vector("group")); - UNIT_ASSERT_TRUE(group->children.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(group.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(group->children.size(), 0UL, "vector size must be zero"); + UNIT_ASSERT_TRUE(group->children.empty()); + UNIT_ASSERT_EQUAL(group.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(group->children.size(), 0UL); group->children.push_back(tim); - UNIT_ASSERT_FALSE(group->children.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(group->children.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(group->children.front()->name, "tim", "name must be 'tim'"); - UNIT_ASSERT_EQUAL(tim.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(group->children.empty()); + UNIT_ASSERT_EQUAL(group->children.size(), 1UL); + UNIT_ASSERT_EQUAL(group->children.front()->name, "tim"); + UNIT_ASSERT_EQUAL(tim.reference_count(), 1UL); group->children.remove(tim); - UNIT_ASSERT_TRUE(group->children.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(group->children.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_GREATER(tim.id(), 0UL, "object id must be valid"); - UNIT_ASSERT_EQUAL(tim.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(group->children.empty()); + UNIT_ASSERT_EQUAL(group->children.size(), 0UL); + UNIT_ASSERT_GREATER(tim.id(), 0UL); + UNIT_ASSERT_EQUAL(tim.reference_count(), 0UL); group->children.push_back(tim); - UNIT_ASSERT_FALSE(group->children.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(group->children.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(group->children.front()->name, "tim", "name must be 'tim'"); - UNIT_ASSERT_EQUAL(tim.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(group->children.empty()); + UNIT_ASSERT_EQUAL(group->children.size(), 1UL); + UNIT_ASSERT_EQUAL(group->children.front()->name, "tim"); + UNIT_ASSERT_EQUAL(tim.reference_count(), 1UL); group->children.clear(); - UNIT_ASSERT_TRUE(group->children.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(group->children.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_GREATER(tim.id(), 0UL, "object id must be valid"); - UNIT_ASSERT_EQUAL(tim.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(group->children.empty()); + UNIT_ASSERT_EQUAL(group->children.size(), 0UL); + UNIT_ASSERT_GREATER(tim.id(), 0UL); + UNIT_ASSERT_EQUAL(tim.reference_count(), 0UL); } void RelationTestUnit::test_remove_has_many_vector() @@ -819,102 +819,102 @@ void RelationTestUnit::test_has_many_list() store.attach("child"); store.attach("children_list"); - UNIT_ASSERT_EQUAL(3UL, store.size(), "must be three nodes"); + UNIT_ASSERT_EQUAL(3UL, store.size()); auto node = store.find("children_list"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "children", "endpoint field name must be 'children'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "children"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); // auto foreign_endpoint = endpoint->second->foreign_endpoint.lock(); // -// UNIT_ASSERT_NOT_NULL(foreign_endpoint.get(), "foreign endpoint must be valid"); -// UNIT_ASSERT_EQUAL(foreign_endpoint->field, "list_id", "endpoint field name must be 'list_id'"); -// UNIT_ASSERT_EQUAL(foreign_endpoint->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); +// UNIT_ASSERT_NOT_NULL(foreign_endpoint.get()); +// UNIT_ASSERT_EQUAL(foreign_endpoint->field, "list_id"); +// UNIT_ASSERT_EQUAL(foreign_endpoint->type, matador::detail::basic_relation_endpoint::BELONGS_TO); node = store.find("children"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 2UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 2UL); endpoint = node->find_endpoint("child_id"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "must find endpoint"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "child_id", "endpoint field name must be 'child_id'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "child_id"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); endpoint = node->find_endpoint("list_id"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "must find endpoint"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "list_id", "endpoint field name must be 'list_id'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE, "endpoint type must be HAS_ONE"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "list_id"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE); auto tim = store.insert(new child("tim")); auto group = store.insert(new children_list("group")); - UNIT_ASSERT_TRUE(group->children.empty(), "list must be empty"); - UNIT_ASSERT_EQUAL(group.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(group->children.size(), 0UL, "list size must be zero"); - UNIT_ASSERT_EQUAL(tim.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(group->children.empty()); + UNIT_ASSERT_EQUAL(group.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(group->children.size(), 0UL); + UNIT_ASSERT_EQUAL(tim.reference_count(), 0UL); group->children.push_back(tim); - UNIT_ASSERT_FALSE(group->children.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(group->children.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(tim.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(group->children.front()->name, "tim", "name must be 'tim'"); + UNIT_ASSERT_FALSE(group->children.empty()); + UNIT_ASSERT_EQUAL(group->children.size(), 1UL); + UNIT_ASSERT_EQUAL(tim.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(group->children.front()->name, "tim"); } void RelationTestUnit::test_has_many_builtin() { - using many_vector_ints = many_builtins; + using local_many_vector_ints = many_builtins; // using many_vector_strings = many_builtins; matador::object_store store; - store.attach("many_vector_ints"); + store.attach("local_many_vector_ints"); - UNIT_ASSERT_EQUAL(2UL, store.size(), "must be two nodes"); + UNIT_ASSERT_EQUAL(2UL, store.size()); - auto node = store.find("many_vector_ints"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + auto node = store.find("local_many_vector_ints"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->find_endpoint("elements"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "must find endpoint"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "elements", "endpoint field name must be 'elements'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "elements"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); node = store.find("elements"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); endpoint = node->find_endpoint("list_id"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "must find endpoint"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "list_id", "endpoint field name must be 'list_id'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE, "endpoint type must be HAS_ONE"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "list_id"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_ONE); endpoint = node->find_endpoint("value"); - UNIT_ASSERT_TRUE(endpoint == node->endpoint_end(), "must not find endpoint 'value'"); + UNIT_ASSERT_TRUE(endpoint == node->endpoint_end()); - auto many_ints = store.insert(new many_vector_ints); + auto many_ints = store.insert(new local_many_vector_ints); - UNIT_ASSERT_TRUE(many_ints->elements.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(many_ints->elements.size(), 0UL, "vector size must be zero"); + UNIT_ASSERT_TRUE(many_ints->elements.empty()); + UNIT_ASSERT_EQUAL(many_ints->elements.size(), 0UL); many_ints->elements.push_back(7); - UNIT_ASSERT_FALSE(many_ints->elements.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(many_ints->elements.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(many_ints->elements.front(), 7, "values must be equal"); + UNIT_ASSERT_FALSE(many_ints->elements.empty()); + UNIT_ASSERT_EQUAL(many_ints->elements.size(), 1UL); + UNIT_ASSERT_EQUAL(many_ints->elements.front(), 7); } void RelationTestUnit::test_has_many_to_many() @@ -926,97 +926,97 @@ void RelationTestUnit::test_has_many_to_many() store.attach("student"); store.attach("course"); - UNIT_ASSERT_EQUAL(4UL, store.size(), "must be four nodes"); + UNIT_ASSERT_EQUAL(4UL, store.size()); auto node = store.find("student"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); auto endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "student_course", "endpoint field name must be 'student_course'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "student_course"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); node = store.find("student_course"); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 2UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 2UL); endpoint = node->find_endpoint("course_id"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "endpoint must be found"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "course_id", "endpoint field name must be 'course_id'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "course_id"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); endpoint = node->find_endpoint("student_id"); - UNIT_ASSERT_FALSE(endpoint == node->endpoint_end(), "endpoint must be found"); - UNIT_ASSERT_EQUAL(endpoint->second->field, "student_id", "endpoint field name must be 'student_id'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO, "endpoint type must be BELONGS_TO"); + UNIT_ASSERT_FALSE(endpoint == node->endpoint_end()); + UNIT_ASSERT_EQUAL(endpoint->second->field, "student_id"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::BELONGS_TO); node = store.find(); - UNIT_ASSERT_TRUE(node != store.end(), "must find a node"); - UNIT_ASSERT_FALSE(node->endpoints_empty(), "endpoints must not be empty"); - UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL, "endpoints must be one"); + UNIT_ASSERT_TRUE(node != store.end()); + UNIT_ASSERT_FALSE(node->endpoints_empty()); + UNIT_ASSERT_EQUAL(node->endpoints_size(), 1UL); endpoint = node->endpoint_begin(); - UNIT_ASSERT_EQUAL(endpoint->second->field, "student_course", "endpoint field name must be 'student_course'"); - UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY, "endpoint type must be HAS_MANY"); + UNIT_ASSERT_EQUAL(endpoint->second->field, "student_course"); + UNIT_ASSERT_EQUAL(endpoint->second->type, matador::detail::basic_relation_endpoint::HAS_MANY); auto jane = store.insert(new student("jane")); auto tom = store.insert(new student("tom")); auto art = store.insert(new course("art")); - UNIT_ASSERT_TRUE(jane->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_TRUE(tom->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(tom.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_TRUE(art->students.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(art.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(art->students.size(), 0UL, "vector size must be zero"); + UNIT_ASSERT_TRUE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL); + UNIT_ASSERT_TRUE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL); + UNIT_ASSERT_TRUE(art->students.empty()); + UNIT_ASSERT_EQUAL(art.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(art->students.size(), 0UL); jane->courses.push_back(art); - UNIT_ASSERT_FALSE(jane->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->courses.front(), art, "objects must be same"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(art->students.front(), jane, "objects must be same"); + UNIT_ASSERT_FALSE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->courses.front(), art); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); + UNIT_ASSERT_EQUAL(art->students.front(), jane); art->students.push_back(tom); - UNIT_ASSERT_FALSE(tom->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(tom.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(tom->courses.front(), art, "objects must be same"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art.reference_count(), 2UL, "ref count must be two"); - UNIT_ASSERT_EQUAL(art->students.size(), 2UL, "vector size must be two"); - UNIT_ASSERT_EQUAL(art->students.back(), tom, "objects must be same"); + UNIT_ASSERT_FALSE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(tom->courses.front(), art); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art.reference_count(), 2UL); + UNIT_ASSERT_EQUAL(art->students.size(), 2UL); + UNIT_ASSERT_EQUAL(art->students.back(), tom); art->students.remove(tom); - UNIT_ASSERT_TRUE(tom->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(tom.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.back(), jane, "objects must be same"); + UNIT_ASSERT_TRUE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); + UNIT_ASSERT_EQUAL(art->students.back(), jane); jane->courses.clear(); - UNIT_ASSERT_TRUE(jane->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_TRUE(art->students.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(art.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(art->students.size(), 0UL, "vector size must be zero"); + UNIT_ASSERT_TRUE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL); + UNIT_ASSERT_TRUE(art->students.empty()); + UNIT_ASSERT_EQUAL(art.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(art->students.size(), 0UL); } void RelationTestUnit::test_remove_has_many_object() @@ -1042,44 +1042,44 @@ void RelationTestUnit::test_remove_has_many_to_many() auto tom = store.insert(new student("tom")); auto art = store.insert(new course("art")); - UNIT_ASSERT_TRUE(jane->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_TRUE(tom->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(tom.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_TRUE(art->students.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); + UNIT_ASSERT_TRUE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL); + UNIT_ASSERT_EQUAL(tom.reference_count(), 0UL); + UNIT_ASSERT_TRUE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 0UL); + UNIT_ASSERT_EQUAL(art.reference_count(), 0UL); jane->courses.push_back(art); // jane (value) must be push_back to course art (owner) students!! - UNIT_ASSERT_FALSE(jane->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->courses.front(), art, "objects must be same"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.front(), jane, "objects must be same"); - UNIT_ASSERT_EQUAL(art.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->courses.front(), art); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); + UNIT_ASSERT_EQUAL(art->students.front(), jane); + UNIT_ASSERT_EQUAL(art.reference_count(), 1UL); art->students.push_back(tom); - UNIT_ASSERT_FALSE(tom->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(tom->courses.front(), art, "objects must be same"); - UNIT_ASSERT_EQUAL(tom.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 2UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.back(), tom, "objects must be same"); - UNIT_ASSERT_EQUAL(art.reference_count(), 2UL, "reference count must be 2"); + UNIT_ASSERT_FALSE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(tom->courses.front(), art); + UNIT_ASSERT_EQUAL(tom.reference_count(), 1UL); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 2UL); + UNIT_ASSERT_EQUAL(art->students.back(), tom); + UNIT_ASSERT_EQUAL(art.reference_count(), 2UL); store.remove(tom); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.back(), jane, "objects must be same"); - UNIT_ASSERT_EQUAL(art.reference_count(), 1UL, "reference count must be 1"); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); + UNIT_ASSERT_EQUAL(art->students.back(), jane); + UNIT_ASSERT_EQUAL(art.reference_count(), 1UL); } void RelationTestUnit::test_blog_single_post() @@ -1100,38 +1100,38 @@ void RelationTestUnit::test_blog_single_post() using t_post_view = matador::object_view; t_post_view posts(store); - UNIT_ASSERT_EQUAL(store.find("post_category")->size(), 1UL, "size must be one"); + UNIT_ASSERT_EQUAL(store.find("post_category")->size(), 1UL); auto hi = post1->categories.begin().holder_item(); - UNIT_ASSERT_EQUAL(hi.item_proxy()->reference_count(), 2UL, "ref count must be two"); + UNIT_ASSERT_EQUAL(hi.item_proxy()->reference_count(), 2UL); - UNIT_ASSERT_EQUAL(posts.size(), 1UL, "size must be three"); + UNIT_ASSERT_EQUAL(posts.size(), 1UL); - UNIT_ASSERT_EQUAL(post1.reference_count(), 2UL, "ref count must be one"); + UNIT_ASSERT_EQUAL(post1.reference_count(), 2UL); - UNIT_ASSERT_EQUAL(main.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(me->posts.size(), 1UL, "size must be one"); - UNIT_ASSERT_EQUAL(main->posts.size(), 1UL, "size must be one"); + UNIT_ASSERT_EQUAL(main.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(me->posts.size(), 1UL); + UNIT_ASSERT_EQUAL(main->posts.size(), 1UL); auto comment_one = store.insert(new comment("alfons@mail.fr", "cool stuff")); - UNIT_ASSERT_GREATER(comment_one.id(), 0UL, "id must be valid"); - UNIT_ASSERT_FALSE(comment_one->blog_post.valid(), "post must be invalid"); - UNIT_ASSERT_EQUAL(post1->comments.size(), 0UL, "size must be zero"); + UNIT_ASSERT_GREATER(comment_one.id(), 0UL); + UNIT_ASSERT_FALSE(comment_one->blog_post.valid()); + UNIT_ASSERT_EQUAL(post1->comments.size(), 0UL); post1->comments.push_back(comment_one); - UNIT_ASSERT_TRUE(comment_one->blog_post.valid(), "post must be valid"); - UNIT_ASSERT_EQUAL(post1->comments.size(), 1UL, "size must be one"); + UNIT_ASSERT_TRUE(comment_one->blog_post.valid()); + UNIT_ASSERT_EQUAL(post1->comments.size(), 1UL); store.remove(post1); - UNIT_ASSERT_EQUAL(posts.size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(me->posts.size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(me.reference_count(), 0UL, "ref count must be 0"); - UNIT_ASSERT_EQUAL(main->posts.size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(main.reference_count(), 0UL, "ref count must be 0"); + UNIT_ASSERT_EQUAL(posts.size(), 0UL); + UNIT_ASSERT_EQUAL(me->posts.size(), 0UL); + UNIT_ASSERT_EQUAL(me.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(main->posts.size(), 0UL); + UNIT_ASSERT_EQUAL(main.reference_count(), 0UL); } void RelationTestUnit::test_blog_multi_posts() @@ -1155,22 +1155,22 @@ void RelationTestUnit::test_blog_multi_posts() using t_post_view = matador::object_view; t_post_view posts(store); - UNIT_ASSERT_EQUAL(posts.size(), 4UL, "size must be three"); + UNIT_ASSERT_EQUAL(posts.size(), 4UL); - UNIT_ASSERT_EQUAL(post1.reference_count(), 2UL, "ref count must be 1"); - UNIT_ASSERT_EQUAL(post2.reference_count(), 2UL, "ref count must be 1"); - UNIT_ASSERT_EQUAL(post3.reference_count(), 2UL, "ref count must be 1"); - UNIT_ASSERT_EQUAL(post4.reference_count(), 2UL, "ref count must be 1"); + UNIT_ASSERT_EQUAL(post1.reference_count(), 2UL); + UNIT_ASSERT_EQUAL(post2.reference_count(), 2UL); + UNIT_ASSERT_EQUAL(post3.reference_count(), 2UL); + UNIT_ASSERT_EQUAL(post4.reference_count(), 2UL); - UNIT_ASSERT_EQUAL(main->posts.size(), 4UL, "size must be four"); - UNIT_ASSERT_EQUAL(main.reference_count(), 4UL, "ref count must be 4"); - UNIT_ASSERT_EQUAL(me->posts.size(), 4UL, "size must be four"); - UNIT_ASSERT_EQUAL(me.reference_count(), 4UL, "ref count must be 4"); + UNIT_ASSERT_EQUAL(main->posts.size(), 4UL); + UNIT_ASSERT_EQUAL(main.reference_count(), 4UL); + UNIT_ASSERT_EQUAL(me->posts.size(), 4UL); + UNIT_ASSERT_EQUAL(me.reference_count(), 4UL); store.remove(post3); - UNIT_ASSERT_EQUAL(main->posts.size(), 3UL, "size must be three"); - UNIT_ASSERT_EQUAL(main.reference_count(), 3UL, "ref count must be 3"); - UNIT_ASSERT_EQUAL(me->posts.size(), 3UL, "size must be three"); - UNIT_ASSERT_EQUAL(me.reference_count(), 3UL, "ref count must be 3"); + UNIT_ASSERT_EQUAL(main->posts.size(), 3UL); + UNIT_ASSERT_EQUAL(main.reference_count(), 3UL); + UNIT_ASSERT_EQUAL(me->posts.size(), 3UL); + UNIT_ASSERT_EQUAL(me.reference_count(), 3UL); } diff --git a/test/orm/BlogUnitTest.cpp b/test/orm/BlogUnitTest.cpp index f7bf65935..0494e777c 100644 --- a/test/orm/BlogUnitTest.cpp +++ b/test/orm/BlogUnitTest.cpp @@ -50,7 +50,7 @@ struct blog_service } } - bool add_comment(const std::string &email, std::string msg, const matador::object_ptr &pst) + bool add_comment(const std::string &email, std::string msg, matador::object_ptr pst) { auto tr = session_.begin(); try { @@ -69,9 +69,9 @@ struct blog_service matador::session &session_; }; -BlogUnitTest::BlogUnitTest(const std::string &prefix, const std::string &dns) +BlogUnitTest::BlogUnitTest(const std::string& prefix, std::string dns) : unit_test(prefix + "_blog", prefix + " blog unit tests") - , dns_(dns) + , dns_(std::move(dns)) { add_test("blog_single", std::bind(&BlogUnitTest::test_blog_single_post, this), "test single blog post"); add_test("blog_multiple", std::bind(&BlogUnitTest::test_blog_multiple_post, this), "test multiple blog post"); @@ -87,7 +87,7 @@ void BlogUnitTest::test_blog_single_post() p.attach("comment"); p.attach("post"); - UNIT_ASSERT_EQUAL(p.store().size(), 7UL, "there must be seven nodes in store"); + UNIT_ASSERT_EQUAL(p.store().size(), 7UL); p.create(); { @@ -114,24 +114,24 @@ void BlogUnitTest::test_blog_single_post() using t_post_view = matador::object_view; t_post_view posts(s.store()); - UNIT_ASSERT_EQUAL(posts.size(), 1UL, "size must be three"); + UNIT_ASSERT_EQUAL(posts.size(), 1UL); auto post1 = posts.front(); auto hi = post1->categories.begin().holder_item(); - UNIT_ASSERT_EQUAL(hi.item_proxy()->reference_count(), 2UL, "ref count must be two"); - UNIT_ASSERT_EQUAL(posts.size(), 1UL, "size must be three"); - UNIT_ASSERT_EQUAL(post1.reference_count(), 2UL, "ref count must be two"); - UNIT_ASSERT_EQUAL(me.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(main.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(me->posts.size(), 1UL, "size must be one"); - UNIT_ASSERT_EQUAL(main->posts.size(), 1UL, "size must be one"); + UNIT_ASSERT_EQUAL(hi.item_proxy()->reference_count(), 2UL); + UNIT_ASSERT_EQUAL(posts.size(), 1UL); + UNIT_ASSERT_EQUAL(post1.reference_count(), 2UL); + UNIT_ASSERT_EQUAL(me.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(main.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(me->posts.size(), 1UL); + UNIT_ASSERT_EQUAL(main->posts.size(), 1UL); blogger.add_comment("uli@mail.de", "cool stuff", post1); - UNIT_ASSERT_EQUAL(post1->comments.size(), 1UL, "size must be one"); - UNIT_ASSERT_EQUAL(post1.reference_count(), 3UL, "ref count must be two"); + UNIT_ASSERT_EQUAL(post1->comments.size(), 1UL); + UNIT_ASSERT_EQUAL(post1.reference_count(), 3UL); } p.clear(); @@ -151,23 +151,23 @@ void BlogUnitTest::test_blog_single_post() auto main = categories.front(); - UNIT_ASSERT_EQUAL(me->posts.size(), 1UL, "size must be one"); - UNIT_ASSERT_EQUAL(main->posts.size(), 1UL, "size must be one"); - UNIT_ASSERT_EQUAL(main.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(me.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_EQUAL(me->posts.size(), 1UL); + UNIT_ASSERT_EQUAL(main->posts.size(), 1UL); + UNIT_ASSERT_EQUAL(main.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(me.reference_count(), 1UL); using t_post_view = matador::object_view; t_post_view posts(s.store()); - UNIT_ASSERT_EQUAL(posts.size(), 1UL, "size must be three"); + UNIT_ASSERT_EQUAL(posts.size(), 1UL); auto post1 = posts.front(); auto hi = post1->categories.begin().holder_item(); - UNIT_ASSERT_EQUAL(hi.item_proxy()->reference_count(), 2UL, "ref count must be two"); - UNIT_ASSERT_EQUAL(posts.size(), 1UL, "size must be three"); - UNIT_ASSERT_EQUAL(post1.reference_count(), 3UL, "ref count must be two"); + UNIT_ASSERT_EQUAL(hi.item_proxy()->reference_count(), 2UL); + UNIT_ASSERT_EQUAL(posts.size(), 1UL); + UNIT_ASSERT_EQUAL(post1.reference_count(), 3UL); // delete post auto i = std::find_if(posts.begin(), posts.end(), [](const matador::object_ptr &p) { @@ -180,12 +180,12 @@ void BlogUnitTest::test_blog_single_post() blogger.remove(*i); } - UNIT_ASSERT_EQUAL(posts.size(), 0UL, "size must be one"); + UNIT_ASSERT_EQUAL(posts.size(), 0UL); - UNIT_ASSERT_EQUAL(me->posts.size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(main->posts.size(), 0UL, "size must be zero"); - UNIT_ASSERT_EQUAL(main.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(me.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_EQUAL(me->posts.size(), 0UL); + UNIT_ASSERT_EQUAL(main->posts.size(), 0UL); + UNIT_ASSERT_EQUAL(main.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(me.reference_count(), 0UL); } p.drop(); @@ -201,7 +201,7 @@ void BlogUnitTest::test_blog_multiple_post() p.attach("comment"); p.attach("post"); - UNIT_ASSERT_EQUAL(p.store().size(), 7UL, "there must be seven nodes in store"); + UNIT_ASSERT_EQUAL(p.store().size(), 7UL); p.create(); { matador::session s(p); @@ -226,15 +226,15 @@ void BlogUnitTest::test_blog_multiple_post() tr.rollback(); } - UNIT_ASSERT_EQUAL(me.reference_count(), 4UL, "ref count must be four"); - UNIT_ASSERT_EQUAL(main.reference_count(), 4UL, "ref count must be four"); - UNIT_ASSERT_EQUAL(me->posts.size(), 4UL, "size must be four"); - UNIT_ASSERT_EQUAL(main->posts.size(), 4UL, "size must be four"); + UNIT_ASSERT_EQUAL(me.reference_count(), 4UL); + UNIT_ASSERT_EQUAL(main.reference_count(), 4UL); + UNIT_ASSERT_EQUAL(me->posts.size(), 4UL); + UNIT_ASSERT_EQUAL(main->posts.size(), 4UL); using t_post_view = matador::object_view; t_post_view posts(s.store()); - UNIT_ASSERT_EQUAL(posts.size(), 4UL, "size must be three"); + UNIT_ASSERT_EQUAL(posts.size(), 4UL); } p.clear(); @@ -249,26 +249,26 @@ void BlogUnitTest::test_blog_multiple_post() using t_author_view = matador::object_view; t_author_view authors(s.store()); - UNIT_ASSERT_EQUAL(authors.size(), 1UL, "size must be one"); + UNIT_ASSERT_EQUAL(authors.size(), 1UL); auto me = authors.front(); using t_category_view = matador::object_view; t_category_view categories(s.store()); - UNIT_ASSERT_EQUAL(categories.size(), 1UL, "size must be one"); + UNIT_ASSERT_EQUAL(categories.size(), 1UL); auto main = categories.front(); - UNIT_ASSERT_EQUAL(me.reference_count(), 4UL, "ref count must be four"); - UNIT_ASSERT_EQUAL(main.reference_count(), 4UL, "ref count must be four"); - UNIT_ASSERT_EQUAL(me->posts.size(), 4UL, "size must be four"); - UNIT_ASSERT_EQUAL(main->posts.size(), 4UL, "size must be four"); + UNIT_ASSERT_EQUAL(me.reference_count(), 4UL); + UNIT_ASSERT_EQUAL(main.reference_count(), 4UL); + UNIT_ASSERT_EQUAL(me->posts.size(), 4UL); + UNIT_ASSERT_EQUAL(main->posts.size(), 4UL); using t_post_view = matador::object_view; t_post_view posts(s.store()); - UNIT_ASSERT_EQUAL(posts.size(), 4UL, "size must be three"); + UNIT_ASSERT_EQUAL(posts.size(), 4UL); // delete third post auto i = std::find_if(posts.begin(), posts.end(), [](const matador::object_ptr &p) { @@ -279,12 +279,12 @@ void BlogUnitTest::test_blog_multiple_post() blogger.remove(*i); } - UNIT_ASSERT_EQUAL(posts.size(), 3UL, "size must be three"); + UNIT_ASSERT_EQUAL(posts.size(), 3UL); - UNIT_ASSERT_EQUAL(me.reference_count(), 3UL, "ref count must be three"); - UNIT_ASSERT_EQUAL(main.reference_count(), 3UL, "ref count must be three"); - UNIT_ASSERT_EQUAL(me->posts.size(), 3UL, "size must be three"); - UNIT_ASSERT_EQUAL(main->posts.size(), 3UL, "size must be three"); + UNIT_ASSERT_EQUAL(me.reference_count(), 3UL); + UNIT_ASSERT_EQUAL(main.reference_count(), 3UL); + UNIT_ASSERT_EQUAL(me->posts.size(), 3UL); + UNIT_ASSERT_EQUAL(main->posts.size(), 3UL); } p.drop(); } diff --git a/test/orm/BlogUnitTest.hpp b/test/orm/BlogUnitTest.hpp index 7f5d261eb..1ca2f63b0 100644 --- a/test/orm/BlogUnitTest.hpp +++ b/test/orm/BlogUnitTest.hpp @@ -10,7 +10,7 @@ class BlogUnitTest : public matador::unit_test { public: - BlogUnitTest(const std::string &prefix, const std::string &dns); + BlogUnitTest(const std::string& prefix, std::string dns); ~BlogUnitTest() override = default; void test_blog_single_post(); diff --git a/test/orm/OrmRelationTestUnit.cpp b/test/orm/OrmRelationTestUnit.cpp index 00d877435..458791874 100644 --- a/test/orm/OrmRelationTestUnit.cpp +++ b/test/orm/OrmRelationTestUnit.cpp @@ -40,8 +40,8 @@ void OrmRelationTestUnit::test_has_builtin_varchars() auto varchars = s.insert(new many_list_varchars); - UNIT_ASSERT_GREATER(varchars->id, 0UL, "invalid varchars list"); - UNIT_ASSERT_TRUE(varchars->elements.empty(), "varchars list must be empty"); + UNIT_ASSERT_GREATER(varchars->id, 0UL); + UNIT_ASSERT_TRUE(varchars->elements.empty()); auto tr = s.begin(); @@ -54,8 +54,8 @@ void OrmRelationTestUnit::test_has_builtin_varchars() tr.rollback(); } - UNIT_ASSERT_FALSE(varchars->elements.empty(), "varchars list must not be empty"); - UNIT_ASSERT_EQUAL(varchars->elements.size(), 3UL, "invalid varchars list size"); + UNIT_ASSERT_FALSE(varchars->elements.empty()); + UNIT_ASSERT_EQUAL(varchars->elements.size(), 3UL); p.drop(); } @@ -74,16 +74,16 @@ void OrmRelationTestUnit::test_has_builtin_ints() auto ints = s.insert(new many_list_ints); - UNIT_ASSERT_GREATER(ints->id, 0UL, "invalid ints list"); - UNIT_ASSERT_TRUE(ints->elements.empty(), "ints list must be empty"); + UNIT_ASSERT_GREATER(ints->id, 0UL); + UNIT_ASSERT_TRUE(ints->elements.empty()); s.push_back(ints->elements, 37); s.push_back(ints->elements, 4711); s.push_back(ints->elements, -12345); s.push_back(ints->elements, 37); - UNIT_ASSERT_FALSE(ints->elements.empty(), "ints list must not be empty"); - UNIT_ASSERT_EQUAL(ints->elements.size(), 4UL, "invalid ints list size"); + UNIT_ASSERT_FALSE(ints->elements.empty()); + UNIT_ASSERT_EQUAL(ints->elements.size(), 4UL); p.drop(); } @@ -101,31 +101,31 @@ void OrmRelationTestUnit::test_has_many_delete() auto children = s.insert(new children_list("children list")); - UNIT_ASSERT_GREATER(children->id, 0UL, "invalid children list"); - UNIT_ASSERT_TRUE(children->children.empty(), "children list must be empty"); + UNIT_ASSERT_GREATER(children->id, 0UL); + UNIT_ASSERT_TRUE(children->children.empty()); auto kid1 = s.insert(new child("kid 1")); auto kid2 = s.insert(new child("kid 2")); - UNIT_ASSERT_GREATER(kid1->id, 0UL, "invalid child"); - UNIT_ASSERT_GREATER(kid2->id, 0UL, "invalid child"); + UNIT_ASSERT_GREATER(kid1->id, 0UL); + UNIT_ASSERT_GREATER(kid2->id, 0UL); s.push_back(children->children, kid1); s.push_back(children->children, kid1); s.push_back(children->children, kid2); - UNIT_ASSERT_FALSE(children->children.empty(), "children list couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 3UL, "invalid children list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 3UL); s.erase(children->children, children->children.begin()); - UNIT_ASSERT_FALSE(children->children.empty(), "children list couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); s.erase(children->children, children->children.begin(), children->children.end()); - UNIT_ASSERT_GREATER(children->id, 0UL, "invalid children list"); - UNIT_ASSERT_TRUE(children->children.empty(), "children list must be empty"); + UNIT_ASSERT_GREATER(children->id, 0UL); + UNIT_ASSERT_TRUE(children->children.empty()); p.drop(); } @@ -146,35 +146,35 @@ void OrmRelationTestUnit::test_belongs_to() auto jane = s.insert(new employee("jane")); auto dep = s.insert(new department("insurance")); - UNIT_ASSERT_TRUE(dep->employees.empty(), "there must be no employees"); - UNIT_ASSERT_TRUE(george->dep().empty(), "there must not be an department"); - UNIT_ASSERT_TRUE(jane->dep().empty(), "there must not be an department"); + UNIT_ASSERT_TRUE(dep->employees.empty()); + UNIT_ASSERT_TRUE(george->dep().empty()); + UNIT_ASSERT_TRUE(jane->dep().empty()); // department is automatically set s.push_back(dep->employees, george); - UNIT_ASSERT_EQUAL(dep->employees.size(), 1UL, "there must be one employee"); - UNIT_ASSERT_EQUAL(dep->employees.front()->name(), "george", "expected name must be george"); - UNIT_ASSERT_FALSE(george->dep().empty(), "department must not be empty"); - UNIT_ASSERT_EQUAL(george->dep()->name, dep->name, "names must be equal"); + UNIT_ASSERT_EQUAL(dep->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(dep->employees.front()->name(), "george"); + UNIT_ASSERT_FALSE(george->dep().empty()); + UNIT_ASSERT_EQUAL(george->dep()->name, dep->name); // jane is automatically added to deps employee list jane->dep(dep); s.update(jane); - UNIT_ASSERT_EQUAL(dep->employees.size(), 2UL, "there must be two employees"); + UNIT_ASSERT_EQUAL(dep->employees.size(), 2UL); // remove george s.erase(dep->employees, dep->employees.begin()); - UNIT_ASSERT_EQUAL(dep->employees.size(), 1UL, "there must be one employee"); - UNIT_ASSERT_TRUE(george->dep().empty(), "there must not be an department"); - UNIT_ASSERT_EQUAL(dep->employees.front()->name(), "jane", "expected name must be jane"); + UNIT_ASSERT_EQUAL(dep->employees.size(), 1UL); + UNIT_ASSERT_TRUE(george->dep().empty()); + UNIT_ASSERT_EQUAL(dep->employees.front()->name(), "jane"); // jane->department_.clear(); s.update(jane); // - UNIT_ASSERT_TRUE(dep->employees.empty(), "there must be no employees"); + UNIT_ASSERT_TRUE(dep->employees.empty()); p.drop(); } @@ -187,7 +187,7 @@ void OrmRelationTestUnit::test_many_to_many() p.attach("student"); p.attach("course"); - UNIT_ASSERT_EQUAL(4UL, p.store().size(), "unexpected size"); + UNIT_ASSERT_EQUAL(4UL, p.store().size()); p.create(); @@ -198,38 +198,38 @@ void OrmRelationTestUnit::test_many_to_many() auto algebra = s.insert(new course("algebra")); auto art = s.insert(new course("art")); - UNIT_ASSERT_TRUE(george->courses.empty(), "georges courses must be empty"); - UNIT_ASSERT_TRUE(jane->courses.empty(), "janes courses must be empty"); - UNIT_ASSERT_TRUE(algebra->students.empty(), "there must be no students in algebra"); - UNIT_ASSERT_TRUE(art->students.empty(), "there must be no students in art"); + UNIT_ASSERT_TRUE(george->courses.empty()); + UNIT_ASSERT_TRUE(jane->courses.empty()); + UNIT_ASSERT_TRUE(algebra->students.empty()); + UNIT_ASSERT_TRUE(art->students.empty()); s.push_back(art->students, jane); - UNIT_ASSERT_FALSE(art->students.empty(), "there must not be students in art"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "there must be one student in art course"); - UNIT_ASSERT_EQUAL(art->students.front()->name(), jane->name(), "arts student must be jane"); - UNIT_ASSERT_FALSE(jane->courses.empty(), "janes courses must not be empty"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL, "jane must've took one course"); - UNIT_ASSERT_EQUAL(jane->courses.front()->title, art->title, "janes course must be art"); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); + UNIT_ASSERT_EQUAL(art->students.front()->name(), jane->name()); + UNIT_ASSERT_FALSE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->courses.front()->title, art->title); s.erase(jane->courses, jane->courses.begin()); - UNIT_ASSERT_TRUE(jane->courses.empty(), "janes courses must be empty"); - UNIT_ASSERT_TRUE(art->students.empty(), "there must be no students in art"); + UNIT_ASSERT_TRUE(jane->courses.empty()); + UNIT_ASSERT_TRUE(art->students.empty()); s.push_back(george->courses, algebra); - UNIT_ASSERT_FALSE(algebra->students.empty(), "there must not be students in algebra"); - UNIT_ASSERT_EQUAL(algebra->students.size(), 1UL, "there must be one student in algebra course"); - UNIT_ASSERT_EQUAL(algebra->students.front()->name(), george->name(), "algebras student must be george"); - UNIT_ASSERT_FALSE(george->courses.empty(), "georges courses must not be empty"); - UNIT_ASSERT_EQUAL(george->courses.size(), 1UL, "george must've took one course"); - UNIT_ASSERT_EQUAL(george->courses.front()->title, algebra->title, "georges course must be algebra"); + UNIT_ASSERT_FALSE(algebra->students.empty()); + UNIT_ASSERT_EQUAL(algebra->students.size(), 1UL); + UNIT_ASSERT_EQUAL(algebra->students.front()->name(), george->name()); + UNIT_ASSERT_FALSE(george->courses.empty()); + UNIT_ASSERT_EQUAL(george->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(george->courses.front()->title, algebra->title); s.clear(algebra->students); - UNIT_ASSERT_TRUE(george->courses.empty(), "georges courses must be empty"); - UNIT_ASSERT_TRUE(algebra->students.empty(), "there must be no students in algebra"); + UNIT_ASSERT_TRUE(george->courses.empty()); + UNIT_ASSERT_TRUE(algebra->students.empty()); p.drop(); } diff --git a/test/orm/OrmReloadTestUnit.cpp b/test/orm/OrmReloadTestUnit.cpp index e825a2d0a..3c629377e 100644 --- a/test/orm/OrmReloadTestUnit.cpp +++ b/test/orm/OrmReloadTestUnit.cpp @@ -41,7 +41,7 @@ void OrmReloadTestUnit::test_load() for (const std::string &name : names) { auto pptr = s.insert(new person(name, matador::date(18, 5, 1980), 180)); - UNIT_EXPECT_GREATER(pptr->id(), 0UL, "is must be greater zero"); + UNIT_EXPECT_GREATER(pptr->id(), 0UL); } } @@ -56,8 +56,8 @@ void OrmReloadTestUnit::test_load() typedef matador::object_view t_person_view; t_person_view persons(s.store()); - UNIT_ASSERT_TRUE(!persons.empty(), "person view must not be empty"); - UNIT_ASSERT_EQUAL(persons.size(), 6UL, "thier must be 6 persons"); + UNIT_ASSERT_TRUE(!persons.empty()); + UNIT_ASSERT_EQUAL(persons.size(), 6UL); t_person_view::iterator first = persons.begin(); t_person_view::iterator last = persons.end(); @@ -68,7 +68,7 @@ void OrmReloadTestUnit::test_load() return name == pptr->name(); }), names.end()); } - UNIT_ASSERT_TRUE(names.empty(), "names must be empty"); + UNIT_ASSERT_TRUE(names.empty()); } p.drop(); @@ -91,7 +91,7 @@ void OrmReloadTestUnit::test_load_twice() for (const std::string &name : names) { auto pptr = s.insert(new person(name, matador::date(18, 5, 1980), 180)); - UNIT_EXPECT_GREATER(pptr->id(), 0UL, "is must be greater zero"); + UNIT_EXPECT_GREATER(pptr->id(), 0UL); } } @@ -106,8 +106,8 @@ void OrmReloadTestUnit::test_load_twice() typedef matador::object_view t_person_view; t_person_view persons(s.store()); - UNIT_ASSERT_TRUE(!persons.empty(), "person view must not be empty"); - UNIT_ASSERT_EQUAL(persons.size(), 6UL, "there must be 6 persons"); + UNIT_ASSERT_TRUE(!persons.empty()); + UNIT_ASSERT_EQUAL(persons.size(), 6UL); t_person_view::iterator first = persons.begin(); t_person_view::iterator last = persons.end(); @@ -118,7 +118,7 @@ void OrmReloadTestUnit::test_load_twice() return name == pptr->name(); }), names.end()); } - UNIT_ASSERT_TRUE(names.empty(), "names must be empty"); + UNIT_ASSERT_TRUE(names.empty()); } p.clear(); @@ -132,8 +132,8 @@ void OrmReloadTestUnit::test_load_twice() typedef matador::object_view t_person_view; t_person_view persons(s.store()); - UNIT_ASSERT_TRUE(!persons.empty(), "person view must not be empty"); - UNIT_ASSERT_EQUAL(persons.size(), 6UL, "there must be 6 persons"); + UNIT_ASSERT_TRUE(!persons.empty()); + UNIT_ASSERT_EQUAL(persons.size(), 6UL); t_person_view::iterator first = persons.begin(); t_person_view::iterator last = persons.end(); @@ -144,7 +144,7 @@ void OrmReloadTestUnit::test_load_twice() return name == pptr->name(); }), names.end()); } - UNIT_ASSERT_TRUE(names.empty(), "names must be empty"); + UNIT_ASSERT_TRUE(names.empty()); } p.drop(); @@ -179,22 +179,22 @@ void OrmReloadTestUnit::test_load_has_one() typedef matador::object_view t_master_view; t_master_view masters(s.store()); - UNIT_ASSERT_TRUE(!masters.empty(), "master view must not be empty"); - UNIT_ASSERT_EQUAL(masters.size(), 1UL, "their must be 1 master"); + UNIT_ASSERT_TRUE(!masters.empty()); + UNIT_ASSERT_EQUAL(masters.size(), 1UL); auto mptr = masters.front(); - UNIT_ASSERT_NOT_NULL(mptr->children.get(), "child must be valid"); + UNIT_ASSERT_NOT_NULL(mptr->children.get()); typedef matador::object_view t_child_view; t_child_view childview(s.store()); - UNIT_ASSERT_TRUE(!childview.empty(), "master view must not be empty"); - UNIT_ASSERT_EQUAL(childview.size(), 1UL, "their must be 1 master"); + UNIT_ASSERT_TRUE(!childview.empty()); + UNIT_ASSERT_EQUAL(childview.size(), 1UL); auto chptr = childview.front(); - UNIT_ASSERT_TRUE(chptr == mptr->children, "objects must be the same"); - UNIT_ASSERT_EQUAL(chptr.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_TRUE(chptr == mptr->children); + UNIT_ASSERT_EQUAL(chptr.reference_count(), 1UL); } p.drop(); @@ -214,20 +214,20 @@ void OrmReloadTestUnit::test_load_has_many() auto children = s.insert(new children_list("children list 1")); - UNIT_ASSERT_GREATER(children->id, 0UL, "invalid children list"); - UNIT_ASSERT_TRUE(children->children.empty(), "children list must be empty"); + UNIT_ASSERT_GREATER(children->id, 0UL); + UNIT_ASSERT_TRUE(children->children.empty()); auto kid1 = s.insert(new child("kid 1")); auto kid2 = s.insert(new child("kid 2")); - UNIT_ASSERT_GREATER(kid1->id, 0UL, "invalid child"); - UNIT_ASSERT_GREATER(kid2->id, 0UL, "invalid child"); + UNIT_ASSERT_GREATER(kid1->id, 0UL); + UNIT_ASSERT_GREATER(kid2->id, 0UL); s.push_back(children->children, kid1); s.push_back(children->children, kid2); - UNIT_ASSERT_FALSE(children->children.empty(), "children list couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); } p.clear(); @@ -240,19 +240,19 @@ void OrmReloadTestUnit::test_load_has_many() typedef matador::object_view t_children_list_view; t_children_list_view children_lists(s.store()); - UNIT_ASSERT_TRUE(!children_lists.empty(), "children lists view must not be empty"); - UNIT_ASSERT_EQUAL(children_lists.size(), 1UL, "their must be 1 children list"); + UNIT_ASSERT_TRUE(!children_lists.empty()); + UNIT_ASSERT_EQUAL(children_lists.size(), 1UL); auto clptr = children_lists.front(); - UNIT_ASSERT_FALSE(clptr->children.empty(), "children list couldn't be empty"); - UNIT_ASSERT_EQUAL(clptr->children.size(), 2UL, "invalid children list size"); + UNIT_ASSERT_FALSE(clptr->children.empty()); + UNIT_ASSERT_EQUAL(clptr->children.size(), 2UL); std::vector result_names({ "kid 1", "kid 2"}); for (auto kid : clptr->children) { auto it = std::find(result_names.begin(), result_names.end(), kid->name); - UNIT_EXPECT_FALSE(it == result_names.end(), "kid must be found"); - UNIT_ASSERT_EQUAL(kid.reference_count(), 1UL, "ref count must be one"); + UNIT_EXPECT_FALSE(it == result_names.end()); + UNIT_ASSERT_EQUAL(kid.reference_count(), 1UL); } } @@ -276,30 +276,30 @@ void OrmReloadTestUnit::test_load_has_many_to_many() auto tom = s.insert(new student("tom")); auto art = s.insert(new course("art")); - UNIT_ASSERT_TRUE(jane->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_TRUE(tom->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_TRUE(art->students.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 0UL, "vector size must be zero"); + UNIT_ASSERT_TRUE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL); + UNIT_ASSERT_TRUE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL); + UNIT_ASSERT_TRUE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 0UL); s.push_back(jane->courses, art); // jane (value) must be push_back to course art (owner) students!! - UNIT_ASSERT_FALSE(jane->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->courses.front(), art, "objects must be same"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.front(), jane, "objects must be same"); + UNIT_ASSERT_FALSE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->courses.front(), art); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); + UNIT_ASSERT_EQUAL(art->students.front(), jane); s.push_back(art->students, tom); - UNIT_ASSERT_FALSE(tom->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(tom->courses.front(), art, "objects must be same"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 2UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.back(), tom, "objects must be same"); + UNIT_ASSERT_FALSE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(tom->courses.front(), art); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 2UL); + UNIT_ASSERT_EQUAL(art->students.back(), tom); } p.clear(); @@ -312,30 +312,30 @@ void OrmReloadTestUnit::test_load_has_many_to_many() typedef matador::object_view t_student_view; t_student_view student_view(s.store()); - UNIT_ASSERT_TRUE(!student_view.empty(), "student view must not be empty"); - UNIT_ASSERT_EQUAL(student_view.size(), 2UL, "their must be 2 student in list"); + UNIT_ASSERT_TRUE(!student_view.empty()); + UNIT_ASSERT_EQUAL(student_view.size(), 2UL); typedef matador::object_view t_course_view; t_course_view course_view(s.store()); - UNIT_ASSERT_TRUE(!course_view.empty(), "course view must not be empty"); - UNIT_ASSERT_EQUAL(course_view.size(), 1UL, "their must be 1 course in list"); + UNIT_ASSERT_TRUE(!course_view.empty()); + UNIT_ASSERT_EQUAL(course_view.size(), 1UL); for (const auto &stdnt : student_view) { - UNIT_ASSERT_FALSE(stdnt->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(stdnt->courses.size(), 1UL, "vector size must be one"); + UNIT_ASSERT_FALSE(stdnt->courses.empty()); + UNIT_ASSERT_EQUAL(stdnt->courses.size(), 1UL); } auto art = course_view.front(); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 2UL, "vector size must be two"); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 2UL); auto stud = student_view.front(); s.remove(art->students, stud); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be two"); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); } p.drop(); @@ -358,47 +358,47 @@ void OrmReloadTestUnit::test_load_has_many_to_many_remove() auto tom = s.insert(new student("tom")); auto art = s.insert(new course("art")); - UNIT_ASSERT_TRUE(jane->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_TRUE(tom->courses.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_TRUE(art->students.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 0UL, "vector size must be zero"); + UNIT_ASSERT_TRUE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane->courses.size(), 0UL); + UNIT_ASSERT_TRUE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL); + UNIT_ASSERT_TRUE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 0UL); s.push_back(jane->courses, art); // jane (value) must be push_back to course art (owner) students!! - UNIT_ASSERT_FALSE(jane->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(jane->courses.front(), art, "objects must be same"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.front(), jane, "objects must be same"); + UNIT_ASSERT_FALSE(jane->courses.empty()); + UNIT_ASSERT_EQUAL(jane->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->courses.front(), art); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); + UNIT_ASSERT_EQUAL(art->students.front(), jane); s.push_back(art->students, tom); - UNIT_ASSERT_FALSE(tom->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(tom->courses.front(), art, "objects must be same"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 2UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.back(), tom, "objects must be same"); + UNIT_ASSERT_FALSE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(tom->courses.front(), art); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 2UL); + UNIT_ASSERT_EQUAL(art->students.back(), tom); s.remove(art->students, tom); - UNIT_ASSERT_TRUE(tom->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL, "vector size must be one"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.back(), jane, "objects must be same"); + UNIT_ASSERT_TRUE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom->courses.size(), 0UL); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); + UNIT_ASSERT_EQUAL(art->students.back(), jane); s.push_back(art->students, tom); - UNIT_ASSERT_FALSE(tom->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL, "vector size must be one"); - UNIT_ASSERT_EQUAL(tom->courses.front(), art, "objects must be same"); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 2UL, "vector size must be zero"); - UNIT_ASSERT_EQUAL(art->students.back(), tom, "objects must be same"); + UNIT_ASSERT_FALSE(tom->courses.empty()); + UNIT_ASSERT_EQUAL(tom->courses.size(), 1UL); + UNIT_ASSERT_EQUAL(tom->courses.front(), art); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 2UL); + UNIT_ASSERT_EQUAL(art->students.back(), tom); } p.clear(); @@ -411,30 +411,30 @@ void OrmReloadTestUnit::test_load_has_many_to_many_remove() typedef matador::object_view t_student_view; t_student_view student_view(s.store()); - UNIT_ASSERT_TRUE(!student_view.empty(), "student view must not be empty"); - UNIT_ASSERT_EQUAL(student_view.size(), 2UL, "their must be 2 student in list"); + UNIT_ASSERT_TRUE(!student_view.empty()); + UNIT_ASSERT_EQUAL(student_view.size(), 2UL); typedef matador::object_view t_course_view; t_course_view course_view(s.store()); - UNIT_ASSERT_TRUE(!course_view.empty(), "course view must not be empty"); - UNIT_ASSERT_EQUAL(course_view.size(), 1UL, "their must be 1 course in list"); + UNIT_ASSERT_TRUE(!course_view.empty()); + UNIT_ASSERT_EQUAL(course_view.size(), 1UL); for (const auto &stdnt : student_view) { - UNIT_ASSERT_FALSE(stdnt->courses.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(stdnt->courses.size(), 1UL, "vector size must be one"); + UNIT_ASSERT_FALSE(stdnt->courses.empty()); + UNIT_ASSERT_EQUAL(stdnt->courses.size(), 1UL); } auto art = course_view.front(); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 2UL, "vector size must be two"); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 2UL); auto stud = student_view.front(); s.remove(art->students, stud); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be two"); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); } p.clear(); @@ -447,18 +447,18 @@ void OrmReloadTestUnit::test_load_has_many_to_many_remove() typedef matador::object_view t_student_view; t_student_view student_view(s.store()); - UNIT_ASSERT_TRUE(!student_view.empty(), "student view must not be empty"); - UNIT_ASSERT_EQUAL(student_view.size(), 2UL, "their must be 2 student in list"); + UNIT_ASSERT_TRUE(!student_view.empty()); + UNIT_ASSERT_EQUAL(student_view.size(), 2UL); typedef matador::object_view t_course_view; t_course_view course_view(s.store()); - UNIT_ASSERT_TRUE(!course_view.empty(), "course view must not be empty"); - UNIT_ASSERT_EQUAL(course_view.size(), 1UL, "their must be 1 course in list"); + UNIT_ASSERT_TRUE(!course_view.empty()); + UNIT_ASSERT_EQUAL(course_view.size(), 1UL); auto art = course_view.front(); - UNIT_ASSERT_FALSE(art->students.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(art->students.size(), 1UL, "vector size must be one"); + UNIT_ASSERT_FALSE(art->students.empty()); + UNIT_ASSERT_EQUAL(art->students.size(), 1UL); } p.drop(); @@ -477,20 +477,20 @@ void OrmReloadTestUnit::test_load_has_many_int() auto intlist = s.insert(new many_ints); - UNIT_ASSERT_GREATER(intlist->id, 0UL, "invalid intlist list"); - UNIT_ASSERT_TRUE(intlist->elements.empty(), "intlist list must be empty"); + UNIT_ASSERT_GREATER(intlist->id, 0UL); + UNIT_ASSERT_TRUE(intlist->elements.empty()); s.push_back(intlist->elements, 4); - UNIT_ASSERT_EQUAL(intlist->elements.front(), 4, "first int must be 4"); - UNIT_ASSERT_EQUAL(intlist->elements.back(), 4, "last int must be 4"); + UNIT_ASSERT_EQUAL(intlist->elements.front(), 4); + UNIT_ASSERT_EQUAL(intlist->elements.back(), 4); s.push_front(intlist->elements, 7); - UNIT_ASSERT_EQUAL(intlist->elements.front(), 7, "first int must be 7"); + UNIT_ASSERT_EQUAL(intlist->elements.front(), 7); - UNIT_ASSERT_FALSE(intlist->elements.empty(), "intlist list couldn't be empty"); - UNIT_ASSERT_EQUAL(intlist->elements.size(), 2UL, "invalid intlist list size"); + UNIT_ASSERT_FALSE(intlist->elements.empty()); + UNIT_ASSERT_EQUAL(intlist->elements.size(), 2UL); } p.clear(); @@ -503,18 +503,18 @@ void OrmReloadTestUnit::test_load_has_many_int() typedef matador::object_view t_many_ints_view; t_many_ints_view ints_view(s.store()); - UNIT_ASSERT_TRUE(!ints_view.empty(), "many ints view must not be empty"); - UNIT_ASSERT_EQUAL(ints_view.size(), 1UL, "their must be 1 int in many ints list"); + UNIT_ASSERT_TRUE(!ints_view.empty()); + UNIT_ASSERT_EQUAL(ints_view.size(), 1UL); auto intlist = ints_view.front(); - UNIT_ASSERT_FALSE(intlist->elements.empty(), "intlist list couldn't be empty"); - UNIT_ASSERT_EQUAL(intlist->elements.size(), 2UL, "invalid intlist list size"); + UNIT_ASSERT_FALSE(intlist->elements.empty()); + UNIT_ASSERT_EQUAL(intlist->elements.size(), 2UL); std::vector result_ints({ 4, 7 }); for (auto i : intlist->elements) { auto it = std::find(result_ints.begin(), result_ints.end(), i); - UNIT_EXPECT_FALSE(it == result_ints.end(), "int must be found"); + UNIT_EXPECT_FALSE(it == result_ints.end()); } } @@ -538,11 +538,11 @@ void OrmReloadTestUnit::test_load_belongs_to_many() auto jane = s.insert(new employee("jane")); auto insurance = s.insert(new department("insurance")); - UNIT_ASSERT_TRUE(insurance->employees.empty(), "vector must be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL, "ref count must be zero"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL, "vector size must be zero"); - UNIT_ASSERT_NULL(jane->dep().get(), "object must be null"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL, "ref count must be zero"); + UNIT_ASSERT_TRUE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 0UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 0UL); + UNIT_ASSERT_NULL(jane->dep().get()); + UNIT_ASSERT_EQUAL(jane.reference_count(), 0UL); auto tr = s.begin(); try { @@ -553,11 +553,11 @@ void OrmReloadTestUnit::test_load_belongs_to_many() UNIT_FAIL(ex.what()); } - UNIT_ASSERT_FALSE(insurance->employees.empty(), "vector must not be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "employees size must be one"); - UNIT_ASSERT_EQUAL(jane->dep(), insurance, "objects must be equal"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(jane->dep(), insurance); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); } p.clear(); @@ -571,26 +571,26 @@ void OrmReloadTestUnit::test_load_belongs_to_many() typedef matador::object_view t_employee_view; t_employee_view employees(s.store()); - UNIT_ASSERT_TRUE(!employees.empty(), "employees view must not be empty"); - UNIT_ASSERT_EQUAL(employees.size(), 1UL, "their must be 1 employee in employees"); + UNIT_ASSERT_TRUE(!employees.empty()); + UNIT_ASSERT_EQUAL(employees.size(), 1UL); auto jane = employees.front(); - UNIT_ASSERT_TRUE(jane->dep() != nullptr, "department must not be empty"); - UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL, "ref count must be one"); + UNIT_ASSERT_TRUE(jane->dep() != nullptr); + UNIT_ASSERT_EQUAL(jane.reference_count(), 1UL); typedef matador::object_view t_department_view; t_department_view departments(s.store()); - UNIT_ASSERT_TRUE(!departments.empty(), "departments view must not be empty"); - UNIT_ASSERT_EQUAL(departments.size(), 1UL, "their must be 1 department in departments"); + UNIT_ASSERT_TRUE(!departments.empty()); + UNIT_ASSERT_EQUAL(departments.size(), 1UL); auto insurance = departments.front(); - UNIT_ASSERT_FALSE(insurance->employees.empty(), "departments employees must not be empty"); - UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL, "ref count must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL, "employees size must be one"); - UNIT_ASSERT_EQUAL(insurance->employees.front(), jane, "employees must be equal"); + UNIT_ASSERT_FALSE(insurance->employees.empty()); + UNIT_ASSERT_EQUAL(insurance.reference_count(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.size(), 1UL); + UNIT_ASSERT_EQUAL(insurance->employees.front(), jane); } p.drop(); diff --git a/test/orm/OrmTestUnit.cpp b/test/orm/OrmTestUnit.cpp index 6916cb0d8..380be4471 100644 --- a/test/orm/OrmTestUnit.cpp +++ b/test/orm/OrmTestUnit.cpp @@ -15,9 +15,9 @@ using namespace hasmanylist; -OrmTestUnit::OrmTestUnit(const std::string &prefix, const std::string &dns) +OrmTestUnit::OrmTestUnit(const std::string &prefix, std::string dns) : unit_test(prefix + "_orm", prefix + " orm test unit") - , dns_(dns) + , dns_(std::move(dns)) { add_test("create", std::bind(&OrmTestUnit::test_create, this), "test create table"); add_test("insert", std::bind(&OrmTestUnit::test_insert, this), "test insert into table"); @@ -35,12 +35,12 @@ void OrmTestUnit::test_create() p.create(); // check if table exists - UNIT_EXPECT_TRUE(p.exists(), "table must exist"); + UNIT_EXPECT_TRUE(p.exists()); p.drop(); // check if table exists - UNIT_EXPECT_FALSE(p.exists(), "table must not exist"); + UNIT_EXPECT_FALSE(p.exists()); } void OrmTestUnit::test_insert() @@ -55,18 +55,18 @@ void OrmTestUnit::test_insert() auto hans = s.insert(new person("hans", matador::date(18, 5, 1980), 180)); - UNIT_EXPECT_GREATER(hans->id(), 0UL, "is must be greater zero"); + UNIT_EXPECT_GREATER(hans->id(), 0UL); matador::query q("person"); auto res = q.select().where(matador::column("name") == "hans").execute(p.conn()); auto first = res.begin(); - UNIT_ASSERT_TRUE(first != res.end(), "first must not end"); + UNIT_ASSERT_TRUE(first != res.end()); std::unique_ptr p1(first.release()); - UNIT_EXPECT_EQUAL("hans", p1->name(), "invalid name"); + UNIT_EXPECT_EQUAL("hans", p1->name()); // Todo: fix open cursor with Free TDS ++first; @@ -93,17 +93,17 @@ void OrmTestUnit::test_select() std::vector names({ "hans", "otto", "georg", "hilde" }); //std::vector names({ "hans", "otto", "georg", "hilde", "ute", "manfred" }); - for (std::string name : names) { + for (auto const &name : names) { auto pptr = s.insert(new person(name, matador::date(18, 5, 1980), 180)); - UNIT_EXPECT_GREATER(pptr->id(), 0UL, "is must be greater zero"); + UNIT_EXPECT_GREATER(pptr->id(), 0UL); } auto view = s.select(); - UNIT_ASSERT_EQUAL(view.size(), names.size(), "unexpected size"); + UNIT_ASSERT_EQUAL(view.size(), names.size()); for (auto optr : view) { - UNIT_ASSERT_TRUE(contains(names, optr->name()), "unknown name from view"); + UNIT_ASSERT_TRUE(contains(names, optr->name())); } p.drop(); @@ -122,15 +122,15 @@ void OrmTestUnit::test_update() matador::date birthday(18, 5, 1980); auto hans = s.insert(new person("hans", birthday, 180)); - UNIT_EXPECT_GREATER(hans->id(), 0UL, "id must be greater zero"); - UNIT_EXPECT_EQUAL(hans->height(), 180U, "height must be 180"); - UNIT_EXPECT_EQUAL(hans->birthdate(), birthday, "birthday must be equal"); + UNIT_EXPECT_GREATER(hans->id(), 0UL); + UNIT_EXPECT_EQUAL(hans->height(), 180U); + UNIT_EXPECT_EQUAL(hans->birthdate(), birthday); hans->height(179); hans = s.update(hans); - UNIT_EXPECT_EQUAL(hans->height(), 179U, "height must be 179"); + UNIT_EXPECT_EQUAL(hans->height(), 179U); matador::query q("person"); matador::connection c(dns_); @@ -139,13 +139,13 @@ void OrmTestUnit::test_update() auto first = res.begin(); - UNIT_ASSERT_TRUE(first != res.end(), "first must not end"); + UNIT_ASSERT_TRUE(first != res.end()); std::unique_ptr p1(first.release()); - UNIT_EXPECT_EQUAL("hans", p1->name(), "invalid name"); - UNIT_EXPECT_EQUAL(179U, p1->height(), "height must be 179"); - UNIT_EXPECT_EQUAL(hans->birthdate(), birthday, "birthday must be equal"); + UNIT_EXPECT_EQUAL("hans", p1->name()); + UNIT_EXPECT_EQUAL(179U, p1->height()); + UNIT_EXPECT_EQUAL(hans->birthdate(), birthday); p.drop(); } @@ -162,7 +162,7 @@ void OrmTestUnit::test_delete() auto hans = s.insert(new person("hans", matador::date(18, 5, 1980), 180)); - UNIT_EXPECT_GREATER(hans->id(), 0UL, "is must be greater zero"); + UNIT_EXPECT_GREATER(hans->id(), 0UL); matador::query q("person"); matador::connection c(dns_); @@ -171,11 +171,11 @@ void OrmTestUnit::test_delete() auto first = res.begin(); - UNIT_ASSERT_TRUE(first != res.end(), "first must not end"); + UNIT_ASSERT_TRUE(first != res.end()); std::unique_ptr p1((first++).release()); - UNIT_EXPECT_EQUAL("hans", p1->name(), "invalid name"); + UNIT_EXPECT_EQUAL("hans", p1->name()); s.remove(hans); @@ -183,8 +183,8 @@ void OrmTestUnit::test_delete() first = res.begin(); - UNIT_EXPECT_TRUE(first == res.end(), "first must be end"); -// UNIT_EXPECT_TRUE(res.empty(), "result set must be empty"); + UNIT_EXPECT_TRUE(first == res.end()); +// UNIT_EXPECT_TRUE(res.empty()); p.drop(); } diff --git a/test/orm/OrmTestUnit.hpp b/test/orm/OrmTestUnit.hpp index 12363fb5d..970c61656 100644 --- a/test/orm/OrmTestUnit.hpp +++ b/test/orm/OrmTestUnit.hpp @@ -10,7 +10,7 @@ class OrmTestUnit : public matador::unit_test { public: - OrmTestUnit(const std::string &prefix, const std::string &dns); + OrmTestUnit(const std::string &prefix, std::string dns); void test_create(); void test_insert(); diff --git a/test/orm/TransactionTestUnit.cpp b/test/orm/TransactionTestUnit.cpp index f6bce4657..2aa7b51a1 100644 --- a/test/orm/TransactionTestUnit.cpp +++ b/test/orm/TransactionTestUnit.cpp @@ -13,9 +13,9 @@ using namespace matador; -TransactionTestUnit::TransactionTestUnit(const std::string &name, const std::string &msg, std::string const &dns) +TransactionTestUnit::TransactionTestUnit(const std::string &name, const std::string &msg, std::string dns) : unit_test(name, msg) - , dns_(dns) + , dns_(std::move(dns)) { add_test("simple", std::bind(&TransactionTestUnit::test_simple, this), "simple transaction test"); add_test("nested", std::bind(&TransactionTestUnit::test_nested, this), "nested transaction test"); @@ -28,8 +28,6 @@ TransactionTestUnit::TransactionTestUnit(const std::string &name, const std::str } -TransactionTestUnit::~TransactionTestUnit() {} - void TransactionTestUnit::test_simple() { matador::persistence p(dns_); @@ -47,21 +45,21 @@ void TransactionTestUnit::test_simple() auto hans = s.insert(new person("hans", d1, 180)); tr.commit(); - } catch (sql_exception &) { + } catch (sql_exception &ex) { tr.rollback(); - UNIT_FAIL("transaction failed"); + UNIT_FAIL("transaction failed: " << ex.what()); } matador::object_view persons(s.store()); // matador::object_view persons = s.create_view(); - UNIT_ASSERT_EQUAL(1UL, persons.size(), "size must be one"); + UNIT_ASSERT_EQUAL(1UL, persons.size()); auto hans2 = persons.front(); - UNIT_ASSERT_EQUAL("hans", hans2->name(), "name must be 'hans'"); - UNIT_ASSERT_EQUAL(d1, hans2->birthdate(), "birthdate must be " + matador::to_string(d1)); - UNIT_ASSERT_EQUAL(180U, hans2->height(), "height must be 180"); + UNIT_ASSERT_EQUAL("hans", hans2->name()); + UNIT_ASSERT_EQUAL(d1, hans2->birthdate()); + UNIT_ASSERT_EQUAL(180U, hans2->height()); p.drop(); } @@ -85,13 +83,13 @@ void TransactionTestUnit::test_nested() typedef object_view item_view; // insert new serializable item_ptr item = s.store().insert(new Item("Hello World", 70)); - UNIT_ASSERT_GREATER(item->id(), 0UL, "item has invalid serializable id"); + UNIT_ASSERT_GREATER(item->id(), 0UL); tr.commit(); tr.begin(); // modify serializable item->set_int(120); - UNIT_ASSERT_EQUAL(item->get_int(), 120, "item has invalid int value"); + UNIT_ASSERT_EQUAL(item->get_int(), 120); // begin inner transaction @@ -100,22 +98,22 @@ void TransactionTestUnit::test_nested() // change name again item->set_int(170); - UNIT_ASSERT_EQUAL(item->get_int(), 170, "item has invalid int value"); + UNIT_ASSERT_EQUAL(item->get_int(), 170); // rollback transaction tr2.rollback(); - UNIT_ASSERT_EQUAL(item->get_int(), 120, "item has invalid int value"); + UNIT_ASSERT_EQUAL(item->get_int(), 120); } catch (std::exception &ex) { UNIT_WARN("transaction [" << tr2.id() << "] rolled back: " << ex.what()); tr2.rollback(); } tr.rollback(); - UNIT_ASSERT_EQUAL(item->get_int(), 70, "item has invalid int value"); + UNIT_ASSERT_EQUAL(item->get_int(), 70); tr.begin(); // delete serializable - UNIT_ASSERT_TRUE(s.store().is_removable(item), "couldn't delete item"); + UNIT_ASSERT_TRUE(s.store().is_removable(item)); s.store().remove(item); @@ -123,23 +121,23 @@ void TransactionTestUnit::test_nested() item_view view(s.store()); - UNIT_ASSERT_FALSE(view.empty(), "item view is empty"); - UNIT_ASSERT_EQUAL((int)view.size(), 1, "more than one item in view"); + UNIT_ASSERT_FALSE(view.empty()); + UNIT_ASSERT_EQUAL((int)view.size(), 1); item = view.front(); - UNIT_ASSERT_EQUAL(item->get_string(), "Hello World", "invalid item name"); - UNIT_ASSERT_EQUAL(item->get_int(), 70, "invalid item int value"); + UNIT_ASSERT_EQUAL(item->get_string(), "Hello World"); + UNIT_ASSERT_EQUAL(item->get_int(), 70); tr.begin(); - UNIT_ASSERT_TRUE(s.store().is_removable(item), "couldn't delete item"); + UNIT_ASSERT_TRUE(s.store().is_removable(item)); s.store().remove(item); tr.commit(); - UNIT_ASSERT_TRUE(view.empty(), "item view is empty"); + UNIT_ASSERT_TRUE(view.empty()); } catch (sql_exception &ex) { // error, abort transaction UNIT_WARN("transaction [" << tr.id() << "] rolled back: " << ex.what()); @@ -185,38 +183,38 @@ void TransactionTestUnit::test_foreign() object_item_ptr object_item = s.insert(new object_item_t("Foo", 42)); object_item->ptr(item); - UNIT_ASSERT_GREATER(object_item->id(), 0UL, "invalid serializable item"); + UNIT_ASSERT_GREATER(object_item->id(), 0UL); item = object_item->ptr(); - UNIT_ASSERT_GREATER(item->id(), 0UL, "invalid item"); + UNIT_ASSERT_GREATER(item->id(), 0UL); item->set_int(120); item->set_string("Bar"); - UNIT_ASSERT_EQUAL(item->get_int(), 120, "invalid item int value"); - //UNIT_ASSERT_EQUAL(item->get_string(), "Bar", "invalid item string value"); + UNIT_ASSERT_EQUAL(item->get_int(), 120); + //UNIT_ASSERT_EQUAL(item->get_string(), "Bar"); tr.commit(); - UNIT_ASSERT_EQUAL(item->get_int(), 120, "invalid item int value"); - //UNIT_ASSERT_EQUAL(item->get_string(), "Bar", "invalid item string value"); + UNIT_ASSERT_EQUAL(item->get_int(), 120); + //UNIT_ASSERT_EQUAL(item->get_string(), "Bar"); tr.begin(); object_view oview(s.store()); - UNIT_ASSERT_FALSE(oview.empty(), "serializable item view couldn't be empty"); + UNIT_ASSERT_FALSE(oview.empty()); - UNIT_ASSERT_TRUE(s.store().is_removable(object_item), "couldn't remove serializable item"); + UNIT_ASSERT_TRUE(s.store().is_removable(object_item)); s.store().remove(object_item); - UNIT_ASSERT_TRUE(oview.empty(), "serializable item view must be empty"); + UNIT_ASSERT_TRUE(oview.empty()); tr.rollback(); - UNIT_ASSERT_FALSE(oview.empty(), "serializable item view couldn't be empty"); + UNIT_ASSERT_FALSE(oview.empty()); } catch (sql_exception &ex) { // error, abort transaction @@ -246,8 +244,8 @@ void TransactionTestUnit::test_has_many_list_commit() try { auto children = s.insert(new children_list("children list")); - UNIT_ASSERT_GREATER(children->id, 0UL, "invalid children list"); - UNIT_ASSERT_TRUE(children->children.empty(), "children list must be empty"); + UNIT_ASSERT_GREATER(children->id, 0UL); + UNIT_ASSERT_TRUE(children->children.empty()); tr.commit(); @@ -258,18 +256,18 @@ void TransactionTestUnit::test_has_many_list_commit() name << "child " << i; auto kid = s.insert(new child(name.str())); - UNIT_ASSERT_GREATER(kid->id, 0UL, "invalid child"); + UNIT_ASSERT_GREATER(kid->id, 0UL); children->children.push_back(kid); } - UNIT_ASSERT_FALSE(children->children.empty(), "children list couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); tr.commit(); - UNIT_ASSERT_FALSE(children->children.empty(), "item children couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); } catch(sql_exception &ex) { // error, abort transaction @@ -299,8 +297,8 @@ void TransactionTestUnit::test_has_many_list_rollback() try { auto children = s.insert(new children_list("children list")); - UNIT_ASSERT_GREATER(children->id, 0UL, "invalid children list"); - UNIT_ASSERT_TRUE(children->children.empty(), "children list must be empty"); + UNIT_ASSERT_GREATER(children->id, 0UL); + UNIT_ASSERT_TRUE(children->children.empty()); tr.commit(); @@ -311,18 +309,18 @@ void TransactionTestUnit::test_has_many_list_rollback() name << "child " << i; auto kid = s.insert(new child(name.str())); - UNIT_ASSERT_GREATER(kid->id, 0UL, "invalid child"); + UNIT_ASSERT_GREATER(kid->id, 0UL); children->children.push_back(kid); } - UNIT_ASSERT_FALSE(children->children.empty(), "children list couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); tr.rollback(); - UNIT_ASSERT_TRUE(children->children.empty(), "item children must be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 0UL, "invalid children list size"); + UNIT_ASSERT_TRUE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 0UL); } catch(sql_exception &ex) { // error, abort transaction @@ -352,8 +350,8 @@ void TransactionTestUnit::test_has_many_list() try { auto children = s.insert(new children_list("children list")); - UNIT_ASSERT_GREATER(children->id, 0UL, "invalid children list"); - UNIT_ASSERT_TRUE(children->children.empty(), "children list must be empty"); + UNIT_ASSERT_GREATER(children->id, 0UL); + UNIT_ASSERT_TRUE(children->children.empty()); tr.commit(); @@ -364,18 +362,18 @@ void TransactionTestUnit::test_has_many_list() name << "child " << i; auto kid = s.insert(new child(name.str())); - UNIT_ASSERT_GREATER(kid->id, 0UL, "invalid child"); + UNIT_ASSERT_GREATER(kid->id, 0UL); children->children.push_back(kid); } - UNIT_ASSERT_FALSE(children->children.empty(), "children list couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); tr.rollback(); - UNIT_ASSERT_TRUE(children->children.empty(), "children list must be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 0UL, "invalid children list size"); + UNIT_ASSERT_TRUE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 0UL); tr.begin(); @@ -384,30 +382,30 @@ void TransactionTestUnit::test_has_many_list() name << "child " << i; auto kid = s.insert(new child(name.str())); - UNIT_ASSERT_GREATER(kid->id, 0UL, "invalid child"); + UNIT_ASSERT_GREATER(kid->id, 0UL); children->children.push_back(kid); } - UNIT_ASSERT_FALSE(children->children.empty(), "item children couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); tr.commit(); - UNIT_ASSERT_FALSE(children->children.empty(), "item children couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); tr.begin(); children->children.clear(); - UNIT_ASSERT_TRUE(children->children.empty(), "item list must be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 0UL, "invalid item list size"); + UNIT_ASSERT_TRUE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 0UL); tr.rollback(); - UNIT_ASSERT_FALSE(children->children.empty(), "item list couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid item list size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); } catch(sql_exception &ex) { // error, abort transaction @@ -437,8 +435,8 @@ void TransactionTestUnit::test_has_many_vector() try { auto children = s.insert(new children_vector("children vector")); - UNIT_ASSERT_GREATER(children->id, 0UL, "invalid children vector"); - UNIT_ASSERT_TRUE(children->children.empty(), "children vector must be empty"); + UNIT_ASSERT_GREATER(children->id, 0UL); + UNIT_ASSERT_TRUE(children->children.empty()); tr.commit(); @@ -449,18 +447,18 @@ void TransactionTestUnit::test_has_many_vector() name << "child " << i; auto kid = s.insert(new child(name.str())); - UNIT_ASSERT_GREATER(kid->id, 0UL, "invalid child"); + UNIT_ASSERT_GREATER(kid->id, 0UL); children->children.push_back(kid); } - UNIT_ASSERT_FALSE(children->children.empty(), "children vector couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children vector size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); tr.rollback(); - UNIT_ASSERT_TRUE(children->children.empty(), "children vector must be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 0UL, "invalid children vector size"); + UNIT_ASSERT_TRUE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 0UL); tr.begin(); @@ -469,30 +467,30 @@ void TransactionTestUnit::test_has_many_vector() name << "child " << i; auto kid = s.insert(new child(name.str())); - UNIT_ASSERT_GREATER(kid->id, 0UL, "invalid child"); + UNIT_ASSERT_GREATER(kid->id, 0UL); children->children.push_back(kid); } - UNIT_ASSERT_FALSE(children->children.empty(), "item children couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children vector size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); tr.commit(); - UNIT_ASSERT_FALSE(children->children.empty(), "item children couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid children vector size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); tr.begin(); children->children.clear(); - UNIT_ASSERT_TRUE(children->children.empty(), "item vector must be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 0UL, "invalid item vector size"); + UNIT_ASSERT_TRUE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 0UL); tr.rollback(); - UNIT_ASSERT_FALSE(children->children.empty(), "item vector couldn't be empty"); - UNIT_ASSERT_EQUAL(children->children.size(), 2UL, "invalid item vector size"); + UNIT_ASSERT_FALSE(children->children.empty()); + UNIT_ASSERT_EQUAL(children->children.size(), 2UL); } catch(sql_exception &ex) { // error, abort transaction diff --git a/test/orm/TransactionTestUnit.hpp b/test/orm/TransactionTestUnit.hpp index c33ce1be0..339449fc7 100644 --- a/test/orm/TransactionTestUnit.hpp +++ b/test/orm/TransactionTestUnit.hpp @@ -29,8 +29,8 @@ class session; class TransactionTestUnit : public matador::unit_test { public: - TransactionTestUnit(const std::string &name, const std::string &msg, const std::string &dns = "memory"); - virtual ~TransactionTestUnit(); + TransactionTestUnit(const std::string &name, const std::string &msg, std::string dns = "memory"); + ~TransactionTestUnit() override = default; void test_simple(); void test_nested(); diff --git a/test/sql/ConditionUnitTest.cpp b/test/sql/ConditionUnitTest.cpp index 8dce74ecd..e8c7b0ef7 100644 --- a/test/sql/ConditionUnitTest.cpp +++ b/test/sql/ConditionUnitTest.cpp @@ -10,9 +10,12 @@ #include "TestDialect.hpp" +using namespace matador; + ConditionUnitTest::ConditionUnitTest() : unit_test("condition", "condition test unit") { + add_test("literal", std::bind(&ConditionUnitTest::test_col_literal, this), "test col literal"); add_test("logical", std::bind(&ConditionUnitTest::test_logical_condition, this), "test a logical condition"); add_test("and", std::bind(&ConditionUnitTest::test_and_condition, this), "test an and condition"); add_test("or", std::bind(&ConditionUnitTest::test_or_condition, this), "test an or condition"); @@ -22,80 +25,88 @@ ConditionUnitTest::ConditionUnitTest() add_test("between", std::bind(&ConditionUnitTest::test_between_condition, this), "test a between condition"); } +void ConditionUnitTest::test_col_literal() +{ + auto name = "name"_col; + + UNIT_ASSERT_EQUAL(name.name, "name"); +} + void ConditionUnitTest::test_logical_condition() { matador::column name("name"); - UNIT_ASSERT_EQUAL(name.name, "name", "name must be equal name"); + UNIT_ASSERT_EQUAL(name.name, "name"); auto cond1 = name != "Hans"; TestDialect dialect; - UNIT_ASSERT_EQUAL(cond1.evaluate(dialect), "\"name\" <> 'Hans'", "expected evaluated condition is false"); + UNIT_ASSERT_EQUAL(cond1.evaluate(dialect), "\"name\" <> 'Hans'"); matador::column age("age"); - UNIT_ASSERT_EQUAL(age.name, "age", "name must be equal age"); + UNIT_ASSERT_EQUAL(age.name, "age"); auto cond2 = age != 9; - UNIT_ASSERT_EQUAL(cond2.evaluate(dialect), "\"age\" <> 9", "expected evaluated condition is false"); + UNIT_ASSERT_EQUAL(cond2.evaluate(dialect), "\"age\" <> 9"); } void ConditionUnitTest::test_and_condition() { + matador::column name("name"); - UNIT_ASSERT_EQUAL(name.name, "name", "name must be equal name"); + UNIT_ASSERT_EQUAL(name.name, "name"); auto cond = name != "Hans" && name != "Dieter"; TestDialect dialect; - UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"name\" <> 'Hans' AND \"name\" <> 'Dieter')", "expected evaluated condition is false"); + UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"name\" <> 'Hans' AND \"name\" <> 'Dieter')"); } void ConditionUnitTest::test_or_condition() { matador::column name("name"); - UNIT_ASSERT_EQUAL(name.name, "name", "name must be equal name"); + UNIT_ASSERT_EQUAL(name.name, "name"); auto cond = name == "Hans" || name == "Dieter"; TestDialect dialect; - UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "\"name\" = 'Hans' OR \"name\" = 'Dieter'", "expected evaluated condition is false"); + UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "\"name\" = 'Hans' OR \"name\" = 'Dieter'"); } void ConditionUnitTest::test_not_condition() { matador::column name("name"); - UNIT_ASSERT_EQUAL(name.name, "name", "name must be equal name"); + UNIT_ASSERT_EQUAL(name.name, "name"); auto cond = !(name != "Hans"); TestDialect dialect; - UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "NOT (\"name\" <> 'Hans')", "expected evaluated condition is false"); + UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "NOT (\"name\" <> 'Hans')"); } void ConditionUnitTest::test_in_condition() { matador::column age("age"); - UNIT_ASSERT_EQUAL(age.name, "age", "name must be equal age"); + UNIT_ASSERT_EQUAL(age.name, "age"); auto cond = age != 7 && matador::in(age, {7,5,5,8}); TestDialect dialect; - UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"age\" <> 7 AND \"age\" IN (7,5,5,8))", "expected evaluated condition is false"); + UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"age\" <> 7 AND \"age\" IN (7,5,5,8))"); cond = age != 7 && matador::in(age, {7}); - UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"age\" <> 7 AND \"age\" IN (7))", "expected evaluated condition is false"); + UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"age\" <> 7 AND \"age\" IN (7))"); } void ConditionUnitTest::test_in_query_condition() @@ -108,19 +119,19 @@ void ConditionUnitTest::test_in_query_condition() auto cond = age != 7 && matador::in(name, q); - UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"age\" <> 7 AND \"name\" IN (SELECT \"name\" FROM \"test\" ))", "expected evaluated condition is false"); + UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"age\" <> 7 AND \"name\" IN (SELECT \"name\" FROM \"test\" ))"); } void ConditionUnitTest::test_between_condition() { matador::column age("age"); - UNIT_ASSERT_EQUAL(age.name, "age", "name must be equal age"); + UNIT_ASSERT_EQUAL(age.name, "age"); auto cond = age != 7 && matador::between(age, 21, 30); TestDialect dialect; - UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"age\" <> 7 AND \"age\" BETWEEN 21 AND 30)", "expected evaluated condition is false"); + UNIT_ASSERT_EQUAL(cond.evaluate(dialect), "(\"age\" <> 7 AND \"age\" BETWEEN 21 AND 30)"); } diff --git a/test/sql/ConditionUnitTest.hpp b/test/sql/ConditionUnitTest.hpp index f75d0cbde..527552488 100644 --- a/test/sql/ConditionUnitTest.hpp +++ b/test/sql/ConditionUnitTest.hpp @@ -12,6 +12,7 @@ class ConditionUnitTest : public matador::unit_test public: ConditionUnitTest(); + void test_col_literal(); void test_logical_condition(); void test_and_condition(); void test_or_condition(); diff --git a/test/sql/ConnectionTestUnit.cpp b/test/sql/ConnectionTestUnit.cpp index c614234ba..edd4bc9d7 100644 --- a/test/sql/ConnectionTestUnit.cpp +++ b/test/sql/ConnectionTestUnit.cpp @@ -24,9 +24,9 @@ using namespace matador; using namespace std; -ConnectionTestUnit::ConnectionTestUnit(const std::string &name, const std::string &msg, const std::string &dns) +ConnectionTestUnit::ConnectionTestUnit(const std::string &name, const std::string &msg, std::string dns) : unit_test(name, msg) - , dns_(dns) + , dns_(std::move(dns)) { add_test("open_close", std::bind(&ConnectionTestUnit::test_open_close, this), "open sql test"); add_test("reopen", std::bind(&ConnectionTestUnit::test_reopen, this), "reopen sql test"); @@ -36,36 +36,36 @@ void ConnectionTestUnit::test_open_close() { matador::connection conn(connection_string()); - UNIT_ASSERT_FALSE(conn.is_open(), "connection must not be open"); + UNIT_ASSERT_FALSE(conn.is_open()); conn.open(); - UNIT_ASSERT_TRUE(conn.is_open(), "couldn't open sql sql"); + UNIT_ASSERT_TRUE(conn.is_open()); conn.close(); - UNIT_ASSERT_FALSE(conn.is_open(), "couldn't close sql sql"); + UNIT_ASSERT_FALSE(conn.is_open()); } void ConnectionTestUnit::test_reopen() { matador::connection conn(connection_string()); - UNIT_ASSERT_FALSE(conn.is_open(), "connection must not be open"); + UNIT_ASSERT_FALSE(conn.is_open()); conn.open(); - UNIT_ASSERT_TRUE(conn.is_open(), "couldn't open sql sql"); + UNIT_ASSERT_TRUE(conn.is_open()); conn.close(); conn.open(); - UNIT_ASSERT_TRUE(conn.is_open(), "couldn't open sql sql"); + UNIT_ASSERT_TRUE(conn.is_open()); conn.close(); - UNIT_ASSERT_FALSE(conn.is_open(), "couldn't close sql sql"); + UNIT_ASSERT_FALSE(conn.is_open()); } std::string ConnectionTestUnit::connection_string() diff --git a/test/sql/ConnectionTestUnit.hpp b/test/sql/ConnectionTestUnit.hpp index 6569eb542..456ea5656 100644 --- a/test/sql/ConnectionTestUnit.hpp +++ b/test/sql/ConnectionTestUnit.hpp @@ -27,7 +27,7 @@ class session; class ConnectionTestUnit : public matador::unit_test { public: - ConnectionTestUnit(const std::string &name, const std::string &msg, const std::string &dns); + ConnectionTestUnit(const std::string &name, const std::string &msg, std::string dns); ~ConnectionTestUnit() override = default; void test_open_close(); diff --git a/test/sql/DialectTestUnit.cpp b/test/sql/DialectTestUnit.cpp index de35feaeb..efc488de7 100644 --- a/test/sql/DialectTestUnit.cpp +++ b/test/sql/DialectTestUnit.cpp @@ -43,13 +43,14 @@ void DialectTestUnit::test_escaping_quotes() dialect.escape_quotes_in_identifier(str); - UNIT_ASSERT_EQUAL("baba\"\"gaga", str, "strings must be equal"); + UNIT_ASSERT_EQUAL("baba\"\"gaga", str); } void DialectTestUnit::test_create_query() { sql s; + s.reset(t_query_command::CREATE); s.append(new detail::create("person")); std::unique_ptr cols(new columns(columns::WITH_BRACKETS)); @@ -63,25 +64,30 @@ void DialectTestUnit::test_create_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("CREATE TABLE \"person\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"name\" VARCHAR(256), \"age\" INTEGER) ", result, "create statement isn't as expected"); + UNIT_ASSERT_EQUAL("create", s.command()); + UNIT_ASSERT_EQUAL("CREATE TABLE \"person\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"name\" VARCHAR(256), \"age\" INTEGER) ", result); } void DialectTestUnit::test_drop_query() { sql s; + s.reset(t_query_command::DROP); s.append(new detail::drop("person")); TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("DROP TABLE \"person\" ", result, "drop statement isn't as expected"); + UNIT_ASSERT_EQUAL("drop", s.command()); + UNIT_ASSERT_EQUAL("DROP TABLE \"person\" ", result); } void DialectTestUnit::test_insert_query() { sql s; + s.reset(t_query_command::INSERT); + s.table_name("person"); s.append(new detail::insert("person")); std::unique_ptr cols(new columns(columns::WITH_BRACKETS)); @@ -107,13 +113,16 @@ void DialectTestUnit::test_insert_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("INSERT INTO \"person\" (\"id\", \"name\", \"age\") VALUES (8, 'hans', 25) ", result, "insert statement isn't as expected"); + UNIT_ASSERT_EQUAL("person", s.table_name()); + UNIT_ASSERT_EQUAL("insert", s.command()); + UNIT_ASSERT_EQUAL("INSERT INTO \"person\" (\"id\", \"name\", \"age\") VALUES (8, 'hans', 25) ", result); } void DialectTestUnit::test_insert_prepare_query() { sql s; + s.reset(t_query_command::INSERT); s.append(new detail::insert("person")); std::unique_ptr cols(new columns(columns::WITH_BRACKETS)); @@ -139,13 +148,14 @@ void DialectTestUnit::test_insert_prepare_query() TestDialect dialect; std::string result = dialect.prepare(s); - UNIT_ASSERT_EQUAL("INSERT INTO \"person\" (\"id\", \"name\", \"age\") VALUES (?, ?, ?) ", result, "insert statement isn't as expected"); + UNIT_ASSERT_EQUAL("INSERT INTO \"person\" (\"id\", \"name\", \"age\") VALUES (?, ?, ?) ", result); } void DialectTestUnit::test_select_all_query() { sql s; + s.reset(t_query_command::SELECT); s.append(new detail::select); std::unique_ptr cols(new columns(columns::WITHOUT_BRACKETS)); @@ -161,13 +171,15 @@ void DialectTestUnit::test_select_all_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" ", result, "select isn't as expected"); + UNIT_ASSERT_EQUAL("select", s.command()); + UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" ", result); } void DialectTestUnit::test_select_distinct_query() { sql s; + s.reset(t_query_command::SELECT); s.append(new detail::select); s.append(new detail::distinct); @@ -184,13 +196,15 @@ void DialectTestUnit::test_select_distinct_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("SELECT DISTINCT \"id\", \"name\", \"age\" FROM \"person\" ", result, "select distinct isn't as expected"); + UNIT_ASSERT_EQUAL("select", s.command()); + UNIT_ASSERT_EQUAL("SELECT DISTINCT \"id\", \"name\", \"age\" FROM \"person\" ", result); } void DialectTestUnit::test_select_limit_query() { sql s; + s.reset(t_query_command::SELECT); s.append(new detail::select); s.append(new detail::top(10)); @@ -207,13 +221,15 @@ void DialectTestUnit::test_select_limit_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("SELECT LIMIT 10 \"id\", \"name\", \"age\" FROM \"person\" ", result, "select limit isn't as expected"); + UNIT_ASSERT_EQUAL("select", s.command()); + UNIT_ASSERT_EQUAL("SELECT LIMIT 10 \"id\", \"name\", \"age\" FROM \"person\" ", result); } void DialectTestUnit::test_select_ordered_query() { sql s; + s.reset(t_query_command::SELECT); s.append(new detail::select); std::unique_ptr cols(new columns(columns::WITHOUT_BRACKETS)); @@ -231,13 +247,15 @@ void DialectTestUnit::test_select_ordered_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" ORDER BY \"name\" DESC ", result, "select isn't as expected"); + UNIT_ASSERT_EQUAL("select", s.command()); + UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" ORDER BY \"name\" DESC ", result); } void DialectTestUnit::test_select_grouped_query() { sql s; + s.reset(t_query_command::SELECT); s.append(new detail::select); std::unique_ptr cols(new columns(columns::WITHOUT_BRACKETS)); @@ -254,13 +272,15 @@ void DialectTestUnit::test_select_grouped_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" GROUP BY \"name\" ", result, "select isn't as expected"); + UNIT_ASSERT_EQUAL("select", s.command()); + UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" GROUP BY \"name\" ", result); } void DialectTestUnit::test_select_where_query() { sql s; + s.reset(t_query_command::SELECT); s.append(new detail::select); auto cols = std::make_unique(columns::WITHOUT_BRACKETS); @@ -279,7 +299,8 @@ void DialectTestUnit::test_select_where_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" WHERE \"name\" <> 'hans' ", result, "select isn't as expected"); + UNIT_ASSERT_EQUAL("select", s.command()); + UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" WHERE \"name\" <> 'hans' ", result); s.reset(t_query_command::SELECT); @@ -299,13 +320,15 @@ void DialectTestUnit::test_select_where_query() result = dialect.direct(s); - UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" WHERE (\"name\" <> 'Hans' AND \"name\" <> 'Dieter') ", result, "select isn't as expected"); + UNIT_ASSERT_EQUAL("select", s.command()); + UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" WHERE (\"name\" <> 'Hans' AND \"name\" <> 'Dieter') ", result); } void DialectTestUnit::test_update_query() { sql s; + s.reset(t_query_command::UPDATE); s.append(new detail::update); s.append(new detail::tablename("person")); s.append(new detail::set); @@ -322,13 +345,15 @@ void DialectTestUnit::test_update_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"='Dieter', \"age\"=54 ", result, "update isn't as expected"); + UNIT_ASSERT_EQUAL("update", s.command()); + UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"='Dieter', \"age\"=54 ", result); } void DialectTestUnit::test_update_where_query() { sql s; + s.reset(t_query_command::UPDATE); s.append(new detail::update); s.append(new detail::tablename("person")); s.append(new detail::set); @@ -349,13 +374,15 @@ void DialectTestUnit::test_update_where_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"='Dieter', \"age\"=54 WHERE (\"name\" <> 'Hans' AND \"age\" IN (7,5,5,8)) ", result, "update where isn't as expected"); + UNIT_ASSERT_EQUAL("update", s.command()); + UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"='Dieter', \"age\"=54 WHERE (\"name\" <> 'Hans' AND \"age\" IN (7,5,5,8)) ", result); } void DialectTestUnit::test_update_prepare_query() { sql s; + s.reset(t_query_command::UPDATE); s.append(new detail::update); s.append(new detail::tablename("person")); s.append(new detail::set); @@ -372,13 +399,14 @@ void DialectTestUnit::test_update_prepare_query() TestDialect dialect; std::string result = dialect.prepare(s); - UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"=?, \"age\"=? ", result, "update isn't as expected"); + UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"=?, \"age\"=? ", result); } void DialectTestUnit::test_update_where_prepare_query() { sql s; + s.reset(t_query_command::UPDATE); s.append(new detail::update); s.append(new detail::tablename("person")); s.append(new detail::set); @@ -399,7 +427,7 @@ void DialectTestUnit::test_update_where_prepare_query() TestDialect dialect; std::string result = dialect.prepare(s); - UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"=?, \"age\"=? WHERE (\"name\" <> ? AND \"age\" IN (?,?,?,?)) ", result, "update where isn't as expected"); + UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"=?, \"age\"=? WHERE (\"name\" <> ? AND \"age\" IN (?,?,?,?)) ", result); } @@ -407,19 +435,22 @@ void DialectTestUnit::test_delete_query() { sql s; + s.reset(t_query_command::REMOVE); s.append(new detail::remove()); s.append(new detail::from("person")); TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("DELETE FROM \"person\" ", result, "delete isn't as expected"); + UNIT_ASSERT_EQUAL("delete", s.command()); + UNIT_ASSERT_EQUAL("DELETE FROM \"person\" ", result); } void DialectTestUnit::test_delete_where_query() { sql s; + s.reset(t_query_command::REMOVE); s.append(new detail::remove()); s.append(new detail::from("person")); @@ -430,5 +461,5 @@ void DialectTestUnit::test_delete_where_query() TestDialect dialect; std::string result = dialect.direct(s); - UNIT_ASSERT_EQUAL("DELETE FROM \"person\" WHERE (\"name\" <> 'Hans' AND \"age\" BETWEEN 21 AND 30) ", result, "delete where isn't as expected"); + UNIT_ASSERT_EQUAL("DELETE FROM \"person\" WHERE (\"name\" <> 'Hans' AND \"age\" BETWEEN 21 AND 30) ", result); } diff --git a/test/sql/MSSQLDialectTestUnit.cpp b/test/sql/MSSQLDialectTestUnit.cpp index 90bab2ecd..39ec4e854 100644 --- a/test/sql/MSSQLDialectTestUnit.cpp +++ b/test/sql/MSSQLDialectTestUnit.cpp @@ -45,7 +45,7 @@ void MSSQLDialectTestUnit::test_limit() std::string result = conn.dialect()->direct(s); - UNIT_ASSERT_EQUAL("SELECT TOP (10) [id], [name], [age] FROM [person] ", result, "select limit isn't as expected"); + UNIT_ASSERT_EQUAL("SELECT TOP (10) [id], [name], [age] FROM [person] ", result); } void MSSQLDialectTestUnit::test_query_select_sub_select() @@ -60,12 +60,11 @@ void MSSQLDialectTestUnit::test_query_select_sub_select() q.select().where(matador::in(id, subselect)); - UNIT_ASSERT_EQUAL("SELECT [id], [name], [birthdate], [height] FROM [person] WHERE [id] IN (SELECT * FROM (SELECT TOP (1) [id] FROM [person] ) AS p ) ", q.str(conn, false), "select limit isn't as expected"); + UNIT_ASSERT_EQUAL("SELECT [id], [name], [birthdate], [height] FROM [person] WHERE [id] IN (SELECT * FROM (SELECT TOP (1) [id] FROM [person] ) AS p ) ", q.str(conn, false)); } void MSSQLDialectTestUnit::test_query_select_sub_select_result() { - std::cout << "\nstarted sub select\n"; matador::connection conn(::connection::mssql); conn.open(); @@ -96,8 +95,8 @@ void MSSQLDialectTestUnit::test_query_select_sub_select_result() res = q.select().where(matador::in(id, subselect)).execute(conn); //for (auto p : res) { - // UNIT_EXPECT_EQUAL(1UL, p->id(), "invalid value"); - // UNIT_EXPECT_EQUAL("Hans", p->name(), "invalid value"); + // UNIT_EXPECT_EQUAL(1UL, p->id()); + // UNIT_EXPECT_EQUAL("Hans", p->name()); //} q.drop().execute(conn); diff --git a/test/sql/PostgreSQLDialectTestUnit.cpp b/test/sql/PostgreSQLDialectTestUnit.cpp new file mode 100644 index 000000000..9c250dc64 --- /dev/null +++ b/test/sql/PostgreSQLDialectTestUnit.cpp @@ -0,0 +1,121 @@ +// +// Created by sascha on 04.06.19. +// + +#include + +#include "../person.hpp" + +#include "connections.hpp" + +#include "matador/sql/connection.hpp" +#include "matador/sql/sql.hpp" +#include "matador/sql/column.hpp" +#include "matador/sql/dialect_token.hpp" + +#include "PostgreSQLDialectTestUnit.hpp" + +using namespace matador; + +PostgreSQLDialectTestUnit::PostgreSQLDialectTestUnit() + : unit_test("postgresql_dialect" , "postgresql dialect test") +{ + add_test("placeholder", std::bind(&PostgreSQLDialectTestUnit::test_placeholder, this), "test postgresql placeholder link"); + add_test("placeholder_condition", std::bind(&PostgreSQLDialectTestUnit::test_placeholder_condition, this), "test postgresql placeholder in condition link"); + add_test("update_limit", std::bind(&PostgreSQLDialectTestUnit::test_update_limit, this), "test postgresql limit"); + add_test("tablename", std::bind(&PostgreSQLDialectTestUnit::test_table_name, this), "test postgresql extract table name"); +} + +void PostgreSQLDialectTestUnit::test_placeholder() +{ + matador::connection conn(::connection::postgresql); + + sql s; + + s.append(new detail::insert("person")); + + std::unique_ptr cols(new columns(columns::WITH_BRACKETS)); + + cols->push_back(std::make_shared("id")); + cols->push_back(std::make_shared("name")); + cols->push_back(std::make_shared("age")); + + s.append(cols.release()); + + std::unique_ptr vals(new detail::values); + + unsigned long id(8); + std::string name("hans"); + unsigned int age(25); + + vals->push_back(std::make_shared>(id)); + vals->push_back(std::make_shared>(name)); + vals->push_back(std::make_shared>(age)); + + s.append(vals.release()); + + std::string result = conn.dialect()->prepare(s); + + UNIT_ASSERT_EQUAL("INSERT INTO \"person\" (\"id\", \"name\", \"age\") VALUES ($1, $2, $3) ", result); +} + +void PostgreSQLDialectTestUnit::test_placeholder_condition() +{ + matador::connection conn(::connection::postgresql); + + sql s; + + s.append(new detail::select()); + + std::unique_ptr cols(new columns(columns::WITHOUT_BRACKETS)); + + cols->push_back(std::make_shared("id")); + cols->push_back(std::make_shared("name")); + cols->push_back(std::make_shared("age")); + + s.append(cols.release()); + + s.append(new detail::from("person")); + + s.append(new detail::where("name"_col == "hans")); + + std::string result = conn.dialect()->prepare(s); + + UNIT_ASSERT_EQUAL("SELECT \"id\", \"name\", \"age\" FROM \"person\" WHERE \"name\" = $1 ", result); +} + +void PostgreSQLDialectTestUnit::test_update_limit() +{ + matador::connection conn(::connection::postgresql); + + sql s; + + s.append(new detail::update); + s.append(new detail::tablename("relation")); + s.append(new detail::set); + + std::unique_ptr cols(new columns(columns::WITHOUT_BRACKETS)); + + unsigned long owner_id(1); + cols->push_back(std::make_shared>("owner_id", owner_id)); + + s.append(cols.release()); + + s.append(new detail::where("owner_id"_col == 1 && "item_id"_col == 1)); + s.append(new detail::top(1)); + + std::string result = conn.dialect()->direct(s); + + UNIT_ASSERT_EQUAL("UPDATE \"relation\" SET \"owner_id\"=1 WHERE \"owner_id\" = (SELECT \"owner_id\" FROM \"relation\" WHERE (\"owner_id\" = 1 AND \"item_id\" = 1) LIMIT 1 ) ", result); +} + +void PostgreSQLDialectTestUnit::test_table_name() +{ + query q("person"); + + column id("id"); + + q.select(); + + UNIT_ASSERT_EQUAL("person", q.stmt().table_name()); +} diff --git a/test/sql/PostgreSQLDialectTestUnit.hpp b/test/sql/PostgreSQLDialectTestUnit.hpp new file mode 100644 index 000000000..07cb6f802 --- /dev/null +++ b/test/sql/PostgreSQLDialectTestUnit.hpp @@ -0,0 +1,23 @@ +// +// Created by sascha on 04.06.19. +// + +#ifndef MATADOR_POSTGRESQLDIALECTTESTUNIT_HPP +#define MATADOR_POSTGRESQLDIALECTTESTUNIT_HPP + + +#include "matador/unit/unit_test.hpp" + +class PostgreSQLDialectTestUnit : public matador::unit_test +{ +public: + PostgreSQLDialectTestUnit(); + + void test_placeholder(); + void test_placeholder_condition(); + void test_update_limit(); + void test_table_name(); +}; + + +#endif //MATADOR_POSTGRESQLDIALECTTESTUNIT_HPP diff --git a/test/sql/QueryTestUnit.cpp b/test/sql/QueryTestUnit.cpp index d99fd2956..1e9921d00 100644 --- a/test/sql/QueryTestUnit.cpp +++ b/test/sql/QueryTestUnit.cpp @@ -14,10 +14,10 @@ using namespace matador; -QueryTestUnit::QueryTestUnit(const std::string &name, const std::string &msg, const std::string &db, const matador::time &timeval) +QueryTestUnit::QueryTestUnit(const std::string &name, const std::string &msg, std::string db, matador::time timeval) : unit_test(name, msg) - , db_(db) - , time_val_(timeval) + , db_(std::move(db)) + , time_val_(std::move(timeval)) { add_test("datatypes", std::bind(&QueryTestUnit::test_datatypes, this), "test sql datatypes"); add_test("qvc", std::bind(&QueryTestUnit::test_query_value_creator, this), "test query value creator"); @@ -82,7 +82,14 @@ void QueryTestUnit::test_datatypes() bool bval = true; const char *cstr("Armer schwarzer Kater"); matador::varchar<32> vval("hallo welt"); - std::string strval = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; + std::string strval = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam " + "nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, " + "sed diam voluptua. At vero eos et accusam et justo duo dolores et ea " + "rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. " + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy " + "eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. " + "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd " + "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; matador::date date_val(15, 3, 2015); matador::time time_val(time_val_); Item item; @@ -111,23 +118,23 @@ void QueryTestUnit::test_datatypes() auto first = res.begin(); auto last = res.end(); - UNIT_ASSERT_TRUE(first != last, "first must not be last"); + UNIT_ASSERT_TRUE(first != last); std::unique_ptr it((first++).release()); - UNIT_EXPECT_EQUAL(it->get_char(), cval, "character is not equal"); - UNIT_EXPECT_EQUAL(it->get_short(), sval, "short is not equal"); - UNIT_EXPECT_EQUAL(it->get_int(), ival, "integer is not equal"); - UNIT_EXPECT_EQUAL(it->get_long(), lval, "long is not equal"); - UNIT_EXPECT_EQUAL(it->get_unsigned_short(), usval, "unsigned short is not equal"); - UNIT_EXPECT_EQUAL(it->get_unsigned_int(), uival, "unsigned integer is not equal"); - UNIT_EXPECT_EQUAL(it->get_unsigned_long(), ulval, "unsigned long is not equal"); - UNIT_EXPECT_EQUAL(it->get_bool(), bval, "bool is not equal"); - UNIT_EXPECT_EQUAL(it->get_cstr(), cstr, "const char pointer is not equal"); - UNIT_EXPECT_EQUAL(it->get_string(), strval, "strings is not equal"); - UNIT_EXPECT_EQUAL(it->get_varchar(), vval, "varchar is not equal"); - UNIT_EXPECT_EQUAL(it->get_date(), date_val, "date is not equal"); - UNIT_EXPECT_EQUAL(it->get_time(), time_val, "time is not equal"); + UNIT_EXPECT_EQUAL(it->get_char(), cval); + UNIT_EXPECT_EQUAL(it->get_short(), sval); + UNIT_EXPECT_EQUAL(it->get_int(), ival); + UNIT_EXPECT_EQUAL(it->get_long(), lval); + UNIT_EXPECT_EQUAL(it->get_unsigned_short(), usval); + UNIT_EXPECT_EQUAL(it->get_unsigned_int(), uival); + UNIT_EXPECT_EQUAL(it->get_unsigned_long(), ulval); + UNIT_EXPECT_EQUAL(it->get_bool(), bval); + UNIT_EXPECT_EQUAL(it->get_cstr(), cstr); + UNIT_EXPECT_EQUAL(it->get_string(), strval); + UNIT_EXPECT_EQUAL(it->get_varchar(), vval); + UNIT_EXPECT_EQUAL(it->get_date(), date_val); + UNIT_EXPECT_EQUAL(it->get_time(), time_val); q.drop().execute(connection_); } @@ -142,7 +149,7 @@ void QueryTestUnit::test_query_value_creator() auto val = qvc.create_from_any(ac); - UNIT_ASSERT_EQUAL(val->get(), 'c', "values must be equal"); + UNIT_ASSERT_EQUAL(val->get(), 'c'); } void QueryTestUnit::test_quoted_identifier() @@ -159,8 +166,8 @@ void QueryTestUnit::test_quoted_identifier() auto fields = connection_.describe("quotes"); for (auto &&field : fields) { - UNIT_EXPECT_EQUAL(field.name(), columns[field.index()], "invalid column name"); - UNIT_EXPECT_EQUAL((int)field.type(), (int)types[field.index()], "invalid column type"); + UNIT_EXPECT_EQUAL(field.name(), columns[field.index()]); + UNIT_EXPECT_EQUAL((int)field.type(), (int)types[field.index()]); } q.insert({"from", "to"}).values({"Berlin", "London"}).execute(); @@ -168,8 +175,8 @@ void QueryTestUnit::test_quoted_identifier() auto res = q.select({"from", "to"}).from("quotes").execute(); for (auto row : res) { - UNIT_EXPECT_EQUAL("Berlin", row->at("from"), "values must be equal"); - UNIT_EXPECT_EQUAL("London", row->at("to"), "values must be equal"); + UNIT_EXPECT_EQUAL("Berlin", row->at("from")); + UNIT_EXPECT_EQUAL("London", row->at("to")); } column from("from"); @@ -178,8 +185,8 @@ void QueryTestUnit::test_quoted_identifier() res = q.select({"from", "to"}).from("quotes").execute(); for (auto row : res) { - UNIT_EXPECT_EQUAL("Hamburg", row->at("from"), "values must be equal"); - UNIT_EXPECT_EQUAL("New York", row->at("to"), "values must be equal"); + UNIT_EXPECT_EQUAL("Hamburg", row->at("from")); + UNIT_EXPECT_EQUAL("New York", row->at("to")); } q.drop().execute(); @@ -213,8 +220,8 @@ void QueryTestUnit::test_columns_with_quotes_in_name() auto fields = connection_.describe("quotes"); for (auto &&field : fields) { - UNIT_EXPECT_EQUAL(field.name(), columns[field.index()], "invalid column name"); - UNIT_EXPECT_EQUAL((int)field.type(), (int)types[field.index()], "invalid column type"); + UNIT_EXPECT_EQUAL(field.name(), columns[field.index()]); + UNIT_EXPECT_EQUAL((int)field.type(), (int)types[field.index()]); } q.drop().execute(); @@ -234,7 +241,7 @@ void QueryTestUnit::test_quoted_literals() auto res = q.select({"name"}).from("escapes").execute(); for (auto item : res) { - UNIT_ASSERT_EQUAL(item->at(0), "text", "values must be equal"); + UNIT_ASSERT_EQUAL(item->at(0), "text"); } q.update({{"name", "text'd"}}).execute(); @@ -242,7 +249,7 @@ void QueryTestUnit::test_quoted_literals() res = q.select({"name"}).from("escapes").execute(); for (auto item : res) { - UNIT_ASSERT_EQUAL(item->at(0), "text'd", "values must be equal"); + UNIT_ASSERT_EQUAL(item->at(0), "text'd"); } q.update({{"name", "text\nhello\tworld"}}).execute(); @@ -250,7 +257,7 @@ void QueryTestUnit::test_quoted_literals() res = q.select({"name"}).from("escapes").execute(); for (auto item : res) { - UNIT_ASSERT_EQUAL(item->at(0), "text\nhello\tworld", "values must be equal"); + UNIT_ASSERT_EQUAL(item->at(0), "text\nhello\tworld"); } q.update({{"name", "text \"text\""}}).execute(); @@ -258,7 +265,7 @@ void QueryTestUnit::test_quoted_literals() res = q.select({"name"}).from("escapes").execute(); for (auto item : res) { - UNIT_ASSERT_EQUAL(item->at(0), "text \"text\"", "values must be equal"); + UNIT_ASSERT_EQUAL(item->at(0), "text \"text\""); } q.drop().execute(); @@ -270,16 +277,16 @@ void QueryTestUnit::test_bind_tablename() matador::query q0; // tablename should be person - UNIT_ASSERT_TRUE(q0.tablename().empty(), "name must be empty"); + UNIT_ASSERT_TRUE(q0.tablename().empty()); matador::query::bind_table("person"); matador::query q1; // tablename should be person - UNIT_ASSERT_EQUAL(q1.tablename(), "person", "names must be equal"); + UNIT_ASSERT_EQUAL(q1.tablename(), "person"); matador::query q2("student"); // tablename should be student - UNIT_ASSERT_EQUAL(q2.tablename(), "student", "names must be equal"); + UNIT_ASSERT_EQUAL(q2.tablename(), "student"); } void QueryTestUnit::test_describe() @@ -296,8 +303,8 @@ void QueryTestUnit::test_describe() std::vector types = { matador::data_type::type_long, matador::data_type::type_varchar, matador::data_type::type_date, matador::data_type::type_long}; for (auto &&field : fields) { - UNIT_ASSERT_EQUAL(field.name(), columns[field.index()], "invalid column name"); - UNIT_ASSERT_EQUAL((int)field.type(), (int)types[field.index()], "invalid column type"); + UNIT_ASSERT_EQUAL(field.name(), columns[field.index()]); + UNIT_ASSERT_EQUAL((int)field.type(), (int)types[field.index()]); } q.drop().execute(connection_); @@ -334,7 +341,7 @@ void QueryTestUnit::test_identifier() std::unique_ptr p(new pktest(7, "hans")); - UNIT_EXPECT_EQUAL(p->id.value(), 7UL, "identifier value should be greater zero"); + UNIT_EXPECT_EQUAL(p->id.value(), 7UL); q.insert(*p).execute(connection_); @@ -343,11 +350,11 @@ void QueryTestUnit::test_identifier() auto first = res.begin(); auto last = res.end(); - UNIT_ASSERT_TRUE(first != last, "first must not be last"); + UNIT_ASSERT_TRUE(first != last); p.reset((first++).release()); - UNIT_EXPECT_GREATER(p->id.value(), 0UL, "identifier value should be greater zero"); + UNIT_EXPECT_GREATER(p->id.value(), 0UL); q.drop().execute(connection_); } @@ -363,7 +370,7 @@ void QueryTestUnit::test_identifier_prepared() pktest p(7, "hans"); - UNIT_EXPECT_EQUAL(p.id.value(), 7UL, "identifier value should be greater zero"); + UNIT_EXPECT_EQUAL(p.id.value(), 7UL); stmt = q.insert(p).prepare(connection_); stmt.bind(0, &p); @@ -376,11 +383,11 @@ void QueryTestUnit::test_identifier_prepared() // auto first = res.begin(); // auto last = res.end(); // -// UNIT_ASSERT_TRUE(first != last, "first must not be last"); +// UNIT_ASSERT_TRUE(first != last); for (auto pres : res) { - UNIT_EXPECT_EQUAL(pres->name, "hans", "name must be hans"); - UNIT_EXPECT_GREATER(pres->id.value(), 0UL, "identifier value should be greater zero"); + UNIT_EXPECT_EQUAL(pres->name, "hans"); + UNIT_EXPECT_GREATER(pres->id.value(), 0UL); //std::cout << "id: " << pres->id.value() << "\n"; } // std::unique_ptr pres((first++).release()); @@ -405,16 +412,16 @@ void QueryTestUnit::test_create() res = q.select().execute(connection_); -// UNIT_ASSERT_EQUAL(res.size(), 1UL, "expected size must be one (1)"); +// UNIT_ASSERT_EQUAL(res.size(), 1UL); auto first = res.begin(); auto last = res.end(); while (first != last) { std::unique_ptr item(first.release()); - UNIT_EXPECT_EQUAL(item->get_string(), "Hans", "expected name must be 'Hans'"); - UNIT_EXPECT_EQUAL(item->get_int(), 4711, "expected integer must be 4711"); - UNIT_EXPECT_EQUAL(item->get_time(), itime, "expected time is invalid"); + UNIT_EXPECT_EQUAL(item->get_string(), "Hans"); + UNIT_EXPECT_EQUAL(item->get_int(), 4711); + UNIT_EXPECT_EQUAL(item->get_time(), itime); ++first; } @@ -439,8 +446,7 @@ void QueryTestUnit::test_update() q.insert(p).execute(); } - column name("name"); - res = q.select().where(name == "hans").execute(); + res = q.select().where("name"_col == "hans").execute(); auto first = res.begin(); auto last = res.end(); @@ -448,9 +454,9 @@ void QueryTestUnit::test_update() while (first != last) { std::unique_ptr item(first.release()); - UNIT_ASSERT_EQUAL(item->name(), "hans", "expected name must be 'Hans'"); - UNIT_ASSERT_EQUAL(item->height(), 180U, "expected height must be 180"); - UNIT_ASSERT_EQUAL(item->birthdate(), matador::date(12, 3, 1980), "expected birthdate is 12.3.1980"); + UNIT_ASSERT_EQUAL(item->name(), "hans"); + UNIT_ASSERT_EQUAL(item->height(), 180U); + UNIT_ASSERT_EQUAL(item->birthdate(), matador::date(12, 3, 1980)); ++first; } @@ -460,12 +466,12 @@ void QueryTestUnit::test_update() column idcol("id"); q.update(hans).where(idcol == 1).execute(); - res = q.select().where(name == "hans").execute(); + res = q.select().where("name"_col == "hans").execute(); for (auto i : res) { - UNIT_ASSERT_EQUAL(i->name(), "hans", "expected name must be 'Hans'"); - UNIT_ASSERT_EQUAL(i->height(), 165U, "expected height must be 180"); - UNIT_ASSERT_EQUAL(i->birthdate(), matador::date(15, 6, 1990), "expected birthdate is 12.3.1980"); + UNIT_ASSERT_EQUAL(i->name(), "hans"); + UNIT_ASSERT_EQUAL(i->height(), 165U); + UNIT_ASSERT_EQUAL(i->birthdate(), matador::date(15, 6, 1990)); } q.drop().execute(); @@ -487,11 +493,11 @@ void QueryTestUnit::test_anonymous_create() q.execute(); - UNIT_ASSERT_TRUE(connection_.exists("person"), "table person must exist"); + UNIT_ASSERT_TRUE(connection_.exists("person")); auto fields = connection_.describe("person"); for (const auto &fld : fields) { - UNIT_EXPECT_FALSE(std::find(cols.begin(), cols.end(), fld.name()) == cols.end(), "couldn't find expected field"); + UNIT_EXPECT_FALSE(std::find(cols.begin(), cols.end(), fld.name()) == cols.end()); } q.drop("person").execute(connection_); @@ -520,8 +526,8 @@ void QueryTestUnit::test_anonymous_insert() while (first != last) { std::unique_ptr item(first.release()); - UNIT_EXPECT_EQUAL(1L, item->at("id"), "invalid value"); - UNIT_EXPECT_EQUAL("hans", item->at("name"), "invalid value"); + UNIT_EXPECT_EQUAL(1L, item->at("id")); + UNIT_EXPECT_EQUAL("hans", item->at("name")); ++first; } @@ -556,8 +562,8 @@ void QueryTestUnit::test_anonymous_update() while (first != last) { std::unique_ptr item(first.release()); - UNIT_EXPECT_EQUAL("jane", item->at("name"), "invalid value"); - UNIT_EXPECT_EQUAL(47L, item->at("age"), "invalid value"); + UNIT_EXPECT_EQUAL("jane", item->at("name")); + UNIT_EXPECT_EQUAL(47L, item->at("age")); ++first; } @@ -590,19 +596,13 @@ void QueryTestUnit::test_statement_insert() res = stmt.execute(); -// UNIT_ASSERT_EQUAL(res.size(), 1UL, "expected size must be one (1)"); - - //auto first = res.begin(); - //auto last = res.end(); +// UNIT_ASSERT_EQUAL(res.size(), 1UL); - for (auto item : res) { - //while (first != last) { - //std::unique_ptr item(first.release()); - UNIT_EXPECT_EQUAL(item->id(), 23UL, "expected id must be 23"); - UNIT_EXPECT_EQUAL(item->get_string(), "Hans", "expected name must be 'Hans'"); - UNIT_EXPECT_EQUAL(item->get_int(), 4711, "expected integer must be 4711"); - UNIT_EXPECT_EQUAL(item->get_time(), itime, "expected time is invalid"); - //++first; + for (auto const &item : res) { + UNIT_EXPECT_EQUAL(item->id(), 23UL); + UNIT_EXPECT_EQUAL(item->get_string(), "Hans"); + UNIT_EXPECT_EQUAL(item->get_int(), 4711); + UNIT_EXPECT_EQUAL(item->get_time(), itime); } stmt = q.drop().prepare(connection_); @@ -631,25 +631,21 @@ void QueryTestUnit::test_statement_update() stmt.execute(); } - column name("name"); - stmt = q.select().where(name == "").prepare(); - matador::varchar<255> hname("hans"); - stmt.bind(0, hname); + stmt = q.select().where("name"_col == "").prepare(); + matador::varchar<255> name("hans"); + stmt.bind(0, name); res = stmt.execute(); -// UNIT_ASSERT_EQUAL(res.size(), 1UL, "expected size must be one (1)"); +// UNIT_ASSERT_EQUAL(res.size(), 1UL); //auto first = res.begin(); //auto last = res.end(); - for (auto p : res) { - //while (first != last) { - //std::unique_ptr p(first.release()); - UNIT_EXPECT_EQUAL(p->id(), 1UL, "expected id must be 1"); - UNIT_EXPECT_EQUAL(p->name(), "hans", "expected name must be 'hans'"); - UNIT_EXPECT_EQUAL(p->height(), 180U, "expected height must be 180"); - UNIT_EXPECT_EQUAL(p->birthdate(), matador::date(12, 3, 1980), "expected birthdate is 12.3.1980"); - //++first; + for (auto const &p : res) { + UNIT_EXPECT_EQUAL(p->id(), 1UL); + UNIT_EXPECT_EQUAL(p->name(), "hans"); + UNIT_EXPECT_EQUAL(p->height(), 180U); + UNIT_EXPECT_EQUAL(p->birthdate(), matador::date(12, 3, 1980)); } // auto id_cond = id_condition_builder::build(); @@ -666,22 +662,22 @@ void QueryTestUnit::test_statement_update() res = stmt.execute(); - stmt = q.select().where(name == "").prepare(); - stmt.bind(0, hname); + stmt = q.select().where("name"_col == "").prepare(); + stmt.bind(0, name); res = stmt.execute(); -// UNIT_ASSERT_EQUAL(res.size(), 1UL, "expected size must be one (1)"); +// UNIT_ASSERT_EQUAL(res.size(), 1UL); //first = res.begin(); //last = res.end(); - for (auto p : res) { + for (const auto &p : res) { //while (first != last) { //std::unique_ptr p(first.release()); - UNIT_EXPECT_EQUAL(p->id(), 1UL, "expected id must be 1"); - UNIT_EXPECT_EQUAL(p->name(), "hans", "expected name must be 'hans'"); - UNIT_EXPECT_EQUAL(p->height(), 165U, "expected height must be 180"); - UNIT_EXPECT_EQUAL(p->birthdate(), matador::date(15, 6, 1990), "expected birthdate is 12.3.1980"); + UNIT_EXPECT_EQUAL(p->id(), 1UL); + UNIT_EXPECT_EQUAL(p->name(), "hans"); + UNIT_EXPECT_EQUAL(p->height(), 165U); + UNIT_EXPECT_EQUAL(p->birthdate(), matador::date(15, 6, 1990)); //++first; } @@ -714,9 +710,9 @@ void QueryTestUnit::test_delete() //while (first != last) { //std::unique_ptr item(first.release()); - UNIT_EXPECT_EQUAL(p->name(), "Hans", "expected name must be 'Hans'"); - UNIT_EXPECT_EQUAL(p->height(), 180U, "expected height must be 180"); - UNIT_EXPECT_EQUAL(p->birthdate(), matador::date(12, 3, 1980), "expected birthdate is 12.3.1980"); + UNIT_EXPECT_EQUAL(p->name(), "Hans"); + UNIT_EXPECT_EQUAL(p->height(), 180U); + UNIT_EXPECT_EQUAL(p->birthdate(), matador::date(12, 3, 1980)); //++first; } @@ -725,7 +721,7 @@ void QueryTestUnit::test_delete() res = q.select().where(name == "Hans").execute(connection_); - UNIT_ASSERT_TRUE(res.begin() == res.end(), "result list must be empty"); + UNIT_ASSERT_TRUE(res.begin() == res.end()); q.drop().execute(connection_); } @@ -765,8 +761,8 @@ void QueryTestUnit::test_delete() // std::unique_ptr obj(first.release()); // // object_ptr i = obj->ptr(); -// UNIT_ASSERT_TRUE(i.has_primary_key(), "expected valid identifier"); -// UNIT_ASSERT_TRUE(*i.primary_key() == id, "expected id must be 23"); +// UNIT_ASSERT_TRUE(i.has_primary_key()); +// UNIT_ASSERT_TRUE(*i.primary_key() == id); // // ++first; // } @@ -798,16 +794,16 @@ void QueryTestUnit::test_query() while (first != last) { std::unique_ptr item(first.release()); - UNIT_ASSERT_EQUAL(item->name(), "Hans", "expected name must be 'Hans'"); - UNIT_ASSERT_EQUAL(item->height(), 180U, "expected height must be 180"); - UNIT_ASSERT_EQUAL(item->birthdate(), matador::date(12, 3, 1980), "expected birthdate is 12.3.1980"); + UNIT_ASSERT_EQUAL(item->name(), "Hans"); + UNIT_ASSERT_EQUAL(item->height(), 180U); + UNIT_ASSERT_EQUAL(item->birthdate(), matador::date(12, 3, 1980)); ++first; } res = q.select().where(name == "heinz").execute(connection_); - UNIT_ASSERT_TRUE(res.begin() == res.end(), "begin must be equal end"); + UNIT_ASSERT_TRUE(res.begin() == res.end()); q.drop().execute(connection_); } @@ -844,16 +840,16 @@ void QueryTestUnit::test_query_range_loop() for (auto &&item : res) { ++size; - UNIT_EXPECT_TRUE(contains(result_names, item->name()), "expected name '" + item->name() + "'not found"); -// UNIT_ASSERT_EQUAL(item.height(), 180U, "expected height must be 180"); + UNIT_EXPECT_TRUE(contains(result_names, item->name())); +// UNIT_ASSERT_EQUAL(item.height(), 180U); // UNIT_ASSERT_EQUAL(item.birthdate(), matador::date(12, 3, 1980), "expected birthdate is 12.3.1980"); } - UNIT_ASSERT_EQUAL(size, 2U, "result size must be two (2)"); + UNIT_ASSERT_EQUAL(size, 2U); res = q.select().where(name == "heinz").execute(connection_); - UNIT_ASSERT_TRUE(res.begin() == res.end(), "begin must be equal end"); + UNIT_ASSERT_TRUE(res.begin() == res.end()); q.drop().execute(connection_); @@ -884,7 +880,7 @@ void QueryTestUnit::test_query_select() res = q.select().execute(connection_); -// UNIT_ASSERT_EQUAL(res.size(), 4UL, "result size must be one (4)"); +// UNIT_ASSERT_EQUAL(res.size(), 4UL); auto first = res.begin(); auto last = res.end(); @@ -897,7 +893,7 @@ void QueryTestUnit::test_query_select() column name("name"); res = q.select().where(name == "Hans").execute(connection_); -// UNIT_ASSERT_EQUAL(res.size(), 1UL, "result size must be one (1)"); +// UNIT_ASSERT_EQUAL(res.size(), 1UL); first = res.begin(); last = res.end(); @@ -905,9 +901,9 @@ void QueryTestUnit::test_query_select() while (first != last) { std::unique_ptr item(first.release()); - UNIT_ASSERT_EQUAL(item->name(), "Hans", "expected name must be 'Hans'"); - UNIT_ASSERT_EQUAL(item->height(), 180U, "expected height must be 180"); - UNIT_ASSERT_EQUAL(item->birthdate(), matador::date(12, 3, 1980), "expected birthdate is 12.3.1980"); + UNIT_ASSERT_EQUAL(item->name(), "Hans"); + UNIT_ASSERT_EQUAL(item->height(), 180U); + UNIT_ASSERT_EQUAL(item->birthdate(), matador::date(12, 3, 1980)); ++first; } @@ -921,8 +917,8 @@ void QueryTestUnit::test_query_select() std::unique_ptr item(first.release()); if (is_first) { - UNIT_ASSERT_EQUAL(item->name(), "Otto", "expected name must be 'Otto'"); - UNIT_ASSERT_EQUAL(item->height(), 159U, "expected height must be 159"); + UNIT_ASSERT_EQUAL(item->name(), "Otto"); + UNIT_ASSERT_EQUAL(item->height(), 159U); is_first = false; } @@ -936,7 +932,7 @@ void QueryTestUnit::test_query_select() .desc() .execute(connection_); -// UNIT_ASSERT_EQUAL(res.size(), 2UL, "result size must be one (2)"); +// UNIT_ASSERT_EQUAL(res.size(), 2UL); first = res.begin(); @@ -945,8 +941,8 @@ void QueryTestUnit::test_query_select() std::unique_ptr item(first.release()); if (is_first) { - UNIT_ASSERT_EQUAL(item->name(), "Hilde", "expected name must be 'Hilde'"); - UNIT_ASSERT_EQUAL(item->height(), 175U, "expected height must be 175"); + UNIT_ASSERT_EQUAL(item->name(), "Hilde"); + UNIT_ASSERT_EQUAL(item->height(), 175U); is_first = false; } @@ -989,7 +985,7 @@ void QueryTestUnit::test_query_select_count() while (first != last) { std::unique_ptr item(first.release()); - UNIT_EXPECT_EQUAL(2, item->at(0), "invalid value"); + UNIT_EXPECT_EQUAL(2, item->at(0)); ++first; } @@ -1031,8 +1027,8 @@ void QueryTestUnit::test_query_select_columns() while (first != last) { std::unique_ptr item(first.release()); - UNIT_EXPECT_EQUAL(1L, item->at("id"), "invalid value"); - UNIT_EXPECT_EQUAL("Hans", item->at(name.name), "invalid value"); + UNIT_EXPECT_EQUAL(1L, item->at("id")); + UNIT_EXPECT_EQUAL("Hans", item->at(name.name)); ++first; } @@ -1120,7 +1116,7 @@ void QueryTestUnit::test_update_limit() matador::column owner("owner_id"); matador::column item("item_id"); relation::t_id newid(4UL); - q.update({{item.name, newid}}).where(owner == 1 && item == 1).limit(1); + q.update({{item.name, newid}}).where("owner_id"_col == 1 && item == 1).limit(1); res = q.execute(connection_); @@ -1143,13 +1139,13 @@ void QueryTestUnit::test_prepared_statement() stmt.execute(); - UNIT_ASSERT_TRUE(connection_.exists("person"), "table person must exist"); + UNIT_ASSERT_TRUE(connection_.exists("person")); auto fields = connection_.describe("person"); auto cols = { "id", "name", "age" }; for (const auto &fld : fields) { - UNIT_EXPECT_FALSE(std::find(cols.begin(), cols.end(), fld.name()) == cols.end(), "couldn't find expected field"); + UNIT_EXPECT_FALSE(std::find(cols.begin(), cols.end(), fld.name()) == cols.end()); } q.drop().execute(); @@ -1167,7 +1163,7 @@ void QueryTestUnit::test_prepared_statement_creation() stmt.execute(); - UNIT_ASSERT_TRUE(connection_.exists("person"), "table person must exist"); + UNIT_ASSERT_TRUE(connection_.exists("person")); q.drop().execute(); } @@ -1184,7 +1180,7 @@ void QueryTestUnit::test_prepared_object_result_twice() stmt.execute(); - UNIT_ASSERT_TRUE(connection_.exists("person"), "table person must exist"); + UNIT_ASSERT_TRUE(connection_.exists("person")); std::vector names({ "hans", "otto", "georg", "hilde" }); @@ -1207,7 +1203,7 @@ void QueryTestUnit::test_prepared_object_result_twice() for (auto p : result) { auto i = nameset.find(p->name()); - UNIT_EXPECT_TRUE(i != nameset.end(), "name " + p->name() + " not found"); + UNIT_EXPECT_TRUE(i != nameset.end()); nameset.erase(i); } } @@ -1225,7 +1221,7 @@ void QueryTestUnit::test_prepared_object_result_twice() for (auto p : result) { auto i = nameset.find(p->name()); - UNIT_EXPECT_TRUE(i != nameset.end(), "name " + p->name() + " not found"); + UNIT_EXPECT_TRUE(i != nameset.end()); nameset.erase(i); } } @@ -1263,7 +1259,7 @@ void QueryTestUnit::test_prepared_scalar_result_twice() for (auto p : result) { auto i = idset.find(p->at("id")); - UNIT_EXPECT_TRUE(i != idset.end(), "id " + p->str("id") + " not found"); + UNIT_EXPECT_TRUE(i != idset.end()); idset.erase(i); } // } @@ -1278,7 +1274,7 @@ void QueryTestUnit::test_prepared_scalar_result_twice() for (auto p : result) { auto i = idset.find(p->at("id")); - UNIT_EXPECT_TRUE(i != idset.end(), "id " + p->str("id") + " not found"); + UNIT_EXPECT_TRUE(i != idset.end()); idset.erase(i); } // } @@ -1308,11 +1304,11 @@ void QueryTestUnit::test_rows() q.execute(); - UNIT_ASSERT_TRUE(connection_.exists("item"), "table item must exist"); + UNIT_ASSERT_TRUE(connection_.exists("item")); auto fields = connection_.describe("item"); for (const auto &fld : fields) { - UNIT_EXPECT_FALSE(std::find(cols.begin(), cols.end(), fld.name()) == cols.end(), "couldn't find expected field"); + UNIT_EXPECT_FALSE(std::find(cols.begin(), cols.end(), fld.name()) == cols.end()); } q @@ -1323,11 +1319,11 @@ void QueryTestUnit::test_rows() auto res = q.select({"id", "string", "varchar", "int", "float", "double"}).from("item").execute(); for (auto item : res) { - UNIT_EXPECT_EQUAL(1L, item->at("id"), "invalid value"); - UNIT_EXPECT_EQUAL("long text", item->at("string"), "invalid value"); - UNIT_EXPECT_EQUAL(-17, item->at("int"), "invalid value"); - UNIT_EXPECT_EQUAL(3.1415f, item->at("float"), "invalid value"); - UNIT_EXPECT_EQUAL(2.71828, item->at("double"), "invalid value"); + UNIT_EXPECT_EQUAL(1L, item->at("id")); + UNIT_EXPECT_EQUAL("long text", item->at("string")); + UNIT_EXPECT_EQUAL(-17, item->at("int")); + UNIT_EXPECT_EQUAL(3.1415f, item->at("float")); + UNIT_EXPECT_EQUAL(2.71828, item->at("double")); } q.drop("item").execute(); diff --git a/test/sql/QueryTestUnit.hpp b/test/sql/QueryTestUnit.hpp index d7865f867..0958fd597 100644 --- a/test/sql/QueryTestUnit.hpp +++ b/test/sql/QueryTestUnit.hpp @@ -17,7 +17,10 @@ class connection; class QueryTestUnit : public matador::unit_test { public: - QueryTestUnit(const std::string &name, const std::string &msg, const std::string &db = "memory", const matador::time &timeval = matador::time(2015, 3, 15, 13, 56, 23, 123)); + QueryTestUnit( + const std::string &name, const std::string &msg, std::string db = "memory", + matador::time timeval = matador::time(2015, 3, 15, 13, 56, 23, 123) + ); void initialize() override; diff --git a/test/sql/SQLiteDialectTestUnit.cpp b/test/sql/SQLiteDialectTestUnit.cpp index e07685358..701424a9e 100644 --- a/test/sql/SQLiteDialectTestUnit.cpp +++ b/test/sql/SQLiteDialectTestUnit.cpp @@ -45,7 +45,7 @@ void SQLiteDialectTestUnit::test_update_with_limit() std::string result = conn.dialect()->direct(s); - UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"='Dieter', \"age\"=54 WHERE \"rowid\" IN (SELECT \"rowid\" FROM \"person\" WHERE \"name\" <> 'Hans' LIMIT 1 ) ", result, "update where isn't as expected"); + UNIT_ASSERT_EQUAL("UPDATE \"person\" SET \"name\"='Dieter', \"age\"=54 WHERE \"rowid\" IN (SELECT \"rowid\" FROM \"person\" WHERE \"name\" <> 'Hans' LIMIT 1 ) ", result); } void SQLiteDialectTestUnit::test_delete_with_limit() @@ -64,5 +64,5 @@ void SQLiteDialectTestUnit::test_delete_with_limit() std::string result = conn.dialect()->direct(s); - UNIT_ASSERT_EQUAL("DELETE FROM \"person\" WHERE \"rowid\" IN (SELECT \"rowid\" FROM \"person\" WHERE \"name\" <> 'Hans' LIMIT 1 ) ", result, "delete where isn't as expected"); + UNIT_ASSERT_EQUAL("DELETE FROM \"person\" WHERE \"rowid\" IN (SELECT \"rowid\" FROM \"person\" WHERE \"name\" <> 'Hans' LIMIT 1 ) ", result); } diff --git a/test/test_matador.cpp b/test/test_matador.cpp index 119a24cef..07a15ade2 100644 --- a/test/test_matador.cpp +++ b/test/test_matador.cpp @@ -48,18 +48,10 @@ #include "sql/QueryTestUnit.hpp" #include "sql/ConditionUnitTest.hpp" #include "sql/MSSQLDialectTestUnit.hpp" +#include "sql/PostgreSQLDialectTestUnit.hpp" #include "sql/SQLiteDialectTestUnit.hpp" #include "connections.hpp" - -#ifdef OOS_MYSQL -#ifdef WIN32 -#include -#else -#include -#endif -#endif - #include // EXIT_SUCCESS using namespace matador; @@ -138,6 +130,16 @@ int main(int argc, char *argv[]) suite.register_unit(new SQLiteDialectTestUnit()); #endif +#if defined(MATADOR_POSTGRESQL) && defined(MATADOR_POSTGRESQL_TEST) + suite.register_unit(new ConnectionTestUnit("postgresql_conn", "postgresql connection test unit", ::connection::postgresql)); + suite.register_unit(new TransactionTestUnit("postgresql_transaction", "postgresql transaction test unit", ::connection::postgresql)); + suite.register_unit(new QueryTestUnit("postgresql_query", "postgresql query test unit", ::connection::postgresql)); + suite.register_unit(new OrmTestUnit("postgresql", ::connection::postgresql)); + suite.register_unit(new OrmReloadTestUnit("postgresql", ::connection::postgresql)); + suite.register_unit(new OrmRelationTestUnit("postgresql", ::connection::postgresql)); + suite.register_unit(new PostgreSQLDialectTestUnit()); +#endif + //suite.register_unit(new TransactionTestUnit("memory_transaction", "memory transaction test unit")); result = suite.run(); diff --git a/test/unit/FirstTestUnit.hpp b/test/unit/FirstTestUnit.hpp index b9dd4b7a2..69ec2473c 100644 --- a/test/unit/FirstTestUnit.hpp +++ b/test/unit/FirstTestUnit.hpp @@ -33,22 +33,22 @@ class FirstTestUnit : public matador::unit_test void first_sub_test() { - UNIT_ASSERT_EQUAL(1, 1, "one is one"); + UNIT_ASSERT_EQUAL(1, 1); try { - UNIT_ASSERT_EQUAL(1, 0, "one is not zero"); + UNIT_ASSERT_EQUAL(1, 0); } catch (matador::unit_exception &) { - UNIT_ASSERT_TRUE(true, "could not happen"); + UNIT_ASSERT_TRUE(true); } } void second_sub_test() { // gives warning //UNIT_WARN("this is a test warning!"); - UNIT_ASSERT_TRUE(true, "test should be executed"); + UNIT_ASSERT_TRUE(true); } void third_sub_test() { - UNIT_ASSERT_TRUE(true, "test should be executed"); + UNIT_ASSERT_TRUE(true); } }; diff --git a/test/unit/SecondTestUnit.hpp b/test/unit/SecondTestUnit.hpp index 42ea6a04a..599f1f6a5 100644 --- a/test/unit/SecondTestUnit.hpp +++ b/test/unit/SecondTestUnit.hpp @@ -31,10 +31,10 @@ class SecondTestUnit : public matador::unit_test void small_test() { - UNIT_ASSERT_TRUE(true, "test should be executed"); + UNIT_ASSERT_TRUE(true); } void big_test() { - UNIT_ASSERT_TRUE(true, "test should be executed"); + UNIT_ASSERT_TRUE(true); } }; diff --git a/test/utils/AnyTestUnit.cpp b/test/utils/AnyTestUnit.cpp index 38004accd..d8cd1654a 100644 --- a/test/utils/AnyTestUnit.cpp +++ b/test/utils/AnyTestUnit.cpp @@ -52,19 +52,19 @@ void AnyTestUnit::test_any_visitor() visitor.visit(as); - UNIT_ASSERT_EQUAL(2, as._(), "values must be equal"); + UNIT_ASSERT_EQUAL(2, as._()); visitor.visit(ai); - UNIT_ASSERT_EQUAL(8, ai._(), "values must be equal"); + UNIT_ASSERT_EQUAL(8, ai._()); visitor.visit(al); - UNIT_ASSERT_EQUAL(14L, al._(), "values must be equal"); + UNIT_ASSERT_EQUAL(14L, al._()); visitor.visit(astr); - UNIT_ASSERT_EQUAL("welt", astr._(), "values must be equal"); + UNIT_ASSERT_EQUAL("welt", astr._()); } struct processor @@ -110,16 +110,16 @@ void AnyTestUnit::test_any_visitor_class() matador::any astr(std::string("hello")); processor p; - UNIT_ASSERT_EQUAL(7, ai._(), "values must be equal"); + UNIT_ASSERT_EQUAL(7, ai._()); p.apply(ai); - UNIT_ASSERT_EQUAL(8, ai._(), "values must be equal"); - UNIT_ASSERT_EQUAL(13L, al._(), "values must be equal"); + UNIT_ASSERT_EQUAL(8, ai._()); + UNIT_ASSERT_EQUAL(13L, al._()); p.apply(al); - UNIT_ASSERT_EQUAL(14L, al._(), "values must be equal"); - UNIT_ASSERT_EQUAL(0.4f, af._(), "values must be equal"); + UNIT_ASSERT_EQUAL(14L, al._()); + UNIT_ASSERT_EQUAL(0.4f, af._()); p.apply(af); - UNIT_ASSERT_EQUAL(0.5f, af._(), "values must be equal"); - UNIT_ASSERT_EQUAL("hello", astr._(), "values must be equal"); + UNIT_ASSERT_EQUAL(0.5f, af._()); + UNIT_ASSERT_EQUAL("hello", astr._()); p.apply(astr); - UNIT_ASSERT_EQUAL("world", astr._(), "values must be equal"); + UNIT_ASSERT_EQUAL("world", astr._()); } diff --git a/test/utils/BlobTestUnit.cpp b/test/utils/BlobTestUnit.cpp index 0a7b91a1d..d3b4735eb 100644 --- a/test/utils/BlobTestUnit.cpp +++ b/test/utils/BlobTestUnit.cpp @@ -20,16 +20,16 @@ void BlobTestUnit::test_create() b1.append(val); b1.append(val); - UNIT_ASSERT_EQUAL(b1.size(), 8UL, "invalid size"); + UNIT_ASSERT_EQUAL(b1.size(), 8UL); blob b2; b2.append(val); b2.append(val); - UNIT_ASSERT_EQUAL(b2.size(), 8UL, "invalid size"); + UNIT_ASSERT_EQUAL(b2.size(), 8UL); const unsigned char *data = b1.data(); - UNIT_ASSERT_TRUE(data != nullptr, "data must be valid pointer"); + UNIT_ASSERT_TRUE(data != nullptr); } diff --git a/test/utils/DateTestUnit.cpp b/test/utils/DateTestUnit.cpp index 84505e649..da7eea9a1 100644 --- a/test/utils/DateTestUnit.cpp +++ b/test/utils/DateTestUnit.cpp @@ -27,7 +27,7 @@ DateTestUnit::DateTestUnit() void DateTestUnit::test_create() { - time_t t = std::time(0); + time_t t = std::time(nullptr); #ifdef _MSC_VER struct tm *tt = new tm; localtime_s(tt, &t); @@ -37,30 +37,30 @@ void DateTestUnit::test_create() date now; - UNIT_ASSERT_EQUAL(tt->tm_year + 1900, now.year(), "year isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_mon + 1, now.month(), "month of year isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_mday, now.day(), "day of month isn't equal"); + UNIT_ASSERT_EQUAL(tt->tm_year + 1900, now.year()); + UNIT_ASSERT_EQUAL(tt->tm_mon + 1, now.month()); + UNIT_ASSERT_EQUAL(tt->tm_mday, now.day()); } void DateTestUnit::test_parse() { date d = date::parse("13-11-1979", "%d-%m-%Y"); - UNIT_ASSERT_EQUAL(d.day(), 13, "invalid day"); - UNIT_ASSERT_EQUAL(d.month(), 11, "invalid day"); - UNIT_ASSERT_EQUAL(d.year(), 1979, "invalid day"); + UNIT_ASSERT_EQUAL(d.day(), 13); + UNIT_ASSERT_EQUAL(d.month(), 11); + UNIT_ASSERT_EQUAL(d.year(), 1979); d = date::parse("2000-11-24", date_format::ISO8601); - UNIT_ASSERT_EQUAL(d.day(), 24, "invalid day"); - UNIT_ASSERT_EQUAL(d.month(), 11, "invalid day"); - UNIT_ASSERT_EQUAL(d.year(), 2000, "invalid day"); + UNIT_ASSERT_EQUAL(d.day(), 24); + UNIT_ASSERT_EQUAL(d.month(), 11); + UNIT_ASSERT_EQUAL(d.year(), 2000); d.set("12/23/2012", "%m/%d/%Y"); - UNIT_ASSERT_EQUAL(d.day(), 23, "invalid day"); - UNIT_ASSERT_EQUAL(d.month(), 12, "invalid day"); - UNIT_ASSERT_EQUAL(d.year(), 2012, "invalid day"); + UNIT_ASSERT_EQUAL(d.day(), 23); + UNIT_ASSERT_EQUAL(d.month(), 12); + UNIT_ASSERT_EQUAL(d.year(), 2012); } void DateTestUnit::test_julian_date() @@ -68,30 +68,30 @@ void DateTestUnit::test_julian_date() // 15.3.2015 date d(2457090); - UNIT_ASSERT_EQUAL(2015, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(8, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_FALSE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2015, d.year()); + UNIT_ASSERT_EQUAL(3, d.month()); + UNIT_ASSERT_EQUAL(8, d.day()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_FALSE(d.is_daylight_saving()); } void DateTestUnit::test_initialize() { date d(8, 3, 2015); - UNIT_ASSERT_EQUAL(2015, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(8, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2457090, d.julian_date(), "julian date isn't equal 2457090"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_FALSE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2015, d.year()); + UNIT_ASSERT_EQUAL(3, d.month()); + UNIT_ASSERT_EQUAL(8, d.day()); + UNIT_ASSERT_EQUAL(2457090, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_FALSE(d.is_daylight_saving()); } void DateTestUnit::test_invalid() { - UNIT_ASSERT_EXCEPTION(date d(42, 12, 2015), std::logic_error, "date isn't valid", "date should not be valid"); - UNIT_ASSERT_EXCEPTION(date d(31, 13, 2015), std::logic_error, "date isn't valid", "date should not be valid"); - UNIT_ASSERT_EXCEPTION(date d(29, 2, 2015), std::logic_error, "date isn't valid", "date should not be valid"); + UNIT_ASSERT_EXCEPTION(date d(42, 12, 2015), std::logic_error, "date isn't valid"); + UNIT_ASSERT_EXCEPTION(date d(31, 13, 2015), std::logic_error, "date isn't valid"); + UNIT_ASSERT_EXCEPTION(date d(29, 2, 2015), std::logic_error, "date isn't valid"); } void DateTestUnit::test_copy() @@ -100,13 +100,13 @@ void DateTestUnit::test_copy() date d2(d1); - UNIT_ASSERT_TRUE(d1 == d2, "dates must be equal"); - UNIT_ASSERT_EQUAL(2015, d2.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d2.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(8, d2.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2457090, d2.julian_date(), "julian date isn't equal 2457090"); - UNIT_ASSERT_FALSE(d2.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_FALSE(d2.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_TRUE(d1 == d2); + UNIT_ASSERT_EQUAL(2015, d2.year()); + UNIT_ASSERT_EQUAL(3, d2.month()); + UNIT_ASSERT_EQUAL(8, d2.day()); + UNIT_ASSERT_EQUAL(2457090, d2.julian_date()); + UNIT_ASSERT_FALSE(d2.is_leapyear()); + UNIT_ASSERT_FALSE(d2.is_daylight_saving()); } void DateTestUnit::test_assign() @@ -116,13 +116,13 @@ void DateTestUnit::test_assign() date d2; d2 = d1; - UNIT_ASSERT_TRUE(d1 == d2, "dates must be equal"); - UNIT_ASSERT_EQUAL(2015, d2.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d2.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(8, d2.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2457090, d2.julian_date(), "julian date isn't equal 2457090"); - UNIT_ASSERT_FALSE(d2.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_FALSE(d2.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_TRUE(d1 == d2); + UNIT_ASSERT_EQUAL(2015, d2.year()); + UNIT_ASSERT_EQUAL(3, d2.month()); + UNIT_ASSERT_EQUAL(8, d2.day()); + UNIT_ASSERT_EQUAL(2457090, d2.julian_date()); + UNIT_ASSERT_FALSE(d2.is_leapyear()); + UNIT_ASSERT_FALSE(d2.is_daylight_saving()); } void DateTestUnit::test_compare() @@ -131,14 +131,14 @@ void DateTestUnit::test_compare() date d2(27, 8, 2014); date d3(d1); - UNIT_ASSERT_TRUE(d1 > d2, "d1 is greater than d2"); - UNIT_ASSERT_TRUE(d2 < d1, "d2 is less than d1"); - UNIT_ASSERT_TRUE(d2 != d1, "d1 is not equal d2"); - UNIT_ASSERT_TRUE(d3 == d1, "d1 is equal d3"); - UNIT_ASSERT_TRUE(d1 >= d2, "d1 is greater equal than d2"); - UNIT_ASSERT_TRUE(d2 <= d1, "d2 is less equal than d1"); - UNIT_ASSERT_TRUE(d1 >= d3, "d1 is greater equal than d2"); - UNIT_ASSERT_TRUE(d3 <= d1, "d2 is less equal than d1"); + UNIT_ASSERT_TRUE(d1 > d2); + UNIT_ASSERT_TRUE(d2 < d1); + UNIT_ASSERT_TRUE(d2 != d1); + UNIT_ASSERT_TRUE(d3 == d1); + UNIT_ASSERT_TRUE(d1 >= d2); + UNIT_ASSERT_TRUE(d2 <= d1); + UNIT_ASSERT_TRUE(d1 >= d3); + UNIT_ASSERT_TRUE(d3 <= d1); } void DateTestUnit::test_set() @@ -147,126 +147,126 @@ void DateTestUnit::test_set() d.set(8, 3, 2015); - UNIT_ASSERT_EQUAL(2015, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(8, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2457090, d.julian_date(), "julian date isn't equal 2457090"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_FALSE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2015, d.year()); + UNIT_ASSERT_EQUAL(3, d.month()); + UNIT_ASSERT_EQUAL(8, d.day()); + UNIT_ASSERT_EQUAL(2457090, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_FALSE(d.is_daylight_saving()); } void DateTestUnit::test_modify() { date d(8, 3, 2015); - UNIT_ASSERT_EQUAL(2015, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(8, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2457090, d.julian_date(), "julian date isn't equal 2457090"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_FALSE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2015, d.year()); + UNIT_ASSERT_EQUAL(3, d.month()); + UNIT_ASSERT_EQUAL(8, d.day()); + UNIT_ASSERT_EQUAL(2457090, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_FALSE(d.is_daylight_saving()); d.day(3).month(4); - UNIT_ASSERT_EQUAL(2015, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(4, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(3, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2457116, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2015, d.year()); + UNIT_ASSERT_EQUAL(4, d.month()); + UNIT_ASSERT_EQUAL(3, d.day()); + UNIT_ASSERT_EQUAL(2457116, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); d.year(2014); - UNIT_ASSERT_EQUAL(2014, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(4, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(3, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456751, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2014, d.year()); + UNIT_ASSERT_EQUAL(4, d.month()); + UNIT_ASSERT_EQUAL(3, d.day()); + UNIT_ASSERT_EQUAL(2456751, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); d = d + 5; - UNIT_ASSERT_EQUAL(2014, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(4, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(8, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456756, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2014, d.year()); + UNIT_ASSERT_EQUAL(4, d.month()); + UNIT_ASSERT_EQUAL(8, d.day()); + UNIT_ASSERT_EQUAL(2456756, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); d = d - 2; - UNIT_ASSERT_EQUAL(2014, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(4, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(6, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456754, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2014, d.year()); + UNIT_ASSERT_EQUAL(4, d.month()); + UNIT_ASSERT_EQUAL(6, d.day()); + UNIT_ASSERT_EQUAL(2456754, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); d += 7; - UNIT_ASSERT_EQUAL(2014, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(4, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(13, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456761, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2014, d.year()); + UNIT_ASSERT_EQUAL(4, d.month()); + UNIT_ASSERT_EQUAL(13, d.day()); + UNIT_ASSERT_EQUAL(2456761, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); d -= 13; - UNIT_ASSERT_EQUAL(2014, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(31, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456748, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2014, d.year()); + UNIT_ASSERT_EQUAL(3, d.month()); + UNIT_ASSERT_EQUAL(31, d.day()); + UNIT_ASSERT_EQUAL(2456748, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); date d1 = d++; - UNIT_ASSERT_EQUAL(2014, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(4, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(1, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456749, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); - UNIT_ASSERT_EQUAL(2014, d1.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d1.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(31, d1.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456748, d1.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d1.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d1.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2014, d.year()); + UNIT_ASSERT_EQUAL(4, d.month()); + UNIT_ASSERT_EQUAL(1, d.day()); + UNIT_ASSERT_EQUAL(2456749, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); + UNIT_ASSERT_EQUAL(2014, d1.year()); + UNIT_ASSERT_EQUAL(3, d1.month()); + UNIT_ASSERT_EQUAL(31, d1.day()); + UNIT_ASSERT_EQUAL(2456748, d1.julian_date()); + UNIT_ASSERT_FALSE(d1.is_leapyear()); + UNIT_ASSERT_TRUE(d1.is_daylight_saving()); d1 = d--; - UNIT_ASSERT_EQUAL(2014, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(31, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456748, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); - UNIT_ASSERT_EQUAL(2014, d1.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(4, d1.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(1, d1.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456749, d1.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d1.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d1.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2014, d.year()); + UNIT_ASSERT_EQUAL(3, d.month()); + UNIT_ASSERT_EQUAL(31, d.day()); + UNIT_ASSERT_EQUAL(2456748, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); + UNIT_ASSERT_EQUAL(2014, d1.year()); + UNIT_ASSERT_EQUAL(4, d1.month()); + UNIT_ASSERT_EQUAL(1, d1.day()); + UNIT_ASSERT_EQUAL(2456749, d1.julian_date()); + UNIT_ASSERT_FALSE(d1.is_leapyear()); + UNIT_ASSERT_TRUE(d1.is_daylight_saving()); ++d; - UNIT_ASSERT_EQUAL(2014, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(4, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(1, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456749, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2014, d.year()); + UNIT_ASSERT_EQUAL(4, d.month()); + UNIT_ASSERT_EQUAL(1, d.day()); + UNIT_ASSERT_EQUAL(2456749, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); --d; - UNIT_ASSERT_EQUAL(2014, d.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(3, d.month(), "month of year isn't equal 3"); - UNIT_ASSERT_EQUAL(31, d.day(), "day of month isn't equal 15"); - UNIT_ASSERT_EQUAL(2456748, d.julian_date(), "julian date isn't equal 2457116"); - UNIT_ASSERT_FALSE(d.is_leapyear(), "year isn't a leapp year"); - UNIT_ASSERT_TRUE(d.is_daylight_saving(), "date is inside daylight saving period"); + UNIT_ASSERT_EQUAL(2014, d.year()); + UNIT_ASSERT_EQUAL(3, d.month()); + UNIT_ASSERT_EQUAL(31, d.day()); + UNIT_ASSERT_EQUAL(2456748, d.julian_date()); + UNIT_ASSERT_FALSE(d.is_leapyear()); + UNIT_ASSERT_TRUE(d.is_daylight_saving()); } void DateTestUnit::test_difference() @@ -275,7 +275,7 @@ void DateTestUnit::test_difference() date d2(1, 6, 2015); int diff = d2.difference(d1); - UNIT_ASSERT_EQUAL(diff, 29, "difference between d1 and d2 must be 29 days"); + UNIT_ASSERT_EQUAL(diff, 29); } void DateTestUnit::test_to_string() @@ -284,5 +284,5 @@ void DateTestUnit::test_to_string() std::string str = matador::to_string(d1); - UNIT_ASSERT_EQUAL(str, "2015-06-30", "result must be '2015-06-30'"); + UNIT_ASSERT_EQUAL(str, "2015-06-30"); } diff --git a/test/utils/FactoryTestUnit.cpp b/test/utils/FactoryTestUnit.cpp index 60351fce5..edab4ce48 100644 --- a/test/utils/FactoryTestUnit.cpp +++ b/test/utils/FactoryTestUnit.cpp @@ -60,11 +60,11 @@ FactoryTestUnit::FactoryTestUnit() void FactoryTestUnit::create_factory() { typedef factory vehicle_factory_t; - vehicle_factory_t *vfac = new vehicle_factory_t; + auto *vfac = new vehicle_factory_t; - UNIT_ASSERT_NOT_NULL(vfac, "factory pointer must be valid"); - UNIT_ASSERT_TRUE(vfac->empty(), "factory should be empty"); - UNIT_ASSERT_EQUAL((int)vfac->size(), 0, "size of factory must be zero"); + UNIT_ASSERT_NOT_NULL(vfac); + UNIT_ASSERT_TRUE(vfac->empty()); + UNIT_ASSERT_EQUAL((int)vfac->size(), 0); delete vfac; } @@ -74,8 +74,8 @@ void FactoryTestUnit::insert_items() typedef factory vehicle_factory; vehicle_factory vfac; - UNIT_ASSERT_TRUE(vfac.empty(), "factory should be empty"); - UNIT_ASSERT_EQUAL((int)vfac.size(), 0, "size of factory must be zero"); + UNIT_ASSERT_TRUE(vfac.empty()); + UNIT_ASSERT_EQUAL((int)vfac.size(), 0); vfac.insert("plane", new vehicle_factory::default_producer); @@ -83,8 +83,8 @@ void FactoryTestUnit::insert_items() vfac.insert("car", new vehicle_factory::default_producer); vfac.insert("ship", new vehicle_factory::default_producer); - UNIT_ASSERT_FALSE(vfac.empty(), "factory must not be empty"); - UNIT_ASSERT_EQUAL((int)vfac.size(), 4, "size of factory must be four"); + UNIT_ASSERT_FALSE(vfac.empty()); + UNIT_ASSERT_EQUAL((int)vfac.size(), 4); } void FactoryTestUnit::produce_items() @@ -99,8 +99,8 @@ void FactoryTestUnit::produce_items() Vehicle *vec = vfac.create("car"); - UNIT_ASSERT_NOT_NULL(vec, "produced item must not be zero"); - UNIT_ASSERT_EQUAL(vec->type(), "car", "invalid produced item"); + UNIT_ASSERT_NOT_NULL(vec); + UNIT_ASSERT_EQUAL(vec->type(), "car"); delete vec; } @@ -118,7 +118,7 @@ void FactoryTestUnit::list_items() vehicle_factory::const_iterator first = vfac.begin(); vehicle_factory::const_iterator last = vfac.end(); - UNIT_ASSERT_FALSE(first == last, "iterators must not be the same"); + UNIT_ASSERT_FALSE(first == last); - UNIT_ASSERT_EQUAL(vfac.size(), (size_t)4, "size of factory must be 4 (four)"); + UNIT_ASSERT_EQUAL(vfac.size(), (size_t)4); } diff --git a/test/utils/SequencerTestUnit.cpp b/test/utils/SequencerTestUnit.cpp index 7a2eb1916..710232fd3 100644 --- a/test/utils/SequencerTestUnit.cpp +++ b/test/utils/SequencerTestUnit.cpp @@ -13,13 +13,11 @@ SequencerTestUnit::SequencerTestUnit() : unit_test("sequencer", "sequencer test add_test("exchange", std::bind(&SequencerTestUnit::test_reset, this), "exchange sequencer"); } -SequencerTestUnit::~SequencerTestUnit() {} - void SequencerTestUnit::test_init() { matador::sequencer seq; - UNIT_ASSERT_EQUAL(seq.init(), 0UL, "invalid value"); + UNIT_ASSERT_EQUAL(seq.init(), 0UL); } void SequencerTestUnit::test_inc() @@ -28,9 +26,9 @@ void SequencerTestUnit::test_inc() seq.init(); - UNIT_ASSERT_EQUAL(seq.current(), 0UL, "invalid value"); - UNIT_ASSERT_EQUAL(seq.next(), 1UL, "invalid value"); - UNIT_ASSERT_EQUAL(seq.update(5), 5UL, "invalid value"); + UNIT_ASSERT_EQUAL(seq.current(), 0UL); + UNIT_ASSERT_EQUAL(seq.next(), 1UL); + UNIT_ASSERT_EQUAL(seq.update(5), 5UL); } void SequencerTestUnit::test_reset() @@ -39,9 +37,9 @@ void SequencerTestUnit::test_reset() seq.init(); - UNIT_ASSERT_EQUAL(seq.current(), 0UL, "invalid value"); - UNIT_ASSERT_EQUAL(seq.next(), 1UL, "invalid value"); - UNIT_ASSERT_EQUAL(seq.reset(3), 3UL, "invalid value"); + UNIT_ASSERT_EQUAL(seq.current(), 0UL); + UNIT_ASSERT_EQUAL(seq.next(), 1UL); + UNIT_ASSERT_EQUAL(seq.reset(3), 3UL); } void SequencerTestUnit::test_exchange() @@ -50,13 +48,13 @@ void SequencerTestUnit::test_exchange() seq.init(); - UNIT_ASSERT_EQUAL(seq.current(), 0UL, "invalid value"); - UNIT_ASSERT_EQUAL(seq.next(), 1UL, "invalid value"); + UNIT_ASSERT_EQUAL(seq.current(), 0UL); + UNIT_ASSERT_EQUAL(seq.next(), 1UL); matador::sequencer_impl_ptr another_seq_ptr(new matador::default_sequencer); auto old_seq_ptr = seq.exchange_sequencer(another_seq_ptr); - UNIT_ASSERT_EQUAL(seq.current(), 0UL, "invalid value"); - UNIT_ASSERT_EQUAL(seq.next(), 1UL, "invalid value"); + UNIT_ASSERT_EQUAL(seq.current(), 0UL); + UNIT_ASSERT_EQUAL(seq.next(), 1UL); } diff --git a/test/utils/SequencerTestUnit.hpp b/test/utils/SequencerTestUnit.hpp index 922bd8693..3f3985f61 100644 --- a/test/utils/SequencerTestUnit.hpp +++ b/test/utils/SequencerTestUnit.hpp @@ -12,7 +12,7 @@ class SequencerTestUnit : public matador::unit_test { public: SequencerTestUnit(); - virtual ~SequencerTestUnit(); + ~SequencerTestUnit() override = default; void test_init(); void test_inc(); diff --git a/test/utils/StringTestUnit.cpp b/test/utils/StringTestUnit.cpp index 368da9f7e..d416787cd 100644 --- a/test/utils/StringTestUnit.cpp +++ b/test/utils/StringTestUnit.cpp @@ -21,8 +21,8 @@ void StringTestUnit::test_split() size_t count = matador::split(str, ',', strvec); - UNIT_ASSERT_EQUAL(count, (size_t)5, "expected count must be 5"); - UNIT_ASSERT_EQUAL(strvec.size(), (size_t)5, "expected vector size must be 5"); + UNIT_ASSERT_EQUAL(count, (size_t)5); + UNIT_ASSERT_EQUAL(strvec.size(), (size_t)5); } void StringTestUnit::test_trim() @@ -31,9 +31,9 @@ void StringTestUnit::test_trim() std::string result = matador::trim(str); - UNIT_ASSERT_EQUAL(result, "middle", "expect string must be 'middle'"); + UNIT_ASSERT_EQUAL(result, "middle"); result = matador::trim(str, "-"); - UNIT_ASSERT_EQUAL(result, str, "expect string must be '" + str + "'"); + UNIT_ASSERT_EQUAL(result, str); } diff --git a/test/utils/TimeTestUnit.cpp b/test/utils/TimeTestUnit.cpp index 7f91ceba8..444d5992d 100644 --- a/test/utils/TimeTestUnit.cpp +++ b/test/utils/TimeTestUnit.cpp @@ -33,43 +33,40 @@ void TimeTestUnit::test_create() matador::time now(t); - UNIT_ASSERT_EQUAL(tt->tm_year + 1900, now.year(), "year isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_mon + 1, now.month(), "month of year isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_mday, now.day(), "day of month isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_hour, now.hour(), "hour of day isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_min, now.minute(), "minute of day isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_sec, now.second(), "second of day isn't equal"); + UNIT_ASSERT_EQUAL(tt->tm_year + 1900, now.year()); + UNIT_ASSERT_EQUAL(tt->tm_mon + 1, now.month()); + UNIT_ASSERT_EQUAL(tt->tm_mday, now.day()); + UNIT_ASSERT_EQUAL(tt->tm_hour, now.hour()); + UNIT_ASSERT_EQUAL(tt->tm_min, now.minute()); + UNIT_ASSERT_EQUAL(tt->tm_sec, now.second()); -#ifdef _MSC_VER - localtime_s(tt, &t); -#else - tt = localtime(&t); -#endif matador::time t1 = time::now(); - UNIT_ASSERT_EQUAL(tt->tm_year + 1900, t1.year(), "year isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_mon + 1, t1.month(), "month of year isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_mday, t1.day(), "day of month isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_hour, t1.hour(), "hour of day isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_min, t1.minute(), "minute of day isn't equal"); - UNIT_ASSERT_EQUAL(tt->tm_sec, t1.second(), "second of day isn't equal"); + struct tm ttt = t1.get_tm(); + + UNIT_ASSERT_EQUAL(ttt.tm_year + 1900, t1.year()); + UNIT_ASSERT_EQUAL(ttt.tm_mon + 1, t1.month()); + UNIT_ASSERT_EQUAL(ttt.tm_mday, t1.day()); + UNIT_ASSERT_EQUAL(ttt.tm_hour, t1.hour()); + UNIT_ASSERT_EQUAL(ttt.tm_min, t1.minute()); + UNIT_ASSERT_EQUAL(ttt.tm_sec, t1.second()); } void TimeTestUnit::test_initialize() { matador::time t1(2014, 12, 3, 20, 17, 45); - UNIT_ASSERT_EQUAL(2014, t1.year(), "year isn't equal 2014"); - UNIT_ASSERT_EQUAL(12, t1.month(), "month of year isn't equal 12"); - UNIT_ASSERT_EQUAL(3, t1.day(), "day of month isn't equal 3"); - UNIT_ASSERT_EQUAL(20, t1.hour(), "hour of day isn't equal 20"); - UNIT_ASSERT_EQUAL(17, t1.minute(), "minute day isn't equal 17"); - UNIT_ASSERT_EQUAL(45, t1.second(), "second of day isn't equal 45"); - UNIT_ASSERT_EQUAL(0, t1.milli_second(), "millisecond of day isn't equal 0"); - UNIT_ASSERT_EQUAL(3, t1.day_of_week(), "day of week isn't equal 0"); - UNIT_ASSERT_EQUAL(336, t1.day_of_year(), "day of week isn't equal 0"); - UNIT_ASSERT_FALSE(t1.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_FALSE(t1.is_leapyear(), "time stamp must not be a leap year"); + UNIT_ASSERT_EQUAL(2014, t1.year()); + UNIT_ASSERT_EQUAL(12, t1.month()); + UNIT_ASSERT_EQUAL(3, t1.day()); + UNIT_ASSERT_EQUAL(20, t1.hour()); + UNIT_ASSERT_EQUAL(17, t1.minute()); + UNIT_ASSERT_EQUAL(45, t1.second()); + UNIT_ASSERT_EQUAL(0, t1.milli_second()); + UNIT_ASSERT_EQUAL(3, t1.day_of_week()); + UNIT_ASSERT_EQUAL(336, t1.day_of_year()); + UNIT_ASSERT_FALSE(t1.is_daylight_saving()); + UNIT_ASSERT_FALSE(t1.is_leapyear()); time_t t; ::time(&t); @@ -90,26 +87,26 @@ void TimeTestUnit::test_initialize() matador::time t2(mktime(tt)); - UNIT_ASSERT_EQUAL(2014, t2.year(), "year isn't equal 2014"); - UNIT_ASSERT_EQUAL(12, t2.month(), "month of year isn't equal 12"); - UNIT_ASSERT_EQUAL(3, t2.day(), "day of month isn't equal 3"); - UNIT_ASSERT_EQUAL(20, t2.hour(), "hour of day isn't equal 20"); - UNIT_ASSERT_EQUAL(17, t2.minute(), "minute day isn't equal 17"); - UNIT_ASSERT_EQUAL(45, t2.second(), "second of day isn't equal 45"); - UNIT_ASSERT_EQUAL(0, t2.milli_second(), "millisecond of day isn't equal 0"); - UNIT_ASSERT_FALSE(t2.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_FALSE(t2.is_leapyear(), "time stamp must not be a leap year"); + UNIT_ASSERT_EQUAL(2014, t2.year()); + UNIT_ASSERT_EQUAL(12, t2.month()); + UNIT_ASSERT_EQUAL(3, t2.day()); + UNIT_ASSERT_EQUAL(20, t2.hour()); + UNIT_ASSERT_EQUAL(17, t2.minute()); + UNIT_ASSERT_EQUAL(45, t2.second()); + UNIT_ASSERT_EQUAL(0, t2.milli_second()); + UNIT_ASSERT_FALSE(t2.is_daylight_saving()); + UNIT_ASSERT_FALSE(t2.is_leapyear()); } void TimeTestUnit::test_invalid() { - UNIT_ASSERT_EXCEPTION(matador::time(2015, 12, 42, 12, 12, 12), std::logic_error, "date isn't valid", "date should not be valid"); - UNIT_ASSERT_EXCEPTION(matador::time(2015, 13, 31, 12, 12, 12), std::logic_error, "date isn't valid", "date should not be valid"); - UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 29, 12, 12, 12), std::logic_error, "date isn't valid", "date should not be valid"); - UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 28, 63, 12, 12), std::logic_error, "time isn't valid", "time should not be valid"); - UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 28, 12, 63, 12), std::logic_error, "time isn't valid", "time should not be valid"); - UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 28, 12, 12, 63), std::logic_error, "time isn't valid", "time should not be valid"); - UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 28, 12, 12, 12, 10000), std::logic_error, "time isn't valid", "time should not be valid"); + UNIT_ASSERT_EXCEPTION(matador::time(2015, 12, 42, 12, 12, 12), std::logic_error, "date isn't valid"); + UNIT_ASSERT_EXCEPTION(matador::time(2015, 13, 31, 12, 12, 12), std::logic_error, "date isn't valid"); + UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 29, 12, 12, 12), std::logic_error, "date isn't valid"); + UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 28, 63, 12, 12), std::logic_error, "time isn't valid"); + UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 28, 12, 63, 12), std::logic_error, "time isn't valid"); + UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 28, 12, 12, 63), std::logic_error, "time isn't valid"); + UNIT_ASSERT_EXCEPTION(matador::time(2015, 2, 28, 12, 12, 12, 10000), std::logic_error, "time isn't valid"); } void TimeTestUnit::test_copy() @@ -117,27 +114,27 @@ void TimeTestUnit::test_copy() matador::time t1(2014, 12, 3, 20, 17, 45); matador::time t2(t1); - UNIT_ASSERT_EQUAL(2014, t1.year(), "year isn't equal 2014"); - UNIT_ASSERT_EQUAL(12, t1.month(), "month of year isn't equal 12"); - UNIT_ASSERT_EQUAL(3, t1.day(), "day of month isn't equal 3"); - UNIT_ASSERT_EQUAL(20, t1.hour(), "hour of day isn't equal 20"); - UNIT_ASSERT_EQUAL(17, t1.minute(), "minute day isn't equal 17"); - UNIT_ASSERT_EQUAL(45, t1.second(), "second of day isn't equal 45"); - UNIT_ASSERT_EQUAL(0, t1.milli_second(), "millisecond of day isn't equal 0"); - UNIT_ASSERT_FALSE(t1.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_FALSE(t1.is_leapyear(), "time stamp must not be a leap year"); - - UNIT_ASSERT_EQUAL(2014, t2.year(), "year isn't equal 2014"); - UNIT_ASSERT_EQUAL(12, t2.month(), "month of year isn't equal 12"); - UNIT_ASSERT_EQUAL(3, t2.day(), "day of month isn't equal 3"); - UNIT_ASSERT_EQUAL(20, t2.hour(), "hour of day isn't equal 20"); - UNIT_ASSERT_EQUAL(17, t2.minute(), "minute day isn't equal 17"); - UNIT_ASSERT_EQUAL(45, t2.second(), "second of day isn't equal 45"); - UNIT_ASSERT_EQUAL(0, t2.milli_second(), "millisecond of day isn't equal 0"); - UNIT_ASSERT_FALSE(t2.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_FALSE(t2.is_leapyear(), "time stamp must not be a leap year"); - - UNIT_ASSERT_TRUE(t1 == t2, "times must be equal"); + UNIT_ASSERT_EQUAL(2014, t1.year()); + UNIT_ASSERT_EQUAL(12, t1.month()); + UNIT_ASSERT_EQUAL(3, t1.day()); + UNIT_ASSERT_EQUAL(20, t1.hour()); + UNIT_ASSERT_EQUAL(17, t1.minute()); + UNIT_ASSERT_EQUAL(45, t1.second()); + UNIT_ASSERT_EQUAL(0, t1.milli_second()); + UNIT_ASSERT_FALSE(t1.is_daylight_saving()); + UNIT_ASSERT_FALSE(t1.is_leapyear()); + + UNIT_ASSERT_EQUAL(2014, t2.year()); + UNIT_ASSERT_EQUAL(12, t2.month()); + UNIT_ASSERT_EQUAL(3, t2.day()); + UNIT_ASSERT_EQUAL(20, t2.hour()); + UNIT_ASSERT_EQUAL(17, t2.minute()); + UNIT_ASSERT_EQUAL(45, t2.second()); + UNIT_ASSERT_EQUAL(0, t2.milli_second()); + UNIT_ASSERT_FALSE(t2.is_daylight_saving()); + UNIT_ASSERT_FALSE(t2.is_leapyear()); + + UNIT_ASSERT_TRUE(t1 == t2); } void TimeTestUnit::test_assign() @@ -146,27 +143,27 @@ void TimeTestUnit::test_assign() matador::time t2; t2 = t1; - UNIT_ASSERT_EQUAL(2014, t1.year(), "year isn't equal 2014"); - UNIT_ASSERT_EQUAL(12, t1.month(), "month of year isn't equal 12"); - UNIT_ASSERT_EQUAL(3, t1.day(), "day of month isn't equal 3"); - UNIT_ASSERT_EQUAL(20, t1.hour(), "hour of day isn't equal 20"); - UNIT_ASSERT_EQUAL(17, t1.minute(), "minute day isn't equal 17"); - UNIT_ASSERT_EQUAL(45, t1.second(), "second of day isn't equal 45"); - UNIT_ASSERT_EQUAL(0, t1.milli_second(), "millisecond of day isn't equal 0"); - UNIT_ASSERT_FALSE(t1.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_FALSE(t1.is_leapyear(), "time stamp must not be a leap year"); - - UNIT_ASSERT_EQUAL(2014, t2.year(), "year isn't equal 2014"); - UNIT_ASSERT_EQUAL(12, t2.month(), "month of year isn't equal 12"); - UNIT_ASSERT_EQUAL(3, t2.day(), "day of month isn't equal 3"); - UNIT_ASSERT_EQUAL(20, t2.hour(), "hour of day isn't equal 20"); - UNIT_ASSERT_EQUAL(17, t2.minute(), "minute day isn't equal 17"); - UNIT_ASSERT_EQUAL(45, t2.second(), "second of day isn't equal 45"); - UNIT_ASSERT_EQUAL(0, t2.milli_second(), "millisecond of day isn't equal 0"); - UNIT_ASSERT_FALSE(t2.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_FALSE(t2.is_leapyear(), "time stamp must not be a leap year"); - - UNIT_ASSERT_TRUE(t1 == t2, "times must be equal"); + UNIT_ASSERT_EQUAL(2014, t1.year()); + UNIT_ASSERT_EQUAL(12, t1.month()); + UNIT_ASSERT_EQUAL(3, t1.day()); + UNIT_ASSERT_EQUAL(20, t1.hour()); + UNIT_ASSERT_EQUAL(17, t1.minute()); + UNIT_ASSERT_EQUAL(45, t1.second()); + UNIT_ASSERT_EQUAL(0, t1.milli_second()); + UNIT_ASSERT_FALSE(t1.is_daylight_saving()); + UNIT_ASSERT_FALSE(t1.is_leapyear()); + + UNIT_ASSERT_EQUAL(2014, t2.year()); + UNIT_ASSERT_EQUAL(12, t2.month()); + UNIT_ASSERT_EQUAL(3, t2.day()); + UNIT_ASSERT_EQUAL(20, t2.hour()); + UNIT_ASSERT_EQUAL(17, t2.minute()); + UNIT_ASSERT_EQUAL(45, t2.second()); + UNIT_ASSERT_EQUAL(0, t2.milli_second()); + UNIT_ASSERT_FALSE(t2.is_daylight_saving()); + UNIT_ASSERT_FALSE(t2.is_leapyear()); + + UNIT_ASSERT_TRUE(t1 == t2); } void TimeTestUnit::test_compare() @@ -175,65 +172,65 @@ void TimeTestUnit::test_compare() matador::time t2(2014, 12, 3, 20, 17, 45); matador::time t3(t1); - UNIT_ASSERT_TRUE(t1 > t2, "t1 is greater than t2"); - UNIT_ASSERT_TRUE(t2 < t1, "t2 is less than t1"); - UNIT_ASSERT_TRUE(t2 != t1, "t1 is not equal t2"); - UNIT_ASSERT_TRUE(t3 == t1, "t1 is equal t3"); - UNIT_ASSERT_TRUE(t1 >= t2, "t1 is greater equal than t2"); - UNIT_ASSERT_TRUE(t2 <= t1, "t2 is less equal than t1"); - UNIT_ASSERT_TRUE(t1 >= t3, "t1 is greater equal than t2"); - UNIT_ASSERT_TRUE(t3 <= t1, "t2 is less equal than t1"); + UNIT_ASSERT_TRUE(t1 > t2); + UNIT_ASSERT_TRUE(t2 < t1); + UNIT_ASSERT_TRUE(t2 != t1); + UNIT_ASSERT_TRUE(t3 == t1); + UNIT_ASSERT_TRUE(t1 >= t2); + UNIT_ASSERT_TRUE(t2 <= t1); + UNIT_ASSERT_TRUE(t1 >= t3); + UNIT_ASSERT_TRUE(t3 <= t1); } void TimeTestUnit::test_modify() { matador::time t(2015, 1, 31, 11, 35, 7); - UNIT_ASSERT_EQUAL(2015, t.year(), "year isn't equal 2015"); - UNIT_ASSERT_EQUAL(1, t.month(), "month of year isn't equal 1"); - UNIT_ASSERT_EQUAL(31, t.day(), "day of month isn't equal 31"); - UNIT_ASSERT_EQUAL(11, t.hour(), "hour of day isn't equal 11"); - UNIT_ASSERT_EQUAL(35, t.minute(), "minute day isn't equal 35"); - UNIT_ASSERT_EQUAL(7, t.second(), "second of day isn't equal 7"); - UNIT_ASSERT_EQUAL(0, t.milli_second(), "millisecond of day isn't equal 0"); - UNIT_ASSERT_FALSE(t.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_FALSE(t.is_leapyear(), "time stamp must not be a leap year"); + UNIT_ASSERT_EQUAL(2015, t.year()); + UNIT_ASSERT_EQUAL(1, t.month()); + UNIT_ASSERT_EQUAL(31, t.day()); + UNIT_ASSERT_EQUAL(11, t.hour()); + UNIT_ASSERT_EQUAL(35, t.minute()); + UNIT_ASSERT_EQUAL(7, t.second()); + UNIT_ASSERT_EQUAL(0, t.milli_second()); + UNIT_ASSERT_FALSE(t.is_daylight_saving()); + UNIT_ASSERT_FALSE(t.is_leapyear()); t.year(2014).month(8).day(8); - UNIT_ASSERT_EQUAL(2014, t.year(), "year isn't equal 2014"); - UNIT_ASSERT_EQUAL(8, t.month(), "month of year isn't equal 12"); - UNIT_ASSERT_EQUAL(8, t.day(), "day of month isn't equal 3"); - UNIT_ASSERT_EQUAL(11, t.hour(), "hour of day isn't equal 11"); - UNIT_ASSERT_EQUAL(35, t.minute(), "minute day isn't equal 35"); - UNIT_ASSERT_EQUAL(7, t.second(), "second of day isn't equal 7"); - UNIT_ASSERT_EQUAL(0, t.milli_second(), "millisecond of day isn't equal 0"); -// UNIT_ASSERT_TRUE(t.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_FALSE(t.is_leapyear(), "time stamp must not be a leap year"); + UNIT_ASSERT_EQUAL(2014, t.year()); + UNIT_ASSERT_EQUAL(8, t.month()); + UNIT_ASSERT_EQUAL(8, t.day()); + UNIT_ASSERT_EQUAL(11, t.hour()); + UNIT_ASSERT_EQUAL(35, t.minute()); + UNIT_ASSERT_EQUAL(7, t.second()); + UNIT_ASSERT_EQUAL(0, t.milli_second()); +// UNIT_ASSERT_TRUE(t.is_daylight_saving()); + UNIT_ASSERT_FALSE(t.is_leapyear()); t.year(2016); - UNIT_ASSERT_EQUAL(2016, t.year(), "year isn't equal 2016"); - UNIT_ASSERT_EQUAL(8, t.month(), "month of year isn't equal 8"); - UNIT_ASSERT_EQUAL(8, t.day(), "day of month isn't equal 8"); - UNIT_ASSERT_EQUAL(11, t.hour(), "hour of day isn't equal 11"); - UNIT_ASSERT_EQUAL(35, t.minute(), "minute day isn't equal 35"); - UNIT_ASSERT_EQUAL(7, t.second(), "second of day isn't equal 7"); - UNIT_ASSERT_EQUAL(0, t.milli_second(), "millisecond of day isn't equal 0"); -// UNIT_ASSERT_TRUE(t.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_TRUE(t.is_leapyear(), "time stamp must be a leap year"); + UNIT_ASSERT_EQUAL(2016, t.year()); + UNIT_ASSERT_EQUAL(8, t.month()); + UNIT_ASSERT_EQUAL(8, t.day()); + UNIT_ASSERT_EQUAL(11, t.hour()); + UNIT_ASSERT_EQUAL(35, t.minute()); + UNIT_ASSERT_EQUAL(7, t.second()); + UNIT_ASSERT_EQUAL(0, t.milli_second()); +// UNIT_ASSERT_TRUE(t.is_daylight_saving()); + UNIT_ASSERT_TRUE(t.is_leapyear()); t.year(2000).hour(23).minute(13).second(1).milli_second(4711); - UNIT_ASSERT_EQUAL(2000, t.year(), "year isn't equal 2000"); - UNIT_ASSERT_EQUAL(8, t.month(), "month of year isn't equal 8"); - UNIT_ASSERT_EQUAL(8, t.day(), "day of month isn't equal 8"); - UNIT_ASSERT_EQUAL(23, t.hour(), "hour of day isn't equal 11"); - UNIT_ASSERT_EQUAL(13, t.minute(), "minute day isn't equal 35"); - UNIT_ASSERT_EQUAL(1, t.second(), "second of day isn't equal 7"); - UNIT_ASSERT_EQUAL(4711, t.milli_second(), "millisecond of day isn't equal 4711"); -// UNIT_ASSERT_TRUE(t.is_daylight_saving(), "time stamp must not be daylight saving"); - UNIT_ASSERT_TRUE(t.is_leapyear(), "time stamp must be a leap year"); + UNIT_ASSERT_EQUAL(2000, t.year()); + UNIT_ASSERT_EQUAL(8, t.month()); + UNIT_ASSERT_EQUAL(8, t.day()); + UNIT_ASSERT_EQUAL(23, t.hour()); + UNIT_ASSERT_EQUAL(13, t.minute()); + UNIT_ASSERT_EQUAL(1, t.second()); + UNIT_ASSERT_EQUAL(4711, t.milli_second()); +// UNIT_ASSERT_TRUE(t.is_daylight_saving()); + UNIT_ASSERT_TRUE(t.is_leapyear()); } void TimeTestUnit::test_parse() @@ -242,37 +239,37 @@ void TimeTestUnit::test_parse() matador::time t = matador::time::parse(tstr1, "%d.%m.%Y %H:%M:%S.%f"); - UNIT_ASSERT_EQUAL(2015, t.year(), "year must be 2015"); - UNIT_ASSERT_EQUAL(4, t.month(), "month must be 4"); - UNIT_ASSERT_EQUAL(3, t.day(), "day must be 3"); - UNIT_ASSERT_EQUAL(12, t.hour(), "hour must be 12"); - UNIT_ASSERT_EQUAL(55, t.minute(), "minute must be 55"); - UNIT_ASSERT_EQUAL(12, t.second(), "second must be 12"); - UNIT_ASSERT_EQUAL(123, t.milli_second(), "millisecond must be 123"); + UNIT_ASSERT_EQUAL(2015, t.year()); + UNIT_ASSERT_EQUAL(4, t.month()); + UNIT_ASSERT_EQUAL(3, t.day()); + UNIT_ASSERT_EQUAL(12, t.hour()); + UNIT_ASSERT_EQUAL(55, t.minute()); + UNIT_ASSERT_EQUAL(12, t.second()); + UNIT_ASSERT_EQUAL(123, t.milli_second()); tstr1.assign("12:55:12.123 03.04.2015"); t = matador::time::parse(tstr1, "%H:%M:%S.%f %d.%m.%Y"); - UNIT_ASSERT_EQUAL(2015, t.year(), "year must be 2015"); - UNIT_ASSERT_EQUAL(4, t.month(), "month must be 4"); - UNIT_ASSERT_EQUAL(3, t.day(), "day must be 3"); - UNIT_ASSERT_EQUAL(12, t.hour(), "hour must be 12"); - UNIT_ASSERT_EQUAL(55, t.minute(), "minute must be 55"); - UNIT_ASSERT_EQUAL(12, t.second(), "second must be 12"); - UNIT_ASSERT_EQUAL(123, t.milli_second(), "millisecond must be 123"); + UNIT_ASSERT_EQUAL(2015, t.year()); + UNIT_ASSERT_EQUAL(4, t.month()); + UNIT_ASSERT_EQUAL(3, t.day()); + UNIT_ASSERT_EQUAL(12, t.hour()); + UNIT_ASSERT_EQUAL(55, t.minute()); + UNIT_ASSERT_EQUAL(12, t.second()); + UNIT_ASSERT_EQUAL(123, t.milli_second()); tstr1.assign("12:55:12 03.04.2015"); t = matador::time::parse(tstr1, "%H:%M:%S %d.%m.%Y"); - UNIT_ASSERT_EQUAL(2015, t.year(), "year must be 2015"); - UNIT_ASSERT_EQUAL(4, t.month(), "month must be 4"); - UNIT_ASSERT_EQUAL(3, t.day(), "day must be 3"); - UNIT_ASSERT_EQUAL(12, t.hour(), "hour must be 12"); - UNIT_ASSERT_EQUAL(55, t.minute(), "minute must be 55"); - UNIT_ASSERT_EQUAL(12, t.second(), "second must be 12"); - UNIT_ASSERT_EQUAL(0, t.milli_second(), "millisecond must be 0"); + UNIT_ASSERT_EQUAL(2015, t.year()); + UNIT_ASSERT_EQUAL(4, t.month()); + UNIT_ASSERT_EQUAL(3, t.day()); + UNIT_ASSERT_EQUAL(12, t.hour()); + UNIT_ASSERT_EQUAL(55, t.minute()); + UNIT_ASSERT_EQUAL(12, t.second()); + UNIT_ASSERT_EQUAL(0, t.milli_second()); } void TimeTestUnit::test_format() @@ -281,5 +278,5 @@ void TimeTestUnit::test_format() std::string tstr(to_string(t, "%H:%M:%S.%f %d.%m.%Y")); - UNIT_ASSERT_EQUAL(tstr, "11:35:07.123 31.01.2015", "invalid time string [" + tstr + "]"); + UNIT_ASSERT_EQUAL(tstr, "11:35:07.123 31.01.2015"); } diff --git a/test/utils/VarCharTestUnit.cpp b/test/utils/VarCharTestUnit.cpp index c7860f222..82e6fe094 100644 --- a/test/utils/VarCharTestUnit.cpp +++ b/test/utils/VarCharTestUnit.cpp @@ -21,18 +21,18 @@ void VarCharTestUnit::test_create() { varchar<8> str8; - UNIT_ASSERT_EQUAL((int)str8.capacity(), 8, "invalid capacity of varchar"); - UNIT_ASSERT_EQUAL((int)str8.size(), 0, "size of varchar must be zero"); + UNIT_ASSERT_EQUAL((int)str8.capacity(), 8); + UNIT_ASSERT_EQUAL((int)str8.size(), 0); str8 = "Hallo"; - UNIT_ASSERT_EQUAL((int)str8.capacity(), 8, "invalid capacity of varchar"); - UNIT_ASSERT_EQUAL((int)str8.size(), 5, "size of varchar must be zero"); + UNIT_ASSERT_EQUAL((int)str8.capacity(), 8); + UNIT_ASSERT_EQUAL((int)str8.size(), 5); str8 += std::string("Welt"); - UNIT_ASSERT_EQUAL((int)str8.capacity(), 8, "invalid capacity of varchar"); - UNIT_ASSERT_EQUAL((int)str8.size(), 8, "size of varchar must be zero"); + UNIT_ASSERT_EQUAL((int)str8.capacity(), 8); + UNIT_ASSERT_EQUAL((int)str8.size(), 8); } void VarCharTestUnit::test_copy() @@ -41,7 +41,7 @@ void VarCharTestUnit::test_copy() varchar<8> str8_2(str8); - UNIT_ASSERT_EQUAL(str8_2, "Hallo", "expected string must be 'Hallo'"); + UNIT_ASSERT_EQUAL(str8_2, "Hallo"); } void VarCharTestUnit::test_assign() @@ -50,21 +50,21 @@ void VarCharTestUnit::test_assign() varchar<8> str8_2 = str8; - UNIT_ASSERT_EQUAL(str8_2, "Hallo", "expected string must be 'Hallo'"); + UNIT_ASSERT_EQUAL(str8_2, "Hallo"); str8 = "Baba"; - UNIT_ASSERT_EQUAL(str8, "Baba", "expected string must be 'Baba'"); + UNIT_ASSERT_EQUAL(str8, "Baba"); } void VarCharTestUnit::test_init() { varchar<16> str("hallo"); - UNIT_ASSERT_EQUAL((int)str.capacity(), 16, "invalid capacity of varchar"); - UNIT_ASSERT_EQUAL((int)str.size(), 5, "size of varchar must be zero"); - UNIT_ASSERT_TRUE(str.valid(), "varchar must be valid"); - UNIT_ASSERT_EQUAL(str, "hallo", "size of varchar must be zero"); + UNIT_ASSERT_EQUAL((int)str.capacity(), 16); + UNIT_ASSERT_EQUAL((int)str.size(), 5); + UNIT_ASSERT_TRUE(str.valid()); + UNIT_ASSERT_EQUAL(str, "hallo"); } void VarCharTestUnit::test_modify() @@ -73,10 +73,10 @@ void VarCharTestUnit::test_modify() str += " welt"; - UNIT_ASSERT_EQUAL((int)str.capacity(), 16, "invalid capacity of varchar"); - UNIT_ASSERT_EQUAL((int)str.size(), 10, "size of varchar must be zero"); - UNIT_ASSERT_TRUE(str.valid(), "varchar must be valid"); - UNIT_ASSERT_EQUAL(str, "hallo welt", "size of varchar must be zero"); + UNIT_ASSERT_EQUAL((int)str.capacity(), 16); + UNIT_ASSERT_EQUAL((int)str.size(), 10); + UNIT_ASSERT_TRUE(str.valid()); + UNIT_ASSERT_EQUAL(str, "hallo welt"); str = "hallo"; @@ -84,34 +84,34 @@ void VarCharTestUnit::test_modify() str += echo; - UNIT_ASSERT_EQUAL((int)str.capacity(), 16, "invalid capacity of varchar"); - UNIT_ASSERT_EQUAL((int)str.size(), 10, "size of varchar must be zero"); - UNIT_ASSERT_TRUE(str.valid(), "varchar must be valid"); - UNIT_ASSERT_EQUAL(str, "hallo echo", "size of varchar must be zero"); + UNIT_ASSERT_EQUAL((int)str.capacity(), 16); + UNIT_ASSERT_EQUAL((int)str.size(), 10); + UNIT_ASSERT_TRUE(str.valid()); + UNIT_ASSERT_EQUAL(str, "hallo echo"); echo = "1234567"; - UNIT_ASSERT_EQUAL((int)echo.capacity(), 6, "invalid capacity of varchar"); - UNIT_ASSERT_EQUAL((int)echo.size(), 7, "size of varchar must be zero"); - UNIT_ASSERT_FALSE(echo.valid(), "varchar must be invalid"); - UNIT_ASSERT_EQUAL(echo, "1234567", "size of varchar must be zero"); + UNIT_ASSERT_EQUAL((int)echo.capacity(), 6); + UNIT_ASSERT_EQUAL((int)echo.size(), 7); + UNIT_ASSERT_FALSE(echo.valid()); + UNIT_ASSERT_EQUAL(echo, "1234567"); echo.trim(); - UNIT_ASSERT_EQUAL((int)echo.size(), 6, "size of varchar must be zero"); - UNIT_ASSERT_TRUE(echo.valid(), "varchar must be valid"); - UNIT_ASSERT_EQUAL(echo, "123456", "size of varchar must be zero"); + UNIT_ASSERT_EQUAL((int)echo.size(), 6); + UNIT_ASSERT_TRUE(echo.valid()); + UNIT_ASSERT_EQUAL(echo, "123456"); } void VarCharTestUnit::test_access() { varchar<16> str("hello"); - UNIT_ASSERT_EQUAL((int)str.capacity(), 16, "invalid capacity of varchar"); - UNIT_ASSERT_EQUAL((int)str.size(), 5, "size of varchar must be zero"); - UNIT_ASSERT_TRUE(str.valid(), "varchar must be valid"); - UNIT_ASSERT_EQUAL(str, "hello", "unexpected value"); - UNIT_ASSERT_EQUAL(str.str(), "hello", "unexpected value"); - UNIT_ASSERT_EQUAL(str.c_str(), "hello", "unexpected value"); - UNIT_ASSERT_EQUAL(str.data(), "hello", "unexpected value"); + UNIT_ASSERT_EQUAL((int)str.capacity(), 16); + UNIT_ASSERT_EQUAL((int)str.size(), 5); + UNIT_ASSERT_TRUE(str.valid()); + UNIT_ASSERT_EQUAL(str, "hello"); + UNIT_ASSERT_EQUAL(str.str(), "hello"); + UNIT_ASSERT_EQUAL(str.c_str(), "hello"); + UNIT_ASSERT_EQUAL(str.data(), "hello"); }