Skip to content

Commit

Permalink
[unittest] Add googletests to check guards
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jan 20, 2024
1 parent cee4e62 commit 0ead71c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/zeroD/test_zeroD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ TEST(zerodim, simple)
}
}

// Test guards preventing segfaults for uninitialized zerodim objects
TEST(zerodim, test_guards)
{
// Reactor with no contents
Reactor reactor;
EXPECT_THROW(reactor.temperature(), CanteraError);
EXPECT_THROW(reactor.density(), CanteraError);
EXPECT_THROW(reactor.massFractions(), CanteraError);
EXPECT_THROW(reactor.massFraction(0), CanteraError);

// Wall with no adjacent reactors
Wall wall;
EXPECT_THROW(wall.heatRate(), CanteraError);
EXPECT_THROW(wall.expansionRate(), CanteraError);
suppress_deprecation_warnings();
EXPECT_THROW(wall.Q(0.), CanteraError);
EXPECT_THROW(wall.vdot(0.), CanteraError);
make_deprecation_warnings_fatal();

// FlowDevice with no adjacent reactors
EXPECT_THROW(FlowDevice().massFlowRate(), CanteraError);
EXPECT_THROW(MassFlowController().updateMassFlowRate(0.), CanteraError);
EXPECT_THROW(PressureController().updateMassFlowRate(0.), CanteraError);
EXPECT_THROW(Valve().updateMassFlowRate(0.), CanteraError);
}

// This test ensures that prior reactor initialization of a reactor does
// not affect later integration within a network. This example was
// adapted from test_reactor.py::test_equilibrium_HP.
Expand Down

0 comments on commit 0ead71c

Please sign in to comment.