]> git.proxmox.com Git - mirror_qemu.git/blame - check-qint.c
TCG: Revert ppc64 tcg_out_movi32 change
[mirror_qemu.git] / check-qint.c
CommitLineData
33837ba6
LC
1/*
2 * QInt unit-tests.
3 *
4 * Copyright (C) 2009 Red Hat Inc.
5 *
6 * Authors:
7 * Luiz Capitulino <lcapitulino@redhat.com>
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
LC
11 */
12#include <check.h>
13
14#include "qint.h"
15#include "qemu-common.h"
16
17/*
18 * Public Interface test-cases
19 *
20 * (with some violations to access 'private' data)
21 */
22
23START_TEST(qint_from_int_test)
24{
25 QInt *qi;
26 const int value = -42;
27
28 qi = qint_from_int(value);
29 fail_unless(qi != NULL);
30 fail_unless(qi->value == value);
31 fail_unless(qi->base.refcnt == 1);
32 fail_unless(qobject_type(QOBJECT(qi)) == QTYPE_QINT);
33
34 // destroy doesn't exit yet
35 qemu_free(qi);
36}
37END_TEST
38
39START_TEST(qint_destroy_test)
40{
41 QInt *qi = qint_from_int(0);
42 QDECREF(qi);
43}
44END_TEST
45
46START_TEST(qint_from_int64_test)
47{
48 QInt *qi;
02c068c3 49 const int64_t value = 0x1234567890abcdefLL;
33837ba6
LC
50
51 qi = qint_from_int(value);
02c068c3 52 fail_unless((int64_t) qi->value == value);
33837ba6
LC
53
54 QDECREF(qi);
55}
56END_TEST
57
58START_TEST(qint_get_int_test)
59{
60 QInt *qi;
61 const int value = 123456;
62
63 qi = qint_from_int(value);
64 fail_unless(qint_get_int(qi) == value);
65
66 QDECREF(qi);
67}
68END_TEST
69
70START_TEST(qobject_to_qint_test)
71{
72 QInt *qi;
73
74 qi = qint_from_int(0);
75 fail_unless(qobject_to_qint(QOBJECT(qi)) == qi);
76
77 QDECREF(qi);
78}
79END_TEST
80
81static Suite *qint_suite(void)
82{
83 Suite *s;
84 TCase *qint_public_tcase;
85
86 s = suite_create("QInt test-suite");
87
88 qint_public_tcase = tcase_create("Public Interface");
89 suite_add_tcase(s, qint_public_tcase);
90 tcase_add_test(qint_public_tcase, qint_from_int_test);
91 tcase_add_test(qint_public_tcase, qint_destroy_test);
92 tcase_add_test(qint_public_tcase, qint_from_int64_test);
93 tcase_add_test(qint_public_tcase, qint_get_int_test);
94 tcase_add_test(qint_public_tcase, qobject_to_qint_test);
95
96 return s;
97}
98
99int main(void)
100{
101 int nf;
102 Suite *s;
103 SRunner *sr;
104
105 s = qint_suite();
106 sr = srunner_create(s);
107
108 srunner_run_all(sr, CK_NORMAL);
109 nf = srunner_ntests_failed(sr);
110 srunner_free(sr);
111
112 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
113}