Mercurial > malikania
diff tests/libclient/js-color/main.cpp @ 53:fe7e3524e571
Tests: various style fixes
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 16 Dec 2016 13:07:44 +0100 |
parents | f30c84b4b9ed |
children | 96ba0c5cf893 |
line wrap: on
line diff
--- a/tests/libclient/js-color/main.cpp Thu Dec 15 13:46:46 2016 +0100 +++ b/tests/libclient/js-color/main.cpp Fri Dec 16 13:07:44 2016 +0100 @@ -46,11 +46,13 @@ BOOST_FIXTURE_TEST_SUITE(test_color_suite, test_color) /* - * Valid constructors + * Valid constructors. * ------------------------------------------------------------------ */ -BOOST_AUTO_TEST_CASE(ConstructorNoArgs) +BOOST_AUTO_TEST_SUITE(constructors) + +BOOST_AUTO_TEST_CASE(constructor_default) { try { auto ret = duk_peval_string(m_ctx, @@ -61,8 +63,9 @@ "a = c.alpha;" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } BOOST_REQUIRE_EQUAL(0, component("r")); BOOST_REQUIRE_EQUAL(0, component("g")); @@ -73,7 +76,7 @@ } } -BOOST_AUTO_TEST_CASE(ConstructorString) +BOOST_AUTO_TEST_CASE(constructor_string) { try { auto ret = duk_peval_string(m_ctx, @@ -84,8 +87,9 @@ "a = c.alpha;" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } BOOST_REQUIRE_EQUAL(255, component("r")); BOOST_REQUIRE_EQUAL(255, component("g")); @@ -96,7 +100,7 @@ } } -BOOST_AUTO_TEST_CASE(ConstructorStringRgb) +BOOST_AUTO_TEST_CASE(constructor_string_rgb) { try { auto ret = duk_peval_string(m_ctx, @@ -107,8 +111,9 @@ "a = c.alpha;" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } BOOST_REQUIRE_EQUAL(0, component("r")); BOOST_REQUIRE_EQUAL(0, component("g")); @@ -119,7 +124,7 @@ } } -BOOST_AUTO_TEST_CASE(Constructor3Args) +BOOST_AUTO_TEST_CASE(constructor_3_args) { try { auto ret = duk_peval_string(m_ctx, @@ -130,8 +135,9 @@ "a = c.alpha;" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } BOOST_REQUIRE_EQUAL(10, component("r")); BOOST_REQUIRE_EQUAL(20, component("g")); @@ -142,7 +148,7 @@ } } -BOOST_AUTO_TEST_CASE(Constructor4Args) +BOOST_AUTO_TEST_CASE(constructor_4_args) { try { auto ret = duk_peval_string(m_ctx, @@ -153,8 +159,9 @@ "a = c.alpha;" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } BOOST_REQUIRE_EQUAL(10, component("r")); BOOST_REQUIRE_EQUAL(20, component("g")); @@ -165,7 +172,7 @@ } } -BOOST_AUTO_TEST_CASE(ConstructorObjectNoAlpha) +BOOST_AUTO_TEST_CASE(constructor_object_no_alpha) { try { auto ret = duk_peval_string(m_ctx, @@ -176,8 +183,9 @@ "a = c.alpha;" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } BOOST_REQUIRE_EQUAL(10, component("r")); BOOST_REQUIRE_EQUAL(20, component("g")); @@ -188,7 +196,7 @@ } } -BOOST_AUTO_TEST_CASE(ConstructorObjectAlpha) +BOOST_AUTO_TEST_CASE(constructor_object_alpha) { try { auto ret = duk_peval_string(m_ctx, @@ -199,8 +207,9 @@ "a = c.alpha;" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } BOOST_REQUIRE_EQUAL(10, component("r")); BOOST_REQUIRE_EQUAL(20, component("g")); @@ -211,7 +220,7 @@ } } -BOOST_AUTO_TEST_CASE(ConstructorNew) +BOOST_AUTO_TEST_CASE(constructor_new) { /* * Just one test, function parse the same way, only 'this' or a new object is returned. @@ -225,8 +234,9 @@ "a = c.alpha;" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } BOOST_REQUIRE_EQUAL(10, component("r")); BOOST_REQUIRE_EQUAL(20, component("g")); @@ -237,12 +247,16 @@ } } +BOOST_AUTO_TEST_SUITE_END() + /* - * Valid constructors + * Invalid constructors. * ------------------------------------------------------------------ */ -BOOST_AUTO_TEST_CASE(InvalidConstructorArg1) +BOOST_AUTO_TEST_SUITE(invalid_constructors) + +BOOST_AUTO_TEST_CASE(constructor_arg_1) { try { auto ret = duk_peval_string(m_ctx, @@ -254,8 +268,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("TypeError", duk_to_string(m_ctx, -1)); @@ -268,7 +283,7 @@ } } -BOOST_AUTO_TEST_CASE(InvalidConstructorArg2) +BOOST_AUTO_TEST_CASE(constructor_arg_2) { try { auto ret = duk_peval_string(m_ctx, @@ -280,8 +295,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("TypeError", duk_to_string(m_ctx, -1)); @@ -294,7 +310,7 @@ } } -BOOST_AUTO_TEST_CASE(InvalidConstructorRange1) +BOOST_AUTO_TEST_CASE(constructor_range_1) { try { auto ret = duk_peval_string(m_ctx, @@ -306,8 +322,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); @@ -320,7 +337,7 @@ } } -BOOST_AUTO_TEST_CASE(InvalidConstructorRange2) +BOOST_AUTO_TEST_CASE(constructor_range_2) { try { auto ret = duk_peval_string(m_ctx, @@ -332,8 +349,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); @@ -346,7 +364,7 @@ } } -BOOST_AUTO_TEST_CASE(InvalidConstructorRange3) +BOOST_AUTO_TEST_CASE(constructor_range_3) { try { auto ret = duk_peval_string(m_ctx, @@ -358,8 +376,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); @@ -372,7 +391,7 @@ } } -BOOST_AUTO_TEST_CASE(InvalidConstructorRange4) +BOOST_AUTO_TEST_CASE(constructor_object_range_red) { try { auto ret = duk_peval_string(m_ctx, @@ -384,8 +403,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); @@ -398,7 +418,7 @@ } } -BOOST_AUTO_TEST_CASE(InvalidConstructorRange5) +BOOST_AUTO_TEST_CASE(constructor_object_range_alpha) { try { auto ret = duk_peval_string(m_ctx, @@ -410,8 +430,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); @@ -424,7 +445,7 @@ } } -BOOST_AUTO_TEST_CASE(InvalidConstructorStringUnknown) +BOOST_AUTO_TEST_CASE(constructor_string) { try { auto ret = duk_peval_string(m_ctx, @@ -436,8 +457,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("Error", duk_to_string(m_ctx, -1)); @@ -450,7 +472,7 @@ } } -BOOST_AUTO_TEST_CASE(InvalidConstructorStringRgb) +BOOST_AUTO_TEST_CASE(constructor_string_rgb) { try { auto ret = duk_peval_string(m_ctx, @@ -462,8 +484,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("Error", duk_to_string(m_ctx, -1)); @@ -476,6 +499,8 @@ } } +BOOST_AUTO_TEST_SUITE_END() + /* * Require. * ------------------------------------------------------------------ @@ -484,7 +509,9 @@ * can be ommitted but if it is present and incorrect, an exception is also raised. */ -BOOST_AUTO_TEST_CASE(requireSuccess) +BOOST_AUTO_TEST_SUITE(require) + +BOOST_AUTO_TEST_CASE(success) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -505,8 +532,9 @@ auto ret = duk_peval_string(m_ctx, "draw('#ff0000');"); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "r"); BOOST_REQUIRE_EQUAL(255U, duk_to_uint(m_ctx, -1)); @@ -525,7 +553,7 @@ } } -BOOST_AUTO_TEST_CASE(requireFail) +BOOST_AUTO_TEST_CASE(fail) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -544,8 +572,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("Error", duk_to_string(m_ctx, -1)); @@ -558,7 +587,7 @@ } } -BOOST_AUTO_TEST_CASE(requireFailAlpha) +BOOST_AUTO_TEST_CASE(fail_alpha) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -577,8 +606,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "name"); BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); @@ -591,6 +621,8 @@ } } +BOOST_AUTO_TEST_SUITE_END() + /* * Get. * ------------------------------------------------------------------ @@ -598,7 +630,9 @@ * TypeTraits<Color>::get readjust any invalid values. */ -BOOST_AUTO_TEST_CASE(getNormal) +BOOST_AUTO_TEST_SUITE(get) + +BOOST_AUTO_TEST_CASE(normal) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -619,8 +653,9 @@ auto ret = duk_peval_string(m_ctx, "draw('#ff0000');"); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "r"); BOOST_REQUIRE_EQUAL(255U, duk_to_uint(m_ctx, -1)); @@ -639,7 +674,7 @@ } } -BOOST_AUTO_TEST_CASE(getAdjustRgb) +BOOST_AUTO_TEST_CASE(adjust_rgb) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -660,8 +695,9 @@ auto ret = duk_peval_string(m_ctx, "draw('#ghijkl');"); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "r"); BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); @@ -680,7 +716,7 @@ } } -BOOST_AUTO_TEST_CASE(getAdjustAll) +BOOST_AUTO_TEST_CASE(adjust_all) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -701,8 +737,9 @@ auto ret = duk_peval_string(m_ctx, "draw({ red: -1, green: 256, blue: 100, alpha: 800 });"); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "r"); BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); @@ -721,7 +758,7 @@ } } -BOOST_AUTO_TEST_CASE(getSomethingElse) +BOOST_AUTO_TEST_CASE(something_else) { try { duk_push_c_function(m_ctx, [] (auto ctx) { @@ -742,8 +779,9 @@ auto ret = duk_peval_string(m_ctx, "draw(null);"); - if (ret != 0) + if (ret != 0) { throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "r"); BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); @@ -763,3 +801,5 @@ } BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END()