]>
Commit | Line | Data |
---|---|---|
33837ba6 LC |
1 | /* |
2 | * QInt unit-tests. | |
3 | * | |
4 | * Copyright (C) 2009 Red Hat Inc. | |
5 | * | |
6 | * Authors: | |
7 | * Luiz Capitulino <[email protected]> | |
41836a9f LC |
8 | * |
9 | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. | |
10 | * See the COPYING.LIB file in the top-level directory. | |
33837ba6 | 11 | */ |
681c28a3 | 12 | #include "qemu/osdep.h" |
65cdadd2 | 13 | #include <glib.h> |
33837ba6 | 14 | |
7b1b5d19 | 15 | #include "qapi/qmp/qint.h" |
33837ba6 LC |
16 | #include "qemu-common.h" |
17 | ||
18 | /* | |
19 | * Public Interface test-cases | |
20 | * | |
21 | * (with some violations to access 'private' data) | |
22 | */ | |
23 | ||
65cdadd2 | 24 | static void qint_from_int_test(void) |
33837ba6 LC |
25 | { |
26 | QInt *qi; | |
27 | const int value = -42; | |
28 | ||
29 | qi = qint_from_int(value); | |
65cdadd2 AL |
30 | g_assert(qi != NULL); |
31 | g_assert(qi->value == value); | |
32 | g_assert(qi->base.refcnt == 1); | |
33 | g_assert(qobject_type(QOBJECT(qi)) == QTYPE_QINT); | |
33837ba6 LC |
34 | |
35 | // destroy doesn't exit yet | |
7267c094 | 36 | g_free(qi); |
33837ba6 | 37 | } |
33837ba6 | 38 | |
65cdadd2 | 39 | static void qint_destroy_test(void) |
33837ba6 LC |
40 | { |
41 | QInt *qi = qint_from_int(0); | |
42 | QDECREF(qi); | |
43 | } | |
33837ba6 | 44 | |
65cdadd2 | 45 | static void qint_from_int64_test(void) |
33837ba6 LC |
46 | { |
47 | QInt *qi; | |
02c068c3 | 48 | const int64_t value = 0x1234567890abcdefLL; |
33837ba6 LC |
49 | |
50 | qi = qint_from_int(value); | |
65cdadd2 | 51 | g_assert((int64_t) qi->value == value); |
33837ba6 LC |
52 | |
53 | QDECREF(qi); | |
54 | } | |
33837ba6 | 55 | |
65cdadd2 | 56 | static void qint_get_int_test(void) |
33837ba6 LC |
57 | { |
58 | QInt *qi; | |
59 | const int value = 123456; | |
60 | ||
61 | qi = qint_from_int(value); | |
65cdadd2 | 62 | g_assert(qint_get_int(qi) == value); |
33837ba6 LC |
63 | |
64 | QDECREF(qi); | |
65 | } | |
33837ba6 | 66 | |
65cdadd2 | 67 | static void qobject_to_qint_test(void) |
33837ba6 LC |
68 | { |
69 | QInt *qi; | |
70 | ||
71 | qi = qint_from_int(0); | |
65cdadd2 | 72 | g_assert(qobject_to_qint(QOBJECT(qi)) == qi); |
33837ba6 LC |
73 | |
74 | QDECREF(qi); | |
75 | } | |
33837ba6 | 76 | |
65cdadd2 | 77 | int main(int argc, char **argv) |
33837ba6 | 78 | { |
65cdadd2 | 79 | g_test_init(&argc, &argv, NULL); |
33837ba6 | 80 | |
65cdadd2 AL |
81 | g_test_add_func("/public/from_int", qint_from_int_test); |
82 | g_test_add_func("/public/destroy", qint_destroy_test); | |
83 | g_test_add_func("/public/from_int64", qint_from_int64_test); | |
84 | g_test_add_func("/public/get_int", qint_get_int_test); | |
85 | g_test_add_func("/public/to_qint", qobject_to_qint_test); | |
33837ba6 | 86 | |
65cdadd2 | 87 | return g_test_run(); |
33837ba6 | 88 | } |