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