Skip to content

Commit 1e72beb

Browse files
committed
Improve coverage
1 parent 18667d4 commit 1e72beb

5 files changed

Lines changed: 36 additions & 0 deletions

File tree

application/testing/tests.custom.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ set_tests_properties(f3d::TestInvalidCLIArgs PROPERTIES PASS_REGULAR_EXPRESSION
1212
add_test(NAME f3d::TestNoCliInvalidPlugin COMMAND $<TARGET_FILE:f3d> --load-plugins=invalid --no-render)
1313
set_tests_properties(f3d::TestNoCliInvalidPlugin PROPERTIES PASS_REGULAR_EXPRESSION "Cannot open the library")
1414

15+
# Test that a file group whose file lives in the statefile directory is stored as a relative path.
16+
# The file is copied into a temporary directory next to the statefile so the relative branch is taken.
17+
add_test(NAME f3d::TestStatefileRelativeAugmentSetup
18+
COMMAND ${CMAKE_COMMAND} -E copy ${F3D_SOURCE_DIR}/testing/data/cow.vtp ${CMAKE_BINARY_DIR}/Testing/Temporary/statefile_relative/cow.vtp)
19+
set_tests_properties(f3d::TestStatefileRelativeAugmentSetup PROPERTIES FIXTURES_SETUP statefile_relative)
20+
add_test(NAME f3d::TestStatefileRelativeAugment COMMAND $<TARGET_FILE:f3d> --no-render --no-config ${CMAKE_BINARY_DIR}/Testing/Temporary/statefile_relative/cow.vtp --save-statefile=${CMAKE_BINARY_DIR}/Testing/Temporary/statefile_relative/state.json --verbose)
21+
set_tests_properties(f3d::TestStatefileRelativeAugment PROPERTIES FIXTURES_REQUIRED statefile_relative PASS_REGULAR_EXPRESSION "Statefile saved to")
22+
1523
# Test that f3d resolution can be controlled from config file
1624
add_test(NAME f3d::TestConfigResolution COMMAND $<TARGET_FILE:f3d> --config=${F3D_SOURCE_DIR}/testing/configs/resolution.json ${F3D_SOURCE_DIR}/testing/data/suzanne.stl --output=${CMAKE_BINARY_DIR}/Testing/Temporary/TestConfigResolution.png --reference=${F3D_SOURCE_DIR}/testing/baselines/TestConfigResolution.png)
1725

application/testing/tests.features.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ f3d_test(NAME TestStatefileLoadKnown DATA cow.vtp NO_RENDER NO_BASELINE ARGS --l
502502
f3d_test(NAME TestStatefileLoadOverride DATA cow.vtp NO_RENDER NO_BASELINE ARGS --load-statefile=${F3D_SOURCE_DIR}/testing/statefiles/test_statefile.json -D render.background.color=1,0,0 REGEXP "'render.background.color' = '1,0,0' from CLI options")
503503
# A missing statefile is skipped with a warning instead of failing
504504
f3d_test(NAME TestStatefileLoadMissing DATA cow.vtp NO_RENDER NO_BASELINE ARGS --load-statefile=${CMAKE_BINARY_DIR}/Testing/Temporary/does_not_exist.json REGEXP "Could not open statefile, skipping")
505+
# A file that exists but is not a valid statefile is reported and skipped
506+
f3d_test(NAME TestStatefileLoadInvalidContent DATA cow.vtp NO_RENDER NO_BASELINE ARGS --load-statefile=${F3D_SOURCE_DIR}/testing/data/cow.vtp REGEXP "Could not parse statefile content")
505507
# `-` writes the statefile to the standard output
506508
f3d_test(NAME TestStatefileSaveStdout DATA cow.vtp NO_RENDER NO_BASELINE ARGS --save-statefile=- REGEXP "\"options\"")
507509
# Missing parent directories of the statefile path are created
@@ -528,6 +530,10 @@ f3d_test(NAME TestCommandScriptLoadStatefileOverridesTweak SCRIPT DATA cow.vtp W
528530
f3d_test(NAME TestCommandScriptLoadStatefileMissing SCRIPT DATA cow.vtp WORKING_DIR ${F3D_SOURCE_DIR}/testing ARGS --verbose REGEXP "Could not open statefile, skipping" NO_BASELINE)
529531
# load_statefile with an out of range file group index falls back to the first group
530532
f3d_test(NAME TestCommandScriptLoadStatefileInvalidGroup SCRIPT DATA cow.vtp WORKING_DIR ${F3D_SOURCE_DIR}/testing ARGS --verbose REGEXP "cow.vtp" NO_BASELINE)
533+
# save_statefile and load_statefile with no argument and an empty --statefile-filename warn and no-op
534+
f3d_test(NAME TestCommandScriptStatefileEmptyFilename SCRIPT DATA cow.vtp ARGS --statefile-filename= --verbose REGEXP "No statefile location provided" NO_BASELINE)
535+
# save_statefile to a path that cannot be written (a directory) reports the error
536+
f3d_test(NAME TestCommandScriptSaveStatefileError SCRIPT DATA cow.vtp WORKING_DIR ${F3D_SOURCE_DIR}/testing ARGS --verbose REGEXP "Could not save statefile" NO_BASELINE)
531537

532538
# The clipboard round-trip needs a real onscreen window for the X11 selection to work, it fails with
533539
# the offscreen backends (egl, osmesa), so only run it where an onscreen window is available, ie on

library/testing/TestSDKStatefile.cxx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,27 @@ int TestSDKStatefile([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
104104
test(
105105
"no option statefile leaves no added file", noOptEng.getScene().getAddedFiles().empty(), true);
106106

107+
// Options that do not exist or cannot be parsed are skipped with a warning, not a failure
108+
f3d::engine optEng = f3d::engine::createNone();
109+
optEng.loadStatefileFromString("{ \"options\": { \"not.a.real.option\": \"1\" } }");
110+
optEng.loadStatefileFromString("{ \"options\": { \"render.line_width\": \"not_a_number\" } }");
111+
test("invalid options are skipped", optEng.getScene().getAddedFiles().empty(), true);
112+
113+
// Restoring a camera into an engine without a window is skipped with a log, not a failure
114+
f3d::engine noWinEng = f3d::engine::createNone();
115+
noWinEng.loadStatefileFromString(
116+
"{ \"camera\": { \"position\": [0.0, 0.0, 1.0], "
117+
"\"focal_point\": [0.0, 0.0, 0.0], \"view_up\": [0.0, 1.0, 0.0], "
118+
"\"view_angle\": 30.0 } }");
119+
test("camera without window is skipped", noWinEng.getScene().getAddedFiles().empty(), true);
120+
107121
// Failure modes
122+
const fs::path invalidStatefilePath = tmpDir / "invalid_statefile.json";
123+
std::ofstream(invalidStatefilePath) << "{ not valid json";
108124
test.expect<f3d::engine::statefile_exception>(
109125
"load a non existent statefile", [&]() { dst.loadStatefile(tmpDir / "no_such_file.json"); });
126+
test.expect<f3d::engine::statefile_exception>(
127+
"load an invalid statefile file", [&]() { dst.loadStatefile(invalidStatefilePath); });
110128
test.expect<f3d::engine::statefile_exception>(
111129
"load invalid statefile content", [&]() { dst.loadStatefileFromString("{ not valid json"); });
112130

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
save_statefile data
2+
save_statefile data/cow.vtp/sub/state.json
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
save_statefile
2+
load_statefile

0 commit comments

Comments
 (0)