Skip to content

Commit

Permalink
DeathTest Condition for AddGeneratorAt with Exception
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   tests/DataStructures/Graphs/TestPowerGrid.cpp
  • Loading branch information
franziska-wegner committed Dec 30, 2023
1 parent 51f3da2 commit a723985
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/DataStructures/Graphs/TestPowerGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ TEST_F ( TestPowerGridPyPsaExample
// ***********************************************************************
// ***********************************************************************

#ifdef EGOA_ENABLE_ASSERTION
TEST_F ( TestNetworkEmptyDeathTest
, AddGeneratorAtUsingVertexId )
{
Expand All @@ -725,6 +726,34 @@ TEST_F ( TestNetworkEmptyDeathTest
, generatorProperties );}
, assertionString );
}
#else
#ifdef EGOA_ENABLE_EXCEPTION_HANDLING
TEST_F ( TestNetworkEmpty
, AddGeneratorAtUsingVertexIdExceptionHandling )
{
TGeneratorProperties generatorProperties;
generatorProperties.Name() = "TestGenerator1";

auto assertionString = buildAssertionString ( "PowerGrid.hpp"
, "PowerGrid"
, "AddGeneratorAt"
, "Graph\\(\\).VertexExists\\( vertexId \\)");
ASSERT_DEATH ( {network_.AddGeneratorAt ( static_cast<Types::vertexId>(0)
, generatorProperties );}
, assertionString );
try {
network_.AddGeneratorAt ( static_cast<Types::vertexId>(0), generatorProperties );
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( error.what(), MatchesRegex(assertionString.c_str()) );
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
<< assertionString;
}
}
#endif // ifdef EGOA_ENABLE_EXCEPTION_HANDLING
#endif // ifdef EGOA_ENABLE_ASSERTION

TEST_F ( TestNetworkEmpty
, AddGeneratorAtUsingVertexId )
Expand Down

0 comments on commit a723985

Please sign in to comment.