/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later // SPDX-FileCopyrightText: 2013 Endless Mobile, Inc. // SPDX-FileContributor: Authored By: Sam Spilsbury #ifndef TEST_GJS_TEST_UTILS_H_ #define TEST_GJS_TEST_UTILS_H_ #include #include // for g_assert_... #include // for uintptr_t #include // for numeric_limits #include #include // for is_same #include #include "gjs/context.h" #include struct GjsUnitTestFixture { GjsContext *gjs_context; JSContext *cx; JS::Realm* realm; }; void gjs_unit_test_fixture_setup(GjsUnitTestFixture* fx, const void* unused); void gjs_unit_test_destroy_context(GjsUnitTestFixture *fx); void gjs_unit_test_fixture_teardown(GjsUnitTestFixture* fx, const void* unused); void gjs_test_add_tests_for_coverage (); void gjs_test_add_tests_for_parse_call_args(void); void gjs_test_add_tests_for_rooting(void); void gjs_test_add_tests_for_jsapi_utils(); namespace Gjs { namespace Test { void add_tests_for_toggle_queue(); template constexpr bool comparable_types() { if constexpr (std::is_same()) { return true; } else if constexpr (std::is_arithmetic_v == std::is_arithmetic_v) { return std::is_signed_v == std::is_signed_v; } else if constexpr (std::is_enum_v == std::is_enum_v) { return std::is_signed_v == std::is_signed_v; } else { return false; } } template constexpr void assert_equal(T a, U b) { static_assert(comparable_types()); if constexpr (std::is_integral_v || std::is_enum_v) { if constexpr (std::is_unsigned_v) g_assert_cmpuint(a, ==, b); else g_assert_cmpint(a, ==, b); } else if constexpr (std::is_arithmetic_v) { g_assert_cmpfloat_with_epsilon(a, b, std::numeric_limits::epsilon()); } else if constexpr (std::is_same_v) { g_assert_cmpstr(a, ==, b); } else if constexpr (std::is_same_v) { assert_equal(a.c_str(), b.c_str()); } else if constexpr (std::is_pointer_v) { assert_equal(reinterpret_cast(a), reinterpret_cast(b)); } else { g_assert_true(a == b); } } template constexpr void assert_equal(std::pair const& pair, T first, U second) { assert_equal(pair.first, first); assert_equal(pair.second, second); } } // namespace Test } // namespace Gjs #endif // TEST_GJS_TEST_UTILS_H_