From ecebc3ac7c34adc1f40dc3532e6d5998bc05bf88 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 14 Aug 2023 23:31:46 +0100 Subject: Don't support operations that don't make sense GetSubclassModelPart and GetContainedModelPart throw if called on ModelParts which don't support them. This should remove the need for shared_from_this. --- slicer/slicer/modelParts.cpp | 4 ++-- slicer/test/compilation.cpp | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index 1b40773..abe94d8 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -14,7 +14,7 @@ namespace Slicer { ModelPartPtr ModelPart::GetSubclassModelPart(const std::string &) { - return shared_from_this(); + throw std::logic_error {"GetSubclassModelPart not supported on this ModelPart"}; } TypeId @@ -69,7 +69,7 @@ namespace Slicer { ModelPartPtr ModelPart::GetContainedModelPart() { - return shared_from_this(); + throw std::logic_error {"GetContainedModelPart not supported on this ModelPart"}; } bool diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp index 6bc6993..fbbbb5f 100644 --- a/slicer/test/compilation.cpp +++ b/slicer/test/compilation.cpp @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_class) { TypeTest(TestModule::BuiltInsPtr, std::make_shared(), ModelPartForClass, ModelPartType::Complex); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } static void @@ -53,7 +53,7 @@ hookHandler(std::vector * names, const std::string & name, Slicer:: { names->push_back(name); BOOST_REQUIRE(mpp); - BOOST_REQUIRE(mpp->GetContainedModelPart()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); BOOST_REQUIRE(h); BOOST_REQUIRE_EQUAL(h->name, name); } @@ -104,61 +104,61 @@ BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_mapstructs) BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_string) { StackTypeTest(std::string, ModelPartForSimple, ModelPartType::Simple); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_bool) { StackTypeTest(bool, ModelPartForSimple, ModelPartType::Simple); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_float) { StackTypeTest(Ice::Float, ModelPartForSimple, ModelPartType::Simple); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_double) { StackTypeTest(Ice::Double, ModelPartForSimple, ModelPartType::Simple); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_byte) { StackTypeTest(Ice::Byte, ModelPartForSimple, ModelPartType::Simple); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_short) { StackTypeTest(Ice::Short, ModelPartForSimple, ModelPartType::Simple); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_int) { StackTypeTest(Ice::Int, ModelPartForSimple, ModelPartType::Simple); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_long) { StackTypeTest(Ice::Long, ModelPartForSimple, ModelPartType::Simple); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_struct) { StackTypeTest(TestModule::StructType, ModelPartForStruct, ModelPartType::Complex); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_enum) { StackTypeTest(TestModule::SomeNumbers, ModelPartForEnum, ModelPartType::Simple); - BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get()); + BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error); } BOOST_AUTO_TEST_CASE(normalClassTypeId) -- cgit v1.2.3