9 |
9 |
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
10 |
10 |
* See the COPYING.LIB file in the top-level directory.
|
11 |
11 |
*/
|
12 |
|
#include <check.h>
|
|
12 |
#include <glib.h>
|
13 |
13 |
|
14 |
14 |
#include "qint.h"
|
15 |
15 |
#include "qemu-common.h"
|
... | ... | |
20 |
20 |
* (with some violations to access 'private' data)
|
21 |
21 |
*/
|
22 |
22 |
|
23 |
|
START_TEST(qint_from_int_test)
|
|
23 |
static void qint_from_int_test(void)
|
24 |
24 |
{
|
25 |
25 |
QInt *qi;
|
26 |
26 |
const int value = -42;
|
27 |
27 |
|
28 |
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);
|
|
29 |
g_assert(qi != NULL);
|
|
30 |
g_assert(qi->value == value);
|
|
31 |
g_assert(qi->base.refcnt == 1);
|
|
32 |
g_assert(qobject_type(QOBJECT(qi)) == QTYPE_QINT);
|
33 |
33 |
|
34 |
34 |
// destroy doesn't exit yet
|
35 |
35 |
g_free(qi);
|
36 |
36 |
}
|
37 |
|
END_TEST
|
38 |
37 |
|
39 |
|
START_TEST(qint_destroy_test)
|
|
38 |
static void qint_destroy_test(void)
|
40 |
39 |
{
|
41 |
40 |
QInt *qi = qint_from_int(0);
|
42 |
41 |
QDECREF(qi);
|
43 |
42 |
}
|
44 |
|
END_TEST
|
45 |
43 |
|
46 |
|
START_TEST(qint_from_int64_test)
|
|
44 |
static void qint_from_int64_test(void)
|
47 |
45 |
{
|
48 |
46 |
QInt *qi;
|
49 |
47 |
const int64_t value = 0x1234567890abcdefLL;
|
50 |
48 |
|
51 |
49 |
qi = qint_from_int(value);
|
52 |
|
fail_unless((int64_t) qi->value == value);
|
|
50 |
g_assert((int64_t) qi->value == value);
|
53 |
51 |
|
54 |
52 |
QDECREF(qi);
|
55 |
53 |
}
|
56 |
|
END_TEST
|
57 |
54 |
|
58 |
|
START_TEST(qint_get_int_test)
|
|
55 |
static void qint_get_int_test(void)
|
59 |
56 |
{
|
60 |
57 |
QInt *qi;
|
61 |
58 |
const int value = 123456;
|
62 |
59 |
|
63 |
60 |
qi = qint_from_int(value);
|
64 |
|
fail_unless(qint_get_int(qi) == value);
|
|
61 |
g_assert(qint_get_int(qi) == value);
|
65 |
62 |
|
66 |
63 |
QDECREF(qi);
|
67 |
64 |
}
|
68 |
|
END_TEST
|
69 |
65 |
|
70 |
|
START_TEST(qobject_to_qint_test)
|
|
66 |
static void qobject_to_qint_test(void)
|
71 |
67 |
{
|
72 |
68 |
QInt *qi;
|
73 |
69 |
|
74 |
70 |
qi = qint_from_int(0);
|
75 |
|
fail_unless(qobject_to_qint(QOBJECT(qi)) == qi);
|
|
71 |
g_assert(qobject_to_qint(QOBJECT(qi)) == qi);
|
76 |
72 |
|
77 |
73 |
QDECREF(qi);
|
78 |
74 |
}
|
79 |
|
END_TEST
|
80 |
75 |
|
81 |
|
static Suite *qint_suite(void)
|
|
76 |
int main(int argc, char **argv)
|
82 |
77 |
{
|
83 |
|
Suite *s;
|
84 |
|
TCase *qint_public_tcase;
|
|
78 |
g_test_init(&argc, &argv, NULL);
|
85 |
79 |
|
86 |
|
s = suite_create("QInt test-suite");
|
|
80 |
g_test_add_func("/public/from_int", qint_from_int_test);
|
|
81 |
g_test_add_func("/public/destroy", qint_destroy_test);
|
|
82 |
g_test_add_func("/public/from_int64", qint_from_int64_test);
|
|
83 |
g_test_add_func("/public/get_int", qint_get_int_test);
|
|
84 |
g_test_add_func("/public/to_qint", qobject_to_qint_test);
|
87 |
85 |
|
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 |
|
|
99 |
|
int 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;
|
|
86 |
return g_test_run();
|
113 |
87 |
}
|