summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (TreviƱo) <mail@3v1n0.net>2020-09-07 14:43:26 +0200
committerPhilip Chimento <philip.chimento@gmail.com>2020-09-19 19:13:43 -0700
commit34d5102347c52df9d65f804cd72f9cc32318a162 (patch)
tree15cdd5bd05f49f2646d49a8ac942e0050ae409fa
parentd4a1b0f9f65c35b8edf7d665eabb10978e7c4086 (diff)
downloadgjs-34d5102347c52df9d65f804cd72f9cc32318a162.tar.gz
gjs-tests: Add tests to verify rounded GArgument getter
-rw-r--r--test/gjs-tests.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index d08c3bf9..1c09bf65 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -582,6 +582,37 @@ static void gjstest_test_args_set_get_unset() {
random_unsigned_iface);
}
+static void gjstest_test_args_rounded_values() {
+ GIArgument arg = {0};
+
+ gjs_arg_set<int64_t>(&arg, std::numeric_limits<int64_t>::max());
+ g_test_expect_message(
+ G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*cannot be safely stored in a JS Number and may be rounded");
+ assert_equal(gjs_arg_get_maybe_rounded<int64_t>(&arg),
+ static_cast<double>(gjs_arg_get<int64_t>(&arg)));
+ g_test_assert_expected_messages();
+
+ gjs_arg_set<int64_t>(&arg, std::numeric_limits<int64_t>::min());
+ g_test_expect_message(
+ G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*cannot be safely stored in a JS Number and may be rounded");
+ assert_equal(gjs_arg_get_maybe_rounded<int64_t>(&arg),
+ static_cast<double>(gjs_arg_get<int64_t>(&arg)));
+ g_test_assert_expected_messages();
+
+ gjs_arg_set<uint64_t>(&arg, std::numeric_limits<uint64_t>::max());
+ g_test_expect_message(
+ G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*cannot be safely stored in a JS Number and may be rounded");
+ assert_equal(gjs_arg_get_maybe_rounded<uint64_t>(&arg),
+ static_cast<double>(gjs_arg_get<uint64_t>(&arg)));
+ g_test_assert_expected_messages();
+
+ gjs_arg_set<uint64_t>(&arg, std::numeric_limits<uint64_t>::min());
+ assert_equal(gjs_arg_get_maybe_rounded<uint64_t>(&arg), 0.0);
+}
+
int
main(int argc,
char **argv)
@@ -624,6 +655,8 @@ main(int argc,
gjstest_test_func_util_misc_strv_concat_pointers);
g_test_add_func("/gi/args/set-get-unset", gjstest_test_args_set_get_unset);
+ g_test_add_func("/gi/args/rounded_values",
+ gjstest_test_args_rounded_values);
#define ADD_JSAPI_UTIL_TEST(path, func) \
g_test_add("/gjs/jsapi/util/" path, GjsUnitTestFixture, NULL, \