Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bindings/python/tests/model/test-py-brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,20 @@ def test_registry(brep):
raise ValueError("[Test] Wrong collection registry entry")


def test_unknown_component_access():
brep = model.BRep()
unknown = basic.uuid()
try:
brep.surface(unknown)
except Exception as exception:
if f"Surface with id {unknown}" not in str(exception):
raise ValueError(
"[Test] Accessing an unknown Surface should name its type and id"
)
else:
raise ValueError("[Test] Accessing an unknown Surface should raise")


def test_component_id_hash(brep, surface_uuids):
surface = brep.surface(surface_uuids[0])
same = model.ComponentID(
Expand Down Expand Up @@ -915,6 +929,7 @@ def test_component_id_hash(brep, surface_uuids):
test_physical_properties(brep, physical_attribute_id)
test_clone(brep)
test_component_id_hash(brep, surface_uuids)
test_unknown_component_access()
brep_copy = model.BRep()
model.BRepBuilder(brep_copy).copy(brep)
test_physical_properties(brep_copy, physical_attribute_id)
Expand Down
18 changes: 14 additions & 4 deletions include/geode/model/mixin/core/detail/components_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@

void delete_component( const uuid& component_id )
{
components_.erase( components_.find( component_id ) );
const auto it = components_.find( component_id );

Check warning on line 165 in include/geode/model/mixin/core/detail/components_storage.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/model/mixin/core/detail/components_storage.hpp:165:24 [readability-identifier-length]

variable name 'it' is too short, expected at least 3 characters
check_component_exists( it, component_id );
components_.erase( it );
}

/*!
Expand Down Expand Up @@ -211,9 +213,9 @@
{
auto path = file.path();
auto filename = path.replace_extension( "" ).u8string();
if( filename.size() > 36 )

Check warning on line 216 in include/geode/model/mixin/core/detail/components_storage.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/model/mixin/core/detail/components_storage.hpp:216:39 [cppcoreguidelines-avoid-magic-numbers]

36 is a magic number; consider replacing it with a named constant
{
auto uuid = filename.substr( filename.size() - 36 );

Check warning on line 218 in include/geode/model/mixin/core/detail/components_storage.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/model/mixin/core/detail/components_storage.hpp:218:68 [cppcoreguidelines-avoid-magic-numbers]

36 is a magic number; consider replacing it with a named constant
mapping.emplace(
std::move( uuid ), file.path().u8string() );
}
Expand Down Expand Up @@ -241,7 +243,7 @@
} } } );
}

void repair_loaded_components( std::string_view filename )

Check warning on line 246 in include/geode/model/mixin/core/detail/components_storage.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/model/mixin/core/detail/components_storage.hpp:246:14 [readability-function-cognitive-complexity]

function 'repair_loaded_components' has cognitive complexity of 12 (threshold 10)
{
bool has_wrong_component{ false };
for( const auto& [component_id, component] : components_ )
Expand All @@ -267,7 +269,7 @@
component_id.string(), " from file: ", filename );
continue;
}
auto id = component->id();

Check warning on line 272 in include/geode/model/mixin/core/detail/components_storage.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/model/mixin/core/detail/components_storage.hpp:272:22 [readability-identifier-length]

variable name 'id' is too short, expected at least 3 characters
if( id != component_id )
{
Logger::warning( "[ComponentsStorage::load_components] "
Expand All @@ -287,14 +289,22 @@
components_ = std::move( repaired );
}

[[nodiscard]] Component& find_component(
void check_component_exists(
typename ComponentsStore::const_iterator it,

Check warning on line 293 in include/geode/model/mixin/core/detail/components_storage.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/model/mixin/core/detail/components_storage.hpp:293:54 [readability-identifier-length]

parameter name 'it' is too short, expected at least 3 characters
const uuid& component_id ) const
{
const auto it = components_.find( component_id );
OpenGeodeModelException::check_exception( it != components_.end(),
component_id, OpenGeodeException::TYPE::data,
"[ComponentsStorage::component] Component with id ",
"[ComponentsStorage] ",
Component::component_type_static().get(), " with id ",
component_id.string(), " does not exist" );
}

[[nodiscard]] Component& find_component(
const uuid& component_id ) const
{
const auto it = components_.find( component_id );

Check warning on line 306 in include/geode/model/mixin/core/detail/components_storage.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/model/mixin/core/detail/components_storage.hpp:306:24 [readability-identifier-length]

variable name 'it' is too short, expected at least 3 characters
check_component_exists( it, component_id );
auto& component = *it->second;
OpenGeodeModelException::check_exception(
component.id() == component_id, component_id,
Expand Down
25 changes: 25 additions & 0 deletions tests/model/test-brep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <absl/container/flat_hash_map.h>
#include <absl/strings/match.h>
#include <absl/strings/str_cat.h>

#include <geode/basic/assert.hpp>
#include <geode/basic/attribute_manager.hpp>
Expand Down Expand Up @@ -65,11 +66,11 @@

#include <geode/tests/common.hpp>

std::array< geode::uuid, 6 > add_corners(

Check warning on line 69 in tests/model/test-brep.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

tests/model/test-brep.cpp:69:30 [misc-use-internal-linkage]

function 'add_corners' can be made static or moved into an anonymous namespace to enforce internal linkage
const geode::BRep& model, geode::BRepBuilder& builder )
{
std::array< geode::uuid, 6 > uuids;

Check warning on line 72 in tests/model/test-brep.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

tests/model/test-brep.cpp:72:30 [cppcoreguidelines-avoid-magic-numbers]

6 is a magic number; consider replacing it with a named constant
for( const auto c : geode::Range{ 6 } )

Check warning on line 73 in tests/model/test-brep.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

tests/model/test-brep.cpp:73:21 [readability-identifier-length]

variable name 'c' is too short, expected at least 3 characters
{
uuids[c] = builder.add_corner();
builder.set_corner_name(
Expand Down Expand Up @@ -1873,6 +1874,29 @@
false, "Accessing an unknown component should throw" );
}

void test_remove_unknown_component()
{
geode::BRep brep;
geode::BRepBuilder builder{ brep };
builder.add_surface();
const geode::uuid unknown_id;
bool thrown{ false };
try
{
builder.remove_surfaces( { unknown_id } );
}
catch( const geode::OpenGeodeException& exception )
{
thrown = absl::StrContains( exception.what(),
absl::StrCat( "Surface with id ", unknown_id.string() ) );
}
geode::OpenGeodeModelException::test( thrown,
"Removing an unknown Surface should throw an exception naming the "
"component type and id" );
geode::OpenGeodeModelException::test( brep.nb_surfaces() == 1,
"Removing an unknown Surface should not modify the model" );
}

void test_unknown_components( const geode::BRep& model )
{
test_unknown_component_access( [&model]( const geode::uuid& id ) {
Expand Down Expand Up @@ -2177,6 +2201,7 @@
model, surface_uuids, surface_collection_uuids );
test_block_collection_ranges( model, block_uuid, block_collection_uuid );
test_unknown_components( model );
test_remove_unknown_component();
test_is_closed();
test_bounding_box();
const geode::uuid physical_attribute_id;
Expand Down
Loading