From 5251322d3560577cc9ae65a2600d5ecebe9ef751 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 16 Oct 2019 15:11:16 +0200 Subject: [PATCH] + Catch2 as Unit Test Framework + Demo Unit Test + README + LICENCE + CHANGELOG --- .gitignore | 13 ++++++++++++- CHANGELOG.md | 33 +++++++++++++++++++++++++++++++++ CMakeLists.txt | 31 ++++++++++++++++++++++++------- LICENSE | 29 +++++++++++++++++++++++++++++ README.md | 24 ++++++++++++++++++++++++ src/add.cpp | 4 ---- src/add.h | 6 +----- test/add_test.cpp | 11 +++++++++++ test/test_main.cpp | 6 ++++++ 9 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 test/add_test.cpp create mode 100644 test/test_main.cpp diff --git a/.gitignore b/.gitignore index 4d92641..e8eb7d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,15 @@ +# Editors & IDEs cmake-build-*/ -build/ .idea/ +*.iml .vs/ + +# CMake +CMakeFiles +CmakeCache.txt + + +bin/ +lib/ +include/ +build/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..101bcbe --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,33 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + + +## [Unreleased] + +- Continuous Integration + +## [0.0.1] - 2019-10-24 + +### Added + +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## [0.0.0] - 2019-10-17 + +### Added + +- README +- LICENCE +- CMake configuration \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 15c7744..3eae4bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,37 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.0) + +if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") + message(FATAL_ERROR "In-source builds are disabled. + Please create a subfolder called build and use `cmake ..` inside it. + NOTE: cmake will now create CMakeCache.txt and CMakeFiles/*. + You must delete them, or cmake will refuse to work.") +endif() +set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "bin" "doc" "CMakeFiles" "lib" "include") + project(library) set(CMAKE_CXX_STANDARD 14) file(GLOB_RECURSE SOURCES src/*.cpp) file(GLOB_RECURSE HEADERS src/*.h) +file(GLOB_RECURSE TESTS test/*.cpp) include_directories(src) +include_directories(test) + add_library(library ${SOURCES} ${HEADERS}) file(COPY "${CMAKE_SOURCE_DIR}/src/" - DESTINATION "${CMAKE_SOURCE_DIR}/build/include" + DESTINATION "${CMAKE_SOURCE_DIR}/include" FILES_MATCHING PATTERN *.h ) -file(COPY "${CMAKE_BINARY_DIR}/" - DESTINATION "${CMAKE_SOURCE_DIR}/build/lib" - FILES_MATCHING - PATTERN *.a - ) \ No newline at end of file +set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib) + +enable_testing() +find_package(Catch2 REQUIRED) +add_executable(UnitTests test/test_main.cpp ${SOURCES} ${HEADERS} ${TESTS}) +target_link_libraries(UnitTests Catch2::Catch2) + +include(CTest) +include(Catch) +catch_discover_tests(UnitTests) \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0c3a5a8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2019, Projektgruppe vKVM WS 2019 +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..086aedc --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# vKVM Library + +# Installation + +Use the installation script provided in the Scripts repository +to install the full package. + +Installing a single component is currently not supported. + +# Usage + +Include this library with + +``` +set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") + +include_directories(${LIB_PATH}/include) +add_executable(your_client ${SOURCES} ${HEADERS}) + +target_link_libraries(your_client ${LIB_PATH}/lib/liblibrary.a) +``` +in your CMakeLists. + +More documentation coming soon. diff --git a/src/add.cpp b/src/add.cpp index e9af79b..c3f4e9f 100644 --- a/src/add.cpp +++ b/src/add.cpp @@ -1,7 +1,3 @@ -// -// Copyright (c) 2019 Julian Hinxlage. All rights reserved. -// - #include "add.h" int add(int a, int b){ diff --git a/src/add.h b/src/add.h index d852a57..c950a3c 100644 --- a/src/add.h +++ b/src/add.h @@ -1,10 +1,6 @@ -// -// Copyright (c) 2019 Julian Hinxlage. All rights reserved. -// - #ifndef LIBRARY_ADD_H #define LIBRARY_ADD_H int add(int a, int b); -#endif //LIBRARY_ADD_H +#endif diff --git a/test/add_test.cpp b/test/add_test.cpp new file mode 100644 index 0000000..0b30d42 --- /dev/null +++ b/test/add_test.cpp @@ -0,0 +1,11 @@ +#include +#include "../src/add.h" + +TEST_CASE("add works") { + SECTION("equals") { + REQUIRE(add(2, 2) == 4); + } + SECTION("not equals") { + REQUIRE(add(2, 2) != 5); + } +} \ No newline at end of file diff --git a/test/test_main.cpp b/test/test_main.cpp new file mode 100644 index 0000000..1a32dbe --- /dev/null +++ b/test/test_main.cpp @@ -0,0 +1,6 @@ +#define CATCH_CONFIG_MAIN + +#include + +//Dont touch this file. +// add your own tests in this directory according to https://github.com/catchorg/Catch2/blob/master/docs/tutorial.md \ No newline at end of file