Skip to content

Commit

Permalink
-added static reflection examples and functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamchatka-volcano committed Jan 14, 2024
1 parent d846265 commit d18d55b
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 17 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,30 @@ 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",
os: ubuntu-latest,
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",
os: windows-latest,
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
Expand All @@ -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 }})
Expand Down Expand Up @@ -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}}
Expand Down
17 changes: 7 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
SealLake_OptionalBuildSteps(
tests
tests_cpp20
tests_static_refl
examples
examples_static_refl
)
43 changes: 41 additions & 2 deletions examples/demo.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
#pragma once
#include <figcone/config.h>
#include <figcone/figcone.h>
#include <figcone/shortmacros.h> //enables macros without FIGCONE_ prefix
#include <string>
#include <vector>
#include <map>

#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<HostCfg> hosts;

using traits = figcone::FieldTraits<
figcone::OptionalField<&SharedAlbumCfg::hosts>>;
};
struct PhotoViewerCfg {
std::filesystem::path rootDir;
std::vector<std::string> supportedFiles;
ThumbnailCfg thumbnails;
std::vector<SharedAlbumCfg> sharedAlbums;
std::map<std::string, std::string> 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);
Expand All @@ -27,4 +64,6 @@ struct PhotoViewerCfg : public figcone::Config{
COPY_NODELIST(sharedAlbums, std::vector<SharedAlbumCfg>)();
using StringMap = std::map<std::string, std::string>;
DICT(envVars, StringMap)();
};
};

#endif
19 changes: 19 additions & 0 deletions examples_static_refl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 12 additions & 0 deletions functional_tests/example_1_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -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

---
12 changes: 12 additions & 0 deletions functional_tests/example_2_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -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

---
13 changes: 13 additions & 0 deletions functional_tests/example_3_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -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

---
5 changes: 5 additions & 0 deletions functional_tests/example_4_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-Suite: static reflection examples

-Check static reflection example #4:
Config error:Parameter 'rootDir': a path must exist
---
16 changes: 16 additions & 0 deletions functional_tests/lunchtoast.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions functional_tests/test_ini_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -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 }}
7 changes: 7 additions & 0 deletions functional_tests/test_json_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 5 additions & 0 deletions functional_tests/test_shoal_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 5 additions & 0 deletions functional_tests/test_toml_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 5 additions & 0 deletions functional_tests/test_xml_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -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 }}
7 changes: 7 additions & 0 deletions functional_tests/test_yaml_static_refl/test.toast
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit d18d55b

Please sign in to comment.