From 1b23f91f722c1d43ae1277e7120792bdc1cf8df4 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Mon, 3 Sep 2018 13:48:18 +0300 Subject: [PATCH] Unit test for EN_addcontrol --- tests/test_toolkit.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/test_toolkit.cpp b/tests/test_toolkit.cpp index f514a26..e3f1997 100644 --- a/tests/test_toolkit.cpp +++ b/tests/test_toolkit.cpp @@ -260,4 +260,61 @@ BOOST_FIXTURE_TEST_CASE(test_addpattern, Fixture) BOOST_REQUIRE(pat_index == n_patterns_2); } +BOOST_FIXTURE_TEST_CASE(test_add_control, Fixture) +{ + int flag = 00; + long t, tstep; + float h1, h2; + + // run with original controls + error = EN_openH(ph); + BOOST_REQUIRE(error == 0); + error = EN_initH(ph, flag); + BOOST_REQUIRE(error == 0); + do { + error = EN_runH(ph, &t); + BOOST_REQUIRE(error == 0); + error = EN_getnodevalue(ph, 11, EN_HEAD, h1); // get the tank head + BOOST_REQUIRE(error == 0); + error = EN_nextH(ph, &tstep); + BOOST_REQUIRE(error == 0); + } while (tstep > 0); + + error = EN_closeH(ph); + BOOST_REQUIRE(error == 0); + + // disable current controls + error = ENsetcontrol(ph, 1, EN_LOWLEVEL, 0, 0, 0, 0); + BOOST_REQUIRE(error == 0); + error = ENsetcontrol(ph, 2, EN_HILEVEL, 0, 0, 0, 0); + BOOST_REQUIRE(error == 0); + + // add new controls + error = ENaddcontrol(ph, Cindex, EN_LOWLEVEL, Lindex, 1, Nindex, 110); + BOOST_REQUIRE(error == 0); + BOOST_REQUIRE(Cindex == 3); + error = ENaddcontrol(ph, Cindex, EN_HILEVEL, Lindex, 0, Nindex, 140); + BOOST_REQUIRE(error == 0); + BOOST_REQUIRE(Cindex == 4); + + // run with new controls + error = EN_openH(ph); + BOOST_REQUIRE(error == 0); + error = EN_initH(ph, flag); + BOOST_REQUIRE(error == 0); + do { + error = EN_runH(ph, &t); + BOOST_REQUIRE(error == 0); + error = EN_getnodevalue(ph, 11, EN_HEAD, h2); // get the tank head + BOOST_REQUIRE(error == 0); + error = EN_nextH(ph, &tstep); + BOOST_REQUIRE(error == 0); + } while (tstep > 0); + + error = EN_closeH(ph); + BOOST_REQUIRE(error == 0); + + BOOST_REQUIRE(h1 == h2); // end head should be the same with new controls +} + BOOST_AUTO_TEST_SUITE_END()