From 491acaada17667b0758186c84614088a10734c52 Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Wed, 16 Oct 2019 12:17:59 +0200 Subject: [PATCH 1/5] fixed pixel value bug --- src/main.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a498b2c..2678494 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,15 +14,17 @@ int main() { Bitmap bitmap; bitmap.load("../res/font.bmp"); - std::string str = "Hello, World!"; + std::string str; + std::cout << "string to draw: "; + std::cin >> str; //values used to calculate the coordinates of the characters - int xOffset = 1; + int xOffset = 2; int yOffset = 2; - int xSize = 6; + int xSize = 5; int ySize = 7; int xCount = 18; - int xStart = 0; + int xStart = 1; int yStart = 2; //print vertical @@ -41,12 +43,18 @@ int main() { //print current row of the current character for (int j = x; j < x + xSize; j++) { - auto *pixel = (unsigned int *) bitmap.getPixel(j, i + y); - if (*pixel == 0) { + char *pixel_ptr = bitmap.getPixel(j, i + y); + unsigned int pixel = 0; + *((char*)&pixel+0) = pixel_ptr[0]; + *((char*)&pixel+1) = pixel_ptr[1]; + *((char*)&pixel+2) = pixel_ptr[2]; + + if (pixel == 0) { std::cout << " "; } else { - std::cout << "1"; + std::cout << "1"; } + } std::cout << " "; } From afc6e475606d1fa624a80832c3bc37e327bcee42 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 16 Oct 2019 15:44:13 +0200 Subject: [PATCH 2/5] + Unit test framework + README + LICENSE + CHANGELOG --- .gitignore | 4 ---- CHANGELOG.md | 33 +++++++++++++++++++++++++++++++++ CMakeLists.txt | 24 ++++++++++++++++++++++-- LICENCE | 29 +++++++++++++++++++++++++++++ README.md | 9 +++++++++ {src => main}/main.cpp | 2 +- src/Bitmap.h | 14 +++++++------- test/test_bitmap.cpp | 9 +++++++++ test/test_main.cpp | 6 ++++++ 9 files changed, 116 insertions(+), 14 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 LICENCE create mode 100644 README.md rename {src => main}/main.cpp (99%) create mode 100644 test/test_bitmap.cpp create mode 100644 test/test_main.cpp diff --git a/.gitignore b/.gitignore index 4d92641..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +0,0 @@ -cmake-build-*/ -build/ -.idea/ -.vs/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5fdc8ee --- /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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a5296a..b5b37ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,35 @@ 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(TextRenderer) 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) -set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library/build") +set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") include_directories(${LIB_PATH}/include) -add_executable(TextRenderer ${SOURCES} ${HEADERS} src/Bitmap.cpp src/Bitmap.h) +add_executable(TextRenderer ${SOURCES} ${HEADERS} main/main.cpp) target_link_libraries(TextRenderer ${LIB_PATH}/lib/liblibrary.a) + +enable_testing() +find_package(Catch2 REQUIRED) +add_executable(UnitTests ${SOURCES} ${HEADERS} ${TESTS}) +target_link_libraries(UnitTests Catch2::Catch2) + +include(CTest) +include(Catch) +catch_discover_tests(UnitTests) diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..66aec33 --- /dev/null +++ b/LICENCE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..67291f7 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# vKVM TextRenderer + +## Installation + +Use the installation script provided in the Scripts repository +to install the full package. + +Installing a single component is currently not supported. + diff --git a/src/main.cpp b/main/main.cpp similarity index 99% rename from src/main.cpp rename to main/main.cpp index 2678494..3fbdaf0 100644 --- a/src/main.cpp +++ b/main/main.cpp @@ -3,7 +3,7 @@ #include "add.h" #include "Bitmap.h" -/* +/** * @author: Julian Hinxlage * @since: v0.0.0 * @brief: An image is loaded and used as a font. diff --git a/src/Bitmap.h b/src/Bitmap.h index 48cc47c..2619a22 100644 --- a/src/Bitmap.h +++ b/src/Bitmap.h @@ -3,7 +3,7 @@ #include -/* +/** * @author: Julian Hinxlage * @since: v0.0.0 * @brief: Used to load a Bitmap from a file. @@ -14,42 +14,42 @@ public: ~Bitmap(); - /* + /** * @author: Julian Hinxlage * @since: v0.0.0 * @brief: Used to load a Bitmap from a file. */ void load(const std::string &file); - /* + /** * @author: Julian Hinxlage * @since: v0.0.0 * @return: the width of the image. */ int getWidth(); - /* + /** * @author: Julian Hinxlage * @since: v0.0.0 * @return: the height of the image */ int getHeight(); - /* + /** * @author: Julian Hinxlage * @since: v0.0.0 * @return: the pixel data as an byte array */ char *getData(); - /* + /** * @author: Julian Hinxlage * @since: v0.0.0 * @return: the number of bits uses per pixel */ int getBitsPerPixel(); - /* + /** * @author: Julian Hinxlage * @since: v0.0.0 * @return: the pixel value by coordinates, (0,0) is on the top left diff --git a/test/test_bitmap.cpp b/test/test_bitmap.cpp new file mode 100644 index 0000000..a902711 --- /dev/null +++ b/test/test_bitmap.cpp @@ -0,0 +1,9 @@ +#include +#include + +TEST_CASE("default values") { + Bitmap bitmap = Bitmap(); + REQUIRE(bitmap.getWidth() == 0); + REQUIRE(bitmap.getHeight() == 0); + REQUIRE(bitmap.getBitsPerPixel() == 0); +} \ No newline at end of file diff --git a/test/test_main.cpp b/test/test_main.cpp new file mode 100644 index 0000000..6372e38 --- /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 From 8e52eba091e34f3333c0c80201cdb7090b2ae61b Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 16 Oct 2019 16:18:13 +0200 Subject: [PATCH 3/5] now the gitignore has content --- .gitignore | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.gitignore b/.gitignore index e69de29..e8eb7d3 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,15 @@ +# Editors & IDEs +cmake-build-*/ +.idea/ +*.iml +.vs/ + +# CMake +CMakeFiles +CmakeCache.txt + + +bin/ +lib/ +include/ +build/ \ No newline at end of file From ae02c477129374a92533eab287401f8eb9ff91b5 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 16 Oct 2019 16:46:08 +0200 Subject: [PATCH 4/5] wrong filename for license --- LICENCE => LICENSE | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LICENCE => LICENSE (100%) diff --git a/LICENCE b/LICENSE similarity index 100% rename from LICENCE rename to LICENSE From 7f23ad766c7f1e4daf1cf6f923fb8801bafc805c Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Mon, 21 Oct 2019 15:22:28 +0000 Subject: [PATCH 5/5] + clang_tidy --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5b37ac..b41e461 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.7.2) if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") message(FATAL_ERROR "In-source builds are disabled. @@ -11,6 +11,10 @@ set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "bin" "doc" " project(TextRenderer) set(CMAKE_CXX_STANDARD 14) +# enable clang_tidy +set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*") +set(CMAKE_CXX_CLANG_TIDY clang-tidy;-header-filter=.;-checks=*;) + file(GLOB_RECURSE SOURCES src/*.cpp) file(GLOB_RECURSE HEADERS src/*.h) file(GLOB_RECURSE TESTS test/*.cpp)