Skip to content

Commit

Permalink
Add test suite that loads+inits all user-facing models in the documen…
Browse files Browse the repository at this point in the history
…tation (#844)
  • Loading branch information
adamkewley committed Jul 29, 2024
1 parent 0cb1d18 commit 7b5bb36
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
experiment with scripting in a developer-facing fashion (no user-facing LUA support... yet)
- Internal: a wrapper layer was added around `ImPlot`, so that the UI code can use oscar-like
bindings, rather than translating everything to ImPlot
- Internal: the `OpenSimCreator` test suite now also ensures that all user-facing models in the
documentation can be loaded + rendered by `OpenSimCreator` (#844)


## [0.5.12] - 2024/04/29
Expand Down
1 change: 1 addition & 0 deletions tests/TestOpenSimCreator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ find_package(GTest REQUIRED CONFIG)
add_executable(TestOpenSimCreator

ComponentRegistry/TestStaticComponentRegistries.cpp
docs/TestDocumentationModels.cpp
Documents/CustomComponents/TestInMemoryMesh.cpp
Documents/Landmarks/TestLandmarkHelpers.cpp
Documents/Model/TestBasicModelStatePair.cpp
Expand Down
5 changes: 5 additions & 0 deletions tests/TestOpenSimCreator/TestOpenSimCreatorConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
// absolute path to the general resources directory for the OSC project
#define OSC_RESOURCES_DIR "@CMAKE_CURRENT_SOURCE_DIR@/../../resources"

// char[]
//
// absolute path to OpenSimCreator's documentation
#define OSC_DOCS_SOURCES_DIR "@CMAKE_CURRENT_SOURCE_DIR@/../../docs/source"

// char[]
//
// absolute path to the resources directory for this test suite
Expand Down
51 changes: 51 additions & 0 deletions tests/TestOpenSimCreator/docs/TestDocumentationModels.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// no associated header: this is a top-level integration test

#include <TestOpenSimCreator/TestOpenSimCreatorConfig.h>

#include <OpenSimCreator/Documents/Model/UndoableModelStatePair.h>
#include <OpenSimCreator/Graphics/OpenSimDecorationOptions.h>
#include <OpenSimCreator/Graphics/OpenSimDecorationGenerator.h>
#include <OpenSimCreator/Platform/OpenSimCreatorApp.h>

#include <gtest/gtest.h>
#include <oscar/Graphics/Scene/SceneCache.h>
#include <oscar/Graphics/Scene/SceneDecoration.h>
#include <oscar/Utils/FilesystemHelpers.h>

#include <array>
#include <filesystem>
#include <string_view>
#include <vector>

using namespace osc;

// sanity check: test that all user-facing `.osim` files in the documentation
// can be loaded and rendered without issue
//
// this is mostly to double-check that a configuration/library change hasn't
// bricked the documentation models
TEST(DocumentationModels, CanAllBeLoadedAndInitializedWithoutThrowingAnException)
{
GloballyInitOpenSim();
GloballyAddDirectoryToOpenSimGeometrySearchPath(std::filesystem::path{OSC_RESOURCES_DIR} / "geometry");

SceneCache cache;
OpenSimDecorationOptions options;

std::filesystem::path docSourcesDir{OSC_DOCS_SOURCES_DIR};
for_each_file_with_extensions_recursive(docSourcesDir, [&cache, &options](std::filesystem::path osim)
{
// load + initialize the documentation model
UndoableModelStatePair model{osim};

// try to generate 3D decorations from the model, which forces the backend
// to (e.g.) try and load mesh files, etc.
std::vector<SceneDecoration> decorations;
GenerateModelDecorations(cache, model.getModel(), model.getState(), options, 1.0f, [&decorations](const OpenSim::Component&, SceneDecoration&& decoration)
{
decorations.push_back(decoration);
});

ASSERT_FALSE(decorations.empty());
}, std::to_array<std::string_view>({".osim"}));
}

0 comments on commit 7b5bb36

Please sign in to comment.