blob: 49887bb7d9c1b9514b30fe2a7787758e13b1d8d7 [file] [log] [blame]
Luiz Capitulino33837ba2009-08-28 15:27:29 -03001/*
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
20START_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}
34END_TEST
35
36START_TEST(qint_destroy_test)
37{
38 QInt *qi = qint_from_int(0);
39 QDECREF(qi);
40}
41END_TEST
42
43START_TEST(qint_from_int64_test)
44{
45 QInt *qi;
Pierre Riteau02c068c2009-09-08 11:53:37 +020046 const int64_t value = 0x1234567890abcdefLL;
Luiz Capitulino33837ba2009-08-28 15:27:29 -030047
48 qi = qint_from_int(value);
Pierre Riteau02c068c2009-09-08 11:53:37 +020049 fail_unless((int64_t) qi->value == value);
Luiz Capitulino33837ba2009-08-28 15:27:29 -030050
51 QDECREF(qi);
52}
53END_TEST
54
55START_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}
65END_TEST
66
67START_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}
76END_TEST
77
78static 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
96int 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}