Skip to content

Commit

Permalink
More NLHandler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Mar 2, 2016
1 parent df7eaa6 commit 4f2e047
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions test/nl-reader-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1586,14 +1586,24 @@ TEST(NLReaderTest, NameReader) {
EXPECT_EQ("def", names[1].to_string());
}

struct DummyNLHandler : public mp::NLHandler<DummyNLHandler, int> {};

TEST(NLReaderTest, OnUnhandled) {
DummyNLHandler handler;
EXPECT_THROW_MSG(handler.OnUnhandled("foo"), mp::UnsupportedError,
"unsupported: foo");
EXPECT_THROW_MSG(handler.OnHeader(mp::NLHeader()), mp::UnsupportedError,
"unsupported: NL header");
}

#define EXPECT_UNHANDLED(kind, call) { \
MockNLHandler handler; \
mp::NLHandler<MockNLHandler, TestExpr> &base = handler; \
EXPECT_CALL(handler, OnUnhandled(testing::StrEq(kind))); \
base.call; \
}

TEST(NLReaderTest, OnUnhandled) {
TEST(NLReaderTest, OnUnhandledDispatch) {
EXPECT_UNHANDLED("NL header", OnHeader(mp::NLHeader()));
EXPECT_UNHANDLED("objective", OnObj(0, mp::obj::MAX, TestExpr()));
EXPECT_UNHANDLED("nonlinear constraint", OnAlgebraicCon(0, TestExpr()));
Expand Down Expand Up @@ -1666,5 +1676,6 @@ TEST(NLReaderTest, OnUnhandled) {
}

TEST(NLReaderTest, NullNLHandler) {
// TODO: test
mp::NullNLHandler<int> handler;
handler.OnHeader(mp::NLHeader());
}

0 comments on commit 4f2e047

Please sign in to comment.