Mercurial > malikania
diff tests/libclient/js-rectangle/main.cpp @ 44:f30c84b4b9ed
Tests: switch from GoogleTest to Boost.Unit, closes #588
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 30 Nov 2016 21:15:53 +0100 |
parents | fabbe1759cec |
children | fe7e3524e571 |
line wrap: on
line diff
--- a/tests/libclient/js-rectangle/main.cpp Tue Nov 29 22:25:17 2016 +0100 +++ b/tests/libclient/js-rectangle/main.cpp Wed Nov 30 21:15:53 2016 +0100 @@ -16,16 +16,17 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <gtest/gtest.h> +#define BOOST_TEST_MODULE "Javascript Rectangle" +#include <boost/test/unit_test.hpp> #include <malikania/js_rectangle.hpp> -class TestRectangle : public testing::Test { +class test_rectangle { protected: UniqueContext m_ctx; public: - TestRectangle() + test_rectangle() { duk_push_object(m_ctx); duk_put_global_string(m_ctx, "Malikania"); @@ -33,12 +34,14 @@ } }; +BOOST_FIXTURE_TEST_SUITE(test_rectangle_suite, test_rectangle) + /* * Valid constructors * ------------------------------------------------------------------ */ -TEST_F(TestRectangle, ConstructorNoArgs) +BOOST_AUTO_TEST_CASE(ConstructorNoArgs) { try { auto ret = duk_peval_string(m_ctx, @@ -54,23 +57,23 @@ } duk_get_global_string(m_ctx, "x"); - ASSERT_EQ(0, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "y"); - ASSERT_EQ(0, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "w"); - ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "h"); - ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); } catch (const std::exception &ex) { - FAIL() << ex.what(); + BOOST_FAIL(ex.what()); } } -TEST_F(TestRectangle, Constructor4Args) +BOOST_AUTO_TEST_CASE(Constructor4Args) { try { auto ret = duk_peval_string(m_ctx, @@ -86,23 +89,23 @@ } duk_get_global_string(m_ctx, "x"); - ASSERT_EQ(10, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(10, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "y"); - ASSERT_EQ(20, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(20, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "w"); - ASSERT_EQ(30U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(30U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "h"); - ASSERT_EQ(40U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(40U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); } catch (const std::exception &ex) { - FAIL() << ex.what(); + BOOST_FAIL(ex.what()); } } -TEST_F(TestRectangle, ConstructorObject) +BOOST_AUTO_TEST_CASE(ConstructorObject) { try { auto ret = duk_peval_string(m_ctx, @@ -118,23 +121,23 @@ } duk_get_global_string(m_ctx, "x"); - ASSERT_EQ(10, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(10, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "y"); - ASSERT_EQ(20, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(20, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "w"); - ASSERT_EQ(30U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(30U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "h"); - ASSERT_EQ(40U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(40U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); } catch (const std::exception &ex) { - FAIL() << ex.what(); + BOOST_FAIL(ex.what()); } } -TEST_F(TestRectangle, ConstructorNew) +BOOST_AUTO_TEST_CASE(ConstructorNew) { try { auto ret = duk_peval_string(m_ctx, @@ -150,19 +153,19 @@ } duk_get_global_string(m_ctx, "x"); - ASSERT_EQ(10, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(10, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "y"); - ASSERT_EQ(20, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(20, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "w"); - ASSERT_EQ(30U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(30U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "h"); - ASSERT_EQ(40U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(40U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); } catch (const std::exception &ex) { - FAIL() << ex.what(); + BOOST_FAIL(ex.what()); } } @@ -171,7 +174,7 @@ * ------------------------------------------------------------------ */ -TEST_F(TestRectangle, InvalidConstructorArg1) +BOOST_AUTO_TEST_CASE(InvalidConstructorArg1) { try { auto ret = duk_peval_string(m_ctx, @@ -188,17 +191,17 @@ } duk_get_global_string(m_ctx, "name"); - ASSERT_STREQ("TypeError", duk_to_string(m_ctx, -1)); + BOOST_REQUIRE_EQUAL("TypeError", duk_to_string(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "correct"); - ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); + BOOST_REQUIRE(duk_to_boolean(m_ctx, -1)); duk_pop(m_ctx); } catch (const std::exception &ex) { - FAIL() << ex.what(); + BOOST_FAIL(ex.what()); } } -TEST_F(TestRectangle, InvalidConstructorRange1) +BOOST_AUTO_TEST_CASE(InvalidConstructorRange1) { try { auto ret = duk_peval_string(m_ctx, @@ -215,13 +218,13 @@ } duk_get_global_string(m_ctx, "name"); - ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1)); + BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "correct"); - ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); + BOOST_REQUIRE(duk_to_boolean(m_ctx, -1)); duk_pop(m_ctx); } catch (const std::exception &ex) { - FAIL() << ex.what(); + BOOST_FAIL(ex.what()); } } @@ -230,7 +233,7 @@ * ------------------------------------------------------------------ */ -TEST_F(TestRectangle, requireSuccess) +BOOST_AUTO_TEST_CASE(requireSuccess) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -256,23 +259,23 @@ } duk_get_global_string(m_ctx, "x"); - ASSERT_EQ(50, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(50, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "y"); - ASSERT_EQ(80, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(80, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "w"); - ASSERT_EQ(100U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(100U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "h"); - ASSERT_EQ(200U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(200U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); } catch (const std::exception &ex) { - FAIL() << ex.what(); + BOOST_FAIL(ex.what()); } } -TEST_F(TestRectangle, requireFail) +BOOST_AUTO_TEST_CASE(requireFail) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -296,13 +299,13 @@ } duk_get_global_string(m_ctx, "name"); - ASSERT_STREQ("Error", duk_to_string(m_ctx, -1)); + BOOST_REQUIRE_EQUAL("Error", duk_to_string(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "correct"); - ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); + BOOST_REQUIRE(duk_to_boolean(m_ctx, -1)); duk_pop(m_ctx); } catch (const std::exception &ex) { - FAIL() << ex.what(); + BOOST_FAIL(ex.what()); } } @@ -311,7 +314,7 @@ * ------------------------------------------------------------------ */ -TEST_F(TestRectangle, getAdjustAll) +BOOST_AUTO_TEST_CASE(getAdjustAll) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -336,25 +339,20 @@ } duk_get_global_string(m_ctx, "x"); - ASSERT_EQ(0, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "y"); - ASSERT_EQ(0, duk_to_int(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "w"); - ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "h"); - ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); + BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); } catch (const std::exception &ex) { - FAIL() << ex.what(); + BOOST_FAIL(ex.what()); } } -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +BOOST_AUTO_TEST_SUITE_END()