From d18d55b377926aa69db45a0189c0e8db09f37f30 Mon Sep 17 00:00:00 2001 From: kamchatka-volcano Date: Sun, 14 Jan 2024 23:21:13 +0300 Subject: [PATCH] -added static reflection examples and functional tests --- .github/workflows/build_and_test.yml | 17 +++++--- CMakeLists.txt | 17 +++----- examples/demo.h | 43 ++++++++++++++++++- examples_static_refl/CMakeLists.txt | 19 ++++++++ .../example_1_static_refl/test.toast | 12 ++++++ .../example_2_static_refl/test.toast | 12 ++++++ .../example_3_static_refl/test.toast | 13 ++++++ .../example_4_static_refl/test.toast | 5 +++ functional_tests/lunchtoast.cfg | 16 +++++++ .../test_ini_static_refl/test.toast | 5 +++ .../test_json_static_refl/test.toast | 7 +++ .../test_shoal_static_refl/test.toast | 5 +++ .../test_toml_static_refl/test.toast | 5 +++ .../test_xml_static_refl/test.toast | 5 +++ .../test_yaml_static_refl/test.toast | 7 +++ 15 files changed, 171 insertions(+), 17 deletions(-) create mode 100644 examples_static_refl/CMakeLists.txt create mode 100644 functional_tests/example_1_static_refl/test.toast create mode 100644 functional_tests/example_2_static_refl/test.toast create mode 100644 functional_tests/example_3_static_refl/test.toast create mode 100644 functional_tests/example_4_static_refl/test.toast create mode 100644 functional_tests/test_ini_static_refl/test.toast create mode 100644 functional_tests/test_json_static_refl/test.toast create mode 100644 functional_tests/test_shoal_static_refl/test.toast create mode 100644 functional_tests/test_toml_static_refl/test.toast create mode 100644 functional_tests/test_xml_static_refl/test.toast create mode 100644 functional_tests/test_yaml_static_refl/test.toast diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 24a7949..ed8338a 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -29,7 +29,7 @@ jobs: cc: "gcc", cxx: "g++", flags: "-Wall -Werror -Wextra -Wpedantic -Wcast-align -Wnon-virtual-dtor -Woverloaded-virtual -Wunused", - artifacts-path: "build/examples" + artifacts-path: "" } - { name: "Ubuntu Latest clang", @@ -37,7 +37,7 @@ jobs: cc: "clang", cxx: "clang++", flags: "-Wall -Werror -Wextra -Wpedantic -Wcast-align -Wnon-virtual-dtor -Woverloaded-virtual -Wunused", - artifacts-path: "build/examples" + artifacts-path: "" } - { name: "Windows Latest MSVC", @@ -45,14 +45,14 @@ jobs: cc: "cl", cxx: "cl", flags: "/EHsc /W4 /WX /wd4267", - artifacts-path: "build/examples/Release" + artifacts-path: "/Release" } steps: - uses: actions/checkout@v3 - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -DENABLE_TESTS_CPP20=ON -DENABLE_TESTS_STATIC_REFL=ON -DENABLE_EXAMPLES=ON -DFIGCONE_USE_NAMEOF=${{ matrix.use_nameof }} -DCMAKE_CXX_FLAGS="${{ matrix.config.flags }}" + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -DENABLE_TESTS_CPP20=ON -DENABLE_TESTS_STATIC_REFL=ON -DENABLE_EXAMPLES=ON -DENABLE_EXAMPLES_STATIC_REFL=ON -DFIGCONE_USE_NAMEOF=${{ matrix.use_nameof }} -DCMAKE_CXX_FLAGS="${{ matrix.config.flags }}" - name: Build run: cmake --build ${{github.workspace}}/build --config Release @@ -65,7 +65,9 @@ jobs: uses: actions/upload-artifact@v3 with: name: figcone-examples-${{ matrix.config.os }}-nameof-${{ matrix.use_nameof }} - path: ${{ matrix.config.artifacts-path }} + path: | + "build/examples${{ matrix.config.artifacts-path }}" + "build/examples_static_refl${{ matrix.config.artifacts-path }}" functional_tests: name: Functional testing (${{ matrix.config.name }}, nameof = ${{ matrix.use_nameof }}) @@ -116,6 +118,11 @@ jobs: shell: sh working-directory: ${{github.workspace}}/build/examples run: chmod +x ex* && chmod +x demo_* + - name: Set artifacts execute permissions + if: matrix.config.name == 'Linux' + shell: sh + working-directory: ${{github.workspace}}/build/examples_static_refl + run: chmod +x ex* && chmod +x demo_* - name: Launch tests id: launch_tests working-directory: ${{github.workspace}} diff --git a/CMakeLists.txt b/CMakeLists.txt index f38d6eb..eba79cf 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,15 +97,6 @@ SealLake_HeaderOnlyLibrary( figcone_tree 2.0.0 ) -#if (FIGCONE_USE_NAMEOF) -# SealLake_Libraries( -# nameof::nameof -# ) -# SealLake_Dependencies( -# nameof 0.10.2 -# ) -#endif() - if (FIGCONE_USE_ALL OR FIGCONE_USE_JSON OR FIGCONE_USE_YAML OR FIGCONE_USE_TOML OR FIGCONE_USE_INI OR FIGCONE_USE_XML OR FIGCONE_USE_SHOAL) SealLake_Libraries( figcone::figcone_formats @@ -115,4 +106,10 @@ if (FIGCONE_USE_ALL OR FIGCONE_USE_JSON OR FIGCONE_USE_YAML OR FIGCONE_USE_TOML ) endif () -SealLake_OptionalBuildSteps(tests tests_cpp20 tests_static_refl examples) \ No newline at end of file +SealLake_OptionalBuildSteps( + tests + tests_cpp20 + tests_static_refl + examples + examples_static_refl +) \ No newline at end of file diff --git a/examples/demo.h b/examples/demo.h index a8c4c40..414751f 100644 --- a/examples/demo.h +++ b/examples/demo.h @@ -1,10 +1,47 @@ #pragma once -#include +#include #include //enables macros without FIGCONE_ prefix #include #include #include +#ifdef FIGCONE_EXAMPLE_STATIC_REFLECTION + +struct ThumbnailCfg { + bool enabled = true; + int maxWidth; + int maxHeight; + + using traits = figcone::FieldTraits< + figcone::OptionalField<&ThumbnailCfg::enabled>>; +}; +struct HostCfg { + std::string ip; + int port; +}; +struct SharedAlbumCfg { + std::filesystem::path dir; + std::string name; + std::vector hosts; + + using traits = figcone::FieldTraits< + figcone::OptionalField<&SharedAlbumCfg::hosts>>; +}; +struct PhotoViewerCfg { + std::filesystem::path rootDir; + std::vector supportedFiles; + ThumbnailCfg thumbnails; + std::vector sharedAlbums; + std::map envVars; + + using traits = figcone::FieldTraits< + figcone::OptionalField<&PhotoViewerCfg::envVars>, + figcone::OptionalField<&PhotoViewerCfg::sharedAlbums>, + figcone::CopyNodeListField<&PhotoViewerCfg::sharedAlbums>>; +}; + +#else + struct ThumbnailCfg : public figcone::Config { PARAM(enabled, bool)(true); @@ -27,4 +64,6 @@ struct PhotoViewerCfg : public figcone::Config{ COPY_NODELIST(sharedAlbums, std::vector)(); using StringMap = std::map; DICT(envVars, StringMap)(); -}; \ No newline at end of file +}; + +#endif \ No newline at end of file diff --git a/examples_static_refl/CMakeLists.txt b/examples_static_refl/CMakeLists.txt new file mode 100644 index 0000000..ca40a64 --- /dev/null +++ b/examples_static_refl/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.18) +project(figcone_examples_static_refl) + +file(GLOB SRC_FILES "../examples/*.cpp") +foreach(SRC_FILE ${SRC_FILES}) + SealLake_StringAfterLast(${SRC_FILE} "/" TEST_NAME) + SealLake_StringBeforeLast(${TEST_NAME} "." TEST_NAME) + + SealLake_Executable( + NAME ${TEST_NAME}_static_refl + SOURCES ${SRC_FILE} + COMPILE_FEATURES cxx_std_20 + PROPERTIES + CXX_EXTENSIONS OFF + LIBRARIES + figcone::figcone + ) + target_compile_definitions(${TEST_NAME}_static_refl PUBLIC "FIGCONE_EXAMPLE_STATIC_REFLECTION") +endforeach() \ No newline at end of file diff --git a/functional_tests/example_1_static_refl/test.toast b/functional_tests/example_1_static_refl/test.toast new file mode 100644 index 0000000..cd29392 --- /dev/null +++ b/functional_tests/example_1_static_refl/test.toast @@ -0,0 +1,12 @@ +-Suite: static reflection examples + +-Check static reflection example #1: +Launching PhotoViewer in directory "~/Photos" +Supported files: + .jpg + .png +Thumbnail settings: + Max width:256 + Max height:256 + +--- \ No newline at end of file diff --git a/functional_tests/example_2_static_refl/test.toast b/functional_tests/example_2_static_refl/test.toast new file mode 100644 index 0000000..9adc3b6 --- /dev/null +++ b/functional_tests/example_2_static_refl/test.toast @@ -0,0 +1,12 @@ +-Suite: static reflection examples + +-Check static reflection example #2: +Launching PhotoViewer in directory "/home/kamchatka-volcano/photos" +Supported files: + .jpg + .png +Thumbnail settings: + Max width:256 + Max height:256 + +--- \ No newline at end of file diff --git a/functional_tests/example_3_static_refl/test.toast b/functional_tests/example_3_static_refl/test.toast new file mode 100644 index 0000000..58f94af --- /dev/null +++ b/functional_tests/example_3_static_refl/test.toast @@ -0,0 +1,13 @@ +-Suite: static reflection examples + +-Check static reflection example #3: +Launching PhotoViewer in directory "~/Photos" +Supported files: + .jpg + png +Shared albums: + Album:Summer 2019 + Hosts: + 127.0.0.1:8080 + +--- \ No newline at end of file diff --git a/functional_tests/example_4_static_refl/test.toast b/functional_tests/example_4_static_refl/test.toast new file mode 100644 index 0000000..299e0d4 --- /dev/null +++ b/functional_tests/example_4_static_refl/test.toast @@ -0,0 +1,5 @@ +-Suite: static reflection examples + +-Check static reflection example #4: +Config error:Parameter 'rootDir': a path must exist +--- \ No newline at end of file diff --git a/functional_tests/lunchtoast.cfg b/functional_tests/lunchtoast.cfg index 3258de8..b2b3313 100644 --- a/functional_tests/lunchtoast.cfg +++ b/functional_tests/lunchtoast.cfg @@ -15,6 +15,22 @@ command = ../../build/examples/demo_all ../../examples/%1 checkOutput = %input +### + format = Check %1 static reflection demo + command = ../../build/examples_static_refl/demo_%1_static_refl + checkOutput = %input + +### + format = Check static reflection example #%1 + command = ../../build/examples_static_refl/ex0%1_static_refl + checkOutput = %input + checkExitCode = any + +### + format = Check all formats static reflection demo with %1 + command = ../../build/examples/demo_all_static_refl ../../examples/%1 + checkOutput = %input + ### format = Ensure error message file %1 command = ../paths_to_filename.sh %1 diff --git a/functional_tests/test_ini_static_refl/test.toast b/functional_tests/test_ini_static_refl/test.toast new file mode 100644 index 0000000..7ca9dca --- /dev/null +++ b/functional_tests/test_ini_static_refl/test.toast @@ -0,0 +1,5 @@ +-Name: ini +-Suite: static reflection format support + +-Check ini static reflection demo: ${{ format_demo_expected_output }} +-Check all formats static reflection demo with demo.ini: ${{ format_demo_expected_output }} \ No newline at end of file diff --git a/functional_tests/test_json_static_refl/test.toast b/functional_tests/test_json_static_refl/test.toast new file mode 100644 index 0000000..33d03b0 --- /dev/null +++ b/functional_tests/test_json_static_refl/test.toast @@ -0,0 +1,7 @@ +-Name: json +-Suite: static reflection format support + +-Check json static reflection demo: ${{ format_demo_expected_output }} +-Check all formats static reflection demo with demo.json: ${{ format_demo_expected_output }} + +-Check json_root_list static reflection demo: ${{ format_demo_root_list_expected_output }} \ No newline at end of file diff --git a/functional_tests/test_shoal_static_refl/test.toast b/functional_tests/test_shoal_static_refl/test.toast new file mode 100644 index 0000000..e13b824 --- /dev/null +++ b/functional_tests/test_shoal_static_refl/test.toast @@ -0,0 +1,5 @@ +-Name: shoal +-Suite: static reflection format support + +-Check shoal static reflection demo: ${{ format_demo_expected_output }} +-Check all formats static reflection demo with demo.shoal: ${{ format_demo_expected_output }} \ No newline at end of file diff --git a/functional_tests/test_toml_static_refl/test.toast b/functional_tests/test_toml_static_refl/test.toast new file mode 100644 index 0000000..ff47fad --- /dev/null +++ b/functional_tests/test_toml_static_refl/test.toast @@ -0,0 +1,5 @@ +-Name: toml +-Suite: static reflection format support + +-Check toml static reflection demo: ${{ format_demo_expected_output }} +-Check all formats static reflection demo with demo.toml: ${{ format_demo_expected_output }} \ No newline at end of file diff --git a/functional_tests/test_xml_static_refl/test.toast b/functional_tests/test_xml_static_refl/test.toast new file mode 100644 index 0000000..a50e4f5 --- /dev/null +++ b/functional_tests/test_xml_static_refl/test.toast @@ -0,0 +1,5 @@ +-Name: xml +-Suite: static reflection format support + +-Check xml static reflection demo: ${{ format_demo_expected_output }} +-Check all formats static reflection demo with demo.xml: ${{ format_demo_expected_output }} \ No newline at end of file diff --git a/functional_tests/test_yaml_static_refl/test.toast b/functional_tests/test_yaml_static_refl/test.toast new file mode 100644 index 0000000..ab87c1f --- /dev/null +++ b/functional_tests/test_yaml_static_refl/test.toast @@ -0,0 +1,7 @@ +-Name: yaml +-Suite: static reflection format support + +-Check yaml static reflection demo: ${{ format_demo_expected_output }} +-Check all formats static reflection demo with demo.yaml: ${{ format_demo_expected_output }} + +-Check yaml_root_list static reflection demo: ${{ format_demo_root_list_expected_output }} \ No newline at end of file