From b3d29409c0ec90a32a91243675a3f55617cf63e1 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 12 Aug 2017 13:59:54 +0100 Subject: More tests and improving header adding --- CMakeLists.txt | 21 ++++++++++++++--- include/YAGE/yage.hpp | 9 ++------ scripts/add_version_headers | 56 ++++++++++++++++++++++++++++++++------------- sourceme | 11 +++++++++ test/particlebodytest.cpp | 8 +++---- test/windowtest.cpp | 20 ++++++++++++++++ test/yagetest.cpp | 20 ++++++++++++++++ 7 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 sourceme create mode 100644 test/windowtest.cpp create mode 100644 test/yagetest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dec234b..f084702c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,10 @@ +# ---------------------------------------------------------------------------- +# CMakeLists.txt +# +# Copyright (c) 2017 Yann Herklotz Grave -- MIT License +# See file LICENSE for more details +# ---------------------------------------------------------------------------- + cmake_minimum_required(VERSION 3.0) # yage library cmakelists.txt @@ -69,14 +76,18 @@ include_directories(${YAGE_INCLUDE_DIR} # make it a static library add_library(${PROJECT_NAME} ${YAGE_SOURCES}) -set(YAGE_LIB_DEP_L yage - ${OPENGL_LIBRARIES} - ${GLEW_LIBRARIES}) +set(YAGE_LIB_DEP_L "yage;${OPENGL_LIBRARIES};${GLEW_LIBRARIES};${SDL2_LIBRAIRES}") + +message("${YAGE_LIB_DEP_L}") # enable tests enable_testing() set(SIMULATION_RUNS 1000) +add_executable(yagetest ${YAGE_TEST_DIR}/yagetest.cpp) +target_link_libraries(yagetest gtest_main ${YAGE_LIB_DEP_L}) +add_test(NAME Yagetest COMMAND yagetest --gtest_repeat=${SIMULATION_RUNS} --gtest_break_on_failure) + add_executable(matrixtest ${YAGE_TEST_DIR}/matrixtest.cpp) target_link_libraries(matrixtest gtest_main ${YAGE_LIB_DEP_L}) add_test(NAME MatrixTest COMMAND matrixtest --gtest_repeat=${SIMULATION_RUNS} --gtest_break_on_failure) @@ -84,3 +95,7 @@ add_test(NAME MatrixTest COMMAND matrixtest --gtest_repeat=${SIMULATION_RUNS} -- add_executable(particlebodytest ${YAGE_TEST_DIR}/particlebodytest.cpp) target_link_libraries(particlebodytest gtest_main ${YAGE_LIB_DEP_L}) add_test(NAME ParticleBodyTest COMMAND particlebodytest --gtest_repeat=${SIMULATION_RUNS} --gtest_break_on_failure) + +add_executable(windowtest ${YAGE_TEST_DIR}/windowtest.cpp) +target_link_libraries(windowtest gtest_main ${YAGE_LIB_DEP_L}) +add_test(NAME Windowtest COMMAND windowtest --gtest_repeat=${SIMULATION_RUNS} --gtest_break_on_failure) diff --git a/include/YAGE/yage.hpp b/include/YAGE/yage.hpp index 45c1c4d7..31289d64 100644 --- a/include/YAGE/yage.hpp +++ b/include/YAGE/yage.hpp @@ -27,14 +27,9 @@ namespace yage { -bool init() { - if (SDL_Init(SDL_INIT_VIDEO)) { - return false; - } - return true; -} - +bool init() { return SDL_Init(SDL_INIT_VIDEO); } void quit() { SDL_Quit(); } + }; #endif diff --git a/scripts/add_version_headers b/scripts/add_version_headers index 5de82a6c..0949fb86 100755 --- a/scripts/add_version_headers +++ b/scripts/add_version_headers @@ -28,30 +28,54 @@ import re import sys -header = """/* ---------------------------------------------------------------\ -------------- +header = """/* ----------------------------------------------------------------------------- * {0} * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License, + * See LICENSE file for more details. + * ----------------------------------------------------------------------------- */ """ +class HeaderUpdate(object): + """Updates the header in all the source and header files in the code""" + def __init__(self, **kwargs): + self.match_re = ".*[.]cpp$|.*[.]hpp$" + if "match_re" in kwargs: + self.match_re = kwargs["match_re"] + self.exclude_re = "" + if "exlude_re" in kwargs: + self.exclude_re = kwargs["exclude_re"] + self.exclude_build = True + if "exclude_build" in kwargs: + self.exclude_build = kwargs["exclude_build"] + + def writeHeader(self): + for subdir, dirs, files in os.walk(os.getcwd()): + if (not re.match(".*build.*", subdir) or (not self.exclude_build)): + for file_ in files: + if (re.match(self.match_re, file_)) and (not re.match(self.exclude_re, file_)): + + with open(os.path.join(subdir, file_), 'r') as src_file: + src = src_file.read() + if not re.match("^/[*] -*$"): + print(os.path.join(subdir, file_), end=" ") + with open(os.path.join(subdir, file_), 'w') as src_file_lic: + src_file_lic.write(header.format(file_)) + src_file_lic.write(src) + print("-- done") + + def updateHeader(self): + ... + + def removeHeader(self): + ... + + def main(argv): - for subdir, dirs, files in os.walk(os.getcwd()): - if not re.match(".*build.*", subdir): - for file_ in files: - if re.match(".*[.]cpp$|.*[.]hpp$", file_) and not re.match("^picopng[.]cpp$", file_): - print(os.path.join(subdir, file_), end=" ") - with open(os.path.join(subdir, file_), 'r') as src_file: - src = src_file.read() - with open(os.path.join(subdir, file_), 'w') as src_file_lic: - src_file_lic.write(header.format(file_)) - src_file_lic.write(src) - print("-- done") + udpate = HeaderUpdate(exclude_re="^picopng[.]cpp") if __name__ == "__main__": diff --git a/sourceme b/sourceme new file mode 100644 index 00000000..e0aeae94 --- /dev/null +++ b/sourceme @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# ----------------------------------------------------------------------------- +# sourceme +# +# Copyright (c) 2017 Yann Herklotz Grave -- MIT License +# See file LICENSE for more details +# ----------------------------------------------------------------------------- + +PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null 2>&1 && pwd )" + +export PATH="${PATH}:${PROJECT_DIR}/scripts" diff --git a/test/particlebodytest.cpp b/test/particlebodytest.cpp index c8e493a0..5c915a9a 100644 --- a/test/particlebodytest.cpp +++ b/test/particlebodytest.cpp @@ -24,11 +24,11 @@ double gravityAcceleration(int iterations) { // Tests TEST(ParticleBody, Gravity) { - int random_itr = rand() % 25; - double idealPosition = 0.5 * -9.81 * std::pow(random_itr, 2); + int randomItr = rand() % 10; + double idealPosition = 0.5 * -9.81 * std::pow(randomItr, 2); - ASSERT_GE(idealPosition * 0.95, gravityAcceleration(random_itr)); - ASSERT_LE(idealPosition * 1.05, gravityAcceleration(random_itr)); + ASSERT_GE(idealPosition * 0.95, gravityAcceleration(randomItr)); + ASSERT_LE(idealPosition * 1.05, gravityAcceleration(randomItr)); } int main(int argc, char** argv) { diff --git a/test/windowtest.cpp b/test/windowtest.cpp new file mode 100644 index 00000000..d252f28f --- /dev/null +++ b/test/windowtest.cpp @@ -0,0 +1,20 @@ +/* ---------------------------------------------------------------------------- + * windowtest.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#include "gtest/gtest.h" + +#include "yage.hpp" + +TEST(Window, Open) { + ASSERT_TRUE(true); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/yagetest.cpp b/test/yagetest.cpp new file mode 100644 index 00000000..8ca6c83e --- /dev/null +++ b/test/yagetest.cpp @@ -0,0 +1,20 @@ +/* ---------------------------------------------------------------------------- + * yagetest.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#include "gtest/gtest.h" + +#include "yage.hpp" + +TEST(YAGE, InitQuit) { + ASSERT_TRUE(true); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} -- cgit