aboutsummaryrefslogtreecommitdiff
path: root/tests/check-qnum.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/check-qnum.c')
-rw-r--r--tests/check-qnum.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/check-qnum.c b/tests/check-qnum.c
index da7e0b0a9a..d702d5da9c 100644
--- a/tests/check-qnum.c
+++ b/tests/check-qnum.c
@@ -39,6 +39,21 @@ static void qnum_from_int_test(void)
QDECREF(qn);
}
+static void qnum_from_uint_test(void)
+{
+ QNum *qn;
+ const uint64_t value = UINT64_MAX;
+
+ qn = qnum_from_uint(value);
+ g_assert(qn != NULL);
+ g_assert_cmpint(qn->kind, ==, QNUM_U64);
+ g_assert(qn->u.u64 == value);
+ g_assert(qn->base.refcnt == 1);
+ g_assert(qobject_type(QOBJECT(qn)) == QTYPE_QNUM);
+
+ QDECREF(qn);
+}
+
static void qnum_from_double_test(void)
{
QNum *qn;
@@ -76,6 +91,37 @@ static void qnum_get_int_test(void)
QDECREF(qn);
}
+static void qnum_get_uint_test(void)
+{
+ QNum *qn;
+ const int value = 123456;
+ uint64_t val;
+ int64_t ival;
+
+ qn = qnum_from_uint(value);
+ g_assert(qnum_get_try_uint(qn, &val));
+ g_assert_cmpuint(val, ==, value);
+ QDECREF(qn);
+
+ qn = qnum_from_int(value);
+ g_assert(qnum_get_try_uint(qn, &val));
+ g_assert_cmpuint(val, ==, value);
+ QDECREF(qn);
+
+ /* invalid cases */
+ qn = qnum_from_int(-1);
+ g_assert(!qnum_get_try_uint(qn, &val));
+ QDECREF(qn);
+
+ qn = qnum_from_uint(-1ULL);
+ g_assert(!qnum_get_try_int(qn, &ival));
+ QDECREF(qn);
+
+ qn = qnum_from_double(0.42);
+ g_assert(!qnum_get_try_uint(qn, &val));
+ QDECREF(qn);
+}
+
static void qobject_to_qnum_test(void)
{
QNum *qn;
@@ -112,9 +158,11 @@ int main(int argc, char **argv)
g_test_init(&argc, &argv, NULL);
g_test_add_func("/qnum/from_int", qnum_from_int_test);
+ g_test_add_func("/qnum/from_uint", qnum_from_uint_test);
g_test_add_func("/qnum/from_double", qnum_from_double_test);
g_test_add_func("/qnum/from_int64", qnum_from_int64_test);
g_test_add_func("/qnum/get_int", qnum_get_int_test);
+ g_test_add_func("/qnum/get_uint", qnum_get_uint_test);
g_test_add_func("/qnum/to_qnum", qobject_to_qnum_test);
g_test_add_func("/qnum/to_string", qnum_to_string_test);