diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2017-06-07 20:36:01 +0400 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2017-06-20 14:31:31 +0200 |
commit | 61a8f418b26a2d974e38e4ae55020aca8d402d88 (patch) | |
tree | 3d0247aa5282793a911b8c699ae7c2da5772e50c /tests | |
parent | 36aeb6094f04bed036c43c5e0eb675ca78bf72fe (diff) |
qnum: add uint type
In order to store integer values between INT64_MAX and UINT64_MAX, add
a uint64_t internal representation.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20170607163635.17635-10-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check-qnum.c | 48 |
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); |