From 564e88bafe1e806910cfc5580824dec614f4a204 Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 20 Sep 2023 07:54:14 +0200 Subject: [PATCH 1/5] Remove stubborn construction test --- src/CMakeLists.txt | 2 -- src/cppIni.cpp | 24 ------------------------ tests/CMakeLists.txt | 1 - tests/ConstructionTest.cpp | 27 --------------------------- 4 files changed, 54 deletions(-) delete mode 100644 src/cppIni.cpp delete mode 100644 tests/ConstructionTest.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a3429e..6f2bd9a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.24) set(CMAKE_DEBUG_POSTFIX d) set(SOURCES - cppIni.cpp - Entry.cpp File.cpp Section.cpp diff --git a/src/cppIni.cpp b/src/cppIni.cpp deleted file mode 100644 index be57b89..0000000 --- a/src/cppIni.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * cppIni - C++20/23 library for dealing with settings files - * Copyright (C) 2023 Nils Hofmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -int one() -{ - return 1; -} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b400dc5..0eec84b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.24) find_package(doctest REQUIRED) set(TEST_SOURCES - ConstructionTest.cpp EntryTest.cpp FileTest.cpp SectionTest.cpp diff --git a/tests/ConstructionTest.cpp b/tests/ConstructionTest.cpp deleted file mode 100644 index 1532c16..0000000 --- a/tests/ConstructionTest.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * cppIni - C++20/23 library for dealing with settings files - * Copyright (C) 2023 Nils Hofmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN - -#include -#include - -TEST_CASE("Construction test") -{ - CHECK_EQ(one(), 1); -} From 8ada5d9691337f63e834bde34ce4580ea0ac80d7 Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 20 Sep 2023 07:55:19 +0200 Subject: [PATCH 2/5] Fix test include directories --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0eec84b..652bf0e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,7 +17,7 @@ target_compile_definitions(${PROJECT_NAME}_tests WORKING_DIR="${CMAKE_CURRENT_SOURCE_DIR}" ) -target_include_directories(${PROJECT_NAME} +target_include_directories(${PROJECT_NAME}_tests PUBLIC ${PROJECT_SOURCE_DIR}/include ${DOCTEST_INCLUDE_DIR} From 204f1adb61f751a404bd97d2e18f8b5525e3017f Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 20 Sep 2023 07:57:57 +0200 Subject: [PATCH 3/5] Make classes part of the public API --- {src => include/cppIni}/Entry.h | 9 ++++++++- {src => include/cppIni}/File.h | 6 ++++-- {src => include/cppIni}/Section.h | 5 +++-- include/cppIni/cppIni.h | 6 +++--- src/CMakeLists.txt | 11 ++++++----- src/Entry.cpp | 4 ++-- src/File.cpp | 2 +- src/Section.cpp | 2 +- tests/EntryTest.cpp | 2 +- tests/FileTest.cpp | 5 +++-- tests/SectionTest.cpp | 4 ++-- 11 files changed, 34 insertions(+), 22 deletions(-) rename {src => include/cppIni}/Entry.h (97%) rename {src => include/cppIni}/File.h (94%) rename {src => include/cppIni}/Section.h (96%) diff --git a/src/Entry.h b/include/cppIni/Entry.h similarity index 97% rename from src/Entry.h rename to include/cppIni/Entry.h index ed6c1d3..19c55a0 100644 --- a/src/Entry.h +++ b/include/cppIni/Entry.h @@ -18,6 +18,7 @@ #pragma once +#include #include class Section; @@ -28,7 +29,7 @@ class Section; /// \note The value is stored as a string. /// \note The value is copied into the Entry and not moved. /// \note The parent Section is a pointer to the Section object that contains this Entry. -class Entry { +class CPPINI_EXPORT Entry { public: constexpr Entry() = default; ///< Default constructor virtual ~Entry() = default; ///< Destructor @@ -105,6 +106,12 @@ inline auto Entry::setData(std::string value) -> void m_data = std::move(value); } +template<> +inline auto Entry::setData(std::string_view value) -> void +{ + m_data = value; +} + template<> inline auto Entry::value() const -> char { return std::stoi(m_data); } template<> inline auto Entry::value() const -> short { return std::stoi(m_data); } template<> inline auto Entry::value() const -> int { return std::stoi(m_data); } diff --git a/src/File.h b/include/cppIni/File.h similarity index 94% rename from src/File.h rename to include/cppIni/File.h index 3048c3c..d4aea57 100644 --- a/src/File.h +++ b/include/cppIni/File.h @@ -18,13 +18,15 @@ #pragma once -#include "Section.h" +#include +#include +#include #include /// \brief Represents a file on disk. /// A file is a collection of Sections. -class File { +class CPPINI_EXPORT File { public: explicit File(std::string_view filename); ///< Constructor. virtual ~File() = default; ///< Destructor. diff --git a/src/Section.h b/include/cppIni/Section.h similarity index 96% rename from src/Section.h rename to include/cppIni/Section.h index 5ecddd6..308494e 100644 --- a/src/Section.h +++ b/include/cppIni/Section.h @@ -18,14 +18,15 @@ #pragma once -#include "Entry.h" +#include +#include #include /// \brief Represents a section in a configuration file /// \details A section is a collection of Entry objects with a title (e.g. [Section]) in a configuration file /// \note A section has a title and a list of Entry objects -class Section { +class CPPINI_EXPORT Section { public: explicit Section(std::string_view title, Section* parent = nullptr); ///< Constructor with title diff --git a/include/cppIni/cppIni.h b/include/cppIni/cppIni.h index e6d6991..8f7249f 100644 --- a/include/cppIni/cppIni.h +++ b/include/cppIni/cppIni.h @@ -18,6 +18,6 @@ #pragma once -#include - -int CPPINI_EXPORT one(); +#include +#include +#include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f2bd9a..268dd6c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,16 +10,17 @@ set(SOURCES set(API_HEADERS cppIni.h -) -LIST(TRANSFORM API_HEADERS PREPEND ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/) - -set(HEADERS Entry.h File.h Section.h ) +LIST(TRANSFORM API_HEADERS PREPEND ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/) + +set(PRIVATE_HEADERS + +) -add_library(${PROJECT_NAME} ${SOURCES} ${API_HEADERS} ${HEADERS}) +add_library(${PROJECT_NAME} ${SOURCES} ${API_HEADERS} ${PRIVATE_HEADERS}) include(GenerateExportHeader) string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) diff --git a/src/Entry.cpp b/src/Entry.cpp index 243c4b4..396fa1c 100644 --- a/src/Entry.cpp +++ b/src/Entry.cpp @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#include "Entry.h" -#include "Section.h" +#include +#include auto Entry::fqKey() const -> std::string { diff --git a/src/File.cpp b/src/File.cpp index 8b621b4..ad1295d 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include "File.h" +#include #include #include diff --git a/src/Section.cpp b/src/Section.cpp index 196845b..58f130d 100644 --- a/src/Section.cpp +++ b/src/Section.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include "Section.h" +#include #include diff --git a/tests/EntryTest.cpp b/tests/EntryTest.cpp index a9ee376..fe13001 100644 --- a/tests/EntryTest.cpp +++ b/tests/EntryTest.cpp @@ -20,7 +20,7 @@ #include #include -#include "../src/Entry.h" +#include TEST_SUITE_BEGIN("Entry"); diff --git a/tests/FileTest.cpp b/tests/FileTest.cpp index 7a90847..8599d90 100644 --- a/tests/FileTest.cpp +++ b/tests/FileTest.cpp @@ -16,10 +16,11 @@ * along with this program. If not, see . */ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN + #include -#include -#include "../src/File.h" +#include using namespace std::literals; diff --git a/tests/SectionTest.cpp b/tests/SectionTest.cpp index ff3fe28..f861c6e 100644 --- a/tests/SectionTest.cpp +++ b/tests/SectionTest.cpp @@ -1,5 +1,5 @@ /* - * cppIni - C++17/20/23 library for dealing with settings files + * cppIni - C++20/23 library for dealing with settings files * Copyright (C) 2023 Nils Hofmann * * This program is free software: you can redistribute it and/or modify @@ -18,7 +18,7 @@ #include -#include "../src/Section.h" +#include TEST_SUITE_BEGIN("Section"); From 8bd736dd2eae086eda7d297af9271b4ca47db0d7 Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 20 Sep 2023 07:58:12 +0200 Subject: [PATCH 4/5] Set working directory for doctest --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 652bf0e..a3dabf6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,5 +28,5 @@ if(NOT DOCTEST_CMAKE) message(FATAL_ERROR "Could not find doctest.cmake") else() include(${DOCTEST_CMAKE}) - doctest_discover_tests(${PROJECT_NAME}_tests) + doctest_discover_tests(${PROJECT_NAME}_tests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../src) endif() From c00c0d34626aca37a05f26ebf53a6de71eb730ab Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 20 Sep 2023 07:58:32 +0200 Subject: [PATCH 5/5] Let CMake link the correct target for tests --- tests/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a3dabf6..ab235f1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,7 +9,8 @@ set(TEST_SOURCES ) add_executable(${PROJECT_NAME}_tests ${TEST_SOURCES}) -target_link_libraries(${PROJECT_NAME}_tests doctest::doctest cppIni) + +target_link_libraries(${PROJECT_NAME}_tests doctest::doctest ${PROJECT_NAME}) target_compile_definitions(${PROJECT_NAME}_tests PUBLIC DOCTEST_CONFIG_NO_MULTITHREADING