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